@reqvire-org/ads 0.4.0 → 0.4.2
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 +105 -86
- package/dist/a11y.mjs +108 -29
- 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 +140 -0
- package/dist/analysis/impact.mjs +20 -0
- package/dist/analysis/inputs.mjs +15 -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 +146 -0
- package/dist/analysis/standalone.mjs +57 -0
- package/dist/analysis/syntax.mjs +164 -0
- package/dist/analysis/worker.mjs +182 -0
- package/dist/assets.mjs +5 -5
- 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 +135 -38
- 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 +40 -57
- package/dist/check.mjs +749 -188
- package/dist/cli.mjs +200 -99
- package/dist/color-values.mjs +21 -21
- package/dist/component-contrast.mjs +2 -2
- package/dist/config.mjs +303 -135
- package/dist/construction-styles.cjs +10 -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 +7 -5
- package/dist/font-rules.mjs +2 -2
- package/dist/fonts-generated.mjs +2 -2
- package/dist/foundation-views.mjs +238 -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 +109 -36
- 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 +901 -281
- package/dist/mcp/execution-coordinator.mjs +417 -167
- package/dist/mcp/execution-results.mjs +7 -7
- package/dist/mcp/mutations.mjs +670 -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 +2402 -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/preview-bun.mjs +493 -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 +2 -2
- 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/{browser-audit → render-audit}/render-states.mjs +208 -52
- package/dist/{browser-audit → render-audit}/worker.mjs +86 -30
- package/dist/render-audit.mjs +828 -0
- package/dist/render-color-probe.mjs +96 -42
- 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 +18 -0
- package/dist/showcase/favicon.ico +0 -0
- package/dist/showcase/favicon.svg +1 -0
- package/dist/showcase/foundation-view.css +55 -0
- package/dist/showcase/foundation-view.mjs +252 -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/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 +1062 -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 +130 -119
- package/dist/skills/ads-designer/references/accessibility.md +12 -13
- 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 +98 -10
- 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/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 +54 -343
- 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 +266 -128
- 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/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/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 +208 -98
- package/dist/usage.mjs +138 -38
- package/dist/validation-checks.mjs +115 -38
- package/dist/validation-inputs.mjs +187 -78
- package/dist/validation.mjs +268 -102
- package/dist/verification/browser.mjs +27 -5
- package/dist/verification.mjs +711 -187
- package/docs/ADS.md +90 -79
- package/docs/ARCHITECTURE.md +294 -136
- package/docs/BEHAVIORS.md +29 -25
- package/docs/CACHING.md +52 -17
- package/docs/CHANGELOG.md +309 -17
- package/docs/CONTRACTS.md +12 -4
- package/docs/DESIGN-REFERENCES.md +40 -0
- package/docs/GUIDE.md +270 -258
- package/docs/MCP.md +181 -324
- package/docs/SPATIAL-CHECKS.md +69 -0
- package/docs/benchmarks/README.md +39 -0
- package/package.json +42 -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,492 @@ 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
|
-
const value = inspect(id);
|
|
270
|
-
if(value.dependencyErrors.length)throw new Error(`Draft dependency error: ${value.dependencyErrors[0].message}`);
|
|
527
|
+
async function prepare(id) {
|
|
528
|
+
const value = await inspect(id);
|
|
529
|
+
if (value.dependencyErrors.length) throw new Error(`Draft dependency error: ${value.dependencyErrors[0].message}`);
|
|
271
530
|
if (value.conflicts.length) throw new Error(`Draft baseline conflict: ${value.conflicts.join(", ")}`);
|
|
272
531
|
let session = previews.get(id);
|
|
273
532
|
if (!session) {
|
|
274
533
|
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});
|
|
534
|
+
const directory = path.dirname(workspace);
|
|
535
|
+
if (existsSync(directory) && realpathSync(directory) !== directory) throw new Error("Draft preview storage cannot be a symlink.");
|
|
536
|
+
rmSync(directory, { recursive: true, force: true });
|
|
278
537
|
mkdirSync(workspace, { recursive: true });
|
|
279
538
|
if (realpathSync(workspace) !== workspace) throw new Error("Draft preview workspace cannot be a symlink.");
|
|
280
|
-
session = { workspace, inputs: new Map() };
|
|
539
|
+
session = { workspace, inputs: new Map() };
|
|
540
|
+
previews.set(id, session);
|
|
541
|
+
reconcileWatches();
|
|
281
542
|
}
|
|
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
|
|
543
|
+
if (session.revision && !existsSync(path.join(session.workspace, ".ds/draft-preview.json"))) session.recovering = true;
|
|
544
|
+
mkdirSync(session.workspace, { recursive: true });
|
|
545
|
+
if (realpathSync(session.workspace) !== session.workspace) throw new Error("Draft preview workspace cannot be a symlink.");
|
|
546
|
+
const captured = new Map();
|
|
547
|
+
const inputs = await validationInputFiles(loadConfig(root), [], { onFile: (file, content) => captured.set(file, content) }),
|
|
548
|
+
desired = new Map();
|
|
549
|
+
const baseline = new Map([...captured].filter(([file]) => isAnalysisSource(file)).map(([file, content]) => [file, content.toString("utf8")]));
|
|
286
550
|
let size = 0;
|
|
287
|
-
for (const [target, digest] of Object.entries(inputs))
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
551
|
+
for (const [target, digest] of Object.entries(inputs))
|
|
552
|
+
if (digest && target !== "installed-dependencies") {
|
|
553
|
+
const content = captured.get(target);
|
|
554
|
+
if (content !== null) {
|
|
555
|
+
desired.set(target, content);
|
|
556
|
+
size += content.length;
|
|
557
|
+
}
|
|
558
|
+
if (desired.size > 100000 || size > 2 * 1024 ** 3) throw new Error("Draft preview input limit exceeded.");
|
|
559
|
+
}
|
|
292
560
|
const applied = new Map();
|
|
293
561
|
function overlay(proposal) {
|
|
294
562
|
if (proposal.conflicts.length) throw new Error(`Dependency draft conflict: ${proposal.conflicts.join(", ")}`);
|
|
295
563
|
for (const dependency of proposal.dependencies) overlay(dependency);
|
|
296
564
|
for (const file of proposal.changes) {
|
|
297
565
|
const digest = fileHash(file.content);
|
|
298
|
-
if (applied.has(file.target) && applied.get(file.target) !== digest)
|
|
566
|
+
if (applied.has(file.target) && applied.get(file.target) !== digest)
|
|
567
|
+
throw new Error(`Drafts both change ${file.target}; use one coupled draft for overlapping edits.`);
|
|
299
568
|
applied.set(file.target, digest);
|
|
300
|
-
if (file.content === null) desired.delete(file.target);
|
|
569
|
+
if (file.content === null) desired.delete(file.target);
|
|
570
|
+
else desired.set(file.target, file.content);
|
|
301
571
|
}
|
|
302
572
|
}
|
|
303
573
|
overlay(value);
|
|
304
574
|
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)
|
|
575
|
+
for (const [target, content] of desired)
|
|
576
|
+
if (session.inputs.get(target) !== hash(content) || !existsSync(safe(session.workspace, target))) atomic(safe(session.workspace, target), content);
|
|
306
577
|
session.inputs = new Map([...desired].map(([target, content]) => [target, hash(content)]));
|
|
307
578
|
// 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
|
-
|
|
579
|
+
|
|
580
|
+
const key = hash(JSON.stringify([...session.inputs]));
|
|
581
|
+
if (session.themeKey !== key) {
|
|
582
|
+
session.themeKey = key;
|
|
583
|
+
const register = async () => {
|
|
584
|
+
const sources = new Map([...desired].filter(([file]) => isAnalysisSource(file)).map(([file, content]) => [file, content.toString("utf8")]));
|
|
585
|
+
const changes = [...new Set([...baseline.keys(), ...sources.keys()])]
|
|
586
|
+
.filter((file) => baseline.get(file) !== sources.get(file))
|
|
587
|
+
.map((file) => [file, sources.get(file) ?? null]);
|
|
588
|
+
await registerAnalysisRevision(root, session.workspace, baseline, changes, inputs["installed-dependencies"] ?? "");
|
|
589
|
+
};
|
|
590
|
+
// Defer the request until dependencies and generated entries below exist.
|
|
591
|
+
session.themeTask = Promise.resolve()
|
|
592
|
+
.then(async () => {
|
|
593
|
+
if (closed || previews.get(id) !== session || session.themeKey !== key) return;
|
|
594
|
+
for (const generated of (await writeGeneratedEntries(loadConfig(session.workspace))).files)
|
|
595
|
+
desired.set(path.relative(session.workspace, generated.file), Buffer.from(generated.text));
|
|
596
|
+
await register();
|
|
597
|
+
const tokens = await analyze(session.workspace, "tokens");
|
|
598
|
+
if (!closed && previews.get(id) === session && session.themeKey === key) {
|
|
599
|
+
const options = loadConfig(session.workspace);
|
|
600
|
+
for (const generated of [...writeThemesCss(options, tokens).files, ...(await writeGeneratedEntries(options)).files]) {
|
|
601
|
+
if (generated.text !== undefined) desired.set(path.relative(session.workspace, generated.file), Buffer.from(generated.text));
|
|
602
|
+
}
|
|
603
|
+
await register();
|
|
604
|
+
}
|
|
605
|
+
})
|
|
606
|
+
.catch(async () => {
|
|
607
|
+
if (session.themeKey === key) {
|
|
608
|
+
session.themeKey = undefined;
|
|
609
|
+
await releaseAnalysisRevision(session.workspace).catch(() => {});
|
|
610
|
+
}
|
|
611
|
+
// Acceptance reports broken tokens; discovery can recover independently.
|
|
612
|
+
});
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
try {
|
|
616
|
+
await writeGeneratedEntries(loadConfig(session.workspace));
|
|
617
|
+
} catch {
|
|
618
|
+
/* Acceptance checks report broken exports files. */
|
|
619
|
+
}
|
|
310
620
|
const modules = path.join(session.workspace, "node_modules");
|
|
311
|
-
if (!existsSync(modules) && existsSync(path.join(root, "node_modules")))
|
|
621
|
+
if (!existsSync(modules) && existsSync(path.join(root, "node_modules")))
|
|
622
|
+
symlinkSync(realpathSync(path.join(root, "node_modules")), modules, process.platform === "win32" ? "junction" : "dir");
|
|
312
623
|
if (!existsSync(path.join(session.workspace, "dist")) && existsSync(path.join(root, "dist/cli.mjs"))) {
|
|
313
|
-
let count=0,
|
|
314
|
-
|
|
624
|
+
let count = 0,
|
|
625
|
+
total = 0;
|
|
626
|
+
cpSync(path.join(root, "dist"), path.join(session.workspace, "dist"), {
|
|
627
|
+
recursive: true,
|
|
628
|
+
filter(file) {
|
|
629
|
+
const stat = lstatSync(file);
|
|
630
|
+
if (stat.isSymbolicLink()) throw new Error("Generated runtime copies cannot contain symlinks.");
|
|
631
|
+
if (stat.isFile()) {
|
|
632
|
+
count++;
|
|
633
|
+
total += stat.size;
|
|
634
|
+
}
|
|
635
|
+
if (count > 100000 || total > 2 * 1024 ** 3) throw new Error("Generated runtime exceeds the preview limit.");
|
|
636
|
+
return true;
|
|
637
|
+
},
|
|
638
|
+
});
|
|
315
639
|
}
|
|
316
640
|
atomic(path.join(session.workspace, ".ds/draft-preview.json"), JSON.stringify({ previewOnly: true }));
|
|
317
641
|
if (session.revision && session.revision !== value.revision && session.runtime && session.build?.scenarios.length) {
|
|
318
642
|
const before = previewStatus(id);
|
|
319
|
-
session.build = {
|
|
320
|
-
|
|
643
|
+
session.build = {
|
|
644
|
+
...before,
|
|
645
|
+
state: "queued",
|
|
646
|
+
building: true,
|
|
647
|
+
current: false,
|
|
648
|
+
stale: true,
|
|
649
|
+
scenarios: before.scenarios.map((item) => ({ ...item, state: "queued", building: true, current: false, stale: true })),
|
|
650
|
+
};
|
|
321
651
|
}
|
|
322
652
|
session.revision = value.revision;
|
|
323
653
|
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)){
|
|
654
|
+
session.error = undefined;
|
|
655
|
+
const watched = new Set();
|
|
656
|
+
for (const target of Object.keys(inputs)) {
|
|
657
|
+
let file = target === "installed-dependencies" ? path.join(root, "node_modules/.package-lock.json") : path.join(root, target);
|
|
658
|
+
while (isInside(root, file)) {
|
|
659
|
+
watched.add(file);
|
|
660
|
+
if (file === root) break;
|
|
661
|
+
file = path.dirname(file);
|
|
662
|
+
}
|
|
329
663
|
}
|
|
330
|
-
session.watchFiles=[...watched];
|
|
664
|
+
session.watchFiles = [...watched];
|
|
665
|
+
session.ownObserved = ownStamp(id);
|
|
666
|
+
session.acceptedObserved = watchStamp(session);
|
|
331
667
|
return { ...value, session };
|
|
332
668
|
}
|
|
333
669
|
async function show(args, signal) {
|
|
334
670
|
++showing;
|
|
335
|
-
try {
|
|
671
|
+
try {
|
|
672
|
+
return await showDraft(args, signal);
|
|
673
|
+
} finally {
|
|
674
|
+
--showing;
|
|
675
|
+
}
|
|
336
676
|
}
|
|
337
677
|
async function showDraft({ id, scenario }, signal) {
|
|
338
678
|
if (signal?.aborted) throw new Error("Draft preview request cancelled.");
|
|
339
679
|
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
|
|
680
|
+
const existing = previews.get(id);
|
|
681
|
+
if (existing && (existing.recovering || !existsSync(path.join(existing.workspace, ".ds/draft-preview.json")))) await retire(id);
|
|
682
|
+
if (!previews.has(id) && [...previews.values()].filter((session) => session.starting).length >= 4) {
|
|
683
|
+
const oldest = [...previews].find(([, session]) => session.starting);
|
|
684
|
+
if (oldest) await retire(oldest[0]);
|
|
685
|
+
}
|
|
686
|
+
const value = await prepare(id),
|
|
687
|
+
{ session } = value;
|
|
688
|
+
await session.themeTask;
|
|
689
|
+
session.opened = true;
|
|
690
|
+
lastShown = id;
|
|
691
|
+
const options = loadConfig(session.workspace),
|
|
692
|
+
units = await inspectUnits(options);
|
|
693
|
+
const metadata = await discovery.refresh(session.workspace, value.revision);
|
|
347
694
|
let registry = metadata.registry;
|
|
348
|
-
const known = scenario
|
|
349
|
-
|
|
350
|
-
|
|
695
|
+
const known = scenario
|
|
696
|
+
? registry?.scenarios.find((item) => item.id === scenario)
|
|
697
|
+
: registry?.scenarios.find((item) => value.manifest.units.includes(units.owner(units.relative(item.file))));
|
|
698
|
+
if (!registry || !known || !existsSync(path.join(session.workspace, known.file)) || registry.diagnostics.length)
|
|
699
|
+
registry = await discovery.current(session.workspace, value.revision);
|
|
351
700
|
const metadataRevision = metadata.revision;
|
|
352
|
-
const diagnosticsUri
|
|
353
|
-
session.registry=registry;
|
|
354
|
-
if(registry.diagnostics.length) {
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
701
|
+
const diagnosticsUri = `ads://drafts/${id}/resource?uri=${encodeURIComponent("ads://project/scenarios")}`;
|
|
702
|
+
session.registry = registry;
|
|
703
|
+
if (registry.diagnostics.length) {
|
|
704
|
+
session.build = {
|
|
705
|
+
state: "error",
|
|
706
|
+
building: false,
|
|
707
|
+
current: false,
|
|
708
|
+
stale: true,
|
|
709
|
+
scenarios: [],
|
|
710
|
+
diagnosticCount: registry.diagnostics.length,
|
|
711
|
+
resourceUri: scopedBuild(id),
|
|
712
|
+
};
|
|
713
|
+
++discoveryVersion;
|
|
714
|
+
onChange?.();
|
|
715
|
+
return {
|
|
716
|
+
...summary(value),
|
|
717
|
+
ok: false,
|
|
718
|
+
diagnostics: registry.diagnostics,
|
|
719
|
+
diagnosticsUri,
|
|
720
|
+
previewOnly: true,
|
|
721
|
+
next: "Fix these diagnostics in this draft's source. The accepted project registry is separate. Reopen ads_show_draft after editing.",
|
|
722
|
+
};
|
|
723
|
+
}
|
|
724
|
+
const scenarios = registry.scenarios.map(({ id, title, kind, group, file }) => ({
|
|
725
|
+
id,
|
|
726
|
+
title,
|
|
727
|
+
kind,
|
|
728
|
+
...(group ? { group } : {}),
|
|
729
|
+
unit: units.owner(units.relative(file)),
|
|
730
|
+
}));
|
|
731
|
+
const owned = scenarios.find((item) => value.manifest.units.includes(item.unit))?.id;
|
|
732
|
+
if (!scenario && !owned && value.manifest.units.some((unit) => /^(?:components|patterns|composition)\//.test(unit)))
|
|
733
|
+
throw new Error("Draft has no independently mountable owner scenario yet. Add its scenario/fixture or select an explicit existing context scenario.");
|
|
360
734
|
const selected = scenario ?? owned ?? registry.scenarios[0]?.id;
|
|
361
735
|
session.selected = selected;
|
|
362
|
-
if (scenario && !registry.scenarios.some(item => item.id === scenario))
|
|
736
|
+
if (scenario && !registry.scenarios.some((item) => item.id === scenario))
|
|
737
|
+
throw new Error("Unknown draft scenario. Read ads_show_draft without scenario to discover it.");
|
|
363
738
|
await startSession(id, session);
|
|
364
739
|
if (signal?.aborted) throw new Error("Draft preview request cancelled.");
|
|
365
740
|
if (metadata.revision === value.revision) session.runtime.primeRegistry?.(registry);
|
|
366
|
-
const url = new URL(session.runtime.url);
|
|
741
|
+
const url = new URL(session.runtime.url);
|
|
742
|
+
if (selected) url.searchParams.set("scenario", selected);
|
|
367
743
|
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
|
-
|
|
744
|
+
const acceptedExists = accepted.scenarios.some((item) => item.id === selected);
|
|
745
|
+
const previewResult =
|
|
746
|
+
selected && session.runtime.callTool ? await session.runtime.callTool("ads_show_scenario", { id: selected, waitFor: "compiled" }, signal) : undefined;
|
|
747
|
+
if (session.runtime.buildStatus) recordBuild(id, session, await session.runtime.buildStatus());
|
|
748
|
+
if (previewResult?.isError) {
|
|
749
|
+
registry = await discovery.current(session.workspace, value.revision);
|
|
750
|
+
session.registry = registry;
|
|
751
|
+
const diagnostics = registry.diagnostics.length
|
|
752
|
+
? registry.diagnostics
|
|
753
|
+
: [{ rule: "draft-preview", message: previewResult.content?.find((item) => item.type === "text")?.text ?? "Draft preview compilation failed." }];
|
|
754
|
+
return {
|
|
755
|
+
...summary(value),
|
|
756
|
+
ok: false,
|
|
757
|
+
scenario: selected,
|
|
758
|
+
diagnostics,
|
|
759
|
+
diagnosticsUri,
|
|
760
|
+
previewOnly: true,
|
|
761
|
+
previewResult,
|
|
762
|
+
next: "Fix the draft-private preview errors, then reopen this draft. Accepted source has not changed.",
|
|
763
|
+
};
|
|
376
764
|
}
|
|
377
|
-
return {
|
|
765
|
+
return {
|
|
766
|
+
...summary(value),
|
|
767
|
+
scenario: selected,
|
|
768
|
+
scenarios,
|
|
769
|
+
diagnostics: registry.diagnostics,
|
|
770
|
+
diagnosticsUri,
|
|
771
|
+
discovery: discovery.status(metadata, metadataRevision),
|
|
772
|
+
build: previewResult?.structuredContent?.build ?? previewStatus(id),
|
|
773
|
+
showcaseUrl: url.href,
|
|
774
|
+
acceptedExists,
|
|
775
|
+
previewOnly: true,
|
|
776
|
+
previewResult,
|
|
777
|
+
draftScope: `ads://drafts/${id}/resource?uri=`,
|
|
778
|
+
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.",
|
|
779
|
+
};
|
|
378
780
|
}
|
|
379
781
|
async function startSession(id, session) {
|
|
782
|
+
await session.themeTask;
|
|
380
783
|
session.starting ??= (async () => {
|
|
381
|
-
if ([...previews.values()].filter(item => item !== session && item.starting).length >= 4) {
|
|
784
|
+
if ([...previews.values()].filter((item) => item !== session && item.starting).length >= 4) {
|
|
382
785
|
const oldest = [...previews].find(([other, item]) => other !== id && item.starting);
|
|
383
786
|
if (oldest) await retire(oldest[0]);
|
|
384
787
|
}
|
|
385
788
|
if (closed || previews.get(id) !== session) throw new Error("Draft preview was closed before startup.");
|
|
386
789
|
const runtime = await startPreview(session.workspace, id);
|
|
387
|
-
if (closed || previews.get(id) !== session) {
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
790
|
+
if (closed || previews.get(id) !== session) {
|
|
791
|
+
await runtime.close();
|
|
792
|
+
throw new Error("Draft preview startup was cancelled.");
|
|
793
|
+
}
|
|
794
|
+
session.unsubscribeBuild = runtime.onBuildChange?.((report) => recordBuild(id, session, report));
|
|
795
|
+
return (session.runtime = runtime);
|
|
796
|
+
})().catch((error) => {
|
|
797
|
+
session.starting = undefined;
|
|
798
|
+
throw error;
|
|
799
|
+
});
|
|
391
800
|
return session.starting;
|
|
392
801
|
}
|
|
393
802
|
async function retire(id) {
|
|
394
|
-
const session=previews.get(id),
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
803
|
+
const session = previews.get(id),
|
|
804
|
+
workspace = path.join(previewDirectory(id), "project");
|
|
805
|
+
previews.delete(id);
|
|
806
|
+
discovery.remove(workspace);
|
|
807
|
+
if (session) {
|
|
808
|
+
try {
|
|
809
|
+
await session.themeTask;
|
|
810
|
+
await session.starting;
|
|
811
|
+
} catch {
|
|
812
|
+
/* Failed startup remains disposable. */
|
|
813
|
+
}
|
|
814
|
+
session.unsubscribeBuild?.();
|
|
815
|
+
await session.runtime?.close();
|
|
816
|
+
}
|
|
817
|
+
await releaseAnalysisRevision(workspace).catch(() => {});
|
|
818
|
+
if (previews.has(id)) return;
|
|
398
819
|
// 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
|
-
|
|
820
|
+
const directory = path.dirname(workspace),
|
|
821
|
+
retired = `${directory}.retired-${randomUUID()}`;
|
|
822
|
+
try {
|
|
823
|
+
renameSync(directory, retired);
|
|
824
|
+
} catch {
|
|
825
|
+
rmSync(directory, { recursive: true, force: true });
|
|
826
|
+
return;
|
|
827
|
+
}
|
|
828
|
+
rmSync(retired, { recursive: true, force: true });
|
|
402
829
|
}
|
|
403
830
|
function queuePrewarm(id) {
|
|
404
|
-
if (!prewarm || !startPreview || !loadConfig(root).config.
|
|
831
|
+
if (!prewarm || !startPreview || !loadConfig(root).config.framework) return;
|
|
405
832
|
pendingPrewarm = id;
|
|
406
833
|
clearTimeout(prewarmTimer);
|
|
407
|
-
prewarmTimer = setTimeout(warmNext, 50);
|
|
834
|
+
prewarmTimer = setTimeout(warmNext, 50);
|
|
835
|
+
prewarmTimer.unref();
|
|
408
836
|
}
|
|
409
|
-
function warmNext() {
|
|
837
|
+
async function warmNext() {
|
|
410
838
|
if (closed || prewarming || !pendingPrewarm) return;
|
|
411
|
-
const id = pendingPrewarm;
|
|
839
|
+
const id = pendingPrewarm;
|
|
840
|
+
pendingPrewarm = undefined;
|
|
412
841
|
prewarming = (async () => {
|
|
413
842
|
if (!existsSync(manifestFile(id))) return;
|
|
414
843
|
for (const [other, session] of previews) if (other !== id && session.prewarmed && !session.opened) await retire(other);
|
|
415
|
-
const { session } = prepare(id);
|
|
844
|
+
const { session } = await prepare(id);
|
|
416
845
|
session.prewarmed = true;
|
|
417
846
|
await startSession(id, session);
|
|
418
847
|
await session.runtime.prewarm?.();
|
|
419
|
-
})()
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
848
|
+
})()
|
|
849
|
+
.catch(() => {
|
|
850
|
+
/* A malformed/incomplete draft can be edited and retried through show(). */
|
|
851
|
+
})
|
|
852
|
+
.finally(() => {
|
|
853
|
+
prewarming = undefined;
|
|
854
|
+
if (!closed && pendingPrewarm) {
|
|
855
|
+
prewarmTimer = setTimeout(warmNext, 0);
|
|
856
|
+
prewarmTimer.unref();
|
|
857
|
+
}
|
|
858
|
+
});
|
|
423
859
|
}
|
|
424
860
|
async function drop({ id, revision }) {
|
|
425
861
|
if (active) throw new Error("Wait for acceptance before dropping a draft.");
|
|
426
|
-
const value = inspect(id);
|
|
862
|
+
const value = await inspect(id);
|
|
427
863
|
if (revision !== value.revision) throw new Error("Draft revision changed; read ads_drafts again.");
|
|
428
864
|
await retire(id);
|
|
429
865
|
rmSync(path.dirname(manifestFile(id)), { recursive: true });
|
|
@@ -431,94 +867,208 @@ export function createDraftController(directory, { edits, startPreview, prewarm
|
|
|
431
867
|
}
|
|
432
868
|
async function accept({ id, revision, dryRun = false }, signal, progress) {
|
|
433
869
|
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}`);
|
|
870
|
+
const value = await inspect(id);
|
|
871
|
+
if (value.dependencyErrors.length) throw new Error(`Draft dependency error: ${value.dependencyErrors[0].message}`);
|
|
436
872
|
if (value.revision !== revision) throw new Error("Draft revision changed. Review the current draft before accepting.");
|
|
437
873
|
if (value.dependencies.length) throw new Error("Accept dependency drafts first. Dependent previews will automatically use their accepted implementations.");
|
|
438
|
-
if (value.conflicts.length)
|
|
874
|
+
if (value.conflicts.length)
|
|
875
|
+
throw new Error(
|
|
876
|
+
`Draft baseline conflict: accepted source changed outside this draft (${value.conflicts.join(", ")}). Drop the draft and create a new one from current source.`,
|
|
877
|
+
);
|
|
439
878
|
if (!value.changes.length) throw new Error("The draft has no changes to accept. Drop it instead.");
|
|
440
879
|
// 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
|
-
|
|
880
|
+
const groups = new Map(),
|
|
881
|
+
add = (unit, file) => groups.set(unit, [...(groups.get(unit) ?? []), file]);
|
|
882
|
+
const proposal = (content) =>
|
|
883
|
+
content === null || content.includes(0) || !Buffer.from(content.toString("utf8")).equals(content) ? content : content.toString("utf8");
|
|
884
|
+
for (const file of value.changes) add(file.unit, { path: file.target, content: proposal(file.content) });
|
|
885
|
+
const plans = value.manifest.units.filter((unit) => groups.has(unit)).map((unit) => ({ unit, files: groups.get(unit) }));
|
|
445
886
|
// Check and render in the draft's preview workspace, served by the project's own host and
|
|
446
887
|
// compiler; a controller without previews lets the engine check its own copy.
|
|
447
888
|
let checkRoot, previewHost;
|
|
448
889
|
if (startPreview) {
|
|
449
890
|
try {
|
|
450
|
-
const { session } = prepare(id);
|
|
451
|
-
if (session.revision === revision) {
|
|
452
|
-
|
|
891
|
+
const { session } = await prepare(id);
|
|
892
|
+
if (session.revision === revision) {
|
|
893
|
+
previewHost = await startSession(id, session);
|
|
894
|
+
checkRoot = session.workspace;
|
|
895
|
+
}
|
|
896
|
+
} catch {
|
|
897
|
+
checkRoot = previewHost = undefined;
|
|
898
|
+
}
|
|
453
899
|
}
|
|
454
|
-
const originals = new Map(value.changes.map(file => [file.target,bytes(safe(root,file.target))]));
|
|
900
|
+
const originals = new Map(value.changes.map((file) => [file.target, bytes(safe(root, file.target))]));
|
|
455
901
|
const abort = new AbortController();
|
|
456
|
-
active = { id, abort };
|
|
902
|
+
active = { id, abort };
|
|
903
|
+
if (!dryRun) event(id, revision, "checking");
|
|
457
904
|
try {
|
|
458
|
-
const result = await edits.apply(
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
905
|
+
const result = await edits.apply(
|
|
906
|
+
{ ...(plans.length === 1 ? plans[0] : { patches: plans }), dryRun, ...(checkRoot ? { checkRoot, previewHost } : {}) },
|
|
907
|
+
signal ? AbortSignal.any([signal, abort.signal]) : abort.signal,
|
|
908
|
+
progress,
|
|
909
|
+
{
|
|
910
|
+
async beforeApply() {
|
|
911
|
+
if ((await inspect(id)).revision !== revision)
|
|
912
|
+
throw new Error("Draft changed during acceptance; no changes were applied. Review and accept the new revision.");
|
|
913
|
+
},
|
|
914
|
+
},
|
|
915
|
+
);
|
|
916
|
+
if (dryRun)
|
|
917
|
+
return {
|
|
918
|
+
...result,
|
|
919
|
+
draft: id,
|
|
920
|
+
revision,
|
|
921
|
+
dryRun: true,
|
|
922
|
+
next: result.ok
|
|
923
|
+
? "Every acceptance check passed on this revision; nothing was written. Accept it with ads_accept and the same revision."
|
|
924
|
+
: "Acceptance would fail. Fix the draft, then check again.",
|
|
925
|
+
};
|
|
462
926
|
let outcome;
|
|
463
|
-
try
|
|
464
|
-
|
|
927
|
+
try {
|
|
928
|
+
outcome = event(id, revision, result.applied ? "applied" : "failed", { diagnostics: result.diagnostics?.slice(0, 3) });
|
|
929
|
+
} catch (error) {
|
|
930
|
+
if (!result.applied) throw error;
|
|
931
|
+
result.warnings = [...(result.warnings ?? []), { rule: "draft-event", message: `Source applied; event storage needs recovery: ${error.message}` }];
|
|
932
|
+
}
|
|
465
933
|
if (result.applied) {
|
|
466
934
|
const updated = [];
|
|
467
|
-
for (const dependent of ids().filter(other => other !== id)) {
|
|
468
|
-
try{
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
935
|
+
for (const dependent of ids().filter((other) => other !== id)) {
|
|
936
|
+
try {
|
|
937
|
+
const manifest = read(dependent);
|
|
938
|
+
if (manifest.dependencies.includes(id)) {
|
|
939
|
+
for (const file of manifest.files)
|
|
940
|
+
if (originals.has(file.target) && file.baseline === fileHash(originals.get(file.target))) {
|
|
941
|
+
const accepted = bytes(safe(root, file.target)),
|
|
942
|
+
source = file.source ? bytes(safe(path.dirname(manifestFile(dependent)), file.source)) : null;
|
|
943
|
+
if (fileHash(source) === file.baseline) {
|
|
944
|
+
file.baseline = fileHash(accepted);
|
|
945
|
+
if (file.source && accepted) atomic(safe(path.dirname(manifestFile(dependent)), file.source), accepted);
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
manifest.dependencies = manifest.dependencies.filter((dependency) => dependency !== id);
|
|
949
|
+
save(manifest);
|
|
950
|
+
updated.push(dependent);
|
|
474
951
|
}
|
|
475
|
-
|
|
952
|
+
} catch (error) {
|
|
953
|
+
result.warnings = [
|
|
954
|
+
...(result.warnings ?? []),
|
|
955
|
+
{ rule: "draft-dependency", message: `Source applied; dependent ${dependent} needs recovery: ${error.message}` },
|
|
956
|
+
];
|
|
476
957
|
}
|
|
477
|
-
}catch(error){result.warnings=[...(result.warnings??[]),{rule:"draft-dependency",message:`Source applied; dependent ${dependent} needs recovery: ${error.message}`}];}
|
|
478
958
|
}
|
|
479
|
-
try
|
|
480
|
-
|
|
959
|
+
try {
|
|
960
|
+
rmSync(path.dirname(manifestFile(id)), { recursive: true });
|
|
961
|
+
await retire(id);
|
|
962
|
+
} catch (error) {
|
|
963
|
+
result.warnings = [
|
|
964
|
+
...(result.warnings ?? []),
|
|
965
|
+
{ rule: "draft-cleanup", message: `Source applied; draft ${id} cleanup needs recovery: ${error.message}` },
|
|
966
|
+
];
|
|
967
|
+
}
|
|
481
968
|
return { ...result, draft: id, revision, event: outcome, updatedDependents: updated };
|
|
482
969
|
}
|
|
483
970
|
return { ...result, draft: id, revision, event: outcome };
|
|
484
|
-
} finally {
|
|
971
|
+
} finally {
|
|
972
|
+
active = undefined;
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
function draftStamp() {
|
|
976
|
+
const rows = [];
|
|
977
|
+
function walk(folder) {
|
|
978
|
+
if (!existsSync(folder)) return;
|
|
979
|
+
for (const entry of readdirSync(folder, { withFileTypes: true })) {
|
|
980
|
+
const file = path.join(folder, entry.name);
|
|
981
|
+
if (entry.isSymbolicLink()) continue;
|
|
982
|
+
if (entry.isDirectory()) walk(file);
|
|
983
|
+
else {
|
|
984
|
+
const stat = lstatSync(file);
|
|
985
|
+
rows.push([file, stat.mtimeMs, stat.ctimeMs, stat.size]);
|
|
986
|
+
}
|
|
987
|
+
if (rows.length > 20000) throw new Error("Too many draft files.");
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
walk(storage);
|
|
991
|
+
if (existsSync(eventFile)) rows.push(bytes(eventFile)?.toString());
|
|
992
|
+
return hash(JSON.stringify(rows));
|
|
485
993
|
}
|
|
486
|
-
function
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
994
|
+
function watchStamp(session) {
|
|
995
|
+
return hash(
|
|
996
|
+
JSON.stringify(
|
|
997
|
+
(session.watchFiles ?? []).map((file) => {
|
|
998
|
+
try {
|
|
999
|
+
const stat = lstatSync(file);
|
|
1000
|
+
return [file, stat.mtimeMs, stat.ctimeMs, stat.ino, stat.size];
|
|
1001
|
+
} catch {
|
|
1002
|
+
return [file, null];
|
|
1003
|
+
}
|
|
1004
|
+
}),
|
|
1005
|
+
),
|
|
1006
|
+
);
|
|
490
1007
|
}
|
|
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
1008
|
// A draft's own edits and the viewed draft resync at once. Other drafts behind an accepted-source
|
|
493
1009
|
// change catch up in the background, one at a time, paused while a draft is being shown; their
|
|
494
1010
|
// rebuilds run last in the compiler's queue.
|
|
495
|
-
function ownStamp(id)
|
|
1011
|
+
function ownStamp(id) {
|
|
1012
|
+
const rows = [];
|
|
1013
|
+
(function walk(folder) {
|
|
1014
|
+
if (!existsSync(folder)) return;
|
|
1015
|
+
for (const entry of readdirSync(folder, { withFileTypes: true })) {
|
|
1016
|
+
const file = path.join(folder, entry.name);
|
|
1017
|
+
if (entry.isSymbolicLink()) continue;
|
|
1018
|
+
if (entry.isDirectory()) walk(file);
|
|
1019
|
+
else {
|
|
1020
|
+
const stat = lstatSync(file);
|
|
1021
|
+
rows.push([file, stat.mtimeMs, stat.size]);
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
})(path.dirname(manifestFile(id)));
|
|
1025
|
+
return hash(JSON.stringify(rows));
|
|
1026
|
+
}
|
|
496
1027
|
const backlog = new Set();
|
|
497
|
-
let backlogTimer,
|
|
1028
|
+
let backlogTimer,
|
|
1029
|
+
showing = 0;
|
|
498
1030
|
function stale(id, session) {
|
|
499
|
-
let own;
|
|
1031
|
+
let own;
|
|
1032
|
+
try {
|
|
1033
|
+
own = ownStamp(id);
|
|
1034
|
+
} catch {
|
|
1035
|
+
return null;
|
|
1036
|
+
}
|
|
500
1037
|
return session.ownObserved !== own ? "own" : session.acceptedObserved !== watchStamp(session) ? "accepted" : null;
|
|
501
1038
|
}
|
|
502
|
-
function resync(id) {
|
|
503
|
-
|
|
1039
|
+
async function resync(id) {
|
|
1040
|
+
try {
|
|
1041
|
+
await prepare(id);
|
|
1042
|
+
} catch (error) {
|
|
1043
|
+
const session = previews.get(id);
|
|
1044
|
+
if (session) session.error = error.message;
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
async function syncPreviews() {
|
|
504
1048
|
const order = [...previews.keys()].sort((a, b) => (b === lastShown) - (a === lastShown));
|
|
505
1049
|
for (const id of order) {
|
|
506
1050
|
const reason = stale(id, previews.get(id));
|
|
507
1051
|
if (!reason) continue;
|
|
508
|
-
if (reason === "own" || id === lastShown) {
|
|
509
|
-
|
|
1052
|
+
if (reason === "own" || id === lastShown) {
|
|
1053
|
+
backlog.delete(id);
|
|
1054
|
+
await resync(id);
|
|
1055
|
+
} else backlog.add(id);
|
|
510
1056
|
}
|
|
511
1057
|
drainBacklog();
|
|
512
1058
|
}
|
|
513
1059
|
function drainBacklog() {
|
|
514
1060
|
if (closed || backlogTimer || !backlog.size) return;
|
|
515
|
-
backlogTimer = setTimeout(() => {
|
|
1061
|
+
backlogTimer = setTimeout(async () => {
|
|
516
1062
|
backlogTimer = undefined;
|
|
517
1063
|
if (closed) return;
|
|
518
|
-
if (showing) {
|
|
519
|
-
|
|
1064
|
+
if (showing) {
|
|
1065
|
+
drainBacklog();
|
|
1066
|
+
return;
|
|
1067
|
+
}
|
|
1068
|
+
const [id] = backlog;
|
|
1069
|
+
backlog.delete(id);
|
|
520
1070
|
const session = previews.get(id);
|
|
521
|
-
if (session && stale(id, session)) resync(id);
|
|
1071
|
+
if (session && stale(id, session)) await resync(id);
|
|
522
1072
|
drainBacklog();
|
|
523
1073
|
}, 50);
|
|
524
1074
|
backlogTimer.unref();
|
|
@@ -526,9 +1076,11 @@ export function createDraftController(directory, { edits, startPreview, prewarm
|
|
|
526
1076
|
function changed() {
|
|
527
1077
|
if (closed) return;
|
|
528
1078
|
clearTimeout(changeTimer);
|
|
529
|
-
changeTimer = setTimeout(() => {
|
|
1079
|
+
changeTimer = setTimeout(async () => {
|
|
530
1080
|
if (closed) return;
|
|
531
|
-
reconcileWatches();
|
|
1081
|
+
reconcileWatches();
|
|
1082
|
+
await syncPreviews();
|
|
1083
|
+
onChange?.();
|
|
532
1084
|
}, 16);
|
|
533
1085
|
changeTimer.unref();
|
|
534
1086
|
}
|
|
@@ -538,62 +1090,130 @@ export function createDraftController(directory, { edits, startPreview, prewarm
|
|
|
538
1090
|
function draftDirectories(folder) {
|
|
539
1091
|
if (!existsSync(folder) || realpathSync(folder) !== folder) return;
|
|
540
1092
|
wanted.add(folder);
|
|
541
|
-
for (const entry of readdirSync(folder, { withFileTypes: true }))
|
|
1093
|
+
for (const entry of readdirSync(folder, { withFileTypes: true }))
|
|
1094
|
+
if (entry.isDirectory() && !entry.isSymbolicLink()) draftDirectories(path.join(folder, entry.name));
|
|
542
1095
|
}
|
|
543
1096
|
try {
|
|
544
1097
|
draftDirectories(storage);
|
|
545
1098
|
const options = loadConfig(root);
|
|
546
1099
|
if (previews.size) for (const folder of previewWatchDirectories(options)) wanted.add(folder);
|
|
547
1100
|
for (const folder of wanted) {
|
|
548
|
-
const stat = lstatSync(folder),
|
|
1101
|
+
const stat = lstatSync(folder),
|
|
1102
|
+
identity = `${stat.dev}:${stat.ino}`;
|
|
549
1103
|
if (watchers.get(folder)?.identity === identity) continue;
|
|
550
1104
|
watchers.get(folder)?.watcher.close();
|
|
551
1105
|
const watcher = watch(folder, (event, file) => {
|
|
552
1106
|
if (!file) return;
|
|
553
1107
|
const target = path.join(folder, String(file));
|
|
554
1108
|
if (!isInside(storage, target) && previewFileIgnored(options, target)) return;
|
|
555
|
-
if (
|
|
1109
|
+
if (
|
|
1110
|
+
isInside(storage, target) ||
|
|
1111
|
+
event === "rename" ||
|
|
1112
|
+
/\.(?:[cm]?[jt]sx?|css|html|json|md|svg|png|jpe?g|webp|gif|woff2?|ttf|otf|lock|lockb)$/.test(target)
|
|
1113
|
+
)
|
|
1114
|
+
changed();
|
|
1115
|
+
});
|
|
1116
|
+
watcher.unref();
|
|
1117
|
+
watcher.on("error", () => {
|
|
1118
|
+
watcher.close();
|
|
1119
|
+
watchers.delete(folder);
|
|
556
1120
|
});
|
|
557
|
-
watcher.unref(); watcher.on("error", () => { watcher.close(); watchers.delete(folder); });
|
|
558
1121
|
watchers.set(folder, { identity, watcher });
|
|
559
1122
|
}
|
|
560
|
-
for (const [folder, item] of watchers)
|
|
561
|
-
|
|
1123
|
+
for (const [folder, item] of watchers)
|
|
1124
|
+
if (!wanted.has(folder) || !existsSync(folder)) {
|
|
1125
|
+
item.watcher.close();
|
|
1126
|
+
watchers.delete(folder);
|
|
1127
|
+
}
|
|
1128
|
+
} catch {
|
|
1129
|
+
/* Reconciliation retries removed/replaced directories. */
|
|
1130
|
+
}
|
|
562
1131
|
}
|
|
563
|
-
const timer = setInterval(() => {
|
|
1132
|
+
const timer = setInterval(async () => {
|
|
1133
|
+
if (!closed) {
|
|
1134
|
+
reconcileWatches();
|
|
1135
|
+
await syncPreviews();
|
|
1136
|
+
}
|
|
1137
|
+
}, 5000);
|
|
564
1138
|
timer.unref();
|
|
565
|
-
const generated=path.join(root,".ds/draft-previews");
|
|
566
|
-
if(existsSync(generated)&&realpathSync(generated)===
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
1139
|
+
const generated = path.join(root, ".ds/draft-previews");
|
|
1140
|
+
if (existsSync(generated) && realpathSync(generated) === generated)
|
|
1141
|
+
for (const entry of readdirSync(generated, { withFileTypes: true })) {
|
|
1142
|
+
if (entry.isDirectory() && !entry.isSymbolicLink() && /\.retired-[a-f0-9-]{36}$/.test(entry.name)) {
|
|
1143
|
+
rmSync(path.join(generated, entry.name), { recursive: true, force: true });
|
|
1144
|
+
continue;
|
|
1145
|
+
}
|
|
1146
|
+
if (entry.isDirectory() && !entry.isSymbolicLink() && idSchema.safeParse(entry.name).success && !existsSync(manifestFile(entry.name)))
|
|
1147
|
+
rmSync(previewDirectory(entry.name), { recursive: true, force: true });
|
|
1148
|
+
}
|
|
570
1149
|
reconcileWatches();
|
|
571
|
-
return {
|
|
1150
|
+
return {
|
|
1151
|
+
list,
|
|
1152
|
+
create,
|
|
1153
|
+
update,
|
|
1154
|
+
show,
|
|
1155
|
+
drop,
|
|
1156
|
+
accept,
|
|
1157
|
+
prepare,
|
|
1158
|
+
events,
|
|
1159
|
+
inspect,
|
|
1160
|
+
tokenGroups,
|
|
572
1161
|
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
|
-
|
|
1162
|
+
readFile(file, { offset = 0, limit = 12000 } = {}) {
|
|
1163
|
+
const parts = file.split("/");
|
|
1164
|
+
if (parts[0] !== DRAFT_DIRECTORY || parts.length < 3) throw new Error("Use a tracked draft path from ads_drafts.");
|
|
1165
|
+
const manifest = read(parts[1]),
|
|
1166
|
+
folder = path.dirname(manifestFile(parts[1]));
|
|
1167
|
+
const mapping = manifest.files.find((entry) => entry.source === parts.slice(2).join("/"));
|
|
1168
|
+
if (!mapping && parts.slice(2).join("/") !== "proposal.ads.draft.json")
|
|
1169
|
+
throw new Error("Draft reads are limited to the manifest and registered source files.");
|
|
1170
|
+
const content = bytes(safe(folder, parts.slice(2).join("/")));
|
|
1171
|
+
if (content === null) throw new Error("Draft source is missing.");
|
|
1172
|
+
const binary = content.includes(0) || !Buffer.from(content.toString("utf8")).equals(content),
|
|
1173
|
+
text = content.toString("utf8"),
|
|
1174
|
+
end = offset + limit;
|
|
1175
|
+
if (!Number.isSafeInteger(offset) || offset < 0 || offset > text.length || !Number.isSafeInteger(limit) || limit < 1 || limit > 12000)
|
|
1176
|
+
throw new Error("Invalid draft read range.");
|
|
1177
|
+
return {
|
|
1178
|
+
path: file,
|
|
1179
|
+
draft: parts[1],
|
|
1180
|
+
unit: mapping?.unit ?? null,
|
|
1181
|
+
digest: `sha256:${hash(content)}`,
|
|
1182
|
+
bytes: content.length,
|
|
1183
|
+
binary,
|
|
1184
|
+
content: binary ? null : text.slice(offset, end),
|
|
1185
|
+
offset,
|
|
1186
|
+
nextOffset: !binary && end < text.length ? end : null,
|
|
1187
|
+
totalChars: binary ? null : text.length,
|
|
1188
|
+
startLine: text.slice(0, offset).split("\n").length,
|
|
1189
|
+
};
|
|
584
1190
|
},
|
|
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)}]};
|
|
1191
|
+
async readResource(id, uri, signal) {
|
|
1192
|
+
const session = previews.get(id);
|
|
1193
|
+
if (session?.error) throw new Error(`Draft preview is stale: ${session.error}`);
|
|
1194
|
+
if (uri === "ads://project/scenarios" && session?.registry) {
|
|
1195
|
+
await prepare(id);
|
|
1196
|
+
session.registry = await discovery.current(session.workspace, session.revision);
|
|
1197
|
+
return { contents: [{ uri, mimeType: "application/json", text: JSON.stringify(session.registry) }] };
|
|
592
1198
|
}
|
|
593
|
-
if(!session?.starting)throw new Error("Draft preview is not active. Reopen ads_show_draft.");
|
|
594
|
-
await session.starting;
|
|
1199
|
+
if (!session?.starting) throw new Error("Draft preview is not active. Reopen ads_show_draft.");
|
|
1200
|
+
await session.starting;
|
|
1201
|
+
return session.runtime.readResource(uri, signal);
|
|
1202
|
+
},
|
|
1203
|
+
fingerprint: () => `${draftStamp()}:${discoveryVersion}`,
|
|
1204
|
+
async close() {
|
|
1205
|
+
closed = true;
|
|
1206
|
+
clearInterval(timer);
|
|
1207
|
+
clearTimeout(backlogTimer);
|
|
1208
|
+
backlog.clear();
|
|
1209
|
+
clearTimeout(changeTimer);
|
|
1210
|
+
clearTimeout(prewarmTimer);
|
|
1211
|
+
pendingPrewarm = undefined;
|
|
1212
|
+
for (const { watcher } of watchers.values()) watcher.close();
|
|
1213
|
+
watchers.clear();
|
|
1214
|
+
active?.abort.abort();
|
|
1215
|
+
await Promise.allSettled([discovery.close(), ...(await mapAsync([...previews.keys()], retire))]);
|
|
1216
|
+
await prewarming;
|
|
595
1217
|
},
|
|
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
1218
|
};
|
|
599
1219
|
}
|