@reqvire-org/ads 0.4.7 → 0.5.1
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 +268 -420
- package/dist/accessibility-declarations.mjs +43 -0
- package/dist/active-clock.d.mts +30 -0
- package/dist/active-clock.mjs +26 -17
- package/dist/ads-errors.mjs +3684 -0
- package/dist/ads-view-choices.mjs +17 -0
- package/dist/ads-views.mjs +12 -0
- package/dist/analysis/captured-content.mjs +16 -0
- package/dist/analysis/compiler-options.mjs +3 -7
- package/dist/analysis/context.mjs +14 -20
- package/dist/analysis/controller-gates.mjs +119 -0
- package/dist/analysis/design-usage.mjs +142 -0
- package/dist/analysis/file-tree.mjs +44 -29
- package/dist/analysis/framework-imports.mjs +62 -0
- package/dist/analysis/glyph-macros.mjs +103 -0
- package/dist/analysis/helpers.mjs +119 -91
- package/dist/analysis/impact.mjs +25 -12
- package/dist/analysis/inputs.mjs +19 -13
- package/dist/analysis/mock-check.mjs +99 -0
- package/dist/analysis/module-graph.mjs +156 -0
- package/dist/analysis/module-resolvers.mjs +30 -28
- package/dist/analysis/native-adapter.mjs +139 -146
- package/dist/analysis/native-boundary.mjs +52 -0
- package/dist/analysis/native-project.mjs +331 -231
- package/dist/analysis/native-session.mjs +20 -0
- package/dist/analysis/owner-accessibility.mjs +74 -0
- package/dist/analysis/owner-analysis-cache.mjs +125 -0
- package/dist/analysis/owner-analysis-key.mjs +114 -0
- package/dist/analysis/owner-choices.mjs +896 -0
- package/dist/analysis/owner-composition.mjs +636 -0
- package/dist/analysis/owner-controls.mjs +27 -0
- package/dist/analysis/owner-discovery.mjs +164 -0
- package/dist/analysis/owner-failures.mjs +19 -0
- package/dist/analysis/owner-outcomes.mjs +42 -0
- package/dist/analysis/owner-reuse.mjs +100 -0
- package/dist/analysis/owner-source.mjs +1555 -0
- package/dist/analysis/prose-owners.mjs +57 -0
- package/dist/analysis/public-imports.mjs +31 -0
- package/dist/analysis/queries.mjs +72 -54
- package/dist/analysis/runtime-setters.mjs +114 -0
- package/dist/analysis/scenario-keys.mjs +151 -0
- package/dist/analysis/service.mjs +111 -70
- package/dist/analysis/standalone.mjs +40 -37
- package/dist/analysis/styling-ownership.mjs +298 -0
- package/dist/analysis/svg-attributes.mjs +199 -0
- package/dist/analysis/syntax.mjs +82 -78
- package/dist/analysis/visual-bindings.mjs +68 -0
- package/dist/analysis/worker-protocol.mjs +302 -0
- package/dist/analysis/worker.mjs +234 -166
- package/dist/api-signature.mjs +53 -0
- package/dist/app-icon-checks.mjs +298 -0
- package/dist/app-icon-declaration.d.mts +53 -0
- package/dist/app-icon-declaration.mjs +66 -0
- package/dist/asset-binding.mjs +35 -0
- package/dist/asset-catalog.mjs +83 -0
- package/dist/asset-declaration.d.mts +42 -0
- package/dist/asset-declaration.mjs +108 -0
- package/dist/asset-macro.d.mts +63 -0
- package/dist/asset-macro.mjs +22 -0
- package/dist/asset-model.mjs +74 -0
- package/dist/asset-usage.mjs +14 -0
- package/dist/asset-view-facts.mjs +41 -0
- package/dist/authoring-macro.d.mts +11 -0
- package/dist/authoring-macro.mjs +21 -0
- package/dist/autocomplete-hints.mjs +31 -0
- package/dist/availability.mjs +9 -0
- package/dist/behavior-macro.d.mts +31 -0
- package/dist/behavior-macro.mjs +3 -0
- package/dist/behavior-registry.mjs +358 -0
- package/dist/boundaries.mjs +50 -212
- package/dist/browser-runtime.mjs +73 -0
- package/dist/browser-test.d.mts +3 -0
- package/dist/browser-test.mjs +2 -0
- package/dist/bun-bundler.mjs +10 -0
- package/dist/bun-compiler.mjs +30 -18
- package/dist/bun-runtime.mjs +4 -0
- package/dist/bun-worker.mjs +10 -4
- package/dist/capture/request.mjs +81 -0
- package/dist/capture/worker.mjs +69 -40
- package/dist/capture/worker.page.mjs +6 -0
- package/dist/capture-store.mjs +159 -75
- package/dist/capture.mjs +232 -95
- package/dist/check-service.mjs +27 -33
- package/dist/check.mjs +206 -904
- package/dist/cli-arguments.mjs +278 -0
- package/dist/cli.mjs +374 -304
- package/dist/color-values.mjs +294 -242
- package/dist/composed-contrast.mjs +648 -0
- package/dist/composed-keyline.mjs +107 -0
- package/dist/config.mjs +162 -468
- package/dist/construction-output.mjs +345 -0
- package/dist/construction-spec.d.mts +915 -0
- package/dist/construction-spec.mjs +1178 -0
- package/dist/corner-overpaint.mjs +53 -0
- package/dist/css-length.mjs +80 -0
- package/dist/css-quantity.mjs +173 -0
- package/dist/deletion-model.mjs +56 -0
- package/dist/deletion-plan.mjs +364 -0
- package/dist/dependency-manifest.mjs +56 -0
- package/dist/design-context-model.d.mts +61 -0
- package/dist/design-context-model.mjs +79 -0
- package/dist/design-contexts.mjs +105 -0
- package/dist/design-foundation.mjs +532 -0
- package/dist/design-inputs.mjs +156 -0
- package/dist/design-modules.mjs +27 -0
- package/dist/design-rejection.d.mts +23 -0
- package/dist/design-rejection.mjs +29 -0
- package/dist/design-system-closure.mjs +108 -0
- package/dist/design-usage.mjs +54 -0
- package/dist/development-modules.mjs +2 -0
- package/dist/development-runtime.mjs +0 -7
- package/dist/digest.mjs +2 -0
- package/dist/draft-boundary.mjs +1 -27
- package/dist/draft-workspace.mjs +11 -5
- package/dist/emit/accept.mjs +33 -0
- package/dist/emit/app-icon-emission.mjs +124 -0
- package/dist/emit/app-icon-render.mjs +126 -0
- package/dist/emit/asset-imports.mjs +18 -0
- package/dist/emit/cli-report.mjs +97 -0
- package/dist/emit/contract.mjs +136 -0
- package/dist/emit/emission.mjs +182 -0
- package/dist/emit/font-emission.mjs +111 -0
- package/dist/emit/foundation-sheet.mjs +56 -0
- package/dist/emit/icon-containers.mjs +46 -0
- package/dist/emit/integrity.mjs +61 -0
- package/dist/emit/lock.mjs +66 -0
- package/dist/emit/namespace.mjs +79 -0
- package/dist/emit/operation-reply.mjs +3 -0
- package/dist/emit/operation.mjs +36 -0
- package/dist/emit/output-location.mjs +20 -0
- package/dist/emit/output-package.mjs +7 -0
- package/dist/emit/owner-emission-cache.mjs +52 -0
- package/dist/emit/palette-module.mjs +19 -0
- package/dist/emit/palette-refresh.mjs +77 -0
- package/dist/emit/preview-emitter.mjs +110 -0
- package/dist/emit/preview-tree.mjs +174 -0
- package/dist/emit/scheduler.mjs +75 -0
- package/dist/emit/service.mjs +249 -0
- package/dist/emit/sync.mjs +38 -0
- package/dist/emit/watch.mjs +74 -0
- package/dist/emit/writer.mjs +102 -0
- package/dist/evidence.mjs +6 -8
- package/dist/example-babel.mjs +7 -0
- package/dist/example-literals.mjs +88 -0
- package/dist/finding-rules.mjs +78 -77
- package/dist/focus-checks.mjs +93 -0
- package/dist/font-checks.mjs +185 -0
- package/dist/font-declaration.d.mts +64 -0
- package/dist/font-declaration.mjs +99 -0
- package/dist/font-fallback.d.mts +37 -0
- package/dist/font-fallback.mjs +25 -0
- package/dist/font-macro.d.mts +42 -0
- package/dist/font-macro.mjs +6 -0
- package/dist/font-metrics.d.mts +34 -0
- package/dist/font-metrics.mjs +314 -0
- package/dist/font-model.mjs +63 -0
- package/dist/form-states.mjs +82 -0
- package/dist/foundation-macro.d.mts +108 -0
- package/dist/foundation-macro.mjs +6 -0
- package/dist/frame-regions.mjs +253 -0
- package/dist/glyph-set-declaration.d.mts +27 -0
- package/dist/glyph-set-declaration.mjs +36 -0
- package/dist/grid-checks.mjs +94 -0
- package/dist/grid-facts.mjs +148 -0
- package/dist/grid-lowering.mjs +263 -0
- package/dist/guard/cli.mjs +51 -0
- package/dist/guard/config.mjs +67 -0
- package/dist/guard/files.mjs +31 -0
- package/dist/guard/index.mjs +3 -0
- package/dist/guard/run.mjs +56 -0
- package/dist/guard/tsconfig.declarations.json +13 -0
- package/dist/index.mjs +2 -7
- package/dist/init-project.mjs +134 -0
- package/dist/init.mjs +217 -264
- package/dist/input-digests.mjs +109 -163
- package/dist/input-scope.mjs +18 -41
- package/dist/inspected-svg.d.mts +28 -0
- package/dist/inspected-svg.mjs +40 -0
- package/dist/inventories.mjs +149 -0
- package/dist/inventory-query.mjs +15 -0
- package/dist/investigations.mjs +177 -99
- package/dist/json.d.mts +10 -0
- package/dist/json.mjs +36 -0
- package/dist/linaria/atomic-processor.json +96 -0
- package/dist/linaria/atomic-processor.mjs +2452 -0
- package/dist/linaria/backend-identity.mjs +26 -0
- package/dist/linaria/compatibility.json +61 -0
- package/dist/linaria/css-shape.mjs +94 -0
- package/dist/linaria/custom-property-css.mjs +56 -0
- package/dist/linaria/delivery.mjs +111 -0
- package/dist/linaria/direct-extract.mjs +43 -0
- package/dist/linaria/extraction-cache.mjs +31 -0
- package/dist/linaria/extraction-model.mjs +5 -0
- package/dist/linaria/fingerprint.mjs +183 -0
- package/dist/linaria/pair-manifest.json +2315 -0
- package/dist/linaria/persisted-extraction-cache.mjs +352 -0
- package/dist/linaria/preservation.mjs +13 -0
- package/dist/linaria/priority-emitted-rank.mjs +40 -0
- package/dist/linaria/priority-manifest.mjs +87 -0
- package/dist/linaria/priority-table.mjs +47 -0
- package/dist/linaria/priority-tiers.mjs +27 -0
- package/dist/linaria/processor-host.mjs +42 -0
- package/dist/linaria/processor-runtime.mjs +36 -0
- package/dist/linaria-processor-NOTICES.md +147 -0
- package/dist/lowering-components.mjs +14 -0
- package/dist/lowering-effects.mjs +38 -0
- package/dist/lowering-emitter.mjs +29 -0
- package/dist/lowering-enter.mjs +31 -0
- package/dist/lowering-hidden.mjs +30 -0
- package/dist/lowering-layer.mjs +141 -0
- package/dist/lowering-motion.mjs +37 -0
- package/dist/lowering-normalize.mjs +194 -0
- package/dist/lowering-overlaps.mjs +328 -0
- package/dist/lowering-paint.mjs +32 -0
- package/dist/lowering-properties.mjs +165 -0
- package/dist/lowering-region-layout.mjs +225 -0
- package/dist/lowering-sequence.mjs +89 -0
- package/dist/lowering-serialize.mjs +40 -0
- package/dist/lowering-session.mjs +137 -0
- package/dist/lowering-tiers.mjs +23 -0
- package/dist/lowering-transitions.mjs +53 -0
- package/dist/mcp/ads-mcp.mjs +423 -0
- package/dist/mcp/apps.mjs +3 -25
- package/dist/mcp/behavior-pages.mjs +58 -51
- package/dist/mcp/build-status.mjs +233 -267
- package/dist/mcp/catalog.mjs +21 -128
- package/dist/mcp/compiler-channel.mjs +218 -83
- package/dist/mcp/context.mjs +50 -40
- package/dist/mcp/deletions.mjs +147 -0
- package/dist/mcp/draft-discovery.mjs +43 -38
- package/dist/mcp/drafts.mjs +635 -691
- package/dist/mcp/execution-context.mjs +33 -22
- package/dist/mcp/execution-coordinator.mjs +367 -354
- package/dist/mcp/execution-results.mjs +440 -173
- package/dist/mcp/mutation-limits.mjs +1 -2
- package/dist/mcp/mutations.mjs +515 -553
- package/dist/mcp/patch.mjs +117 -75
- package/dist/mcp/preview-http.bundle.js +3 -7
- package/dist/mcp/preview-http.mjs +220 -107
- package/dist/mcp/preview-owner-guard.mjs +81 -43
- package/dist/mcp/preview-watch.mjs +428 -365
- package/dist/mcp/preview-widget.bundle.js +42 -46
- package/dist/mcp/preview-work.mjs +25 -13
- package/dist/mcp/prompts.mjs +22 -16
- package/dist/mcp/resource-loader.js +1 -1
- package/dist/mcp/result-pages.mjs +94 -54
- package/dist/mcp/sandbox-host.mjs +41 -19
- package/dist/mcp/server-discovery.mjs +96 -0
- package/dist/mcp/server-guides.mjs +43 -0
- package/dist/mcp/server-host.mjs +203 -0
- package/dist/mcp/server-observation.mjs +225 -0
- package/dist/mcp/server-project.mjs +371 -0
- package/dist/mcp/server-resources.mjs +466 -0
- package/dist/mcp/server-shared.mjs +79 -0
- package/dist/mcp/server-tools.mjs +791 -0
- package/dist/mcp/server.mjs +2 -2813
- package/dist/mcp/showcase-host.mjs +209 -135
- package/dist/mcp/showcase-http.mjs +50 -28
- package/dist/mcp/skills.mjs +32 -36
- package/dist/mcp/text-diff.mjs +18 -36
- package/dist/measured-geometry.mjs +157 -0
- package/dist/motion-model.mjs +52 -0
- package/dist/non-text-contrast.mjs +118 -0
- package/dist/owner-analysis-check.mjs +711 -0
- package/dist/owner-design.mjs +15 -0
- package/dist/owner-errors.mjs +216 -0
- package/dist/owner-lowering.mjs +206 -0
- package/dist/owner-scenarios.mjs +854 -0
- package/dist/ownership-model.d.mts +6 -0
- package/dist/ownership-model.mjs +143 -0
- package/dist/package-declarations.mjs +34 -0
- package/dist/paint-contrast.mjs +186 -0
- package/dist/palette-generated.mjs +101 -116
- package/dist/pictogram-model.mjs +13 -51
- package/dist/placeholder-contrast.mjs +35 -0
- package/dist/platform-features.mjs +401 -0
- package/dist/press-scale.mjs +26 -0
- package/dist/preview-bun.mjs +334 -404
- package/dist/preview-compile-inputs.mjs +78 -0
- package/dist/preview-contexts.mjs +7 -0
- package/dist/preview-controls.mjs +35 -0
- package/dist/preview-failure.mjs +20 -10
- package/dist/preview-files.mjs +18 -36
- package/dist/preview-imports.mjs +76 -70
- package/dist/preview-incremental.mjs +322 -222
- package/dist/preview-inputs.mjs +26 -26
- package/dist/preview-manifest-update.mjs +67 -49
- package/dist/preview-requests.mjs +10 -17
- package/dist/preview-resources.mjs +275 -323
- package/dist/preview-scope.mjs +15 -17
- package/dist/preview-source.mjs +182 -0
- package/dist/preview-spatial.mjs +27 -0
- package/dist/profile-macro.d.mts +56 -0
- package/dist/profile-macro.mjs +6 -0
- package/dist/profile-model.d.mts +65 -0
- package/dist/profile-model.mjs +213 -0
- package/dist/profile-view-facts.mjs +93 -0
- package/dist/program-cache.mjs +9 -7
- package/dist/project-boundary.mjs +8 -13
- package/dist/project-documents.mjs +25 -29
- package/dist/property-registrations.mjs +44 -35
- package/dist/prose-model.d.mts +81 -0
- package/dist/prose-model.mjs +101 -0
- package/dist/public-catalog.mjs +76 -0
- package/dist/recipe-defaults.mjs +117 -0
- package/dist/recipe-macro.d.mts +502 -0
- package/dist/recipe-macro.mjs +23 -0
- package/dist/recipe-model.d.mts +26 -0
- package/dist/recipe-model.mjs +214 -0
- package/dist/region-lowering.mjs +723 -0
- package/dist/registration-css.mjs +41 -0
- package/dist/registration-roles.mjs +35 -0
- package/dist/render-audit/axe-run.page.mjs +28 -0
- package/dist/render-audit/corner-overpaint.page.mjs +54 -0
- package/dist/render-audit/first-render.page.mjs +35 -0
- package/dist/render-audit/image-shape.page.mjs +42 -0
- package/dist/render-audit/layout-overflow.page.mjs +240 -0
- package/dist/render-audit/layout-shift.page.mjs +36 -0
- package/dist/render-audit/non-text-contrast.page.mjs +138 -0
- package/dist/render-audit/render-states.mjs +66 -293
- package/dist/render-audit/render-states.page.mjs +177 -0
- package/dist/render-audit/text-scale.mjs +42 -0
- package/dist/render-audit/text-scale.page.mjs +25 -0
- package/dist/render-audit/worker.mjs +130 -112
- package/dist/render-audit/worker.page.mjs +21 -0
- package/dist/render-audit.mjs +490 -500
- package/dist/resource-limits.mjs +174 -223
- package/dist/result.d.mts +34 -0
- package/dist/result.mjs +60 -0
- package/dist/role-vocabulary.d.mts +260 -0
- package/dist/role-vocabulary.mjs +258 -0
- package/dist/runtime-paint-contrast.mjs +97 -0
- package/dist/runtime-paint.mjs +42 -0
- package/dist/runtime-requirements.mjs +10 -11
- package/dist/runtime-style.mjs +21 -0
- package/dist/scenario-groups.mjs +42 -33
- package/dist/scenario-inspector.mjs +4 -4
- package/dist/scenario-kit.d.mts +85 -0
- package/dist/scenario-kit.mjs +18 -0
- package/dist/scenario-registry-model.mjs +2 -0
- package/dist/scenario-registry.mjs +89 -108
- package/dist/scenarios-compiler.mjs +875 -662
- package/dist/scheme-switch.d.mts +8 -0
- package/dist/scheme-switch.mjs +1 -0
- package/dist/showcase/ads-views.mjs +166 -0
- package/dist/showcase/assets-view.mjs +252 -0
- package/dist/showcase/client.bundle.js +211 -48
- package/dist/showcase/guide-controls.d.mts +28 -0
- package/dist/showcase/guide-controls.mjs +31 -0
- package/dist/showcase/http-client.bundle.js +172 -9
- package/dist/showcase/index.html +1 -1
- package/dist/showcase/preview-frame.css +18 -0
- package/dist/showcase/preview-frame.d.mts +5 -0
- package/dist/showcase/preview-frame.mjs +4 -0
- package/dist/showcase/preview-root.d.mts +2 -0
- package/dist/showcase/preview-root.mjs +9 -0
- package/dist/showcase/profiles-view.mjs +321 -0
- package/dist/showcase/project-rules.mjs +9 -0
- package/dist/showcase/sandbox.bundle.js +1 -1
- package/dist/showcase/scenario-page.d.mts +49 -0
- package/dist/showcase/scenario-page.mjs +105 -0
- package/dist/showcase/style.css +2 -0
- package/dist/showcase/token-sample.mjs +89 -0
- package/dist/showcase/tokens-view.mjs +233 -0
- package/dist/showcase/ui/apple-touch-icon-9zwv3w79.png +0 -0
- package/dist/showcase/{favicon.ico → ui/favicon-c2c9kvtf.ico} +0 -0
- package/dist/showcase/ui/icon-192-t5zh7mxx.png +0 -0
- package/dist/showcase/ui/icon-512-ed6yz0n0.png +0 -0
- package/dist/showcase/ui/ui.css +1 -1353
- package/dist/showcase/ui/ui.js +165 -1064
- package/dist/showcase-http-routes.mjs +28 -21
- package/dist/skills/README.md +28 -28
- package/dist/skills/ads-designer/README.md +1 -1
- package/dist/skills/ads-designer/SKILL.md +313 -551
- package/dist/skills/ads-designer/references/accessibility.md +162 -114
- package/dist/skills/ads-designer/references/atomic-styles.md +72 -277
- package/dist/skills/ads-designer/references/behaviors.md +144 -280
- package/dist/skills/ads-designer/references/branding.md +137 -222
- package/dist/skills/ads-designer/references/captures.md +13 -7
- package/dist/skills/ads-designer/references/cli.md +80 -63
- package/dist/skills/ads-designer/references/contracts.md +225 -286
- package/dist/skills/ads-designer/references/design-craft.md +2 -2
- package/dist/skills/ads-designer/references/design-data.md +299 -323
- package/dist/skills/ads-designer/references/drafts.md +83 -22
- package/dist/skills/ads-designer/references/evidence.md +2 -1
- package/dist/skills/ads-designer/references/forms.md +199 -0
- package/dist/skills/ads-designer/references/guarded-editing.md +37 -48
- package/dist/skills/ads-designer/references/layers.md +64 -76
- package/dist/skills/ads-designer/references/layout.md +224 -330
- package/dist/skills/ads-designer/references/mobile.md +2 -2
- package/dist/skills/ads-designer/references/motion.md +66 -25
- package/dist/skills/ads-designer/references/performance.md +55 -50
- package/dist/skills/ads-designer/references/pictograms.md +62 -127
- package/dist/skills/ads-designer/references/recipes.md +368 -0
- package/dist/skills/ads-designer/references/review.md +51 -95
- package/dist/skills/ads-designer/references/runtimes.md +34 -33
- package/dist/skills/ads-designer/references/scenarios.md +256 -216
- package/dist/skills/ads-designer/references/stress-test.md +13 -5
- package/dist/skills/ads-designer/references/validation.md +28 -21
- package/dist/skills/ads-designer/references/workflows.md +7 -5
- package/dist/skills/ads-import/SKILL.md +29 -29
- package/dist/skills/ads-import/references/atomic-styles.md +72 -277
- package/dist/skills/ads-import/references/behaviors.md +144 -280
- package/dist/skills/ads-import/references/branding.md +24 -41
- package/dist/skills/ads-import/references/captures.md +13 -7
- package/dist/skills/ads-import/references/cli.md +80 -63
- package/dist/skills/ads-import/references/compatibility.md +3 -3
- package/dist/skills/ads-import/references/contracts.md +225 -286
- package/dist/skills/ads-import/references/design-data.md +299 -323
- package/dist/skills/ads-import/references/drafts.md +83 -22
- package/dist/skills/ads-import/references/evidence.md +2 -1
- package/dist/skills/ads-import/references/forms.md +199 -0
- package/dist/skills/ads-import/references/guarded-editing.md +37 -48
- package/dist/skills/ads-import/references/implementation.md +20 -20
- package/dist/skills/ads-import/references/layers.md +64 -76
- package/dist/skills/ads-import/references/layout.md +224 -330
- package/dist/skills/ads-import/references/recipes.md +368 -0
- package/dist/skills/ads-import/references/review.md +51 -95
- package/dist/skills/ads-import/references/runtimes.md +34 -33
- package/dist/skills/ads-import/references/scenarios.md +256 -216
- package/dist/skills/ads-import/references/tokens.md +26 -17
- package/dist/skills/ads-import/references/validation.md +28 -21
- package/dist/skills/ads-import/references/workflows.md +7 -5
- package/dist/skills/ads-migrate/SKILL.md +20 -5
- package/dist/skills/ads-migrate/references/0.4.1-to-0.4.2.md +6 -0
- package/dist/skills/ads-migrate/references/0.4.7-to-0.5.0-boundary.md +71 -0
- package/dist/skills/ads-migrate/references/0.4.7-to-0.5.0-grid.md +204 -0
- package/dist/skills/ads-migrate/references/0.4.7-to-0.5.0.md +727 -0
- package/dist/skills/ads-migrate/references/0.5.0-to-0.5.1.md +239 -0
- package/dist/skills/ads-port/SKILL.md +27 -28
- package/dist/skills/ads-port/references/atomic-styles.md +72 -277
- package/dist/skills/ads-port/references/behaviors.md +144 -280
- package/dist/skills/ads-port/references/captures.md +13 -7
- package/dist/skills/ads-port/references/cli.md +80 -63
- package/dist/skills/ads-port/references/contracts.md +225 -286
- package/dist/skills/ads-port/references/design-data.md +299 -323
- package/dist/skills/ads-port/references/drafts.md +83 -22
- package/dist/skills/ads-port/references/evidence.md +2 -1
- package/dist/skills/ads-port/references/forms.md +199 -0
- package/dist/skills/ads-port/references/guarded-editing.md +37 -48
- package/dist/skills/ads-port/references/layers.md +64 -76
- package/dist/skills/ads-port/references/layout.md +224 -330
- package/dist/skills/ads-port/references/lint-and-docs.md +2 -3
- package/dist/skills/ads-port/references/native-implementation.md +23 -33
- package/dist/skills/ads-port/references/recipes.md +368 -0
- package/dist/skills/ads-port/references/review.md +51 -95
- package/dist/skills/ads-port/references/runtimes.md +34 -33
- package/dist/skills/ads-port/references/scenarios.md +256 -216
- package/dist/skills/ads-port/references/validation.md +28 -21
- package/dist/skills/ads-port/references/workflows.md +7 -5
- package/dist/source-inventory.mjs +33 -0
- package/dist/source-values.mjs +272 -262
- package/dist/spatial-css.mjs +403 -0
- package/dist/spatial-metadata.mjs +11 -11
- package/dist/spatial-model.mjs +438 -0
- package/dist/spatial-reading.mjs +127 -0
- package/dist/stage-timing.mjs +27 -0
- package/dist/state-conditions.d.mts +80 -0
- package/dist/state-conditions.mjs +107 -0
- package/dist/static-values.mjs +94 -0
- package/dist/surface-contrast.mjs +252 -0
- package/dist/surface-effects.mjs +98 -0
- package/dist/target-size.mjs +177 -0
- package/dist/task-cache.mjs +142 -136
- package/dist/task-worker.mjs +18 -18
- package/dist/test-boundaries.mjs +50 -189
- package/dist/token-checks.mjs +21 -0
- package/dist/token-dtcg.mjs +136 -0
- package/dist/token-expression.mjs +19 -0
- package/dist/token-inventory.mjs +146 -0
- package/dist/token-operations.mjs +37 -0
- package/dist/token-overlap.mjs +29 -0
- package/dist/token-provenance.mjs +260 -0
- package/dist/token-references.mjs +71 -0
- package/dist/token-registrations.mjs +116 -0
- package/dist/token-resolution.mjs +38 -0
- package/dist/token-sections.mjs +123 -0
- package/dist/token-shapes.mjs +121 -0
- package/dist/token-sheet-check.mjs +54 -0
- package/dist/token-type-check.mjs +89 -0
- package/dist/token-view-facts.mjs +111 -0
- package/dist/tsconfig.declarations.json +24 -0
- package/dist/types/css-tree.d.ts +45 -0
- package/dist/ui-framework.mjs +34 -34
- package/dist/units.mjs +186 -226
- package/dist/unknown.d.mts +9 -0
- package/dist/unknown.mjs +13 -0
- package/dist/unreached-sources.mjs +5 -0
- package/dist/validation-checks.mjs +62 -71
- package/dist/validation-inputs.mjs +209 -279
- package/dist/validation.mjs +132 -159
- package/dist/verification/browser.d.mts +21 -25
- package/dist/verification/browser.mjs +281 -124
- package/dist/verification/browser.page.d.mts +22 -0
- package/dist/verification/browser.page.mjs +19 -0
- package/dist/verification/paint-audit.page.d.mts +55 -0
- package/dist/verification/paint-audit.page.mjs +144 -0
- package/dist/verification/playwright-reporter.mjs +160 -0
- package/dist/verification/preview-startup.d.mts +51 -0
- package/dist/verification/preview-startup.mjs +76 -0
- package/dist/verification/request.d.mts +28 -0
- package/dist/verification/request.mjs +30 -0
- package/dist/verification/unit-preload.mjs +37 -0
- package/dist/verification.mjs +574 -607
- package/docs/ADS.md +585 -565
- package/docs/ARCHITECTURE.md +2002 -1384
- package/docs/ASSETS.md +487 -0
- package/docs/BEHAVIORS.md +339 -370
- package/docs/CACHING.md +365 -154
- package/docs/CHANGELOG.md +462 -21
- package/docs/COMPARISON.md +21 -26
- package/docs/DESIGN-REFERENCES.md +40 -27
- package/docs/GUIDE.md +2473 -1292
- package/docs/LANGUAGE.md +1159 -0
- package/docs/LOWERING.md +180 -0
- package/docs/MCP.md +1461 -1179
- package/docs/MOTION.md +491 -0
- package/docs/PROFILE-KINDS.md +544 -0
- package/docs/PROFILES.md +176 -0
- package/docs/RULES.md +590 -0
- package/docs/TOKEN-ROLES.md +377 -0
- package/docs/benchmarks/README.md +26 -27
- package/package.json +59 -45
- package/dist/a11y.mjs +0 -187
- package/dist/assets.mjs +0 -159
- package/dist/atomic-composition.mjs +0 -337
- package/dist/atomic-trace.mjs +0 -162
- package/dist/behavior-libraries.mjs +0 -174
- package/dist/behaviors.mjs +0 -306
- package/dist/brand-assets.mjs +0 -458
- package/dist/brands.mjs +0 -141
- package/dist/component-contrast.mjs +0 -256
- package/dist/construction-styles.cjs +0 -10
- package/dist/contracts/foundation.json +0 -211
- package/dist/contracts/tokens.json +0 -52
- package/dist/contracts.d.mts +0 -30
- package/dist/contrast-composition.mjs +0 -80
- package/dist/contrast-styles.mjs +0 -88
- package/dist/control-padding.mjs +0 -113
- package/dist/css-values.mjs +0 -27
- package/dist/declarative-flow.mjs +0 -244
- package/dist/design-values.mjs +0 -173
- package/dist/font-rules.mjs +0 -108
- package/dist/fonts-generated.mjs +0 -112
- package/dist/foundation-views.mjs +0 -242
- package/dist/foundation.mjs +0 -154
- package/dist/generated-entries.mjs +0 -198
- package/dist/html.mjs +0 -30
- package/dist/icons.mjs +0 -154
- package/dist/image-attributes.mjs +0 -187
- package/dist/image-size.mjs +0 -28
- package/dist/layers.mjs +0 -461
- package/dist/layout-widths.mjs +0 -332
- package/dist/linaria/atomic-css.cjs +0 -2
- package/dist/linaria/atomic-styled.cjs +0 -2
- package/dist/linaria/preserve-values.cjs +0 -58
- package/dist/linaria/spatial-inputs.cjs +0 -56
- package/dist/linaria.d.mts +0 -1
- package/dist/linaria.mjs +0 -9
- package/dist/lockup-composition.mjs +0 -44
- package/dist/lockup-model.cjs +0 -64
- package/dist/paint-contracts.mjs +0 -216
- package/dist/pictograms.mjs +0 -52
- package/dist/public-api.mjs +0 -121
- package/dist/public-props.mjs +0 -91
- package/dist/render-audit/axe-run.mjs +0 -17
- package/dist/render-audit/first-render.mjs +0 -40
- package/dist/render-audit/image-shape.mjs +0 -46
- package/dist/render-audit/layout-overflow.mjs +0 -167
- package/dist/render-audit/layout-shift.mjs +0 -32
- package/dist/render-audit/non-text-contrast.mjs +0 -151
- package/dist/render-audit/pictograms.mjs +0 -88
- package/dist/render-color-probe.mjs +0 -202
- package/dist/render-composition.mjs +0 -186
- package/dist/runtime-contracts.mjs +0 -506
- package/dist/scenario-program.mjs +0 -19
- package/dist/scenario-selectors.mjs +0 -237
- package/dist/scenario-slots.mjs +0 -217
- package/dist/scenario-trace.mjs +0 -314
- package/dist/scenarios-vite.d.mts +0 -2
- package/dist/scenarios-vite.mjs +0 -2
- package/dist/scenarios.mjs +0 -616
- package/dist/selector-match.mjs +0 -94
- package/dist/showcase/comparison.js +0 -48
- package/dist/showcase/connection.js +0 -10
- package/dist/showcase/draft-navigation.js +0 -59
- package/dist/showcase/foundation-view.css +0 -58
- package/dist/showcase/foundation-view.mjs +0 -255
- package/dist/showcase/guide-controls.ads.review.mjs +0 -32
- package/dist/showcase/http-connection.js +0 -86
- package/dist/showcase/http-preview.js +0 -81
- package/dist/showcase/icons.js +0 -2
- package/dist/showcase/navigation.js +0 -13
- package/dist/showcase/pictogram-view.mjs +0 -53
- package/dist/showcase/preview-frame.ads.review.css +0 -46
- package/dist/showcase/preview-frame.ads.review.d.mts +0 -11
- package/dist/showcase/preview-frame.ads.review.mjs +0 -22
- package/dist/showcase/preview-state.js +0 -11
- package/dist/showcase/refresh-scheduler.js +0 -23
- package/dist/showcase/resource-reader.js +0 -37
- package/dist/showcase-coverage.mjs +0 -139
- package/dist/source-symbols.mjs +0 -4
- package/dist/spatial-composition.mjs +0 -322
- package/dist/spatial-contexts.cjs +0 -56
- package/dist/spatial-css.cjs +0 -351
- package/dist/spatial-inputs.cjs +0 -80
- package/dist/spatial-model.cjs +0 -322
- package/dist/spatial.mjs +0 -21
- package/dist/stage-timing.cjs +0 -21
- package/dist/starters/preact/design-system/patterns/Conversation/Conversation.tsx +0 -105
- package/dist/starters/preact/design-system/patterns/Shell/Shell.tsx +0 -275
- package/dist/starters/preact/design-system/review/demo-frame/DemoFrame.ads.review.tsx +0 -7
- package/dist/starters/preact/design-system/review/screen-frame/ScreenFrame.ads.review.tsx +0 -10
- package/dist/starters/preact/design-system/showcase/mcp/main.ads.mount.tsx +0 -8
- package/dist/starters/preact/ds.config.json +0 -37
- package/dist/starters/preact/package.json +0 -35
- package/dist/starters/preact/src/vite-env.d.ts +0 -7
- package/dist/starters/preact/tsconfig.json +0 -35
- package/dist/starters/preact/vite.config.ts +0 -23
- package/dist/starters/react/ADS.md +0 -286
- package/dist/starters/react/README.md +0 -184
- package/dist/starters/react/biome.css.json +0 -21
- package/dist/starters/react/design-system/assets/brand/README.md +0 -41
- package/dist/starters/react/design-system/assets/brand/app-icon.svg +0 -4
- package/dist/starters/react/design-system/assets/brand/logo.dark.svg +0 -6
- package/dist/starters/react/design-system/assets/brand/logo.svg +0 -6
- package/dist/starters/react/design-system/assets/glyphs/README.md +0 -15
- package/dist/starters/react/design-system/assets/glyphs/aliases.json +0 -1
- package/dist/starters/react/design-system/assets/glyphs/check.svg +0 -1
- package/dist/starters/react/design-system/assets/glyphs/chevron-down.svg +0 -1
- package/dist/starters/react/design-system/assets/glyphs/chevron-right.svg +0 -1
- package/dist/starters/react/design-system/assets/glyphs/close.svg +0 -1
- package/dist/starters/react/design-system/assets/glyphs/external-link.svg +0 -1
- package/dist/starters/react/design-system/assets/glyphs/info.svg +0 -1
- package/dist/starters/react/design-system/assets/glyphs/menu.svg +0 -1
- package/dist/starters/react/design-system/assets/glyphs/plus.svg +0 -1
- package/dist/starters/react/design-system/assets/glyphs/search.svg +0 -1
- package/dist/starters/react/design-system/assets/glyphs/warning.svg +0 -1
- package/dist/starters/react/design-system/assets/pictograms/catalog.ads.json +0 -13
- package/dist/starters/react/design-system/assets/pictograms/journey.dark.svg +0 -7
- package/dist/starters/react/design-system/assets/pictograms/journey.svg +0 -7
- package/dist/starters/react/design-system/components/Actions/Button/Button.ads.exports.ts +0 -1
- package/dist/starters/react/design-system/components/Actions/Button/Button.ads.fixture.ts +0 -1
- package/dist/starters/react/design-system/components/Actions/Button/Button.ads.scenario.tsx +0 -13
- package/dist/starters/react/design-system/components/Actions/Button/Button.tsx +0 -56
- package/dist/starters/react/design-system/components/Actions/Button/README.md +0 -12
- package/dist/starters/react/design-system/components/Actions/IconButton/IconButton.ads.exports.ts +0 -1
- package/dist/starters/react/design-system/components/Actions/IconButton/IconButton.ads.fixture.ts +0 -9
- package/dist/starters/react/design-system/components/Actions/IconButton/IconButton.ads.scenario.tsx +0 -16
- package/dist/starters/react/design-system/components/Actions/IconButton/IconButton.tsx +0 -60
- package/dist/starters/react/design-system/components/Actions/IconButton/README.md +0 -17
- package/dist/starters/react/design-system/components/Content/Icon/Icon.ads.exports.ts +0 -1
- package/dist/starters/react/design-system/components/Content/Icon/Icon.ads.fixture.ts +0 -6
- package/dist/starters/react/design-system/components/Content/Icon/Icon.ads.scenario.tsx +0 -16
- package/dist/starters/react/design-system/components/Content/Icon/Icon.tsx +0 -42
- package/dist/starters/react/design-system/components/Content/Icon/README.md +0 -17
- package/dist/starters/react/design-system/components/Content/Icon/glyphs.ts +0 -17
- package/dist/starters/react/design-system/components/Content/Image/Image.ads.exports.ts +0 -1
- package/dist/starters/react/design-system/components/Content/Image/Image.ads.fixture.ts +0 -2
- package/dist/starters/react/design-system/components/Content/Image/Image.ads.scenario.tsx +0 -13
- package/dist/starters/react/design-system/components/Content/Image/Image.tsx +0 -51
- package/dist/starters/react/design-system/components/Content/Image/README.md +0 -20
- package/dist/starters/react/design-system/components/Content/Logo/Logo.ads.exports.ts +0 -1
- package/dist/starters/react/design-system/components/Content/Logo/Logo.ads.fixture.ts +0 -1
- package/dist/starters/react/design-system/components/Content/Logo/Logo.ads.scenario.tsx +0 -12
- package/dist/starters/react/design-system/components/Content/Logo/Logo.tsx +0 -35
- package/dist/starters/react/design-system/components/Content/Logo/README.md +0 -12
- package/dist/starters/react/design-system/components/Content/Pictogram/Pictogram.ads.exports.ts +0 -1
- package/dist/starters/react/design-system/components/Content/Pictogram/Pictogram.ads.fixture.ts +0 -1
- package/dist/starters/react/design-system/components/Content/Pictogram/Pictogram.ads.scenario.tsx +0 -7
- package/dist/starters/react/design-system/components/Content/Pictogram/Pictogram.tsx +0 -26
- package/dist/starters/react/design-system/components/Forms/TextField/README.md +0 -14
- package/dist/starters/react/design-system/components/Forms/TextField/TextField.ads.exports.ts +0 -1
- package/dist/starters/react/design-system/components/Forms/TextField/TextField.ads.fixture.ts +0 -6
- package/dist/starters/react/design-system/components/Forms/TextField/TextField.ads.scenario.tsx +0 -13
- package/dist/starters/react/design-system/components/Forms/TextField/TextField.tsx +0 -61
- package/dist/starters/react/design-system/composition/Search/SearchPage/README.md +0 -4
- package/dist/starters/react/design-system/composition/Search/SearchPage/SearchPage.ads.fixture.ts +0 -7
- package/dist/starters/react/design-system/composition/Search/SearchPage/SearchPage.ads.scenario.tsx +0 -16
- package/dist/starters/react/design-system/composition/Workspace/WorkspacePage/README.md +0 -5
- package/dist/starters/react/design-system/composition/Workspace/WorkspacePage/WorkspacePage.ads.fixture.ts +0 -13
- package/dist/starters/react/design-system/composition/Workspace/WorkspacePage/WorkspacePage.ads.scenario.tsx +0 -22
- package/dist/starters/react/design-system/controllers/Palette/Palette.ads.exports.ts +0 -1
- package/dist/starters/react/design-system/controllers/Palette/Palette.ts +0 -164
- package/dist/starters/react/design-system/index.ts +0 -12
- package/dist/starters/react/design-system/patterns/Conversation/Conversation.ads.exports.ts +0 -1
- package/dist/starters/react/design-system/patterns/Conversation/Conversation.ads.fixture.ts +0 -7
- package/dist/starters/react/design-system/patterns/Conversation/Conversation.ads.scenario.tsx +0 -15
- package/dist/starters/react/design-system/patterns/Conversation/Conversation.tsx +0 -105
- package/dist/starters/react/design-system/patterns/Conversation/README.md +0 -9
- package/dist/starters/react/design-system/patterns/Search/SearchBar/README.md +0 -12
- package/dist/starters/react/design-system/patterns/Search/SearchBar/SearchBar.ads.exports.ts +0 -1
- package/dist/starters/react/design-system/patterns/Search/SearchBar/SearchBar.ads.fixture.ts +0 -1
- package/dist/starters/react/design-system/patterns/Search/SearchBar/SearchBar.ads.scenario.tsx +0 -11
- package/dist/starters/react/design-system/patterns/Search/SearchBar/SearchBar.tsx +0 -41
- package/dist/starters/react/design-system/patterns/Shell/Floating.ads.fixture.ts +0 -5
- package/dist/starters/react/design-system/patterns/Shell/Floating.ads.scenario.tsx +0 -21
- package/dist/starters/react/design-system/patterns/Shell/README.md +0 -43
- package/dist/starters/react/design-system/patterns/Shell/Shell.ads.exports.ts +0 -1
- package/dist/starters/react/design-system/patterns/Shell/Shell.ads.fixture.ts +0 -5
- package/dist/starters/react/design-system/patterns/Shell/Shell.ads.scenario.tsx +0 -21
- package/dist/starters/react/design-system/patterns/Shell/Shell.tsx +0 -274
- package/dist/starters/react/design-system/review/demo-frame/DemoFrame.ads.exports.ts +0 -1
- package/dist/starters/react/design-system/review/demo-frame/DemoFrame.ads.review.tsx +0 -7
- package/dist/starters/react/design-system/review/index.ads.review.ts +0 -4
- package/dist/starters/react/design-system/review/region-block/RegionBlock.ads.exports.ts +0 -1
- package/dist/starters/react/design-system/review/region-block/RegionBlock.ads.review.tsx +0 -6
- package/dist/starters/react/design-system/review/screen-frame/ScreenFrame.ads.exports.ts +0 -1
- package/dist/starters/react/design-system/review/screen-frame/ScreenFrame.ads.review.tsx +0 -10
- package/dist/starters/react/design-system/showcase/mcp/main.ads.mount.tsx +0 -10
- package/dist/starters/react/design-system/styles.css +0 -7
- package/dist/starters/react/design-system/tokens/base.css +0 -36
- package/dist/starters/react/design-system/tokens/catalog.ads.json +0 -1221
- package/dist/starters/react/design-system/tokens/colors.css +0 -215
- package/dist/starters/react/design-system/tokens/elevation.css +0 -53
- package/dist/starters/react/design-system/tokens/spacing.css +0 -87
- package/dist/starters/react/design-system/tokens/spatial.ads.json +0 -70
- package/dist/starters/react/design-system/tokens/themes.generated.css +0 -142
- package/dist/starters/react/design-system/tokens/themes.generated.ts +0 -402
- package/dist/starters/react/design-system/tokens/typography.css +0 -31
- package/dist/starters/react/ds.config.json +0 -37
- package/dist/starters/react/gitignore.template +0 -8
- package/dist/starters/react/package.json +0 -39
- package/dist/starters/react/scripts/build-mcp-previews.mjs +0 -3
- package/dist/starters/react/src/vite-env.d.ts +0 -7
- package/dist/starters/react/tsconfig.build.json +0 -20
- package/dist/starters/react/tsconfig.json +0 -34
- package/dist/starters/react/vite.config.ts +0 -23
- package/dist/style-boundaries.mjs +0 -106
- package/dist/style-token-rules.mjs +0 -51
- package/dist/themes-generated.mjs +0 -161
- package/dist/themes-watch.mjs +0 -83
- package/dist/themes.mjs +0 -360
- package/dist/token-export.mjs +0 -94
- package/dist/token-origins.mjs +0 -24
- package/dist/token-policy.mjs +0 -26
- package/dist/token-quality.mjs +0 -149
- package/dist/token-samples.mjs +0 -19
- package/dist/tokens.mjs +0 -194
- package/dist/unit-contracts.mjs +0 -396
- package/dist/usage.mjs +0 -184
- package/dist/verification/playwright-reporter.cjs +0 -87
- package/docs/CONTRACTS.md +0 -285
- package/docs/HTTP-SHOWCASE-POC.md +0 -397
- package/docs/SPATIAL-CHECKS.md +0 -69
- package/docs/benchmarks/http-showcase-optimized.json +0 -1879
- package/docs/benchmarks/http-showcase-profile.json +0 -308
- package/docs/benchmarks/http-showcase.json +0 -3069
- /package/dist/{starters/react/design-system/assets/fonts/.gitkeep → analysis/semantic.mjs} +0 -0
- /package/dist/{starters/react/design-system/controllers/.gitkeep → lowering-model.mjs} +0 -0
- /package/dist/showcase/{favicon.svg → ui/favicon-scavmehf.svg} +0 -0
package/dist/resource-limits.mjs
CHANGED
|
@@ -3,44 +3,28 @@ import { existsSync, mkdtempSync, readFileSync, readdirSync, rmSync, writeFileSy
|
|
|
3
3
|
import os from "node:os";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import { fileURLToPath } from "node:url";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
new Promise((resolve) =>
|
|
10
|
-
execFile(command, args, { timeout: 5000, windowsHide: true, maxBuffer: 8 * MiB }, (error, stdout) => resolve(error ? null : stdout)),
|
|
11
|
-
);
|
|
12
|
-
|
|
6
|
+
const MiB = 1048576, MIN_BUDGET_MB = 64, MAX_BUDGET_MB = 1048576, enforcements = ["cgroup", "inherited-cgroup", "watchdog"], isEnforcement = (value) => enforcements.some((item) => item === value), execute = (command, args) => new Promise((resolve) => {
|
|
7
|
+
execFile(command, args, { timeout: 5000, windowsHide: !0, maxBuffer: 8 * MiB }, (error, stdout) => resolve(error ? null : stdout));
|
|
8
|
+
});
|
|
13
9
|
function hostMemory() {
|
|
14
|
-
let available = os.freemem(),
|
|
15
|
-
parentLimit = Infinity;
|
|
10
|
+
let available = os.freemem(), parentLimit = 1 / 0;
|
|
16
11
|
if (process.platform === "linux") {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
if (value !== "max") parentLimit = Math.min(parentLimit, Number(value));
|
|
29
|
-
} catch {
|
|
30
|
-
/* Not every ancestor has a memory controller. */
|
|
31
|
-
}
|
|
32
|
-
if (folder === "/sys/fs/cgroup") break;
|
|
33
|
-
folder = path.dirname(folder);
|
|
12
|
+
const reported = /^MemAvailable:\s+(\d+)/m.exec(readOptional("/proc/meminfo") ?? "")?.[1];
|
|
13
|
+
if (reported !== void 0)
|
|
14
|
+
available = Number(reported) * 1024;
|
|
15
|
+
const group = /^0::(.*)$/m.exec(readOptional("/proc/self/cgroup") ?? "")?.[1];
|
|
16
|
+
if (group !== void 0)
|
|
17
|
+
for (let folder = path.join("/sys/fs/cgroup", group);folder.startsWith("/sys/fs/cgroup"); folder = path.dirname(folder)) {
|
|
18
|
+
const value = readOptional(path.join(folder, "memory.max"))?.trim();
|
|
19
|
+
if (value !== void 0 && value !== "max")
|
|
20
|
+
parentLimit = Math.min(parentLimit, Number(value));
|
|
21
|
+
if (folder === "/sys/fs/cgroup")
|
|
22
|
+
break;
|
|
34
23
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
} else if (process.platform === "darwin") available = darwinAvailable() ?? available;
|
|
24
|
+
} else if (process.platform === "darwin")
|
|
25
|
+
available = darwinAvailable() ?? available;
|
|
39
26
|
return { totalMb: os.totalmem() / MiB, availableMb: available / MiB, parentLimitMb: parentLimit / MiB };
|
|
40
27
|
}
|
|
41
|
-
|
|
42
|
-
// macOS's free memory excludes inactive, speculative and purgeable pages the
|
|
43
|
-
// kernel reclaims on demand, so os.freemem() alone understates what is available.
|
|
44
28
|
function darwinAvailable() {
|
|
45
29
|
try {
|
|
46
30
|
return parseDarwinAvailable(execFileSync("vm_stat", { timeout: 2000, encoding: "utf8" }));
|
|
@@ -48,253 +32,220 @@ function darwinAvailable() {
|
|
|
48
32
|
return null;
|
|
49
33
|
}
|
|
50
34
|
}
|
|
51
|
-
|
|
52
|
-
/** Parse vm_stat output (exported for tests). */
|
|
53
35
|
export function parseDarwinAvailable(text) {
|
|
54
|
-
const page = Number(
|
|
55
|
-
pages = (name) => Number(text.match(new RegExp(`^Pages ${name}:\\s+(\\d+)`, "m"))?.[1] ?? 0);
|
|
36
|
+
const page = Number(/page size of (\d+) bytes/.exec(text)?.[1]), pages = (name) => Number(new RegExp(`^Pages ${name}:\\s+(\\d+)`, "m").exec(text)?.[1] ?? 0);
|
|
56
37
|
return page ? (pages("free") + pages("inactive") + pages("speculative") + pages("purgeable")) * page : null;
|
|
57
38
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
const automatic = Math.max(128, Math.floor(Math.min(6144, Math.max(floor, Math.min(host.totalMb / 4, host.availableMb - 1024)))));
|
|
67
|
-
return Math.max(
|
|
39
|
+
function readOptional(file) {
|
|
40
|
+
try {
|
|
41
|
+
return readFileSync(file, "utf8");
|
|
42
|
+
} catch {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
export function resolveMemoryBudget(resources = {}, host = hostMemory()) {
|
|
47
|
+
const floor = Math.min(3072, host.totalMb / 2), automatic = Math.max(128, Math.floor(Math.min(6144, Math.max(floor, Math.min(host.totalMb / 4, host.availableMb - 1024)))));
|
|
48
|
+
return Math.max(MIN_BUDGET_MB, Math.floor(Math.min(resources.memoryLimitMb ?? automatic, host.parentLimitMb ?? 1 / 0)));
|
|
68
49
|
}
|
|
69
|
-
|
|
70
50
|
function inheritedScope() {
|
|
71
|
-
const folder = process.env.ADS_MEMORY_SCOPE;
|
|
72
|
-
|
|
73
|
-
return folder &&
|
|
74
|
-
Number.isInteger(budget) &&
|
|
75
|
-
budget >= 64 &&
|
|
76
|
-
["cgroup", "inherited-cgroup", "watchdog"].includes(process.env.ADS_MEMORY_ENFORCEMENT) &&
|
|
77
|
-
path.basename(folder).startsWith("ads-memory-") &&
|
|
78
|
-
existsSync(folder)
|
|
79
|
-
? folder
|
|
80
|
-
: null;
|
|
51
|
+
const folder = process.env.ADS_MEMORY_SCOPE, budget = Number(process.env.ADS_MEMORY_LIMIT_MB), enforcement = process.env.ADS_MEMORY_ENFORCEMENT;
|
|
52
|
+
return folder && Number.isInteger(budget) && budget >= MIN_BUDGET_MB && isEnforcement(enforcement) && path.basename(folder).startsWith("ads-memory-") && existsSync(folder) ? { folder, budget, enforcement } : null;
|
|
81
53
|
}
|
|
82
|
-
|
|
83
54
|
export function resourceLimitsStatus(resources) {
|
|
84
55
|
const inherited = inheritedScope();
|
|
85
|
-
return {
|
|
86
|
-
memoryLimitMb: inherited ? Number(process.env.ADS_MEMORY_LIMIT_MB) : resolveMemoryBudget(resources),
|
|
87
|
-
enforcement: inherited ? process.env.ADS_MEMORY_ENFORCEMENT : "host-managed",
|
|
88
|
-
scope: inherited ? "ADS command and descendants" : "embedding host",
|
|
89
|
-
hardLimit: !!inherited && ["cgroup", "inherited-cgroup"].includes(process.env.ADS_MEMORY_ENFORCEMENT),
|
|
90
|
-
};
|
|
56
|
+
return inherited ? { memoryLimitMb: inherited.budget, enforcement: inherited.enforcement, scope: "ADS command and descendants", hardLimit: inherited.enforcement !== "watchdog" } : { memoryLimitMb: resolveMemoryBudget(resources), enforcement: "host-managed", scope: "embedding host", hardLimit: !1 };
|
|
91
57
|
}
|
|
92
|
-
|
|
93
58
|
async function processes() {
|
|
94
59
|
if (process.platform === "linux") {
|
|
95
|
-
const values = new Map
|
|
96
|
-
for (const name of readdirSync("/proc"))
|
|
97
|
-
if (
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
60
|
+
const values = new Map;
|
|
61
|
+
for (const name of readdirSync("/proc")) {
|
|
62
|
+
if (!/^\d+$/.test(name))
|
|
63
|
+
continue;
|
|
64
|
+
const text = readOptional(`/proc/${name}/stat`);
|
|
65
|
+
if (text === void 0)
|
|
66
|
+
continue;
|
|
67
|
+
const fields = text.slice(text.lastIndexOf(")") + 2).split(" ");
|
|
68
|
+
values.set(Number(name), { parent: Number(fields[1]), start: fields[19] ?? "" });
|
|
69
|
+
}
|
|
105
70
|
return values;
|
|
106
71
|
}
|
|
107
|
-
const output =
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
);
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
const [pid, parent, rss, ...date] = line.trim().split(/\s+/);
|
|
129
|
-
return [Number(pid), { parent: Number(parent), rss: Number(rss) * 1024, start: date.join(" ") }];
|
|
130
|
-
}),
|
|
131
|
-
);
|
|
72
|
+
const output = process.platform === "win32" ? await execute("powershell.exe", [
|
|
73
|
+
"-NoProfile",
|
|
74
|
+
"-Command",
|
|
75
|
+
"Get-CimInstance Win32_Process | Select-Object ProcessId,ParentProcessId,WorkingSetSize,CreationDate | ConvertTo-Json -Compress"
|
|
76
|
+
]) : await execute("ps", ["-axo", "pid=,ppid=,rss=,lstart="]);
|
|
77
|
+
if (output === null)
|
|
78
|
+
throw Error("Cannot sample process-tree memory.");
|
|
79
|
+
if (process.platform === "win32") {
|
|
80
|
+
const rows = JSON.parse(output);
|
|
81
|
+
return new Map([rows].flat().flatMap((row) => {
|
|
82
|
+
if (typeof row !== "object" || row === null)
|
|
83
|
+
return [];
|
|
84
|
+
const field = (name) => Reflect.get(row, name);
|
|
85
|
+
return [[Number(field("ProcessId")), { parent: Number(field("ParentProcessId")), rss: Number(field("WorkingSetSize")), start: String(field("CreationDate")) }]];
|
|
86
|
+
}));
|
|
87
|
+
}
|
|
88
|
+
return new Map(output.trim().split(`
|
|
89
|
+
`).filter(Boolean).map((line) => {
|
|
90
|
+
const [pid, parent, rss, ...date] = line.trim().split(/\s+/);
|
|
91
|
+
return [Number(pid), { parent: Number(parent), rss: Number(rss) * 1024, start: date.join(" ") }];
|
|
92
|
+
}));
|
|
132
93
|
}
|
|
133
|
-
|
|
134
|
-
export async function sampleMemoryTree(pid, owned = new Map()) {
|
|
94
|
+
export async function sampleMemoryTree(pid, owned = new Map) {
|
|
135
95
|
const current = await processes();
|
|
136
|
-
for (const [id, start] of owned)
|
|
137
|
-
|
|
138
|
-
|
|
96
|
+
for (const [id, start] of owned)
|
|
97
|
+
if (current.get(id)?.start !== start)
|
|
98
|
+
owned.delete(id);
|
|
99
|
+
const root = current.get(pid);
|
|
100
|
+
if (root)
|
|
101
|
+
owned.set(pid, root.start);
|
|
102
|
+
for (let pass = 0;pass < 100; pass++) {
|
|
139
103
|
const before = owned.size;
|
|
140
|
-
for (const [id, value] of current)
|
|
141
|
-
|
|
104
|
+
for (const [id, value] of current)
|
|
105
|
+
if (owned.has(value.parent))
|
|
106
|
+
owned.set(id, value.start);
|
|
107
|
+
if (owned.size === before)
|
|
108
|
+
break;
|
|
142
109
|
}
|
|
143
110
|
let bytes = 0;
|
|
144
|
-
for (const id of owned.keys())
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
111
|
+
for (const id of owned.keys()) {
|
|
112
|
+
const sample = current.get(id);
|
|
113
|
+
if (!sample)
|
|
114
|
+
continue;
|
|
115
|
+
bytes += sample.rss ?? Number(/^VmRSS:\s+(\d+)/m.exec(readOptional(`/proc/${id}/status`) ?? "")?.[1] ?? 0) * 1024;
|
|
116
|
+
}
|
|
150
117
|
return { bytes, owned };
|
|
151
118
|
}
|
|
152
|
-
|
|
153
|
-
/** Dedicated CLI supervision; embedded APIs retain their host's resource policy. */
|
|
154
|
-
export async function runWithMemoryBudget(command, args, { cwd = process.cwd(), memoryLimitMb, kernel = true } = {}) {
|
|
119
|
+
export async function runWithMemoryBudget(command, args, { cwd = process.cwd(), memoryLimitMb, kernel = !0 } = {}) {
|
|
155
120
|
const budget = memoryLimitMb ?? resolveMemoryBudget();
|
|
156
|
-
if (!Number.isInteger(budget) || budget <
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
let interrupted = false,
|
|
161
|
-
exceeded = false,
|
|
162
|
-
monitorError = false,
|
|
163
|
-
child,
|
|
164
|
-
guard,
|
|
165
|
-
observing = false,
|
|
166
|
-
timer,
|
|
167
|
-
peak = 0;
|
|
121
|
+
if (!Number.isInteger(budget) || budget < MIN_BUDGET_MB || budget > MAX_BUDGET_MB)
|
|
122
|
+
throw Error("A process memory budget must be 64\u20131048576 MiB.");
|
|
123
|
+
const folder = mkdtempSync(path.join(os.tmpdir(), "ads-memory-")), marker = path.join(folder, "started.json"), unit = `ads-memory-${process.pid}-${path.basename(folder).slice(-6)}.scope`;
|
|
124
|
+
let interrupted = !1, exceeded = !1, monitorError = !1, guard, observing = !1, timer, peak = 0;
|
|
168
125
|
const stop = () => {
|
|
169
|
-
interrupted =
|
|
170
|
-
guard?.stdin.end(
|
|
126
|
+
interrupted = !0;
|
|
127
|
+
guard?.stdin.end(`cleanup
|
|
128
|
+
`);
|
|
171
129
|
};
|
|
172
|
-
for (const signal of ["SIGINT", "SIGTERM"])
|
|
130
|
+
for (const signal of ["SIGINT", "SIGTERM"])
|
|
131
|
+
process.on(signal, stop);
|
|
173
132
|
async function launch(mode) {
|
|
174
133
|
const enforced = mode === "cgroup";
|
|
175
|
-
let pending = "",
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
`--unit=${unit}`,
|
|
187
|
-
"-p",
|
|
188
|
-
`MemoryMax=${budget}M`,
|
|
189
|
-
"-p",
|
|
190
|
-
"MemorySwapMax=0",
|
|
191
|
-
"-p",
|
|
192
|
-
"OOMPolicy=kill",
|
|
193
|
-
"--",
|
|
194
|
-
command,
|
|
195
|
-
...args,
|
|
196
|
-
]
|
|
197
|
-
: args,
|
|
198
|
-
{ cwd, env, stdio: ["inherit", "inherit", "pipe"], detached: process.platform !== "win32", windowsHide: true },
|
|
199
|
-
);
|
|
200
|
-
const active = child;
|
|
201
|
-
if (child.pid) {
|
|
202
|
-
guard = spawn(process.execPath, [fileURLToPath(new URL("./mcp/preview-owner-guard.mjs", import.meta.url)), String(child.pid), "--tree"], {
|
|
203
|
-
stdio: ["pipe", "ignore", "ignore"],
|
|
204
|
-
windowsHide: true,
|
|
205
|
-
});
|
|
206
|
-
guard.stdin.on("error", () => {});
|
|
207
|
-
guard.on("error", () => {
|
|
208
|
-
monitorError = true;
|
|
209
|
-
active.kill("SIGKILL");
|
|
210
|
-
});
|
|
211
|
-
guard.once("exit", () => {
|
|
212
|
-
if (!done && !interrupted && !exceeded && !monitorError) {
|
|
213
|
-
monitorError = true;
|
|
214
|
-
active.kill("SIGKILL");
|
|
215
|
-
}
|
|
216
|
-
});
|
|
217
|
-
if (mode === "watchdog") {
|
|
218
|
-
const owned = new Map();
|
|
219
|
-
timer = setInterval(async () => {
|
|
220
|
-
if (observing) return;
|
|
221
|
-
observing = true;
|
|
222
|
-
try {
|
|
223
|
-
const { bytes } = await sampleMemoryTree(active.pid, owned);
|
|
224
|
-
peak = Math.max(peak, bytes);
|
|
225
|
-
if (bytes > budget * MiB) {
|
|
226
|
-
exceeded = true;
|
|
227
|
-
guard.stdin.end("kill\n");
|
|
228
|
-
}
|
|
229
|
-
} catch {
|
|
230
|
-
monitorError = true;
|
|
231
|
-
guard.stdin.end("kill\n");
|
|
232
|
-
} finally {
|
|
233
|
-
observing = false;
|
|
234
|
-
}
|
|
235
|
-
}, 200);
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
function forward(bytes) {
|
|
134
|
+
let pending = "", started = !1, done = !1;
|
|
135
|
+
const env = { ...process.env, ADS_MEMORY_SCOPE: folder, ADS_MEMORY_LIMIT_MB: String(budget), ADS_MEMORY_ENFORCEMENT: mode }, scope = ["--user", "--scope", "--quiet", `--unit=${unit}`, "-p", `MemoryMax=${budget}M`, "-p", "MemorySwapMax=0", "-p", "OOMPolicy=kill", "--", command, ...args], child = spawn(enforced ? "systemd-run" : command, enforced ? scope : [...args], {
|
|
136
|
+
cwd,
|
|
137
|
+
env,
|
|
138
|
+
stdio: ["inherit", "inherit", "pipe"],
|
|
139
|
+
detached: process.platform !== "win32",
|
|
140
|
+
windowsHide: !0
|
|
141
|
+
});
|
|
142
|
+
if (child.pid !== void 0)
|
|
143
|
+
supervise(child, child.pid, mode, () => done);
|
|
144
|
+
const forward = (bytes) => {
|
|
239
145
|
if (!process.stderr.write(bytes)) {
|
|
240
|
-
|
|
241
|
-
process.stderr.once("drain", () =>
|
|
146
|
+
child.stderr.pause();
|
|
147
|
+
process.stderr.once("drain", () => child.stderr.resume());
|
|
242
148
|
}
|
|
243
|
-
}
|
|
149
|
+
};
|
|
244
150
|
child.stderr.on("data", (bytes) => {
|
|
245
151
|
if (!enforced || started || existsSync(marker)) {
|
|
246
|
-
started =
|
|
152
|
+
started = !0;
|
|
247
153
|
if (pending) {
|
|
248
154
|
forward(pending);
|
|
249
155
|
pending = "";
|
|
250
156
|
}
|
|
251
157
|
forward(bytes);
|
|
252
|
-
} else
|
|
158
|
+
} else
|
|
159
|
+
pending = (pending + bytes.toString()).slice(-8000);
|
|
253
160
|
});
|
|
254
161
|
const result = await new Promise((resolve) => {
|
|
255
162
|
child.once("error", (error) => resolve({ code: 1, error }));
|
|
256
163
|
child.once("close", (code, signal) => resolve({ code: code ?? (signal ? 1 : 0), signal }));
|
|
257
164
|
});
|
|
258
|
-
done =
|
|
165
|
+
done = !0;
|
|
259
166
|
clearInterval(timer);
|
|
260
|
-
guard?.stdin.end(
|
|
261
|
-
|
|
262
|
-
if (
|
|
167
|
+
guard?.stdin.end(`cleanup
|
|
168
|
+
`);
|
|
169
|
+
if (enforced && !existsSync(marker) && !interrupted)
|
|
170
|
+
return null;
|
|
171
|
+
if (pending)
|
|
172
|
+
forward(pending);
|
|
263
173
|
if (enforced) {
|
|
264
|
-
|
|
265
|
-
exceeded = status?.trim() === "oom-kill";
|
|
174
|
+
exceeded = (await execute("systemctl", ["--user", "show", unit, "--property=Result", "--value"]))?.trim() === "oom-kill";
|
|
266
175
|
await execute("systemctl", ["--user", "reset-failed", unit]);
|
|
267
176
|
}
|
|
268
177
|
if (exceeded)
|
|
269
|
-
process.stderr.write(
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
178
|
+
process.stderr.write(`ADS_MEMORY_LIMIT: ADS command exceeded its ${budget} MiB process-tree memory budget${peak ? ` (sampled ${Math.ceil(peak / MiB)} MiB RSS)` : ""}. This invocation failed; inspect retained results before retrying.
|
|
179
|
+
`);
|
|
180
|
+
if (monitorError)
|
|
181
|
+
process.stderr.write(`ADS_MEMORY_MONITOR_FAILED: resource supervision failed; command stopped.
|
|
182
|
+
`);
|
|
273
183
|
return exceeded || monitorError ? 1 : interrupted ? 0 : result.code;
|
|
274
184
|
}
|
|
185
|
+
function supervise(active, pid, mode, finished) {
|
|
186
|
+
const owner = spawn(process.execPath, [fileURLToPath(new URL("./mcp/preview-owner-guard.mjs", import.meta.url)), String(pid), "--tree"], {
|
|
187
|
+
stdio: ["pipe", "ignore", "ignore"],
|
|
188
|
+
windowsHide: !0
|
|
189
|
+
});
|
|
190
|
+
guard = owner;
|
|
191
|
+
owner.stdin.on("error", () => {});
|
|
192
|
+
owner.on("error", () => {
|
|
193
|
+
monitorError = !0;
|
|
194
|
+
active.kill("SIGKILL");
|
|
195
|
+
});
|
|
196
|
+
owner.once("exit", () => {
|
|
197
|
+
if (!finished() && !interrupted && !exceeded && !monitorError) {
|
|
198
|
+
monitorError = !0;
|
|
199
|
+
active.kill("SIGKILL");
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
if (mode !== "watchdog")
|
|
203
|
+
return;
|
|
204
|
+
const owned = new Map;
|
|
205
|
+
timer = setInterval(() => {
|
|
206
|
+
if (observing)
|
|
207
|
+
return;
|
|
208
|
+
observing = !0;
|
|
209
|
+
sampleMemoryTree(pid, owned).then(({ bytes }) => {
|
|
210
|
+
peak = Math.max(peak, bytes);
|
|
211
|
+
if (bytes > budget * MiB) {
|
|
212
|
+
exceeded = !0;
|
|
213
|
+
owner.stdin.end(`kill
|
|
214
|
+
`);
|
|
215
|
+
}
|
|
216
|
+
}).catch(() => {
|
|
217
|
+
monitorError = !0;
|
|
218
|
+
owner.stdin.end(`kill
|
|
219
|
+
`);
|
|
220
|
+
}).finally(() => {
|
|
221
|
+
observing = !1;
|
|
222
|
+
});
|
|
223
|
+
}, 200);
|
|
224
|
+
}
|
|
275
225
|
try {
|
|
276
|
-
const parentLimit = hostMemory().parentLimitMb;
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
if (kernel && process.platform === "linux" && Number.isFinite(parentLimit)) return await launch(parentLimit <= budget ? "inherited-cgroup" : "watchdog");
|
|
226
|
+
const parentLimit = hostMemory().parentLimitMb ?? 1 / 0;
|
|
227
|
+
if (kernel && process.platform === "linux" && Number.isFinite(parentLimit))
|
|
228
|
+
return await launch(parentLimit <= budget ? "inherited-cgroup" : "watchdog") ?? 1;
|
|
280
229
|
if (kernel && process.platform === "linux") {
|
|
281
230
|
const result = await launch("cgroup");
|
|
282
|
-
if (result !== null)
|
|
231
|
+
if (result !== null)
|
|
232
|
+
return result;
|
|
283
233
|
}
|
|
284
|
-
return await launch("watchdog");
|
|
234
|
+
return await launch("watchdog") ?? 1;
|
|
285
235
|
} finally {
|
|
286
236
|
clearInterval(timer);
|
|
287
|
-
for (const signal of ["SIGINT", "SIGTERM"])
|
|
288
|
-
|
|
237
|
+
for (const signal of ["SIGINT", "SIGTERM"])
|
|
238
|
+
process.removeListener(signal, stop);
|
|
239
|
+
rmSync(folder, { recursive: !0, force: !0 });
|
|
289
240
|
}
|
|
290
241
|
}
|
|
291
|
-
|
|
292
242
|
export async function enterMemoryBudget(config, args) {
|
|
293
243
|
const inherited = inheritedScope();
|
|
294
244
|
if (inherited) {
|
|
295
|
-
const file = path.join(inherited, "started.json");
|
|
296
|
-
if (!existsSync(file))
|
|
245
|
+
const file = path.join(inherited.folder, "started.json");
|
|
246
|
+
if (!existsSync(file))
|
|
247
|
+
writeFileSync(file, JSON.stringify({ pid: process.pid }));
|
|
297
248
|
return null;
|
|
298
249
|
}
|
|
299
|
-
return runWithMemoryBudget(process.execPath, [process.argv[1], ...args], { memoryLimitMb: resolveMemoryBudget(config.resources) });
|
|
250
|
+
return runWithMemoryBudget(process.execPath, [process.argv[1] ?? "", ...args], { memoryLimitMb: resolveMemoryBudget(config.resources) });
|
|
300
251
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** A success or a typed failure. Failures are values, not thrown control flow. */
|
|
2
|
+
export type Result<T, E> = Ok<T> | Err<E>;
|
|
3
|
+
export interface Ok<T> {
|
|
4
|
+
readonly kind: "ok";
|
|
5
|
+
readonly value: T;
|
|
6
|
+
}
|
|
7
|
+
export interface Err<E> {
|
|
8
|
+
readonly kind: "err";
|
|
9
|
+
readonly error: E;
|
|
10
|
+
}
|
|
11
|
+
export declare const ok: <T>(value: T) => Ok<T>;
|
|
12
|
+
export declare const err: <E>(error: E) => Err<E>;
|
|
13
|
+
/** Exhaustiveness guard for `switch` over a discriminated union. */
|
|
14
|
+
export declare function assertNever(value: never, context: string): never;
|
|
15
|
+
/** Collects successes in order; returns the first failure unchanged. */
|
|
16
|
+
export declare function collect<T, E>(results: Iterable<Result<T, E>>): Result<readonly T[], E>;
|
|
17
|
+
/** Maps a success, leaving a failure unchanged. */
|
|
18
|
+
export declare function map<T, U, E>(result: Result<T, E>, transform: (value: T) => U): Result<U, E>;
|
|
19
|
+
/** Maps a failure, leaving a success unchanged. */
|
|
20
|
+
export declare function mapErr<T, E, F>(result: Result<T, E>, transform: (error: E) => F): Result<T, F>;
|
|
21
|
+
/** Stops the enclosing {@link attempt} with a typed failure. */
|
|
22
|
+
export type Reject<E> = (failure: E) => never;
|
|
23
|
+
/**
|
|
24
|
+
* Runs deeply nested validation that stops at its first failure, returning that
|
|
25
|
+
* failure as a value. The rejection is private to this call: an unrelated
|
|
26
|
+
* exception, or a rejection from another attempt, propagates unchanged.
|
|
27
|
+
*/
|
|
28
|
+
export declare function attempt<T, E>(run: (reject: Reject<E>) => T): Result<T, E>;
|
|
29
|
+
/** {@link attempt} for asynchronous work. */
|
|
30
|
+
export declare function attemptAsync<T, E>(run: (reject: Reject<E>) => Promise<T>): Promise<Result<T, E>>;
|
|
31
|
+
/** Unwraps a result inside an {@link attempt}, translating its failure. */
|
|
32
|
+
export declare function unwrapOr<T, E, F>(result: Result<T, E>, reject: Reject<F>, translate: (error: E) => F): T;
|
|
33
|
+
/** Message of an unknown thrown value, without assuming it is an Error. */
|
|
34
|
+
export declare function thrownMessage(thrown: unknown): string;
|
package/dist/result.mjs
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
export const ok = (value) => ({ kind: "ok", value }), err = (error) => ({ kind: "err", error });
|
|
2
|
+
export function assertNever(value, context) {
|
|
3
|
+
throw TypeError(`Unhandled ${context}: ${JSON.stringify(value)}`);
|
|
4
|
+
}
|
|
5
|
+
export function collect(results) {
|
|
6
|
+
const values = [];
|
|
7
|
+
for (const result of results) {
|
|
8
|
+
if (result.kind === "err")
|
|
9
|
+
return result;
|
|
10
|
+
values.push(result.value);
|
|
11
|
+
}
|
|
12
|
+
return ok(values);
|
|
13
|
+
}
|
|
14
|
+
export function map(result, transform) {
|
|
15
|
+
return result.kind === "ok" ? ok(transform(result.value)) : result;
|
|
16
|
+
}
|
|
17
|
+
export function mapErr(result, transform) {
|
|
18
|
+
return result.kind === "err" ? err(transform(result.error)) : result;
|
|
19
|
+
}
|
|
20
|
+
export function attempt(run) {
|
|
21
|
+
const rejection = privateRejection();
|
|
22
|
+
try {
|
|
23
|
+
return ok(run(rejection.reject));
|
|
24
|
+
} catch (thrown) {
|
|
25
|
+
return rejection.failureOf(thrown);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export async function attemptAsync(run) {
|
|
29
|
+
const rejection = privateRejection();
|
|
30
|
+
try {
|
|
31
|
+
return ok(await run(rejection.reject));
|
|
32
|
+
} catch (thrown) {
|
|
33
|
+
return rejection.failureOf(thrown);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
export function unwrapOr(result, reject, translate) {
|
|
37
|
+
return result.kind === "ok" ? result.value : reject(translate(result.error));
|
|
38
|
+
}
|
|
39
|
+
function privateRejection() {
|
|
40
|
+
|
|
41
|
+
class Rejection {
|
|
42
|
+
failure;
|
|
43
|
+
constructor(failure) {
|
|
44
|
+
this.failure = failure;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
reject: (failure) => {
|
|
49
|
+
throw new Rejection(failure);
|
|
50
|
+
},
|
|
51
|
+
failureOf: (thrown) => {
|
|
52
|
+
if (thrown instanceof Rejection)
|
|
53
|
+
return err(thrown.failure);
|
|
54
|
+
throw thrown;
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
export function thrownMessage(thrown) {
|
|
59
|
+
return thrown instanceof Error ? thrown.message : String(thrown);
|
|
60
|
+
}
|