@delurio/cli 0.1.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,26 @@
1
+ # Changelog
2
+
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
+
5
+ ## 0.3.0 (2026-10-25)
6
+
7
+ - 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.
8
+ - SPEC.md §7: a video's AI disclosure is its first card, which says that the whole video is made with AI, in place of a label people see throughout.
9
+
10
+ ## 0.2.0 (2026-10-25)
11
+
12
+ - JSON Schemas (2020-12) for `flow`, `ui`, `nav` (and `nav.extracted.yaml`), `domain` and `catalog` files, shipped in `schemas/`, for editors: completion, hover help from SPEC.md, and errors such as a typo in a key or a title cut short by a comma inside `{ }`.
13
+ - `page --watch` writes the pages again on every change under the folder; `page --serve [--port <n>]` also serves them on 127.0.0.1 and reloads the open page after each write, or says why a graph could not be loaded.
14
+ - `check` validates every graph file against its kind's schema: each place a file does not follow it is an error of the new rule `schema`, at its line and column, which fails `--strict` (exit 2) and works with `--baseline`.
15
+
16
+ ## 0.1.1 (2026-10-25)
17
+
18
+ - `page` on a folder writes the page of every graph under it and `index.html` listing them, in one process.
19
+ - A folder that holds no graph gets one line instead of a stack trace; counts read in the singular when there is one.
20
+ - The README runs every command as `npx @delurio/cli`.
21
+
22
+ ## 0.1.0 (2026-10-25)
23
+
24
+ - `check`: every graph under a folder, as GNU error lines or SARIF 2.1.0, with `--baseline`; exit 0, 1 or 2.
25
+ - `page`: a graph's page in words, with its guarantees, screens and diagram.
26
+ - `diff`: what a revision changes in a graph, in words, for a pull request.
package/README.md CHANGED
@@ -64,6 +64,34 @@ Given a folder of graphs instead, it writes the page of every graph under it, ea
64
64
  npx @delurio/cli page graphs --out viz
65
65
  ```
66
66
 
67
+ ## Write a graph in an editor
68
+
69
+ The package ships a JSON Schema (2020-12) for each kind of graph file in `schemas/`: `flow`, `ui`, `nav` (also `nav.extracted.yaml`), `domain` and `catalog`. With them an editor completes keys, explains each one from SPEC.md on hover, and marks a typo, a value of the wrong kind, or a title cut short by a comma inside `{ }`. In VS Code, with the YAML extension, put this in `.vscode/settings.json`:
70
+
71
+ ```json
72
+ {
73
+ "yaml.schemas": {
74
+ "https://unpkg.com/@delurio/cli@0.2.0/schemas/flow.schema.json": "**/flow.yaml",
75
+ "https://unpkg.com/@delurio/cli@0.2.0/schemas/ui.schema.json": "**/ui.yaml",
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"
78
+ },
79
+ "json.schemas": [
80
+ { "fileMatch": ["**/catalog/*.json"], "url": "https://unpkg.com/@delurio/cli@0.2.0/schemas/catalog.schema.json" }
81
+ ]
82
+ }
83
+ ```
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.
86
+
87
+ Next to the editor, keep the pages open and current:
88
+
89
+ ```sh
90
+ npx @delurio/cli page graphs --serve # http://127.0.0.1:4600/, written again and reloaded on every save
91
+ ```
92
+
93
+ `--watch` writes the pages again on every change without serving them. `--serve` listens on 127.0.0.1 only and serves the written pages and nothing else; when a save leaves a graph that cannot be loaded, the open page says why until the next good save.
94
+
67
95
  ## What a revision changes, in words
68
96
 
69
97
  ```sh
@@ -72,6 +100,20 @@ npx @delurio/cli diff examples/qauth-authorize --base origin/main
72
100
 
73
101
  This prints Markdown for a pull request. It covers what the flow does differently (found by running both revisions) and what changed in the graph.
74
102
 
103
+ ## As a library
104
+
105
+ A tool built on the format can use the same loader and checker the CLI uses:
106
+
107
+ ```ts
108
+ import { load } from '@delurio/cli/graph';
109
+ import { explore, Model } from '@delurio/cli/model';
110
+
111
+ const g = load('graphs/billing/billing.payment');
112
+ const configurations = explore(new Model(g.flow)).configs.length;
113
+ ```
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.
116
+
75
117
  ## Licence
