@keemakr/ui-sdk 1.7.0 → 1.8.0-dev-20261114152523

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/README.md CHANGED
@@ -172,7 +172,31 @@ const [mobile] = assertDrawableOn(tree, ['mobile'], { allowFallback: true });
172
172
 
173
173
  With no targets, the testkit checks every app that renders module screens (web and mobile). An app
174
174
  named alone is checked at every release it has, so `['mobile']` covers mobile 0.2.0 as well as the
175
- newest build.
175
+ newest build. Name a version with `claim: 'current'` (`{ client: 'web', version: '0.2.0', claim:
176
+ 'current' }`) to see what a dev-channel web build gets on dev and stage.
177
+
178
+ ### Stories: try a screen with sample data
179
+
180
+ A `*.stories.ts` file holds sample pages in one format: each story is a screen tree and the
181
+ datasets it places, declared as a module declares them.
182
+
183
+ ```ts
184
+ import { defineStories, sampleRows, sampleAnswer } from '@keemakr/ui-sdk/stories';
185
+
186
+ export default defineStories({
187
+ title: 'Leads',
188
+ stories: [{ name: 'Leads as a table', tree, datasets: [leads] }],
189
+ });
190
+
191
+ sampleRows(leads, 400); // 400 synthetic rows: the same on every run
192
+ sampleRows(leads, 5, 'long_text'); // every text value as long as a dataset allows
193
+ sampleRows(leads, 5, 'error'); // rows the platform refuses: the view's error state
194
+ sampleAnswer(leads, rows, { limit: 25 }); // one page, as a module answers a query
195
+ ```
196
+
197
+ `defineStories` throws a `StoryError` naming the story when a tree or a dataset does not pass the
198
+ schema, or a tree places a dataset the story does not declare. The rows are made up from a fixed
199
+ word list, so a story never holds real data.
176
200
 
177
201
  ## 7. Return the new screen from an action
178
202
 
@@ -272,3 +296,141 @@ map's values, and `@<value>` into the variant whose `type` or `kind` is that val
272
296
  items of an array or keys of a map.
273
297
  Numeric ranges (`dataset.limit` is 1 to 100) are not caps, so they are not in `NODE_LIMITS`: read
274
298
  them from `schema` (`minimum`, `maximum`, `default`).
