@reqvire-org/ads 0.3.52 → 0.4.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 (151) hide show
  1. package/README.md +10 -9
  2. package/dist/assets.mjs +16 -2
  3. package/dist/behaviors.mjs +6 -5
  4. package/dist/boundaries.mjs +5 -5
  5. package/dist/browser-audit/first-render.mjs +22 -0
  6. package/dist/browser-audit/image-shape.mjs +36 -0
  7. package/dist/browser-audit/render-states.mjs +61 -35
  8. package/dist/browser-audit/worker.mjs +47 -12
  9. package/dist/browser-audit.mjs +75 -12
  10. package/dist/bun-compiler.mjs +14 -7
  11. package/dist/check-service.mjs +83 -0
  12. package/dist/check.mjs +20 -18
  13. package/dist/cli.mjs +5 -3
  14. package/dist/config.mjs +20 -41
  15. package/dist/contracts.d.mts +9 -0
  16. package/dist/finding-rules.mjs +8 -1
  17. package/dist/font-rules.mjs +103 -0
  18. package/dist/fonts-generated.mjs +32 -12
  19. package/dist/generated-entries.mjs +131 -0
  20. package/dist/icons.mjs +1 -1
  21. package/dist/init.mjs +11 -32
  22. package/dist/layers.mjs +7 -3
  23. package/dist/lint-config.mjs +4 -2
  24. package/dist/mcp/catalog.mjs +2 -1
  25. package/dist/mcp/context.mjs +3 -3
  26. package/dist/mcp/drafts.mjs +136 -121
  27. package/dist/mcp/mutations.mjs +65 -19
  28. package/dist/mcp/preview-watch.mjs +31 -5
  29. package/dist/mcp/preview-widget.bundle.js +50 -47
  30. package/dist/mcp/project-widget.bundle.js +45 -42
  31. package/dist/mcp/prompts.mjs +1 -1
  32. package/dist/mcp/server.mjs +81 -40
  33. package/dist/mcp/showcase-host.mjs +20 -7
  34. package/dist/mcp/widget.bundle.js +49 -46
  35. package/dist/oxlint.mjs +3 -2
  36. package/dist/program-cache.mjs +36 -0
  37. package/dist/public-api.mjs +2 -1
  38. package/dist/scenarios-compiler.mjs +82 -14
  39. package/dist/scenarios-vite.mjs +1 -1
  40. package/dist/scenarios.mjs +4 -3
  41. package/dist/showcase/client.bundle.js +27 -27
  42. package/dist/showcase/index.html +2 -2
  43. package/dist/skills/ads-break-ui/SKILL.md +25 -28
  44. package/dist/skills/ads-break-ui/references/behaviors.md +7 -6
  45. package/dist/skills/ads-break-ui/references/captures.md +7 -32
  46. package/dist/skills/ads-break-ui/references/contracts.md +58 -25
  47. package/dist/skills/ads-break-ui/references/drafts.md +59 -43
  48. package/dist/skills/ads-break-ui/references/evidence.md +1 -1
  49. package/dist/skills/ads-break-ui/references/guarded-editing.md +58 -47
  50. package/dist/skills/ads-break-ui/references/review.md +9 -8
  51. package/dist/skills/ads-break-ui/references/scenarios.md +1 -1
  52. package/dist/skills/ads-break-ui/references/validation.md +8 -4
  53. package/dist/skills/ads-break-ui/references/workflows.md +15 -8
  54. package/dist/skills/ads-designer/SKILL.md +30 -31
  55. package/dist/skills/ads-designer/references/accessibility.md +9 -5
  56. package/dist/skills/ads-designer/references/behaviors.md +7 -6
  57. package/dist/skills/ads-designer/references/branding.md +2 -2
  58. package/dist/skills/ads-designer/references/captures.md +7 -32
  59. package/dist/skills/ads-designer/references/cli.md +5 -1
  60. package/dist/skills/ads-designer/references/contracts.md +58 -25
  61. package/dist/skills/ads-designer/references/drafts.md +59 -43
  62. package/dist/skills/ads-designer/references/evidence.md +1 -1
  63. package/dist/skills/ads-designer/references/guarded-editing.md +58 -47
  64. package/dist/skills/ads-designer/references/performance.md +57 -6
  65. package/dist/skills/ads-designer/references/review.md +9 -8
  66. package/dist/skills/ads-designer/references/scenarios.md +1 -1
  67. package/dist/skills/ads-designer/references/validation.md +8 -4
  68. package/dist/skills/ads-designer/references/workflows.md +15 -8
  69. package/dist/skills/ads-import/SKILL.md +25 -28
  70. package/dist/skills/ads-import/references/behaviors.md +7 -6
  71. package/dist/skills/ads-import/references/captures.md +7 -32
  72. package/dist/skills/ads-import/references/cli.md +5 -1
  73. package/dist/skills/ads-import/references/contracts.md +58 -25
  74. package/dist/skills/ads-import/references/drafts.md +59 -43
  75. package/dist/skills/ads-import/references/evidence.md +1 -1
  76. package/dist/skills/ads-import/references/guarded-editing.md +58 -47
  77. package/dist/skills/ads-import/references/review.md +9 -8
  78. package/dist/skills/ads-import/references/scenarios.md +1 -1
  79. package/dist/skills/ads-import/references/validation.md +8 -4
  80. package/dist/skills/ads-import/references/workflows.md +15 -8
  81. package/dist/skills/ads-motion/SKILL.md +25 -28
  82. package/dist/skills/ads-motion/references/behaviors.md +7 -6
  83. package/dist/skills/ads-motion/references/captures.md +7 -32
  84. package/dist/skills/ads-motion/references/contracts.md +58 -25
  85. package/dist/skills/ads-motion/references/drafts.md +59 -43
  86. package/dist/skills/ads-motion/references/evidence.md +1 -1
  87. package/dist/skills/ads-motion/references/guarded-editing.md +58 -47
  88. package/dist/skills/ads-motion/references/review.md +9 -8
  89. package/dist/skills/ads-motion/references/scenarios.md +1 -1
  90. package/dist/skills/ads-motion/references/validation.md +8 -4
  91. package/dist/skills/ads-motion/references/workflows.md +15 -8
  92. package/dist/skills/ads-port/SKILL.md +25 -28
  93. package/dist/skills/ads-port/references/behaviors.md +7 -6
  94. package/dist/skills/ads-port/references/captures.md +7 -32
  95. package/dist/skills/ads-port/references/cli.md +5 -1
  96. package/dist/skills/ads-port/references/contracts.md +58 -25
  97. package/dist/skills/ads-port/references/drafts.md +59 -43
  98. package/dist/skills/ads-port/references/evidence.md +1 -1
  99. package/dist/skills/ads-port/references/guarded-editing.md +58 -47
  100. package/dist/skills/ads-port/references/native-implementation.md +6 -6
  101. package/dist/skills/ads-port/references/review.md +9 -8
  102. package/dist/skills/ads-port/references/scenarios.md +1 -1
  103. package/dist/skills/ads-port/references/validation.md +8 -4
  104. package/dist/skills/ads-port/references/workflows.md +15 -8
  105. package/dist/starters/preact/design-system/components/Layout/Grid/Grid.ads.contract.ts +6 -0
  106. package/dist/starters/preact/design-system/review/token-preview/TokenPreview.ads.contract.ts +6 -0
  107. package/dist/starters/preact/ds.config.json +0 -14
  108. package/dist/starters/react/README.md +9 -5
  109. package/dist/starters/react/design-system/brand/Icons/AppIcon/AppIcon.ads.fixture.ts +1 -1
  110. package/dist/starters/react/design-system/brand/Identity/Logo/Logo.ads.fixture.ts +2 -2
  111. package/dist/starters/react/design-system/components/Actions/Button/Button.ads.exports.ts +1 -0
  112. package/dist/starters/react/design-system/components/Actions/IconButton/IconButton.ads.exports.ts +1 -0
  113. package/dist/starters/react/design-system/components/Content/Icon/Icon.ads.exports.ts +1 -0
  114. package/dist/starters/react/design-system/components/Content/Image/Image.ads.exports.ts +1 -0
  115. package/dist/starters/react/design-system/components/Content/Logo/Logo.ads.exports.ts +1 -0
  116. package/dist/starters/react/design-system/components/Content/Logo/Logo.tsx +2 -2
  117. package/dist/starters/react/design-system/components/Forms/TextField/TextField.ads.exports.ts +1 -0
  118. package/dist/starters/react/design-system/components/Layout/Grid/Grid.ads.contract.ts +6 -0
  119. package/dist/starters/react/design-system/components/Layout/Grid/Grid.ads.exports.ts +1 -0
  120. package/dist/starters/react/design-system/controllers/Palette/Palette.ads.exports.ts +1 -0
  121. package/dist/starters/react/design-system/index.ts +3 -7
  122. package/dist/starters/react/design-system/patterns/Search/SearchBar/SearchBar.ads.exports.ts +1 -0
  123. package/dist/starters/react/design-system/review/brand-preview/BrandPreview.ads.exports.ts +1 -0
  124. package/dist/starters/react/design-system/review/demo-frame/DemoFrame.ads.exports.ts +1 -0
  125. package/dist/starters/react/design-system/review/grid-cell/GridCell.ads.exports.ts +1 -0
  126. package/dist/starters/react/design-system/review/index.ts +4 -3
  127. package/dist/starters/react/design-system/review/screen-frame/ScreenFrame.ads.exports.ts +1 -0
  128. package/dist/starters/react/design-system/review/token-preview/TokenPreview.ads.contract.ts +6 -0
  129. package/dist/starters/react/design-system/review/token-preview/TokenPreview.ads.exports.ts +1 -0
  130. package/dist/starters/react/design-system/styles.css +1 -0
  131. package/dist/starters/react/ds.config.json +0 -14
  132. package/dist/style-boundaries.mjs +7 -6
  133. package/dist/test-boundaries.mjs +2 -2
  134. package/dist/themes-watch.mjs +9 -3
  135. package/dist/token-fixtures.mjs +1 -1
  136. package/dist/unit-contracts.mjs +38 -4
  137. package/dist/units.mjs +16 -91
  138. package/dist/validation-checks.mjs +7 -1
  139. package/docs/ADS.md +10 -10
  140. package/docs/ARCHITECTURE.md +104 -44
  141. package/docs/BEHAVIORS.md +8 -7
  142. package/docs/CACHING.md +15 -6
  143. package/docs/CHANGELOG.md +107 -12
  144. package/docs/COMPARISON.md +1 -1
  145. package/docs/CONTRACTS.md +10 -25
  146. package/docs/GUIDE.md +98 -57
  147. package/docs/MCP.md +116 -151
  148. package/package.json +7 -7
  149. package/dist/contract-migration.mjs +0 -110
  150. package/dist/mcp/draft-exports.mjs +0 -40
  151. package/dist/mcp/edit-preparation.mjs +0 -115
