@cagov/ca-ds 0.0.0-stage → 1.0.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 (100) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +600 -2
  3. package/bin/ca-ds.js +5 -0
  4. package/package.json +62 -4
  5. package/src/cli/add.js +134 -0
  6. package/src/cli/build.js +15 -0
  7. package/src/cli/diff.js +39 -0
  8. package/src/cli/eject.js +112 -0
  9. package/src/cli/exit.js +22 -0
  10. package/src/cli/format.js +52 -0
  11. package/src/cli/init.js +148 -0
  12. package/src/cli/install.js +178 -0
  13. package/src/cli/items.js +10 -0
  14. package/src/cli/login.js +331 -0
  15. package/src/cli/main.js +108 -0
  16. package/src/cli/new.js +230 -0
  17. package/src/cli/outdated.js +74 -0
  18. package/src/cli/pack.js +75 -0
  19. package/src/cli/preview.js +31 -0
  20. package/src/cli/publish.js +295 -0
  21. package/src/cli/pull.js +208 -0
  22. package/src/cli/remote.js +52 -0
  23. package/src/cli/remove.js +69 -0
  24. package/src/cli/update.js +223 -0
  25. package/src/cli/validate.js +131 -0
  26. package/src/lib/browser.js +12 -0
  27. package/src/lib/build.js +249 -0
  28. package/src/lib/bundle.js +148 -0
  29. package/src/lib/catalog.js +44 -0
  30. package/src/lib/checks.js +31 -0
  31. package/src/lib/collection.js +65 -0
  32. package/src/lib/emblem.js +29 -0
  33. package/src/lib/fixtures.js +59 -0
  34. package/src/lib/floor.js +79 -0
  35. package/src/lib/glyph.js +148 -0
  36. package/src/lib/image.js +138 -0
  37. package/src/lib/json-text.js +213 -0
  38. package/src/lib/keys.js +322 -0
  39. package/src/lib/links.js +321 -0
  40. package/src/lib/markdown.js +408 -0
  41. package/src/lib/merge.js +93 -0
  42. package/src/lib/pack.js +30 -0
  43. package/src/lib/page-schema.js +368 -0
  44. package/src/lib/page.js +372 -0
  45. package/src/lib/patch.js +9 -0
  46. package/src/lib/regions.js +173 -0
  47. package/src/lib/registry.js +371 -0
  48. package/src/lib/release.js +119 -0
  49. package/src/lib/repoints.js +120 -0
  50. package/src/lib/resolve.js +32 -0
  51. package/src/lib/schema.js +28 -0
  52. package/src/lib/serial.js +4 -0
  53. package/src/lib/serialize.js +444 -0
  54. package/src/lib/structured.js +72 -0
  55. package/src/lib/system.js +13 -0
  56. package/src/lib/targets.js +85 -0
  57. package/src/lib/terms.js +11 -0
  58. package/src/lib/token-view.js +289 -0
  59. package/src/lib/tokens.js +247 -0
  60. package/src/lib/version.js +34 -0
  61. package/src/preview/frame.js +75 -0
  62. package/src/preview/pages.js +128 -0
  63. package/src/preview/preview.css +58 -0
  64. package/src/preview/screenshots.js +72 -0
  65. package/src/preview/server.js +378 -0
  66. package/src/preview/shell.js +153 -0
  67. package/src/schema/a11y.schema.json +56 -0
  68. package/src/schema/collection.lock.schema.json +58 -0
  69. package/src/schema/collection.schema.json +65 -0
  70. package/src/schema/composition.schema.json +98 -0
  71. package/src/schema/contract.schema.json +116 -0
  72. package/src/schema/interface.schema.json +257 -0
  73. package/src/schema/item.schema.json +362 -0
  74. package/src/schema/release.schema.json +39 -0
  75. package/src/schema/system.schema.json +75 -0
  76. package/src/schema/variants.schema.json +60 -0
  77. package/src/validate/collection.js +19 -0
  78. package/src/validate/collisions.js +124 -0
  79. package/src/validate/context.js +357 -0
  80. package/src/validate/facts.js +253 -0
  81. package/src/validate/files.js +103 -0
  82. package/src/validate/findings.js +19 -0
  83. package/src/validate/glyphs.js +126 -0
  84. package/src/validate/html.js +215 -0
  85. package/src/validate/imports.js +29 -0
  86. package/src/validate/index.js +75 -0
  87. package/src/validate/item.js +47 -0
  88. package/src/validate/links.js +113 -0
  89. package/src/validate/manifest.js +147 -0
  90. package/src/validate/media.js +65 -0
  91. package/src/validate/page.js +74 -0
  92. package/src/validate/prefixes.js +58 -0
  93. package/src/validate/relations.js +310 -0
  94. package/src/validate/release.js +109 -0
  95. package/src/validate/skill.js +122 -0
  96. package/src/validate/structured.js +335 -0
  97. package/src/validate/tasc.js +80 -0
  98. package/src/validate/template.js +129 -0
  99. package/src/validate/tokens.js +154 -0
  100. package/src/validate/zip.js +40 -0
