@reqvire-org/ads 0.3.53 → 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 (138) hide show
  1. package/README.md +9 -8
  2. package/dist/assets.mjs +1 -1
  3. package/dist/behaviors.mjs +6 -5
  4. package/dist/boundaries.mjs +5 -5
  5. package/dist/browser-audit.mjs +10 -5
  6. package/dist/bun-compiler.mjs +14 -7
  7. package/dist/check-service.mjs +83 -0
  8. package/dist/check.mjs +16 -17
  9. package/dist/cli.mjs +4 -2
  10. package/dist/config.mjs +17 -40
  11. package/dist/contracts.d.mts +9 -0
  12. package/dist/fonts-generated.mjs +2 -0
  13. package/dist/generated-entries.mjs +131 -0
  14. package/dist/icons.mjs +1 -1
  15. package/dist/init.mjs +11 -32
  16. package/dist/layers.mjs +7 -3
  17. package/dist/lint-config.mjs +4 -2
  18. package/dist/mcp/catalog.mjs +2 -1
  19. package/dist/mcp/context.mjs +3 -3
  20. package/dist/mcp/drafts.mjs +136 -121
  21. package/dist/mcp/mutations.mjs +65 -19
  22. package/dist/mcp/preview-watch.mjs +31 -5
  23. package/dist/mcp/prompts.mjs +1 -1
  24. package/dist/mcp/server.mjs +79 -38
  25. package/dist/mcp/showcase-host.mjs +20 -7
  26. package/dist/oxlint.mjs +3 -2
  27. package/dist/program-cache.mjs +36 -0
  28. package/dist/public-api.mjs +2 -1
  29. package/dist/scenarios-compiler.mjs +82 -14
  30. package/dist/scenarios-vite.mjs +1 -1
  31. package/dist/scenarios.mjs +4 -3
  32. package/dist/showcase/client.bundle.js +1 -1
  33. package/dist/showcase/index.html +2 -2
  34. package/dist/skills/ads-break-ui/SKILL.md +25 -28
  35. package/dist/skills/ads-break-ui/references/behaviors.md +7 -6
  36. package/dist/skills/ads-break-ui/references/captures.md +7 -32
  37. package/dist/skills/ads-break-ui/references/contracts.md +58 -25
  38. package/dist/skills/ads-break-ui/references/drafts.md +59 -43
  39. package/dist/skills/ads-break-ui/references/evidence.md +1 -1
  40. package/dist/skills/ads-break-ui/references/guarded-editing.md +58 -47
  41. package/dist/skills/ads-break-ui/references/review.md +9 -8
  42. package/dist/skills/ads-break-ui/references/scenarios.md +1 -1
  43. package/dist/skills/ads-break-ui/references/validation.md +8 -4
  44. package/dist/skills/ads-break-ui/references/workflows.md +15 -8
  45. package/dist/skills/ads-designer/SKILL.md +25 -28
  46. package/dist/skills/ads-designer/references/accessibility.md +9 -5
  47. package/dist/skills/ads-designer/references/behaviors.md +7 -6
  48. package/dist/skills/ads-designer/references/captures.md +7 -32
  49. package/dist/skills/ads-designer/references/cli.md +5 -1
  50. package/dist/skills/ads-designer/references/contracts.md +58 -25
  51. package/dist/skills/ads-designer/references/drafts.md +59 -43
  52. package/dist/skills/ads-designer/references/evidence.md +1 -1
  53. package/dist/skills/ads-designer/references/guarded-editing.md +58 -47
  54. package/dist/skills/ads-designer/references/performance.md +3 -2
  55. package/dist/skills/ads-designer/references/review.md +9 -8
  56. package/dist/skills/ads-designer/references/scenarios.md +1 -1
  57. package/dist/skills/ads-designer/references/validation.md +8 -4
  58. package/dist/skills/ads-designer/references/workflows.md +15 -8
  59. package/dist/skills/ads-import/SKILL.md +25 -28
  60. package/dist/skills/ads-import/references/behaviors.md +7 -6
  61. package/dist/skills/ads-import/references/captures.md +7 -32
  62. package/dist/skills/ads-import/references/cli.md +5 -1
  63. package/dist/skills/ads-import/references/contracts.md +58 -25
  64. package/dist/skills/ads-import/references/drafts.md +59 -43
  65. package/dist/skills/ads-import/references/evidence.md +1 -1
  66. package/dist/skills/ads-import/references/guarded-editing.md +58 -47
  67. package/dist/skills/ads-import/references/review.md +9 -8
  68. package/dist/skills/ads-import/references/scenarios.md +1 -1
  69. package/dist/skills/ads-import/references/validation.md +8 -4
  70. package/dist/skills/ads-import/references/workflows.md +15 -8
  71. package/dist/skills/ads-motion/SKILL.md +25 -28
  72. package/dist/skills/ads-motion/references/behaviors.md +7 -6
  73. package/dist/skills/ads-motion/references/captures.md +7 -32
  74. package/dist/skills/ads-motion/references/contracts.md +58 -25
  75. package/dist/skills/ads-motion/references/drafts.md +59 -43
  76. package/dist/skills/ads-motion/references/evidence.md +1 -1
  77. package/dist/skills/ads-motion/references/guarded-editing.md +58 -47
  78. package/dist/skills/ads-motion/references/review.md +9 -8
  79. package/dist/skills/ads-motion/references/scenarios.md +1 -1
  80. package/dist/skills/ads-motion/references/validation.md +8 -4
  81. package/dist/skills/ads-motion/references/workflows.md +15 -8
  82. package/dist/skills/ads-port/SKILL.md +25 -28
  83. package/dist/skills/ads-port/references/behaviors.md +7 -6
  84. package/dist/skills/ads-port/references/captures.md +7 -32
  85. package/dist/skills/ads-port/references/cli.md +5 -1
  86. package/dist/skills/ads-port/references/contracts.md +58 -25
  87. package/dist/skills/ads-port/references/drafts.md +59 -43
  88. package/dist/skills/ads-port/references/evidence.md +1 -1
  89. package/dist/skills/ads-port/references/guarded-editing.md +58 -47
  90. package/dist/skills/ads-port/references/native-implementation.md +6 -6
  91. package/dist/skills/ads-port/references/review.md +9 -8
  92. package/dist/skills/ads-port/references/scenarios.md +1 -1
  93. package/dist/skills/ads-port/references/validation.md +8 -4
  94. package/dist/skills/ads-port/references/workflows.md +15 -8
  95. package/dist/starters/preact/design-system/components/Layout/Grid/Grid.ads.contract.ts +6 -0
  96. package/dist/starters/preact/design-system/review/token-preview/TokenPreview.ads.contract.ts +6 -0
  97. package/dist/starters/preact/ds.config.json +0 -14
  98. package/dist/starters/react/README.md +9 -5
  99. package/dist/starters/react/design-system/components/Actions/Button/Button.ads.exports.ts +1 -0
  100. package/dist/starters/react/design-system/components/Actions/IconButton/IconButton.ads.exports.ts +1 -0
  101. package/dist/starters/react/design-system/components/Content/Icon/Icon.ads.exports.ts +1 -0
  102. package/dist/starters/react/design-system/components/Content/Image/Image.ads.exports.ts +1 -0
  103. package/dist/starters/react/design-system/components/Content/Logo/Logo.ads.exports.ts +1 -0
  104. package/dist/starters/react/design-system/components/Forms/TextField/TextField.ads.exports.ts +1 -0
  105. package/dist/starters/react/design-system/components/Layout/Grid/Grid.ads.contract.ts +6 -0
  106. package/dist/starters/react/design-system/components/Layout/Grid/Grid.ads.exports.ts +1 -0
  107. package/dist/starters/react/design-system/controllers/Palette/Palette.ads.exports.ts +1 -0
  108. package/dist/starters/react/design-system/index.ts +3 -7
  109. package/dist/starters/react/design-system/patterns/Search/SearchBar/SearchBar.ads.exports.ts +1 -0
  110. package/dist/starters/react/design-system/review/brand-preview/BrandPreview.ads.exports.ts +1 -0
  111. package/dist/starters/react/design-system/review/demo-frame/DemoFrame.ads.exports.ts +1 -0
  112. package/dist/starters/react/design-system/review/grid-cell/GridCell.ads.exports.ts +1 -0
  113. package/dist/starters/react/design-system/review/index.ts +4 -3
  114. package/dist/starters/react/design-system/review/screen-frame/ScreenFrame.ads.exports.ts +1 -0
  115. package/dist/starters/react/design-system/review/token-preview/TokenPreview.ads.contract.ts +6 -0
  116. package/dist/starters/react/design-system/review/token-preview/TokenPreview.ads.exports.ts +1 -0
  117. package/dist/starters/react/design-system/styles.css +1 -0
  118. package/dist/starters/react/ds.config.json +0 -14
  119. package/dist/style-boundaries.mjs +7 -6
  120. package/dist/test-boundaries.mjs +2 -2
  121. package/dist/themes-watch.mjs +9 -3
  122. package/dist/token-fixtures.mjs +1 -1
  123. package/dist/unit-contracts.mjs +38 -4
  124. package/dist/units.mjs +16 -91
  125. package/dist/validation-checks.mjs +7 -1
  126. package/docs/ADS.md +10 -10
  127. package/docs/ARCHITECTURE.md +79 -43
  128. package/docs/BEHAVIORS.md +8 -7
  129. package/docs/CACHING.md +15 -6
  130. package/docs/CHANGELOG.md +61 -12
  131. package/docs/COMPARISON.md +1 -1
  132. package/docs/CONTRACTS.md +10 -25
  133. package/docs/GUIDE.md +64 -55
  134. package/docs/MCP.md +116 -151
  135. package/package.json +1 -1
  136. package/dist/contract-migration.mjs +0 -110
  137. package/dist/mcp/draft-exports.mjs +0 -40
  138. package/dist/mcp/edit-preparation.mjs +0 -115