@@ -0,0 +1 @@
1
+ export { SearchBar, type SearchBarProps } from "./SearchBar";
@@ -0,0 +1 @@
1
+ export { BrandPreview } from "./BrandPreview";
@@ -0,0 +1 @@
1
+ export { DemoFrame } from "./DemoFrame";
@@ -0,0 +1 @@
1
+ export { GridCell } from "./GridCell";
@@ -1,5 +1,6 @@
1
- export { TokenPreview } from "./token-preview/TokenPreview";
2
- export { ScreenFrame } from "./screen-frame/ScreenFrame";
3
- export { DemoFrame } from "./demo-frame/DemoFrame";
1
+ // Generated by ADS from each owner's .ads.exports.ts; do not edit. Declare an owner's public names in its exports file.
4
2
  export { BrandPreview } from "./brand-preview/BrandPreview";
3
+ export { DemoFrame } from "./demo-frame/DemoFrame";
5
4
  export { GridCell } from "./grid-cell/GridCell";
5
+ export { ScreenFrame } from "./screen-frame/ScreenFrame";
6
+ export { TokenPreview } from "./token-preview/TokenPreview";
@@ -0,0 +1 @@
1
+ export { ScreenFrame } from "./ScreenFrame";
@@ -0,0 +1,6 @@
1
+ import type { UnitContract } from "@reqvire-org/ads/contracts";
2
+
3
+ export default {
4
+ schemaVersion: 1,
5
+ styles: { writes: { "./TokenPreview.tsx": ["--ux-token-preview-value"] } },
6
+ } satisfies UnitContract;
@@ -0,0 +1 @@
1
+ export { TokenPreview } from "./TokenPreview";
@@ -1,3 +1,4 @@
1
+ /* Generated by ADS from the token sheets present in the token folder, in foundation order; do not edit. */
1
2
  @import "./tokens/colors.css";