@@ -0,0 +1,153 @@
1
+ const esc = (s) =>
2
+ String(s).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
3
+
4
+ export function renderIndex(groups, name) {
5
+ const sections = [...groups.entries()]
6
+ .map(([group, pages]) => {
7
+ const items = pages
8
+ .map(
9
+ (p) =>
10
+ ` <li><span class="kind">${p.kind}</span> <a href="/preview/${esc(p.route)}">${esc(p.title)}</a> <code>${esc(p.file)}</code></li>`,
11
+ )
12
+ .join('\n');
13
+ return ` <section>
14
+ <h2>${esc(group)}</h2>
15
+ <ul>\n${items}\n </ul>
16
+ </section>`;
17
+ })
18
+ .join('\n');
19
+
20
+ return `<!doctype html>
21
+ <html lang="en">
22
+ <head>
23
+ <meta charset="utf-8">
24
+ <meta name="viewport" content="width=device-width, initial-scale=1">
25
+ <title>Previews: ${esc(name)}</title>
26
+ <style>${INDEX_CSS}</style>
27
+ </head>
28
+ <body>
29
+ <h1>Previews</h1>
30
+ <p><code>${esc(name)}</code></p>
31
+ <main>
32
+ ${sections}
33
+ </main>
34
+ </body>
35
+ </html>
36
+ `;
37
+ }
38
+
39
+ export function renderShell(page) {
40
+ return `<!doctype html>
41
+ <html lang="en">
42
+ <head>
43
+ <meta charset="utf-8">
44
+ <meta name="viewport" content="width=device-width, initial-scale=1">
45
+ <title>${esc(page.title)}: preview</title>
46
+ <style>${SHELL_CSS}</style>
47
+ </head>
48
+ <body>
49
+ <header class="bar">
50
+ <a class="back" href="/">&larr; all previews</a>
51
+ <span class="title">${esc(page.title)}</span>
52
+ <code class="path">${esc(page.route)}</code>
53
+ <span class="spacer"></span>
54
+ <span class="widths" role="group" aria-label="Viewport width">
55
+ <button type="button" data-w="400">400</button>
56
+ <button type="button" data-w="768">768</button>
57
+ <button type="button" data-w="1024">1024</button>
58
+ <button type="button" data-w="0" class="active">Full</button>
59
+ </span>
60
+ <button type="button" id="theme">Dark</button>
61
+ </header>
62
+ <div class="stage">
63
+ <iframe id="frame" title="${esc(page.title)}" src="/frame/${esc(page.route)}"></iframe>
64
+ </div>
65
+ <pre id="overlay" hidden></pre>
66
+ <script>${SHELL_JS}</script>
67
+ </body>
68
+ </html>
69
+ `;
70
+ }
71
+
72
+ // Built CSS first in <head>, so the page's own sheets follow and win.
73
+ export function renderDocument(page) {
74
+ const links = ['/assets/tokens.css', '/assets/bundle.css'].map((href) => `\n <link rel="stylesheet" href="${href}">`).join('');
75
+ const script = ' <script type="module" src="/assets/bundle.js"></script>\n';
76
+ let html = page.body;
77
+ if (/<head[^>]*>/i.test(html)) html = html.replace(/<head[^>]*>/i, (tag) => tag + links);
78
+ else html = html.replace(/<html[^>]*>/i, (tag) => `${tag}\n<head>${links}\n</head>`);
79
+ return /<\/body>/i.test(html) ? html.replace(/<\/body>(?![\s\S]*<\/body>)/i, `${script}</body>`) : html + script;
80
+ }
81
+
82
+ const INDEX_CSS = `
83
+ :root { color-scheme: light dark; }
84
+ body { font-family: system-ui, sans-serif; max-inline-size: 42rem; margin: 3rem auto; padding-inline: 1.5rem; line-height: 1.5; }
85
+ h1 { font-size: 1.5rem; }
86
+ h2 { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; color: #888; margin-block: 2rem 0.5rem; }
87
+ ul { list-style: none; padding: 0; margin: 0; }
88
+ li { padding: 0.35rem 0; border-block-end: 1px solid #e5e5e5; }
89
+ a { color: #0050a0; text-decoration: none; }
90
+ a:hover { text-decoration: underline; }
91
+ code { color: #999; font-size: 0.8em; }
92
+ .kind { color: #888; font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.05em; }
93
+ `;
94
+
95
+ const SHELL_CSS = `
96
+ * { box-sizing: border-box; }
97
+ html, body { height: 100%; margin: 0; }
98
+ body { display: flex; flex-direction: column; font-family: system-ui, sans-serif; }
99
+ .bar { display: flex; align-items: center; gap: 0.75rem; padding: 0.5rem 0.75rem; border-block-end: 1px solid #ddd; background: #fafafa; font-size: 0.8rem; }
100
+ .bar .title { font-weight: 600; }
101
+ .bar .path { color: #999; }
102
+ .bar .spacer { flex: 1; }
103
+ .bar a { color: #0050a0; text-decoration: none; }
104
+ .widths { display: inline-flex; gap: 2px; }
105
+ .bar button { font: inherit; font-size: 0.75rem; padding: 0.2rem 0.5rem; border: 1px solid #ccc; background: #fff; cursor: pointer; border-radius: 3px; }
106
+ .bar button.active { background: #0050a0; color: #fff; border-color: #0050a0; }
107
+ .stage { flex: 1; overflow: auto; display: flex; justify-content: center; background: #f0f0f0; }
108
+ iframe { width: 100%; height: 100%; border: 0; background: #fff; }
109
+ #overlay { position: fixed; inset: auto 1rem 1rem 1rem; max-height: 40vh; overflow: auto; margin: 0; padding: 1rem; background: #2b0a0a; color: #ffb4b4; border: 1px solid #ff6b6b; border-radius: 4px; white-space: pre-wrap; font-size: 0.8rem; }
110
+ `;
111
+
112
+ const SHELL_JS = `
113
+ const frame = document.getElementById('frame');
114
+ const overlay = document.getElementById('overlay');
115
+ // The frame starts in the OS color scheme, and the toggle flips it.
116
+ const themeButton = document.getElementById('theme');
117
+ let theme = matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
118
+ themeButton.textContent = theme === 'light' ? 'Dark' : 'Light';
119
+
120
+ // Re-apply chrome-controlled state after every (re)load of the frame doc.
121
+ function applyState() {
122
+ try {
123
+ const doc = frame.contentDocument;
124
+ if (doc) doc.documentElement.style.colorScheme = theme;
125
+ } catch (e) {}
126
+ }
127
+ frame.addEventListener('load', applyState);
128
+
129
+ themeButton.addEventListener('click', (e) => {
130
+ theme = theme === 'light' ? 'dark' : 'light';
131
+ e.target.textContent = theme === 'light' ? 'Dark' : 'Light';
132
+ applyState();
133
+ });
134
+
135
+ document.querySelectorAll('.widths button').forEach((b) => {
136
+ b.addEventListener('click', () => {
137
+ document.querySelectorAll('.widths button').forEach((x) => x.classList.remove('active'));
138
+ b.classList.add('active');
139
+ const w = Number(b.dataset.w);
140
+ frame.style.width = w ? w + 'px' : '100%';
141
+ });
142
+ });
143
+
144
+ const es = new EventSource('/events');
145
+ es.addEventListener('reload', () => {
146
+ overlay.hidden = true;
147
+ frame.contentWindow.location.reload();
148
+ });
149
+ es.addEventListener('builderror', (e) => {
150
+ overlay.hidden = false;
151
+ overlay.textContent = e.data.replace(/\\\\n/g, '\\n');
152
+ });
153
+ `;
@@ -0,0 +1,56 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "a11y.schema.json",
4
+ "title": "<name>.a11y.json",
5
+ "description": "A component's accessibility notes: the facts that aren't pass/fail rules, under fixed topics. A checkable accessibility requirement is a contract rule tagged a11y, and the docs site's accessibility section shows both.",
6
+ "type": "object",
7
+ "additionalProperties": false,
8
+ "minProperties": 1,
9
+ "properties": {
10
+ "$comment": {
11
+ "description": "A note for maintainers. It carries no data.",
12
+ "type": "string"
13
+ },
14
+ "semantics": {
15
+ "description": "The native element the component rests on, and what ARIA it adds, if any.",
16
+ "$ref": "#/$defs/notes"
17
+ },
18
+ "keyboard": {
19
+ "description": "Only where the keyboard model departs from the native element's.",
20
+ "$ref": "#/$defs/notes"
21
+ },
22
+ "screen-reader": {
23
+ "description": "Only where the announcement departs from the native element's, or varies by browser and assistive technology.",
24
+ "$ref": "#/$defs/notes"
25
+ },
26
+ "motion": { "$ref": "#/$defs/notes" },
27
+ "contrast": {
28
+ "description": "Claims, never hand-measured ratios. A ratio restates token values and goes stale.",
29
+ "$ref": "#/$defs/notes"
30
+ }
31
+ },
32
+ "$defs": {
33
+ "notes": {
34
+ "type": "array",
35
+ "minItems": 1,
36
+ "items": {
37
+ "type": "object",
38
+ "additionalProperties": false,
39
+ "required": ["note"],
40
+ "properties": {
41
+ "note": {
42
+ "description": "A sentence or two.",
43
+ "type": "string",
44
+ "minLength": 1
45
+ },
46
+ "wcag": {
47
+ "type": "array",
48
+ "minItems": 1,
49
+ "uniqueItems": true,
50
+ "items": { "type": "string", "pattern": "^[1-4]\\.[0-9]+\\.[0-9]+$" }
51
+ }
52
+ }
53
+ }
54
+ }
55
+ }
56
+ }
@@ -0,0 +1,58 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "collection.lock.schema.json",
4
+ "title": "collection.lock.json",
5
+ "description": "What a collection's request resolved to: every installed item at its exact version, with the hash of each file it was installed with. A collection that installs nothing holds an empty lock.",
6
+ "type": "object",
7
+ "additionalProperties": false,
8
+ "required": ["release", "items"],
9
+ "properties": {
10
+ "$comment": { "type": "string" },
11
+ "release": {
12
+ "description": "The system release the items resolved against, or null.",
13
+ "oneOf": [{ "type": "null" }, { "$ref": "system.schema.json#/$defs/tag" }]
14
+ },
15
+ "foundation": {
16
+ "description": "The foundation the items resolved with, in load order, which leads a build's order and a validation's set when the collection has no system.json. Absent, the collection has none.",
17
+ "type": "array",
18
+ "uniqueItems": true,
19
+ "items": { "$ref": "system.schema.json#/$defs/scopedName" }
20
+ },
21
+ "items": {
22
+ "description": "Each installed item, by scoped name.",
23
+ "type": "object",
24
+ "propertyNames": { "$ref": "system.schema.json#/$defs/scopedName" },
25
+ "additionalProperties": { "$ref": "#/$defs/installed" }
26
+ }
27
+ },
28
+ "$defs": {
29
+ "installed": {
30
+ "type": "object",
31
+ "additionalProperties": false,
32
+ "required": ["version", "path", "requested", "files"],
33
+ "properties": {
34
+ "version": { "$ref": "system.schema.json#/$defs/semver" },
35
+ "path": {
36
+ "description": "The item's folder, relative to the collection's folder. A skill's is the first skills folder's copy, which each later folder links to.",
37
+ "$ref": "item.schema.json#/$defs/path"
38
+ },
39
+ "requested": {
40
+ "description": "True for an item collection.json asks for, and false for one pulled in as a dependency.",
41
+ "type": "boolean"
42
+ },
43
+ "links": {
44
+ "description": "A skill's links and copies in the later skills folders, each relative to the collection's folder, as the install made them. remove, update, and eject touch these alone, each only while it is still a link to the skill's folder or a copy carrying the .ca-ds-copy marker.",
45
+ "type": "array",
46
+ "uniqueItems": true,
47
+ "items": { "$ref": "item.schema.json#/$defs/path" }
48
+ },
49
+ "files": {
50
+ "description": "The baseline a diff and an update compare against: the SHA-256 of each file as installed, in lowercase hex, by item-relative path.",
51
+ "type": "object",
52
+ "propertyNames": { "$ref": "item.schema.json#/$defs/path" },
53
+ "additionalProperties": { "type": "string", "pattern": "^[0-9a-f]{64}$" }
54
+ }
55
+ }
56
+ }
57
+ }
58
+ }
@@ -0,0 +1,65 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "collection.schema.json",
4
+ "title": "collection.json",
5
+ "description": "What a collection asks for: the registry it reads, the namespaces it authors, and the items it installs. collection.lock.json records what resolved.",
6
+ "type": "object",
7
+ "additionalProperties": false,
8
+ "properties": {
9
+ "$comment": { "type": "string" },
10
+ "registry": {
11
+ "description": "The registry's base URL. CA_DS_URL overrides it, and the skill's production host is the default.",
12
+ "type": "string",
13
+ "pattern": "^https?://"
14
+ },
15
+ "namespaces": {
16
+ "description": "The namespaces the collection authors. An item whose scope is one of them is authored here, and the collection may publish it.",
17
+ "type": "array",
18
+ "uniqueItems": true,
19
+ "items": { "$ref": "#/$defs/namespace" }
20
+ },
21
+ "release": {
22
+ "description": "The system release the installed items resolve against, v<semver>.",
23
+ "$ref": "system.schema.json#/$defs/tag"
24
+ },
25
+ "items": {
26
+ "description": "The items asked for, each with a semver range.",
27
+ "type": "object",
28
+ "propertyNames": { "$ref": "system.schema.json#/$defs/scopedName" },
29
+ "additionalProperties": { "$ref": "item.schema.json#/$defs/range" }
30
+ },
31
+ "presets": {
32
+ "description": "Named subsets of the collection's items, for a build of one.",
33
+ "type": "object",
34
+ "propertyNames": { "pattern": "^[a-z0-9]+(-[a-z0-9]+)*$" },
35
+ "additionalProperties": { "$ref": "system.schema.json#/$defs/preset" }
36
+ },
37
+ "pages": {
38
+ "description": "Globs of the consumer's own HTML pages, relative to the collection's folder.",
39
+ "type": "array",
40
+ "items": { "type": "string", "minLength": 1 }
41
+ },
42
+ "install": {
43
+ "description": "The folder an installed item is written to, as <install>/<scope>/<name>/. items by default.",
44
+ "$ref": "item.schema.json#/$defs/path"
45
+ },
46
+ "skills": {
47
+ "description": "The folders an installed skill is written to. The first holds its files, as <folder>/<skill name>/, and each later one a link to it. .agents/skills and .claude/skills by default.",
48
+ "type": "array",
49
+ "minItems": 1,
50
+ "uniqueItems": true,
51
+ "items": { "$ref": "item.schema.json#/$defs/path" }
52
+ },
53
+ "dist": {
54
+ "description": "The folder the build writes to. dist by default.",
55
+ "$ref": "item.schema.json#/$defs/path"
56
+ }
57
+ },
58
+ "$defs": {
59
+ "namespace": {
60
+ "description": "A scope, the part of a scoped name before the slash.",
61
+ "type": "string",
62
+ "pattern": "^[a-z0-9]+(-[a-z0-9]+)*$"
63
+ }
64
+ }
65
+ }
@@ -0,0 +1,98 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "composition.schema.json",
4
+ "title": "<page-type>.composition.json",
5
+ "description": "A template's composition: the intent of each region of its page, the variations a page of its type may take, and what no component covers yet. A region's components are derived from the page, never stored here.",
6
+ "type": "object",
7
+ "additionalProperties": false,
8
+ "required": ["regions"],
9
+ "properties": {
10
+ "$comment": {
11
+ "description": "A note for maintainers. It carries no data.",
12
+ "type": "string"
13
+ },
14
+ "regions": {
15
+ "description": "One record per region of the page, in document order. A region is each slotted child of ca-layout, the header, each direct child of main, and the footer. The validator holds the count against the page.",
16
+ "type": "array",
17
+ "minItems": 1,
18
+ "items": { "$ref": "#/$defs/region" }
19
+ },
20
+ "variations": {
21
+ "type": "array",
22
+ "minItems": 1,
23
+ "items": { "$ref": "#/$defs/variation" }
24
+ },
25
+ "gaps": {
26
+ "type": "array",
27
+ "minItems": 1,
28
+ "items": { "$ref": "#/$defs/gap" }
29
+ }
30
+ },
31
+ "$defs": {
32
+ "text": { "type": "string", "minLength": 1 },
33
+ "id": {
34
+ "description": "Unique within its array.",
35
+ "type": "string",
36
+ "pattern": "^[a-z0-9]+(-[a-z0-9]+)*$"
37
+ },
38
+ "pointer": {
39
+ "description": "A link target, an item's scoped name, a #, and an anchor of its page, or a repo path from the root, with no leading slash and no parent segment, and optionally a # and a record id.",
40
+ "type": "string",
41
+ "minLength": 1,
42
+ "pattern": "^(?!/)(?!.*(^|/)\\.\\.(/|$))[^\\s\\\\#]+(#[^\\s#]+)?$"
43
+ },
44
+ "region": {
45
+ "type": "object",
46
+ "additionalProperties": false,
47
+ "required": ["id", "title", "contents"],
48
+ "properties": {
49
+ "id": { "$ref": "#/$defs/id" },
50
+ "title": { "$ref": "#/$defs/text" },
51
+ "contents": {
52
+ "description": "The region's intent, what a real page puts there in place of the example's placeholder content.",
53
+ "$ref": "#/$defs/text"
54
+ }
55
+ }
56
+ },
57
+ "variation": {
58
+ "type": "object",
59
+ "additionalProperties": false,
60
+ "required": ["id", "region", "see", "use"],
61
+ "properties": {
62
+ "id": { "$ref": "#/$defs/id" },
63
+ "region": {
64
+ "description": "The id of the region the variation changes.",
65
+ "$ref": "#/$defs/id"
66
+ },
67
+ "see": {
68
+ "description": "The variant or interface record the variation takes, as a link target to it, its item's scoped name, a #, and the record's anchor, or as a repo path to its file, a #, and its id. It points and never restates.",
69
+ "type": "string",
70
+ "pattern": "^([a-z0-9][a-z0-9-]*/[a-z0-9][a-z0-9-]*#[a-z0-9]+(-[a-z0-9]+)*|(?!/)(?!.*(^|/)\\.\\.(/|$))[^\\s\\\\#]+\\.(variants|interface)\\.json#[^\\s#]+)$"
71
+ },
72
+ "use": {
73
+ "description": "When a page of the type takes it.",
74
+ "$ref": "#/$defs/text"
75
+ },
76
+ "avoid": {
77
+ "description": "When not to. It links a contract rule rather than restating one.",
78
+ "$ref": "#/$defs/text"
79
+ }
80
+ }
81
+ },
82
+ "gap": {
83
+ "type": "object",
84
+ "additionalProperties": false,
85
+ "required": ["need"],
86
+ "properties": {
87
+ "need": {
88
+ "description": "What a page of the type needs that no component covers yet.",
89
+ "$ref": "#/$defs/text"
90
+ },
91
+ "see": {
92
+ "description": "The record or file nearest the need, such as the contract rule that rules it out.",
93
+ "$ref": "#/$defs/pointer"
94
+ }
95
+ }
96
+ }
97
+ }
98
+ }
@@ -0,0 +1,116 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "contract.schema.json",
4
+ "title": "<name>.contract.json",
5
+ "description": "A component's contract: the rules its generated output must and should satisfy. The validator runs each rule's check over the item's examples, and the verify tool runs it over a consumer's page.",
6
+ "type": "object",
7
+ "additionalProperties": false,
8
+ "required": ["rules"],
9
+ "properties": {
10
+ "$comment": {
11
+ "description": "A note for maintainers. It carries no data.",
12
+ "type": "string"
13
+ },
14
+ "rules": {
15
+ "type": "array",
16
+ "minItems": 1,
17
+ "items": { "$ref": "#/$defs/rule" }
18
+ },
19
+ "waives": {
20
+ "description": "The rules of a base a remix waives. A waived rule drops each failing element that is, or sits inside, an element matching the remix's key. A standard item carries none.",
21
+ "type": "array",
22
+ "minItems": 1,
23
+ "items": { "$ref": "#/$defs/waiver" }
24
+ }
25
+ },
26
+ "$defs": {
27
+ "text": { "type": "string", "minLength": 1 },
28
+ "id": {
29
+ "description": "Unique within the file, and cited as <item>/<id>, such as standard/button/icon-only-named.",
30
+ "type": "string",
31
+ "pattern": "^[a-z0-9]+(-[a-z0-9]+)*$"
32
+ },
33
+ "selector": {
34
+ "description": "A CSS selector, :has() included, matched against the whole document.",
35
+ "type": "string",
36
+ "minLength": 1
37
+ },
38
+ "rule": {
39
+ "type": "object",
40
+ "additionalProperties": false,
41
+ "required": ["id", "rule", "severity", "tags"],
42
+ "properties": {
43
+ "id": { "$ref": "#/$defs/id" },
44
+ "rule": {
45
+ "description": "A declarative pass condition, written so that output either meets it or doesn't.",
46
+ "$ref": "#/$defs/text"
47
+ },
48
+ "severity": {
49
+ "description": "must: every failure is fixed. should: a failure may stand with a noted reason. Sharpen a soft rule into a must, or move it to a variant's avoid, before writing a should.",
50
+ "enum": ["must", "should"]
51
+ },
52
+ "tags": {
53
+ "type": "array",
54
+ "minItems": 1,
55
+ "uniqueItems": true,
56
+ "items": { "enum": ["a11y", "structure", "tokens", "content", "behavior"] }
57
+ },
58
+ "wcag": {
59
+ "description": "The WCAG success criteria the rule serves, by number.",
60
+ "type": "array",
61
+ "minItems": 1,
62
+ "uniqueItems": true,
63
+ "items": { "type": "string", "pattern": "^[1-4]\\.[0-9]+\\.[0-9]+$" }
64
+ },
65
+ "why": {
66
+ "description": "One sentence on what breaks without the rule. The full rationale lives in the folder's notes.md.",
67
+ "$ref": "#/$defs/text"
68
+ },
69
+ "check": { "$ref": "#/$defs/check" }
70
+ },
71
+ "allOf": [
72
+ {
73
+ "description": "A should rule says why, which tells an agent when breaking it is fine.",
74
+ "if": { "properties": { "severity": { "const": "should" } } },
75
+ "then": { "required": ["why"] }
76
+ }
77
+ ]
78
+ },
79
+ "waiver": {
80
+ "type": "object",
81
+ "additionalProperties": false,
82
+ "required": ["rule", "why"],
83
+ "properties": {
84
+ "rule": {
85
+ "description": "The waived rule, cited as <scope>/<name>/<id>, such as standard/layout/format-selects.",
86
+ "type": "string",
87
+ "pattern": "^[a-z0-9]+(-[a-z0-9]+)*/[a-z0-9]+(-[a-z0-9]+)*/[a-z0-9]+(-[a-z0-9]+)*$"
88
+ },
89
+ "why": {
90
+ "description": "One sentence on why the rule doesn't hold under the remix's key.",
91
+ "$ref": "#/$defs/text"
92
+ }
93
+ }
94
+ },
95
+ "check": {
96
+ "description": "A selector assertion over the document. none passes when nothing matches. each with has passes when every element each matches also matches has. A rule no selector can decide carries no check, and the agent judges it.",
97
+ "oneOf": [
98
+ {
99
+ "type": "object",
100
+ "additionalProperties": false,
101
+ "required": ["none"],
102
+ "properties": { "none": { "$ref": "#/$defs/selector" } }
103
+ },
104
+ {
105
+ "type": "object",
106
+ "additionalProperties": false,
107
+ "required": ["each", "has"],
108
+ "properties": {
109
+ "each": { "$ref": "#/$defs/selector" },
110
+ "has": { "$ref": "#/$defs/selector" }
111
+ }
112
+ }
113
+ ]
114
+ }
115
+ }
116
+ }