@@ -18,6 +18,7 @@ import { holdLivePreview, preparePreviewCache } from "../scenarios-compiler.mjs"
18
18
  import { validationInputFiles } from "../validation-inputs.mjs";
19
19
  import { mutationLimits } from "./mutation-limits.mjs";
20
20
  import { writeThemesCss } from "../themes-generated.mjs";
21
+ import { generatedEntries } from "../generated-entries.mjs";
21
22
  import { inspectTokens } from "../tokens.mjs";
22
23
 
23
24
  export { mutationLimits } from "./mutation-limits.mjs";
@@ -47,7 +48,7 @@ function address(options, file) {
47
48
  return target;
48
49
  }
49
50
 
50
- function readPatchFile(options, file) {
51
+ export function readPatchFile(options, file) {
51
52
  if (typeof file !== "string" || file.includes("\\") || file.includes("\0") || !/^\.ds\/patches\/[^/]+\.(?:patch|diff)$/.test(file)) throw fail("mutation-patch", "Patch files must be regular .patch/.diff files in .ds/patches/.");
52
53
  const target = path.join(options.root, file);
53
54
  for (const current of [path.join(options.root, ".ds"), path.dirname(target), target]) {
@@ -144,6 +145,8 @@ function mutationEvidence(result, candidateRevision) {
144
145
 
145
146
 
146
147
  export function createMutationController(directory, { captures = createCaptureController(directory), previewWork } = {}) {
148
+ // A passing dry run's audit holds for accepting the same candidate: remembered by its revision and selection.
149
+ const audits = new Map();
147
150
  const root = path.resolve(directory);
148
151
  let busy = false;
149
152
  let lastResult = null;
@@ -155,7 +158,7 @@ export function createMutationController(directory, { captures = createCaptureCo
155
158
  let commands = [], diagnostics = [];
156
159
  try { commands = checks(options).map(check => [check.command, ...check.args].join(" ")); }
157
160
  catch (error) { diagnostics = [error.diagnostic ?? { rule: "mutation-check", message: error.message }]; }
158
- return { enabled: true, scope: "one-ds-unit", format: "git-unified-diff", transactions:{tool:"ads_apply_transaction",maxUnits:mutationLimits.units,finalCandidateChecks:true}, preparation:{owner:"ads_prepare_patch",tokenSamples:"ads_prepare_token_samples"}, dsDir: options.config.dsDir, limits: mutationLimits, checks: ["ads check", ...commands, ...options.config.mcp.previewManifest && options.config.mcp.previewWatch ? ["managed production previews"] : []], diagnostics, busy, ...(progress ? { progress } : {}), lastResult };
161
+ return { enabled: true, scope: "one-ds-unit", format: "git-unified-diff", route:"draft", drafts:{create:"ads_create_draft",edit:"ads_update_draft",review:"ads_show_draft",accept:"ads_accept",maxUnits:mutationLimits.units,finalCandidateChecks:true}, preparation:{tokenSamples:"ads_prepare_token_samples"}, dsDir: options.config.dsDir, limits: mutationLimits, checks: ["ads check", ...commands, ...options.config.mcp.previewManifest && options.config.mcp.previewWatch ? ["managed production previews"] : []], diagnostics, busy, ...(progress ? { progress } : {}), lastResult };
159
162
  },
160
163
  cancel() { active?.abort(); },
161
164
  units() { return inspectUnits(loadConfig(root)).units; },
@@ -171,7 +174,7 @@ export function createMutationController(directory, { captures = createCaptureCo
171
174
  return { ...source, unit, content, offset, nextOffset: end < source.content.length ? end : null, totalChars: source.content.length,
172
175
  startLine: source.content.slice(0, offset).split("\n").length };
173
176
  },
174
- async apply({ unit, patch, patchFile, patches, dryRun = false, screenshot = false, captures: selections }, signal, notifyProgress, { beforeApply } = {}) {
177
+ async apply({ unit, patch, patchFile, files, patches, checkRoot, previewHost: reviewedHost, dryRun = false, screenshot = false, captures: selections }, signal, notifyProgress, { beforeApply } = {}) {
175
178
  if (busy) return mutationEvidence({ ok: false, applied: false, diagnostics: [{ rule: "mutation-busy", message: "Another mutation is validating; retry after it finishes.",failure:evidenceFailure("runner","mutation-execution","ADS_MUTATION_BUSY") }] });
176
179
  busy = true;
177
180
  active = new AbortController();
@@ -184,11 +187,16 @@ export function createMutationController(directory, { captures = createCaptureCo
184
187
  if (screenshot && !dryRun || selections !== undefined && !screenshot) throw fail("mutation-capture", "Use screenshot:true only with dryRun:true and an explicit captures:[{scenario,target?,theme?,brand?,viewport?}] selection. Ordinary patches create no screenshots.");
185
188
  if (screenshot) selections = captureSelections(selections);
186
189
  if (patches !== undefined && (unit !== undefined || patch !== undefined || patchFile !== undefined || !Array.isArray(patches) || patches.length < 2 || patches.length > mutationLimits.units)) throw fail("mutation-batch", `A transaction requires 2–${mutationLimits.units} distinct owner patches, without a top-level unit/patch.`);
187
- const groups = patches ?? [{unit,patch,patchFile}];
190
+ const groups = patches ?? [{unit,patch,patchFile,...(files ? {files} : {})}];
188
191
  if (new Set(groups.map(group => group.unit)).size !== groups.length) throw fail("mutation-batch", "Use one patch per distinct unit in a transaction.");
189
192
  let patchBytes = 0;
190
193
  const plans = groups.map(group => {
191
194
  validateUnitId(group.unit);
195
+ // A draft hands over its proposed files as they are; no diff round trip.
196
+ if (group.files !== undefined) {
197
+ if (group.patch !== undefined || group.patchFile !== undefined || !Array.isArray(group.files) || !group.files.length || group.files.length > mutationLimits.files) throw fail("mutation-batch", "Provide an owner's proposed files, or one patch, not both.");
198
+ return {unit:group.unit,entries:group.files.map(file => ({path:file.path, direct:true, content:file.content}))};
199
+ }
192
200
  if ((typeof group.patch === "string") === (typeof group.patchFile === "string")) throw fail("mutation-patch", "Provide exactly one of patch or patchFile for each owner.");
193
201
  const value = group.patchFile === undefined ? group.patch : readPatchFile(options,group.patchFile);
194
202
  const maxPatch = group.patchFile === undefined ? mutationLimits.patchBytes : mutationLimits.patchFileBytes;
@@ -234,8 +242,8 @@ export function createMutationController(directory, { captures = createCaptureCo
234
242
  const current = loadConfig(candidate), selected = plan.entries.map(entry => {
235
243
  address(options,entry.path);
236
244
  const before = read(current,entry.path);
237
- if (!entry.binary && before.binary) throw fail("mutation-patch", "Binary assets require a git diff --binary patch.", entry.path);
238
- const change = {path:entry.path, originalContent:before.content, content:entry.binary ? entry.operation === "delete" ? null : before.content ?? Buffer.alloc(0) : applyFilePatch(entry,before.content), ...(entry.binary ? {binaryPatch:entry.patch} : {})};
245
+ if (!entry.binary && !entry.direct && before.binary) throw fail("mutation-patch", "Binary assets require a git diff --binary patch.", entry.path);
246
+ const change = {path:entry.path, originalContent:before.content, content:entry.direct ? entry.content : entry.binary ? entry.operation === "delete" ? null : before.content ?? Buffer.alloc(0) : applyFilePatch(entry,before.content), ...(entry.binary ? {binaryPatch:entry.patch} : {})};
239
247
  if (!entry.binary) validateContent(change,plan.unit);
240
248
  if (!byPath.has(entry.path)) {
241
249
  const original = read(options,entry.path);
@@ -262,10 +270,28 @@ export function createMutationController(directory, { captures = createCaptureCo
262
270
  }
263
271
  checkUnitCandidate(loadConfig(candidate),plan.unit,selected,inventory);
264
272
  }
265
- // Token sheet and theme/brand config patches carry the regenerated theme sheet with them.
273
+ // ADS removes an empty .gitkeep itself once accepted source is added beneath it.
274
+ for (const change of changes.filter(item => item.originalContent === null && item.content !== null)) {
275
+ for (let directory = path.posix.dirname(change.path); directory !== "." && isInside(options.dsRoot, path.join(root, directory)) && path.join(root, directory) !== options.dsRoot; directory = path.posix.dirname(directory)) {
276
+ const marker = `${directory}/.gitkeep`, live = read(options, marker);
277
+ if (!live.exists || live.content !== "" || byPath.has(marker)) continue;
278
+ originals.push({...live,mode:lstatSync(address(options,marker)).mode});
279
+ byPath.set(marker,changes.length);
280
+ changes.push({path:marker,originalContent:"",content:null,expectedDigest:live.digest});
281
+ // The live placeholder is part of the baseline the publication fences against.
282
+ copiedInputs.set(marker,digest(Buffer.from("")));
283
+ rmSync(path.join(candidate,marker),{force:true});
284
+ }
285
+ }
286
+ // Token sheet and theme/brand config changes carry the regenerated theme sheet with them,
287
+ // and exports file or token sheet changes carry the regenerated entries (barrels, styles entry).
266
288
  {
267
289
  const generatedOptions = loadConfig(candidate);
268
- for (const generated of writeThemesCss(generatedOptions, inspectTokens(candidate, generatedOptions)).files) {
290
+ // Theme files first: the public barrel publishes the generated font preloads when they exist.
291
+ const themes = writeThemesCss(generatedOptions, inspectTokens(candidate, generatedOptions)).files;
292
+ const barrels = generatedEntries(generatedOptions);
293
+ for (const barrel of barrels) { mkdirSync(path.dirname(barrel.file), { recursive: true }); writeFileSync(barrel.file, barrel.text); }
294
+ for (const generated of [...themes, ...barrels]) {
269
295
  const relative = path.relative(candidate, generated.file).replaceAll("\\", "/"), current = generated.text !== undefined && read(options, relative);
270
296
  if (current && current.content !== generated.text) {
271
297
  if (!byPath.has(relative)) {
@@ -297,7 +323,16 @@ export function createMutationController(directory, { captures = createCaptureCo
297
323
  const expected = snapshot(candidateOptions);
298
324
  candidateRevision=digest(Buffer.from(expected));
299
325
  if (previewWork) releasePreview = await previewWork.acquire(signal);
300
- const result = await checkCandidate(candidate, signal, root);
326
+ // A reviewed draft's workspace holds exactly this candidate's inputs at a stable path, so
327
+ // its warm check (and a remembered report from a dry run) applies; otherwise check the copy.
328
+ // Compared over the project's own inputs plus the changed files.
329
+ const compared = [...new Set([...Object.keys(validationInputFiles(options)), ...changes.map(change => change.path)])];
330
+ const pick = (digests) => JSON.stringify(compared.map(file => [file, digests[file] ?? null]));
331
+ const sameInputs = checkRoot && existsSync(checkRoot) && pick(validationInputFiles(loadConfig(checkRoot), compared)) === pick(validationInputFiles(candidateOptions, compared));
332
+ // Browser checks of a reviewed draft render its workspace through the project's own host and
333
+ // compiler; only a candidate without one gets a preview host of its own.
334
+ const reviewRoot = sameInputs ? checkRoot : candidate, sharedHost = sameInputs ? reviewedHost : undefined;
335
+ const result = await checkCandidate(reviewRoot, signal, root);
301
336
  verified.push({name:"ads check",passed:result.ok,cache:result.cache});
302
337
  if (!result.ok) return lastResult = mutationEvidence({ ok: false, applied: false, diagnostics: result.diagnostics, total: result.diagnostics.length, checks: verified },candidateRevision);
303
338
  if (assets || configuration) {
@@ -310,25 +345,28 @@ export function createMutationController(directory, { captures = createCaptureCo
310
345
  verified.push(await checkCommand(check.command, check.args, candidate, signal, undefined, {category:"build",phase:`project-check:${check.args.at(-1)}`}, candidateOptions.config.mcp.mutationCheckTimeoutMs));
311
346
  }
312
347
  const behaviorUnits = candidateOptions.config.acceptance.behaviorChecks ? affectedBehaviorUnits(candidateOptions, changes.map(change => change.path)) : [];
313
- // acceptance.browserAudit (on unless false): axe-core audits the candidate's affected UI scenarios before any source is written.
348
+ // acceptance.browserAudit: "owners" audits the changed owners' own scenarios, "affected" every scenario they reach, false none.
314
349
  // It reuses the candidate preview host built for behavior checks/captures; on its own it starts a
315
350
  // candidate host that compiles only the selected scenarios.
316
351
  const audit = candidateOptions.config.acceptance.browserAudit ? await import("../browser-audit.mjs") : null;
317
- const auditSelection = audit?.auditScenarioSelection(candidateOptions, changes.map(change => change.path));
352
+ const auditSelection = audit?.auditScenarioSelection(candidateOptions, changes.map(change => change.path), { mode: candidateOptions.config.acceptance.browserAudit, owners: units });
318
353
  if ((behaviorUnits.length || screenshot) && candidateOptions.config.mcp.previewManifest && candidateOptions.config.mcp.previewWatch) {
319
354
  boundary=evidenceFailure("build","preview-build","ADS_PREVIEW_BUILD");
320
355
  progress={stage:"preview-build",message:"Building all candidate previews"};notifyProgress?.(progress);
321
- const { startAdsMcp } = await import("./server.mjs");
322
- previewHost = await startAdsMcp(candidate, { stdio:false });
323
- await previewHost.buildAll(signal, {timeoutMs:candidateOptions.config.mcp.mutationCheckTimeoutMs});
324
- // Browser checks consume this immutable production graph. Keep its
325
- // resources hosted, release its compiler, and leave Explorer live.
326
- await previewHost.parkCompiler();
356
+ if (sharedHost) await sharedHost.buildAll(signal, {timeoutMs:candidateOptions.config.mcp.mutationCheckTimeoutMs});
357
+ else {
358
+ const { startAdsMcp } = await import("./server.mjs");
359
+ previewHost = await startAdsMcp(candidate, { stdio:false });
360
+ await previewHost.buildAll(signal, {timeoutMs:candidateOptions.config.mcp.mutationCheckTimeoutMs});
361
+ // Browser checks consume this immutable production graph. Keep its
362
+ // resources hosted, release its compiler, and leave Explorer live.
363
+ await previewHost.parkCompiler();
364
+ }
327
365
  verified.push({ name:"managed production previews", passed:true });
328
366
  }
329
367
  boundary=evidenceFailure("runner","behavior-verification","ADS_BEHAVIOR_SETUP");
330
368
  if (behaviorUnits.length) {
331
- const verification = createVerificationController(candidate, { reportRoot: root, previewHost, onProgress: value => { progress = { stage: "behavior", ...value }; notifyProgress?.(progress); } });
369
+ const verification = createVerificationController(reviewRoot, { reportRoot: root, previewHost: previewHost ?? sharedHost, onProgress: value => { progress = { stage: "behavior", ...value }; notifyProgress?.(progress); } });
332
370
  let evidence;
333
371
  try { evidence = await verification.run({ units: behaviorUnits, persist: false }, signal); }
334
372
  finally { await verification.close(); }
@@ -342,16 +380,24 @@ export function createMutationController(directory, { captures = createCaptureCo
342
380
  if (!auditSelection.scenarios.length) verified.push({name:"browser-accessibility-audit",skipped:true,reason:"No affected UI scenarios.",scenarios:0,...selection});
343
381
  else {
344
382
  progress={stage:"browser-audit",message:`Accessibility audit of ${auditSelection.scenarios.length} candidate scenarios`};notifyProgress?.(progress);
383
+ const auditKey = `${candidateRevision}:${JSON.stringify(auditSelection.scenarios)}`, remembered = audits.get(auditKey);
384
+ if (remembered) {
385
+ verified.push({ ...remembered.check, remembered: true });
386
+ if (!remembered.check.passed) return lastResult = mutationEvidence({ ok: false, applied: false, diagnostics: remembered.diagnostics, total: remembered.diagnostics.length, checks: verified },candidateRevision);
387
+ } else {
345
388
  let result;
346
- try { result = await audit.runBrowserAudit(candidate, {scenarios:auditSelection.scenarios,previewHost,signal,onProgress:value=>{progress=value;notifyProgress?.(value);}}); }
389
+ try { result = await audit.runBrowserAudit(reviewRoot, {scenarios:auditSelection.scenarios,previewHost:previewHost ?? sharedHost,signal,onProgress:value=>{progress=value;notifyProgress?.(value);}}); }
347
390
  catch (error) {
348
391
  if (signal.aborted) throw error;
349
392
  verified.push({name:"browser-accessibility-audit",passed:false,...selection});
350
393
  return lastResult = mutationEvidence({ ok: false, applied: false, diagnostics: [{ rule: "browser-audit", message: error.message, failure: evidenceFailure("runner","browser-audit",error.code ?? "ADS_AUDIT_FAILED") }], checks: verified },candidateRevision);
351
394
  }
352
395
  const {routed,check} = audit.auditCheck(result,selection);
396
+ audits.set(auditKey, { check, diagnostics: routed.diagnostics.map(item => ({...item,failure:evidenceFailure("assertion","browser-audit",item.rule)})) });
397
+ while (audits.size > 16) audits.delete(audits.keys().next().value);
353
398
  verified.push(check);
354
399
  if (!check.passed) return lastResult = mutationEvidence({ ok: false, applied: false, diagnostics: routed.diagnostics.map(item => ({...item,failure:evidenceFailure("assertion","browser-audit",item.rule)})), total: routed.diagnostics.length, checks: verified, ...(routed.advisories.length ? {advisories:routed.advisories,advisoryCount:routed.advisories.length} : {}) },candidateRevision);
400
+ }
355
401
  }
356
402
  }
357
403
  let screenshots;
@@ -16,7 +16,7 @@ function stamp(file) {
16
16
  }
17
17
 
18
18
  /** One project-owned compiler process, shared by all protocol instances. */
19
- export function createPreviewWatch(root, config, { log = process.stderr, buildTimeout = 30000, prewarm = false, despitePolicy = false } = {}) {
19
+ export function createPreviewWatch(root, config, { log = process.stderr, buildTimeout = config.previewBuildTimeoutMs ?? 300000, prewarm = false, despitePolicy = false, delegate } = {}) {
20
20
  config = { ...config, apps: [...config.apps] };
21
21
  const command = config.previewWatch;
22
22
  let session = randomUUID();
@@ -47,6 +47,15 @@ export function createPreviewWatch(root, config, { log = process.stderr, buildTi
47
47
  let invalidation;
48
48
  let requestFile = path.join(root, ".ds", `preview-requests-${session}.json`);
49
49
  let reportFile = path.join(root, ".ds", `build-status-${session}.json`);
50
+ // Draft workspaces compile inside this watcher's process; the control file lists them.
51
+ const drafts = new Map();
52
+ const controlFile = () => path.join(root, ".ds", `draft-compilers-${session}.json`);
53
+ function writeControl() {
54
+ if (delegate || !command) return;
55
+ mkdirSync(path.join(root, ".ds"), { recursive: true });
56
+ const temporary = `${controlFile()}.tmp`;
57
+ writeFileSync(temporary, JSON.stringify({ drafts: [...drafts.values()] })); renameSync(temporary, controlFile());
58
+ }
50
59
  function request(file,force = false) {
51
60
  if (!command || !force && requests.has(file) && active === file) return;
52
61
  if (file) { requests.add(file); active = file; }
@@ -74,10 +83,17 @@ export function createPreviewWatch(root, config, { log = process.stderr, buildTi
74
83
  baselines.set(file, stamp(file));
75
84
  }
76
85
  state = "running";
86
+ // A draft workspace has no compiler process of its own: the project's compiler hosts it.
87
+ if (delegate) {
88
+ delegate.attachDraft({ root, session, requestFile, statusFile: reportFile });
89
+ if (active) request(active, true);
90
+ return;
91
+ }
92
+ writeControl();
77
93
  // No shell: configured arguments remain literal. Child stdin cannot consume
78
94
  // the MCP channel, and both output streams go exclusively to diagnostics.
79
95
  const executable = developmentExecutable(command.command);
80
- const env = { ...process.env, ADS_MCP_BUILD_SESSION: session, ADS_MCP_BUILD_STATUS: reportFile, ADS_MCP_REQUEST_FILE: requestFile, ADS_MCP_PREWARM_VIEWS: prewarm ? "1" : "0", ADS_PREVIEW_DESPITE_POLICY: despitePolicy ? "1" : "0", PATH: [path.join(root, "node_modules/.bin"), path.dirname(process.execPath), process.env.PATH ?? ""].join(path.delimiter) };
96
+ const env = { ...process.env, ADS_MCP_BUILD_SESSION: session, ADS_MCP_BUILD_STATUS: reportFile, ADS_MCP_REQUEST_FILE: requestFile, ADS_MCP_DRAFT_CONTROL: controlFile(), ADS_WARM_CHECKS: "1", ADS_MCP_PREWARM_VIEWS: prewarm ? "1" : "0", ADS_PREVIEW_DESPITE_POLICY: despitePolicy ? "1" : "0", PATH: [path.join(root, "node_modules/.bin"), path.dirname(process.execPath), process.env.PATH ?? ""].join(path.delimiter) };
81
97
  try {
82
98
  child = spawn(executable, command.args, { cwd: root, env, shell: false, detached: process.platform !== "win32", stdio: ["ignore", "pipe", "pipe"], windowsHide: true });
83
99
  } catch (failure) {
@@ -135,6 +151,7 @@ export function createPreviewWatch(root, config, { log = process.stderr, buildTi
135
151
  return restarting ??= (async () => {
136
152
  await stopChild();
137
153
  if (disposed) return;
154
+ if (!delegate) rmSync(controlFile(), { force: true });
138
155
  session = randomUUID();
139
156
  requestFile = path.join(root, ".ds", `preview-requests-${session}.json`);
140
157
  reportFile = path.join(root, ".ds", `build-status-${session}.json`);
@@ -199,6 +216,7 @@ export function createPreviewWatch(root, config, { log = process.stderr, buildTi
199
216
  }
200
217
  if (build?.state === "error") throw buildFailure(build);
201
218
  if (command && state !== "running") throw new Error(error ?? "Preview watcher is stopped.");
219
+ if (delegate && delegate.status().state === "failed") throw new Error(delegate.status().error ?? "The project's preview compiler stopped.");
202
220
  if (build?.current) return build;
203
221
  if (build?.state === "unreported" && (!command || ready.has(file))) return build;
204
222
  const current = stamp(file);
@@ -220,7 +238,8 @@ export function createPreviewWatch(root, config, { log = process.stderr, buildTi
220
238
  async function stopChild({ preserve = false } = {}) {
221
239
  rmSync(requestFile, { force: true });
222
240
  if (stopping) return stopping;
223
- const cleanup = () => { if (!preserve) { rmSync(reportFile, { force: true }); rmSync(path.join(root, ".ds", `full-build-${session}.json`), {force:true}); clearOutput(); } };
241
+ const cleanup = () => { if (!preserve) { rmSync(reportFile, { force: true }); rmSync(path.join(root, ".ds", `full-build-${session}.json`), {force:true}); clearOutput(); } if (!delegate) rmSync(controlFile(), { force: true }); };
242
+ if (delegate) { delegate.detachDraft(session); state = "stopped"; cleanup(); return; }
224
243
  if (!child || childClosed) { if (command) state = "stopped"; cleanup(); return; }
225
244
  if (state === "stopped") return;
226
245
  state = "stopping";
@@ -305,7 +324,11 @@ export function createPreviewWatch(root, config, { log = process.stderr, buildTi
305
324
  let finish; resuming = { promise: new Promise(resolve => { finish = resolve; }), finish: () => finish() };
306
325
  suspending = (async () => { await restarting; await stopChild({ preserve: true }); if (!disposed) state = "suspended"; })();
307
326
  try { await suspending; } finally { suspending = undefined; }
308
- }, resume, async stop() { disposed = true; await restarting; await suspending; resume(); return stopChild(); }, kill: () => kill("SIGKILL"), status, resourceSession, buildStatus, setApps(apps) {
327
+ }, resume, async stop() { disposed = true; await restarting; await suspending; resume(); return stopChild(); }, kill: () => kill("SIGKILL"), status, resourceSession, buildStatus,
328
+ /** Host a draft workspace's compiler instance in this watcher's process, starting it if needed. */
329
+ attachDraft(entry) { drafts.set(entry.session, entry); if (state === "running") writeControl(); else start(); },
330
+ detachDraft(id) { if (drafts.delete(id) && state === "running") writeControl(); },
331
+ setApps(apps) {
309
332
  for (const app of apps) {
310
333
  const file = path.resolve(root, app.file);
311
334
  if (!baselines.has(file)) baselines.set(file, stamp(file));
@@ -319,6 +342,7 @@ export function createReconfigurablePreviewWatch(root, config, options) {
319
342
  let current = createPreviewWatch(root, config, options);
320
343
  let signature = JSON.stringify(config);
321
344
  let apps = config.apps;
345
+ const drafts = new Map();
322
346
  let pending = Promise.resolve(), replacing = false, stopped = false, parked = false, parkOptions;
323
347
  return {
324
348
  start() { if (!stopped && !replacing && !parked) current.start(); },
@@ -333,6 +357,8 @@ export function createReconfigurablePreviewWatch(root, config, options) {
333
357
  async suspend(options) { parked = true; parkOptions=options; await pending; if (!stopped && parked) return current.suspend(options); },
334
358
  resume() { parked = false; current.resume(); },
335
359
  setApps(next) { apps = next; current.setApps(next); },
360
+ attachDraft(entry) { drafts.set(entry.session, entry); if (!replacing && !stopped) current.attachDraft(entry); },
361
+ detachDraft(id) { drafts.delete(id); current.detachDraft(id); },
336
362
  kill() { current.kill(); },
337
363
  reconfigure(next, force = false) {
338
364
  const nextSignature = JSON.stringify(next);
@@ -343,7 +369,7 @@ export function createReconfigurablePreviewWatch(root, config, options) {
343
369
  await current.stop();
344
370
  if (stopped) return;
345
371
  current = createPreviewWatch(root, { ...next, apps }, options);
346
- if (parked) await current.suspend(parkOptions); else current.start();
372
+ if (parked) await current.suspend(parkOptions); else { current.start(); for (const entry of drafts.values()) current.attachDraft(entry); }
347
373
  }).finally(() => { replacing = false; });
348
374
  return pending;
349
375
  },
@@ -1,7 +1,7 @@
1
1
  export const reasoning = `Choose direct code editing or MCP-only editing using ads://guides/workflows, based on actual source access and user instructions. Direct editors change owned files normally and use MCP for previews/checks; ordinary direct edits do not require tracked drafts or ads_accept. MCP-only iterative design uses enabled draft tools: create a coherent proposal, edit it, inspect ads_show_draft and accept its exact reviewed revision. Direct editors may choose that isolated workflow too. Complete required tracked proposals by acceptance; fix failing checks or report unfinished work, and retain proposals only when requested. Accept dependency drafts first, then review dependents again. Auto mode implies agent review, not an extra human approval gate. Compiler ownership is independent: mcp.previewWatch:false is the direct-editing/external-builder variant; MCP serves published graph/evidence without starting a compiler. Source changes stale existing evidence until verified updated output is published.
2
2
  ADS is development tooling. The project owns its components, patterns, token values and branding.
3
3
  Start with ads_status and use its projectRoot, workflow and project commands; the MCP workspace may be nested inside the client repository. If ADS tools are not exposed, read ads://project/guide then ads://project/status. Find existing public UI with ads_catalog and load one relevant ADS workflow via ads_skills/ads_read_skill. UI implementation/refinement uses ads-designer; library adaptation ads-port; ADS transfer ads-import; motion ads-motion; stress testing ads-break-ui. Domain-model workflows are separate. Inspect the relevant public API, local guide, token definitions and real showcase fixture before proposing changes. Keep source/instruction discovery scoped to the target project, ancestry and selected external sources; broad scans of /mnt or home are not needed to discover this ADS.
4
- For MCP-only low-level repairs/migrations when ads_status.mutations.enabled, discover one owner with ads_units, read relevant ranges with ads_read_file and send only a Git unified diff through ads_apply_patch({unit,patch,dryRun}). A unit includes its own scenarios/fixtures; imported peers remain separate. tokens is the token foundation unit. Only that owner's public re-exports may change in the shared entry; preserve unrelated statements. A real re-export may replace a redundant export {}; placeholder; do not add empty exports. Token manifests list companionFiles: include required foundation import changes only for canonical token files created/deleted in the same patch, preserving other imports/comments and canonical order. Use dryRun to review validation. Rejected patches leave source unchanged; fix diagnostics rather than bypassing checks with direct writes. Shared globals use foundation; guides use documentation; assets use discovered assets/* units. Intentional configuration, registered project guards/builders and rule exceptions use configuration, which validates the proposed settings and refreshes its compiler. Keep mandatory ADS gates. For large/binary diffs, pass patchFile pointing to .ds/patches/<name>.patch rather than loading bytes into context; Git binary patches require installed Git. Direct editors use their authorized editor instead; MCP-only clients without mutation tools cannot edit.
4
+ For MCP-only low-level repairs/migrations when ads_status.mutations.enabled, discover one owner with ads_units, create its draft with ads_create_draft, read relevant ranges with ads_read_file and send a Git unified diff through ads_update_draft({id,revision,patch}). Only a draft can be accepted: check it with ads_accept({id,revision,dryRun:true}), then accept it. A unit includes its own scenarios/fixtures; imported peers remain separate. tokens is the token foundation unit. An owner declares its public names in its own <Owner>.ads.exports.ts and its style permissions in its contract; ADS generates the public barrel, review entry and styles entry, so never edit them. A failed acceptance leaves source unchanged; fix diagnostics rather than bypassing checks with direct writes. Shared globals use foundation; guides use documentation; assets use discovered assets/* units. Intentional configuration, registered project guards/builders and rule exceptions use configuration, which validates the proposed settings and refreshes its compiler. Keep mandatory ADS gates. For large diffs, pass patchFile pointing to .ds/patches/<name>.patch rather than loading bytes into context; binary files go through ads_update_draft changes with encoding:base64. Direct editors use their authorized editor instead; MCP-only clients without mutation tools cannot edit.
5
5
  Reason through Data (design-token values, semantic roles and relationships), UX (structure, behavior, accessibility, states and layout), and Skin (token-backed identity and visual states). Business data is a separate application-owned input, supplied through typed props or injected callbacks/services. Shared foundation Data is the only design-value catalogue. Components map it with --ds-* and patterns/review with --ux-*; there are no independent owner token namespaces or value sheets. Reuse project font, text and spacing roles when upstream constants differ. Read ads://guides/tokens for source boundaries and duplication review. The project uses Linaria extraction for owned styles; MCP adds no production runtime.
6
6
  Choose an existing public component or pattern first. Keep application data/routing/effects in the application and fixture data/state beside its scenario. Change presentation in its owning ADS implementation, then demonstrate the same public API in the showcase. Put demo-only sizing and framing in a development-only review/ helper, exported through the separate review entry rather than the production barrel; add component props for deliberate runtime API needs and preserve required behavior. Do not create a widget-only replica or override component internals.
7
7
  For token source inspection, call ads_tokens with a focused query. For token samples, components, patterns and composition, use ads_scenarios to select a path-derived id and invoke ads_show_scenario. Showcase and MCP mount that exact entry and its colocated fixture; no page initialization is required. The showcase is a minimal tool-owned shell plus an MCP client and Apps host. Its menus come from tools; it invokes the same entry tools and refreshes the active scenario through notifications. The reusable App loads framework runtime, foundation CSS, fonts and selected modules via MCP resources inside its sandbox. Keep project execution and styles out of the outer host; preserve mount/unmount cleanup and lazy dependencies. Use the existing ads_status showcase URL, or ads showcase when no MCP runtime is connected. Projects supply scenarios/fixtures and the compiler, not browser page files or another shell. Tool metadata selects an MCP App; a resources/read of HTML alone is not proof of rendered UI. If the host has no Apps view, give the configured showcase URL and use text/resources.