2
3
  @import "./tokens/typography.css";
3
4
  @import "./tokens/spacing.css";
@@ -7,20 +7,6 @@
7
7
  "mcp": {
8
8
  "previewManifest": ".ds/preview/manifest.json"
9
9
  },
10
- "boundaries": {
11
- "styleWrites": [
12
- {
13
- "file": "design-system/components/Layout/Grid/Grid.tsx",
14
- "properties": ["--ds-grid-span-sm", "--ds-grid-span-md", "--ds-grid-span-lg"]
15
- },
16
- {
17
- "file": "design-system/review/token-preview/TokenPreview.tsx",
18
- "properties": [
19
- "--ux-token-preview-value"
20
- ]
21
- }
22
- ]
23
- },
24
10
  "assets": {
25
11
  "iconSource": "assets/brand/app-icon.svg",
26
12
  "glyphs": {
@@ -3,11 +3,13 @@ import ts from "typescript";
3
3
  import { isUiCssProperties, styleAccessProperty } from "./boundaries.mjs";
4
4
  import { uiOperation } from "./ui-framework.mjs";
5
5
  import { findingSeverity } from "./finding-rules.mjs";
6
+ import { ownerStylePolicy } from "./unit-contracts.mjs";
6
7
 
7
8
  const nameOf = node => node && (ts.isIdentifier(node) || ts.isStringLiteralLike(node)) ? node.text : null;
8
9
 
9
10
  /** Audit explicit permissions without inferring project-specific style APIs. */
10
- export function inspectStyleBoundaries({ root, config }, program, report) {
11
+ export function inspectStyleBoundaries(options, program, report) {
12
+ const { root } = options, policy = ownerStylePolicy(options);
11
13
  const checker = program.getTypeChecker(), usage = new Map();
12
14
  function inspect(file) {
13
15
  if (usage.has(file)) return usage.get(file);
@@ -26,13 +28,12 @@ export function inspectStyleBoundaries({ root, config }, program, report) {
26
28
  usage.set(file, result);
27
29
  return result;
28
30
  }
29
- const configFile = path.join(root, "ds.config.json");
30
- for (const file of config.inlineStyleFiles) {
31
- if (!inspect(path.resolve(root, file)).inline) report(configFile, "stale-style-boundary", `inlineStyleFiles entry ${file} has no JSX/factory style or UI CSSProperties use. Remove the unused permission; migrate source and its own boundary entries together in the owner's patch.`);
31
+ for (const { file, contract } of policy.inline) {
32
+ if (!inspect(path.resolve(root, file)).inline) report(path.join(root, contract), "stale-style-boundary", `styles.inline names ${file}, which has no JSX/factory style or UI CSSProperties use. Remove the unused permission from the owner's contract.`);
32
33
  }
33
- for (const { file, properties } of config.boundaries.styleWrites) {
34
+ for (const { file, properties, contract } of policy.styleWrites) {
34
35
  const used = inspect(path.resolve(root, file)).writes;
35
- for (const property of properties) if (!used.has(property)) report(configFile, "stale-style-boundary", `styleWrites entry ${file} never writes ${property}. Remove the unused property in the owner's source/boundary patch.`);
36
+ for (const property of properties) if (!used.has(property)) report(path.join(root, contract), "stale-style-boundary", `styles.writes for ${file} lists ${property}, which it never writes. Remove the unused property from the owner's contract.`);
36
37
  }
37
38
  }
38
39
 
@@ -1,7 +1,7 @@
1
1
  import { existsSync, readFileSync, readdirSync } from "node:fs";
2
2
  import path from "node:path";
3
3
  import ts from "typescript";
4
- import { adsFileRole, isInside, isDevelopmentFile, isTestFile } from "./config.mjs";
4
+ import { adsFileRole, isInside, isDevelopmentFile, isScenarioFile, isTestFile } from "./config.mjs";
5
5
  import { importResolver } from "./boundaries.mjs";
6
6
  import { createPreviewFileFilter } from "./preview-files.mjs";
7
7
 
@@ -86,7 +86,7 @@ export function inspectTestBoundaries(options, inventory, contracts, program) {
86
86
  if (marked && !registered.has(file)) report(file,"test-registration","ADS behavior specs must be registered by their owning contract. Register this file or remove the obsolete spec.");
87
87
  if (inside) {
88
88
  const unit = inventory.units.find(unit=>unit.id===own);
89
- const real = ["configuration","foundation","tokens"].includes(own) || unit?.files.some(relative=>{const target=path.resolve(options.root,relative);return !isDevelopmentFile(target,options) || own?.startsWith("composition/") && /\.scenario\.[cm]?[jt]sx?$/.test(target);});
89
+ const real = ["configuration","foundation","tokens"].includes(own) || unit?.files.some(relative=>{const target=path.resolve(options.root,relative);return !isDevelopmentFile(target,options) || own?.startsWith("composition/") && isScenarioFile(target);});
90
90
  if (!real) report(file,"test-ownership","ADS tests belong beside a real runtime or composition owner. A test/helper file alone cannot create an owner.");
91
91
  }
92
92
  if (!inside) {
@@ -3,6 +3,7 @@ import path from "node:path";
3
3
  import { loadConfig } from "./config.mjs";
4
4
  import { inspectTokens } from "./tokens.mjs";
5
5
  import { generatedThemeFiles, generatedThemesFile, writeThemesCss } from "./themes-generated.mjs";
6
+ import { isExportsFile, writeGeneratedEntries } from "./generated-entries.mjs";
6
7
 
7
8
  /** Rewrites the project's themes.generated.css and themes.generated.ts from its token sheets and config when stale. */
8
9
  export function refreshThemesCss(directory) {
@@ -10,7 +11,8 @@ export function refreshThemesCss(directory) {
10
11
  return { ...writeThemesCss(options, inspectTokens(directory, options)), root: options.root };
11
12
  }
12
13
 
13
- /** Keeps themes.generated.css and .ts current: once now, then on every token sheet or config change. */
14
+ /** Keeps themes.generated.css and .ts current on every token sheet or config change, and the
15
+ * generated barrels current on every exports file change: once now, then on each change. */
14
16
  export function watchThemesCss(directory, { log = () => {} } = {}) {
15
17
  const watchers = [];
16
18
  let timer;
@@ -19,6 +21,10 @@ export function watchThemesCss(directory, { log = () => {} } = {}) {
19
21
  const result = refreshThemesCss(directory);
20
22
  for (const item of result.files ?? []) if (item.written) log(`ADS wrote ${path.relative(result.root, item.file).replaceAll("\\", "/")}`);
21
23
  } catch (error) { log(`ADS could not write ${generatedThemesFile}: ${error.message}`); }
24
+ try {
25
+ const options = loadConfig(directory);
26
+ for (const item of writeGeneratedEntries(options).files) if (item.changed) log(`ADS wrote ${path.relative(options.root, item.file).replaceAll("\\", "/")}`);
27
+ } catch (error) { log(`ADS could not write the generated entries: ${error.message}`); }
22
28
  };
23
29
  const changed = file => {
24
30
  const name = path.basename(String(file ?? ""));
@@ -30,9 +36,9 @@ export function watchThemesCss(directory, { log = () => {} } = {}) {
30
36
  refresh();
31
37
  try {
32
38
  const { root, dsRoot, config } = loadConfig(directory);
33
- for (const [folder, filter] of [[path.join(dsRoot, config.tokenDir), file => String(file).endsWith(".css")], [root, file => String(file) === "ds.config.json"]]) {
39
+ for (const [folder, filter] of [[path.join(dsRoot, config.tokenDir), file => String(file).endsWith(".css")], [root, file => String(file) === "ds.config.json"], [dsRoot, file => isExportsFile(String(file))]]) {
34
40
  try {
35
- const watcher = watch(folder, { recursive: folder !== root }, (_event, file) => { if (filter(file)) changed(file); });
41
+ const watcher = watch(folder, { recursive: folder !== root }, (_event, file) => { if (file && filter(file)) changed(file); });
36
42
  watcher.unref(); watcher.on("error", () => watcher.close());
37
43
  watchers.push(watcher);
38
44
  } catch { /* A missing token folder has nothing to generate from. */ }
@@ -26,5 +26,5 @@ export function reconcileTokenSamples(options, {id, bindings = []}) {
26
26
  const next = JSON.stringify(current) === JSON.stringify(list) ? source.content : source.content.slice(0,source.start) + JSON.stringify(list,null,2) + source.content.slice(source.end);
27
27
  return {unit:owner,id,file:source.file,sampleCount:list.length,removed,unresolved,
28
28
  patch:textDiff(source.file,source.content,next),
29
- guidance:"Bindings and probes belong to the project. No token-name/type heuristic chooses a renderer or probe. Apply the proposed owner patch through ads_apply_patch, then verify its real preview."};
29
+ guidance:"Bindings and probes belong to the project. No token-name/type heuristic chooses a renderer or probe. The proposed owner patch goes into a draft; review its real preview before accepting."};
30
30
  }
@@ -1,11 +1,13 @@
1
- import { realpathSync, statSync } from "node:fs";
1
+ import { existsSync, realpathSync, statSync } from "node:fs";
2
2
  import path from "node:path";
3
3
  import ts from "typescript";
4
4
  import { z } from "zod";
5
- import { isContractFile, isDevelopmentFile, isInside, isReviewFile, sourceFiles } from "./config.mjs";
5
+ import { isContractFile, isDevelopmentFile, isInside, isReviewFile, isStateVariable, sourceFiles } from "./config.mjs";
6
+ import { isSharedToken } from "./token-policy.mjs";
6
7
  import { projectCompilerOptions } from "./boundaries.mjs";
7
8
  import { inspectUnits } from "./units.mjs";
8
9
  import { publicApi, reviewApi } from "./public-api.mjs";
10
+ import { cachedProgram } from "./program-cache.mjs";
9
11
 
10
12
  const identities = new WeakSet();
11
13
  const ref = z.custom(value => value && typeof value === "object" && identities.has(value), "Use a resolved implementation symbol, not its name or an object describing it.");
@@ -16,7 +18,14 @@ const paint = z.object({ api: ref, property: field, kind: z.literal("paint-refer
16
18
  const binding = z.object({ input: z.object({ api: ref, property: field }).strict(), producer: ref, valueFrom: z.union([field,z.array(field).min(1).max(12).refine(paths=>new Set(paths).size===paths.length,"Value paths must be distinct.")]),
17
19
  variable: z.string().regex(/^--[a-z][\w-]*\$\{key\}[\w-]*$/), scope: z.object({ api: ref, selector: z.string().min(1).max(200) }).strict(), checks }).strict();
18
20
  const part = z.object({ api: ref, parent: ref, consumer: ref, checks }).strict();
21
+ // An owner's own style permissions: runtime style writes and inline-style files (owner-local
22
+ // paths relative to the contract), and the --ds-* variables it publishes for outside customization.
23
+ const ownerFile = z.string().min(1).max(300).regex(/^\.\.?\//, "Use a path relative to the contract, such as ./Menu.tsx.");
24
+ const styleProperty = z.string().regex(/^(?:--[\w-]+|[a-z][a-z0-9-]*)$/).refine(name => name !== "css-text" && !isStateVariable(name) && !isSharedToken(name) && (!name.startsWith("--") || /^(?:--ds-|--ux-|--showcase-)/.test(name)), "Name one CSS property or an owned --ds-/--ux-/--showcase- variable; never cssText, state variables or shared tokens.");
25
+ const styles = z.object({ writes: z.record(ownerFile, z.array(styleProperty).min(1).max(50)).optional(), inline: z.array(ownerFile).max(50).optional() }).strict();
26
+ const customization = z.array(z.string().regex(/^--ds-[\w-]+$/).refine(name => !isStateVariable(name), "Interaction state variables cannot be customized from outside.")).max(100);
19
27
  const schema = z.object({ schemaVersion: z.literal(1),
28
+ styles: styles.optional(), customization: customization.optional(),
20
29
  paintInputs: z.array(paint).max(100).optional(), bindings: z.record(id, binding).optional(),
21
30
  declarativeParts: z.array(part).max(100).optional(), behavior: z.record(z.string(), z.unknown()).optional(),
22
31
  }).strict();
@@ -103,7 +112,7 @@ export function inspectUnitContracts(options, suppliedProgram) {
103
112
  options.unitContracts = result;
104
113
  if (!files.length) return result;
105
114
  const inventory = inspectUnits(options);
106
- const program = suppliedProgram ?? ts.createProgram(sourceFiles(options.dsRoot).filter(file => /\.[cm]?[jt]sx?$/.test(file)), { ...projectCompilerOptions(options), allowJs: true });
115
+ const program = suppliedProgram ?? cachedProgram(`contracts:${options.root}`, sourceFiles(options.dsRoot).filter(file => /\.[cm]?[jt]sx?$/.test(file)), { ...projectCompilerOptions(options), allowJs: true });
107
116
  result.program = program;
108
117
  const checker = program.getTypeChecker();
109
118
  const publicItems = [...publicApi(program, options), ...reviewApi(program, options)];
@@ -120,7 +129,7 @@ export function inspectUnitContracts(options, suppliedProgram) {
120
129
  }
121
130
  try {
122
131
  if (!source || statSync(file).size > 128 * 1024 || realpathSync(file) !== file) throw new Error("Contracts must be real owner-local files of at most 128 KiB.");
123
- if (!/^(?:components|patterns|controllers|review)\//.test(unit ?? "")) throw new Error("Contracts belong to a component, pattern, controller or review owner.");
132
+ if (!/^(?:components|patterns|controllers|review)\/|^showcase$/.test(unit ?? "")) throw new Error("Contracts belong to a component, pattern, controller, review or showcase owner.");
124
133
  if (seen.has(unit)) throw new Error(`Only one TypeScript contract may describe ${unit}.`);
125
134
  seen.add(unit);
126
135
  for (const statement of source.statements) {
@@ -135,6 +144,17 @@ export function inspectUnitContracts(options, suppliedProgram) {
135
144
  const parsed = schema.safeParse(value);
136
145
  if (!parsed.success) { for (const issue of parsed.error.issues.slice(0, 12)) report(`${issue.path.join(".")}: ${issue.message}`, issue.path.join(".")); continue; }
137
146
  const data = parsed.data;
147
+ // Style permissions name real files of this owner; paths are stored project-relative.
148
+ const ownedFile = (file, fieldName) => {
149
+ const absolute = path.resolve(path.dirname(path.resolve(options.root, relative)), file), target = slash(path.relative(options.root, absolute));
150
+ if (!existsSync(absolute) || inventory.owner(inventory.relative(target)) !== unit) { report(`${fieldName} must name a file of ${unit}: ${file}`, fieldName); return null; }
151
+ return target;
152
+ };
153
+ if (data.styles) data.styles = {
154
+ writes: Object.entries(data.styles.writes ?? {}).map(([file, properties]) => ({ file: ownedFile(file, `styles.writes.${file}`), properties })).filter(entry => entry.file),
155
+ inline: (data.styles.inline ?? []).map((file, index) => ownedFile(file, `styles.inline.${index}`)).filter(Boolean),
156
+ };
157
+ if (data.customization && !unit.startsWith("components/")) report("Only components publish --ds-* customization variables.", "customization");
138
158
  const apiName = (reference, fieldName) => {
139
159
  const owner = inventory.owner(inventory.relative(reference.source));
140
160
  const api = publicByIdentity.get(reference.identity);
@@ -204,6 +224,20 @@ export function inspectUnitContracts(options, suppliedProgram) {
204
224
  return result;
205
225
  }
206
226
 
227
+ /** Style permissions declared by owners in their contracts: runtime style writes, inline-style
228
+ * files and published customization variables. Cached on the options object. */
229
+ export function ownerStylePolicy(options) {
230
+ if (options.ownerStylePolicy) return options.ownerStylePolicy;
231
+ const policy = { styleWrites: [], inline: [], inlineStyleFiles: [], componentVariables: [] };
232
+ options.ownerStylePolicy = policy;
233
+ for (const contract of inspectUnitContracts(options).contracts) {
234
+ for (const entry of contract.styles?.writes ?? []) policy.styleWrites.push({ ...entry, unit: contract.unit, contract: contract.file });
235
+ for (const file of contract.styles?.inline ?? []) { policy.inline.push({ file, unit: contract.unit, contract: contract.file }); policy.inlineStyleFiles.push(file); }
236
+ for (const name of contract.customization ?? []) policy.componentVariables.push(name);
237
+ }
238
+ return policy;
239
+ }
240
+
207
241
  /** An ownership lookup, not source/browser certification of the declaration. */
208
242
  export function runtimeBindingOwner(options, name) {
209
243
  for (const contract of inspectUnitContracts(options).contracts) for (const [id, binding] of Object.entries(contract.bindings ?? {})) {
package/dist/units.mjs CHANGED
@@ -2,11 +2,9 @@ import { existsSync, readFileSync, readdirSync } from "node:fs";
2
2
  import path from "node:path";
3
3
  import { hasProjectConfig } from "./project-boundary.mjs";
4
4
  import ts from "typescript";
5
- import postcss from "postcss";
6
5
  import { adsFileRole, isDevelopmentFile, isInside, scenarioIdentity } from "./config.mjs";
7
6
  import { importResolver } from "./boundaries.mjs";
8
7
  import { documentationFilePolicy, isProjectDocument, projectDocumentFiles } from "./project-documents.mjs";
9
- import { foundationFiles, foundationImportTarget } from "./token-policy.mjs";
10
8
 
11
9
  const source = /\.[cm]?[jt]sx?$/;
12
10
  const slash = file => file.replaceAll("\\", "/");
@@ -122,15 +120,15 @@ export function inspectUnits(options) {
122
120
  // Runtime entry conventions keep directory ownership stable when an optional
123
121
  // preview is removed. A flat scenario family still denotes separate owners.
124
122
  const sameName = name => name.replace(/[-_]/g, "").toLowerCase();
125
- const legacyFlatFamilies = new Set(files.filter(file => !adsFileRole(file) && /\.scenario\.[cm]?[jt]sx?$/.test(file)).map(file => path.posix.dirname(file)));
123
+ const scenarioFiles = files.filter(file => adsFileRole(file) === "scenario" && source.test(file));
126
124
  const canonicalDefaults = new Set();
127
- const directories = new Set(files.filter(file => /(?:^|\/)Scenario\.[cm]?[jt]sx?$/.test(file)).map(file => slash(path.dirname(file))));
128
- // A canonical marked default is the development entry of the same directory
129
- // owner as Scenario.tsx. It needs no production module or empty contract to
130
- // retain that boundary. Preserve explicit flat IDs and existing peer families.
131
- for (const file of files.filter(file => adsFileRole(file) === "scenario")) {
125
+ const directories = new Set();
126
+ // A canonical default <Dir>/<Dir>.ads.scenario.* is the development entry of
127
+ // its directory owner. It needs no production module or empty contract to
128
+ // retain that boundary. An explicit flat ID keeps the file a flat entry.
129
+ for (const file of scenarioFiles) {
132
130
  const directory = path.posix.dirname(file);
133
- if (legacyFlatFamilies.has(directory) || scenarioIdentity(path.join(dsRoot,file),dsRoot) !== directory) continue;
131
+ if (scenarioIdentity(path.join(dsRoot,file),dsRoot) !== directory) continue;
134
132
  const ast = ts.createSourceFile(file,readFileSync(path.join(dsRoot,file),"utf8"),ts.ScriptTarget.Latest,true);
135
133
  const declaration = ast.statements.filter(ts.isVariableStatement).flatMap(statement=>statement.declarationList.declarations)
136
134
  .find(declaration=>ts.isIdentifier(declaration.name)&&declaration.name.text==="scenario");
@@ -145,10 +143,9 @@ export function inspectUnits(options) {
145
143
  directories.add(directory);
146
144
  canonicalDefaults.add(directory);
147
145
  }
148
- // Marked flat siblings still outrank a directory index/runtime barrel. Losing
149
- // the final legacy spelling must not merge otherwise unrelated peer owners.
150
- const flatFamilies = new Set(files.filter(file => /\.scenario\.[cm]?[jt]sx?$/.test(file)
151
- && (!adsFileRole(file) || !canonicalDefaults.has(path.posix.dirname(file)))).map(file => path.posix.dirname(file)));
146
+ // Flat scenario siblings outrank a directory index/runtime barrel, so a
147
+ // directory of flat owners is never merged into one owner.
148
+ const flatFamilies = new Set(scenarioFiles.map(file => path.posix.dirname(file)).filter(directory => !canonicalDefaults.has(directory)));
152
149
  for (const file of files.filter(file => /^(?:components|patterns)\/.+\/tokens\.json$/.test(file))) directories.add(path.posix.dirname(file));
153
150
  for (const file of files.filter(file => /\.ads\.contract\.[cm]?ts$/.test(file))) {
154
151
  const directory=path.posix.dirname(file);
@@ -157,9 +154,9 @@ export function inspectUnits(options) {
157
154
  for (const file of files) {
158
155
  if (!/^(?:components|patterns|controllers|composition|review|brand)\//.test(file) || !source.test(file)) continue;
159
156
  const directory = slash(path.dirname(file)), name = path.basename(file).replace(source, "");
160
- if (!directory.includes("/") || adsFileRole(file) || /\.(?:scenario|fixture|scenario-adapter)$/.test(name)) continue;
157
+ if (!directory.includes("/") || adsFileRole(file)) continue;
161
158
  if (flatFamilies.has(directory)) continue;
162
- if (name === "index" || sameName(name) === sameName(path.posix.basename(directory)) || name === "fixture") directories.add(directory);
159
+ if (name === "index" || sameName(name) === sameName(path.posix.basename(directory))) directories.add(directory);
163
160
  }
164
161
  const directoryUnits = [...directories].sort((a, b) => b.length - a.length);
165
162
  const flatUnits = [...new Set(files.filter(file => /^(?:components|patterns|controllers|composition|review|brand)\//.test(file) && source.test(file) && !directoryUnits.some(directory => file.startsWith(directory + "/"))).map(file => {
@@ -174,7 +171,7 @@ export function inspectUnits(options) {
174
171
  const projectFile = slash(path.relative(root, path.resolve(dsRoot, relative)));
175
172
  if (setup.has(projectFile)) return "configuration";
176
173
  if (!isInside(dsRoot, path.resolve(dsRoot, relative))) return isProjectDocument(projectFile) ? "documentation" : null;
177
- if (relative === publicEntry || relative === reviewEntry) return null; // Controlled re-export bookkeeping.
174
+ if (relative === publicEntry || relative === reviewEntry || relative === stylesEntry) return null; // Generated entries have no owner.
178
175
  if (relative.startsWith(tokenDir + "/")) return "tokens";
179
176
  if (relative.startsWith("assets/")) return relative.split("/").length > 2 ? relative.split("/").slice(0, 2).join("/") : "assets";
180
177
  if (isProjectDocument(relative)) return "documentation";
@@ -188,8 +185,6 @@ export function inspectUnits(options) {
188
185
  const units = new Map();
189
186
  units.set("configuration", { id: "configuration", kind: "configuration", files: [...setup].filter(file => existsSync(path.join(root, file))).sort() });
190
187
  for (const id of ["foundation", "documentation", "tokens", "assets/brand", "assets/fonts"]) units.set(id, { id, kind: id.split("/")[0], files: [] });
191
- units.get("tokens").companionFiles = [{ path: slash(path.relative(root, path.join(dsRoot, stylesEntry))),
192
- allowedChanges: "Only add/remove canonical foundation imports required by token foundation files created/deleted in this patch; preserve other imports and comments." }];
193
188
  units.get("documentation").files = projectDocumentFiles(root).filter(file => owner(slash(path.relative(dsRoot,path.resolve(root,file)))) === "documentation");
194
189
  units.get("documentation").filePolicy = documentationFilePolicy;
195
190
  for (const relative of files) {
@@ -202,14 +197,6 @@ export function inspectUnits(options) {
202
197
  for (const unit of units.values()) if (boundaryCompanion(unit.id)) {
203
198
  const contracts=unit.files.filter(file=>/\.ads\.contract\.[cm]?ts$/.test(file));
204
199
  if(contracts.length===1)unit.contractFile=contracts[0];
205
- if (unit.id.startsWith("review/")) (unit.companionFiles ??= []).push({ path: slash(path.relative(root, path.join(dsRoot, reviewEntry))), allowedChanges: "Only this review owner's re-exports in the separate development entry; never the production public entry." });
206
- (unit.companionFiles ??= []).push({ path: "ds.config.json", allowedChanges: "Only this owner's inlineStyleFiles and boundaries.styleWrites entries, together with its source change; preserve all other configuration and peer permissions." });
207
- if (/^(?:components|patterns|controllers|composition|review|brand)\//.test(unit.id)) {
208
- for (let directory = unit.id; directory !== "."; directory = path.posix.dirname(directory)) {
209
- const marker = path.join(dsRoot, directory, ".gitkeep");
210
- if (existsSync(marker) && readFileSync(marker).length === 0) (unit.companionFiles ??= []).push({ path: slash(path.relative(root, marker)), allowedChanges: "Delete this empty placeholder only while adding real source in the selected owner below it." });
211
- }
212
- }
213
200
  }
214
201
  return { units: [...units.values()].sort((a, b) => a.id.localeCompare(b.id)), owner, publicEntry, reviewEntry, stylesEntry, tokenDir,
215
202
  relative: file => slash(path.relative(dsRoot, path.resolve(root, file))) };
@@ -226,18 +213,10 @@ export function checkUnitFiles(options, unit, changes, inventory = inspectUnits(
226
213
  validateUnitId(unit);
227
214
  for (const change of changes) {
228
215
  const relative = inventory.relative(change.path);
229
- if (path.posix.basename(relative) === ".gitkeep") {
230
- const directory = path.posix.dirname(relative);
231
- if (change.originalContent !== "" || change.content !== null || !/^(?:components|patterns|controllers|composition|review|brand)\//.test(relative)
232
- || !(unit === directory || unit.startsWith(directory + "/"))
233
- || !changes.some(item => item.originalContent === null && item.content !== null && source.test(item.path)
234
- && (inventory.relative(item.path).startsWith(unit + "/") || inventory.relative(item.path).startsWith(unit + ".")))) throw fail("Only delete an existing empty .gitkeep while adding source in the selected owner beneath it. Other hidden-file changes are not allowed.", change.path);
235
- continue;
236
- }
216
+ if (path.posix.basename(relative) === ".gitkeep") throw fail("ADS removes an empty .gitkeep itself when accepted source is added beneath it; leave placeholders alone.", change.path);
237
217
  if (allowNew && unit === "configuration") continue; // The candidate must register every setup/extension file.
238
- if (change.path === "ds.config.json" && boundaryCompanion(unit)) continue; // Validated against only this owner below.
239
- if (relative === inventory.publicEntry || relative === inventory.reviewEntry) continue;
240
- if (unit === "tokens" && relative === inventory.stylesEntry) continue; // Controlled foundation import bookkeeping.
218
+ if (relative === inventory.publicEntry || relative === inventory.reviewEntry) throw fail(`${path.basename(relative)} is generated by ADS from .ads.exports.ts files. Declare public names in the owner's exports file instead.`, change.path);
219
+ if (relative === inventory.stylesEntry) throw fail(`${path.basename(relative)} is generated by ADS from the token sheets; add or remove a canonical token sheet instead.`, change.path);
241
220
  if (allowNew && change.originalContent === null && (relative.startsWith(unit + "/") || relative.startsWith(unit + "."))) continue;
242
221
  const owner = inventory.owner(relative);
243
222
  if (owner !== unit) throw fail(`This patch targets ${unit}; ${change.path} belongs to ${owner ?? "a different ADS layer"}. Submit a separate unit patch.${unit === "documentation" ? ` ${documentationFilePolicy}` : ""}`, change.path);
@@ -255,59 +234,5 @@ export function checkUnitCandidate(afterOptions, unit, changes, before) {
255
234
  if (unit === "configuration" && (entry.id === "configuration" || after.owner(relative) === "configuration")) continue;
256
235
  if (after.owner(relative) !== entry.id) throw fail("A patch cannot change ownership of existing peer units. Choose an unoccupied owner path.", file);
257
236
  }
258
- const boundaryChange = changes.find(change => change.path === "ds.config.json");
259
- if (boundaryChange && unit !== "configuration") {
260
- if (!boundaryCompanion(unit) || typeof boundaryChange.originalContent !== "string" || typeof boundaryChange.content !== "string") throw fail("This unit cannot create/delete configuration.", boundaryChange.path);
261
- if (!changes.some(change => change.path !== boundaryChange.path && (before.owner(before.relative(change.path)) === unit || after.owner(after.relative(change.path)) === unit))) throw fail("Boundary companions require a source change in the selected owner.", boundaryChange.path);
262
- function peerPolicy(content, inventory) {
263
- const config = JSON.parse(content);
264
- const owns = file => typeof file === "string" && inventory.owner(inventory.relative(file)) === unit;
265
- config.inlineStyleFiles = (config.inlineStyleFiles ?? []).filter(file => !owns(file));
266
- config.boundaries = { ...config.boundaries, styleWrites: (config.boundaries?.styleWrites ?? []).filter(entry => !owns(entry.file)) };
267
- return config;
268
- }
269
- function canonical(value) {
270
- if (Array.isArray(value)) return value.map(canonical);
271
- if (value && typeof value === "object") return Object.fromEntries(Object.keys(value).sort().map(key => [key, canonical(value[key])]));
272
- return value;
273
- }
274
- if (JSON.stringify(canonical(peerPolicy(boundaryChange.originalContent, before))) !== JSON.stringify(canonical(peerPolicy(boundaryChange.content, after)))) throw fail("Boundary companion patches may change only inlineStyleFiles and styleWrites entries owned by the selected unit; preserve all other configuration and peer permissions.", boundaryChange.path);
275
- }
276
- const foundationChange = changes.find(change => before.relative(change.path) === before.stylesEntry);
277
- if (unit === "tokens" && foundationChange) {
278
- const { originalContent: current, content: proposed } = foundationChange;
279
- if (typeof current !== "string" || typeof proposed !== "string") throw fail("A token patch cannot create or delete the foundation entry.", foundationChange.path);
280
- const canonical = new Set(foundationFiles.map(name => slash(path.join(before.tokenDir, name))));
281
- const affected = new Set(changes.filter(change => (change.originalContent === null || change.content === null) && canonical.has(before.relative(change.path)))
282
- .map(change => path.join(afterOptions.dsRoot, before.relative(change.path))));
283
- if (!affected.size) throw fail("Foundation companion changes require creating or deleting a canonical token foundation file in the same token patch.", foundationChange.path);
284
- const file = path.join(afterOptions.dsRoot, afterOptions.config.stylesEntry);
285
- function unrelated(content) {
286
- try {
287
- return postcss.parse(content, { from: file }).nodes.filter(node => !affected.has(foundationImportTarget(node, file))).map(node => node.toString());
288
- } catch (error) { throw fail(`Invalid foundation import companion: ${error.reason ?? error.message}`, foundationChange.path); }
289
- }
290
- if (JSON.stringify(unrelated(current)) !== JSON.stringify(unrelated(proposed))) throw fail("Foundation companion patches may change only canonical imports for token files created/deleted in this patch; preserve all other imports and comments.", foundationChange.path);
291
- }
292
- for (const entry of [before.publicEntry, before.reviewEntry]) {
293
- const exportChange = changes.find(change => before.relative(change.path) === entry);
294
- if (!exportChange) continue;
295
- if (!(entry === before.reviewEntry ? ["review"] : ["components", "patterns", "controllers"]).includes(unit.split("/")[0])) throw fail("Only its own layer may update re-exports: product owners use the public entry, review owners use the development review entry.", exportChange.path);
296
- const current = exportChange.originalContent ?? "", proposed = exportChange.content;
297
- if (proposed === null) throw fail("The shared public entry cannot be deleted.", exportChange.path);
298
- const resolve = importResolver(afterOptions);
299
- const file = path.join(afterOptions.dsRoot, entry);
300
- const original = ts.createSourceFile(file, current, ts.ScriptTarget.Latest, true);
301
- const candidate = ts.createSourceFile(file, proposed, ts.ScriptTarget.Latest, true);
302
- const emptyExport = statement => ts.isExportDeclaration(statement) && !statement.moduleSpecifier && statement.exportClause && ts.isNamedExports(statement.exportClause) && !statement.exportClause.elements.length;
303
- function ownedExport(statement) {
304
- if (!ts.isExportDeclaration(statement) || !statement.moduleSpecifier || !ts.isStringLiteralLike(statement.moduleSpecifier)) return false;
305
- const targets = resolve(statement.moduleSpecifier.text, file);
306
- return targets.length && targets.every(target => isInside(afterOptions.dsRoot, target) && after.owner(slash(path.relative(afterOptions.dsRoot, target))) === unit);
307
- }
308
- const cleanup = candidate.statements.some(ownedExport) && !candidate.statements.some(emptyExport);
309
- const unrelated = ast => ast.statements.filter(statement => !ownedExport(statement) && !(cleanup && emptyExport(statement))).map(statement => statement.getText(ast)).join("\n");
310
- if (unrelated(original) !== unrelated(candidate)) throw fail("Public-entry patches may change only re-exports from the selected unit and remove a redundant empty export alongside its real re-export; preserve all other statements.", exportChange.path);
311
- }
312
237
  if (!before.units.some(entry => entry.id === unit) && !after.units.some(entry => entry.id === unit)) throw fail("The patched files do not establish the selected ADS unit.");
313
238
  }
@@ -1,6 +1,6 @@
1
1
  import { executionContext, finishExecutionGuard, trackExecutionChild, trackExecutionWorkspace } from "./mcp/execution-context.mjs";
2
2
  import { spawn } from "node:child_process";
3
- import { mkdtempSync, readFileSync, rmSync } from "node:fs";
3
+ import { existsSync, mkdtempSync, readFileSync, rmSync } from "node:fs";
4
4
  import { tmpdir } from "node:os";
5
5
  import { fileURLToPath } from "node:url";
6
6
  import path from "node:path";
@@ -11,6 +11,12 @@ import { failure as evidenceFailure } from "./evidence.mjs";
11
11
  const fail = (rule, message, file, failure) => Object.assign(new Error(message), { diagnostic: {rule, message, ...(file ? {file} : {}), ...(failure ? {failure} : {})} });
12
12
 
13
13
  export async function checkCandidate(root, signal, trackingRoot = root, options = {}) {
14
+ // Long-lived processes check in their warm worker; one-shot CLI and CI checks use the Turbo task.
15
+ const service = await import("./check-service.mjs");
16
+ if (service.warmChecksFor(trackingRoot) && existsSync(root)) {
17
+ const { warmCheck } = service;
18
+ return warmCheck(root, trackingRoot, signal, { fresh: executionContext.getStore()?.fresh, ...options });
19
+ }
14
20
  const directory = mkdtempSync(path.join(tmpdir(), "ads-architecture-"));
15
21
  trackExecutionWorkspace(directory);
16
22
  try {
package/docs/ADS.md CHANGED
@@ -23,16 +23,16 @@ Draft edits, stale inputs, conflicts and failed checks cannot publish source.
23
23
  Agents must accept the required drafts before reporting a coherent design change
24
24
  complete, unless the user explicitly requested a retained proposal.
25
25
 
26
- MCP source editing is opt-in through `ads mcp --mutations`. Its write operation
27
- accepts a Git unified diff for one ADS unit (or bounded owner patches for coupled
28
- transactions) and validates its source, scenario and
29
- fixture changes against native ADS gates and configured project checks
30
- before application. This includes
31
- foundation, documentation, original assets and an explicit configuration unit for
32
- project settings, registered guard code and compiler integration. Configuration
33
- patches validate the proposed policy; mandatory core gates remain enabled.
34
- Required public re-exports and canonical foundation import changes may accompany
35
- their owner under the narrow companion rules in the MCP editing contract.
26
+ MCP source editing is opt-in through `ads mcp --mutations`. Every change goes through
27
+ a draft of one or more owners (file contents or a Git unified diff), and only
28
+ `ads_accept` of an exact draft revision writes accepted source, after validating its
29
+ source, scenario and fixture changes against native ADS gates and configured project
30
+ checks. This includes foundation, documentation, original assets and an explicit
31
+ configuration unit for project settings, registered guard code and compiler
32
+ integration. Configuration drafts validate the proposed policy; mandatory core gates
33
+ remain enabled. An owner is in at most one open draft, every authored file has one
34
+ owner, and shared entries (the public barrel, review entry and styles entry) are
35
+ generated from the owners' exports files and token sheets.
36
36
  Source checks do not establish visual correctness; normal lint/build gates
37
37
  remain required for edits made through other tools.
38
38
  See the [MCP editing contract](MCP.md#guarded-editing).