@reqvire-org/ads 0.4.0 → 0.4.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.
- package/README.md +115 -87
- package/dist/a11y.mjs +133 -48
- package/dist/analysis/compiler-options.mjs +13 -0
- package/dist/analysis/context.mjs +46 -0
- package/dist/analysis/file-tree.mjs +52 -0
- package/dist/analysis/helpers.mjs +142 -0
- package/dist/analysis/impact.mjs +20 -0
- package/dist/analysis/inputs.mjs +22 -0
- package/dist/analysis/module-resolvers.mjs +46 -0
- package/dist/analysis/native-adapter.mjs +180 -0
- package/dist/analysis/native-project.mjs +323 -0
- package/dist/analysis/queries.mjs +133 -0
- package/dist/analysis/service.mjs +153 -0
- package/dist/analysis/standalone.mjs +57 -0
- package/dist/analysis/syntax.mjs +179 -0
- package/dist/analysis/worker.mjs +182 -0
- package/dist/assets.mjs +6 -6
- package/dist/atomic-composition.mjs +191 -70
- package/dist/atomic-trace.mjs +120 -50
- package/dist/behavior-libraries.mjs +106 -37
- package/dist/behaviors.mjs +219 -77
- package/dist/boundaries.mjs +140 -41
- package/dist/brand-assets.mjs +219 -47
- package/dist/brands.mjs +86 -27
- package/dist/bun-compiler.mjs +28 -14
- package/dist/bun-worker.mjs +7 -5
- package/dist/capture/worker.mjs +15 -4
- package/dist/capture-store.mjs +4 -2
- package/dist/capture.mjs +17 -14
- package/dist/check-service.mjs +44 -58
- package/dist/check.mjs +754 -188
- package/dist/cli.mjs +200 -99
- package/dist/color-values.mjs +21 -21
- package/dist/component-contrast.mjs +127 -9
- package/dist/config.mjs +303 -135
- package/dist/construction-styles.cjs +10 -0
- package/dist/contrast-composition.mjs +134 -0
- package/dist/control-padding.mjs +45 -25
- package/dist/css-values.mjs +3 -2
- package/dist/declarative-flow.mjs +209 -109
- package/dist/design-values.mjs +136 -51
- package/dist/development-runtime.mjs +4 -6
- package/dist/draft-boundary.mjs +11 -6
- package/dist/evidence.mjs +1 -1
- package/dist/finding-rules.mjs +9 -5
- package/dist/font-rules.mjs +22 -17
- package/dist/fonts-generated.mjs +23 -16
- package/dist/foundation-views.mjs +242 -0
- package/dist/foundation.mjs +63 -39
- package/dist/generated-entries.mjs +101 -34
- package/dist/icons.mjs +79 -32
- package/dist/image-attributes.mjs +143 -66
- package/dist/image-size.mjs +1 -1
- package/dist/index.mjs +0 -2
- package/dist/init.mjs +122 -41
- package/dist/investigations.mjs +2 -2
- package/dist/layers.mjs +298 -129
- package/dist/layout-widths.mjs +180 -85
- package/dist/linaria/preserve-values.cjs +7 -0
- package/dist/linaria/spatial-inputs.cjs +56 -0
- package/dist/lockup-composition.mjs +44 -0
- package/dist/lockup-model.cjs +64 -0
- package/dist/mcp/THIRD_PARTY_NOTICES.md +51 -1
- package/dist/mcp/apps.mjs +4 -30
- package/dist/mcp/behavior-pages.mjs +72 -24
- package/dist/mcp/build-status.mjs +257 -64
- package/dist/mcp/catalog.mjs +90 -26
- package/dist/mcp/context.mjs +17 -18
- package/dist/mcp/draft-discovery.mjs +44 -21
- package/dist/mcp/drafts.mjs +903 -281
- package/dist/mcp/execution-coordinator.mjs +417 -167
- package/dist/mcp/execution-results.mjs +7 -7
- package/dist/mcp/mutations.mjs +673 -234
- package/dist/mcp/preview-watch.mjs +448 -170
- package/dist/mcp/preview-widget.bundle.js +44 -50
- package/dist/mcp/prompts.mjs +5 -5
- package/dist/mcp/result-pages.mjs +1 -1
- package/dist/mcp/sandbox-host.mjs +1 -1
- package/dist/mcp/server.mjs +2409 -577
- package/dist/mcp/showcase-host.mjs +165 -41
- package/dist/mcp/skills.mjs +1 -1
- package/dist/mcp/text-diff.mjs +29 -10
- package/dist/paint-contracts.mjs +174 -81
- package/dist/palette-generated.mjs +2 -2
- package/dist/pictogram-model.mjs +59 -0
- package/dist/pictograms.mjs +52 -0
- package/dist/preview-bun.mjs +494 -187
- package/dist/preview-failure.mjs +1 -1
- package/dist/preview-files.mjs +13 -13
- package/dist/preview-imports.mjs +104 -55
- package/dist/preview-inputs.mjs +2 -2
- package/dist/preview-requests.mjs +24 -0
- package/dist/preview-resources.mjs +288 -147
- package/dist/preview-scope.mjs +5 -4
- package/dist/program-cache.mjs +8 -34
- package/dist/project-documents.mjs +1 -1
- package/dist/public-api.mjs +69 -31
- package/dist/public-props.mjs +39 -22
- package/dist/{browser-audit → render-audit}/axe-run.mjs +3 -3
- package/dist/{browser-audit → render-audit}/image-shape.mjs +15 -5
- package/dist/{browser-audit → render-audit}/layout-overflow.mjs +86 -23
- package/dist/{browser-audit → render-audit}/non-text-contrast.mjs +86 -27
- package/dist/render-audit/pictograms.mjs +88 -0
- package/dist/{browser-audit → render-audit}/render-states.mjs +208 -52
- package/dist/{browser-audit → render-audit}/worker.mjs +98 -30
- package/dist/render-audit.mjs +838 -0
- package/dist/render-color-probe.mjs +96 -42
- package/dist/render-composition.mjs +164 -0
- package/dist/resource-limits.mjs +229 -97
- package/dist/runtime-contracts.mjs +467 -185
- package/dist/scenario-groups.mjs +22 -10
- package/dist/scenario-inspector.mjs +6 -43
- package/dist/scenario-program.mjs +8 -25
- package/dist/scenario-registry.mjs +72 -30
- package/dist/scenario-selectors.mjs +161 -64
- package/dist/scenario-slots.mjs +149 -56
- package/dist/scenario-trace.mjs +215 -109
- package/dist/scenarios-compiler.mjs +719 -378
- package/dist/scenarios-vite.d.mts +1 -3
- package/dist/scenarios-vite.mjs +2 -81
- package/dist/scenarios.mjs +421 -157
- package/dist/selector-match.mjs +2 -2
- package/dist/showcase/client.bundle.js +57 -56
- package/dist/showcase/draft-navigation.js +21 -3
- package/dist/showcase/favicon.ico +0 -0
- package/dist/showcase/favicon.svg +1 -0
- package/dist/showcase/foundation-view.css +58 -0
- package/dist/showcase/foundation-view.mjs +255 -0
- package/dist/showcase/guide-controls.ads.review.mjs +32 -0
- package/dist/showcase/icons.js +1 -145
- package/dist/showcase/index.html +3 -31
- package/dist/showcase/pictogram-view.mjs +53 -0
- package/dist/showcase/preview-frame.ads.review.css +46 -0
- package/dist/showcase/preview-frame.ads.review.d.mts +11 -0
- package/dist/showcase/preview-frame.ads.review.mjs +22 -0
- package/dist/showcase/preview-state.js +0 -9
- package/dist/showcase/refresh-scheduler.js +23 -0
- package/dist/showcase/style.css +5 -47
- package/dist/showcase/ui/ui.css +1353 -0
- package/dist/showcase/ui/ui.js +1064 -0
- package/dist/showcase-coverage.mjs +58 -37
- package/dist/skills/README.md +24 -23
- package/dist/skills/ads-designer/README.md +8 -2
- package/dist/skills/ads-designer/SKILL.md +143 -120
- package/dist/skills/ads-designer/references/accessibility.md +78 -15
- package/dist/skills/ads-designer/references/atomic-styles.md +4 -4
- package/dist/skills/ads-designer/references/behaviors.md +30 -27
- package/dist/skills/ads-designer/references/branding.md +101 -24
- package/dist/skills/ads-designer/references/captures.md +25 -0
- package/dist/skills/ads-designer/references/cli.md +21 -24
- package/dist/skills/ads-designer/references/contracts.md +7 -6
- package/dist/skills/ads-designer/references/design-data.md +49 -52
- package/dist/skills/ads-designer/references/drafts.md +20 -17
- package/dist/skills/ads-designer/references/evidence.md +1 -5
- package/dist/skills/ads-designer/references/guarded-editing.md +14 -18
- package/dist/skills/ads-designer/references/layers.md +1 -1
- package/dist/skills/ads-designer/references/layout.md +347 -0
- package/dist/skills/ads-designer/references/mobile.md +2 -1
- package/dist/skills/{ads-motion/references/performance.md → ads-designer/references/motion-performance.md} +5 -1
- package/dist/skills/{ads-motion/references/build.md → ads-designer/references/motion.md} +73 -5
- package/dist/skills/ads-designer/references/performance.md +3 -2
- package/dist/skills/ads-designer/references/pictograms.md +131 -0
- package/dist/skills/ads-designer/references/review.md +37 -34
- package/dist/skills/ads-designer/references/runtimes.md +33 -30
- package/dist/skills/ads-designer/references/scenarios.md +16 -18
- package/dist/skills/{ads-break-ui/references/catalog.md → ads-designer/references/stress-catalog.md} +3 -1
- package/dist/skills/ads-designer/references/stress-test.md +68 -0
- package/dist/skills/ads-designer/references/validation.md +83 -75
- package/dist/skills/ads-designer/references/workflows.md +8 -33
- package/dist/skills/ads-import/SKILL.md +43 -325
- package/dist/skills/ads-import/references/atomic-styles.md +4 -4
- package/dist/skills/ads-import/references/behaviors.md +30 -27
- package/dist/skills/ads-import/references/branding.md +5 -5
- package/dist/skills/ads-import/references/captures.md +25 -0
- package/dist/skills/ads-import/references/cli.md +21 -24
- package/dist/skills/ads-import/references/compatibility.md +1 -1
- package/dist/skills/ads-import/references/contracts.md +7 -6
- package/dist/skills/ads-import/references/design-data.md +49 -52
- package/dist/skills/ads-import/references/drafts.md +20 -17
- package/dist/skills/ads-import/references/evidence.md +1 -5
- package/dist/skills/ads-import/references/guarded-editing.md +14 -18
- package/dist/skills/ads-import/references/implementation.md +2 -1
- package/dist/skills/ads-import/references/layers.md +1 -1
- package/dist/skills/ads-import/references/layout.md +347 -0
- package/dist/skills/ads-import/references/review.md +37 -34
- package/dist/skills/ads-import/references/runtimes.md +33 -30
- package/dist/skills/ads-import/references/scenarios.md +16 -18
- package/dist/skills/ads-import/references/tokens.md +3 -3
- package/dist/skills/ads-import/references/validation.md +83 -75
- package/dist/skills/ads-import/references/workflows.md +8 -33
- package/dist/skills/ads-migrate/SKILL.md +56 -0
- package/dist/skills/ads-migrate/references/0.4.1-to-0.4.2.md +602 -0
- package/dist/skills/ads-port/SKILL.md +58 -344
- package/dist/skills/ads-port/references/atomic-styles.md +4 -4
- package/dist/skills/ads-port/references/behaviors.md +30 -27
- package/dist/skills/ads-port/references/captures.md +25 -0
- package/dist/skills/ads-port/references/cli.md +21 -24
- package/dist/skills/ads-port/references/contracts.md +7 -6
- package/dist/skills/ads-port/references/design-data.md +49 -52
- package/dist/skills/ads-port/references/drafts.md +20 -17
- package/dist/skills/ads-port/references/evidence.md +1 -5
- package/dist/skills/ads-port/references/guarded-editing.md +14 -18
- package/dist/skills/ads-port/references/layers.md +1 -1
- package/dist/skills/ads-port/references/layout.md +347 -0
- package/dist/skills/ads-port/references/lint-and-docs.md +8 -11
- package/dist/skills/ads-port/references/native-implementation.md +2 -1
- package/dist/skills/ads-port/references/review.md +37 -34
- package/dist/skills/ads-port/references/runtimes.md +33 -30
- package/dist/skills/ads-port/references/scenarios.md +16 -18
- package/dist/skills/ads-port/references/validation.md +83 -75
- package/dist/skills/ads-port/references/workflows.md +8 -33
- package/dist/source-symbols.mjs +1 -8
- package/dist/source-values.mjs +270 -129
- package/dist/spatial-composition.mjs +322 -0
- package/dist/spatial-contexts.cjs +56 -0
- package/dist/spatial-css.cjs +351 -0
- package/dist/spatial-inputs.cjs +80 -0
- package/dist/spatial-metadata.mjs +18 -0
- package/dist/spatial-model.cjs +322 -0
- package/dist/spatial.mjs +21 -0
- package/dist/stage-timing.cjs +20 -0
- package/dist/starters/preact/design-system/patterns/Conversation/Conversation.tsx +105 -0
- package/dist/starters/preact/design-system/patterns/Shell/Shell.tsx +275 -0
- package/dist/starters/preact/design-system/review/demo-frame/DemoFrame.ads.review.tsx +7 -0
- package/dist/starters/preact/design-system/review/screen-frame/ScreenFrame.ads.review.tsx +10 -0
- package/dist/starters/preact/design-system/showcase/mcp/main.ads.mount.tsx +8 -0
- package/dist/starters/preact/ds.config.json +25 -6
- package/dist/starters/preact/package.json +4 -8
- package/dist/starters/preact/tsconfig.json +4 -5
- package/dist/starters/preact/vite.config.ts +3 -3
- package/dist/starters/react/ADS.md +42 -47
- package/dist/starters/react/README.md +47 -49
- package/dist/starters/react/design-system/assets/pictograms/catalog.ads.json +13 -0
- package/dist/starters/react/design-system/assets/pictograms/journey.dark.svg +7 -0
- package/dist/starters/react/design-system/assets/pictograms/journey.svg +7 -0
- package/dist/starters/react/design-system/components/Actions/IconButton/IconButton.tsx +18 -2
- package/dist/starters/react/design-system/components/Actions/IconButton/README.md +3 -0
- package/dist/starters/react/design-system/components/Content/Pictogram/Pictogram.ads.exports.ts +1 -0
- package/dist/starters/react/design-system/components/Content/Pictogram/Pictogram.ads.fixture.ts +1 -0
- package/dist/starters/react/design-system/components/Content/Pictogram/Pictogram.ads.scenario.tsx +7 -0
- package/dist/starters/react/design-system/components/Content/Pictogram/Pictogram.tsx +26 -0
- package/dist/starters/react/design-system/composition/Workspace/WorkspacePage/README.md +5 -0
- package/dist/starters/react/design-system/composition/Workspace/WorkspacePage/WorkspacePage.ads.fixture.ts +13 -0
- package/dist/starters/react/design-system/composition/Workspace/WorkspacePage/WorkspacePage.ads.scenario.tsx +22 -0
- package/dist/starters/react/design-system/index.ts +2 -1
- package/dist/starters/react/design-system/patterns/Conversation/Conversation.ads.exports.ts +1 -0
- package/dist/starters/react/design-system/patterns/Conversation/Conversation.ads.fixture.ts +7 -0
- package/dist/starters/react/design-system/patterns/Conversation/Conversation.ads.scenario.tsx +15 -0
- package/dist/starters/react/design-system/patterns/Conversation/Conversation.tsx +105 -0
- package/dist/starters/react/design-system/patterns/Conversation/README.md +9 -0
- package/dist/starters/react/design-system/patterns/Shell/Floating.ads.fixture.ts +5 -0
- package/dist/starters/react/design-system/patterns/Shell/Floating.ads.scenario.tsx +21 -0
- package/dist/starters/react/design-system/patterns/Shell/README.md +43 -0
- package/dist/starters/react/design-system/patterns/Shell/Shell.ads.exports.ts +1 -0
- package/dist/starters/react/design-system/patterns/Shell/Shell.ads.fixture.ts +5 -0
- package/dist/starters/react/design-system/patterns/Shell/Shell.ads.scenario.tsx +21 -0
- package/dist/starters/react/design-system/patterns/Shell/Shell.tsx +274 -0
- package/dist/starters/react/design-system/review/demo-frame/DemoFrame.ads.exports.ts +1 -1
- package/dist/starters/react/design-system/review/demo-frame/DemoFrame.ads.review.tsx +7 -0
- package/dist/starters/react/design-system/review/index.ads.review.ts +4 -0
- package/dist/starters/react/design-system/review/region-block/RegionBlock.ads.exports.ts +1 -0
- package/dist/starters/react/design-system/review/region-block/RegionBlock.ads.review.tsx +6 -0
- package/dist/starters/react/design-system/review/screen-frame/ScreenFrame.ads.exports.ts +1 -1
- package/dist/starters/react/design-system/review/screen-frame/ScreenFrame.ads.review.tsx +10 -0
- package/dist/starters/react/design-system/showcase/mcp/{main.tsx → main.ads.mount.tsx} +4 -2
- package/dist/starters/react/design-system/tokens/catalog.ads.json +1221 -0
- package/dist/starters/react/design-system/tokens/colors.css +1 -1
- package/dist/starters/react/design-system/tokens/spacing.css +22 -32
- package/dist/starters/react/design-system/tokens/spatial.ads.json +70 -0
- package/dist/starters/react/design-system/tokens/themes.generated.ts +1 -1
- package/dist/starters/react/ds.config.json +25 -6
- package/dist/starters/react/package.json +2 -6
- package/dist/starters/react/tsconfig.json +2 -3
- package/dist/starters/react/vite.config.ts +3 -3
- package/dist/style-boundaries.mjs +70 -25
- package/dist/task-cache.mjs +173 -72
- package/dist/task-worker.mjs +22 -11
- package/dist/test-boundaries.mjs +132 -59
- package/dist/themes-generated.mjs +1 -1
- package/dist/themes-watch.mjs +57 -22
- package/dist/themes.mjs +176 -73
- package/dist/token-export.mjs +39 -14
- package/dist/token-policy.mjs +6 -3
- package/dist/token-quality.mjs +6 -6
- package/dist/token-samples.mjs +16 -5
- package/dist/tokens.mjs +71 -26
- package/dist/ui-framework.mjs +16 -14
- package/dist/unit-contracts.mjs +251 -104
- package/dist/units.mjs +209 -99
- package/dist/usage.mjs +138 -38
- package/dist/validation-checks.mjs +115 -38
- package/dist/validation-inputs.mjs +191 -78
- package/dist/validation.mjs +268 -102
- package/dist/verification/browser.mjs +27 -5
- package/dist/verification.mjs +711 -187
- package/docs/ADS.md +96 -80
- package/docs/ARCHITECTURE.md +368 -137
- package/docs/BEHAVIORS.md +29 -25
- package/docs/CACHING.md +77 -17
- package/docs/CHANGELOG.md +332 -17
- package/docs/CONTRACTS.md +12 -4
- package/docs/DESIGN-REFERENCES.md +40 -0
- package/docs/GUIDE.md +300 -263
- package/docs/MCP.md +187 -324
- package/docs/SPATIAL-CHECKS.md +69 -0
- package/docs/benchmarks/README.md +39 -0
- package/package.json +43 -34
- package/dist/browser-audit.mjs +0 -429
- package/dist/create.mjs +0 -48
- package/dist/lint-config.mjs +0 -50
- package/dist/mcp/project-widget.bundle.js +0 -114
- package/dist/mcp/reports.mjs +0 -101
- package/dist/mcp/widget.bundle.js +0 -147
- package/dist/oxlint.mjs +0 -89
- package/dist/preview-builder.mjs +0 -133
- package/dist/preview-workers.mjs +0 -184
- package/dist/showcase.mjs +0 -77
- package/dist/skills/ads-break-ui/LICENSE.upstream +0 -21
- package/dist/skills/ads-break-ui/README.md +0 -16
- package/dist/skills/ads-break-ui/SKILL.md +0 -412
- package/dist/skills/ads-break-ui/agents/openai.yaml +0 -4
- package/dist/skills/ads-break-ui/references/atomic-styles.md +0 -293
- package/dist/skills/ads-break-ui/references/behaviors.md +0 -412
- package/dist/skills/ads-break-ui/references/captures.md +0 -135
- package/dist/skills/ads-break-ui/references/contracts.md +0 -317
- package/dist/skills/ads-break-ui/references/design-data.md +0 -354
- package/dist/skills/ads-break-ui/references/drafts.md +0 -194
- package/dist/skills/ads-break-ui/references/evidence.md +0 -128
- package/dist/skills/ads-break-ui/references/guarded-editing.md +0 -165
- package/dist/skills/ads-break-ui/references/layers.md +0 -145
- package/dist/skills/ads-break-ui/references/reporting.md +0 -101
- package/dist/skills/ads-break-ui/references/review.md +0 -97
- package/dist/skills/ads-break-ui/references/runtimes.md +0 -203
- package/dist/skills/ads-break-ui/references/scenarios.md +0 -246
- package/dist/skills/ads-break-ui/references/validation.md +0 -166
- package/dist/skills/ads-break-ui/references/verification.md +0 -58
- package/dist/skills/ads-break-ui/references/workflows.md +0 -90
- package/dist/skills/ads-designer/references/reporting.md +0 -101
- package/dist/skills/ads-import/references/reporting.md +0 -101
- package/dist/skills/ads-motion/LICENSE.upstream +0 -21
- package/dist/skills/ads-motion/README.md +0 -22
- package/dist/skills/ads-motion/SKILL.md +0 -385
- package/dist/skills/ads-motion/agents/openai.yaml +0 -4
- package/dist/skills/ads-motion/references/atomic-styles.md +0 -293
- package/dist/skills/ads-motion/references/audit.md +0 -44
- package/dist/skills/ads-motion/references/behaviors.md +0 -412
- package/dist/skills/ads-motion/references/captures.md +0 -135
- package/dist/skills/ads-motion/references/contracts.md +0 -317
- package/dist/skills/ads-motion/references/design-data.md +0 -354
- package/dist/skills/ads-motion/references/drafts.md +0 -194
- package/dist/skills/ads-motion/references/evidence.md +0 -128
- package/dist/skills/ads-motion/references/guarded-editing.md +0 -165
- package/dist/skills/ads-motion/references/layers.md +0 -145
- package/dist/skills/ads-motion/references/motion-review.md +0 -35
- package/dist/skills/ads-motion/references/reporting.md +0 -101
- package/dist/skills/ads-motion/references/review.md +0 -97
- package/dist/skills/ads-motion/references/runtimes.md +0 -203
- package/dist/skills/ads-motion/references/scenarios.md +0 -246
- package/dist/skills/ads-motion/references/validation.md +0 -166
- package/dist/skills/ads-motion/references/verification.md +0 -39
- package/dist/skills/ads-motion/references/workflows.md +0 -90
- package/dist/skills/ads-port/references/reporting.md +0 -101
- package/dist/starters/preact/design-system/components/Layout/Grid/Grid.ads.contract.ts +0 -6
- package/dist/starters/preact/design-system/components/Layout/Grid/Grid.tsx +0 -76
- package/dist/starters/preact/design-system/review/demo-frame/DemoFrame.tsx +0 -29
- package/dist/starters/preact/design-system/review/screen-frame/ScreenFrame.tsx +0 -34
- package/dist/starters/preact/design-system/review/token-preview/TokenPreview.ads.contract.ts +0 -6
- package/dist/starters/preact/design-system/review/token-preview/TokenPreview.tsx +0 -137
- package/dist/starters/preact/design-system/showcase/mcp/main.tsx +0 -6
- package/dist/starters/react/design-system/brand/Icons/AppIcon/AppIcon.ads.fixture.ts +0 -7
- package/dist/starters/react/design-system/brand/Icons/AppIcon/AppIcon.ads.scenario.tsx +0 -4
- package/dist/starters/react/design-system/brand/Identity/Logo/Logo.ads.fixture.ts +0 -7
- package/dist/starters/react/design-system/brand/Identity/Logo/Logo.ads.scenario.tsx +0 -4
- package/dist/starters/react/design-system/components/Layout/Grid/Grid.ads.contract.ts +0 -6
- package/dist/starters/react/design-system/components/Layout/Grid/Grid.ads.exports.ts +0 -1
- package/dist/starters/react/design-system/components/Layout/Grid/Grid.ads.fixture.ts +0 -12
- package/dist/starters/react/design-system/components/Layout/Grid/Grid.ads.scenario.tsx +0 -17
- package/dist/starters/react/design-system/components/Layout/Grid/Grid.tsx +0 -75
- package/dist/starters/react/design-system/components/Layout/Grid/README.md +0 -21
- package/dist/starters/react/design-system/review/brand-preview/BrandPreview.ads.exports.ts +0 -1
- package/dist/starters/react/design-system/review/brand-preview/BrandPreview.tsx +0 -112
- package/dist/starters/react/design-system/review/demo-frame/DemoFrame.tsx +0 -29
- package/dist/starters/react/design-system/review/grid-cell/GridCell.ads.exports.ts +0 -1
- package/dist/starters/react/design-system/review/grid-cell/GridCell.tsx +0 -18
- package/dist/starters/react/design-system/review/index.ts +0 -6
- package/dist/starters/react/design-system/review/screen-frame/ScreenFrame.tsx +0 -34
- package/dist/starters/react/design-system/review/token-preview/TokenPreview.ads.contract.ts +0 -6
- package/dist/starters/react/design-system/review/token-preview/TokenPreview.ads.exports.ts +0 -1
- package/dist/starters/react/design-system/review/token-preview/TokenPreview.tsx +0 -137
- package/dist/starters/react/design-system/showcase/mcp/index.html +0 -1
- package/dist/starters/react/design-system/tokens/Color.ads.fixture.ts +0 -124
- package/dist/starters/react/design-system/tokens/Color.ads.scenario.tsx +0 -4
- package/dist/starters/react/design-system/tokens/Layout.ads.fixture.ts +0 -39
- package/dist/starters/react/design-system/tokens/Layout.ads.scenario.tsx +0 -4
- package/dist/starters/react/design-system/tokens/Motion.ads.fixture.ts +0 -18
- package/dist/starters/react/design-system/tokens/Motion.ads.scenario.tsx +0 -4
- package/dist/starters/react/design-system/tokens/Shape.ads.fixture.ts +0 -30
- package/dist/starters/react/design-system/tokens/Shape.ads.scenario.tsx +0 -4
- package/dist/starters/react/design-system/tokens/Space.ads.fixture.ts +0 -37
- package/dist/starters/react/design-system/tokens/Space.ads.scenario.tsx +0 -4
- package/dist/starters/react/design-system/tokens/Type.ads.fixture.ts +0 -29
- package/dist/starters/react/design-system/tokens/Type.ads.scenario.tsx +0 -4
- package/dist/starters/react/package-lock.json +0 -4707
- package/dist/token-fixtures.mjs +0 -30
- package/docs/benchmarks/bun-previews.md +0 -91
- package/docs/benchmarks/preview-memory.md +0 -147
- package/docs/benchmarks/turbo-poc.md +0 -284
- package/docs/plans/execution-coordination.md +0 -57
- /package/dist/{browser-audit → render-audit}/first-render.mjs +0 -0
- /package/dist/{browser-audit → render-audit}/layout-shift.mjs +0 -0
package/dist/mcp/drafts.mjs
CHANGED
|
@@ -1,6 +1,20 @@
|
|
|
1
|
+
import { mapAsync } from "../analysis/queries.mjs";
|
|
1
2
|
import { writeThemesCss } from "../themes-generated.mjs";
|
|
2
3
|
import { createHash, randomUUID } from "node:crypto";
|
|
3
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
cpSync,
|
|
6
|
+
existsSync,
|
|
7
|
+
lstatSync,
|
|
8
|
+
mkdirSync,
|
|
9
|
+
readFileSync,
|
|
10
|
+
readdirSync,
|
|
11
|
+
realpathSync,
|
|
12
|
+
renameSync,
|
|
13
|
+
rmSync,
|
|
14
|
+
symlinkSync,
|
|
15
|
+
watch,
|
|
16
|
+
writeFileSync,
|
|
17
|
+
} from "node:fs";
|
|
4
18
|
import path from "node:path";
|
|
5
19
|
import { z } from "zod";
|
|
6
20
|
import { loadConfig, isInside } from "../config.mjs";
|
|
@@ -9,6 +23,8 @@ import { inspectUnits, validateUnitId } from "../units.mjs";
|
|
|
9
23
|
import { validationInputFiles } from "../validation-inputs.mjs";
|
|
10
24
|
import { writeGeneratedEntries } from "../generated-entries.mjs";
|
|
11
25
|
import { inspectTokens } from "../tokens.mjs";
|
|
26
|
+
import { analyze, registerAnalysisRevision, releaseAnalysisRevision } from "../analysis/service.mjs";
|
|
27
|
+
import { isAnalysisSource } from "../analysis/inputs.mjs";
|
|
12
28
|
import { previewFileIgnored, previewWatchDirectories } from "../preview-files.mjs";
|
|
13
29
|
import { createDraftDiscovery } from "./draft-discovery.mjs";
|
|
14
30
|
import { mutationLimits } from "./mutation-limits.mjs";
|
|
@@ -16,12 +32,48 @@ import { applyFilePatch, parseUnifiedPatch } from "./patch.mjs";
|
|
|
16
32
|
import { readPatchFile } from "./mutations.mjs";
|
|
17
33
|
|
|
18
34
|
export const DRAFTS_URI = "ads://project/drafts";
|
|
19
|
-
const hash = bytes => createHash("sha256").update(bytes).digest("hex");
|
|
35
|
+
const hash = (bytes) => createHash("sha256").update(bytes).digest("hex");
|
|
20
36
|
const idSchema = z.string().regex(/^[a-z0-9][a-z0-9-]{0,79}$/);
|
|
21
|
-
const relative = z
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
37
|
+
const relative = z
|
|
38
|
+
.string()
|
|
39
|
+
.min(1)
|
|
40
|
+
.max(500)
|
|
41
|
+
.refine(
|
|
42
|
+
(value) =>
|
|
43
|
+
!path.isAbsolute(value) && !value.includes("\\") && !value.includes("\0") && !value.split("/").some((part) => !part || part === "." || part === ".."),
|
|
44
|
+
"Use a canonical project-relative path.",
|
|
45
|
+
);
|
|
46
|
+
const fileSchema = z
|
|
47
|
+
.object({
|
|
48
|
+
target: relative,
|
|
49
|
+
source: relative.nullable(),
|
|
50
|
+
baseline: z
|
|
51
|
+
.string()
|
|
52
|
+
.regex(/^[a-f0-9]{64}$/)
|
|
53
|
+
.nullable(),
|
|
54
|
+
unit: z.string().max(256),
|
|
55
|
+
})
|
|
56
|
+
.strict();
|
|
57
|
+
const draftUnits = z
|
|
58
|
+
.array(z.string().min(1).max(256))
|
|
59
|
+
.min(1)
|
|
60
|
+
.max(mutationLimits.units)
|
|
61
|
+
.refine((values) => new Set(values).size === values.length, "Draft owners must be unique.");
|
|
62
|
+
const manifestSchema = z
|
|
63
|
+
.object({
|
|
64
|
+
schemaVersion: z.literal(1),
|
|
65
|
+
id: idSchema,
|
|
66
|
+
title: z.string().min(1).max(160),
|
|
67
|
+
units: draftUnits,
|
|
68
|
+
dependencies: z
|
|
69
|
+
.array(idSchema)
|
|
70
|
+
.max(8)
|
|
71
|
+
.refine((values) => new Set(values).size === values.length, "Draft dependencies must be unique.")
|
|
72
|
+
.default([]),
|
|
73
|
+
tokenGroups: z.array(z.string().min(1).max(160)).max(32).default([]),
|
|
74
|
+
files: z.array(fileSchema).max(mutationLimits.files),
|
|
75
|
+
})
|
|
76
|
+
.strict();
|
|
25
77
|
export const draftIdSchema = idSchema;
|
|
26
78
|
export const draftRevisionSchema = z.string().regex(/^[a-f0-9]{64}$/);
|
|
27
79
|
|
|
@@ -31,7 +83,8 @@ function safe(root, relativePath) {
|
|
|
31
83
|
if (!isInside(root, target) || target === root) throw new Error("Draft paths must stay inside their project or proposal.");
|
|
32
84
|
for (let current = target; isInside(root, current); current = path.dirname(current)) {
|
|
33
85
|
const stat = lstatSync(current, { throwIfNoEntry: false });
|
|
34
|
-
if (stat?.isSymbolicLink() || stat && current === target && (!stat.isFile() || stat.nlink !== 1))
|
|
86
|
+
if (stat?.isSymbolicLink() || (stat && current === target && (!stat.isFile() || stat.nlink !== 1)))
|
|
87
|
+
throw new Error("Draft paths require ordinary directories and unlinked regular files.");
|
|
35
88
|
if (current === root) break;
|
|
36
89
|
if (stat && current !== target && !stat.isDirectory()) throw new Error("Invalid draft directory.");
|
|
37
90
|
}
|
|
@@ -40,130 +93,277 @@ function safe(root, relativePath) {
|
|
|
40
93
|
function bytes(file) {
|
|
41
94
|
if (!existsSync(file)) return null;
|
|
42
95
|
const stat = lstatSync(file);
|
|
43
|
-
if (!stat.isFile() || stat.nlink !== 1 || realpathSync(file) !== file || stat.size > 16 * 1024 * 1024)
|
|
96
|
+
if (!stat.isFile() || stat.nlink !== 1 || realpathSync(file) !== file || stat.size > 16 * 1024 * 1024)
|
|
97
|
+
throw new Error("Draft inputs must be ordinary files no larger than 16 MiB.");
|
|
44
98
|
return readFileSync(file);
|
|
45
99
|
}
|
|
46
|
-
const fileHash = content => content === null ? null : hash(content);
|
|
100
|
+
const fileHash = (content) => (content === null ? null : hash(content));
|
|
47
101
|
function atomic(file, content) {
|
|
48
102
|
mkdirSync(path.dirname(file), { recursive: true });
|
|
49
103
|
if (realpathSync(path.dirname(file)) !== path.dirname(file)) throw new Error("Draft storage cannot resolve through a symlink.");
|
|
50
104
|
const staging = `${file}.${randomUUID()}.tmp`;
|
|
51
|
-
try {
|
|
52
|
-
|
|
105
|
+
try {
|
|
106
|
+
writeFileSync(staging, content);
|
|
107
|
+
renameSync(staging, file);
|
|
108
|
+
} finally {
|
|
109
|
+
rmSync(staging, { force: true });
|
|
110
|
+
}
|
|
53
111
|
}
|
|
54
|
-
const storedName = target => `files/${target}.ads`;
|
|
112
|
+
const storedName = (target) => `files/${target}.ads`;
|
|
55
113
|
|
|
56
114
|
/** Tracked proposal source is separate from disposable compiler state. No Git checkout is required. */
|
|
57
115
|
export function createDraftController(directory, { edits, startPreview, prewarm = false, onChange, scenarioInspector } = {}) {
|
|
58
|
-
const root = path.resolve(directory),
|
|
116
|
+
const root = path.resolve(directory),
|
|
117
|
+
storage = path.join(root, DRAFT_DIRECTORY);
|
|
59
118
|
const previews = new Map();
|
|
60
119
|
function previewDirectory(id) {
|
|
61
|
-
const folder=path.join(root,".ds/draft-previews",idSchema.parse(id));
|
|
62
|
-
for(let current=folder;isInside(root,current);current=path.dirname(current)) {
|
|
63
|
-
if(lstatSync(current,{throwIfNoEntry:false})?.isSymbolicLink())throw new Error("Draft preview storage cannot resolve through a symlink.");
|
|
64
|
-
if(current===root)break;
|
|
120
|
+
const folder = path.join(root, ".ds/draft-previews", idSchema.parse(id));
|
|
121
|
+
for (let current = folder; isInside(root, current); current = path.dirname(current)) {
|
|
122
|
+
if (lstatSync(current, { throwIfNoEntry: false })?.isSymbolicLink()) throw new Error("Draft preview storage cannot resolve through a symlink.");
|
|
123
|
+
if (current === root) break;
|
|
65
124
|
}
|
|
66
125
|
return folder;
|
|
67
126
|
}
|
|
68
|
-
let active,
|
|
127
|
+
let active,
|
|
128
|
+
closed = false,
|
|
129
|
+
lastShown;
|
|
69
130
|
let changeTimer, prewarmTimer, prewarming, pendingPrewarm;
|
|
70
131
|
const watchers = new Map();
|
|
71
132
|
let discoveryVersion = 0;
|
|
72
|
-
const discovery = createDraftDiscovery(root, {
|
|
73
|
-
|
|
74
|
-
|
|
133
|
+
const discovery = createDraftDiscovery(root, {
|
|
134
|
+
inspector: scenarioInspector,
|
|
135
|
+
onChange: () => {
|
|
136
|
+
++discoveryVersion;
|
|
137
|
+
onChange?.();
|
|
138
|
+
},
|
|
139
|
+
});
|
|
140
|
+
const manifestFile = (id) => safe(root, `${DRAFT_DIRECTORY}/${idSchema.parse(id)}/proposal.ads.draft.json`);
|
|
141
|
+
const save = (manifest) => atomic(manifestFile(manifest.id), JSON.stringify(manifestSchema.parse(manifest), null, 2) + "\n");
|
|
75
142
|
function read(id) {
|
|
76
|
-
const file = manifestFile(id),
|
|
143
|
+
const file = manifestFile(id),
|
|
144
|
+
content = bytes(file);
|
|
77
145
|
if (!content || content.length > 256 * 1024) throw new Error("Unknown or oversized ADS draft manifest.");
|
|
78
146
|
const manifest = manifestSchema.parse(JSON.parse(content.toString("utf8")));
|
|
79
|
-
if (
|
|
147
|
+
if (
|
|
148
|
+
manifest.id !== id ||
|
|
149
|
+
new Set(manifest.units).size !== manifest.units.length ||
|
|
150
|
+
new Set(manifest.files.map((file) => file.target)).size !== manifest.files.length
|
|
151
|
+
)
|
|
152
|
+
throw new Error("Draft IDs, units and target paths must be unique and consistent.");
|
|
80
153
|
for (const unit of manifest.units) validateUnitId(unit);
|
|
81
154
|
for (const file of manifest.files) {
|
|
82
155
|
safe(root, file.target);
|
|
83
|
-
if (!manifest.units.includes(file.unit) || file.target.split("/").some(part => [DRAFT_DIRECTORY, ".ds", "node_modules", ".git"].includes(part)))
|
|
84
|
-
|
|
156
|
+
if (!manifest.units.includes(file.unit) || file.target.split("/").some((part) => [DRAFT_DIRECTORY, ".ds", "node_modules", ".git"].includes(part)))
|
|
157
|
+
throw new Error("Draft targets must be normal source owned by a declared unit.");
|
|
158
|
+
if (file.source && (!file.source.startsWith("files/") || !file.source.endsWith(".ads")))
|
|
159
|
+
throw new Error("Draft sources must use the non-importable .ads extension under files/.");
|
|
85
160
|
if (file.source) safe(path.dirname(manifestFile(id)), file.source);
|
|
86
161
|
}
|
|
87
162
|
return manifest;
|
|
88
163
|
}
|
|
89
164
|
// Keep machine execution records out of Git; proposal source/manifests are durable.
|
|
90
165
|
const eventFile = path.join(root, ".ds/draft-events.json");
|
|
91
|
-
function events() {
|
|
166
|
+
function events() {
|
|
167
|
+
try {
|
|
168
|
+
const value = JSON.parse(bytes(eventFile)?.toString() ?? "[]");
|
|
169
|
+
return Array.isArray(value) ? value.slice(-100) : [];
|
|
170
|
+
} catch {
|
|
171
|
+
return [];
|
|
172
|
+
}
|
|
173
|
+
}
|
|
92
174
|
function event(id, revision, state, extra = {}) {
|
|
93
175
|
const value = { id: randomUUID(), draft: id, revision, state, at: new Date().toISOString(), ...extra };
|
|
94
176
|
atomic(eventFile, JSON.stringify([...events(), value].slice(-100)));
|
|
95
177
|
return value;
|
|
96
178
|
}
|
|
97
|
-
function inspect(id, stack = [], context
|
|
179
|
+
async function inspect(id, stack = [], context) {
|
|
180
|
+
if (context === undefined) context = { inputs: await validationInputFiles(loadConfig(root)), seen: new Set(), memo: new Map() };
|
|
98
181
|
if (stack.includes(id)) throw new Error(`Draft dependency cycle: ${[...stack, id].join(" → ")}`);
|
|
99
|
-
if(context.memo.has(id))return context.memo.get(id);
|
|
100
|
-
context.seen.add(id);
|
|
101
|
-
|
|
102
|
-
const
|
|
103
|
-
|
|
182
|
+
if (context.memo.has(id)) return context.memo.get(id);
|
|
183
|
+
context.seen.add(id);
|
|
184
|
+
if (context.seen.size > 32 || stack.length > 16) throw new Error("Draft dependency graph exceeds 32 drafts/16 levels.");
|
|
185
|
+
const manifest = read(id),
|
|
186
|
+
folder = path.dirname(manifestFile(id));
|
|
187
|
+
const files = manifest.files.map((file) => ({ ...file, content: file.source ? bytes(safe(folder, file.source)) : null }));
|
|
188
|
+
if (files.some((file) => file.source && file.content === null))
|
|
189
|
+
throw new Error("A registered draft source is missing. Use ads_update_draft with content:null to propose deletion.");
|
|
104
190
|
if (files.reduce((size, file) => size + (file.content?.length ?? 0), 0) > 32 * 1024 * 1024) throw new Error("Draft exceeds 32 MiB.");
|
|
105
|
-
const dependencies = [],
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
191
|
+
const dependencies = [],
|
|
192
|
+
dependencyErrors = [];
|
|
193
|
+
for (const dependency of manifest.dependencies) {
|
|
194
|
+
try {
|
|
195
|
+
const value = await inspect(dependency, [...stack, id], context);
|
|
196
|
+
dependencies.push(value);
|
|
197
|
+
dependencyErrors.push(...value.dependencyErrors);
|
|
198
|
+
} catch (error) {
|
|
199
|
+
dependencyErrors.push({ draft: dependency, message: error.message });
|
|
200
|
+
}
|
|
109
201
|
}
|
|
110
202
|
const projectInputs = context.inputs;
|
|
111
|
-
const revision = hash(
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
203
|
+
const revision = hash(
|
|
204
|
+
JSON.stringify([
|
|
205
|
+
manifest,
|
|
206
|
+
files.map((file) => [file.target, fileHash(file.content)]),
|
|
207
|
+
dependencies.map((dependency) => [dependency.manifest.id, dependency.revision]),
|
|
208
|
+
dependencyErrors,
|
|
209
|
+
projectInputs,
|
|
210
|
+
]),
|
|
211
|
+
);
|
|
212
|
+
const changes = files.filter((file) => fileHash(file.content) !== file.baseline);
|
|
213
|
+
const conflicts = changes.filter((file) => fileHash(bytes(safe(root, file.target))) !== file.baseline).map((file) => file.target);
|
|
214
|
+
const result = { manifest, files, changes, dependencies, dependencyErrors, revision, conflicts };
|
|
215
|
+
context.memo.set(id, result);
|
|
216
|
+
return result;
|
|
115
217
|
}
|
|
116
218
|
function ids() {
|
|
117
219
|
if (!existsSync(storage)) return [];
|
|
118
220
|
if (realpathSync(storage) !== storage) throw new Error("Draft storage cannot be a symlink.");
|
|
119
|
-
return readdirSync(storage, { withFileTypes: true })
|
|
221
|
+
return readdirSync(storage, { withFileTypes: true })
|
|
222
|
+
.filter((entry) => entry.isDirectory() && !entry.isSymbolicLink() && idSchema.safeParse(entry.name).success && existsSync(manifestFile(entry.name)))
|
|
223
|
+
.map((entry) => entry.name)
|
|
224
|
+
.sort();
|
|
120
225
|
}
|
|
121
226
|
function summary(value) {
|
|
122
227
|
const { manifest, revision, conflicts, changes } = value;
|
|
123
|
-
const last = events()
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
228
|
+
const last = events()
|
|
229
|
+
.filter((event) => event.draft === manifest.id)
|
|
230
|
+
.at(-1);
|
|
231
|
+
return {
|
|
232
|
+
id: manifest.id,
|
|
233
|
+
title: manifest.title,
|
|
234
|
+
units: manifest.units,
|
|
235
|
+
dependencies: manifest.dependencies,
|
|
236
|
+
tokenGroups: manifest.tokenGroups,
|
|
237
|
+
revision,
|
|
238
|
+
changes: changes.length,
|
|
239
|
+
conflicts,
|
|
240
|
+
state:
|
|
241
|
+
active?.id === manifest.id
|
|
242
|
+
? "checking"
|
|
243
|
+
: value.dependencyErrors.length
|
|
244
|
+
? "dependency-error"
|
|
245
|
+
: conflicts.length
|
|
246
|
+
? "conflict"
|
|
247
|
+
: last?.state === "checking"
|
|
248
|
+
? "interrupted"
|
|
249
|
+
: last?.state === "failed" && last.revision === revision
|
|
250
|
+
? "failed"
|
|
251
|
+
: "draft",
|
|
252
|
+
preview: previewStatus(manifest.id, revision),
|
|
253
|
+
manifest: path.relative(root, manifestFile(manifest.id)).replaceAll("\\", "/"),
|
|
254
|
+
};
|
|
127
255
|
}
|
|
128
|
-
const scopedBuild = id => `ads://drafts/${id}/resource?uri=${encodeURIComponent("ads://project/build")}`;
|
|
256
|
+
const scopedBuild = (id) => `ads://drafts/${id}/resource?uri=${encodeURIComponent("ads://project/build")}`;
|
|
129
257
|
function previewStatus(id, revision) {
|
|
130
|
-
const session = previews.get(id),
|
|
131
|
-
|
|
132
|
-
|
|
258
|
+
const session = previews.get(id),
|
|
259
|
+
build = session?.build ?? { state: "unreported", building: false, current: false, stale: null, scenarios: [], resourceUri: scopedBuild(id) };
|
|
260
|
+
if (revision && session?.revision !== revision && build.scenarios.length)
|
|
261
|
+
return {
|
|
262
|
+
...build,
|
|
263
|
+
state: "queued",
|
|
264
|
+
building: true,
|
|
265
|
+
current: false,
|
|
266
|
+
stale: true,
|
|
267
|
+
scenarios: build.scenarios.map((item) => ({ ...item, state: "queued", building: true, current: false, stale: true })),
|
|
268
|
+
};
|
|
133
269
|
return build;
|
|
134
270
|
}
|
|
135
271
|
function recordBuild(id, session, report) {
|
|
136
272
|
if (closed || previews.get(id) !== session) return;
|
|
137
|
-
const scenarios = report.previews
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
273
|
+
const scenarios = report.previews
|
|
274
|
+
.filter((item) => item.revision > 0 || item.live || item.state === "error")
|
|
275
|
+
.map((item) => ({
|
|
276
|
+
id: item.id,
|
|
277
|
+
state: item.live ? "checking" : item.state,
|
|
278
|
+
building: ["idle", "building"].includes(item.state),
|
|
279
|
+
current: item.current,
|
|
280
|
+
stale: item.stale,
|
|
281
|
+
revision: item.revision,
|
|
282
|
+
...(item.live ? { live: item.live } : {}),
|
|
283
|
+
...(item.failure ? { failure: item.failure } : {}),
|
|
284
|
+
diagnosticCount: item.diagnostics.length,
|
|
285
|
+
}));
|
|
286
|
+
const building = scenarios.some((item) => item.building);
|
|
287
|
+
const state = scenarios.some((item) => item.state === "error")
|
|
288
|
+
? "error"
|
|
289
|
+
: building
|
|
290
|
+
? scenarios.some((item) => item.live)
|
|
291
|
+
? "checking"
|
|
292
|
+
: "building"
|
|
293
|
+
: scenarios.some((item) => item.current)
|
|
294
|
+
? "ready"
|
|
295
|
+
: report.state;
|
|
296
|
+
const build = {
|
|
297
|
+
state,
|
|
298
|
+
building,
|
|
299
|
+
current: state === "ready",
|
|
300
|
+
stale: state === "ready" ? false : scenarios.length ? true : null,
|
|
301
|
+
session: report.session,
|
|
302
|
+
sequence: report.sequence,
|
|
303
|
+
...(report.progress ? { phase: report.progress.phase } : {}),
|
|
304
|
+
scenarios: scenarios.slice(0, 32),
|
|
305
|
+
scenarioCount: scenarios.length,
|
|
306
|
+
resourceUri: scopedBuild(id),
|
|
307
|
+
};
|
|
145
308
|
if (JSON.stringify(build) === JSON.stringify(session.build)) return;
|
|
146
|
-
session.build = build;
|
|
309
|
+
session.build = build;
|
|
310
|
+
++discoveryVersion;
|
|
311
|
+
onChange?.();
|
|
147
312
|
}
|
|
148
|
-
function list({ id, unit, query = "", offset = 0, limit = 20 } = {}) {
|
|
149
|
-
const diagnostics = [],
|
|
313
|
+
async function list({ id, unit, query = "", offset = 0, limit = 20 } = {}) {
|
|
314
|
+
const diagnostics = [],
|
|
315
|
+
all = [];
|
|
150
316
|
let inputs;
|
|
151
317
|
for (const selected of id ? [id] : ids()) {
|
|
152
318
|
try {
|
|
153
|
-
inputs??=validationInputFiles(loadConfig(root));
|
|
154
|
-
const value = inspect(selected,[],{inputs,seen:new Set(),memo:new Map()}),
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
319
|
+
inputs ??= await validationInputFiles(loadConfig(root));
|
|
320
|
+
const value = await inspect(selected, [], { inputs, seen: new Set(), memo: new Map() }),
|
|
321
|
+
item = summary(value);
|
|
322
|
+
diagnostics.push(...value.dependencyErrors.map((error) => ({ ...error, draft: selected, dependency: error.draft })));
|
|
323
|
+
if ((!unit || item.units.includes(unit)) && `${item.id} ${item.title} ${item.units.join(" ")}`.toLowerCase().includes(query.toLowerCase()))
|
|
324
|
+
all.push(
|
|
325
|
+
id
|
|
326
|
+
? {
|
|
327
|
+
...item,
|
|
328
|
+
files: value.files
|
|
329
|
+
.slice(offset, offset + limit)
|
|
330
|
+
.map(({ content: _content, ...file }) => ({ ...file, source: file.source ? `${DRAFT_DIRECTORY}/${id}/${file.source}` : null })),
|
|
331
|
+
fileCount: value.files.length,
|
|
332
|
+
...(offset + limit < value.files.length ? { nextOffset: offset + limit } : {}),
|
|
333
|
+
}
|
|
334
|
+
: item,
|
|
335
|
+
);
|
|
336
|
+
} catch (error) {
|
|
337
|
+
diagnostics.push({ draft: selected, message: error.message });
|
|
338
|
+
}
|
|
158
339
|
}
|
|
159
|
-
return {
|
|
340
|
+
return {
|
|
341
|
+
mode: "auto",
|
|
342
|
+
total: all.length,
|
|
343
|
+
drafts: id ? all : all.slice(offset, offset + limit),
|
|
344
|
+
...(!id && offset + limit < all.length ? { nextOffset: offset + limit } : {}),
|
|
345
|
+
diagnostics,
|
|
346
|
+
events: events().slice(-10),
|
|
347
|
+
resourceUri: DRAFTS_URI,
|
|
348
|
+
};
|
|
160
349
|
}
|
|
161
|
-
function tokenGroups() {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
350
|
+
async function tokenGroups(tokens) {
|
|
351
|
+
if (tokens === undefined) tokens = (await inspectTokens(root)).tokens;
|
|
352
|
+
const options = loadConfig(root),
|
|
353
|
+
directory = path.join(options.dsRoot, options.config.tokenDir),
|
|
354
|
+
groups = new Map();
|
|
355
|
+
for (const token of tokens)
|
|
356
|
+
for (const definition of token.definitions) {
|
|
357
|
+
const id = path
|
|
358
|
+
.relative(directory, path.join(root, definition.file))
|
|
359
|
+
.replaceAll("\\", "/")
|
|
360
|
+
.replace(/\.css$/, "");
|
|
361
|
+
if (!groups.has(id)) groups.set(id, { id, file: definition.file, tokens: new Set() });
|
|
362
|
+
groups.get(id).tokens.add(token.name);
|
|
363
|
+
}
|
|
364
|
+
return [...groups.values()].map(({ tokens, ...group }) => ({ ...group, count: tokens.size })).sort((a, b) => a.id.localeCompare(b.id));
|
|
165
365
|
}
|
|
166
|
-
function create({ units, title, id = randomUUID(), dependencies = [], tokenGroups: selectedGroups = [] }) {
|
|
366
|
+
async function create({ units, title, id = randomUUID(), dependencies = [], tokenGroups: selectedGroups = [] }) {
|
|
167
367
|
if (closed) throw new Error("Draft controller is closed.");
|
|
168
368
|
units = draftUnits.parse(units);
|
|
169
369
|
idSchema.parse(id);
|
|
@@ -174,256 +374,494 @@ export function createDraftController(directory, { edits, startPreview, prewarm
|
|
|
174
374
|
if (!manifest.units.includes(unit)) return false;
|
|
175
375
|
if (unit !== "tokens") return true;
|
|
176
376
|
const mine = manifest.tokenGroups ?? [];
|
|
177
|
-
return !mine.length || !selectedGroups.length || mine.some(group => selectedGroups.includes(group));
|
|
377
|
+
return !mine.length || !selectedGroups.length || mine.some((group) => selectedGroups.includes(group));
|
|
178
378
|
};
|
|
179
379
|
for (const other of ids()) {
|
|
180
380
|
let held;
|
|
181
|
-
try {
|
|
182
|
-
|
|
381
|
+
try {
|
|
382
|
+
const manifest = read(other);
|
|
383
|
+
held = units.filter((unit) => holds(manifest, unit));
|
|
384
|
+
} catch {
|
|
385
|
+
continue;
|
|
386
|
+
}
|
|
387
|
+
if (held.length)
|
|
388
|
+
throw new Error(
|
|
389
|
+
`${held.join(", ")} ${held.length === 1 ? "is" : "are"} already in open draft ${other}. Accept or drop that draft first, or depend on it from a draft of other owners.`,
|
|
390
|
+
);
|
|
183
391
|
}
|
|
184
|
-
const options = loadConfig(root),
|
|
185
|
-
|
|
186
|
-
|
|
392
|
+
const options = loadConfig(root),
|
|
393
|
+
inventory = await inspectUnits(options),
|
|
394
|
+
files = new Map();
|
|
395
|
+
const groups = selectedGroups.length ? await tokenGroups() : [];
|
|
396
|
+
if (selectedGroups.length && (!units.includes("tokens") || selectedGroups.some((id) => !groups.some((group) => group.id === id))))
|
|
397
|
+
throw new Error("Choose discovered tokenGroups from ads_tokens and include the tokens owner.");
|
|
187
398
|
for (const unit of units) {
|
|
188
399
|
validateUnitId(unit);
|
|
189
|
-
const owner = inventory.units.find(item => item.id === unit);
|
|
190
|
-
if (!owner && !/^(?:components|patterns|controllers|composition|review)\/.+/.test(unit))
|
|
400
|
+
const owner = inventory.units.find((item) => item.id === unit);
|
|
401
|
+
if (!owner && !/^(?:components|patterns|controllers|composition|review)\/.+/.test(unit))
|
|
402
|
+
throw new Error("Choose a discovered owner or a new component/pattern/controller/composition/review owner.");
|
|
191
403
|
// Only the owner's own files: a shared companion (ds.config.json, the foundation styles entry)
|
|
192
404
|
// joins a draft when the draft changes it, so drafts of different owners do not share copies.
|
|
193
405
|
const paths = owner?.files ?? [];
|
|
194
|
-
for (const target of paths)
|
|
195
|
-
if(
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
406
|
+
for (const target of paths)
|
|
407
|
+
if (!files.has(target)) {
|
|
408
|
+
if (
|
|
409
|
+
unit === "tokens" &&
|
|
410
|
+
selectedGroups.length &&
|
|
411
|
+
target.endsWith(".css") &&
|
|
412
|
+
isInside(path.join(options.dsRoot, options.config.tokenDir), path.join(root, target)) &&
|
|
413
|
+
!groups.some((group) => selectedGroups.includes(group.id) && group.file === target)
|
|
414
|
+
)
|
|
415
|
+
continue;
|
|
416
|
+
const content = bytes(safe(root, target));
|
|
417
|
+
if (content === null) continue;
|
|
418
|
+
const source = storedName(target);
|
|
419
|
+
files.set(target, { target, source, baseline: hash(content), unit });
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
const manifest = manifestSchema.parse({
|
|
423
|
+
schemaVersion: 1,
|
|
424
|
+
id,
|
|
425
|
+
title: title ?? units.join(", ").slice(0, 160),
|
|
426
|
+
units,
|
|
427
|
+
dependencies,
|
|
428
|
+
tokenGroups: selectedGroups,
|
|
429
|
+
files: [...files.values()],
|
|
430
|
+
});
|
|
431
|
+
for (const dependency of dependencies) {
|
|
432
|
+
const value = await inspect(dependency, [id]);
|
|
433
|
+
if (value.dependencyErrors.length) throw new Error(value.dependencyErrors[0].message);
|
|
201
434
|
}
|
|
202
|
-
const manifest = manifestSchema.parse({ schemaVersion: 1, id, title: title ?? units.join(", ").slice(0,160), units, dependencies, tokenGroups:selectedGroups, files: [...files.values()] });
|
|
203
|
-
for (const dependency of dependencies) {const value=inspect(dependency,[id]);if(value.dependencyErrors.length)throw new Error(value.dependencyErrors[0].message);}
|
|
204
435
|
for (const file of manifest.files) {
|
|
205
|
-
const content=bytes(safe(root,file.target)),
|
|
206
|
-
|
|
436
|
+
const content = bytes(safe(root, file.target)),
|
|
437
|
+
folder = path.dirname(manifestFile(id));
|
|
438
|
+
atomic(safe(folder, file.source), content);
|
|
207
439
|
}
|
|
208
440
|
save(manifest);
|
|
209
|
-
const value = inspect(id);
|
|
210
|
-
|
|
211
|
-
|
|
441
|
+
const value = await inspect(id);
|
|
442
|
+
event(id, value.revision, "created");
|
|
443
|
+
reconcileWatches();
|
|
444
|
+
queuePrewarm(id);
|
|
445
|
+
return {
|
|
446
|
+
...summary(value),
|
|
447
|
+
directory: `${DRAFT_DIRECTORY}/${id}`,
|
|
448
|
+
next: "Edit the marked source files, or patch/register files with ads_update_draft. Use ads_show_draft, review the rendered result, then ads_accept with its exact revision (dryRun:true checks without writing). Do not finish a design change with unaccepted drafts.",
|
|
449
|
+
};
|
|
212
450
|
}
|
|
213
451
|
/** Write one proposed file into a draft: content null proposes deletion. Accepted source never changes. */
|
|
214
|
-
function stage(manifest, {unit, path: target, content}) {
|
|
452
|
+
function stage(manifest, { unit, path: target, content }) {
|
|
215
453
|
if (!manifest.units.includes(unit)) throw new Error("Changes must belong to a declared draft unit.");
|
|
216
454
|
const folder = path.dirname(manifestFile(manifest.id));
|
|
217
|
-
let file = manifest.files.find(file => file.target === target);
|
|
218
|
-
if (!file) {
|
|
455
|
+
let file = manifest.files.find((file) => file.target === target);
|
|
456
|
+
if (!file) {
|
|
457
|
+
file = { target, source: null, baseline: fileHash(bytes(safe(root, target))), unit };
|
|
458
|
+
manifest.files.push(file);
|
|
459
|
+
}
|
|
219
460
|
file.unit = unit;
|
|
220
461
|
if (content === null) file.source = null;
|
|
221
|
-
else {
|
|
462
|
+
else {
|
|
463
|
+
file.source ??= storedName(target);
|
|
464
|
+
atomic(safe(folder, file.source), content);
|
|
465
|
+
}
|
|
222
466
|
}
|
|
223
467
|
/** The draft's current proposal for a canonical path: its source, null when deleted or absent. */
|
|
224
468
|
function proposed(manifest, target) {
|
|
225
|
-
const file = manifest.files.find(file => file.target === target);
|
|
469
|
+
const file = manifest.files.find((file) => file.target === target);
|
|
226
470
|
if (!file) return bytes(safe(root, target));
|
|
227
471
|
return file.source ? bytes(safe(path.dirname(manifestFile(manifest.id)), file.source)) : null;
|
|
228
472
|
}
|
|
229
|
-
function ownerOf(manifest, target) {
|
|
230
|
-
const known = manifest.files.find(file => file.target === target)?.unit;
|
|
473
|
+
async function ownerOf(manifest, target) {
|
|
474
|
+
const known = manifest.files.find((file) => file.target === target)?.unit;
|
|
231
475
|
if (known) return known;
|
|
232
|
-
const units = inspectUnits(loadConfig(root)),
|
|
476
|
+
const units = await inspectUnits(loadConfig(root)),
|
|
477
|
+
owner = units.owner(units.relative(target));
|
|
233
478
|
if (manifest.units.includes(owner)) return owner;
|
|
234
479
|
if (manifest.units.length === 1) return manifest.units[0];
|
|
235
480
|
throw new Error(`${target} is not owned by a declared draft unit. Add its owner to a draft, or use changes with an explicit unit.`);
|
|
236
481
|
}
|
|
237
482
|
/** Apply a Git unified diff, written against canonical paths, to the draft's proposed files. */
|
|
238
|
-
function patchDraft(manifest, text) {
|
|
239
|
-
const entries = parseUnifiedPatch(text, mutationLimits.files),
|
|
483
|
+
async function patchDraft(manifest, text) {
|
|
484
|
+
const entries = parseUnifiedPatch(text, mutationLimits.files),
|
|
485
|
+
staged = [];
|
|
240
486
|
for (const entry of entries) {
|
|
241
487
|
if (entry.binary) throw new Error(`${entry.path}: binary patches cannot edit a draft. Send the file through changes with encoding:base64.`);
|
|
242
488
|
safe(root, entry.path);
|
|
243
489
|
const before = proposed(manifest, entry.path);
|
|
244
|
-
if (before !== null && !Buffer.from(before.toString("utf8")).equals(before))
|
|
490
|
+
if (before !== null && !Buffer.from(before.toString("utf8")).equals(before))
|
|
491
|
+
throw new Error(`${entry.path} is binary; replace it through changes with encoding:base64.`);
|
|
245
492
|
const after = applyFilePatch(entry, before === null ? null : before.toString("utf8"));
|
|
246
|
-
staged.push({ unit: ownerOf(manifest, entry.path), path: entry.path, content: after === null ? null : Buffer.from(after) });
|
|
493
|
+
staged.push({ unit: await ownerOf(manifest, entry.path), path: entry.path, content: after === null ? null : Buffer.from(after) });
|
|
247
494
|
}
|
|
248
495
|
for (const change of staged) stage(manifest, change);
|
|
249
|
-
return staged.map(change => change.path);
|
|
496
|
+
return staged.map((change) => change.path);
|
|
250
497
|
}
|
|
251
|
-
function update({ id, revision, changes = [], dependencies, patch, patchFile }) {
|
|
252
|
-
const value = inspect(id);
|
|
498
|
+
async function update({ id, revision, changes = [], dependencies, patch, patchFile }) {
|
|
499
|
+
const value = await inspect(id);
|
|
253
500
|
if (value.revision !== revision) throw new Error("Draft revision changed. Read ads_drafts again before editing.");
|
|
254
501
|
const manifest = value.manifest;
|
|
255
502
|
if (patch !== undefined || patchFile !== undefined) {
|
|
256
503
|
if (patch !== undefined && patchFile !== undefined) throw new Error("Provide exactly one of patch or patchFile.");
|
|
257
504
|
if (changes.length || dependencies) throw new Error("Patch a draft separately from changes and dependency edits.");
|
|
258
|
-
const patched = patchDraft(manifest, patch ?? readPatchFile(loadConfig(root), patchFile));
|
|
259
|
-
save(manifest);
|
|
260
|
-
|
|
505
|
+
const patched = await patchDraft(manifest, patch ?? readPatchFile(loadConfig(root), patchFile));
|
|
506
|
+
save(manifest);
|
|
507
|
+
changed();
|
|
508
|
+
return { ...summary(await inspect(id)), patched };
|
|
261
509
|
}
|
|
262
|
-
if (dependencies) {
|
|
263
|
-
|
|
510
|
+
if (dependencies) {
|
|
511
|
+
for (const dependency of dependencies) {
|
|
512
|
+
const value = await inspect(dependency, [id]);
|
|
513
|
+
if (value.dependencyErrors.length) throw new Error(value.dependencyErrors[0].message);
|
|
514
|
+
}
|
|
515
|
+
manifest.dependencies = dependencies;
|
|
516
|
+
}
|
|
517
|
+
for (const change of changes)
|
|
518
|
+
stage(manifest, {
|
|
519
|
+
unit: change.unit,
|
|
520
|
+
path: change.path,
|
|
521
|
+
content: change.content === null ? null : Buffer.from(change.content, change.encoding === "base64" ? "base64" : "utf8"),
|
|
522
|
+
});
|
|
264
523
|
save(manifest);
|
|
265
524
|
changed();
|
|
266
|
-
return summary(inspect(id));
|
|
525
|
+
return summary(await inspect(id));
|
|
267
526
|
}
|
|
268
|
-
function prepare(id) {
|
|
269
|
-
|
|
270
|
-
|
|
527
|
+
async function prepare(id) {
|
|
528
|
+
// One operation owns both the inspection revision and the workspace bytes.
|
|
529
|
+
// inspect still performs its targeted live conflict/path checks.
|
|
530
|
+
const captured = new Map();
|
|
531
|
+
const inputs = await validationInputFiles(loadConfig(root), [], { onFile: (file, content) => captured.set(file, content) });
|
|
532
|
+
const value = await inspect(id, [], { inputs, seen: new Set(), memo: new Map() });
|
|
533
|
+
if (value.dependencyErrors.length) throw new Error(`Draft dependency error: ${value.dependencyErrors[0].message}`);
|
|
271
534
|
if (value.conflicts.length) throw new Error(`Draft baseline conflict: ${value.conflicts.join(", ")}`);
|
|
272
535
|
let session = previews.get(id);
|
|
273
536
|
if (!session) {
|
|
274
537
|
const workspace = path.join(previewDirectory(id), "project");
|
|
275
|
-
const directory=path.dirname(workspace);
|
|
276
|
-
if(existsSync(directory)&&realpathSync(directory)!==directory)throw new Error("Draft preview storage cannot be a symlink.");
|
|
277
|
-
rmSync(directory,{recursive:true,force:true});
|
|
538
|
+
const directory = path.dirname(workspace);
|
|
539
|
+
if (existsSync(directory) && realpathSync(directory) !== directory) throw new Error("Draft preview storage cannot be a symlink.");
|
|
540
|
+
rmSync(directory, { recursive: true, force: true });
|
|
278
541
|
mkdirSync(workspace, { recursive: true });
|
|
279
542
|
if (realpathSync(workspace) !== workspace) throw new Error("Draft preview workspace cannot be a symlink.");
|
|
280
|
-
session = { workspace, inputs: new Map() };
|
|
543
|
+
session = { workspace, inputs: new Map() };
|
|
544
|
+
previews.set(id, session);
|
|
545
|
+
reconcileWatches();
|
|
281
546
|
}
|
|
282
|
-
if(session.revision
|
|
283
|
-
mkdirSync(session.workspace,{recursive:true});
|
|
284
|
-
if(realpathSync(session.workspace)!==session.workspace)throw new Error("Draft preview workspace cannot be a symlink.");
|
|
285
|
-
const
|
|
547
|
+
if (session.revision && !existsSync(path.join(session.workspace, ".ds/draft-preview.json"))) session.recovering = true;
|
|
548
|
+
mkdirSync(session.workspace, { recursive: true });
|
|
549
|
+
if (realpathSync(session.workspace) !== session.workspace) throw new Error("Draft preview workspace cannot be a symlink.");
|
|
550
|
+
const desired = new Map();
|
|
551
|
+
const baseline = new Map([...captured].filter(([file]) => isAnalysisSource(file)).map(([file, content]) => [file, content.toString("utf8")]));
|
|
286
552
|
let size = 0;
|
|
287
|
-
for (const [target, digest] of Object.entries(inputs))
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
553
|
+
for (const [target, digest] of Object.entries(inputs))
|
|
554
|
+
if (digest && target !== "installed-dependencies") {
|
|
555
|
+
const content = captured.get(target);
|
|
556
|
+
if (content !== null) {
|
|
557
|
+
desired.set(target, content);
|
|
558
|
+
size += content.length;
|
|
559
|
+
}
|
|
560
|
+
if (desired.size > 100000 || size > 2 * 1024 ** 3) throw new Error("Draft preview input limit exceeded.");
|
|
561
|
+
}
|
|
292
562
|
const applied = new Map();
|
|
293
563
|
function overlay(proposal) {
|
|
294
564
|
if (proposal.conflicts.length) throw new Error(`Dependency draft conflict: ${proposal.conflicts.join(", ")}`);
|
|
295
565
|
for (const dependency of proposal.dependencies) overlay(dependency);
|
|
296
566
|
for (const file of proposal.changes) {
|
|
297
567
|
const digest = fileHash(file.content);
|
|
298
|
-
if (applied.has(file.target) && applied.get(file.target) !== digest)
|
|
568
|
+
if (applied.has(file.target) && applied.get(file.target) !== digest)
|
|
569
|
+
throw new Error(`Drafts both change ${file.target}; use one coupled draft for overlapping edits.`);
|
|
299
570
|
applied.set(file.target, digest);
|
|
300
|
-
if (file.content === null) desired.delete(file.target);
|
|
571
|
+
if (file.content === null) desired.delete(file.target);
|
|
572
|
+
else desired.set(file.target, file.content);
|
|
301
573
|
}
|
|
302
574
|
}
|
|
303
575
|
overlay(value);
|
|
304
576
|
for (const target of session.inputs.keys()) if (!desired.has(target)) rmSync(safe(session.workspace, target), { force: true });
|
|
305
|
-
for (const [target, content] of desired)
|
|
577
|
+
for (const [target, content] of desired)
|
|
578
|
+
if (session.inputs.get(target) !== hash(content) || !existsSync(safe(session.workspace, target))) atomic(safe(session.workspace, target), content);
|
|
306
579
|
session.inputs = new Map([...desired].map(([target, content]) => [target, hash(content)]));
|
|
307
580
|
// A draft's token edits preview with their own generated theme sheet, and its exports files and token sheets with their own generated entries.
|
|
308
|
-
|
|
309
|
-
|
|
581
|
+
|
|
582
|
+
const key = hash(JSON.stringify([...session.inputs]));
|
|
583
|
+
if (session.themeKey !== key) {
|
|
584
|
+
session.themeKey = key;
|
|
585
|
+
const register = async () => {
|
|
586
|
+
const sources = new Map([...desired].filter(([file]) => isAnalysisSource(file)).map(([file, content]) => [file, content.toString("utf8")]));
|
|
587
|
+
const changes = [...new Set([...baseline.keys(), ...sources.keys()])]
|
|
588
|
+
.filter((file) => baseline.get(file) !== sources.get(file))
|
|
589
|
+
.map((file) => [file, sources.get(file) ?? null]);
|
|
590
|
+
await registerAnalysisRevision(root, session.workspace, baseline, changes, inputs["installed-dependencies"] ?? "");
|
|
591
|
+
};
|
|
592
|
+
// Defer the request until dependencies and generated entries below exist.
|
|
593
|
+
session.themeTask = Promise.resolve()
|
|
594
|
+
.then(async () => {
|
|
595
|
+
if (closed || previews.get(id) !== session || session.themeKey !== key) return;
|
|
596
|
+
for (const generated of (await writeGeneratedEntries(loadConfig(session.workspace))).files)
|
|
597
|
+
desired.set(path.relative(session.workspace, generated.file), Buffer.from(generated.text));
|
|
598
|
+
await register();
|
|
599
|
+
const tokens = await analyze(session.workspace, "tokens");
|
|
600
|
+
if (!closed && previews.get(id) === session && session.themeKey === key) {
|
|
601
|
+
const options = loadConfig(session.workspace);
|
|
602
|
+
for (const generated of [...writeThemesCss(options, tokens).files, ...(await writeGeneratedEntries(options)).files]) {
|
|
603
|
+
if (generated.text !== undefined) desired.set(path.relative(session.workspace, generated.file), Buffer.from(generated.text));
|
|
604
|
+
}
|
|
605
|
+
await register();
|
|
606
|
+
}
|
|
607
|
+
})
|
|
608
|
+
.catch(async () => {
|
|
609
|
+
if (session.themeKey === key) {
|
|
610
|
+
session.themeKey = undefined;
|
|
611
|
+
await releaseAnalysisRevision(session.workspace).catch(() => {});
|
|
612
|
+
}
|
|
613
|
+
// Acceptance reports broken tokens; discovery can recover independently.
|
|
614
|
+
});
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
try {
|
|
618
|
+
await writeGeneratedEntries(loadConfig(session.workspace));
|
|
619
|
+
} catch {
|
|
620
|
+
/* Acceptance checks report broken exports files. */
|
|
621
|
+
}
|
|
310
622
|
const modules = path.join(session.workspace, "node_modules");
|
|
311
|
-
if (!existsSync(modules) && existsSync(path.join(root, "node_modules")))
|
|
623
|
+
if (!existsSync(modules) && existsSync(path.join(root, "node_modules")))
|
|
624
|
+
symlinkSync(realpathSync(path.join(root, "node_modules")), modules, process.platform === "win32" ? "junction" : "dir");
|
|
312
625
|
if (!existsSync(path.join(session.workspace, "dist")) && existsSync(path.join(root, "dist/cli.mjs"))) {
|
|
313
|
-
let count=0,
|
|
314
|
-
|
|
626
|
+
let count = 0,
|
|
627
|
+
total = 0;
|
|
628
|
+
cpSync(path.join(root, "dist"), path.join(session.workspace, "dist"), {
|
|
629
|
+
recursive: true,
|
|
630
|
+
filter(file) {
|
|
631
|
+
const stat = lstatSync(file);
|
|
632
|
+
if (stat.isSymbolicLink()) throw new Error("Generated runtime copies cannot contain symlinks.");
|
|
633
|
+
if (stat.isFile()) {
|
|
634
|
+
count++;
|
|
635
|
+
total += stat.size;
|
|
636
|
+
}
|
|
637
|
+
if (count > 100000 || total > 2 * 1024 ** 3) throw new Error("Generated runtime exceeds the preview limit.");
|
|
638
|
+
return true;
|
|
639
|
+
},
|
|
640
|
+
});
|
|
315
641
|
}
|
|
316
642
|
atomic(path.join(session.workspace, ".ds/draft-preview.json"), JSON.stringify({ previewOnly: true }));
|
|
317
643
|
if (session.revision && session.revision !== value.revision && session.runtime && session.build?.scenarios.length) {
|
|
318
644
|
const before = previewStatus(id);
|
|
319
|
-
session.build = {
|
|
320
|
-
|
|
645
|
+
session.build = {
|
|
646
|
+
...before,
|
|
647
|
+
state: "queued",
|
|
648
|
+
building: true,
|
|
649
|
+
current: false,
|
|
650
|
+
stale: true,
|
|
651
|
+
scenarios: before.scenarios.map((item) => ({ ...item, state: "queued", building: true, current: false, stale: true })),
|
|
652
|
+
};
|
|
321
653
|
}
|
|
322
654
|
session.revision = value.revision;
|
|
323
655
|
session.projectRevision = hash(JSON.stringify(inputs));
|
|
324
|
-
session.error=undefined;
|
|
325
|
-
const watched=new Set();
|
|
326
|
-
for(const target of Object.keys(inputs)){
|
|
327
|
-
let file=target==="installed-dependencies"?path.join(root,"node_modules/.package-lock.json"):path.join(root,target);
|
|
328
|
-
while(isInside(root,file)){
|
|
656
|
+
session.error = undefined;
|
|
657
|
+
const watched = new Set();
|
|
658
|
+
for (const target of Object.keys(inputs)) {
|
|
659
|
+
let file = target === "installed-dependencies" ? path.join(root, "node_modules/.package-lock.json") : path.join(root, target);
|
|
660
|
+
while (isInside(root, file)) {
|
|
661
|
+
watched.add(file);
|
|
662
|
+
if (file === root) break;
|
|
663
|
+
file = path.dirname(file);
|
|
664
|
+
}
|
|
329
665
|
}
|
|
330
|
-
session.watchFiles=[...watched];
|
|
666
|
+
session.watchFiles = [...watched];
|
|
667
|
+
session.ownObserved = ownStamp(id);
|
|
668
|
+
session.acceptedObserved = watchStamp(session);
|
|
331
669
|
return { ...value, session };
|
|
332
670
|
}
|
|
333
671
|
async function show(args, signal) {
|
|
334
672
|
++showing;
|
|
335
|
-
try {
|
|
673
|
+
try {
|
|
674
|
+
return await showDraft(args, signal);
|
|
675
|
+
} finally {
|
|
676
|
+
--showing;
|
|
677
|
+
}
|
|
336
678
|
}
|
|
337
679
|
async function showDraft({ id, scenario }, signal) {
|
|
338
680
|
if (signal?.aborted) throw new Error("Draft preview request cancelled.");
|
|
339
681
|
if (closed) throw new Error("Draft controller is closed.");
|
|
340
|
-
const existing=previews.get(id);
|
|
341
|
-
if(existing&&(existing.recovering
|
|
342
|
-
if(!previews.has(id)&&[...previews.values()].filter(session=>session.starting).length>=4){
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
const
|
|
682
|
+
const existing = previews.get(id);
|
|
683
|
+
if (existing && (existing.recovering || !existsSync(path.join(existing.workspace, ".ds/draft-preview.json")))) await retire(id);
|
|
684
|
+
if (!previews.has(id) && [...previews.values()].filter((session) => session.starting).length >= 4) {
|
|
685
|
+
const oldest = [...previews].find(([, session]) => session.starting);
|
|
686
|
+
if (oldest) await retire(oldest[0]);
|
|
687
|
+
}
|
|
688
|
+
const value = await prepare(id),
|
|
689
|
+
{ session } = value;
|
|
690
|
+
await session.themeTask;
|
|
691
|
+
session.opened = true;
|
|
692
|
+
lastShown = id;
|
|
693
|
+
const options = loadConfig(session.workspace),
|
|
694
|
+
units = await inspectUnits(options);
|
|
695
|
+
const metadata = await discovery.refresh(session.workspace, value.revision);
|
|
347
696
|
let registry = metadata.registry;
|
|
348
|
-
const known = scenario
|
|
349
|
-
|
|
350
|
-
|
|
697
|
+
const known = scenario
|
|
698
|
+
? registry?.scenarios.find((item) => item.id === scenario)
|
|
699
|
+
: registry?.scenarios.find((item) => value.manifest.units.includes(units.owner(units.relative(item.file))));
|
|
700
|
+
if (!registry || !known || !existsSync(path.join(session.workspace, known.file)) || registry.diagnostics.length)
|
|
701
|
+
registry = await discovery.current(session.workspace, value.revision);
|
|
351
702
|
const metadataRevision = metadata.revision;
|
|
352
|
-
const diagnosticsUri
|
|
353
|
-
session.registry=registry;
|
|
354
|
-
if(registry.diagnostics.length) {
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
703
|
+
const diagnosticsUri = `ads://drafts/${id}/resource?uri=${encodeURIComponent("ads://project/scenarios")}`;
|
|
704
|
+
session.registry = registry;
|
|
705
|
+
if (registry.diagnostics.length) {
|
|
706
|
+
session.build = {
|
|
707
|
+
state: "error",
|
|
708
|
+
building: false,
|
|
709
|
+
current: false,
|
|
710
|
+
stale: true,
|
|
711
|
+
scenarios: [],
|
|
712
|
+
diagnosticCount: registry.diagnostics.length,
|
|
713
|
+
resourceUri: scopedBuild(id),
|
|
714
|
+
};
|
|
715
|
+
++discoveryVersion;
|
|
716
|
+
onChange?.();
|
|
717
|
+
return {
|
|
718
|
+
...summary(value),
|
|
719
|
+
ok: false,
|
|
720
|
+
diagnostics: registry.diagnostics,
|
|
721
|
+
diagnosticsUri,
|
|
722
|
+
previewOnly: true,
|
|
723
|
+
next: "Fix these diagnostics in this draft's source. The accepted project registry is separate. Reopen ads_show_draft after editing.",
|
|
724
|
+
};
|
|
725
|
+
}
|
|
726
|
+
const scenarios = registry.scenarios.map(({ id, title, kind, group, file }) => ({
|
|
727
|
+
id,
|
|
728
|
+
title,
|
|
729
|
+
kind,
|
|
730
|
+
...(group ? { group } : {}),
|
|
731
|
+
unit: units.owner(units.relative(file)),
|
|
732
|
+
}));
|
|
733
|
+
const owned = scenarios.find((item) => value.manifest.units.includes(item.unit))?.id;
|
|
734
|
+
if (!scenario && !owned && value.manifest.units.some((unit) => /^(?:components|patterns|composition)\//.test(unit)))
|
|
735
|
+
throw new Error("Draft has no independently mountable owner scenario yet. Add its scenario/fixture or select an explicit existing context scenario.");
|
|
360
736
|
const selected = scenario ?? owned ?? registry.scenarios[0]?.id;
|
|
361
737
|
session.selected = selected;
|
|
362
|
-
if (scenario && !registry.scenarios.some(item => item.id === scenario))
|
|
738
|
+
if (scenario && !registry.scenarios.some((item) => item.id === scenario))
|
|
739
|
+
throw new Error("Unknown draft scenario. Read ads_show_draft without scenario to discover it.");
|
|
363
740
|
await startSession(id, session);
|
|
364
741
|
if (signal?.aborted) throw new Error("Draft preview request cancelled.");
|
|
365
742
|
if (metadata.revision === value.revision) session.runtime.primeRegistry?.(registry);
|
|
366
|
-
const url = new URL(session.runtime.url);
|
|
743
|
+
const url = new URL(session.runtime.url);
|
|
744
|
+
if (selected) url.searchParams.set("scenario", selected);
|
|
367
745
|
const accepted = await discovery.current(root, session.projectRevision);
|
|
368
|
-
const acceptedExists = accepted.scenarios.some(item => item.id === selected);
|
|
369
|
-
const previewResult=
|
|
370
|
-
|
|
371
|
-
if(
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
746
|
+
const acceptedExists = accepted.scenarios.some((item) => item.id === selected);
|
|
747
|
+
const previewResult =
|
|
748
|
+
selected && session.runtime.callTool ? await session.runtime.callTool("ads_show_scenario", { id: selected, waitFor: "compiled" }, signal) : undefined;
|
|
749
|
+
if (session.runtime.buildStatus) recordBuild(id, session, await session.runtime.buildStatus());
|
|
750
|
+
if (previewResult?.isError) {
|
|
751
|
+
registry = await discovery.current(session.workspace, value.revision);
|
|
752
|
+
session.registry = registry;
|
|
753
|
+
const diagnostics = registry.diagnostics.length
|
|
754
|
+
? registry.diagnostics
|
|
755
|
+
: [{ rule: "draft-preview", message: previewResult.content?.find((item) => item.type === "text")?.text ?? "Draft preview compilation failed." }];
|
|
756
|
+
return {
|
|
757
|
+
...summary(value),
|
|
758
|
+
ok: false,
|
|
759
|
+
scenario: selected,
|
|
760
|
+
diagnostics,
|
|
761
|
+
diagnosticsUri,
|
|
762
|
+
previewOnly: true,
|
|
763
|
+
previewResult,
|
|
764
|
+
next: "Fix the draft-private preview errors, then reopen this draft. Accepted source has not changed.",
|
|
765
|
+
};
|
|
376
766
|
}
|
|
377
|
-
return {
|
|
767
|
+
return {
|
|
768
|
+
...summary(value),
|
|
769
|
+
scenario: selected,
|
|
770
|
+
scenarios,
|
|
771
|
+
diagnostics: registry.diagnostics,
|
|
772
|
+
diagnosticsUri,
|
|
773
|
+
discovery: discovery.status(metadata, metadataRevision),
|
|
774
|
+
build: previewResult?.structuredContent?.build ?? previewStatus(id),
|
|
775
|
+
showcaseUrl: url.href,
|
|
776
|
+
acceptedExists,
|
|
777
|
+
previewOnly: true,
|
|
778
|
+
previewResult,
|
|
779
|
+
draftScope: `ads://drafts/${id}/resource?uri=`,
|
|
780
|
+
next: "Inspect the actual rendered draft and its build freshness. Catalogue metadata may refresh in the background. Subscribe to ads://project/build and ads://project/drafts for updates. Reopen after edits; accept only the revision you reviewed. Full acceptance checks have not run.",
|
|
781
|
+
};
|
|
378
782
|
}
|
|
379
783
|
async function startSession(id, session) {
|
|
784
|
+
await session.themeTask;
|
|
380
785
|
session.starting ??= (async () => {
|
|
381
|
-
if ([...previews.values()].filter(item => item !== session && item.starting).length >= 4) {
|
|
786
|
+
if ([...previews.values()].filter((item) => item !== session && item.starting).length >= 4) {
|
|
382
787
|
const oldest = [...previews].find(([other, item]) => other !== id && item.starting);
|
|
383
788
|
if (oldest) await retire(oldest[0]);
|
|
384
789
|
}
|
|
385
790
|
if (closed || previews.get(id) !== session) throw new Error("Draft preview was closed before startup.");
|
|
386
791
|
const runtime = await startPreview(session.workspace, id);
|
|
387
|
-
if (closed || previews.get(id) !== session) {
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
792
|
+
if (closed || previews.get(id) !== session) {
|
|
793
|
+
await runtime.close();
|
|
794
|
+
throw new Error("Draft preview startup was cancelled.");
|
|
795
|
+
}
|
|
796
|
+
session.unsubscribeBuild = runtime.onBuildChange?.((report) => recordBuild(id, session, report));
|
|
797
|
+
return (session.runtime = runtime);
|
|
798
|
+
})().catch((error) => {
|
|
799
|
+
session.starting = undefined;
|
|
800
|
+
throw error;
|
|
801
|
+
});
|
|
391
802
|
return session.starting;
|
|
392
803
|
}
|
|
393
804
|
async function retire(id) {
|
|
394
|
-
const session=previews.get(id),
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
805
|
+
const session = previews.get(id),
|
|
806
|
+
workspace = path.join(previewDirectory(id), "project");
|
|
807
|
+
previews.delete(id);
|
|
808
|
+
discovery.remove(workspace);
|
|
809
|
+
if (session) {
|
|
810
|
+
try {
|
|
811
|
+
await session.themeTask;
|
|
812
|
+
await session.starting;
|
|
813
|
+
} catch {
|
|
814
|
+
/* Failed startup remains disposable. */
|
|
815
|
+
}
|
|
816
|
+
session.unsubscribeBuild?.();
|
|
817
|
+
await session.runtime?.close();
|
|
818
|
+
}
|
|
819
|
+
await releaseAnalysisRevision(workspace).catch(() => {});
|
|
820
|
+
if (previews.has(id)) return;
|
|
398
821
|
// Move the workspace aside in one step: a compiler instance still stopping sees its root gone, not half-deleted.
|
|
399
|
-
const directory=path.dirname(workspace),
|
|
400
|
-
|
|
401
|
-
|
|
822
|
+
const directory = path.dirname(workspace),
|
|
823
|
+
retired = `${directory}.retired-${randomUUID()}`;
|
|
824
|
+
try {
|
|
825
|
+
renameSync(directory, retired);
|
|
826
|
+
} catch {
|
|
827
|
+
rmSync(directory, { recursive: true, force: true });
|
|
828
|
+
return;
|
|
829
|
+
}
|
|
830
|
+
rmSync(retired, { recursive: true, force: true });
|
|
402
831
|
}
|
|
403
832
|
function queuePrewarm(id) {
|
|
404
|
-
if (!prewarm || !startPreview || !loadConfig(root).config.
|
|
833
|
+
if (!prewarm || !startPreview || !loadConfig(root).config.framework) return;
|
|
405
834
|
pendingPrewarm = id;
|
|
406
835
|
clearTimeout(prewarmTimer);
|
|
407
|
-
prewarmTimer = setTimeout(warmNext, 50);
|
|
836
|
+
prewarmTimer = setTimeout(warmNext, 50);
|
|
837
|
+
prewarmTimer.unref();
|
|
408
838
|
}
|
|
409
|
-
function warmNext() {
|
|
839
|
+
async function warmNext() {
|
|
410
840
|
if (closed || prewarming || !pendingPrewarm) return;
|
|
411
|
-
const id = pendingPrewarm;
|
|
841
|
+
const id = pendingPrewarm;
|
|
842
|
+
pendingPrewarm = undefined;
|
|
412
843
|
prewarming = (async () => {
|
|
413
844
|
if (!existsSync(manifestFile(id))) return;
|
|
414
845
|
for (const [other, session] of previews) if (other !== id && session.prewarmed && !session.opened) await retire(other);
|
|
415
|
-
const { session } = prepare(id);
|
|
846
|
+
const { session } = await prepare(id);
|
|
416
847
|
session.prewarmed = true;
|
|
417
848
|
await startSession(id, session);
|
|
418
849
|
await session.runtime.prewarm?.();
|
|
419
|
-
})()
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
850
|
+
})()
|
|
851
|
+
.catch(() => {
|
|
852
|
+
/* A malformed/incomplete draft can be edited and retried through show(). */
|
|
853
|
+
})
|
|
854
|
+
.finally(() => {
|
|
855
|
+
prewarming = undefined;
|
|
856
|
+
if (!closed && pendingPrewarm) {
|
|
857
|
+
prewarmTimer = setTimeout(warmNext, 0);
|
|
858
|
+
prewarmTimer.unref();
|
|
859
|
+
}
|
|
860
|
+
});
|
|
423
861
|
}
|
|
424
862
|
async function drop({ id, revision }) {
|
|
425
863
|
if (active) throw new Error("Wait for acceptance before dropping a draft.");
|
|
426
|
-
const value = inspect(id);
|
|
864
|
+
const value = await inspect(id);
|
|
427
865
|
if (revision !== value.revision) throw new Error("Draft revision changed; read ads_drafts again.");
|
|
428
866
|
await retire(id);
|
|
429
867
|
rmSync(path.dirname(manifestFile(id)), { recursive: true });
|
|
@@ -431,94 +869,208 @@ export function createDraftController(directory, { edits, startPreview, prewarm
|
|
|
431
869
|
}
|
|
432
870
|
async function accept({ id, revision, dryRun = false }, signal, progress) {
|
|
433
871
|
if (closed || active) throw new Error("Wait for the active acceptance, or reopen ADS.");
|
|
434
|
-
const value = inspect(id);
|
|
435
|
-
if(value.dependencyErrors.length)throw new Error(`Draft dependency error: ${value.dependencyErrors[0].message}`);
|
|
872
|
+
const value = await inspect(id);
|
|
873
|
+
if (value.dependencyErrors.length) throw new Error(`Draft dependency error: ${value.dependencyErrors[0].message}`);
|
|
436
874
|
if (value.revision !== revision) throw new Error("Draft revision changed. Review the current draft before accepting.");
|
|
437
875
|
if (value.dependencies.length) throw new Error("Accept dependency drafts first. Dependent previews will automatically use their accepted implementations.");
|
|
438
|
-
if (value.conflicts.length)
|
|
876
|
+
if (value.conflicts.length)
|
|
877
|
+
throw new Error(
|
|
878
|
+
`Draft baseline conflict: accepted source changed outside this draft (${value.conflicts.join(", ")}). Drop the draft and create a new one from current source.`,
|
|
879
|
+
);
|
|
439
880
|
if (!value.changes.length) throw new Error("The draft has no changes to accept. Drop it instead.");
|
|
440
881
|
// The engine receives each owner's proposed files as they are: text as strings, binary as bytes.
|
|
441
|
-
const groups = new Map(),
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
882
|
+
const groups = new Map(),
|
|
883
|
+
add = (unit, file) => groups.set(unit, [...(groups.get(unit) ?? []), file]);
|
|
884
|
+
const proposal = (content) =>
|
|
885
|
+
content === null || content.includes(0) || !Buffer.from(content.toString("utf8")).equals(content) ? content : content.toString("utf8");
|
|
886
|
+
for (const file of value.changes) add(file.unit, { path: file.target, content: proposal(file.content) });
|
|
887
|
+
const plans = value.manifest.units.filter((unit) => groups.has(unit)).map((unit) => ({ unit, files: groups.get(unit) }));
|
|
445
888
|
// Check and render in the draft's preview workspace, served by the project's own host and
|
|
446
889
|
// compiler; a controller without previews lets the engine check its own copy.
|
|
447
890
|
let checkRoot, previewHost;
|
|
448
891
|
if (startPreview) {
|
|
449
892
|
try {
|
|
450
|
-
const { session } = prepare(id);
|
|
451
|
-
if (session.revision === revision) {
|
|
452
|
-
|
|
893
|
+
const { session } = await prepare(id);
|
|
894
|
+
if (session.revision === revision) {
|
|
895
|
+
previewHost = await startSession(id, session);
|
|
896
|
+
checkRoot = session.workspace;
|
|
897
|
+
}
|
|
898
|
+
} catch {
|
|
899
|
+
checkRoot = previewHost = undefined;
|
|
900
|
+
}
|
|
453
901
|
}
|
|
454
|
-
const originals = new Map(value.changes.map(file => [file.target,bytes(safe(root,file.target))]));
|
|
902
|
+
const originals = new Map(value.changes.map((file) => [file.target, bytes(safe(root, file.target))]));
|
|
455
903
|
const abort = new AbortController();
|
|
456
|
-
active = { id, abort };
|
|
904
|
+
active = { id, abort };
|
|
905
|
+
if (!dryRun) event(id, revision, "checking");
|
|
457
906
|
try {
|
|
458
|
-
const result = await edits.apply(
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
907
|
+
const result = await edits.apply(
|
|
908
|
+
{ ...(plans.length === 1 ? plans[0] : { patches: plans }), dryRun, ...(checkRoot ? { checkRoot, previewHost } : {}) },
|
|
909
|
+
signal ? AbortSignal.any([signal, abort.signal]) : abort.signal,
|
|
910
|
+
progress,
|
|
911
|
+
{
|
|
912
|
+
async beforeApply() {
|
|
913
|
+
if ((await inspect(id)).revision !== revision)
|
|
914
|
+
throw new Error("Draft changed during acceptance; no changes were applied. Review and accept the new revision.");
|
|
915
|
+
},
|
|
916
|
+
},
|
|
917
|
+
);
|
|
918
|
+
if (dryRun)
|
|
919
|
+
return {
|
|
920
|
+
...result,
|
|
921
|
+
draft: id,
|
|
922
|
+
revision,
|
|
923
|
+
dryRun: true,
|
|
924
|
+
next: result.ok
|
|
925
|
+
? "Every acceptance check passed on this revision; nothing was written. Accept it with ads_accept and the same revision."
|
|
926
|
+
: "Acceptance would fail. Fix the draft, then check again.",
|
|
927
|
+
};
|
|
462
928
|
let outcome;
|
|
463
|
-
try
|
|
464
|
-
|
|
929
|
+
try {
|
|
930
|
+
outcome = event(id, revision, result.applied ? "applied" : "failed", { diagnostics: result.diagnostics?.slice(0, 3) });
|
|
931
|
+
} catch (error) {
|
|
932
|
+
if (!result.applied) throw error;
|
|
933
|
+
result.warnings = [...(result.warnings ?? []), { rule: "draft-event", message: `Source applied; event storage needs recovery: ${error.message}` }];
|
|
934
|
+
}
|
|
465
935
|
if (result.applied) {
|
|
466
936
|
const updated = [];
|
|
467
|
-
for (const dependent of ids().filter(other => other !== id)) {
|
|
468
|
-
try{
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
937
|
+
for (const dependent of ids().filter((other) => other !== id)) {
|
|
938
|
+
try {
|
|
939
|
+
const manifest = read(dependent);
|
|
940
|
+
if (manifest.dependencies.includes(id)) {
|
|
941
|
+
for (const file of manifest.files)
|
|
942
|
+
if (originals.has(file.target) && file.baseline === fileHash(originals.get(file.target))) {
|
|
943
|
+
const accepted = bytes(safe(root, file.target)),
|
|
944
|
+
source = file.source ? bytes(safe(path.dirname(manifestFile(dependent)), file.source)) : null;
|
|
945
|
+
if (fileHash(source) === file.baseline) {
|
|
946
|
+
file.baseline = fileHash(accepted);
|
|
947
|
+
if (file.source && accepted) atomic(safe(path.dirname(manifestFile(dependent)), file.source), accepted);
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
manifest.dependencies = manifest.dependencies.filter((dependency) => dependency !== id);
|
|
951
|
+
save(manifest);
|
|
952
|
+
updated.push(dependent);
|
|
474
953
|
}
|
|
475
|
-
|
|
954
|
+
} catch (error) {
|
|
955
|
+
result.warnings = [
|
|
956
|
+
...(result.warnings ?? []),
|
|
957
|
+
{ rule: "draft-dependency", message: `Source applied; dependent ${dependent} needs recovery: ${error.message}` },
|
|
958
|
+
];
|
|
476
959
|
}
|
|
477
|
-
}catch(error){result.warnings=[...(result.warnings??[]),{rule:"draft-dependency",message:`Source applied; dependent ${dependent} needs recovery: ${error.message}`}];}
|
|
478
960
|
}
|
|
479
|
-
try
|
|
480
|
-
|
|
961
|
+
try {
|
|
962
|
+
rmSync(path.dirname(manifestFile(id)), { recursive: true });
|
|
963
|
+
await retire(id);
|
|
964
|
+
} catch (error) {
|
|
965
|
+
result.warnings = [
|
|
966
|
+
...(result.warnings ?? []),
|
|
967
|
+
{ rule: "draft-cleanup", message: `Source applied; draft ${id} cleanup needs recovery: ${error.message}` },
|
|
968
|
+
];
|
|
969
|
+
}
|
|
481
970
|
return { ...result, draft: id, revision, event: outcome, updatedDependents: updated };
|
|
482
971
|
}
|
|
483
972
|
return { ...result, draft: id, revision, event: outcome };
|
|
484
|
-
} finally {
|
|
973
|
+
} finally {
|
|
974
|
+
active = undefined;
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
function draftStamp() {
|
|
978
|
+
const rows = [];
|
|
979
|
+
function walk(folder) {
|
|
980
|
+
if (!existsSync(folder)) return;
|
|
981
|
+
for (const entry of readdirSync(folder, { withFileTypes: true })) {
|
|
982
|
+
const file = path.join(folder, entry.name);
|
|
983
|
+
if (entry.isSymbolicLink()) continue;
|
|
984
|
+
if (entry.isDirectory()) walk(file);
|
|
985
|
+
else {
|
|
986
|
+
const stat = lstatSync(file);
|
|
987
|
+
rows.push([file, stat.mtimeMs, stat.ctimeMs, stat.size]);
|
|
988
|
+
}
|
|
989
|
+
if (rows.length > 20000) throw new Error("Too many draft files.");
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
walk(storage);
|
|
993
|
+
if (existsSync(eventFile)) rows.push(bytes(eventFile)?.toString());
|
|
994
|
+
return hash(JSON.stringify(rows));
|
|
485
995
|
}
|
|
486
|
-
function
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
996
|
+
function watchStamp(session) {
|
|
997
|
+
return hash(
|
|
998
|
+
JSON.stringify(
|
|
999
|
+
(session.watchFiles ?? []).map((file) => {
|
|
1000
|
+
try {
|
|
1001
|
+
const stat = lstatSync(file);
|
|
1002
|
+
return [file, stat.mtimeMs, stat.ctimeMs, stat.ino, stat.size];
|
|
1003
|
+
} catch {
|
|
1004
|
+
return [file, null];
|
|
1005
|
+
}
|
|
1006
|
+
}),
|
|
1007
|
+
),
|
|
1008
|
+
);
|
|
490
1009
|
}
|
|
491
|
-
function watchStamp(session){return hash(JSON.stringify((session.watchFiles??[]).map(file=>{try{const stat=lstatSync(file);return[file,stat.mtimeMs,stat.ctimeMs,stat.ino,stat.size];}catch{return[file,null];}})));}
|
|
492
1010
|
// A draft's own edits and the viewed draft resync at once. Other drafts behind an accepted-source
|
|
493
1011
|
// change catch up in the background, one at a time, paused while a draft is being shown; their
|
|
494
1012
|
// rebuilds run last in the compiler's queue.
|
|
495
|
-
function ownStamp(id)
|
|
1013
|
+
function ownStamp(id) {
|
|
1014
|
+
const rows = [];
|
|
1015
|
+
(function walk(folder) {
|
|
1016
|
+
if (!existsSync(folder)) return;
|
|
1017
|
+
for (const entry of readdirSync(folder, { withFileTypes: true })) {
|
|
1018
|
+
const file = path.join(folder, entry.name);
|
|
1019
|
+
if (entry.isSymbolicLink()) continue;
|
|
1020
|
+
if (entry.isDirectory()) walk(file);
|
|
1021
|
+
else {
|
|
1022
|
+
const stat = lstatSync(file);
|
|
1023
|
+
rows.push([file, stat.mtimeMs, stat.size]);
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
1026
|
+
})(path.dirname(manifestFile(id)));
|
|
1027
|
+
return hash(JSON.stringify(rows));
|
|
1028
|
+
}
|
|
496
1029
|
const backlog = new Set();
|
|
497
|
-
let backlogTimer,
|
|
1030
|
+
let backlogTimer,
|
|
1031
|
+
showing = 0;
|
|
498
1032
|
function stale(id, session) {
|
|
499
|
-
let own;
|
|
1033
|
+
let own;
|
|
1034
|
+
try {
|
|
1035
|
+
own = ownStamp(id);
|
|
1036
|
+
} catch {
|
|
1037
|
+
return null;
|
|
1038
|
+
}
|
|
500
1039
|
return session.ownObserved !== own ? "own" : session.acceptedObserved !== watchStamp(session) ? "accepted" : null;
|
|
501
1040
|
}
|
|
502
|
-
function resync(id) {
|
|
503
|
-
|
|
1041
|
+
async function resync(id) {
|
|
1042
|
+
try {
|
|
1043
|
+
await prepare(id);
|
|
1044
|
+
} catch (error) {
|
|
1045
|
+
const session = previews.get(id);
|
|
1046
|
+
if (session) session.error = error.message;
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
1049
|
+
async function syncPreviews() {
|
|
504
1050
|
const order = [...previews.keys()].sort((a, b) => (b === lastShown) - (a === lastShown));
|
|
505
1051
|
for (const id of order) {
|
|
506
1052
|
const reason = stale(id, previews.get(id));
|
|
507
1053
|
if (!reason) continue;
|
|
508
|
-
if (reason === "own" || id === lastShown) {
|
|
509
|
-
|
|
1054
|
+
if (reason === "own" || id === lastShown) {
|
|
1055
|
+
backlog.delete(id);
|
|
1056
|
+
await resync(id);
|
|
1057
|
+
} else backlog.add(id);
|
|
510
1058
|
}
|
|
511
1059
|
drainBacklog();
|
|
512
1060
|
}
|
|
513
1061
|
function drainBacklog() {
|
|
514
1062
|
if (closed || backlogTimer || !backlog.size) return;
|
|
515
|
-
backlogTimer = setTimeout(() => {
|
|
1063
|
+
backlogTimer = setTimeout(async () => {
|
|
516
1064
|
backlogTimer = undefined;
|
|
517
1065
|
if (closed) return;
|
|
518
|
-
if (showing) {
|
|
519
|
-
|
|
1066
|
+
if (showing) {
|
|
1067
|
+
drainBacklog();
|
|
1068
|
+
return;
|
|
1069
|
+
}
|
|
1070
|
+
const [id] = backlog;
|
|
1071
|
+
backlog.delete(id);
|
|
520
1072
|
const session = previews.get(id);
|
|
521
|
-
if (session && stale(id, session)) resync(id);
|
|
1073
|
+
if (session && stale(id, session)) await resync(id);
|
|
522
1074
|
drainBacklog();
|
|
523
1075
|
}, 50);
|
|
524
1076
|
backlogTimer.unref();
|
|
@@ -526,9 +1078,11 @@ export function createDraftController(directory, { edits, startPreview, prewarm
|
|
|
526
1078
|
function changed() {
|
|
527
1079
|
if (closed) return;
|
|
528
1080
|
clearTimeout(changeTimer);
|
|
529
|
-
changeTimer = setTimeout(() => {
|
|
1081
|
+
changeTimer = setTimeout(async () => {
|
|
530
1082
|
if (closed) return;
|
|
531
|
-
reconcileWatches();
|
|
1083
|
+
reconcileWatches();
|
|
1084
|
+
await syncPreviews();
|
|
1085
|
+
onChange?.();
|
|
532
1086
|
}, 16);
|
|
533
1087
|
changeTimer.unref();
|
|
534
1088
|
}
|
|
@@ -538,62 +1092,130 @@ export function createDraftController(directory, { edits, startPreview, prewarm
|
|
|
538
1092
|
function draftDirectories(folder) {
|
|
539
1093
|
if (!existsSync(folder) || realpathSync(folder) !== folder) return;
|
|
540
1094
|
wanted.add(folder);
|
|
541
|
-
for (const entry of readdirSync(folder, { withFileTypes: true }))
|
|
1095
|
+
for (const entry of readdirSync(folder, { withFileTypes: true }))
|
|
1096
|
+
if (entry.isDirectory() && !entry.isSymbolicLink()) draftDirectories(path.join(folder, entry.name));
|
|
542
1097
|
}
|
|
543
1098
|
try {
|
|
544
1099
|
draftDirectories(storage);
|
|
545
1100
|
const options = loadConfig(root);
|
|
546
1101
|
if (previews.size) for (const folder of previewWatchDirectories(options)) wanted.add(folder);
|
|
547
1102
|
for (const folder of wanted) {
|
|
548
|
-
const stat = lstatSync(folder),
|
|
1103
|
+
const stat = lstatSync(folder),
|
|
1104
|
+
identity = `${stat.dev}:${stat.ino}`;
|
|
549
1105
|
if (watchers.get(folder)?.identity === identity) continue;
|
|
550
1106
|
watchers.get(folder)?.watcher.close();
|
|
551
1107
|
const watcher = watch(folder, (event, file) => {
|
|
552
1108
|
if (!file) return;
|
|
553
1109
|
const target = path.join(folder, String(file));
|
|
554
1110
|
if (!isInside(storage, target) && previewFileIgnored(options, target)) return;
|
|
555
|
-
if (
|
|
1111
|
+
if (
|
|
1112
|
+
isInside(storage, target) ||
|
|
1113
|
+
event === "rename" ||
|
|
1114
|
+
/\.(?:[cm]?[jt]sx?|css|html|json|md|svg|png|jpe?g|webp|gif|woff2?|ttf|otf|lock|lockb)$/.test(target)
|
|
1115
|
+
)
|
|
1116
|
+
changed();
|
|
1117
|
+
});
|
|
1118
|
+
watcher.unref();
|
|
1119
|
+
watcher.on("error", () => {
|
|
1120
|
+
watcher.close();
|
|
1121
|
+
watchers.delete(folder);
|
|
556
1122
|
});
|
|
557
|
-
watcher.unref(); watcher.on("error", () => { watcher.close(); watchers.delete(folder); });
|
|
558
1123
|
watchers.set(folder, { identity, watcher });
|
|
559
1124
|
}
|
|
560
|
-
for (const [folder, item] of watchers)
|
|
561
|
-
|
|
1125
|
+
for (const [folder, item] of watchers)
|
|
1126
|
+
if (!wanted.has(folder) || !existsSync(folder)) {
|
|
1127
|
+
item.watcher.close();
|
|
1128
|
+
watchers.delete(folder);
|
|
1129
|
+
}
|
|
1130
|
+
} catch {
|
|
1131
|
+
/* Reconciliation retries removed/replaced directories. */
|
|
1132
|
+
}
|
|
562
1133
|
}
|
|
563
|
-
const timer = setInterval(() => {
|
|
1134
|
+
const timer = setInterval(async () => {
|
|
1135
|
+
if (!closed) {
|
|
1136
|
+
reconcileWatches();
|
|
1137
|
+
await syncPreviews();
|
|
1138
|
+
}
|
|
1139
|
+
}, 5000);
|
|
564
1140
|
timer.unref();
|
|
565
|
-
const generated=path.join(root,".ds/draft-previews");
|
|
566
|
-
if(existsSync(generated)&&realpathSync(generated)===
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
1141
|
+
const generated = path.join(root, ".ds/draft-previews");
|
|
1142
|
+
if (existsSync(generated) && realpathSync(generated) === generated)
|
|
1143
|
+
for (const entry of readdirSync(generated, { withFileTypes: true })) {
|
|
1144
|
+
if (entry.isDirectory() && !entry.isSymbolicLink() && /\.retired-[a-f0-9-]{36}$/.test(entry.name)) {
|
|
1145
|
+
rmSync(path.join(generated, entry.name), { recursive: true, force: true });
|
|
1146
|
+
continue;
|
|
1147
|
+
}
|
|
1148
|
+
if (entry.isDirectory() && !entry.isSymbolicLink() && idSchema.safeParse(entry.name).success && !existsSync(manifestFile(entry.name)))
|
|
1149
|
+
rmSync(previewDirectory(entry.name), { recursive: true, force: true });
|
|
1150
|
+
}
|
|
570
1151
|
reconcileWatches();
|
|
571
|
-
return {
|
|
1152
|
+
return {
|
|
1153
|
+
list,
|
|
1154
|
+
create,
|
|
1155
|
+
update,
|
|
1156
|
+
show,
|
|
1157
|
+
drop,
|
|
1158
|
+
accept,
|
|
1159
|
+
prepare,
|
|
1160
|
+
events,
|
|
1161
|
+
inspect,
|
|
1162
|
+
tokenGroups,
|
|
572
1163
|
previewStatuses: () => [...previews].map(([id, session]) => ({ id, revision: session.revision, ...previewStatus(id) })),
|
|
573
|
-
readFile(file,{offset=0,limit=12000}={}){
|
|
574
|
-
const parts=file.split("/");
|
|
575
|
-
if(parts[0]!==DRAFT_DIRECTORY||parts.length<3)throw new Error("Use a tracked draft path from ads_drafts.");
|
|
576
|
-
const manifest=read(parts[1]),
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
const
|
|
582
|
-
if(
|
|
583
|
-
|
|
1164
|
+
readFile(file, { offset = 0, limit = 12000 } = {}) {
|
|
1165
|
+
const parts = file.split("/");
|
|
1166
|
+
if (parts[0] !== DRAFT_DIRECTORY || parts.length < 3) throw new Error("Use a tracked draft path from ads_drafts.");
|
|
1167
|
+
const manifest = read(parts[1]),
|
|
1168
|
+
folder = path.dirname(manifestFile(parts[1]));
|
|
1169
|
+
const mapping = manifest.files.find((entry) => entry.source === parts.slice(2).join("/"));
|
|
1170
|
+
if (!mapping && parts.slice(2).join("/") !== "proposal.ads.draft.json")
|
|
1171
|
+
throw new Error("Draft reads are limited to the manifest and registered source files.");
|
|
1172
|
+
const content = bytes(safe(folder, parts.slice(2).join("/")));
|
|
1173
|
+
if (content === null) throw new Error("Draft source is missing.");
|
|
1174
|
+
const binary = content.includes(0) || !Buffer.from(content.toString("utf8")).equals(content),
|
|
1175
|
+
text = content.toString("utf8"),
|
|
1176
|
+
end = offset + limit;
|
|
1177
|
+
if (!Number.isSafeInteger(offset) || offset < 0 || offset > text.length || !Number.isSafeInteger(limit) || limit < 1 || limit > 12000)
|
|
1178
|
+
throw new Error("Invalid draft read range.");
|
|
1179
|
+
return {
|
|
1180
|
+
path: file,
|
|
1181
|
+
draft: parts[1],
|
|
1182
|
+
unit: mapping?.unit ?? null,
|
|
1183
|
+
digest: `sha256:${hash(content)}`,
|
|
1184
|
+
bytes: content.length,
|
|
1185
|
+
binary,
|
|
1186
|
+
content: binary ? null : text.slice(offset, end),
|
|
1187
|
+
offset,
|
|
1188
|
+
nextOffset: !binary && end < text.length ? end : null,
|
|
1189
|
+
totalChars: binary ? null : text.length,
|
|
1190
|
+
startLine: text.slice(0, offset).split("\n").length,
|
|
1191
|
+
};
|
|
584
1192
|
},
|
|
585
|
-
async readResource(id,uri,signal){
|
|
586
|
-
const session=previews.get(id);
|
|
587
|
-
if(session?.error)throw new Error(`Draft preview is stale: ${session.error}`);
|
|
588
|
-
if(uri==="ads://project/scenarios"&&session?.registry){
|
|
589
|
-
prepare(id);
|
|
590
|
-
session.registry=await discovery.current(session.workspace,session.revision);
|
|
591
|
-
return{contents:[{uri,mimeType:"application/json",text:JSON.stringify(session.registry)}]};
|
|
1193
|
+
async readResource(id, uri, signal) {
|
|
1194
|
+
const session = previews.get(id);
|
|
1195
|
+
if (session?.error) throw new Error(`Draft preview is stale: ${session.error}`);
|
|
1196
|
+
if (uri === "ads://project/scenarios" && session?.registry) {
|
|
1197
|
+
await prepare(id);
|
|
1198
|
+
session.registry = await discovery.current(session.workspace, session.revision);
|
|
1199
|
+
return { contents: [{ uri, mimeType: "application/json", text: JSON.stringify(session.registry) }] };
|
|
592
1200
|
}
|
|
593
|
-
if(!session?.starting)throw new Error("Draft preview is not active. Reopen ads_show_draft.");
|
|
594
|
-
await session.starting;
|
|
1201
|
+
if (!session?.starting) throw new Error("Draft preview is not active. Reopen ads_show_draft.");
|
|
1202
|
+
await session.starting;
|
|
1203
|
+
return session.runtime.readResource(uri, signal);
|
|
1204
|
+
},
|
|
1205
|
+
fingerprint: () => `${draftStamp()}:${discoveryVersion}`,
|
|
1206
|
+
async close() {
|
|
1207
|
+
closed = true;
|
|
1208
|
+
clearInterval(timer);
|
|
1209
|
+
clearTimeout(backlogTimer);
|
|
1210
|
+
backlog.clear();
|
|
1211
|
+
clearTimeout(changeTimer);
|
|
1212
|
+
clearTimeout(prewarmTimer);
|
|
1213
|
+
pendingPrewarm = undefined;
|
|
1214
|
+
for (const { watcher } of watchers.values()) watcher.close();
|
|
1215
|
+
watchers.clear();
|
|
1216
|
+
active?.abort.abort();
|
|
1217
|
+
await Promise.allSettled([discovery.close(), ...(await mapAsync([...previews.keys()], retire))]);
|
|
1218
|
+
await prewarming;
|
|
595
1219
|
},
|
|
596
|
-
fingerprint:()=>`${draftStamp()}:${discoveryVersion}`,
|
|
597
|
-
async close() { closed = true; clearInterval(timer); clearTimeout(backlogTimer); backlog.clear(); clearTimeout(changeTimer); clearTimeout(prewarmTimer); pendingPrewarm = undefined; for (const { watcher } of watchers.values()) watcher.close(); watchers.clear(); active?.abort.abort(); await Promise.allSettled([discovery.close(), ...[...previews.keys()].map(retire)]); await prewarming; },
|
|
598
1220
|
};
|
|
599
1221
|
}
|