@delurio/cli 0.10.0 → 0.12.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.
Files changed (89) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/NOTICE +7 -0
  3. package/README.md +38 -22
  4. package/SPEC.md +8 -1
  5. package/js/changes.d.ts +17 -0
  6. package/js/cli.js +6 -0
  7. package/{dist → js}/edges.d.ts +2 -2
  8. package/js/edges.js +40 -0
  9. package/js/expr.js +25 -0
  10. package/{dist → js}/graph.d.ts +3 -0
  11. package/js/graph.js +73 -0
  12. package/{dist → js}/html.d.ts +6 -6
  13. package/js/html.js +13 -0
  14. package/js/internal.js +408 -0
  15. package/js/kit.js +54 -0
  16. package/{dist → js}/model.d.ts +2 -2
  17. package/js/model.js +136 -0
  18. package/js/native.cjs +46 -0
  19. package/js/native.d.cts +328 -0
  20. package/{dist → js}/nav.d.ts +1 -1
  21. package/js/nav.js +70 -0
  22. package/js/needs.js +30 -0
  23. package/{dist → js}/spine.d.ts +3 -3
  24. package/js/spine.js +22 -0
  25. package/{dist → js}/starts.d.ts +1 -3
  26. package/{dist → js}/story.d.ts +2 -2
  27. package/js/story.js +22 -0
  28. package/{dist → js}/wireframe.d.ts +2 -2
  29. package/js/wireframe.js +29 -0
  30. package/js/yaml.d.ts +20 -0
  31. package/js/yaml.js +40 -0
  32. package/package.json +40 -24
  33. package/schemas/binding.schema.json +2211 -0
  34. package/schemas/ui.schema.json +6 -0
  35. package/dist/anchors.d.ts +0 -29
  36. package/dist/anchors.js +0 -160
  37. package/dist/changes.d.ts +0 -25
  38. package/dist/changes.js +0 -101
  39. package/dist/check.d.ts +0 -23
  40. package/dist/check.js +0 -649
  41. package/dist/cli.d.ts +0 -2
  42. package/dist/cli.js +0 -194
  43. package/dist/compare.d.ts +0 -34
  44. package/dist/compare.js +0 -143
  45. package/dist/diff-flow.d.ts +0 -33
  46. package/dist/diff-flow.js +0 -547
  47. package/dist/diff-nav.d.ts +0 -20
  48. package/dist/diff-nav.js +0 -401
  49. package/dist/diff.d.ts +0 -25
  50. package/dist/diff.js +0 -331
  51. package/dist/domain-names.d.ts +0 -18
  52. package/dist/domain-names.js +0 -124
  53. package/dist/domain.d.ts +0 -25
  54. package/dist/domain.js +0 -110
  55. package/dist/edges.js +0 -120
  56. package/dist/expr.js +0 -157
  57. package/dist/graph.js +0 -236
  58. package/dist/html.js +0 -311
  59. package/dist/index-page.d.ts +0 -12
  60. package/dist/index-page.js +0 -50
  61. package/dist/invokes.d.ts +0 -10
  62. package/dist/invokes.js +0 -67
  63. package/dist/kit.js +0 -711
  64. package/dist/mermaid.d.ts +0 -3
  65. package/dist/mermaid.js +0 -50
  66. package/dist/model.js +0 -608
  67. package/dist/nav-page.d.ts +0 -15
  68. package/dist/nav-page.js +0 -283
  69. package/dist/nav.js +0 -578
  70. package/dist/needs.js +0 -335
  71. package/dist/pan.d.ts +0 -2
  72. package/dist/pan.js +0 -252
  73. package/dist/schemas.d.ts +0 -15
  74. package/dist/schemas.js +0 -316
  75. package/dist/spine.js +0 -156
  76. package/dist/starts.js +0 -88
  77. package/dist/story.js +0 -109
  78. package/dist/tutorial-check.d.ts +0 -9
  79. package/dist/tutorial-check.js +0 -297
  80. package/dist/ui-check.d.ts +0 -8
  81. package/dist/ui-check.js +0 -142
  82. package/dist/watch.d.ts +0 -5
  83. package/dist/watch.js +0 -114
  84. package/dist/wireframe.js +0 -276
  85. package/dist/yaml.d.ts +0 -19
  86. package/dist/yaml.js +0 -134
  87. /package/{dist → js}/expr.d.ts +0 -0
  88. /package/{dist → js}/kit.d.ts +0 -0
  89. /package/{dist → js}/needs.d.ts +0 -0