299
+
300
+ ## 10. Build a tree with the typed builders
301
+
302
+ `@keemakr/ui-sdk/ui` has one builder per node, generated from the catalog, and `ui.screen` for the
303
+ tree. A builder sets `type` (and `ui.screen` sets `version`), applies the schema's defaults, and
304
+ returns plain JSON: the same tree core reads after it parses a hand-written one, so nothing core
305
+ receives changes. A value the schema refuses throws a `UiBuildError` that names the field path,
306
+ where you built the node, instead of core refusing the whole screen later:
307
+
308
+ ```ts
309
+ import { defineScreen } from '@keemakr/ui-sdk';
310
+ import { ui, UiBuildError } from '@keemakr/ui-sdk/ui';
311
+
312
+ export default defineScreen({
313
+ load: async () =>
314
+ ui.screen({
315
+ title: 'Leads',
316
+ children: [
317
+ ui.table({
318
+ columns: [{ key: 'name', label: 'Name' }],
319
+ rows: (await listLeads()).map((lead) => ({
320
+ key: lead.id,
321
+ cells: { name: { kind: 'text', value: lead.name } },
322
+ })),
323
+ empty: 'No leads yet',
324
+ }),
325
+ ],
326
+ }),
327
+ });
328
+
329
+ try {
330
+ ui.text({ value: tooLong });
331
+ } catch (error) {
332
+ if (error instanceof UiBuildError) console.log(error.path, error.issues[0]?.limit); // value 5000
333
+ }
334
+ ```
335
+
336
+ `error.path` is the first refused field, from the node the builder makes (`rows[3].cells.name.value`;
337
+ from the screen for `ui.screen`, `children[0].value`). `error.issues` lists every refused field, with
338
+ `limit` set when the value is past a size cap (the same number `NODE_LIMITS` holds; a number past its
339
+ range has none). A builder checks its node with the schema core reads it with, a `section`'s or a
340
+ `tabs`' children included; `ui.screen` checks the whole tree and adds the rules that span nodes (a
341
+ seek must name a recording on the screen). Each builder's doc comment lists the node's top-level
342
+ caps, so an editor shows them as you type.
343
+
344
+ ## 11. Let core keep a screen for a repeat load
345
+
346
+ Most of a screen's load time is the round trip to your runtime. A screen whose data can be a little
347
+ old may let core keep the tree it last drew for a person, and answer that person's next load of the
348
+ same screen, with the same params, from it while core loads the screen again in the background:
349
+
350
+ ```ts
351
+ export default defineScreen({
352
+ cache: { max_age_s: 60 },
353
+ load: async (ctx, params) => ({ version: 1, title: 'Accounts', children: [] }),
354
+ });
355
+ ```
356
+
357
+ - Write `cache` as a literal inside `export default defineScreen({ ... })`: the build reads it
358
+ without running your code and copies it into the screen's `screenRegistry` entry in
359
+ `entry.json`. `max_age_s` is a whole number from 1 to 3600.
360
+ - A kept tree is one person's, for their role and department standing at the time; core never
361
+ shows it to anyone else, and checks the person's access on every load before it.
362
+ - A screen action, a dataset row added through core, or a job status read (the screen polling
363
+ `/screens/:screen/jobs/:id`) that reports the job ended, on any of your screens, drops all your
364
+ module's kept trees, so the next load is fresh. A job nobody polls to its end drops nothing. Any
365
+ write to the company's records (`kee.records.*`, from any agent or person) drops every kept tree
366
+ of the company. Other writes your agent makes on its own (its own store, a connector) are not
367
+ seen: `max_age_s` is how stale such a screen may get.
368
+ - Leave `cache` out for a screen that must always be current (a live queue, a countdown). Without
369
+ it core never keeps the screen. Core keeps nothing unless the company has screen caching on.
370
+
371
+ ## 12. Check a screen or a page before you publish it
372
+
373
+ `@keemakr/ui-sdk/check` is the one checker every publish runs: this package's CLI and CI action,
374
+ core's MCP tools (`ui_tree_validate`, `ui_tree_lint`) and the page builder's gate. It is pure (no
375
+ network), takes a screen tree or a page that wraps one (`{ tree }`), and returns findings, each
376
+ with a rule id, a severity, the field path and a fix:
377
+
378
+ ```ts
379
+ import { checkPage, fixPage } from '@keemakr/ui-sdk/check';
380
+
381
+ const { ok, findings } = checkPage(tree, {
382
+ // Optional: what the company has installed. With it, a dataset node naming another dataset is
383
+ // `binding.dataset_unknown` and a press calling an undeclared action `binding.action_undeclared`.
384
+ bindings: { datasets: ['leads'], actions: ['approve'] },
385
+ });
386
+ // findings[0]: { rule: 'limit.exceeded', severity: 'error', path: 'children[0].text', ... }
387
+ ```
388
+
389
+ Errors (`schema.*`, `limit.exceeded`, `binding.*`) block a publish; warnings (`reach.fallback`,
390
+ `workaround.*`, `a11y.*`, `catalog.mismatch`) are shown. `fixPage` makes the fixes marked
391
+ `fixable` (an empty text spacer becomes a `divider`, a text with a warning sign an `alert`, a
392
+ markdown node holding one link a `link`) on a copy. `CHECK_RULES` lists every rule.
393
+
394
+ From a terminal or CI, on JSON files:
395
+
396
+ ```sh
397
+ npx keemakr-ui check [--json] [--github] [--fix] [--bindings bindings.json] [--client web|mobile[@version]] page.json
398
+ npx keemakr-ui check --rules
399
+ ```
400
+
401
+ It exits 1 when a file has an error, 0 on warnings alone and 2 on a usage error. `--fix` writes
402
+ the safe fixes back to the file. In GitHub Actions, the composite action in the keemakr
403
+ repository (`uses: fsztpartners/keemakr/packages/ui-sdk/ci-action@<sha>`, inputs `files`,
404
+ `bindings`, `sdk-version`, `working-directory`) runs it with `--github`, so each finding is annotated
405
+ on the run.
406
+
407
+ ## 13. The page format
408
+
409
+ A page made in the UI builder (by a person, by Kee or by an agent) has one shape, defined in
410
+ `@keemakr/ui-sdk/page`: a thin envelope over a screen tree. Everything that writes or reads a page
411
+ (the builder, Kee's page skill, export and import) uses exactly this.
412
+
413
+ ```ts
414
+ import { pageDocumentSchema, stampNodeIds } from '@keemakr/ui-sdk/page';
415
+
416
+ const page = pageDocumentSchema.parse({
417
+ format: 'keemakr.page',
418
+ formatVersion: 1,
419
+ catalogId: 'kee/1+…', // the catalog the page was built against (catalog.json)
420
+ kind: 'page', // or 'template'
421
+ title: 'Leads',
422
+ tree: { version: 1, title: 'Leads', children: [{ type: 'heading', value: 'Leads', level: 1 }] },
423
+ bindings: [{ kind: 'dataset', dataset: 'leads' }], // optional, defaults to []
424
+ });
425
+ ```
426
+
427
+ - The envelope is strict; the `tree` is not parsed by it. A tree the screen schema refuses is
428
+ still a page, so saving keeps the work; `checkPage` (section 12) says what is wrong, and only a
429
+ push or a pack submission is refused for it.
430
+ - `bindings` are what the page may read and call: an installed dataset by name, a declared action
431
+ by its stable id.
432
+ - Every node of a stored page has a stable `id` (1-64 of `A-Z a-z 0-9 _ -`, unique in the page),
433
+ so an edit names the node it changes, never its position. `stampNodeIds(page, newId)` returns a
434
+ copy where each node without an id (or with a duplicate or malformed one) gets one from `newId`,
435
+ and every other id is kept. Ids stay in the stored page; they are not part of the screen node
436
+ schemas a renderer is handed.
package/catalog.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "catalogId": "kee/1+53a5c298d159",
2
+ "catalogId": "kee/1+c8e17129b699",
3
3
  "schemaVersion": 1,
4
4
  "nodeTypes": [
5
5
  "heading",
@@ -654,7 +654,7 @@
654
654
  "onPress@focus.field": 64,
655
655
  "onPress@navigate.screen": 64,
656
656
  "onPress@seek.player": 64,
657
- "src": 256
657
+ "src": 2048
658
658
  }
659
659
  },