76
118
 
77
119
  Apache-2.0. See [LICENSE](LICENSE) and [NOTICE](NOTICE). The name "delurio" is not licensed with the code.
package/SPEC.md CHANGED
@@ -68,7 +68,7 @@ states: { <state>: { .. } }
68
68
  assertions: [ { id, never: "<expression>", say, source } ]
69
69
  ```
70
70
 
71
- A flow is a statechart, and its meaning is a subset of SCXML's (W3C Recommendation, 2015). A transition in `on` is an SCXML transition with an event, `always` is a list of eventless transitions, a list of transitions is tried in document order, `invoke` and `type: final` mean what they mean in SCXML, a guard is a `cond` and an effect an `<assign>`; `DONE` and `FAIL.<class>` stand for SCXML's `done.invoke` and `error` events. A flow can therefore be written out as SCXML; that export is an open issue.
71
+ A flow is a statechart, and its meaning is a subset of SCXML's (W3C Recommendation, 2015). A transition in `on` is an SCXML transition with an event, `always` is a list of eventless transitions, a list of transitions is tried in document order, `invoke` and `type: final` mean what they mean in SCXML, a guard is a `cond` and an effect an `<assign>`; `DONE` and `FAIL.<class>` stand for SCXML's `done.invoke` and `error` events. A flow can therefore be written out as SCXML; that export is [#9](https://github.com/delurio-labs/delurio/issues/9).
72
72
 
73
73
  ### Context
74
74
 
@@ -117,7 +117,7 @@ A configuration is a state together with a value for every context variable. The
117
117
 
118
118
  Each assertion is `never: <expression>`: it holds when no reachable configuration satisfies the expression. A violation is reported with the shortest event path from a starting situation. Under `--strict` a violated assertion exits 2.
119
119
 
120
- The checker does not yet fail on unreachable states, transitions no situation takes, or states with no way out; the page already shows them. That is an open issue. Paths that cover every transition are an open issue.
120
+ The checker does not yet fail on unreachable states, transitions no situation takes, or states with no way out; the page already shows them. That is [#2](https://github.com/delurio-labs/delurio/issues/2). Paths that cover every transition are [#4](https://github.com/delurio-labs/delurio/issues/4).
121
121
 
122
122
  ### Several flows
123
123
 
@@ -177,7 +177,7 @@ rules: [ { id, rule } ]
177
177
 
178
178
  A `role` is a WAI-ARIA 1.2 role, and `name` is the accessible name that Accessible Name and Description Computation 1.2 gives the node; `kit check` reads both from the browser's accessibility tree.
179
179
 
180
- A node is shown in a state when the state is in `in`, not in `unless`, and `when` holds. `edges` records relations the page and the checks use: a node labelled by another, an action that leads to a state. `rules` are written but no tool reads them yet; checking them, together with dialogs, focus return, confirmation before a destructive action and events handled where shown, is an open issue.
180
+ A node is shown in a state when the state is in `in`, not in `unless`, and `when` holds. `edges` records relations the page and the checks use: a node labelled by another, an action that leads to a state. `rules` are written but no tool reads them yet; checking them, together with dialogs, focus return, confirmation before a destructive action and events handled where shown, is [#3](https://github.com/delurio-labs/delurio/issues/3).
181
181
 
182
182
  ### Catalog
183
183
 
@@ -231,11 +231,13 @@ invariants:
231
231
 
232
232
  A capture may carry more words of its own on a field (`owner`, `note`, `editableBy`, `matching`, `opaque`). They are kept and compared, and no tool reads them.
233
233
 
234
+ An action, a refusal and an invariant may carry `note`: the author's own words, which no tool reads. An invariant the code does not keep is still written, with `holds: false` and the `finding` that reports it: the finding's id in the graph's report, such as `MS-7`. A capture describes the code, so the invariant says what should hold and the finding says where it does not. Decided on 25 Oct 2026.
235
+
234
236
  **The API.** An action with a `route` (`METHOD /path`) is one OpenAPI 3.1 operation: its name is the `operationId`, `needs` its security requirement, `query` (a JSON Schema object) its query parameters, `body` its request body, `result` its response (`returns` an entity, a `redirect`, a `status`, or a JSON Schema), and each refusal one more response. When a refusal has a body, it is RFC 9457 problem details with the refusal code as its `type`. So a domain can be written out as an OpenAPI document, and an app that already publishes one names it at the top (`openapi: <file>`) and each action's operation by `operationId`, instead of copying them. An action with no route is a step inside the service. `needs`, `policies`, `sideEffects`, `refusals.<code>.redirect` and `invariants` are delurio's own: no standard says who may do what to which data, or what must always hold.
235
237
 
236
- 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 an open issue.
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).
237
239
 
238
- 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 an open issue; generating it from Drizzle and Zod is an open issue; a registry that every API operation and route is covered by a graph is an open issue.
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).
239
241
 
240
242
  ## 6. Navigation (`kind: nav`)
241
243
 
@@ -271,7 +273,7 @@ A **binding** ties a flow to a running app for replay and recording: `apps` (bas
271
273
 
272
274
  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.
273
275
 
274
- 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: the label people see, 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 label 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"). The video tool does none of the three yet; that is an open issue.
276
+ 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.
275
277
 
276
278
  ## 8. Kit (`kind: kit`)
277
279
 
@@ -324,12 +326,12 @@ graphs/product/flow.yaml:88:7: note: step 2: CODE_CHANGED from developing, with
324
326
 
325
327
  The same input gives the same bytes: no times, no random ids, results in a fixed order. Every file written is valid against the OASIS schema.
326
328
 
327
- There is no other machine format: no JSON of delurio's own, and nothing that only one CI reads. A converter for a CI that reads neither (GitLab's Code Quality report, Bitbucket's Code Insights) is written when a customer needs it, outside the checker. The public, pinned, offline CLI that gives both outputs is an open issue.
329
+ There is no other machine format: no JSON of delurio's own, and nothing that only one CI reads. A converter for a CI that reads neither (GitLab's Code Quality report, Bitbucket's Code Insights) is written when a customer needs it, outside the checker. The public, pinned, offline CLI that gives both outputs is `@delurio/cli`, built from this repository; what its first release left out is [#1](https://github.com/delurio-labs/delurio/issues/1).
328
330
 
329
331
  ## 11. Writing a graph
330
332
 
331
333
  - Model the few cases that change behaviour; a guard over hundreds of permission codes is wrong.
332
- - Quote a YAML list item that contains `: `, or YAML reads it as a map.
334
+ - Quote a YAML list item that contains `: `, or YAML reads it as a map. Quote a value inside `{ }` that contains `, ` too, or YAML cuts it there and reads the rest as a key: `{ type: final, title: "Paid, and sent" }`.
333
335
  - Say every rule that must hold as an assertion; do not leave it implied by the drawing.
334
336
  - In capture mode, describe what the code does today: no new feature, no fix. An invariant the code breaks is modelled as the code has it and reported, not written as an assertion that fails.
335
337
  - One process, one flow. A process that runs beside another starts it (`starts:`) or waits for it (`invoke: { flow }`).
@@ -0,0 +1,7 @@
1
+ import type { Graph } from './graph.ts';
2
+ export interface ChangesCheck {
3
+ writes: string[];
4
+ key: string | null;
5
+ problems: string[];
6
+ }
7
+ export declare function checkChanges(g: Graph): ChangesCheck | null;
@@ -0,0 +1,23 @@
1
+ export declare const CHECK_USAGE: string;
2
+ type Level = 'error' | 'warning';
3
+ interface Place {
4
+ file: string;
5
+ line: number;
6
+ column: number;
7
+ }
8
+ interface Note extends Place {
9
+ message: string;
10
+ }
11
+ export interface CheckResult extends Place {
12
+ rule: string;
13
+ level: Level;
14
+ message: string;
15
+ graph: string;
16
+ element: string;
17
+ notes: Note[];
18
+ baselineState?: 'new' | 'unchanged';
19
+ }
20
+ export declare const count: (n: number, word: string) => string;
21
+ export declare function graphDirs(root: string, out?: string[]): string[];
22
+ export declare function checkMain(args: string[]): number;
23
+ export {};
package/dist/check.js CHANGED
@@ -14,6 +14,7 @@ import { checkStarts } from './starts.js';
14
14
  import { checkChanges } from './changes.js';
15
15
  import { KitError, resolveKit } from './kit.js';
16
16
  import { checkGoals, findings, loadNav, viewOf } from './nav.js';
17
+ import { schemaKindOf, validateFile } from './schemas.js';
17
18
  export const CHECK_USAGE = [
18
19
  ' node src/cli.ts check <graphs folder> [--strict] [--baseline <sarif>] [--format sarif --output <file>]',
19
20
  ' checks every graph under the folder and writes nothing else: GNU error lines on stdout, or SARIF 2.1.0;',
@@ -24,6 +25,7 @@ const SKIP = new Set(['viz', 'video', 'recording', 'node_modules', '.git']);
24
25
  const RULES = [
25
26
  { id: 'load', text: 'The graph cannot be loaded', level: 'error' },
26
27
  { id: 'format-newer', text: 'The graph is written for a newer format than this checker reads', level: 'error' },
28
+ { id: 'schema', text: "A graph file does not follow its kind's schema (SPEC.md)", level: 'error' },
27
29
  { id: 'assertion-violated', text: 'A guarantee of the flow is broken by a reachable situation', level: 'error' },
28
30
  { id: 'main-story-unwalkable', text: 'The declared main story cannot be walked', level: 'error' },
29
31
  { id: 'catalog-key-missing', text: 'A catalog key the screens use is missing', level: 'error' },
@@ -65,6 +67,19 @@ export function graphDirs(root, out = []) {
65
67
  }
66
68
  return out;
67
69
  }
70
+ // every file under root that a schema covers (flow, ui, nav, nav.extracted, domain, catalog), in path order
71
+ function graphFiles(root, out = []) {
72
+ for (const name of readdirSync(root).sort()) {
73
+ if (SKIP.has(name) || name.startsWith('.'))
74
+ continue;
75
+ const path = join(root, name);
76
+ if (statSync(path).isDirectory())
77
+ graphFiles(path, out);
78
+ else if (schemaKindOf(path) !== null)
79
+ out.push(path);
80
+ }
81
+ return out;
82
+ }
68
83
  // the format the file says it is written in: null when it is this one
69
84
  function newerFormat(abs) {
70
85
  const doc = parse(readFileSync(abs, 'utf8'));
@@ -239,6 +254,11 @@ export function checkMain(args) {
239
254
  results.push(result('load', file, linePos === undefined ? { line: 1, column: 1 } : { line: linePos.line, column: linePos.col }, err.message.split('\n')[0], rel(d), 'load'));
240
255
  }
241
256
  }
257
+ // every graph file against its kind's schema: what an editor with the schemas marks, check reports
258
+ for (const file of graphFiles(root)) {
259
+ for (const f of validateFile(file))
260
+ results.push(result('schema', file, f, f.message, f.graph ?? rel(file), f.element));
261
+ }
242
262
  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));
243
263
  if (baseline !== undefined) {
244
264
  const prints = baselinePrints(baseline);
package/dist/cli.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/cli.js CHANGED
@@ -19,12 +19,15 @@ import { DIFF_USAGE, diffMain } from './diff.js';
19
19
  import { KitError, resolveKit } from './kit.js';
20
20
  import { CHECK_USAGE, checkMain, count, graphDirs } from './check.js';
21
21
  import { renderIndexPage } from './index-page.js';
22
+ import { watchPages } from './watch.js';
22
23
  const USAGE = [
23
24
  'usage:',
24
25
  CHECK_USAGE,
25
- ' delurio page <graph dir | graphs folder> [--out <dir>] [--kit <kit>] [--locale <code>] [--strict]',
26
+ ' delurio page <graph dir | graphs folder> [--out <dir>] [--kit <kit>] [--locale <code>] [--strict] [--watch] [--serve [--port <n>]]',
26
27
  ' writes the graph\'s page: <out>/index.html and its diagram (default out: <graph dir>/viz); on a folder of graphs,',
27
- ' the page of each at <out>/<its path> and an index of them all at <out>/index.html (default out: <folder>/viz)',
28
+ ' the page of each at <out>/<its path> and an index of them all at <out>/index.html (default out: <folder>/viz);',
29
+ ' --watch writes them again on every change under the folder; --serve also shows them at http://127.0.0.1:<port>/',
30
+ ' (default 4600) and reloads the open page after each write',
28
31
  DIFF_USAGE.replaceAll('node src/cli.ts', 'delurio'),
29
32
  ].join('\n').replaceAll('node src/cli.ts', 'delurio');
30
33
  const flag = (args, name) => {
@@ -94,13 +97,13 @@ const isGraph = (dir) => existsSync(join(dir, 'flow.yaml')) || existsSync(join(d
94
97
  // every graph under the folder, each into <out>/<its path>, and the index of them all. A graph that cannot be loaded
95
98
  // is listed as such and the rest are still written: exit 1 when one cannot be loaded, else 2 under --strict when one
96
99
  // would fail on its own, else 0.
97
- async function treePages(root, args) {
100
+ async function treePages(root, out, args) {
98
101
  const dirs = graphDirs(root);
99
102
  if (dirs.length === 0) {
100
- console.error(`error: ${root} is not a graph and holds none: there is no flow.yaml or nav.yaml in it or under it`);
101
- return 1;
103
+ const message = `${root} is not a graph and holds none: there is no flow.yaml or nav.yaml in it or under it`;
104
+ console.error(`error: ${message}`);
105
+ return { code: 1, message };
102
106
  }
103
- const out = resolve(flag(args, '--out') ?? join(root, 'viz'));
104
107
  const entries = [];
105
108
  let broken = false;
106
109
  let failing = false;
@@ -113,7 +116,7 @@ async function treePages(root, args) {
113
116
  failing ||= code !== 0;
114
117
  }
115
118
  catch (err) {
116
- if (!(err instanceof GraphError || err instanceof ModelError || err instanceof KitError || (err instanceof Error && err.name === 'YAMLParseError')))
119
+ if (!loadError(err))
117
120
  throw err;
118
121
  broken = true;
119
122
  const message = err.message.split('\n')[0].replace(/:$/, '');
@@ -124,7 +127,27 @@ async function treePages(root, args) {
124
127
  mkdirSync(out, { recursive: true });
125
128
  writeFileSync(join(out, 'index.html'), renderIndexPage(basename(resolve(root)), entries));
126
129
  console.log(`wrote ${join(out, 'index.html')} and the pages of ${count(entries.length - entries.filter((e) => e.error !== null).length, 'graph')} under ${out}`);
127
- return broken ? 1 : failing ? 2 : 0;
130
+ const firstError = entries.find((e) => e.error !== null);
131
+ return { code: broken ? 1 : failing ? 2 : 0, message: firstError === undefined ? '' : `${firstError.path}: ${firstError.error}` };
132
+ }
133
+ const loadError = (err) => err instanceof GraphError || err instanceof ModelError || err instanceof KitError || (err instanceof Error && err.name === 'YAMLParseError');
134
+ // one graph's page, or the pages of every graph under the folder
135
+ async function writePages(dir, out, args) {
136
+ if (!isGraph(dir))
137
+ return treePages(dir, out, args);
138
+ try {
139
+ const flow = existsSync(join(dir, 'flow.yaml'));
140
+ const { code } = flow ? await flowPage(dir, out, args) : navPage(dir, out, args);
141
+ console.log(`wrote ${join(out, 'index.html')} and ${join(out, flow ? 'flow.mmd' : 'nav.mmd')}`);
142
+ return { code, message: '' };
143
+ }
144
+ catch (err) {
145
+ if (!loadError(err))
146
+ throw err;
147
+ const message = err.message.split('\n')[0].replace(/:$/, '');
148
+ console.error(`error: ${message}`);
149
+ return { code: 1, message };
150
+ }
128
151
  }
129
152
  async function main() {
130
153
  const args = process.argv.slice(2);
@@ -134,7 +157,7 @@ async function main() {
134
157
  return diffMain(args.slice(1));
135
158
  if (args[0] === 'page') {
136
159
  const rest = args.slice(1);
137
- const withValue = ['--out', '--kit', '--locale'];
160
+ const withValue = ['--out', '--kit', '--locale', '--port'];
138
161
  const dir = rest.find((a, i) => !a.startsWith('--') && !withValue.includes(rest[i - 1] ?? ''));
139
162
  if (dir === undefined) {
140
163
  console.error(USAGE);
@@ -144,12 +167,20 @@ async function main() {
144
167
  console.error(`error: ${dir} is not a folder`);
145
168
  return 1;
146
169
  }
147
- if (!isGraph(dir))
148
- return treePages(dir, rest);
149
170
  const out = resolve(flag(rest, '--out') ?? join(dir, 'viz'));
150
- const { code } = existsSync(join(dir, 'flow.yaml')) ? await flowPage(dir, out, rest) : navPage(dir, out, rest);
151
- console.log(`wrote ${join(out, 'index.html')} and ${join(out, existsSync(join(dir, 'flow.yaml')) ? 'flow.mmd' : 'nav.mmd')}`);
152
- return code;
171
+ const first = await writePages(dir, out, rest);
172
+ const serve = rest.includes('--serve');
173
+ if (!serve && !rest.includes('--watch'))
174
+ return first.code;
175
+ const port = Number(flag(rest, '--port') ?? 4600);
176
+ if (!Number.isInteger(port) || port < 1 || port > 65535) {
177
+ console.error(`error: --port is a port number, not ${flag(rest, '--port')}`);
178
+ return 1;
179
+ }
180
+ return watchPages(dir, out, async () => {
181
+ const again = await writePages(dir, out, rest);
182
+ return { ok: again.code !== 1, message: again.message };
183
+ }, serve ? port : null);
153
184
  }
154
185
  console.error(USAGE);
155
186
  return args.length === 0 || args.includes('--help') ? 0 : 1;
@@ -0,0 +1,34 @@
1
+ export type Op = 'added' | 'removed' | 'changed' | 'moved';
2
+ export interface Change {
3
+ area: string;
4
+ key: string;
5
+ op: Op;
6
+ field?: string;
7
+ before?: unknown;
8
+ after?: unknown;
9
+ say: string | null;
10
+ }
11
+ export interface Shift {
12
+ topic: string;
13
+ key: string;
14
+ persona?: string;
15
+ before: unknown;
16
+ after: unknown;
17
+ say: string;
18
+ detail: string[];
19
+ worse: boolean;
20
+ }
21
+ export declare function canon(v: unknown): string;
22
+ export declare const same: (a: unknown, b: unknown) => boolean;
23
+ export declare function union(before: object | undefined, after: object | undefined): string[];
24
+ export declare const quote: (s: string) => string;
25
+ export declare const joinWords: (xs: string[]) => string;
26
+ export declare function matchOrdered<T>(before: T[], after: T[], keys: Array<(x: T) => string | null>): Array<[number, number]>;
27
+ export declare function moved(pairs: Array<[number, number]>): Array<[number, number]>;
28
+ export declare function deepDiff(area: string, key: string, before: unknown, after: unknown, out: Change[], path?: string[]): void;
29
+ export declare function fieldChanges(area: string, key: string, before: Record<string, unknown>, after: Record<string, unknown>, fields: string[], say: (field: string, b: unknown, a: unknown) => string | null): Change[];
30
+ export declare function otherKeys(key: string, before: Record<string, unknown>, after: Record<string, unknown>, known: string[], out: Change[]): void;
31
+ export declare function listChanges(before: string[] | undefined, after: string[] | undefined): {
32
+ added: string[];
33
+ removed: string[];
34
+ };
@@ -0,0 +1,33 @@
1
+ import type { Graph } from './graph.ts';
2
+ import { Model } from './model.ts';
3
+ import type { Exploration } from './model.ts';
4
+ import type { PathStep } from './story.ts';
5
+ import type { Change, Shift } from './compare.ts';
6
+ export interface FlowSide {
7
+ g: Graph;
8
+ domain: {
9
+ file: string;
10
+ doc: unknown;
11
+ } | null;
12
+ }
13
+ export interface FlowStructure {
14
+ changes: Change[];
15
+ ways: Array<[string, string]>;
16
+ added: string[];
17
+ }
18
+ export declare function flowStructure(b: FlowSide, a: FlowSide): FlowStructure;
19
+ interface Run {
20
+ g: Graph;
21
+ m: Model;
22
+ ex: Exploration;
23
+ violations: Map<string, number>;
24
+ exits: Map<string, number>;
25
+ moves: number;
26
+ main: PathStep[] | null;
27
+ mainBroken: boolean;
28
+ reached: Set<string>;
29
+ }
30
+ export declare function runSide(g: Graph, side: string): Run;
31
+ export declare function flowBehaviour(rb: Run, ra: Run, s: FlowStructure): Shift[];
32
+ export declare function flowSameBehaviour(r: Run): string;
33
+ export {};
@@ -0,0 +1,20 @@
1
+ import type { Finding, Goalcheck, NavGraph, PersonaView } from './nav.ts';
2
+ import type { Change, Shift } from './compare.ts';
3
+ export interface NavSide {
4
+ g: NavGraph;
5
+ warnings: string[];
6
+ }
7
+ export interface NavStructure {
8
+ changes: Change[];
9
+ entries: Array<[number, number]>;
10
+ }
11
+ export declare function navStructure(b: NavSide, a: NavSide): NavStructure;
12
+ export interface NavRun {
13
+ g: NavGraph;
14
+ views: PersonaView[];
15
+ goals: Goalcheck[];
16
+ found: Finding[];
17
+ }
18
+ export declare function runNav(g: NavGraph, side: string): NavRun;
19
+ export declare function navBehaviour(rb: NavRun, ra: NavRun, s: NavStructure): Shift[];
20
+ export declare function navSameBehaviour(r: NavRun): string;
package/dist/diff.d.ts ADDED
@@ -0,0 +1,23 @@
1
+ import type { Change, Shift } from './compare.ts';
2
+ export declare const DIFF_USAGE: string;
3
+ interface Source {
4
+ where: string;
5
+ rev: string | null;
6
+ read: (file: string) => string;
7
+ exists: (file: string) => boolean;
8
+ texts: Map<string, string>;
9
+ }
10
+ export interface Report {
11
+ kind: 'flow' | 'nav';
12
+ title: string;
13
+ before: Source;
14
+ after: Source;
15
+ structure: Change[];
16
+ behaviour: Shift[];
17
+ same: string;
18
+ }
19
+ export declare function renderMarkdown(r: Report): string;
20
+ export declare function renderJson(r: Report): string;
21
+ export declare function compare(before: Source, after: Source, locale?: string): Report;
22
+ export declare function diffMain(args: string[]): Promise<number>;
23
+ export {};
@@ -0,0 +1,21 @@
1
+ import type { Graph, State } from './graph.ts';
2
+ import type { Exploration } from './model.ts';
3
+ export type EdgeKind = 'user' | 'system' | 'route' | 'fail';
4
+ export interface VizEdge {
5
+ from: string;
6
+ to: string;
7
+ labels: string[];
8
+ kind: EdgeKind;
9
+ leave: boolean;
10
+ unused: boolean;
11
+ }
12
+ export type NodeKind = 'server' | 'screen' | 'subflow' | 'exit';
13
+ export declare const BY: Record<string, string>;
14
+ export declare function kindOf(g: Graph, name: string): NodeKind;
15
+ export declare function exitLine(st: State): string;
16
+ export declare function responseLine(r: Record<string, unknown>): string;
17
+ export declare function nodeLine(g: Graph, name: string): string;
18
+ export declare function plain(g: Graph, key: string): string;
19
+ export declare function pressLabel(g: Graph, state: string, event: string): string | null;
20
+ export declare function wrap(text: string, max: number): string[];
21
+ export declare function collectEdges(g: Graph, ex: Exploration): VizEdge[];
package/dist/expr.d.ts ADDED
@@ -0,0 +1,26 @@
1
+ export type Value = string | number | boolean | null | Value[];
2
+ export type Expr = {
3
+ k: 'lit';
4
+ v: Value;
5
+ } | {
6
+ k: 'id';
7
+ name: string;
8
+ } | {
9
+ k: 'list';
10
+ items: Expr[];
11
+ } | {
12
+ k: 'not';
13
+ e: Expr;
14
+ } | {
15
+ k: 'and' | 'or';
16
+ l: Expr;
17
+ r: Expr;
18
+ } | {
19
+ k: 'cmp';
20
+ op: '==' | '!=' | 'in' | 'not in';
21
+ l: Expr;
22
+ r: Expr;
23
+ };
24
+ export declare function parseExpr(src: string): Expr;
25
+ export declare function evaluate(e: Expr, lookup: (name: string) => Value): Value;
26
+ export declare function identifiers(e: Expr, out?: Set<string>): Set<string>;
@@ -0,0 +1,121 @@
1
+ export type Scalar = string | number | boolean;
2
+ export interface Transition {
3
+ target: string;
4
+ guard?: string;
5
+ effect?: string[];
6
+ say?: string;
7
+ starts?: Starts;
8
+ }
9
+ export interface Starts {
10
+ flow: string;
11
+ given?: Record<string, string | number | boolean>;
12
+ }
13
+ export type TransitionSpec = string | Transition | Array<string | Transition>;
14
+ export interface State {
15
+ title?: string;
16
+ description?: string;
17
+ type?: string;
18
+ invoke?: {
19
+ action?: string;
20
+ flow?: string;
21
+ external?: string;
22
+ };
23
+ on?: Record<string, TransitionSpec>;
24
+ always?: Transition[];
25
+ redirect?: string;
26
+ code?: string;
27
+ carries?: string[];
28
+ leavesPage?: boolean;
29
+ by?: 'human' | 'ai' | 'agent' | 'ci';
30
+ goal?: boolean;
31
+ includes?: string[];
32
+ response?: Record<string, unknown>;
33
+ states?: unknown;
34
+ }
35
+ export interface ContextVar {
36
+ values: Scalar[];
37
+ initial: 'any' | Scalar;
38
+ say?: Record<string, string>;
39
+ }
40
+ export interface Effect {
41
+ set?: Record<string, Scalar>;
42
+ havoc?: string[];
43
+ }
44
+ export interface Decision {
45
+ question: string;
46
+ recommend: string;
47
+ affects: string[];
48
+ }
49
+ export interface Flow {
50
+ id: string;
51
+ title?: string;
52
+ status?: string;
53
+ summary?: string;
54
+ decisions?: Record<string, Decision>;
55
+ context: Record<string, ContextVar>;
56
+ guards: Record<string, string>;
57
+ effects: Record<string, Effect>;
58
+ initial: string;
59
+ states: Record<string, State>;
60
+ assertions?: Array<{
61
+ id: string;
62
+ never: string;
63
+ say?: string;
64
+ }>;
65
+ main?: string[] | {
66
+ given?: Record<string, Scalar>;
67
+ events: string[];
68
+ };
69
+ scope?: {
70
+ shows?: string;
71
+ world?: 'open' | 'closed';
72
+ outOfView?: string[];
73
+ };
74
+ domain?: string;
75
+ }
76
+ export interface Label {
77
+ key?: string;
78
+ params?: Record<string, string>;
79
+ labelledBy?: string;
80
+ literal?: string;
81
+ oneOf?: string[];
82
+ }
83
+ export interface UiNode {
84
+ type: string;
85
+ component?: string;
86
+ role?: string;
87
+ intent?: string;
88
+ name?: Label;
89
+ text?: Label;
90
+ in?: string[];
91
+ unless?: string[];
92
+ when?: string;
93
+ disabledIn?: string[];
94
+ emits?: string;
95
+ initialFocus?: string;
96
+ frame?: string;
97
+ }
98
+ export interface Ui {
99
+ absent?: boolean;
100
+ id: string;
101
+ catalog: string;
102
+ kit?: string;
103
+ samples: Record<string, string>;
104
+ nodes: Record<string, UiNode>;
105
+ locales?: string[];
106
+ changes?: {
107
+ key: string;
108
+ };
109
+ }
110
+ export interface Graph {
111
+ dir: string;
112
+ flow: Flow;
113
+ ui: Ui;
114
+ catalog: Record<string, string>;
115
+ }
116
+ export declare class GraphError extends Error {
117
+ }
118
+ export declare function humanize(id: string): string;
119
+ export declare function titleOf(flow: Flow, state: string): string;
120
+ export declare function alternatives(spec: TransitionSpec): Transition[];
121
+ export declare function load(dir: string, read?: (file: string) => string, exists?: (file: string) => boolean): Graph;