@@ -275,6 +275,12 @@
275
275
  "const": "never"
276
276
  },
277
277
  "value": { "$ref": "#/$defs/value", "description": "On a field: what it holds when it is shown, until someone types in it. A replay reads the field's value and compares it." },
278
+ "holds": {
279
+ "type": "string",
280
+ "pattern": "^[A-Za-z_][A-Za-z0-9_]*\\.[A-Za-z_][A-Za-z0-9_]*$",
281
+ "description": "The field of the flow's domain whose value the node shows, or the control takes: <Entity>.<field>. A node that holds a field whose sensitivity is credential is masked wherever the flow's screens are recorded (SPEC.md §4, §7).",
282
+ "examples": ["Client.name", "Credential.secret"]
283
+ },
278
284
  "checked": {
279
285
  "type": ["boolean", "string"],
280
286
  "minLength": 1,
package/dist/anchors.d.ts DELETED
@@ -1,29 +0,0 @@
1
- export type AnchorRule = 'source-unresolved' | 'citation-unresolved';
2
- export interface AnchorProblem {
3
- rule: AnchorRule;
4
- file: string;
5
- line: number;
6
- column: number;
7
- message: string;
8
- graph: string;
9
- element: string;
10
- }
11
- export interface AnchorsCheck {
12
- problems: AnchorProblem[];
13
- anchors: number;
14
- citations: number;
15
- }
16
- export declare class AppFiles {
17
- private readonly kinds;
18
- private readonly lines;
19
- readonly root: string;
20
- constructor(root: string);
21
- abs(path: string): string;
22
- kind(path: string): 'file' | 'folder' | null;
23
- lineCount(path: string): number;
24
- unresolved(value: string): {
25
- subject: string;
26
- reason: string;
27
- } | null;
28
- }
29
- export declare function checkAnchors(files: string[], app: string | null): AnchorsCheck;
package/dist/anchors.js DELETED
@@ -1,160 +0,0 @@
1
- // Source anchors held to the code they name (SPEC.md §9). Every `source:` that a graph file's schema gives as an anchor
2
- // names a file of the application's repository, from its root, and, with a line, a line within that file: one that
3
- // does not is an error (`source-unresolved`), as a need's evidence is (SPEC.md §13). A `path:line` written in a graph's
4
- // words (a description, a `say`, a note) is no anchor, but it cites the code all the same, so it is held to the code
5
- // too, as a warning (`citation-unresolved`): words are not parsed, so only a token that reads as a path from the
6
- // repository's root, a folder of the root first and a file with an extension last, is looked at. Under --no-app neither
7
- // is looked for, and only counted.
8
- import { existsSync, readFileSync, statSync } from 'node:fs';
9
- import { basename, dirname, isAbsolute, join } from 'node:path';
10
- import { anchorsIn, schemaKindOf } from './schemas.js';
11
- import { keyAt, readYaml } from './yaml.js';
12
- const FORMAT = 'delurio-graph/0';
13
- // the kinds whose files carry anchors; a need's evidence is held by its own rule, and a catalog holds the product's
14
- // words, which cite nothing
15
- const ANCHORED = new Set(['flow', 'ui', 'nav', 'domain']);
16
- const WORDED = new Set(['flow', 'ui', 'nav', 'domain', 'needs']);
17
- // what is data rather than words: sample values of the screens, records of an entity, the anchors themselves and a nav
18
- // graph's source; and in a needs file a need's evidence, which its own rule holds (a nav page's evidence is words)
19
- const NOT_WORDS = new Set(['samples', 'examples', 'source']);
20
- const NOT_NEEDS_WORDS = new Set([...NOT_WORDS, 'evidence']);
21
- const lineCount = (body) => body.split('\n').length - (body.endsWith('\n') ? 1 : 0);
22
- const pointer = (path) => path.map((s) => `/${s.replace(/~/g, '~0').replace(/\//g, '~1')}`).join('');
23
- // the files of the application, each looked up once per run: whether it is there and is a file, and its lines
24
- export class AppFiles {
25
- kinds = new Map();
26
- lines = new Map();
27
- root;
28
- constructor(root) {
29
- this.root = root;
30
- }
31
- abs(path) {
32
- return isAbsolute(path) ? path : join(this.root, path);
33
- }
34
- kind(path) {
35
- const abs = this.abs(path);
36
- if (!this.kinds.has(abs))
37
- this.kinds.set(abs, existsSync(abs) ? (statSync(abs).isFile() ? 'file' : 'folder') : null);
38
- return this.kinds.get(abs) ?? null;
39
- }
40
- lineCount(path) {
41
- const abs = this.abs(path);
42
- if (!this.lines.has(abs))
43
- this.lines.set(abs, lineCount(readFileSync(abs, 'utf8')));
44
- return this.lines.get(abs) ?? 0;
45
- }
46
- // why `<path>[:<line>]` names nothing under the root, or null when it names a file and a line within it: what is
47
- // wrong (the path, or the path and its line) and what is wrong with it
48
- unresolved(value) {
49
- const m = /^(.*?)(?::(\d+))?$/.exec(value);
50
- const kind = this.kind(m[1]);
51
- if (kind === null)
52
- return { subject: m[1], reason: 'does not exist' };
53
- if (kind === 'folder')
54
- return { subject: m[1], reason: 'is a folder: an anchor names a file' };
55
- if (m[2] === undefined)
56
- return null;
57
- const line = Number(m[2]);
58
- const n = this.lineCount(m[1]);
59
- if (line < 1)
60
- return { subject: value, reason: `names line ${line}: a file's lines count from 1` };
61
- return line > n ? { subject: value, reason: `is past the file's end: it has ${n} ${n === 1 ? 'line' : 'lines'}` } : null;
62
- }
63
- }
64
- // a token of words that reads as `<path>:<line>`: a folder, then a file with an extension, then the line, and a range's
65
- // last line after a dash; not inside an address, a longer path or a word
66
- const CITATION = /(?<![\p{L}\p{N}_.\/:@~+\-])((?:[\p{L}\p{N}_@.][\p{L}\p{N}_@.()[\]+\-]*\/)+[\p{L}\p{N}_@()[\]+\-.]*?\.[A-Za-z][A-Za-z0-9]*):(\d+)(?:-(\d+))?(?!\d)/gu;
67
- // the folder given as source.app by a nav graph, or by the nav.yaml beside a generated one, to say where an anchor
68
- // would have been had it been written from there
69
- function navApp(file, doc) {
70
- const own = doc.source?.app;
71
- if (typeof own === 'string')
72
- return own;
73
- const beside = join(dirname(file), 'nav.yaml');
74
- if (basename(file) === 'nav.yaml' || !existsSync(beside))
75
- return null;
76
- try {
77
- const app = (readYaml(readFileSync(beside, 'utf8'))?.source)?.app;
78
- return typeof app === 'string' ? app : null;
79
- }
80
- catch {
81
- return null;
82
- }
83
- }
84
- // every anchor and every citation in words of the graph files given, against the application's files under `app`;
85
- // with `app` null (--no-app), each is counted and none is looked for
86
- export function checkAnchors(files, app) {
87
- const out = { problems: [], anchors: 0, citations: 0 };
88
- const code = app === null ? null : new AppFiles(app);
89
- for (const file of files) {
90
- const kind = schemaKindOf(file);
91
- if (kind === null || !WORDED.has(kind))
92
- continue;
93
- let text;
94
- let doc;
95
- try {
96
- text = readFileSync(file, 'utf8');
97
- doc = readYaml(text);
98
- }
99
- catch {
100
- continue; // the schema rule, or the graph's load, says why
101
- }
102
- if (doc === null || typeof doc !== 'object' || Array.isArray(doc))
103
- continue;
104
- const own = doc;
105
- if (typeof own.schema === 'string' && own.schema !== FORMAT)
106
- continue;
107
- const graph = typeof own.id === 'string' ? own.id : basename(dirname(file));
108
- const name = basename(file);
109
- const problem = (rule, path, message, element) => {
110
- out.problems.push({ rule, file, ...keyAt(text, path), message, graph, element });
111
- };
112
- if (ANCHORED.has(kind)) {
113
- const navFrom = kind === 'nav' ? navApp(file, own) : null;
114
- for (const { path, value } of anchorsIn(kind, doc)) {
115
- if (!/^[^\s:]+(:[0-9]+)?$/.test(value))
116
- continue; // the schema rule says why
117
- out.anchors++;
118
- const why = code?.unresolved(value) ?? null;
119
- if (why === null)
120
- continue;
121
- const where = path.slice(0, -1).join('.') || 'the graph';
122
- const from = navFrom === null || code === null ? null : join(navFrom, value);
123
- const there = from !== null && code?.unresolved(from) === null ? `; ${from} is there: an anchor is written from the repository's root, not from source.app` : '';
124
- problem('source-unresolved', path, `${where}: source ${why.subject} ${why.reason}${there} (SPEC.md §9)`, `${name}#${pointer(path)}`);
125
- }
126
- }
127
- const skip = kind === 'needs' ? NOT_NEEDS_WORDS : NOT_WORDS;
128
- const words = (value, path) => {
129
- if (typeof value === 'string') {
130
- for (const m of value.matchAll(CITATION)) {
131
- const first = m[1].split('/')[0];
132
- if (first === '.' || first === '..')
133
- continue;
134
- if (code !== null && code.kind(first) !== 'folder')
135
- continue; // not a path from the repository's root
136
- out.citations++;
137
- if (code === null)
138
- continue;
139
- const line = Math.max(Number(m[2]), Number(m[3] ?? 0));
140
- const why = code.unresolved(`${m[1]}:${line}`);
141
- if (why === null)
142
- continue;
143
- const cited = m[0];
144
- const said = why.subject === m[1] ? `and ${why.subject} ${why.reason}` : `which ${why.reason}`;
145
- problem('citation-unresolved', path, `${path.join('.')} cites ${cited}, ${said} (SPEC.md §9)`, `${name}#${pointer(path)}/${cited}`);
146
- }
147
- return;
148
- }
149
- if (Array.isArray(value))
150
- value.forEach((x, i) => words(x, [...path, String(i)]));
151
- else if (value !== null && typeof value === 'object') {
152
- for (const [k, x] of Object.entries(value))
153
- if (!skip.has(k))
154
- words(x, [...path, k]);
155
- }
156
- };
157
- words(doc, []);
158
- }
159
- return out;
160
- }
package/dist/changes.d.ts DELETED
@@ -1,25 +0,0 @@
1
- import type { Graph } from './graph.ts';
2
- export interface DomainAction {
3
- route?: string;
4
- serverFn?: string;
5
- result?: {
6
- returns?: string;
7
- };
8
- sideEffects?: unknown[];
9
- }
10
- export interface Domain {
11
- id?: string;
12
- actions?: Record<string, DomainAction | null>;
13
- policies?: Array<{
14
- do?: string[];
15
- write?: string[];
16
- }>;
17
- }
18
- export interface ChangesCheck {
19
- writes: string[];
20
- key: string | null;
21
- missing: string | null;
22
- problems: string[];
23
- }
24
- export declare function flowDomain(g: Graph, seen?: Map<string, Domain | null>): Domain | null;
25
- export declare function checkChanges(g: Graph, domainOf?: () => Domain | null): ChangesCheck | null;
package/dist/changes.js DELETED
@@ -1,101 +0,0 @@
1
- // `changes:` in ui.yaml (SPEC.md §4): a flow whose steps write something tells its users, in its own note, what it
2
- // changes and what follows, or says why it has none yet (`missing`, a gap; decided on 16 Nov 2026, d-1116-11). An action writes when its route or its server function is not a GET, when a policy lets
3
- // someone `write` with it, or when it is a step inside the service (neither a route nor a server function) that returns
4
- // an entity; all three are read from the flow's domain, looked up by id among the graphs beside this one, all its files
5
- // read as one (SPEC.md §5). A GET that a policy lists is held to what it does: it writes only when one of its
6
- // `sideEffects` is more than an audit record of the call (`audit:<event>`), as a policy names reads and writes together
7
- // (SPEC.md §4, decided on 16 Nov 2026, d-1116-12). A flow with no screens, or whose domain is not found, is not checked.
8
- import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';
9
- import { basename, dirname, join } from 'node:path';
10
- import { inReadingOrder, isDomainText, mayBeDomain, mergeDomain } from './domain.js';
11
- const SKIP = new Set(['viz', 'video', 'node_modules', '.git']);
12
- // the root to search: the nearest folder called `graphs` above the graph, else the graph's parent
13
- function rootOf(dir) {
14
- for (let d = dir, i = 0; i < 5; i++, d = dirname(d))
15
- if (basename(d) === 'graphs')
16
- return d;
17
- return dirname(dir);
18
- }
19
- function domainUnder(root, id, depth = 4) {
20
- const names = readdirSync(root);
21
- const parts = inReadingOrder(names.filter((name) => mayBeDomain(name) && statSync(join(root, name)).isFile()))
22
- .map((name) => ({ file: join(root, name), text: readFileSync(join(root, name), 'utf8') }))
23
- .filter((p) => isDomainText(p.text));
24
- if (parts.length > 0) {
25
- const merged = mergeDomain(parts);
26
- if (merged.id === id)
27
- return merged.doc;
28
- }
29
- if (depth === 0)
30
- return null;
31
- for (const name of names) {
32
- if (SKIP.has(name))
33
- continue;
34
- const sub = join(root, name);
35
- if (!statSync(sub).isDirectory())
36
- continue;
37
- const found = domainUnder(sub, id, depth - 1);
38
- if (found !== null)
39
- return found;
40
- }
41
- return null;
42
- }
43
- // the domain the flow names, looked up by id among the graphs beside it; null when it names none or it is not found.
44
- // `seen` keeps what a run has found, so that the flows that name one domain look it up once
45
- export function flowDomain(g, seen) {
46
- if (g.flow.domain === undefined)
47
- return null;
48
- const root = rootOf(g.dir);
49
- const key = `${root}\0${g.flow.domain}`;
50
- if (seen?.has(key) === true)
51
- return structuredClone(seen.get(key));
52
- const found = domainUnder(root, g.flow.domain);
53
- seen?.set(key, found);
54
- return seen === undefined ? found : structuredClone(found);
55
- }
56
- // the HTTP method of an action's route or server function; undefined for a step inside the service
57
- const methodOf = (a) => (a?.route ?? a?.serverFn)?.trim().split(/\s+/)[0]?.toUpperCase();
58
- // a side effect that records the call and changes nothing the flow's users are told of: `audit:<event>` (SPEC.md §5)
59
- const isAudit = (s) => typeof s === 'string' && s.trimStart().startsWith('audit:');
60
- // a GET that a writing policy lists writes only when it does more than record that it was called: a policy names its
61
- // actor's reads and writes together, and a GET reads (SPEC.md §4)
62
- const writesThroughPolicy = (a) => methodOf(a) !== 'GET' || (Array.isArray(a?.sideEffects) && a.sideEffects.some((s) => !isAudit(s)));
63
- // `domainOf` finds the flow's domain, called at most once: a caller that reads the domain for another rule as well
64
- // hands over the one it found
65
- export function checkChanges(g, domainOf = () => flowDomain(g)) {
66
- if (g.ui.absent === true)
67
- return null;
68
- const domain = domainOf();
69
- if (domain === null)
70
- return null;
71
- const writing = new Set();
72
- for (const [name, a] of Object.entries(domain.actions ?? {})) {
73
- const method = methodOf(a);
74
- if ((method !== undefined && method !== 'GET') || (method === undefined && a?.result?.returns !== undefined))
75
- writing.add(name);
76
- }
77
- for (const p of domain.policies ?? [])
78
- if ((p.write ?? []).length > 0)
79
- for (const name of p.do ?? [])
80
- if (writesThroughPolicy(domain.actions?.[name]))
81
- writing.add(name);
82
- const invoked = Object.values(g.flow.states).map((s) => s.invoke?.action);
83
- const writes = [...new Set(invoked.filter((a) => a !== undefined && writing.has(a)))].sort();
84
- const key = g.ui.changes?.key ?? null;
85
- const said = g.ui.changes?.missing;
86
- // the note a writing flow says it has no message for yet; a flow that writes nothing is missing none
87
- const missing = writes.length > 0 && key === null && typeof said === 'string' && said.trim() !== '' ? said.trim() : null;
88
- const problems = [];
89
- if (writes.length > 0 && key === null && missing === null)
90
- problems.push(`its steps write (${writes.join(', ')}), but ui.yaml has no changes note (SPEC.md §4)`);
91
- if (key !== null) {
92
- for (const locale of g.ui.locales ?? [basename(g.ui.catalog, '.json')]) {
93
- const file = join(g.dir, dirname(g.ui.catalog), `${locale}.json`);
94
- const catalog = existsSync(file) ? JSON.parse(readFileSync(file, 'utf8')) : null;
95
- const note = catalog?.[key];
96
- if (typeof note !== 'string' || note.trim() === '')
97
- problems.push(`the changes note ${key} is not in the ${locale} catalog`);
98
- }
99
- }
100
- return { writes, key, missing, problems };
101
- }
package/dist/check.d.ts DELETED
@@ -1,23 +0,0 @@
1
- export declare const CHECK_USAGE: string;
2
- type Level = 'error' | 'warning' | 'note';
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 {};