@reqvire-org/ads 0.5.1 → 0.5.3

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 (136) hide show
  1. package/dist/ads-errors.mjs +143 -51
  2. package/dist/analysis/composition-axes.mjs +48 -0
  3. package/dist/analysis/construction-memo.mjs +38 -0
  4. package/dist/analysis/context.mjs +19 -0
  5. package/dist/analysis/design-reads.mjs +177 -0
  6. package/dist/analysis/design-usage.mjs +4 -20
  7. package/dist/analysis/factored-classes.mjs +90 -0
  8. package/dist/analysis/helpers.mjs +5 -7
  9. package/dist/analysis/mock-check.mjs +4 -5
  10. package/dist/analysis/native-project.mjs +12 -0
  11. package/dist/analysis/owner-accessibility.mjs +4 -4
  12. package/dist/analysis/owner-analysis-cache.mjs +86 -23
  13. package/dist/analysis/owner-analysis-key.mjs +42 -10
  14. package/dist/analysis/owner-choices.mjs +56 -7
  15. package/dist/analysis/owner-composition.mjs +179 -45
  16. package/dist/analysis/owner-reuse.mjs +8 -6
  17. package/dist/analysis/owner-source.mjs +304 -110
  18. package/dist/analysis/scenario-keys.mjs +10 -7
  19. package/dist/analysis/service.mjs +50 -3
  20. package/dist/analysis/standalone.mjs +7 -4
  21. package/dist/analysis/syntax.mjs +59 -1
  22. package/dist/analysis/worker-protocol.mjs +14 -2
  23. package/dist/analysis/worker.mjs +32 -10
  24. package/dist/architecture-report.mjs +26 -0
  25. package/dist/asset-view-facts.mjs +16 -2
  26. package/dist/boundaries.mjs +26 -10
  27. package/dist/bun-compiler.mjs +2 -2
  28. package/dist/check-service.mjs +29 -17
  29. package/dist/check.mjs +13 -6
  30. package/dist/cli.mjs +1 -1
  31. package/dist/composed-contrast.mjs +143 -62
  32. package/dist/composed-keyline.mjs +2 -2
  33. package/dist/config.mjs +2 -1
  34. package/dist/construction-output.mjs +9 -3
  35. package/dist/construction-spec.d.mts +145 -31
  36. package/dist/construction-spec.mjs +204 -74
  37. package/dist/corner-overpaint.mjs +20 -7
  38. package/dist/derived-states.mjs +182 -0
  39. package/dist/design-foundation.mjs +16 -0
  40. package/dist/design-inputs.mjs +18 -3
  41. package/dist/design-system-closure.mjs +12 -7
  42. package/dist/design-usage.mjs +2 -8
  43. package/dist/emit/contract.mjs +24 -5
  44. package/dist/emit/emission.mjs +6 -9
  45. package/dist/emit/integrity.mjs +8 -2
  46. package/dist/emit/output-watch.mjs +120 -0
  47. package/dist/emit/owner-emission-cache.mjs +4 -4
  48. package/dist/emit/preview-emitter.mjs +4 -2
  49. package/dist/emit/preview-tree.mjs +1 -1
  50. package/dist/emit/service.mjs +8 -2
  51. package/dist/finding-rules.mjs +3 -0
  52. package/dist/form-states.mjs +8 -0
  53. package/dist/frame-regions.mjs +29 -9
  54. package/dist/grid-lowering.mjs +3 -1
  55. package/dist/hover-geometry.mjs +15 -0
  56. package/dist/input-digests.mjs +17 -10
  57. package/dist/linaria/delivery.mjs +2 -0
  58. package/dist/lowering-enter.mjs +6 -6
  59. package/dist/lowering-properties.mjs +5 -0
  60. package/dist/lowering-region-layout.mjs +7 -2
  61. package/dist/lowering-session.mjs +10 -0
  62. package/dist/mcp/build-status.mjs +9 -1
  63. package/dist/mcp/compiler-channel.mjs +11 -4
  64. package/dist/mcp/mutations.mjs +1 -0
  65. package/dist/mcp/preview-http.bundle.js +1 -1
  66. package/dist/mcp/preview-watch.mjs +2 -1
  67. package/dist/mcp/preview-widget.bundle.js +1 -1
  68. package/dist/mcp/server-observation.mjs +6 -4
  69. package/dist/mcp/server-project.mjs +4 -1
  70. package/dist/motion-model.mjs +1 -1
  71. package/dist/owner-analysis-check.mjs +23 -6
  72. package/dist/owner-errors.mjs +6 -3
  73. package/dist/owner-lowering.mjs +78 -13
  74. package/dist/owner-scenarios.mjs +6 -23
  75. package/dist/ownership-model.mjs +24 -8
  76. package/dist/paint-contrast.mjs +6 -0
  77. package/dist/placeholder-contrast.mjs +17 -1
  78. package/dist/platform-features.mjs +10 -1
  79. package/dist/profile-macro.d.mts +7 -0
  80. package/dist/profile-view-facts.mjs +1 -1
  81. package/dist/recipe-macro.d.mts +103 -40
  82. package/dist/recipe-model.mjs +18 -13
  83. package/dist/region-lowering.mjs +266 -123
  84. package/dist/render-audit/layout-shift.page.mjs +24 -0
  85. package/dist/render-audit/render-states.mjs +122 -1
  86. package/dist/render-audit/render-states.page.mjs +140 -0
  87. package/dist/render-audit/worker.mjs +18 -3
  88. package/dist/render-audit.mjs +114 -1
  89. package/dist/role-vocabulary.d.mts +9 -0
  90. package/dist/role-vocabulary.mjs +16 -1
  91. package/dist/runtime-paint-contrast.mjs +5 -2
  92. package/dist/scenarios-compiler.mjs +20 -6
  93. package/dist/showcase/assets-view.mjs +29 -13
  94. package/dist/showcase/client.bundle.js +50 -50
  95. package/dist/showcase/http-client.bundle.js +15 -15
  96. package/dist/showcase/ui/ui.css +1 -1
  97. package/dist/showcase/ui/ui.js +5 -5
  98. package/dist/skills/ads-designer/references/accessibility.md +10 -4
  99. package/dist/skills/ads-designer/references/branding.md +13 -3
  100. package/dist/skills/ads-designer/references/contracts.md +5 -2
  101. package/dist/skills/ads-designer/references/design-data.md +13 -7
  102. package/dist/skills/ads-designer/references/layout.md +12 -4
  103. package/dist/skills/ads-designer/references/motion.md +11 -2
  104. package/dist/skills/ads-designer/references/recipes.md +49 -15
  105. package/dist/skills/ads-import/references/contracts.md +5 -2
  106. package/dist/skills/ads-import/references/design-data.md +13 -7
  107. package/dist/skills/ads-import/references/layout.md +12 -4
  108. package/dist/skills/ads-import/references/recipes.md +49 -15
  109. package/dist/skills/ads-migrate/SKILL.md +2 -0
  110. package/dist/skills/ads-migrate/references/0.5.1-to-0.5.2.md +185 -0
  111. package/dist/skills/ads-migrate/references/0.5.2-to-0.5.3.md +71 -0
  112. package/dist/skills/ads-port/references/contracts.md +5 -2
  113. package/dist/skills/ads-port/references/design-data.md +13 -7
  114. package/dist/skills/ads-port/references/layout.md +12 -4
  115. package/dist/skills/ads-port/references/recipes.md +49 -15
  116. package/dist/spatial-model.mjs +2 -2
  117. package/dist/surface-contrast.mjs +7 -2
  118. package/dist/surface-effects.mjs +5 -3
  119. package/dist/target-size.mjs +21 -3
  120. package/dist/task-cache.mjs +8 -18
  121. package/dist/validation-checks.mjs +1 -1
  122. package/docs/ADS.md +9 -3
  123. package/docs/ARCHITECTURE.md +96 -30
  124. package/docs/CACHING.md +152 -24
  125. package/docs/CHANGELOG.md +307 -23
  126. package/docs/GUIDE.md +109 -20
  127. package/docs/LANGUAGE.md +262 -117
  128. package/docs/MCP.md +5 -1
  129. package/docs/MOTION.md +15 -4
  130. package/docs/PROFILE-KINDS.md +54 -4
  131. package/docs/RULES.md +34 -25
  132. package/docs/TOKEN-ROLES.md +7 -1
  133. package/package.json +1 -1
  134. package/dist/analysis/prose-owners.mjs +0 -57
  135. package/dist/prose-model.d.mts +0 -81
  136. package/dist/prose-model.mjs +0 -101