660
660
  "video": {
@@ -666,8 +666,8 @@
666
666
  "caption": 200,
667
667
  "captions": 256,
668
668
  "key": 64,
669
- "poster": 256,
670
- "src": 256,
669
+ "poster": 2048,
670
+ "src": 2048,
671
671
  "title": 120
672
672
  }
673
673
  },
@@ -4973,11 +4973,7 @@
4973
4973
  "type": "object",
4974
4974
  "properties": {
4975
4975
  "type": { "type": "string", "const": "image" },
4976
- "src": {
4977
- "type": "string",
4978
- "maxLength": 256,
4979
- "pattern": "^[A-Za-z0-9][A-Za-z0-9._-]*(\\/[A-Za-z0-9][A-Za-z0-9._-]*)*$"
4980
- },
4976
+ "src": { "type": "string", "maxLength": 2048 },
4981
4977
  "alt": { "type": "string", "minLength": 1, "maxLength": 300 },
4982
4978
  "decorative": { "default": false, "type": "boolean" },
4983
4979
  "caption": { "type": "string", "maxLength": 200 },
@@ -5073,17 +5069,9 @@
5073
5069
  "properties": {
5074
5070
  "type": { "type": "string", "const": "video" },
5075
5071
  "key": { "type": "string", "maxLength": 64, "pattern": "^[a-z][a-z0-9_-]*$" },
5076
- "src": {
5077
- "type": "string",
5078
- "maxLength": 256,
5079
- "pattern": "^[A-Za-z0-9][A-Za-z0-9._-]*(\\/[A-Za-z0-9][A-Za-z0-9._-]*)*$"
5080
- },
5072
+ "src": { "type": "string", "maxLength": 2048 },
5081
5073
  "title": { "type": "string", "minLength": 1, "maxLength": 120 },
5082
- "poster": {
5083
- "type": "string",
5084
- "maxLength": 256,
5085
- "pattern": "^[A-Za-z0-9][A-Za-z0-9._-]*(\\/[A-Za-z0-9][A-Za-z0-9._-]*)*$"
5086
- },
5074
+ "poster": { "type": "string", "maxLength": 2048 },
5087
5075
  "captions": {
5088
5076
  "type": "string",
5089
5077
  "maxLength": 256,
package/dist/build.js CHANGED
@@ -3,7 +3,7 @@ import { basename, dirname, join, relative, sep } from 'node:path';
3
3
  import { isDeepStrictEqual } from 'node:util';
4
4
  import ts from 'typescript';
5
5
  import { datasetManifestSchema } from './dataset.js';
6
- import { surfaceDefinitionSchema, uiManifestSchema, } from './schema.js';
6
+ import { screenCacheSchema, surfaceDefinitionSchema, uiManifestSchema, } from './schema.js';
7
7
  const SLUG = /^[a-z][a-z0-9_-]*$/;
8
8
  const IDENTIFIER = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
9
9
  const REMOVED_SCREENS_META_KEY = 'uiSdkRemovedScreens';
@@ -189,6 +189,51 @@ async function readSurfaceDefinition(path) {
189
189
  }
190
190
  return parsed.data;
191
191
  }
192
+ /**
193
+ * The `cache` a screen declares in `export default defineScreen({ cache: { max_age_s: 60 } })`,
194
+ * read statically like a surface (the build never runs module code). Undefined when the screen
195
+ * declares none, or its default export is not a `defineScreen({ ... })` call: core then never
196
+ * keeps the screen, which is the safe side.
197
+ */
198
+ async function readScreenCache(path) {
199
+ const source = ts.createSourceFile(path, await readFile(path, 'utf8'), ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
200
+ for (const statement of source.statements) {
201
+ if (!ts.isExportAssignment(statement))
202
+ continue;
203
+ const exported = unwrap(statement.expression);
204
+ if (!ts.isCallExpression(exported) || exported.arguments.length !== 1)
205
+ continue;
206
+ if (!ts.isIdentifier(exported.expression) || exported.expression.text !== 'defineScreen')
207
+ continue;
208
+ const argument = unwrap(exported.arguments[0]);
209
+ if (!ts.isObjectLiteralExpression(argument))
210
+ return undefined;
211
+ for (const property of argument.properties) {
212
+ const name = property.name;
213
+ if (!name || (!ts.isIdentifier(name) && !ts.isStringLiteral(name)))
214
+ continue;
215
+ if (name.text !== 'cache')
216
+ continue;
217
+ if (!ts.isPropertyAssignment(property)) {
218
+ throw new Error(`${path}: "cache" must use key: value syntax`);
219
+ }
220
+ let raw;
221
+ try {
222
+ raw = declarationValue(property.initializer);
223
+ }
224
+ catch (error) {
225
+ throw new Error(`${path}: "cache": ${error.message}`);
226
+ }
227
+ const parsed = screenCacheSchema.safeParse(raw);
228
+ if (!parsed.success) {
229
+ const issue = parsed.error.issues[0];
230
+ throw new Error(`${path}: cache${issue?.path.length ? `.${issue.path.join('.')}` : ''} ${issue?.message ?? 'is invalid'}`);
231
+ }
232
+ return parsed.data;
233
+ }
234
+ }
235
+ return undefined;
236
+ }
192
237
  async function isFile(path) {
193
238
  return stat(path)
194
239
  .then((value) => value.isFile())
@@ -319,7 +364,8 @@ export async function buildModuleUi(projectRoot = process.cwd()) {
319
364
  throw new Error(`duplicate screen identity "${screen}" in ${previous} and ${file}`);
320
365
  }
321
366
  seenScreens.set(screen, file);
322
- screenRegistry.push({ screen, surface: entry.name });
367
+ const cache = await readScreenCache(file);
368
+ screenRegistry.push({ screen, surface: entry.name, ...(cache ? { cache } : {}) });
323
369
  registryImports.push({ screen, file });
324
370
  }
325
371
  }
@@ -0,0 +1,9 @@
1
+ export declare const CHECK_USAGE: string;
2
+ export interface CheckCliIo {
3
+ readFile(path: string): string;
4
+ writeFile(path: string, text: string): void;
5
+ out(line: string): void;
6
+ err(line: string): void;
7
+ }
8
+ /** Run the command; returns the exit code. Never calls process.exit, so a test can run it. */
9
+ export declare function runCheckCli(args: readonly string[], io?: CheckCliIo): number;
@@ -0,0 +1,145 @@
1
+ // `keemakr-ui check`: the checker (check.ts) for a Pack author's terminal and CI. It reads JSON
2
+ // files, each a screen tree or a page, and prints one line per finding; the exit code is 1 when
3
+ // any file has an error, so a CI step fails on errors and passes on warnings. `--fix` writes the
4
+ // safe fixes back to the file. `--json` prints the findings as JSON (what the CI action and the
5
+ // tests read), and `--github` adds a GitHub Actions annotation per finding.
6
+ import { readFileSync, writeFileSync } from 'node:fs';
7
+ import { CHECK_RULES, checkPage, fixPage, formatFinding, } from './check.js';
8
+ export const CHECK_USAGE = 'Usage: keemakr-ui check [--json] [--github] [--fix] [--bindings <file.json>] ' +
9
+ '[--client web|mobile[@version]]... <file.json>...\n' +
10
+ ' keemakr-ui check --rules';
11
+ const nodeIo = {
12
+ readFile: (path) => readFileSync(path, 'utf8'),
13
+ writeFile: (path, text) => writeFileSync(path, text),
14
+ out: (line) => console.log(line),
15
+ err: (line) => console.error(line),
16
+ };
17
+ const SCREEN_CLIENTS = ['web', 'mobile'];
18
+ function readBindings(io, path) {
19
+ const raw = JSON.parse(io.readFile(path));
20
+ const list = (value, name) => {
21
+ if (!Array.isArray(value) || value.some((item) => typeof item !== 'string')) {
22
+ throw new Error(`${path}: "${name}" must be a list of strings`);
23
+ }
24
+ return value;
25
+ };
26
+ return { datasets: list(raw.datasets, 'datasets'), actions: list(raw.actions, 'actions') };
27
+ }
28
+ function parseClient(value) {
29
+ const [client, version] = value.split('@');
30
+ if (!SCREEN_CLIENTS.includes(client)) {
31
+ throw new Error(`--client takes ${SCREEN_CLIENTS.join(' or ')}, not "${value}"`);
32
+ }
33
+ return version ? { client: client, version } : client;
34
+ }
35
+ /** GitHub's workflow-command escaping for a message and a property value. */
36
+ const escapeData = (text) => text.replace(/%/g, '%25').replace(/\r/g, '%0D').replace(/\n/g, '%0A');
37
+ const escapeProperty = (text) => escapeData(text).replace(/:/g, '%3A').replace(/,/g, '%2C');
38
+ /** Run the command; returns the exit code. Never calls process.exit, so a test can run it. */
39
+ export function runCheckCli(args, io = nodeIo) {
40
+ const files = [];
41
+ const clients = [];
42
+ let json = false;
43
+ let github = false;
44
+ let fix = false;
45
+ let bindings;
46
+ try {
47
+ for (let i = 0; i < args.length; i += 1) {
48
+ const arg = args[i];
49
+ if (arg === '--json')
50
+ json = true;
51
+ else if (arg === '--github')
52
+ github = true;
53
+ else if (arg === '--fix')
54
+ fix = true;
55
+ else if (arg === '--rules') {
56
+ for (const [rule, { severity, summary }] of Object.entries(CHECK_RULES)) {
57
+ io.out(`${severity.padEnd(7)} ${rule} ${summary}`);
58
+ }
59
+ return 0;
60
+ }
61
+ else if (arg === '--bindings' || arg === '--client') {
62
+ const value = args[i + 1];
63
+ if (!value)
64
+ throw new Error(`${arg} needs a value`);
65
+ i += 1;
66
+ if (arg === '--bindings')
67
+ bindings = readBindings(io, value);
68
+ else
69
+ clients.push(parseClient(value));
70
+ }
71
+ else if (arg.startsWith('--'))
72
+ throw new Error(`unknown option ${arg}`);
73
+ else
74
+ files.push(arg);
75
+ }
76
+ if (files.length === 0)
77
+ throw new Error('name at least one JSON file');
78
+ }
79
+ catch (error) {
80
+ io.err(error instanceof Error ? error.message : String(error));
81
+ io.err(CHECK_USAGE);
82
+ return 2;
83
+ }
84
+ const options = { bindings, ...(clients.length > 0 ? { clients } : {}) };
85
+ const reports = [];
86
+ for (const file of files) {
87
+ let document;
88
+ try {
89
+ document = JSON.parse(io.readFile(file));
90
+ }
91
+ catch (error) {
92
+ const message = error instanceof Error ? error.message : String(error);
93
+ const unreadable = {
94
+ rule: 'schema.invalid',
95
+ severity: 'error',
96
+ path: '(root)',
97
+ message: `not readable as JSON: ${message}`,
98
+ fix: 'Write the screen tree or the page as JSON.',
99
+ };
100
+ reports.push({ file, ok: false, findings: [unreadable] });
101
+ continue;
102
+ }
103
+ if (fix) {
104
+ const fixedRun = fixPage(document, options);
105
+ if (fixedRun.fixed.length > 0) {
106
+ io.writeFile(file, `${JSON.stringify(fixedRun.document, null, 2)}\n`);
107
+ }
108
+ reports.push({
109
+ file,
110
+ ok: fixedRun.result.ok,
111
+ findings: fixedRun.result.findings,
112
+ fixed: fixedRun.fixed,
113
+ });
114
+ }
115
+ else {
116
+ const result = checkPage(document, options);
117
+ reports.push({ file, ok: result.ok, findings: result.findings });
118
+ }
119
+ }
120
+ if (json) {
121
+ io.out(JSON.stringify({ ok: reports.every((r) => r.ok), files: reports }, null, 2));
122
+ }
123
+ else {
124
+ for (const report of reports) {
125
+ for (const done of report.fixed ?? [])
126
+ io.out(`${report.file}: fixed ${done.rule} at ${done.path}`);
127
+ if (report.findings.length === 0) {
128
+ io.out(`${report.file}: no findings`);
129
+ continue;
130
+ }
131
+ for (const found of report.findings)
132
+ io.out(`${report.file}: ${formatFinding(found)}`);
133
+ }
134
+ }
135
+ if (github) {
136
+ for (const report of reports) {
137
+ for (const found of report.findings) {
138
+ const level = found.severity === 'error' ? 'error' : 'warning';
139
+ io.out(`::${level} file=${escapeProperty(report.file)},title=${escapeProperty(found.rule)}::` +
140
+ escapeData(`${found.path}: ${found.message} Fix: ${found.fix}`));
141
+ }
142
+ }
143
+ }
144
+ return reports.every((r) => r.ok) ? 0 : 1;
145
+ }
@@ -0,0 +1,166 @@
1
+ import { type ClientTarget } from './negotiate.js';
2
+ export type CheckSeverity = 'error' | 'warning';
3
+ export interface CheckFinding {
4
+ /** A stable id, `<family>.<name>`: what a test, a CI log and the builder all match on. */
5
+ rule: string;
6
+ severity: CheckSeverity;
7
+ /**
8
+ * Where, as a property path from the document's root: `children[2].value`,
9
+ * `tree.children[0].onPress.action`. The same grammar as negotiate's fallbacks.
10
+ */
11
+ path: string;
12
+ message: string;
13
+ /** What to do instead, in one sentence. */
14
+ fix: string;
15
+ /** `fixPage` (and `keemakr-ui check --fix`) can make this change itself. */
16
+ fixable?: true;
17
+ /** For a reach finding: the client and release that gets the fallback. */
18
+ client?: string;
19
+ }
20
+ /** What a company has installed, read by the caller before the check. */
21
+ export interface PageBindings {
22
+ /** The names of the company's installed datasets a `dataset` node may show. */
23
+ datasets: readonly string[];
24
+ /** The action ids a press or a form may call: declared by an installed Pack, by stable id. */
25
+ actions: readonly string[];
26
+ }
27
+ /** The part of `catalog.json` the checker reads. Pass the whole catalog; nothing else is used. */
28
+ export interface CheckCatalog {
29
+ catalogId: string;
30
+ nodeTypes: readonly string[];
31
+ }
32
+ export interface CheckOptions {
33
+ /**
34
+ * The catalog the page is checked against. Unknown node types are read from it, and a page that
35
+ * names another `catalogId` is flagged. Omitted: this package's own node list.
36
+ */
37
+ catalog?: CheckCatalog;
38
+ /**
39
+ * The clients whose reach is checked, each at its newest release unless a version is named.
40
+ * Default: web and mobile, the clients that draw screens. `[]` skips the reach rules.
41
+ */
42
+ clients?: readonly (ClientTarget | {
43
+ client: ClientTarget;
44
+ version: string;
45
+ })[];
46
+ /** Run the binding rules against these. Omitted: they do not run. */
47
+ bindings?: PageBindings;
48
+ }
49
+ export interface CheckResult {
50
+ /** No errors. Warnings do not make a page fail. */
51
+ ok: boolean;
52
+ errors: number;
53
+ warnings: number;
54
+ /** Errors first, then by path, then by rule: the same input always lists the same way. */
55
+ findings: CheckFinding[];
56
+ }
57
+ /** Every rule, with its severity and what it means: for the CLI's `--rules` and the catalog tool. */
58
+ export declare const CHECK_RULES: {
59
+ readonly 'schema.invalid': {
60
+ readonly severity: "error";
61
+ readonly summary: "The tree does not parse as core parses it.";
62
+ };
63
+ readonly 'schema.unknown_node': {
64
+ readonly severity: "error";
65
+ readonly summary: "A node type the catalog does not have.";
66
+ };
67
+ readonly 'limit.exceeded': {
68
+ readonly severity: "error";
69
+ readonly summary: "A field is over its cap in NODE_LIMITS.";
70
+ };
71
+ readonly 'binding.dataset_unknown': {
72
+ readonly severity: "error";
73
+ readonly summary: "A dataset node names a dataset the company has not installed.";
74
+ };
75
+ readonly 'binding.action_undeclared': {
76
+ readonly severity: "error";
77
+ readonly summary: "A press or a form calls an action id no installed Pack declares.";
78
+ };
79
+ readonly 'catalog.mismatch': {
80
+ readonly severity: "warning";
81
+ readonly summary: "The page names a catalog other than the one it is checked against.";
82
+ };
83
+ readonly 'reach.fallback': {
84
+ readonly severity: "warning";
85
+ readonly summary: "A client's newest release gets a fallback in place of the node.";
86
+ };
87
+ readonly 'workaround.empty_text': {
88
+ readonly severity: "warning";
89
+ readonly summary: "An empty text node used as a spacer.";
90
+ };
91
+ readonly 'workaround.text_alert': {
92
+ readonly severity: "warning";
93
+ readonly summary: "A warning or a note written as text with a sign in front.";
94
+ };
95
+ readonly 'workaround.markdown_link': {
96
+ readonly severity: "warning";
97
+ readonly summary: "A markdown node that holds only one link.";
98
+ };
99
+ readonly 'workaround.on_off_select': {
100
+ readonly severity: "warning";
101
+ readonly summary: "A select with only On and Off (or Yes and No).";
102
+ };
103
+ readonly 'workaround.key_value_table': {
104
+ readonly severity: "warning";
105
+ readonly summary: "A two-column table of labels and values.";
106
+ };
107
+ readonly 'a11y.disabled_without_reason': {
108
+ readonly severity: "warning";
109
+ readonly summary: "A disabled control that does not say why.";
110
+ };
111
+ readonly 'check.truncated': {
112
+ readonly severity: "warning";
113
+ readonly summary: "Too many findings: only the first are listed (CHECK_LIMITS.findings).";
114
+ };
115
+ };
116
+ export type CheckRuleId = keyof typeof CHECK_RULES;
117
+ /**
118
+ * Bounds on the work one check does, because a document can come from anyone allowed to call it
119
+ * (an agent over MCP). No real page comes near them: the schema itself nests a few levels and its
120
+ * keys are short. Past `depth` the walks stop; a key longer than `keyLength` is not a schema key
121
+ * and is not walked into; past `findings` the list is cut (the counts stay exact) and
122
+ * `check.truncated` says so.
123
+ */
124
+ export declare const CHECK_LIMITS: {
125
+ readonly depth: 32;
126
+ readonly keyLength: 64;
127
+ readonly findings: 500;
128
+ };
129
+ type Json = Record<string, unknown>;
130
+ export interface PlacedNode {
131
+ node: Json;
132
+ path: string;
133
+ /** Put another node in this one's place (the fixers). */
134
+ replace(next: Json): void;
135
+ /** The list that holds the node, and its position there (page edits). */
136
+ list: unknown[];
137
+ index: number;
138
+ /**
139
+ * In a table row's `expand`, which takes content nodes only: a fixer must not put a node
140
+ * there that the schema refuses in that place, so nothing is replaced in it.
141
+ */
142
+ inExpand: boolean;
143
+ }
144
+ /**
145
+ * Every node of the tree where a node can stand: the tree's children, a section's, each tab's and
146
+ * a table row's `expand`. Read from the raw input, so a tree that fails the schema elsewhere is
147
+ * still walked. The page format (page.ts) stamps node ids over the same walk.
148
+ */
149
+ export declare function placedNodes(tree: unknown, base: string): PlacedNode[];
150
+ /**
151
+ * Check a screen tree, or a page that wraps one, before it is published. Never throws on bad
152
+ * input: an unparseable document is a finding.
153
+ */
154
+ export declare function checkPage(document: unknown, options?: CheckOptions): CheckResult;
155
+ /**
156
+ * Make the changes the checker knows to be safe (each finding marked `fixable`) on a copy of the
157
+ * document, then check the copy. The input is never changed.
158
+ */
159
+ export declare function fixPage(document: unknown, options?: CheckOptions): {
160
+ document: unknown;
161
+ fixed: CheckFinding[];
162
+ result: CheckResult;
163
+ };
164
+ /** One line per finding, for a terminal or a CI log. */
165
+ export declare function formatFinding(finding: CheckFinding): string;
166
+ export {};