@delurio/cli 0.8.0 → 0.10.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 +51 -0
- package/README.md +37 -6
- package/SPEC.md +203 -34
- package/dist/anchors.d.ts +29 -0
- package/dist/anchors.js +160 -0
- package/dist/changes.d.ts +4 -2
- package/dist/changes.js +32 -10
- package/dist/check.d.ts +1 -1
- package/dist/check.js +288 -32
- package/dist/diff-nav.js +15 -5
- package/dist/domain-names.d.ts +18 -0
- package/dist/domain-names.js +124 -0
- package/dist/domain.js +1 -1
- package/dist/graph.d.ts +21 -2
- package/dist/graph.js +149 -30
- package/dist/html.d.ts +1 -1
- package/dist/html.js +1 -1
- package/dist/invokes.d.ts +10 -0
- package/dist/invokes.js +67 -0
- package/dist/kit.d.ts +2 -1
- package/dist/kit.js +3 -2
- package/dist/model.d.ts +9 -1
- package/dist/model.js +89 -33
- package/dist/nav-page.js +15 -3
- package/dist/nav.d.ts +20 -1
- package/dist/nav.js +37 -25
- package/dist/needs.d.ts +51 -0
- package/dist/needs.js +335 -0
- package/dist/schemas.d.ts +6 -1
- package/dist/schemas.js +54 -2
- package/dist/starts.js +8 -1
- package/dist/tutorial-check.d.ts +9 -0
- package/dist/tutorial-check.js +297 -0
- package/dist/ui-check.d.ts +1 -1
- package/dist/ui-check.js +64 -13
- package/dist/wireframe.d.ts +2 -0
- package/dist/wireframe.js +31 -4
- package/dist/yaml.d.ts +1 -0
- package/dist/yaml.js +36 -5
- package/package.json +5 -4
- package/schemas/domain.schema.json +10 -7
- package/schemas/gaps.schema.json +49 -0
- package/schemas/nav.schema.json +34 -3
- package/schemas/needs.schema.json +189 -0
- package/schemas/ui.schema.json +42 -9
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
// The names a domain gives one another (SPEC.md §5), each held to what the domain has, all its files read as one: an
|
|
2
|
+
// action's `returns` and every `references` (on an entity's field, or in a body, a query, a result or a refusal's body)
|
|
3
|
+
// name an entity; an entity's `key` and `required` name its own fields; a policy's `do` names actions, and its `read`
|
|
4
|
+
// and `write` entities. A name that the domain does not have is an error, as a flow's `invoke` names are (decided on
|
|
5
|
+
// 16 Nov 2026, d-1116-10). Each finding is given in the file that gives the name, at its line, with a note where another
|
|
6
|
+
// domain beside it has the entity: a domain names only its own, and one domain may be split across files instead.
|
|
7
|
+
import { readYaml, keyAt } from './yaml.js';
|
|
8
|
+
const isObject = (v) => v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
9
|
+
// the keywords of JSON Schema 2020-12 whose value is a schema, a list of schemas, or schemas by name; a value of any
|
|
10
|
+
// other keyword (`examples`, `default`, `const`, `enum`) is data, never read for `references`
|
|
11
|
+
const ONE = ['items', 'contains', 'not', 'if', 'then', 'else', 'additionalProperties', 'propertyNames', 'unevaluatedItems', 'unevaluatedProperties', 'contentSchema'];
|
|
12
|
+
const LIST = ['allOf', 'anyOf', 'oneOf', 'prefixItems'];
|
|
13
|
+
const BY_NAME = ['properties', 'patternProperties', '$defs', 'dependentSchemas'];
|
|
14
|
+
// every `references` in a schema, with the path to the schema that gives it
|
|
15
|
+
function referencesIn(schema, path, out = []) {
|
|
16
|
+
if (!isObject(schema))
|
|
17
|
+
return out;
|
|
18
|
+
if (schema.references !== undefined)
|
|
19
|
+
out.push({ path, name: schema.references });
|
|
20
|
+
for (const k of ONE)
|
|
21
|
+
referencesIn(schema[k], [...path, k], out);
|
|
22
|
+
for (const k of LIST)
|
|
23
|
+
if (Array.isArray(schema[k]))
|
|
24
|
+
schema[k].forEach((s, i) => referencesIn(s, [...path, k, String(i)], out));
|
|
25
|
+
for (const k of BY_NAME)
|
|
26
|
+
if (isObject(schema[k]))
|
|
27
|
+
for (const [name, s] of Object.entries(schema[k]))
|
|
28
|
+
referencesIn(s, [...path, k, name], out);
|
|
29
|
+
return out;
|
|
30
|
+
}
|
|
31
|
+
// a schema's path inside the value it sits in, for a message: properties.address.properties.city -> address.city
|
|
32
|
+
const inside = (path) => path.map((s, i) => (path[i - 1] === 'properties' ? s : s === 'properties' ? '' : s)).filter((s) => s !== '').join('.');
|
|
33
|
+
// `doc` is the domain's files read as one (mergeDomain); `parts` the files, each read again here for where it gives a name
|
|
34
|
+
export function checkDomainNames(parts, doc, id, elsewhere = () => null) {
|
|
35
|
+
const entities = isObject(doc.entities) ? doc.entities : {};
|
|
36
|
+
const actions = isObject(doc.actions) ? doc.actions : {};
|
|
37
|
+
const isEntity = (name) => Object.hasOwn(entities, name);
|
|
38
|
+
const isAction = (name) => Object.hasOwn(actions, name);
|
|
39
|
+
const fieldsOf = (entity) => {
|
|
40
|
+
const e = entities[entity];
|
|
41
|
+
return isObject(e) && isObject(e.fields) ? e.fields : null;
|
|
42
|
+
};
|
|
43
|
+
const out = [];
|
|
44
|
+
for (const part of parts) {
|
|
45
|
+
let data;
|
|
46
|
+
try {
|
|
47
|
+
data = readYaml(part.text);
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
// a file that is not a map, or is another domain's (domain-place), is no part of this one
|
|
53
|
+
if (!isObject(data) || (typeof data.id === 'string' && data.id !== id))
|
|
54
|
+
continue;
|
|
55
|
+
const at = (rule, path, message, element, entity) => {
|
|
56
|
+
const other = entity === undefined ? null : elsewhere(entity);
|
|
57
|
+
const notes = other === null ? [] : [{ file: other.file, line: other.line, column: other.column, message: `${entity} is an entity of the domain ${other.domain}: a domain names only its own entities, and one domain may be split across the files of its directory (SPEC.md §5)` }];
|
|
58
|
+
out.push({ rule, file: part.file, ...keyAt(part.text, path), message, element, notes });
|
|
59
|
+
};
|
|
60
|
+
const references = (schema, path, where) => {
|
|
61
|
+
for (const r of referencesIn(schema, path)) {
|
|
62
|
+
if (typeof r.name !== 'string' || isEntity(r.name))
|
|
63
|
+
continue;
|
|
64
|
+
const rest = inside(r.path.slice(path.length));
|
|
65
|
+
at('entity-unknown', [...r.path, 'references'], `${where(rest)} references ${r.name}, which is not an entity of the domain ${id} (SPEC.md §5)`, `${r.path.join('/')}/references`, r.name);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
for (const [entity, e] of Object.entries(isObject(data.entities) ? data.entities : {})) {
|
|
69
|
+
if (!isObject(e))
|
|
70
|
+
continue;
|
|
71
|
+
// an entity whose fields no file gives yet is not held to them
|
|
72
|
+
const fields = fieldsOf(entity);
|
|
73
|
+
for (const key of ['key', 'required']) {
|
|
74
|
+
if (fields === null || !Array.isArray(e[key]))
|
|
75
|
+
continue;
|
|
76
|
+
e[key].forEach((name, i) => {
|
|
77
|
+
if (typeof name !== 'string' || Object.hasOwn(fields, name))
|
|
78
|
+
return;
|
|
79
|
+
const said = key === 'key' ? `the key of the entity ${entity} names ${name}` : `the entity ${entity} requires ${name}`;
|
|
80
|
+
at('field-unknown', ['entities', entity, key, String(i)], `${said}, which is not one of its fields (SPEC.md §5)`, `entities/${entity}/${key}/${name}`);
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
for (const [field, schema] of Object.entries(isObject(e.fields) ? e.fields : {})) {
|
|
84
|
+
references(schema, ['entities', entity, 'fields', field], (rest) => `the field ${entity}.${field}${rest === '' ? '' : `, at ${rest},`}`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
for (const [action, a] of Object.entries(isObject(data.actions) ? data.actions : {})) {
|
|
88
|
+
if (!isObject(a))
|
|
89
|
+
continue;
|
|
90
|
+
const result = a.result;
|
|
91
|
+
if (isObject(result) && typeof result.returns === 'string' && !isEntity(result.returns)) {
|
|
92
|
+
at('entity-unknown', ['actions', action, 'result', 'returns'], `the action ${action} returns ${result.returns}, which is not an entity of the domain ${id} (SPEC.md §5)`, `actions/${action}/result/returns`, result.returns);
|
|
93
|
+
}
|
|
94
|
+
for (const section of ['query', 'body', 'result']) {
|
|
95
|
+
references(a[section], ['actions', action, section], (rest) => `the ${section} of the action ${action}${rest === '' ? '' : `, at ${rest},`}`);
|
|
96
|
+
}
|
|
97
|
+
for (const [code, r] of Object.entries(isObject(a.refusals) ? a.refusals : {})) {
|
|
98
|
+
if (isObject(r))
|
|
99
|
+
references(r.body, ['actions', action, 'refusals', code, 'body'], (rest) => `the body of the refusal ${code} of the action ${action}${rest === '' ? '' : `, at ${rest},`}`);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
// the policies of this file, by their place in it; the element names the policy by its actor, as the list's order
|
|
103
|
+
// across files is no part of what it is
|
|
104
|
+
(Array.isArray(data.policies) ? data.policies : []).forEach((p, i) => {
|
|
105
|
+
if (!isObject(p))
|
|
106
|
+
return;
|
|
107
|
+
const actor = typeof p.actor === 'string' ? p.actor : String(i);
|
|
108
|
+
for (const key of ['do', 'read', 'write']) {
|
|
109
|
+
if (!Array.isArray(p[key]))
|
|
110
|
+
continue;
|
|
111
|
+
p[key].forEach((name, j) => {
|
|
112
|
+
if (typeof name !== 'string')
|
|
113
|
+
return;
|
|
114
|
+
const known = key === 'do' ? isAction(name) : isEntity(name);
|
|
115
|
+
if (known)
|
|
116
|
+
return;
|
|
117
|
+
const what = key === 'do' ? 'an action' : 'an entity';
|
|
118
|
+
at('policy-unknown', ['policies', String(i), key, String(j)], `the policy for ${actor} names ${name} in ${key}, which is not ${what} of the domain ${id} (SPEC.md §5)`, `policies/${actor}/${key}/${name}`, key === 'do' ? undefined : name);
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
return out;
|
|
124
|
+
}
|
package/dist/domain.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
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
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
|
-
export const OTHER_KINDS = new Set(['flow.yaml', 'ui.yaml', 'nav.yaml', 'nav.extracted.yaml', 'binding.yaml', 'tutorial.yaml', 'kit.yaml', 'anchors.lock.yaml']);
|
|
7
|
+
export const OTHER_KINDS = new Set(['flow.yaml', 'ui.yaml', 'nav.yaml', 'nav.extracted.yaml', 'binding.yaml', 'tutorial.yaml', 'kit.yaml', 'needs.yaml', 'needs.gaps.yaml', 'anchors.lock.yaml']);
|
|
8
8
|
const OWN = new Set(['schema', 'kind', 'id']);
|
|
9
9
|
const JOINED = new Set(['policies', 'invariants']);
|
|
10
10
|
// a file that may be part of a domain, by its name
|
package/dist/graph.d.ts
CHANGED
|
@@ -92,6 +92,7 @@ export interface UiNode {
|
|
|
92
92
|
unless?: string[];
|
|
93
93
|
when?: string;
|
|
94
94
|
disabledIn?: string[];
|
|
95
|
+
disabledWhen?: string;
|
|
95
96
|
emits?: string;
|
|
96
97
|
initialFocus?: string;
|
|
97
98
|
repeat?: string;
|
|
@@ -104,8 +105,9 @@ export interface UiNode {
|
|
|
104
105
|
export interface UiEdge {
|
|
105
106
|
labelledBy?: [string, string];
|
|
106
107
|
triggers?: [string, string];
|
|
107
|
-
returnsFocus?: [string, string];
|
|
108
|
+
returnsFocus?: [string, string | string[]];
|
|
108
109
|
}
|
|
110
|
+
export declare const OPENER = "opener";
|
|
109
111
|
export declare const CHECKABLE: readonly ['checkbox', 'menuitemcheckbox', 'menuitemradio', 'option', 'radio', 'switch'];
|
|
110
112
|
export declare const isDialog: (n: UiNode | undefined) => boolean;
|
|
111
113
|
export interface Ui {
|
|
@@ -118,6 +120,13 @@ export interface Ui {
|
|
|
118
120
|
locales?: string[];
|
|
119
121
|
changes?: {
|
|
120
122
|
key: string;
|
|
123
|
+
missing?: undefined;
|
|
124
|
+
} | {
|
|
125
|
+
missing: string;
|
|
126
|
+
key?: undefined;
|
|
127
|
+
};
|
|
128
|
+
task?: {
|
|
129
|
+
key: string;
|
|
121
130
|
};
|
|
122
131
|
focus?: Record<string, string>;
|
|
123
132
|
edges?: UiEdge[];
|
|
@@ -128,8 +137,18 @@ export interface Graph {
|
|
|
128
137
|
ui: Ui;
|
|
129
138
|
catalog: Record<string, string>;
|
|
130
139
|
}
|
|
140
|
+
export interface ErrorPlace {
|
|
141
|
+
file: string;
|
|
142
|
+
path?: string[];
|
|
143
|
+
line?: number;
|
|
144
|
+
column?: number;
|
|
145
|
+
}
|
|
131
146
|
export declare class GraphError extends Error {
|
|
147
|
+
readonly place: ErrorPlace | undefined;
|
|
148
|
+
constructor(message: string, place?: ErrorPlace);
|
|
132
149
|
}
|
|
150
|
+
export declare function placed<E>(err: E, place: ErrorPlace): E;
|
|
151
|
+
export declare function transitionPath(state: string, st: State, event: string | null, i: number): string[];
|
|
133
152
|
export declare function humanize(id: string): string;
|
|
134
153
|
export declare function titleOf(flow: Flow, state: string): string;
|
|
135
154
|
export declare function shownIn(n: UiNode, state: string): boolean;
|
|
@@ -138,6 +157,6 @@ export interface FocusAfter {
|
|
|
138
157
|
by: 'returnsFocus' | 'initialFocus' | 'focus';
|
|
139
158
|
from?: string;
|
|
140
159
|
}
|
|
141
|
-
export declare function focusAfter(ui: Ui, from: string | null, to: string): FocusAfter | null;
|
|
160
|
+
export declare function focusAfter(ui: Ui, from: string | null, to: string, pressed?: string): FocusAfter | null;
|
|
142
161
|
export declare function alternatives(spec: TransitionSpec): Transition[];
|
|
143
162
|
export declare function load(dir: string, read?: (file: string) => string, exists?: (file: string) => boolean): Graph;
|
package/dist/graph.js
CHANGED
|
@@ -1,12 +1,72 @@
|
|
|
1
1
|
import { existsSync, readFileSync } from 'node:fs';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
|
-
import { readYaml } from './yaml.js';
|
|
3
|
+
import { lineAndColumn, readYaml } from './yaml.js';
|
|
4
4
|
import { identifiers, parseExpr } from './expr.js';
|
|
5
|
+
// in a returnsFocus, the node that was pressed to open the dialog, whichever it is (SPEC.md §4); no node is called so
|
|
6
|
+
export const OPENER = 'opener';
|
|
5
7
|
// the roles whose node may say whether it is `checked` (WAI-ARIA 1.2: the roles that support aria-checked)
|
|
6
8
|
export const CHECKABLE = ['checkbox', 'menuitemcheckbox', 'menuitemradio', 'option', 'radio', 'switch'];
|
|
7
9
|
// a page node drawn over another page, whose closing `returnsFocus` may give the focus back (SPEC.md §4)
|
|
8
10
|
export const isDialog = (n) => n?.type === 'page' && (n.role === 'dialog' || n.role === 'alertdialog');
|
|
9
11
|
export class GraphError extends Error {
|
|
12
|
+
place;
|
|
13
|
+
constructor(message, place) {
|
|
14
|
+
super(message);
|
|
15
|
+
this.place = place;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
// the place of an error that a reader of the graph's files threw, given to it when it has none yet: a YAML error of
|
|
19
|
+
// ui.yaml then says it is in ui.yaml, and the line the parser gave is kept
|
|
20
|
+
export function placed(err, place) {
|
|
21
|
+
if (err instanceof Error && err.place === undefined)
|
|
22
|
+
Object.assign(err, { place });
|
|
23
|
+
return err;
|
|
24
|
+
}
|
|
25
|
+
// the file a graph names, read as YAML, a YAML error carrying the file it is in
|
|
26
|
+
function readGraphFile(read, file) {
|
|
27
|
+
try {
|
|
28
|
+
return readYaml(read(file));
|
|
29
|
+
}
|
|
30
|
+
catch (err) {
|
|
31
|
+
throw placed(err, { file });
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
const isMapValue = (v) => v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
35
|
+
// the place of a transition in flow.yaml: `on.<event>`, the item of a list of alternatives, or an item of `always`
|
|
36
|
+
export function transitionPath(state, st, event, i) {
|
|
37
|
+
if (event === null)
|
|
38
|
+
return ['states', state, 'always', String(i)];
|
|
39
|
+
return Array.isArray(st.on?.[event]) ? ['states', state, 'on', event, String(i)] : ['states', state, 'on', event];
|
|
40
|
+
}
|
|
41
|
+
// a catalog: a JSON object, read from the file ui.yaml names; one that is not there, or is not JSON, keeps the graph
|
|
42
|
+
// from loading, at the place that names it or at the place the JSON parser gave
|
|
43
|
+
function readCatalog(read, exists, ui) {
|
|
44
|
+
if (typeof ui.catalog !== 'string' || ui.catalog === '') {
|
|
45
|
+
throw new GraphError('ui.yaml names no catalog: it gives the words of its screens as catalog: catalog/<locale>.json (SPEC.md §4)', { file: 'ui.yaml', path: [] });
|
|
46
|
+
}
|
|
47
|
+
if (!exists(ui.catalog))
|
|
48
|
+
throw new GraphError(`the catalog ${ui.catalog} that ui.yaml names does not exist`, { file: 'ui.yaml', path: ['catalog'] });
|
|
49
|
+
let text;
|
|
50
|
+
try {
|
|
51
|
+
text = read(ui.catalog);
|
|
52
|
+
}
|
|
53
|
+
catch (err) {
|
|
54
|
+
throw new GraphError(`the catalog ${ui.catalog} that ui.yaml names cannot be read: ${err.message}`, { file: 'ui.yaml', path: ['catalog'] });
|
|
55
|
+
}
|
|
56
|
+
try {
|
|
57
|
+
return JSON.parse(text);
|
|
58
|
+
}
|
|
59
|
+
catch (err) {
|
|
60
|
+
const message = err.message;
|
|
61
|
+
const at = /line (\d+) column (\d+)/.exec(message);
|
|
62
|
+
const offset = /position (\d+)/.exec(message);
|
|
63
|
+
const place = { file: ui.catalog };
|
|
64
|
+
if (at !== null)
|
|
65
|
+
Object.assign(place, { line: Number(at[1]), column: Number(at[2]) });
|
|
66
|
+
else if (offset !== null)
|
|
67
|
+
Object.assign(place, lineAndColumn(text, Number(offset[1])));
|
|
68
|
+
throw new GraphError(`the catalog ${ui.catalog} is not JSON: ${message}`, place);
|
|
69
|
+
}
|
|
10
70
|
}
|
|
11
71
|
// 'silentRedirect' -> 'silent redirect'; used only when the graph gives no title
|
|
12
72
|
export function humanize(id) {
|
|
@@ -23,18 +83,37 @@ export function shownIn(n, state) {
|
|
|
23
83
|
// The node that has focus once the flow has moved from the state `from` (null when it starts) into another state `to`,
|
|
24
84
|
// both states the flow stops in (SPEC.md §4, Focus): a dialog that closes gives it back to its `returnsFocus` node when
|
|
25
85
|
// `to` shows that node; else a page that opens gives it to its `initialFocus`, a dialog's before the page it covers;
|
|
26
|
-
// else `focus.<to>`. null when the graph does not say, and on a move from a state to itself.
|
|
27
|
-
|
|
86
|
+
// else `focus.<to>`. null when the graph does not say, and on a move from a state to itself. `pressed` is the node that
|
|
87
|
+
// was pressed to open the dialog, which a replay knows and the graph does not: a returnsFocus that lists several
|
|
88
|
+
// nodes, or says OPENER, gives the focus to it. Without it, a list gives the one node of it that `to` shows, and
|
|
89
|
+
// OPENER, or a list of which `to` shows several, gives null.
|
|
90
|
+
export function focusAfter(ui, from, to, pressed) {
|
|
28
91
|
if (from === to)
|
|
29
92
|
return null;
|
|
30
93
|
const nodes = ui.nodes;
|
|
31
94
|
const shown = (id, state) => state !== null && nodes[id] !== undefined && shownIn(nodes[id], state);
|
|
32
95
|
for (const e of ui.edges ?? []) {
|
|
33
|
-
const [dialog,
|
|
34
|
-
if (dialog === undefined ||
|
|
96
|
+
const [dialog, target] = e.returnsFocus ?? [];
|
|
97
|
+
if (dialog === undefined || target === undefined || !isDialog(nodes[dialog]))
|
|
35
98
|
continue;
|
|
36
|
-
if (shown(dialog, from)
|
|
37
|
-
|
|
99
|
+
if (!shown(dialog, from) || shown(dialog, to))
|
|
100
|
+
continue;
|
|
101
|
+
if (typeof target === 'string' && target !== OPENER) {
|
|
102
|
+
if (shown(target, to))
|
|
103
|
+
return { node: target, by: 'returnsFocus', from: dialog };
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
// the node that opened the dialog: the one pressed, when the caller knows it, among those a list allows
|
|
107
|
+
const allowed = (id) => target === OPENER || (Array.isArray(target) && target.includes(id));
|
|
108
|
+
if (pressed !== undefined) {
|
|
109
|
+
if (allowed(pressed) && shown(pressed, to))
|
|
110
|
+
return { node: pressed, by: 'returnsFocus', from: dialog };
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
const candidates = Array.isArray(target) ? target.filter((id) => shown(id, to)) : [];
|
|
114
|
+
if (candidates.length === 1)
|
|
115
|
+
return { node: candidates[0], by: 'returnsFocus', from: dialog };
|
|
116
|
+
return null;
|
|
38
117
|
}
|
|
39
118
|
const opened = Object.entries(nodes).filter(([id, n]) => n.type === 'page' && n.initialFocus !== undefined && shown(id, to) && !shown(id, from));
|
|
40
119
|
const page = opened.find(([, n]) => isDialog(n)) ?? opened[0];
|
|
@@ -49,69 +128,109 @@ export function alternatives(spec) {
|
|
|
49
128
|
}
|
|
50
129
|
// `read` and `exists` take a path relative to `dir`; the revision diff passes ones that read a git revision instead of the disk
|
|
51
130
|
export function load(dir, read = (file) => readFileSync(join(dir, file), 'utf8'), exists = (file) => existsSync(join(dir, file))) {
|
|
52
|
-
const flow =
|
|
131
|
+
const flow = readGraphFile(read, 'flow.yaml');
|
|
132
|
+
if (!isMapValue(flow))
|
|
133
|
+
throw new GraphError('flow.yaml is not a map of keys (SPEC.md §2)', { file: 'flow.yaml', path: [] });
|
|
134
|
+
if (!isMapValue(flow.states))
|
|
135
|
+
throw new GraphError('flow.yaml has no states: a flow gives them as states: { <state>: { .. } } (SPEC.md §2)', { file: 'flow.yaml', path: ['states'] });
|
|
53
136
|
// a flow with no context, guards or effects leaves the key out; every reader expects an object
|
|
54
137
|
flow.context ??= {};
|
|
55
138
|
flow.guards ??= {};
|
|
56
139
|
flow.effects ??= {};
|
|
57
140
|
// a flow with no screens (an endpoint, a webhook, a CI job) has no ui.yaml and no catalog
|
|
58
|
-
const ui = exists('ui.yaml') ?
|
|
59
|
-
|
|
141
|
+
const ui = exists('ui.yaml') ? readGraphFile(read, 'ui.yaml') : { absent: true, id: flow.id, catalog: '', samples: {}, nodes: {} };
|
|
142
|
+
if (!isMapValue(ui))
|
|
143
|
+
throw new GraphError('ui.yaml is not a map of keys (SPEC.md §4)', { file: 'ui.yaml', path: [] });
|
|
144
|
+
ui.nodes ??= {};
|
|
145
|
+
ui.samples ??= {};
|
|
146
|
+
const catalog = ui.absent === true ? {} : readCatalog(read, exists, ui);
|
|
60
147
|
if (flow.states[flow.initial] === undefined)
|
|
61
|
-
throw new GraphError(`initial state ${flow.initial} does not exist
|
|
148
|
+
throw new GraphError(`initial state ${flow.initial} does not exist`, { file: 'flow.yaml', path: ['initial'] });
|
|
62
149
|
for (const [name, st] of Object.entries(flow.states)) {
|
|
150
|
+
if (!isMapValue(st))
|
|
151
|
+
throw new GraphError(`state ${name} is not a map of keys: write it as ${name}: { .. } (SPEC.md §2)`, { file: 'flow.yaml', path: ['states', name] });
|
|
63
152
|
if (st.states !== undefined || st.type === 'parallel' || st.type === 'history') {
|
|
64
|
-
throw new GraphError(`state ${name}: nested, parallel and history states are not supported by graph-viz yet
|
|
153
|
+
throw new GraphError(`state ${name}: nested, parallel and history states are not supported by graph-viz yet`, { file: 'flow.yaml', path: ['states', name, st.states !== undefined ? 'states' : 'type'] });
|
|
65
154
|
}
|
|
66
|
-
const
|
|
67
|
-
...(st.always ?? []).map((a) => a
|
|
68
|
-
...Object.
|
|
155
|
+
const ways = [
|
|
156
|
+
...(st.always ?? []).map((a, i) => [null, i, a]),
|
|
157
|
+
...Object.entries(st.on ?? {}).flatMap(([event, spec]) => alternatives(spec).map((a, i) => [event, i, a])),
|
|
69
158
|
];
|
|
70
|
-
for (const
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
const ways = [...(st.always ?? []), ...Object.values(st.on ?? {}).flatMap((spec) => alternatives(spec))];
|
|
75
|
-
for (const w of ways) {
|
|
159
|
+
for (const [event, i, w] of ways) {
|
|
160
|
+
const path = transitionPath(name, st, event, i);
|
|
161
|
+
if (flow.states[w.target] === undefined)
|
|
162
|
+
throw new GraphError(`state ${name} goes to ${w.target}, which does not exist`, { file: 'flow.yaml', path });
|
|
76
163
|
if (w.starts === undefined)
|
|
77
164
|
continue;
|
|
78
165
|
if (typeof w.starts.flow !== 'string')
|
|
79
|
-
throw new GraphError(`state ${name}: \`starts\` names no flow
|
|
166
|
+
throw new GraphError(`state ${name}: \`starts\` names no flow`, { file: 'flow.yaml', path: [...path, 'starts'] });
|
|
80
167
|
for (const [k, v] of Object.entries(w.starts.given ?? {})) {
|
|
81
168
|
if (typeof v !== 'string')
|
|
82
169
|
continue;
|
|
83
|
-
|
|
170
|
+
const at = { file: 'flow.yaml', path: [...path, 'starts', 'given', k] };
|
|
171
|
+
let names;
|
|
172
|
+
try {
|
|
173
|
+
names = identifiers(parseExpr(v));
|
|
174
|
+
}
|
|
175
|
+
catch (err) {
|
|
176
|
+
throw new GraphError(`state ${name} starts ${w.starts.flow} with ${k} = ${v}: ${err.message}`, at);
|
|
177
|
+
}
|
|
178
|
+
for (const id of names) {
|
|
84
179
|
if (id !== 'state' && flow.context[id] === undefined && flow.guards[id] === undefined) {
|
|
85
|
-
throw new GraphError(`state ${name} starts ${w.starts.flow} with ${k} = ${v}: ${id} is not a variable or a guard of this flow (a value is quoted: '${id}')
|
|
180
|
+
throw new GraphError(`state ${name} starts ${w.starts.flow} with ${k} = ${v}: ${id} is not a variable or a guard of this flow (a value is quoted: '${id}')`, at);
|
|
86
181
|
}
|
|
87
182
|
}
|
|
88
183
|
}
|
|
89
184
|
}
|
|
90
185
|
}
|
|
91
186
|
for (const [id, node] of Object.entries(ui.nodes)) {
|
|
92
|
-
for (const
|
|
93
|
-
|
|
94
|
-
|
|
187
|
+
for (const key of ['in', 'unless', 'disabledIn']) {
|
|
188
|
+
(node[key] ?? []).forEach((s, i) => {
|
|
189
|
+
if (flow.states[s] === undefined)
|
|
190
|
+
throw new GraphError(`ui node ${id} names the unknown state ${s}`, { file: 'ui.yaml', path: ['nodes', id, key, String(i)] });
|
|
191
|
+
});
|
|
95
192
|
}
|
|
96
193
|
// `checked` is an expression over the context (SPEC.md §3), read when the node is shown
|
|
97
194
|
if (typeof node.checked === 'string') {
|
|
195
|
+
const at = { file: 'ui.yaml', path: ['nodes', id, 'checked'] };
|
|
98
196
|
let names;
|
|
99
197
|
try {
|
|
100
198
|
names = identifiers(parseExpr(node.checked));
|
|
101
199
|
}
|
|
102
200
|
catch (err) {
|
|
103
|
-
throw new GraphError(`ui node ${id}: checked: ${err.message}
|
|
201
|
+
throw new GraphError(`ui node ${id}: checked: ${err.message}`, at);
|
|
104
202
|
}
|
|
105
203
|
for (const n of names) {
|
|
106
204
|
if (n !== 'state' && flow.context[n] === undefined && flow.guards[n] === undefined) {
|
|
107
|
-
throw new GraphError(`ui node ${id}: checked: ${node.checked} names ${n}, which is not a variable or a guard of the flow
|
|
205
|
+
throw new GraphError(`ui node ${id}: checked: ${node.checked} names ${n}, which is not a variable or a guard of the flow`, at);
|
|
108
206
|
}
|
|
109
207
|
}
|
|
110
208
|
}
|
|
111
209
|
}
|
|
112
210
|
for (const s of Object.keys(ui.focus ?? {})) {
|
|
113
211
|
if (flow.states[s] === undefined)
|
|
114
|
-
throw new GraphError(`ui focus names the unknown state ${s}
|
|
212
|
+
throw new GraphError(`ui focus names the unknown state ${s}`, { file: 'ui.yaml', path: ['focus', s] });
|
|
115
213
|
}
|
|
214
|
+
disabledWhenReads(flow, ui);
|
|
116
215
|
return { dir, flow, ui, catalog };
|
|
117
216
|
}
|
|
217
|
+
// a node's `disabledWhen` is an expression over the context (SPEC.md §3, §4), read where the node is shown: one that
|
|
218
|
+
// does not parse, or names what is not a variable, a guard or `state`, keeps the graph from loading, as `checked` does
|
|
219
|
+
function disabledWhenReads(flow, ui) {
|
|
220
|
+
for (const [id, node] of Object.entries(ui.nodes)) {
|
|
221
|
+
if (typeof node.disabledWhen !== 'string')
|
|
222
|
+
continue;
|
|
223
|
+
let names;
|
|
224
|
+
try {
|
|
225
|
+
names = identifiers(parseExpr(node.disabledWhen));
|
|
226
|
+
}
|
|
227
|
+
catch (err) {
|
|
228
|
+
throw new GraphError(`ui node ${id}: disabledWhen: ${err.message}`);
|
|
229
|
+
}
|
|
230
|
+
for (const n of names) {
|
|
231
|
+
if (n !== 'state' && flow.context[n] === undefined && flow.guards[n] === undefined) {
|
|
232
|
+
throw new GraphError(`ui node ${id}: disabledWhen: ${node.disabledWhen} names ${n}, which is not a variable or a guard of the flow`);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
package/dist/html.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type { Story } from './story.ts';
|
|
|
4
4
|
import type { Kit } from './kit.ts';
|
|
5
5
|
import type { HandOver } from './starts.ts';
|
|
6
6
|
import type { Domain, DomainAction } from './changes.ts';
|
|
7
|
-
export declare const CSS = "\n:root { --bg:#fafaf9; --surface:#ffffff; --ink:#1c1917; --muted:#6b6560; --line:#d6d3d1; --accent:#1d4ed8; --accent-bg:#eef3ff; --ok:#15803d; --bad:#b91c1c; --server:#eeeeec; --focus:#1d4ed8; --ai:#7e22ce; --ai-bg:#f5edff; --agent:#c2410c; --agent-bg:#fff1e8; --ci:#0f766e; --ci-bg:#e6f6f3; --ok-bg:#eaf7ee; }\n@media (prefers-color-scheme: dark) { :root { --bg:#161513; --surface:#1f1d1b; --ink:#f2efec; --muted:#a8a29e; --line:#44403c; --accent:#8fb0ff; --accent-bg:#1c2438; --ok:#5fcf85; --bad:#f08080; --server:#2a2826; --focus:#8fb0ff; --ai:#c99bff; --ai-bg:#2a2135; --agent:#ff9a66; --agent-bg:#33241b; --ci:#5fd4c4; --ci-bg:#1a2e2b; --ok-bg:#16291d; } }\n* { box-sizing: border-box; }\nbody { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.55 system-ui, -apple-system, \"Segoe UI\", sans-serif; }\nmain { max-width: 1000px; margin: 0 auto; padding: 28px 16px 80px; }\nh1 { font-size: 30px; line-height: 1.2; margin: 6px 0 8px; } h2 { font-size: 21px; margin: 44px 0 12px; } h3 { font-size: 16px; margin: 0; }\ncode, pre, .mono { font-family: ui-monospace, \"SF Mono\", Menlo, Consolas, monospace; font-size: 13px; }\n.muted { color: var(--muted); } .label { margin: 0 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }\n.eyebrow { margin: 0; color: var(--muted); } .lede { font-size: 18px; max-width: 46em; margin: 0; }\n.tag { display: inline-block; padding: 1px 8px; border: 1px solid var(--line); border-radius: 99px; font-size: 12px; color: var(--muted); vertical-align: middle; }\n.scroll { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }\ntable { border-collapse: collapse; width: 100%; } th, td { text-align: left; vertical-align: top; padding: 8px 12px; border-bottom: 1px solid var(--line); } th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); } tr:last-child td { border-bottom: 0; }\ntd ol { margin: 0; padding-left: 20px; }\n.ok { color: var(--ok); font-weight: 600; } .bad { color: var(--bad); font-weight: 600; }\n.story { margin-top: 28px; padding: 18px 22px; border: 1px solid var(--line); border-left: 5px solid var(--accent); border-radius: 10px; background: var(--surface); }\n.story h2 { margin: 0 0 6px; } .story .given { margin: 0 0 8px; } .story ol { margin: 0; padding-left: 26px; } .story li { margin: 5px 0; padding-left: 4px; } .story .result { margin: 10px 0 0; font-weight: 600; }\n.views input { margin-right: 8px; accent-color: var(--accent); } .views label { display: inline-block; margin: 0 0 10px; cursor: pointer; }\n.views .panel-full { display: none; } .views input:checked ~ .panel-main { display: none; } .views input:checked ~ .panel-full { display: block; }\nsvg.spine { display: block; width: 100%; height: auto; padding: 8px; background: var(--surface); margin: 0 auto; }\n.spine .edge { fill: none; stroke-width: 1.5; } .spine .edge-user { stroke: var(--muted); } .spine .edge-system { stroke: var(--muted); } .spine .edge-route { stroke: var(--muted); stroke-dasharray: 2 4; } .spine .edge-fail { stroke: var(--bad); stroke-dasharray: 7 4; } .spine .edge-unused { stroke: var(--line); }\n.spine .edge-main { stroke: var(--accent); stroke-width: 3.5; stroke-dasharray: none; }\n.spine .arrow { fill: var(--muted); } .spine .arrow-fail { fill: var(--bad); } .spine .arrow-main { fill: var(--accent); }\n.spine .elabel rect { fill: var(--surface); stroke: var(--line); } .spine .elabel text { fill: var(--ink); font: 13px system-ui, sans-serif; } .spine .elabel-fail text { fill: var(--bad); } .spine .elabel-main rect { stroke: var(--accent); }\n.spine .node rect { fill: var(--surface); stroke: var(--ink); stroke-width: 1.6; } .spine .node-server rect { fill: var(--server); stroke: var(--muted); stroke-dasharray: 5 3; }\n.spine .node-subflow rect { stroke: var(--accent); } .spine .node-subflow rect.inner { fill: none; stroke-width: 1; }\n.spine .on-main rect { stroke-width: 3; } .spine .node-server.on-main rect { stroke: var(--accent); }\n.spine .exit-never rect { stroke: var(--bad); stroke-width: 3; } .spine .exit-error rect { stroke-dasharray: 6 3; } .spine .exit-left rect { stroke-dasharray: 2 3; stroke: var(--muted); } .spine .exit-success rect { stroke: var(--ok); stroke-width: 3; }\n.spine .node.by-human rect { fill: var(--surface); stroke: var(--ink); stroke-dasharray: none; }\n.spine .node.by-ai rect { fill: var(--ai-bg); stroke: var(--ai); stroke-dasharray: none; }\n.spine .node.by-agent rect { fill: var(--agent-bg); stroke: var(--agent); stroke-dasharray: none; } .spine .node.by-agent rect.inner { fill: none; stroke-width: 1; }\n.spine .node.by-ci rect { fill: var(--ci-bg); stroke: var(--ci); stroke-dasharray: none; }\n.spine .node.goal rect { fill: var(--ok-bg); stroke: var(--ok); stroke-width: 3.5; stroke-dasharray: none; }\n.spine .node.on-main rect { stroke-width: 3.5; }\n.spine .nmore { fill: var(--muted); font: 600 11px system-ui, sans-serif; }\n.legend .sw { display: inline-flex; align-items: center; gap: 6px; } .legend svg { flex: none; }\n.legend .sw-node rect { stroke-width: 1.6; }\n.legend .sw-human rect { fill: var(--surface); stroke: var(--ink); } .legend .sw-ai rect { fill: var(--ai-bg); stroke: var(--ai); } .legend .sw-agent rect { fill: var(--agent-bg); stroke: var(--agent); } .legend .sw-agent rect.inner { fill: none; stroke-width: 1; }\n.legend .sw-ci rect { fill: var(--ci-bg); stroke: var(--ci); } .legend .sw-goal rect { fill: var(--ok-bg); stroke: var(--ok); stroke-width: 3; } .legend .sw-server rect { fill: var(--server); stroke: var(--muted); stroke-dasharray: 4 2; }\n.legend .sw-screen rect { fill: var(--surface); stroke: var(--ink); } .legend .sw-subflow rect { fill: var(--surface); stroke: var(--accent); }\n.legend .sw-node.sw-fail rect { fill: var(--surface); stroke: var(--bad); stroke-width: 3; }\n.legend .sw-line path { fill: none; stroke-width: 3; } .legend .sw-main path { stroke: var(--accent); stroke-width: 3.5; } .legend .sw-fail path { stroke: var(--bad); stroke-dasharray: 6 3; } .legend .sw-route path { stroke: var(--muted); stroke-dasharray: 2 3; }\n.covers { display: grid; gap: 10px; } .covers .cv { border: 1px solid var(--line); border-radius: 10px; background: var(--surface); padding: 10px 14px; } .covers ul { margin: 4px 0 0; padding-left: 20px; }\n.spine .node-unreachable rect { stroke: var(--bad); fill: none; }\n.spine .nname { fill: var(--ink); font: 600 14.5px system-ui, sans-serif; } .spine .nline { fill: var(--muted); font: 11.5px ui-monospace, Menlo, Consolas, monospace; } .spine .start { fill: var(--ink); }\n.spine a:focus-visible .node rect, .spine a:hover .node rect { stroke: var(--focus); stroke-width: 3; }\n.legend { display: flex; flex-wrap: wrap; gap: 4px 18px; margin: 10px 0 0; font-size: 14px; color: var(--muted); }\n.screens { display: grid; gap: 18px; }\n.screen { border: 1px solid var(--line); border-radius: 10px; background: var(--surface); padding: 14px 16px 16px; scroll-margin-top: 16px; }\n.screen:target { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-bg); }\n.screen header { display: flex; align-items: center; gap: 10px; } .screen > p { margin: 4px 0 10px; }\n.wf { border: 1px dashed var(--line); border-radius: 8px; padding: 14px; display: grid; gap: 10px; background: var(--bg); max-width: 560px; }\n.wf-item { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; padding: 2px; border-radius: 4px; }\n.wf-cond { outline: 1.5px dashed var(--muted); outline-offset: 2px; } .wf-focus { outline: 2.5px solid var(--focus); outline-offset: 2px; }\n.wf-h { margin: 0; font-size: 17px; } .wf-t { margin: 0; color: var(--muted); }\n.wf-row { display: flex; flex-wrap: wrap; gap: 10px; }\n.wf-btn, .wf-link { font: inherit; border-radius: 6px; padding: 6px 14px; border: 1px solid var(--ink); background: var(--surface); color: var(--ink); }\n.wf-confirm { background: var(--ink); color: var(--bg); } .wf-link { border: 0; background: none; color: var(--accent); text-decoration: underline; padding: 0; }\n.wf button:disabled { opacity: .45; }\n.wf-list { margin: 0; padding-left: 20px; display: grid; gap: 2px; }\n.wf-status { color: var(--muted); font-style: italic; } .wf-alert { border: 1.5px solid var(--bad); border-radius: 6px; padding: 6px 10px; }\n.wf-field { display: grid; gap: 4px; } .wf-input { font: inherit; border: 1px solid var(--muted); border-radius: 6px; padding: 6px 10px; background: var(--surface); color: var(--ink); }\n.wf-unmapped { border: 1.5px solid var(--bad); padding: 6px 10px; }\n.chip { font: 11px ui-monospace, Menlo, Consolas, monospace; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; white-space: nowrap; }\ndetails { margin-top: 12px; } summary { cursor: pointer; color: var(--muted); }\ndetails.ax-wrap { margin-top: 10px; } pre.ax { margin: 8px 0 0; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; white-space: pre-wrap; overflow-wrap: anywhere; background: var(--bg); line-height: 1.55; }\ndl.guards { margin: 10px 0 0; display: grid; grid-template-columns: max-content 1fr; gap: 3px 14px; } dl.guards dt { font-weight: 600; } dl.guards dd { margin: 0; }\nul.checks { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; } ul.checks li { padding-left: 26px; position: relative; } ul.checks li::before { content: \"\u2713\"; position: absolute; left: 4px; color: var(--ok); font-weight: 700; } ul.checks li.fail::before { content: \"\u2717\"; color: var(--bad); }\nfooter { margin-top: 56px; color: var(--muted); font-size: 13px; }\n";
|
|
7
|
+
export declare const CSS = "\n:root { --bg:#fafaf9; --surface:#ffffff; --ink:#1c1917; --muted:#6b6560; --line:#d6d3d1; --accent:#1d4ed8; --accent-bg:#eef3ff; --ok:#15803d; --bad:#b91c1c; --server:#eeeeec; --focus:#1d4ed8; --ai:#7e22ce; --ai-bg:#f5edff; --agent:#c2410c; --agent-bg:#fff1e8; --ci:#0f766e; --ci-bg:#e6f6f3; --ok-bg:#eaf7ee; }\n@media (prefers-color-scheme: dark) { :root { --bg:#161513; --surface:#1f1d1b; --ink:#f2efec; --muted:#a8a29e; --line:#44403c; --accent:#8fb0ff; --accent-bg:#1c2438; --ok:#5fcf85; --bad:#f08080; --server:#2a2826; --focus:#8fb0ff; --ai:#c99bff; --ai-bg:#2a2135; --agent:#ff9a66; --agent-bg:#33241b; --ci:#5fd4c4; --ci-bg:#1a2e2b; --ok-bg:#16291d; } }\n* { box-sizing: border-box; }\nbody { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.55 system-ui, -apple-system, \"Segoe UI\", sans-serif; }\nmain { max-width: 1000px; margin: 0 auto; padding: 28px 16px 80px; }\nh1 { font-size: 30px; line-height: 1.2; margin: 6px 0 8px; } h2 { font-size: 21px; margin: 44px 0 12px; } h3 { font-size: 16px; margin: 0; }\ncode, pre, .mono { font-family: ui-monospace, \"SF Mono\", Menlo, Consolas, monospace; font-size: 13px; }\n.muted { color: var(--muted); } .label { margin: 0 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }\n.eyebrow { margin: 0; color: var(--muted); } .lede { font-size: 18px; max-width: 46em; margin: 0; }\n.tag { display: inline-block; padding: 1px 8px; border: 1px solid var(--line); border-radius: 99px; font-size: 12px; color: var(--muted); vertical-align: middle; }\n.scroll { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }\ntable { border-collapse: collapse; width: 100%; } th, td { text-align: left; vertical-align: top; padding: 8px 12px; border-bottom: 1px solid var(--line); } th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); } tr:last-child td { border-bottom: 0; }\ntd ol { margin: 0; padding-left: 20px; }\n.ok { color: var(--ok); font-weight: 600; } .bad { color: var(--bad); font-weight: 600; }\n.story { margin-top: 28px; padding: 18px 22px; border: 1px solid var(--line); border-left: 5px solid var(--accent); border-radius: 10px; background: var(--surface); }\n.story h2 { margin: 0 0 6px; } .story .given { margin: 0 0 8px; } .story ol { margin: 0; padding-left: 26px; } .story li { margin: 5px 0; padding-left: 4px; } .story .result { margin: 10px 0 0; font-weight: 600; }\n.views input { margin-right: 8px; accent-color: var(--accent); } .views label { display: inline-block; margin: 0 0 10px; cursor: pointer; }\n.views .panel-full { display: none; } .views input:checked ~ .panel-main { display: none; } .views input:checked ~ .panel-full { display: block; }\nsvg.spine { display: block; width: 100%; height: auto; padding: 8px; background: var(--surface); margin: 0 auto; }\n.spine .edge { fill: none; stroke-width: 1.5; } .spine .edge-user { stroke: var(--muted); } .spine .edge-system { stroke: var(--muted); } .spine .edge-route { stroke: var(--muted); stroke-dasharray: 2 4; } .spine .edge-fail { stroke: var(--bad); stroke-dasharray: 7 4; } .spine .edge-unused { stroke: var(--line); }\n.spine .edge-main { stroke: var(--accent); stroke-width: 3.5; stroke-dasharray: none; }\n.spine .arrow { fill: var(--muted); } .spine .arrow-fail { fill: var(--bad); } .spine .arrow-main { fill: var(--accent); }\n.spine .elabel rect { fill: var(--surface); stroke: var(--line); } .spine .elabel text { fill: var(--ink); font: 13px system-ui, sans-serif; } .spine .elabel-fail text { fill: var(--bad); } .spine .elabel-main rect { stroke: var(--accent); }\n.spine .node rect { fill: var(--surface); stroke: var(--ink); stroke-width: 1.6; } .spine .node-server rect { fill: var(--server); stroke: var(--muted); stroke-dasharray: 5 3; }\n.spine .node-subflow rect { stroke: var(--accent); } .spine .node-subflow rect.inner { fill: none; stroke-width: 1; }\n.spine .on-main rect { stroke-width: 3; } .spine .node-server.on-main rect { stroke: var(--accent); }\n.spine .exit-never rect { stroke: var(--bad); stroke-width: 3; } .spine .exit-error rect { stroke-dasharray: 6 3; } .spine .exit-left rect { stroke-dasharray: 2 3; stroke: var(--muted); } .spine .exit-success rect { stroke: var(--ok); stroke-width: 3; }\n.spine .node.by-human rect { fill: var(--surface); stroke: var(--ink); stroke-dasharray: none; }\n.spine .node.by-ai rect { fill: var(--ai-bg); stroke: var(--ai); stroke-dasharray: none; }\n.spine .node.by-agent rect { fill: var(--agent-bg); stroke: var(--agent); stroke-dasharray: none; } .spine .node.by-agent rect.inner { fill: none; stroke-width: 1; }\n.spine .node.by-ci rect { fill: var(--ci-bg); stroke: var(--ci); stroke-dasharray: none; }\n.spine .node.goal rect { fill: var(--ok-bg); stroke: var(--ok); stroke-width: 3.5; stroke-dasharray: none; }\n.spine .node.on-main rect { stroke-width: 3.5; }\n.spine .nmore { fill: var(--muted); font: 600 11px system-ui, sans-serif; }\n.legend .sw { display: inline-flex; align-items: center; gap: 6px; } .legend svg { flex: none; }\n.legend .sw-node rect { stroke-width: 1.6; }\n.legend .sw-human rect { fill: var(--surface); stroke: var(--ink); } .legend .sw-ai rect { fill: var(--ai-bg); stroke: var(--ai); } .legend .sw-agent rect { fill: var(--agent-bg); stroke: var(--agent); } .legend .sw-agent rect.inner { fill: none; stroke-width: 1; }\n.legend .sw-ci rect { fill: var(--ci-bg); stroke: var(--ci); } .legend .sw-goal rect { fill: var(--ok-bg); stroke: var(--ok); stroke-width: 3; } .legend .sw-server rect { fill: var(--server); stroke: var(--muted); stroke-dasharray: 4 2; }\n.legend .sw-screen rect { fill: var(--surface); stroke: var(--ink); } .legend .sw-subflow rect { fill: var(--surface); stroke: var(--accent); }\n.legend .sw-node.sw-fail rect { fill: var(--surface); stroke: var(--bad); stroke-width: 3; }\n.legend .sw-line path { fill: none; stroke-width: 3; } .legend .sw-main path { stroke: var(--accent); stroke-width: 3.5; } .legend .sw-fail path { stroke: var(--bad); stroke-dasharray: 6 3; } .legend .sw-route path { stroke: var(--muted); stroke-dasharray: 2 3; }\n.covers { display: grid; gap: 10px; } .covers .cv { border: 1px solid var(--line); border-radius: 10px; background: var(--surface); padding: 10px 14px; } .covers ul { margin: 4px 0 0; padding-left: 20px; }\n.spine .node-unreachable rect { stroke: var(--bad); fill: none; }\n.spine .nname { fill: var(--ink); font: 600 14.5px system-ui, sans-serif; } .spine .nline { fill: var(--muted); font: 11.5px ui-monospace, Menlo, Consolas, monospace; } .spine .start { fill: var(--ink); }\n.spine a:focus-visible .node rect, .spine a:hover .node rect { stroke: var(--focus); stroke-width: 3; }\n.legend { display: flex; flex-wrap: wrap; gap: 4px 18px; margin: 10px 0 0; font-size: 14px; color: var(--muted); }\n.screens { display: grid; gap: 18px; }\n.screen { border: 1px solid var(--line); border-radius: 10px; background: var(--surface); padding: 14px 16px 16px; scroll-margin-top: 16px; }\n.screen:target { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-bg); }\n.screen header { display: flex; align-items: center; gap: 10px; } .screen > p { margin: 4px 0 10px; }\n.wf { border: 1px dashed var(--line); border-radius: 8px; padding: 14px; display: grid; gap: 10px; background: var(--bg); max-width: 560px; }\n.wf-item { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; padding: 2px; border-radius: 4px; }\n.wf-cond { outline: 1.5px dashed var(--muted); outline-offset: 2px; } .wf-focus { outline: 2.5px solid var(--focus); outline-offset: 2px; }\n.wf-h { margin: 0; font-size: 17px; } .wf-t { margin: 0; color: var(--muted); }\n.wf-row { display: flex; flex-wrap: wrap; gap: 10px; }\n.wf-btn, .wf-link { font: inherit; border-radius: 6px; padding: 6px 14px; border: 1px solid var(--ink); background: var(--surface); color: var(--ink); }\n.wf-confirm { background: var(--ink); color: var(--bg); } .wf-link { border: 0; background: none; color: var(--accent); text-decoration: underline; padding: 0; }\n.wf button:disabled { opacity: .45; }\n.wf-list { margin: 0; padding-left: 20px; display: grid; gap: 2px; }\n.wf-status { color: var(--muted); font-style: italic; } .wf-alert { border: 1.5px solid var(--bad); border-radius: 6px; padding: 6px 10px; }\n.wf-check { display: flex; gap: 8px; align-items: center; } .wf-field { display: grid; gap: 4px; } .wf-input { font: inherit; border: 1px solid var(--muted); border-radius: 6px; padding: 6px 10px; background: var(--surface); color: var(--ink); }\n.wf-unmapped { border: 1.5px solid var(--bad); padding: 6px 10px; }\n.chip { font: 11px ui-monospace, Menlo, Consolas, monospace; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; white-space: nowrap; }\ndetails { margin-top: 12px; } summary { cursor: pointer; color: var(--muted); }\ndetails.ax-wrap { margin-top: 10px; } pre.ax { margin: 8px 0 0; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; white-space: pre-wrap; overflow-wrap: anywhere; background: var(--bg); line-height: 1.55; }\ndl.guards { margin: 10px 0 0; display: grid; grid-template-columns: max-content 1fr; gap: 3px 14px; } dl.guards dt { font-weight: 600; } dl.guards dd { margin: 0; }\nul.checks { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; } ul.checks li { padding-left: 26px; position: relative; } ul.checks li::before { content: \"\u2713\"; position: absolute; left: 4px; color: var(--ok); font-weight: 700; } ul.checks li.fail::before { content: \"\u2717\"; color: var(--bad); }\nfooter { margin-top: 56px; color: var(--muted); font-size: 13px; }\n";
|
|
8
8
|
export interface PageInput {
|
|
9
9
|
g: Graph;
|
|
10
10
|
m: Model;
|
package/dist/html.js
CHANGED
|
@@ -67,7 +67,7 @@ svg.spine { display: block; width: 100%; height: auto; padding: 8px; background:
|
|
|
67
67
|
.wf button:disabled { opacity: .45; }
|
|
68
68
|
.wf-list { margin: 0; padding-left: 20px; display: grid; gap: 2px; }
|
|
69
69
|
.wf-status { color: var(--muted); font-style: italic; } .wf-alert { border: 1.5px solid var(--bad); border-radius: 6px; padding: 6px 10px; }
|
|
70
|
-
.wf-field { display: grid; gap: 4px; } .wf-input { font: inherit; border: 1px solid var(--muted); border-radius: 6px; padding: 6px 10px; background: var(--surface); color: var(--ink); }
|
|
70
|
+
.wf-check { display: flex; gap: 8px; align-items: center; } .wf-field { display: grid; gap: 4px; } .wf-input { font: inherit; border: 1px solid var(--muted); border-radius: 6px; padding: 6px 10px; background: var(--surface); color: var(--ink); }
|
|
71
71
|
.wf-unmapped { border: 1.5px solid var(--bad); padding: 6px 10px; }
|
|
72
72
|
.chip { font: 11px ui-monospace, Menlo, Consolas, monospace; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; white-space: nowrap; }
|
|
73
73
|
details { margin-top: 12px; } summary { cursor: pointer; color: var(--muted); }
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Domain } from './changes.ts';
|
|
2
|
+
import type { Graph } from './graph.ts';
|
|
3
|
+
export interface InvokeProblem {
|
|
4
|
+
rule: 'invoke-unknown' | 'refusal-unknown';
|
|
5
|
+
path: string[];
|
|
6
|
+
message: string;
|
|
7
|
+
element: string;
|
|
8
|
+
}
|
|
9
|
+
export declare const TRANSPORT_CODES: readonly string[];
|
|
10
|
+
export declare function checkInvokes(g: Graph, domainOf?: () => Domain | null): InvokeProblem[];
|
package/dist/invokes.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// What a flow invokes, held to its domain (SPEC.md §2, §5): `invoke: { action }` names an action of the domain the flow
|
|
2
|
+
// names, and for a state that invokes an action, `failures.<state>.from` does too and each class under it lists
|
|
3
|
+
// refusals of that action. A state that invokes an `external` or a `flow` is not held to the domain. The domain is looked
|
|
4
|
+
// up by id among the graphs beside the flow, all its files read as one, as the `changes` rule finds it. A class may also
|
|
5
|
+
// list a transport code, a failure that is no answer of the action's own (SPEC.md §5). Each finding is an error, which
|
|
6
|
+
// fails --strict (decided on 16 Nov 2026, d-1116-10).
|
|
7
|
+
import { flowDomain } from './changes.js';
|
|
8
|
+
// the key that names a class's action in `failures.<state>`; every other key is a class
|
|
9
|
+
const FROM = 'from';
|
|
10
|
+
// the codes a failure class may list though its action has no such refusal (SPEC.md §5): no answer came back, none came
|
|
11
|
+
// in time, or the server failed with a status the action does not list
|
|
12
|
+
export const TRANSPORT_CODES = ['network', 'timeout', '5xx'];
|
|
13
|
+
// `domainOf` finds the flow's domain, as for checkChanges
|
|
14
|
+
export function checkInvokes(g, domainOf = () => flowDomain(g)) {
|
|
15
|
+
const invoked = Object.entries(g.flow.states).filter(([, st]) => typeof st.invoke?.action === 'string');
|
|
16
|
+
if (g.flow.domain === undefined || invoked.length === 0)
|
|
17
|
+
return [];
|
|
18
|
+
const failures = (g.flow.failures ?? {});
|
|
19
|
+
const domain = domainOf();
|
|
20
|
+
if (domain === null) {
|
|
21
|
+
return [
|
|
22
|
+
{
|
|
23
|
+
rule: 'invoke-unknown',
|
|
24
|
+
path: ['domain'],
|
|
25
|
+
element: 'domain',
|
|
26
|
+
message: `the flow names the domain ${g.flow.domain}, which no domain beside it is (under the nearest folder called graphs), so what its steps invoke is not checked (SPEC.md §5)`,
|
|
27
|
+
},
|
|
28
|
+
];
|
|
29
|
+
}
|
|
30
|
+
const actions = domain.actions ?? {};
|
|
31
|
+
const has = (name) => Object.hasOwn(actions, name);
|
|
32
|
+
const out = [];
|
|
33
|
+
for (const [state, st] of invoked) {
|
|
34
|
+
const action = st.invoke?.action;
|
|
35
|
+
if (has(action))
|
|
36
|
+
continue;
|
|
37
|
+
out.push({ rule: 'invoke-unknown', path: ['states', state, 'invoke', 'action'], element: `states/${state}/invoke`, message: `state ${state} invokes ${action}, which is not an action of the domain ${g.flow.domain} (SPEC.md §5)` });
|
|
38
|
+
}
|
|
39
|
+
for (const [state, classes] of Object.entries(failures)) {
|
|
40
|
+
const action = g.flow.states[state]?.invoke?.action;
|
|
41
|
+
if (classes === null || typeof classes !== 'object' || typeof action !== 'string')
|
|
42
|
+
continue;
|
|
43
|
+
const named = typeof classes[FROM] === 'string' ? classes[FROM] : action;
|
|
44
|
+
if (!has(named)) {
|
|
45
|
+
// an action the state's own invoke names is reported there
|
|
46
|
+
if (named !== action)
|
|
47
|
+
out.push({ rule: 'invoke-unknown', path: ['failures', state, FROM], element: `failures/${state}/from`, message: `failures.${state} comes from ${named}, which is not an action of the domain ${g.flow.domain} (SPEC.md §2, §5)` });
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
const refusals = actions[named]?.refusals ?? {};
|
|
51
|
+
for (const [cls, codes] of Object.entries(classes)) {
|
|
52
|
+
if (cls === FROM || !Array.isArray(codes))
|
|
53
|
+
continue;
|
|
54
|
+
codes.forEach((code, i) => {
|
|
55
|
+
if (typeof code !== 'string' || Object.hasOwn(refusals, code) || TRANSPORT_CODES.includes(code))
|
|
56
|
+
return;
|
|
57
|
+
out.push({
|
|
58
|
+
rule: 'refusal-unknown',
|
|
59
|
+
path: ['failures', state, cls, String(i)],
|
|
60
|
+
element: `failures/${state}/${cls}/${code}`,
|
|
61
|
+
message: `FAIL.${cls} of ${state} stands for ${code}, which is not a refusal of ${named} in the domain ${g.flow.domain}, nor network, timeout or 5xx (SPEC.md §2, §5)`,
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return out;
|
|
67
|
+
}
|
package/dist/kit.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export declare class KitError extends Error {
|
|
2
2
|
}
|
|
3
3
|
declare const SLOTS: readonly ['text', 'name', 'id', 'intent', 'children'];
|
|
4
|
-
declare const FLAGS: readonly ['disabled', 'named', 'conditional'];
|
|
4
|
+
declare const FLAGS: readonly ['disabled', 'named', 'conditional', 'checked'];
|
|
5
5
|
type Slot = (typeof SLOTS)[number];
|
|
6
6
|
type Flag = (typeof FLAGS)[number];
|
|
7
7
|
type Part = {
|
|
@@ -43,6 +43,7 @@ export interface Fill {
|
|
|
43
43
|
disabled: boolean;
|
|
44
44
|
named: boolean;
|
|
45
45
|
conditional: boolean;
|
|
46
|
+
checked: boolean;
|
|
46
47
|
}
|
|
47
48
|
export declare function drawWith(kit: Kit, component: string, f: Fill, warn: (m: string) => void): string | null;
|
|
48
49
|
export declare function mark(html: string, id: string, chips: string): string;
|
package/dist/kit.js
CHANGED
|
@@ -9,7 +9,7 @@ export class KitError extends Error {
|
|
|
9
9
|
}
|
|
10
10
|
const esc = (s) => s.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
|
11
11
|
const SLOTS = ['text', 'name', 'id', 'intent', 'children'];
|
|
12
|
-
const FLAGS = ['disabled', 'named', 'conditional'];
|
|
12
|
+
const FLAGS = ['disabled', 'named', 'conditional', 'checked'];
|
|
13
13
|
// Lists are drawn without a wrapper around each item, so their templates must be one element the renderer can mark.
|
|
14
14
|
const SINGLE = new Set(['List', 'ListItem']);
|
|
15
15
|
const VOID = new Set(['area', 'br', 'col', 'hr', 'img', 'input', 'source', 'track', 'wbr']);
|
|
@@ -304,7 +304,8 @@ function checkCss(css, where) {
|
|
|
304
304
|
};
|
|
305
305
|
if (css.includes('<'))
|
|
306
306
|
fail('"<" is not allowed in kit CSS (percent-encode it in a data: URL)');
|
|
307
|
-
|
|
307
|
+
// `behavior:` is old Internet Explorer's script binding; `scroll-behavior` and `overscroll-behavior` are not
|
|
308
|
+
if (/expression\(|javascript:|-moz-binding|(?:^|[^-\w])behavior\s*:/i.test(css))
|
|
308
309
|
fail('script-like CSS is not allowed');
|
|
309
310
|
let depth = 0;
|
|
310
311
|
let prelude = '';
|