@@ -1,4 +1,4 @@
1
- import { outputIntegrityFingerprint, recordedOutputRevision } from "./emit/integrity.mjs";
1
+ import { recordedOutputRevision, withCurrentOutput } from "./emit/integrity.mjs";
2
2
  import { createHash } from "node:crypto";
3
3
  import { createRequire } from "node:module";
4
4
  import { spawnSync } from "node:child_process";
@@ -6,23 +6,13 @@ import { accessSync, constants, existsSync, mkdirSync, readFileSync, readdirSync
6
6
  import path from "node:path";
7
7
  import { fileURLToPath } from "node:url";
8
8
  import { isInside, loadConfig } from "./config.mjs";
9
+ import { parseArchitectureReport } from "./architecture-report.mjs";
10
+ export { parseArchitectureReport } from "./architecture-report.mjs";
9
11
  import { isRecord } from "./unknown.mjs";
10
12
  import { validationInputFiles } from "./validation-inputs.mjs";
11
13
  import { previewRuntimeFingerprint } from "./runtime-requirements.mjs";
12
14
  import { checkCommand } from "./validation-checks.mjs";
13
- const hash = (value) => createHash("sha256").update(value).digest("hex"), errorCode = (error) => isRecord(error) ? error.code : void 0, toolRoot = path.dirname(fileURLToPath(import.meta.url)), semanticEnv = ["NODE_ENV", "NODE_OPTIONS", "BUN_OPTIONS", "TZ", "LANG", "LC_ALL"], isStringArray = (value) => Array.isArray(value) && value.every((item) => typeof item === "string"), isDiagnostic = (value) => isRecord(value) && typeof value.rule === "string", isDiagnostics = (value) => Array.isArray(value) && value.every(isDiagnostic), isAcceptance = (value) => isRecord(value) && typeof value.scope === "string" && (value.status === "passed" || value.status === "not_established") && isStringArray(value.established) && isStringArray(value.unverified);
14
- export function parseArchitectureReport(value, source) {
15
- if (isRecord(value)) {
16
- const { ok, diagnostics, advisories, acceptance } = value;
17
- if (typeof ok === "boolean" && isDiagnostics(diagnostics) && isAcceptance(acceptance)) {
18
- if (advisories === void 0)
19
- return { ...value, ok, diagnostics, acceptance };
20
- if (isDiagnostics(advisories))
21
- return { ...value, ok, diagnostics, advisories, acceptance };
22
- }
23
- }
24
- throw TypeError(`${source} is not an ADS architecture report.`);
25
- }
15
+ const hash = (value) => createHash("sha256").update(value).digest("hex"), errorCode = (error) => isRecord(error) ? error.code : void 0, toolRoot = path.dirname(fileURLToPath(import.meta.url)), semanticEnv = ["NODE_ENV", "NODE_OPTIONS", "BUN_OPTIONS", "TZ", "LANG", "LC_ALL"];
26
16
  function turboBinary() {
27
17
  const platform = process.platform === "win32" ? "windows" : process.platform === "android" ? "linux" : process.platform, arch = process.arch === "x64" ? "64" : process.arch;
28
18
  try {
@@ -75,11 +65,10 @@ export function architectureExternalInputs(root, trackingRoot = root) {
75
65
  return {
76
66
  dependencies,
77
67
  git,
78
- environment: Object.fromEntries(semanticEnv.map((name) => [name, process.env[name] ?? null])),
79
- output: outputIntegrityFingerprint(options)
68
+ environment: Object.fromEntries(semanticEnv.map((name) => [name, process.env[name] ?? null]))
80
69
  };
81
70
  }
82
- export async function architectureTaskInputs(root, trackingRoot = root, { onFile } = {}) {
71
+ export async function architectureTaskInputs(root, trackingRoot = root, { onFile, environment } = {}) {
83
72
  return {
84
73
  schemaVersion: 1,
85
74
  kind: "architecture",
@@ -87,6 +76,7 @@ export async function architectureTaskInputs(root, trackingRoot = root, { onFile
87
76
  tool: toolInputs(),
88
77
  files: await validationInputFiles(loadConfig(root), [], { onFile }),
89
78
  ...architectureExternalInputs(root, trackingRoot),
79
+ ...environment === void 0 ? {} : { environment },
90
80
  outputRevision: recordedOutputRevision(loadConfig(root))
91
81
  };
92
82
  }
@@ -214,7 +204,7 @@ export async function runArchitectureTask(root, trackingRoot, directory, signal,
214
204
  throw failure ?? Error("ADS task did not produce an architecture report.");
215
205
  if (statSync(report).size > 16777216)
216
206
  throw Error("Architecture report exceeds 16 MiB.");
217
- const result = parseArchitectureReport(JSON.parse(readFileSync(report, "utf8")), "The ADS task report");
207
+ const result = withCurrentOutput(parseArchitectureReport(JSON.parse(readFileSync(report, "utf8")), "The ADS task report"), loadConfig(root));
218
208
  if (failure && result.ok !== !1)
219
209
  throw failure;
220
210
  let hit = !1;
@@ -16,7 +16,7 @@ function executionFresh() {
16
16
  }
17
17
  export async function checkCandidate(root, signal, trackingRoot = root, options = {}) {
18
18
  const service = await import("./check-service.mjs");
19
- if ((service.warmChecksFor(trackingRoot) || hasAnalysisRevision(root)) && existsSync(root)) {
19
+ if ((options.checked !== void 0 || options.environment !== void 0 || service.warmChecksFor(trackingRoot) || hasAnalysisRevision(root)) && existsSync(root)) {
20
20
  const { warmCheck } = service;
21
21
  return warmCheck(root, trackingRoot, signal, { fresh: executionFresh(), ...options });
22
22
  }
package/docs/ADS.md CHANGED
@@ -255,6 +255,11 @@ owners (`component-contrast`, error; [guide](GUIDE.md#design-system-source)).
255
255
  - Every component the barrel exports is also checked on the document surface
256
256
  that `foundation({ surface })` declares. Applications place those components;
257
257
  their own coloured containers are outside the design system.
258
+ - A placement is checked with what its arguments select: a prop it leaves out
259
+ takes its default (or its absence), and an owner state that tests an attribute
260
+ the markup writes holds only where the placement can render that value. A row
261
+ placed with no `state` is not paired with its selected tints there; every
262
+ value stays checked on the document surface for applications.
258
263
  - The minimum is 4.5:1, or 3:1 over provably large text inherited across owners.
259
264
  Hidden, absent or inactive text has none.
260
265
  - A component of the placing owner's own file is expanded only when it passes
@@ -262,8 +267,9 @@ owners (`component-contrast`, error; [guide](GUIDE.md#design-system-source)).
262
267
  of is the user agent's own pair and adds nothing.
263
268
  - What the check cannot prove is `component-contrast-unresolved` (review) at the
264
269
  placement or element concerned, never passed. Examples are an unanalyzed
265
- wrapper, an owner placed in a plain module's markup, a user-agent paint, an
266
- out-of-flow element, opacity, an unknown image and a limit.
270
+ wrapper, a user-agent paint, an out-of-flow element, opacity, an unknown image
271
+ and a limit. A plain module that places components (a sheet arranging rows)
272
+ is followed like an owner.
267
273
 
268
274
  #### Grids, spatial profiles and text layout
269
275
 
@@ -588,7 +594,7 @@ accessibility, interaction, responsive layout, themes and motion.
588
594
  - The package ships no design system. `ads init` sets up configuration,
589
595
  dependencies and an empty design-system folder; the project authors what goes
590
596
  in it. The example design system the documents quote is ADS's own test
591
- project (`tests/fixtures/starter-project/` in the repository), which the
597
+ project (`tests/fixtures/example-project/` in the repository), which the
592
598
  package does not contain.
593
599
  - The tool does not require any design system's names or styles and ships no
594
600
  product UI catalogue.
@@ -125,12 +125,12 @@ author in. It never replaces a project file, edits `.gitignore` or writes a
125
125
  lockfile.
126
126
 
127
127
  ADS tests itself with one example design system, written for React
128
- (`tests/fixtures/starter-project/`). The build writes its declared file set
128
+ (`tests/fixtures/example-project/`). The build writes its declared file set
129
129
  and, through an overlay (`tests/helpers/starter/starter-overlay.mts`), a native
130
130
  Preact copy of the same source to `.ds/test-starters/`, outside the package;
131
131
  the overlay stops the build on a React API without a declared Preact
132
132
  counterpart. The tests install it after `ads init`
133
- (`tests/helpers/starter-project.mjs`).
133
+ (`tests/helpers/example-project.mjs`).
134
134
 
135
135
  ### No production runtime
136
136
 
@@ -204,10 +204,10 @@ section, not a parallel set of "on dark" tokens or component variants.
204
204
  A theme is the unit for sections because it is the unit the checks prove. Every
205
205
  token sheet value is evaluated, and the contrast of every surface pair is
206
206
  proven, in each theme, brand and brand × theme context. A section can therefore
207
- only select a context whose whole colour mode already passes. ADS has no finer
208
- construct, such as a surface that sets the colours its descendants read
209
- (selected rows, tinted banners): it would need its own context in those proofs.
210
- Explicit choices on the child cover those cases.
207
+ only select a context whose whole colour mode already passes. The finer construct,
208
+ a surface that sets the colours its descendants read (selected rows, tinted
209
+ banners), is a contextual role (`provides`, below): it re-binds paint tokens only,
210
+ and composed contrast proves what sits inside it with the provided values.
211
211
 
212
212
  Sections are opt-in because of their cost: the section rules add CSS to every
213
213
  owner sheet, and a design system that switches only `<html>` gains nothing from
@@ -332,19 +332,27 @@ them through `writeKeyframes`. Script-defined animation is refused by
332
332
  through the checker so that a project function of the same name is not
333
333
  reported.
334
334
 
335
- **Prose.** `src/prose-model.mts` is the closed set: element names, their tags,
336
- the browser defaults replaced, and which element can contain which. A prose
337
- root is a region whose `RegionSpec.prose` holds the declared elements;
338
- `lowerProse` (`src/region-lowering.mts`) writes one rule per tag with the
339
- selector `& <tag>:not([class])`, a descendant selector the overlap check
340
- already reasons about by element type, and proves contrast with
341
- `paintContrast` over the token contexts, so a prose owner that declares a
342
- colour is token-dependent. The markup checks need to know prose owners without
343
- the owner analysis: `src/analysis/prose-owners.mts` reads them syntactically
344
- from the barrel's re-exports and each file's own `recipe({ layout: "prose" })`
345
- literal, in the captured revision. Emission writes that map as
346
- `ads-prose.json`; the design-use library reads it beside the entry file,
347
- because an emitted owner carries no recipe.
335
+ **Contextual roles.** A surface profile's `provides` entries are profile fields
336
+ named by the token they re-bind (`--link-ink`), checked in
337
+ `src/design-foundation.mts` (paint to paint; a surface that reads a token it
338
+ provides is `provided-role-self`). Every lowering path that applies a surface
339
+ passes its fields to the rule writer (`src/construction-output.mts`), which sends
340
+ custom-property keys through `LoweringSession.writeProvidedRoles`: the only
341
+ operation that admits custom properties, never `--ads-*` or asset channels.
342
+ Composed contrast (`src/composed-contrast.mts` `providedVariants`) resolves each
343
+ token the text's colour or a backdrop layer reads to the nearest provider at or
344
+ above the element that reads it; a provider under an owner state contributes its
345
+ condition to the pair's requirements, so it pairs only with that state's
346
+ backdrop. Chains are keyed by what their evaluation reads (`evaluationKey`), and
347
+ a component that places itself is followed through each recursive placement once
348
+ per chain, so nested inline content renderers stay within the chain bound.
349
+
350
+ **Content flows.** A region part may be a placed public component
351
+ (`PartContent.kind: "component"`), matched by its marker among the element's
352
+ component facts (`src/analysis/owner-source.mts`); lowering writes its placement
353
+ only. `writePartSpace` (`src/region-lowering.mts`) lowers part `spaceBefore` /
354
+ `spaceAfter` as start margins relative to the stack's gap, ranked by specificity
355
+ (before < after < pair) so the overlap check needs no order.
348
356
 
349
357
  **Entrances.** `enter` on a region root, a region part or a control root is
350
358
  parsed into an `EnterSpec` (`src/construction-spec.mts`) that carries its
@@ -412,6 +420,16 @@ every token context through the shared paint mechanism
412
420
  subtree to that context only when the foundation declares `sections: true`;
413
421
  either way `foundation.css` repaints the element with the document surface.
414
422
 
423
+ **Composition facts.** Each text position and placement records the chains of
424
+ owned elements above it in every reachable choice, with the props that select
425
+ each chain (`src/analysis/owner-composition.mts`). Only the props that change
426
+ the chain are recorded (`src/analysis/composition-axes.mts`, exact: a prop that
427
+ decides whether another is read is kept), so a large variant matrix whose other
428
+ props style other elements keeps few leaves per position; more than 512 distinct
429
+ leaves at one position is a limit. Positions on the same path share one
430
+ enumeration, and each element's facts and each attribute read are reused across
431
+ choices that assign the inputs they read the same.
432
+
415
433
  **Boundaries.** A boundary is a placement above which neither paint is known.
416
434
  A pair that the elements below a boundary decide is checked; a side that
417
435
  reaches it is `component-contrast-unresolved` at the placement.
@@ -420,10 +438,12 @@ reaches it is `component-contrast-unresolved` at the placement.
420
438
  show it passes its children through: it renders `children` in place, passes
421
439
  it on, or spreads its props into a placement. Any other same-file component
422
440
  ends the chain at its placement.
423
- - Plain modules record no composition facts, only the design-system components
424
- their markup places. These are read from the revision's program beside the
425
- other plain-module checks, each revision, so no owner outcome changes. The
426
- join ends those components' chains at each such placement.
441
+ - A plain module whose markup places design-system components (a sheet that
442
+ arranges rows and avatars) records composition facts as an owner does, read
443
+ from the revision's program beside the other plain-module checks, each
444
+ revision, so no owner outcome changes; the join follows its placements like an
445
+ owner's. Only where its facts cannot be read do its placements end the chain,
446
+ as unknown above.
427
447
 
428
448
  A native control's pair is the user agent's, and skipped, only when neither its
429
449
  colour nor any background between the text and its fill comes from the design
@@ -1202,6 +1222,16 @@ flowchart LR
1202
1222
  cache or `current`. Only validation and compilation that both pass against
1203
1223
  unchanged source publish the verified graph; a failure restores the last
1204
1224
  verified view.
1225
+ - **One check for a managed revision.** The MCP process's preview emitter checks
1226
+ in its analysis worker before emitting and sends a passing report over the
1227
+ private compiler channel, held in memory during that MCP process's lifetime.
1228
+ The Bun compiler's validation gate offers that report to the shared
1229
+ check service, which matches the full architecture-input key and refreshes
1230
+ output integrity before reuse. It still fences the build's inputs before
1231
+ publication. Missing or stale evidence checks normally; standalone compilation
1232
+ keeps its own gate. The emitter also seeds the live project's bounded saved
1233
+ reports, without eagerly storing acceptance candidates there. Native programs
1234
+ and owner facts remain in the worker that owns them; no worker cache is copied.
1205
1235
  - **Recovery.** Guarded publication invalidates the compiler explicitly.
1206
1236
  Content reconciliation recovers missed atomic file replacements, so OS watch
1207
1237
  delivery cannot establish freshness.
@@ -1414,7 +1444,9 @@ preview workspaces are full copies of that set.
1414
1444
  Neither set holds application source, public folders, the root `index.html` or
1415
1445
  tests outside `dsDir`. So an application, backend, native-toolchain or
1416
1446
  documentation edit never stales a validation, preview or acceptance revision.
1417
- The emitted output folder is never an input.
1447
+ The emitted output folder is never an input. Its integrity findings are read
1448
+ when a report is returned; the MCP server keeps them event-fed for its project
1449
+ ([caching](CACHING.md)).
1418
1450
 
1419
1451
  Compiled-preview cache keys need no read of application source or
1420
1452
  `node_modules`. The preview compiler's own inputs are the TypeScript
@@ -1493,12 +1525,38 @@ its analysis and emitted module
1493
1525
  ([caching](CACHING.md#owner-analysis-reuse)).
1494
1526
 
1495
1527
  The analysis service bounds active project and revision state. It closes after
1496
- idle time when no registered revision pins it. Direct library clients and
1497
- syntax-only clients have their own short idle cleanup. A one-shot CLI command
1498
- closes its clients when it has reported, so it exits without a wait for that
1499
- idle period. When one scenario inspector closes, its requests are canceled and
1500
- the shared compiler of other callers stays. Persisted registry metadata has
1501
- separate content checks.
1528
+ idle time when no registered revision pins it. Direct library clients keep
1529
+ their native sessions for 60 seconds after their last call, so spaced-out calls
1530
+ keep their programs and ASTs; while idle, a session's compiler process does not
1531
+ hold the event loop, so a finished caller exits at once. Syntax-only clients
1532
+ have their own short idle cleanup. A one-shot CLI command closes its clients
1533
+ when it has reported. When one scenario inspector closes, its requests are
1534
+ canceled and the shared compiler of other callers stays. Persisted registry
1535
+ metadata has separate content checks.
1536
+
1537
+ Cancelling an analysis request stops its work in the analysis worker, not only
1538
+ the caller's wait: the service sends a `cancel` message that the worker serves
1539
+ as it arrives, ahead of its queue. A queued request is answered without running;
1540
+ a running one stops at its next cancellation point (between owners, choices,
1541
+ scenarios, closure files and extracted constructions; `throwIfCancelled` in
1542
+ `src/analysis/context.mts`). Caches keep settled outcomes only, so a canceled
1543
+ analysis leaves nothing behind.
1544
+
1545
+ An unregistered analysis request sends the worker only the files that changed
1546
+ since the inventory the service last sent for that root, named by that
1547
+ inventory. The worker applies the changes only when it holds exactly that
1548
+ inventory (a registration or promotion of the project, or a restart, clears it);
1549
+ otherwise it refuses them and the complete inventory is sent. Stage tracing
1550
+ reports each request's `files` and whether they were `changes` on
1551
+ `analysis-inventory`.
1552
+
1553
+ Configuration read during an analysis is the captured revision's:
1554
+ `ds.config.json` (`loadConfig`) and the TypeScript configuration with its local
1555
+ `extends` chain (`projectCompilerOptions`) are read through the capture, never
1556
+ from newer bytes on disk: every `extends` target named by a path, relative or
1557
+ absolute, is read from the revision, and one the revision lacks or cannot parse
1558
+ is reported (`typescript-config-invalid`) instead of read from disk. A package
1559
+ configuration in `extends` is an installed dependency.
1502
1560
 
1503
1561
  ## On-demand visual evidence
1504
1562
 
@@ -1604,6 +1662,14 @@ and its exemptions.
1604
1662
  - Each render waits, bounded, for its content to settle, and the audit also
1605
1663
  renders interaction states (opened `aria-haspopup` overlays, hovered and
1606
1664
  focused controls).
1665
+ - Owner states are derived, not written (`src/derived-states.mts`): emission
1666
+ reads each construction's lowered CSS, whose selectors all start at its root,
1667
+ takes the compound after the root class as the state, and writes it with the
1668
+ construction's class string to the preview-only `ads-preview-audit.json`.
1669
+ The audit reads it once the previews are built and hands it to the page,
1670
+ which matches a construction by `data-ads-source` (the owner) and the element's
1671
+ classes; within one owner a class string is one construction. Nothing is added
1672
+ to rendered markup, and the facts never reach emitted output.
1607
1673
  - Each worker lists what every render could measure, then assigns targets in
1608
1674
  request order, so which render measures a shared control does not depend on
1609
1675
  page speed.
package/docs/CACHING.md CHANGED
@@ -31,16 +31,57 @@ The key includes:
31
31
  dependency inputs, configuration and lockfiles;
32
32
  - the installed package manifests of declared dependencies, and Git tracking of
33
33
  generated paths;
34
- - the emitted output folder, read by content: its `generated-modified` findings
35
- and the revision its contract records;
34
+ - the revision the emitted output folder's contract records (its contract file
35
+ alone);
36
36
  - the ADS implementation, the runtime and platform, and the check's semantic
37
37
  environment (`NODE_ENV`, `NODE_OPTIONS`, `BUN_OPTIONS`, `TZ`, `LANG`,
38
38
  `LC_ALL`).
39
39
 
40
+ The output folder's emitted files are not an input: a returned report, reused or
41
+ not, carries their `generated-modified` findings read by content when it is
42
+ returned (`withCurrentOutput`, `src/emit/integrity.mts`), once per check instead
43
+ of once per key calculation. A returned report is the evidence a fresh check
44
+ gives for those findings: failed, with acceptance not established, when the
45
+ folder was edited.
46
+
47
+ The MCP server's own project keeps those findings event-fed instead
48
+ (`src/emit/output-watch.mts`): a content-digest map of the output folder, like
49
+ the source inputs' (`src/input-digests.mts`), walked once and then re-reading
50
+ only the files its watcher reports, by content. These integrity findings read the
51
+ contract file again only when its digest changed, and no other emitted file unless
52
+ one was edited (the report-cache key still reads the contract's recorded revision);
53
+ a new, removed or replaced entry walks the folder again, as does the periodic
54
+ safety-net walk. Draft candidates and one-shot checks read the folder directly.
55
+ After a full walk, the shared watcher manager compares device and inode identities
56
+ and reopens handles for replaced directories, including descendants whose paths
57
+ are unchanged. Later edits in a tree replaced by `ads emit` therefore still reach
58
+ the digest map. This reconciliation adds no filesystem reads to unchanged hits.
59
+
40
60
  Inputs are fenced around execution and when a hit is consumed. Install from the
41
61
  lockfile; after hand-modifying installed packages without a lockfile change,
42
62
  request a fresh check.
43
63
 
64
+ The MCP preview emitter checks in the server's analysis worker. A successful,
65
+ fenced emission also stores that report in the server's saved-report shortcut,
66
+ so its first ordinary check can be a direct hit. Eager storage is limited to the
67
+ long-lived project: emitting an acceptance candidate does not add its report to
68
+ the live project's 16-entry list.
69
+
70
+ The emitter sends the passing report and its full task-input key over the existing
71
+ private compiler channel. The report stays in memory for the MCP process's
72
+ lifetime; it is not written to the preview tree or its disk state. The managed
73
+ compiler offers that evidence to its ordinary validation gate,
74
+ which reuses it only when current source membership and bytes, configuration,
75
+ dependencies, Git tracking, tool/runtime, environment and output revision match.
76
+ For the managed compiler, environment means its captured launch environment,
77
+ shared with its build-cache key; Bun's internal `NODE_ENV` change while preparing
78
+ a build does not create a different checking revision.
79
+ Output-integrity findings are refreshed when the report is consumed. Missing,
80
+ malformed or stale evidence runs a normal check; a fresh request bypasses it.
81
+ Standalone compilation retains its own check. An emission whose check reports
82
+ an output-modification finding supplies no passing evidence, so compilation
83
+ still rejects that finding.
84
+
44
85
  What a hit establishes:
45
86
 
46
87
  - A matching report skips rule execution; a changed key requires a new check.
@@ -69,7 +110,8 @@ What a hit establishes:
69
110
  | Relocated draft ASTs | Owned by that draft; releasing it drops the wrapper cache without changing sibling/live paths |
70
111
  | Warm reports and Turbo task artifacts | See [check paths](#check-paths); they hold no live compiler handles or acceptance state |
71
112
  | Construction extractions | Content-keyed, owner-independent compiled CSS; in memory per project, and [persisted](#persisted-extraction-cache) |
72
- | Owner analyses | [Content-keyed per owner](#owner-analysis-reuse); in memory per project (drafts share it, keyed by their own root), at most 512 owners × 3 token revisions; a released draft drops its entries |
113
+ | Owner analyses | [Content-keyed per owner](#owner-analysis-reuse), root-relative; in memory per project (drafts and acceptance candidates share it), at most 512 owners × 3 token revisions; an entry is dropped once every root that used it is released |
114
+ | Construction lowerings | [Content-keyed per construction](#construction-reuse), root-relative; in memory per project, at most 8192 constructions × 2 token revisions; released with owner analyses |
73
115
 
74
116
  Rules read source text from the captured revision.
75
117
  [Captured inputs](ARCHITECTURE.md#captured-inputs) covers warm-check captures,
@@ -104,10 +146,15 @@ inputs changed. The key
104
146
  graph), plus the public barrel when the closure imports the public alias;
105
147
  - every project source that may declare into the global scope (scripts such as
106
148
  `env.d.ts`, `declare global`, `declare module`);
107
- - the profile declarations, the asset records, and the public rows of owners in
108
- its closure analyzed before it;
109
- - the analysed root, `publicAlias`, themes, the compiler session's external
110
- inputs (installed declarations, compared by content) and the schema.
149
+ - the public rows of owners in its closure analyzed before it;
150
+ - `publicAlias`, themes, the compiler session's external inputs (installed
151
+ declarations, compared by content) and the schema.
152
+
153
+ The profile declarations and the asset records are not in the key: an outcome
154
+ records what it read of them and is reused only while those reads give the same
155
+ results ([design reads](#design-reads)). The key does not name where the design system is analysed: paths under the
156
+ analysed root are written root-relative, so a draft workspace or an acceptance
157
+ candidate and the live project share an unchanged owner's entry.
111
158
 
112
159
  A session closed while idle hands its observed external inputs to the next
113
160
  session of the same root, which keeps the environment identity only when every
@@ -126,17 +173,56 @@ the profile declarations already in its key. The composed contrast join over
126
173
  every owner's facts belongs to the revision's memoized check, not to an owner's
127
174
  entry: a token edit reuses every owner analysis and reruns only the join (stage
128
175
  `composed-contrast`), and an owner edit changes that owner's facts alone. The
129
- outcome schema is `ads-owner-analysis/9` (it carries each owner's closed props for the showcase's live controls); it includes the composition facts and
176
+ outcome schema is `ads-owner-analysis/12` (it carries each owner's closed props for the showcase's live controls, the assets it draws with the size of each, and which value of each prop a placement that leaves the prop out selects); it includes the composition facts and
130
177
  the profile/choice inventory `design`.
131
178
 
132
179
  - Settled outcomes (facts or a deterministic analysis failure) are reused;
133
180
  exceptions such as cancellation are never stored.
134
- - A draft never reuses or changes the base project's entries: outcomes carry
135
- absolute source paths, so the analysed root is part of the key.
136
- - `ADS_VERIFY_OWNER_REUSE=1` re-analyzes every reused owner and fails on any
137
- difference. Stage tracing reports `owners`, `reused` and `analyzed` on
181
+ - Drafts, acceptance candidates and the live project share entries. Outcomes
182
+ carry absolute source paths; one analysed under another root is relocated to
183
+ the requesting root (every path under that root, in file names and messages)
184
+ before it is returned. An entry records each root that analysed or reused it;
185
+ releasing a draft forgets its root and drops only the entries no other root
186
+ uses. An MCP edit, check or acceptance therefore analyzes only the owners
187
+ whose inputs it changed.
188
+ - `ADS_VERIFY_OWNER_REUSE=1` re-analyzes every reused owner, relocated ones
189
+ included, and fails on any difference. Stage tracing reports `owners`, `reused` and `analyzed` on
138
190
  `owner-facts` and `owner-analysis`.
139
191
 
192
+ ## Construction reuse
193
+
194
+ An owner whose inputs changed is analyzed again, but an edit rarely changes
195
+ every construction it can produce. Each construction's lowering and its checks
196
+ (state contrast, non-text contrast, inactive surfaces, corner overpaint,
197
+ runtime paints, hover geometry, surface uses) are a pure function of its
198
+ content, and are reused from the project's construction memo
199
+ (`src/analysis/construction-memo.mts`). The key is the digest of:
200
+
201
+ - the construction's identity, which also names its root class: its combined
202
+ spec and every fact that selects it (text, drawings, artwork state and theme,
203
+ hidden targets, inherited grids, aligned rows, decorative parts);
204
+ - the owner's private-name scope;
205
+ - the asset records it draws, by content (root-relative), and the declared
206
+ contexts;
207
+ - the schema (`ads-construction/2`: a placed drawing carries the size it is drawn at).
208
+
209
+ The profile declarations are not in the key: a lowering records the profiles it
210
+ read ([design reads](#design-reads)), and its outcome is reused only while they
211
+ read the same; reusing it replays those reads on the owner's own trace.
212
+
213
+ Token values are recorded the way owner analyses record them: a lowering that
214
+ read token values keeps one outcome per token-sheet digest, and reusing it
215
+ records the read on the owner's own evidence, so the owner stays
216
+ token-dependent. A failed construction is stored with its reviews and reproduces
217
+ the same finding. Reviews and failures are stored at their authored recipe path
218
+ and placed at the current revision's source when replayed; the analysis appends
219
+ an owner's further uses to a copy, never to the stored construction.
220
+
221
+ Choice enumeration, the owner's markup checks and its composition facts still
222
+ run for every analyzed owner. Stage tracing reports `reused` and `built` on
223
+ `construction-reuse`; `ADS_VERIFY_OWNER_REUSE=1` lowers every reused
224
+ construction again and fails on any difference.
225
+
140
226
  ## Import closure reuse
141
227
 
142
228
  The import closure rule (`src/design-system-closure.mts`) resolves every
@@ -149,14 +235,49 @@ and an owner edit resolves that owner's imports alone.
149
235
  - **Key.** The file's bytes and path, the closure's settings (compiler options
150
236
  and excluded folders), the revision's captured file membership (an added or
151
237
  removed file can change what a specifier resolves to), the compiler session's
152
- external inputs (installed packages) and the schema.
153
- - **Lifetime.** The analyzing process; entries of a discarded draft workspace
154
- are released with it.
238
+ external inputs (installed packages) and the schema
239
+ (`ads-design-system-closure/2`), all relative to the analysed project root.
240
+ - **Lifetime.** The analyzing process; a draft workspace or acceptance candidate
241
+ reuses the live project's entries, relocated to its own paths. An entry is
242
+ released once every root that used it is released.
155
243
  - **Bound.** 8192 files, least recently used first out.
156
244
 
245
+ Stage tracing reports `computed` and `reused` on `design-system-closure`;
246
+ `ADS_VERIFY_OWNER_REUSE=1` checks every reused file again.
247
+
248
+ The design inputs (foundation, asset and font records) are read once per
249
+ content: their key is the design files' bytes by design-system-relative name.
250
+ A read under another root is the same read with its asset and font paths moved,
251
+ and everything else (the foundation and its profiles) keeps its identity; each
252
+ entry keeps the moved reads of its last 4 roots.
253
+
157
254
  Without a compiler session's environment identity, every file is checked every
158
255
  revision.
159
256
 
257
+ ## Design reads
258
+
259
+ Owner analyses and construction lowerings record what they read of the profile
260
+ declarations and the asset catalog (`src/analysis/design-reads.mts`), so a
261
+ profile or asset edit invalidates only the results that read what changed:
262
+
263
+ - A read is recorded with its result: `profiles.get`/`has` and the catalog
264
+ maps' `get`/`has` by key, and the profile model's `compose`, `select` and
265
+ `variants` by their arguments (a composed or selected profile includes what it
266
+ extends and binds). Results are digested by content only when a replay
267
+ compares them; asset values are digested root-relative.
268
+ - Iterating a map or reading the foundation's `hash` reads its whole group
269
+ (profiles, or the catalog); the evidence then holds that group's digest by
270
+ content.
271
+ - The evidence also records the revision's whole profile and asset digests.
272
+ While a group's digest is unchanged (every token edit), its reads are not
273
+ replayed. Otherwise reuse replays them against the current revision: equal
274
+ digests mean the result is still valid; a result with no canonical form never
275
+ matches. A comment-only profile edit changes no digest,
276
+ and restoring an edit finds the earlier outcome (a slot keeps up to 3 outcomes
277
+ with different evidence).
278
+ - Profile validation (duplicates, unknown references, composition) still runs
279
+ for every revision in the design-input read.
280
+
160
281
  ## Scenario facts reuse
161
282
 
162
283
  `ads check` registers every scenario, traces what its specimens render
@@ -180,14 +301,18 @@ assembled from them for every revision.
180
301
  name);
181
302
  - the check program's global-scope declarations and the compiler session's
182
303
  external inputs;
183
- - the project and design-system roots, `publicAlias` and the schema.
304
+ - the design-system folder relative to the project root, `publicAlias` and
305
+ the schema (`ads-scenario-facts/4`). The key is written relative to the
306
+ project root.
184
307
  - **Lifetime.** The analyzing process; one cache per project, shared by its
185
- drafts, whose entries are released with the draft workspace.
308
+ drafts and acceptance candidates: a result is kept by the analysed project
309
+ root and relocated to the requesting one. An entry is released once every
310
+ root that used it is released.
186
311
  - **Bound.** 2048 results per project (a scenario's facts and its styling are
187
312
  one each, per key), least recently used first out; 8 projects per process. The
188
313
  resolved import edges of development modules (keyed by their bytes, the
189
- revision's file membership and the session's external inputs) share one bound
190
- of 4096 modules.
314
+ revision's file membership and the session's external inputs, relative to the
315
+ project root, so drafts share them) share one bound of 4096 modules.
191
316
 
192
317
  A token edit, an edit inside an owner no scenario reaches and a restored
193
318
  revision compute no scenario facts. An edit of a scenario, a fixture it reads, a
@@ -198,7 +323,9 @@ scenario: no second program).
198
323
  Without a module graph and check program (owner analysis rejected the revision),
199
324
  facts are read through the scenario program the registry uses. Without a known
200
325
  compiler environment, every scenario is computed. Stage tracing reports
201
- `computed` and `reused` on `owner-scenarios`. The scenarios' TypeScript
326
+ `computed` and `reused` on `owner-scenarios` (facts) and `scenario-styling`;
327
+ `ADS_VERIFY_OWNER_REUSE=1` computes every reused scenario result again and
328
+ fails on any difference. The scenarios' TypeScript
202
329
  diagnostics are part of the program-wide diagnostics.
203
330
 
204
331
  Framework identity (`src/analysis/framework-imports.mts`) reads every captured
@@ -242,10 +369,11 @@ it with the digest of the bytes it captured from the live project. When they
242
369
  differ, the captured revision is analysed instead; an analysis that does not
243
370
  match its own capture is reported as `source-changed`.
244
371
 
245
- The analysed root is part of the owner keys, so the candidate's owner analyses
246
- and emitted modules are keyed under the candidate root. The next emit or check
247
- of the live project in the same process analyzes its owners once under the live
248
- root's keys.
372
+ The acceptance's emit runs with the live project as its tracking root, as its
373
+ check does, so it uses the project's caches. Owner keys and emitted-module keys
374
+ are root-relative (the module text names its imports relative to itself): the
375
+ candidate reuses the modules of every owner the draft left unchanged, and the
376
+ next emit or check of the live project reuses the candidate's.
249
377
 
250
378
  ## Persisted extraction cache
251
379