@behavioral-agentic-design-system/core 0.42.0 → 0.47.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +38 -8
- package/scripts/a11y-lint.cjs +101 -14
- package/scripts/bads-sync.mjs +1 -1
- package/scripts/build-tokens.cjs +122 -7
- package/scripts/check-dark-contrast.mjs +204 -0
- package/scripts/check-flush-edges.mjs +245 -0
- package/scripts/check-spec.mjs +73 -0
- package/scripts/deal-directions.mjs +186 -0
- package/scripts/design-system-advisory/README.md +239 -0
- package/scripts/design-system-advisory/check-copy-punctuation.mjs +44 -0
- package/scripts/design-system-advisory/check-even-padding.mjs +35 -0
- package/scripts/design-system-advisory/check-hand-built-button.mjs +46 -0
- package/scripts/design-system-advisory/check-html-nesting.mjs +51 -0
- package/scripts/design-system-advisory/check-icon-sizing.mjs +79 -0
- package/scripts/design-system-advisory/check-label-case.mjs +92 -0
- package/scripts/design-system-advisory/check-native-form-controls.mjs +53 -0
- package/scripts/design-system-advisory/check-radius.mjs +56 -0
- package/scripts/design-system-advisory/check-raw-values.mjs +61 -0
- package/scripts/design-system-advisory/check-small-text.mjs +72 -0
- package/scripts/design-system-advisory/check-tap-target.mjs +70 -0
- package/scripts/design-system-advisory/defaults.mjs +90 -0
- package/scripts/design-system-advisory/fixtures/clean.tsx.fixture +12 -0
- package/scripts/design-system-advisory/fixtures/violations.tsx.fixture +19 -0
- package/scripts/design-system-advisory/lib.mjs +255 -0
- package/scripts/design-system-advisory/run.mjs +189 -0
- package/scripts/design-system-advisory/workflow.yml +82 -0
- package/scripts/health-report.mjs +20 -14
- package/scripts/lib/copy-strings.mjs +146 -0
- package/scripts/lib/counted-lint.mjs +100 -0
- package/scripts/lib/dark-contrast.mjs +120 -0
- package/scripts/lib/flush-edges.mjs +294 -0
- package/scripts/lib/lab-lint.mjs +62 -0
- package/scripts/lib/marketing-library.mjs +129 -0
- package/scripts/lib/mount-page.mjs +25 -0
- package/scripts/lib/on-system.mjs +249 -0
- package/scripts/lib/random.mjs +22 -0
- package/scripts/lib/source-scan.mjs +173 -0
- package/scripts/lib/spec-parse.d.mts +25 -0
- package/scripts/lib/spec-parse.mjs +188 -0
- package/scripts/lib/tells.mjs +366 -0
- package/scripts/lint-arbitrary-tokens.mjs +47 -0
- package/scripts/lint-component-token-refs.mjs +63 -0
- package/scripts/lint-content-hierarchy.mjs +114 -0
- package/scripts/lint-control-baseline.mjs +72 -0
- package/scripts/lint-copy-punctuation.mjs +60 -0
- package/scripts/lint-css-vars.mjs +175 -0
- package/scripts/lint-even-padding.mjs +58 -0
- package/scripts/lint-html-nesting.mjs +116 -0
- package/scripts/lint-label-case.mjs +219 -0
- package/scripts/lint-live-ctas.mjs +138 -0
- package/scripts/lint-microanimation.mjs +2 -2
- package/scripts/lint-proximity.mjs +181 -0
- package/scripts/lint-slop.mjs +1 -1
- package/scripts/lint-spacing-scale.mjs +78 -0
- package/scripts/lint-target-size.cjs +132 -0
- package/scripts/lint-token-primitives.mjs +307 -0
- package/scripts/on-system-score.mjs +95 -0
- package/scripts/size-audit.cjs +2 -2
- package/scripts/slop-rules.mjs +1 -1
- package/scripts/source-images.mjs +180 -0
- package/scripts/ux-tells.mjs +80 -0
- package/scripts/wcag-audit.cjs +25 -4
- package/src/api/brand-colors.ts +3 -0
- package/src/api/brand-fonts.ts +3 -0
- package/src/api/brand-mark.ts +6 -1
- package/src/api/dev-write-guard.ts +53 -0
- package/src/api/layers/file.ts +9 -4
- package/src/api/onboarding-extract.ts +85 -30
- package/src/api/onboarding.ts +3 -0
- package/src/api/save-tokens.ts +3 -0
- package/src/api/site-auth.ts +14 -2
- package/src/app/layout.tsx +6 -0
- package/src/app/preview/canvas/page.tsx +12 -0
- package/src/app/preview/components/page.tsx +828 -14
- package/src/app/preview/sticker-sheet/page.tsx +329 -0
- package/src/app/preview/sticker-sheet/specimens.tsx +296 -0
- package/src/app/preview/studio/blank-screen.tsx +143 -0
- package/src/app/preview/studio/page.tsx +7 -0
- package/src/app/shell.tsx +164 -47
- package/src/components/Foundations/Colors.stories.tsx +119 -8
- package/src/components/canvas/canvas.tsx +458 -0
- package/src/components/canvas/layout.ts +72 -0
- package/src/components/canvas/parse-canvas.ts +32 -0
- package/src/components/canvas/sample.ts +90 -0
- package/src/components/canvas/spec-frame.tsx +43 -0
- package/src/components/canvas/types.ts +33 -0
- package/src/components/docs-tab.tsx +7 -7
- package/src/components/home-recent.tsx +73 -0
- package/src/components/home-tab.tsx +19 -14
- package/src/components/layers-tab.tsx +2 -2
- package/src/components/markdown-preview.tsx +60 -12
- package/src/components/onboarding-wizard.tsx +1 -1
- package/src/components/studio/control-panel.tsx +299 -0
- package/src/components/studio/control-row.tsx +77 -0
- package/src/components/studio/preview-frame.tsx +165 -0
- package/src/components/studio/preview-pane.tsx +247 -0
- package/src/components/studio/studio.tsx +133 -128
- package/src/components/studio/types.ts +218 -0
- package/src/components/studio/use-studio-tweaks.ts +128 -0
- package/src/components/studio/use-studio-view-state.ts +72 -0
- package/src/components/ui/autocomplete.tsx +1 -1
- package/src/components/ui/avatar.tsx +4 -0
- package/src/components/ui/chart.tsx +134 -42
- package/src/components/ui/checkbox-group.tsx +1 -1
- package/src/components/ui/checkbox.tsx +1 -1
- package/src/components/ui/color-picker.tsx +20 -4
- package/src/components/ui/combobox.tsx +1 -0
- package/src/components/ui/command.tsx +1 -1
- package/src/components/ui/data-table.tsx +64 -3
- package/src/components/ui/date-field.tsx +1 -1
- package/src/components/ui/date-picker.tsx +2 -0
- package/src/components/ui/date-range-picker.tsx +4 -0
- package/src/components/ui/editable.tsx +1 -0
- package/src/components/ui/faceted-filter.tsx +187 -0
- package/src/components/ui/file-upload.tsx +21 -2
- package/src/components/ui/gauge-chart.tsx +18 -4
- package/src/components/ui/heatmap.tsx +3 -1
- package/src/components/ui/inline-edit.tsx +175 -0
- package/src/components/ui/input-group.tsx +5 -2
- package/src/components/ui/month-picker.tsx +1 -1
- package/src/components/ui/multi-select.tsx +1 -0
- package/src/components/ui/number-input.tsx +28 -5
- package/src/components/ui/otp-input.tsx +208 -0
- package/src/components/ui/phone-input.tsx +274 -0
- package/src/components/ui/radio-group.tsx +2 -2
- package/src/components/ui/search-input.tsx +1 -1
- package/src/components/ui/sparkline.tsx +33 -4
- package/src/components/ui/spinner.tsx +23 -4
- package/src/components/ui/table.tsx +9 -0
- package/src/components/ui/tags-input.tsx +1 -1
- package/src/components/ui/timer.tsx +1 -0
- package/src/components/ui/transfer-list.tsx +13 -26
- package/src/components/ui/week-picker.tsx +1 -13
- package/src/components/ui/year-picker.tsx +1 -1
- package/src/data/component-added.json +966 -0
- package/src/data/docs-index.ts +35 -2
- package/src/data/history.json +161 -161
- package/src/data/sticker-sheet.json +9244 -0
- package/src/docs-trace-globs.json +1 -0
- package/src/hooks/use-global-mono-font.ts +1 -0
- package/src/hooks/use-global-primary-color.ts +1 -0
- package/src/hooks/use-global-sans-font.ts +1 -0
- package/src/hooks/use-global-serif-font.ts +1 -0
- package/src/hooks/use-global-type-scale.ts +17 -2
- package/src/hooks/use-mobile.ts +2 -0
- package/src/hooks/use-sync-type-scale.ts +7 -11
- package/src/lib/chart-motion.ts +41 -0
- package/src/lib/get-icon-color.ts +1 -1
- package/src/lib/spec-parse.ts +4 -0
- package/src/lib/svg-sanitize.ts +19 -9
- package/src/stories/Accordion.stories.tsx +7 -0
- package/src/stories/ActionBar.stories.tsx +5 -0
- package/src/stories/Affix.stories.tsx +4 -0
- package/src/stories/AiBadge.stories.tsx +9 -7
- package/src/stories/Alert.stories.tsx +13 -0
- package/src/stories/AlertDialog.stories.tsx +4 -0
- package/src/stories/Anchor.stories.tsx +5 -0
- package/src/stories/AngleSlider.stories.tsx +6 -3
- package/src/stories/AspectRatio.stories.tsx +4 -0
- package/src/stories/Autocomplete.stories.tsx +8 -0
- package/src/stories/Avatar.stories.tsx +10 -0
- package/src/stories/Badge.stories.tsx +14 -6
- package/src/stories/Blockquote.stories.tsx +6 -0
- package/src/stories/BottomNavigation.stories.tsx +4 -0
- package/src/stories/Breadcrumb.stories.tsx +3 -0
- package/src/stories/Burger.stories.tsx +1 -0
- package/src/stories/Button.stories.tsx +24 -0
- package/src/stories/ButtonGroup.stories.tsx +9 -0
- package/src/stories/Calendar.stories.tsx +3 -0
- package/src/stories/Canvas.stories.tsx +45 -0
- package/src/stories/Card.stories.tsx +4 -0
- package/src/stories/Carousel.stories.tsx +6 -0
- package/src/stories/Cascader.stories.tsx +4 -0
- package/src/stories/Chart.stories.tsx +46 -1
- package/src/stories/ChatBubble.stories.tsx +8 -2
- package/src/stories/ChatMarker.stories.tsx +1 -0
- package/src/stories/Checkbox.stories.tsx +40 -0
- package/src/stories/CheckboxCard.stories.tsx +8 -0
- package/src/stories/CheckboxGroup.stories.tsx +19 -0
- package/src/stories/Chip.stories.tsx +10 -19
- package/src/stories/CircularProgress.stories.tsx +13 -27
- package/src/stories/Clipboard.stories.tsx +6 -0
- package/src/stories/CloseButton.stories.tsx +6 -4
- package/src/stories/Code.stories.tsx +8 -1
- package/src/stories/Collapsible.stories.tsx +2 -0
- package/src/stories/ColorPicker.stories.tsx +46 -0
- package/src/stories/ColorSwatch.stories.tsx +1 -0
- package/src/stories/Combobox.stories.tsx +9 -0
- package/src/stories/Command.stories.tsx +2 -0
- package/src/stories/Container.stories.tsx +8 -0
- package/src/stories/ContextMenu.stories.tsx +9 -0
- package/src/stories/CopyButton.stories.tsx +12 -36
- package/src/stories/DataList.stories.tsx +8 -0
- package/src/stories/DataTable.stories.tsx +39 -0
- package/src/stories/DateField.stories.tsx +28 -0
- package/src/stories/DatePicker.stories.tsx +34 -0
- package/src/stories/DateRangePicker.stories.tsx +32 -0
- package/src/stories/Dialog.stories.tsx +8 -0
- package/src/stories/Drawer.stories.tsx +6 -0
- package/src/stories/DropdownMenu.stories.tsx +2 -0
- package/src/stories/Editable.stories.tsx +12 -0
- package/src/stories/EmptyState.stories.tsx +9 -0
- package/src/stories/FacetedFilter.stories.tsx +197 -0
- package/src/stories/Field.stories.tsx +7 -0
- package/src/stories/Fieldset.stories.tsx +8 -0
- package/src/stories/FileButton.stories.tsx +4 -0
- package/src/stories/FileUpload.stories.tsx +16 -17
- package/src/stories/FloatLabel.stories.tsx +3 -8
- package/src/stories/FloatingActionButton.stories.tsx +10 -0
- package/src/stories/FloatingIndicator.stories.tsx +4 -0
- package/src/stories/FloatingPanel.stories.tsx +6 -0
- package/src/stories/FocusTrap.stories.tsx +5 -0
- package/src/stories/FormatByte.stories.tsx +6 -0
- package/src/stories/FormatDate.stories.tsx +8 -0
- package/src/stories/FormatNumber.stories.tsx +9 -0
- package/src/stories/GaugeChart.stories.tsx +9 -3
- package/src/stories/Heatmap.stories.tsx +11 -0
- package/src/stories/Highlight.stories.tsx +6 -0
- package/src/stories/HoverCard.stories.tsx +4 -0
- package/src/stories/Image.stories.tsx +9 -0
- package/src/stories/Indicator.stories.tsx +19 -0
- package/src/stories/InlineEdit.stories.tsx +106 -0
- package/src/stories/Input.stories.tsx +7 -0
- package/src/stories/InputClearButton.stories.tsx +3 -0
- package/src/stories/InputGroup.stories.tsx +40 -0
- package/src/stories/Kbd.stories.tsx +7 -1
- package/src/stories/KeyboardShortcut.stories.tsx +2 -0
- package/src/stories/Label.stories.tsx +2 -0
- package/src/stories/Link.stories.tsx +9 -0
- package/src/stories/List.stories.tsx +8 -0
- package/src/stories/Listbox.stories.tsx +1 -0
- package/src/stories/LoadingDots.stories.tsx +5 -3
- package/src/stories/LoadingOverlay.stories.tsx +5 -1
- package/src/stories/Mark.stories.tsx +5 -0
- package/src/stories/MarkdownPreview.stories.tsx +53 -0
- package/src/stories/Marquee.stories.tsx +4 -0
- package/src/stories/Masonry.stories.tsx +5 -0
- package/src/stories/Menubar.stories.tsx +3 -0
- package/src/stories/Meter.stories.tsx +11 -17
- package/src/stories/MonthPicker.stories.tsx +26 -1
- package/src/stories/MotionToggle.stories.tsx +1 -0
- package/src/stories/MultiSelect.stories.tsx +9 -0
- package/src/stories/NativeSelect.stories.tsx +1 -0
- package/src/stories/NavLink.stories.tsx +7 -0
- package/src/stories/NavigationMenu.stories.tsx +5 -0
- package/src/stories/NavigationRail.stories.tsx +10 -0
- package/src/stories/Notification.stories.tsx +13 -34
- package/src/stories/NumberInput.stories.tsx +33 -1
- package/src/stories/OtpInput.stories.tsx +110 -0
- package/src/stories/Overlay.stories.tsx +5 -1
- package/src/stories/Pagination.stories.tsx +8 -0
- package/src/stories/PasswordInput.stories.tsx +2 -0
- package/src/stories/PhoneInput.stories.tsx +127 -0
- package/src/stories/PinInput.stories.tsx +9 -2
- package/src/stories/Popover.stories.tsx +2 -0
- package/src/stories/Progress.stories.tsx +6 -1
- package/src/stories/Prose.stories.tsx +8 -0
- package/src/stories/QrCode.stories.tsx +2 -0
- package/src/stories/Questionnaire.stories.tsx +7 -0
- package/src/stories/RadioGroup.stories.tsx +40 -0
- package/src/stories/RatingGroup.stories.tsx +8 -4
- package/src/stories/Resizable.stories.tsx +4 -2
- package/src/stories/Result.stories.tsx +3 -0
- package/src/stories/Reveal.stories.tsx +2 -0
- package/src/stories/RollingNumber.stories.tsx +5 -0
- package/src/stories/ScrollArea.stories.tsx +3 -1
- package/src/stories/SearchInput.stories.tsx +10 -6
- package/src/stories/SegmentedControl.stories.tsx +11 -0
- package/src/stories/Select.stories.tsx +7 -0
- package/src/stories/Separator.stories.tsx +6 -0
- package/src/stories/Sheet.stories.tsx +5 -0
- package/src/stories/Sidebar.stories.tsx +40 -1
- package/src/stories/SimpleGrid.stories.tsx +5 -0
- package/src/stories/Skeleton.stories.tsx +8 -0
- package/src/stories/SkeletonTable.stories.tsx +6 -5
- package/src/stories/SkipLink.stories.tsx +3 -0
- package/src/stories/Slider.stories.tsx +2 -1
- package/src/stories/Sonner.stories.tsx +7 -0
- package/src/stories/Sparkline.stories.tsx +14 -1
- package/src/stories/Spinner.stories.tsx +20 -10
- package/src/stories/Spoiler.stories.tsx +5 -0
- package/src/stories/Squircle.stories.tsx +7 -0
- package/src/stories/Stack.stories.tsx +7 -0
- package/src/stories/StatusBadge.stories.tsx +12 -6
- package/src/stories/Stepper.stories.tsx +5 -0
- package/src/stories/Switch.stories.tsx +4 -0
- package/src/stories/Table.stories.tsx +10 -1
- package/src/stories/Tabs.stories.tsx +8 -0
- package/src/stories/Tag.stories.tsx +13 -5
- package/src/stories/TagsInput.stories.tsx +15 -0
- package/src/stories/Text.stories.tsx +12 -0
- package/src/stories/Textarea.stories.tsx +9 -0
- package/src/stories/ThemeIcon.stories.tsx +6 -3
- package/src/stories/TimePicker.stories.tsx +2 -0
- package/src/stories/Timeline.stories.tsx +12 -0
- package/src/stories/Timer.stories.tsx +30 -0
- package/src/stories/Toggle.stories.tsx +7 -5
- package/src/stories/ToggleGroup.stories.tsx +5 -0
- package/src/stories/ToggleTip.stories.tsx +4 -0
- package/src/stories/Toolbar.stories.tsx +6 -0
- package/src/stories/Tooltip.stories.tsx +3 -0
- package/src/stories/Tour.stories.tsx +3 -0
- package/src/stories/TransferList.stories.tsx +7 -0
- package/src/stories/TreeSelect.stories.tsx +4 -0
- package/src/stories/TreeView.stories.tsx +5 -0
- package/src/stories/TypingIndicator.stories.tsx +4 -0
- package/src/stories/VisuallyHidden.stories.tsx +3 -0
- package/src/stories/Watermark.stories.tsx +6 -0
- package/src/stories/WeekPicker.stories.tsx +25 -1
- package/src/stories/WordRotate.stories.tsx +5 -0
- package/src/stories/YearPicker.stories.tsx +26 -11
- package/src/stories/story-groups.json +22 -16
- package/src/styles.css +50 -2
- package/src/tokens.json +86 -58
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* source-images — find real, openly licensed pictures of a client's world and
|
|
4
|
+
* record the credit that has to appear on the page.
|
|
5
|
+
*
|
|
6
|
+
* Why: the anti-defaults say stock or abstract imagery standing in for the
|
|
7
|
+
* product is placeholder content, but until now BADS had no way to find the
|
|
8
|
+
* real thing. A marketing page for a harbor cafe is better with the harbor than
|
|
9
|
+
* with a gradient. The approach, searching open archives with the credit kept
|
|
10
|
+
* beside the file, is from Leonxlnx/taste-skill (MIT). This is a separate,
|
|
11
|
+
* smaller implementation: three key-free sources, an explicit license allowlist,
|
|
12
|
+
* and a credits file that can't be skipped.
|
|
13
|
+
*
|
|
14
|
+
* Sources (no API keys):
|
|
15
|
+
* openverse api.openverse.org CC-licensed photographs
|
|
16
|
+
* met Metropolitan Museum Open Access, public domain only
|
|
17
|
+
* commons Wikimedia Commons license read from each file's metadata
|
|
18
|
+
*
|
|
19
|
+
* Licenses allowed by default: CC0, public domain, CC BY.
|
|
20
|
+
* --allow-sa also allows CC BY-SA. Its share-alike term applies to adaptations
|
|
21
|
+
* of the picture, so confirm with the client before using it.
|
|
22
|
+
* Never allowed: NonCommercial, NoDerivatives, or a license it can't identify.
|
|
23
|
+
*
|
|
24
|
+
* Usage (from the project root):
|
|
25
|
+
* bads-source-images --query "cork harbour ferry" search, print candidates
|
|
26
|
+
* bads-source-images --query "cork harbour ferry" --download also save them
|
|
27
|
+
* options: --source openverse,met,commons --count 6 --out public/images/sourced --allow-sa
|
|
28
|
+
*
|
|
29
|
+
* A downloaded picture is only usable with its credit. credits.json in the output
|
|
30
|
+
* folder holds it; put the attribution on the page near the image, and write real
|
|
31
|
+
* alt text. Check each picture yourself: an open license says nothing about who
|
|
32
|
+
* is in it or whether the scene is right for the client.
|
|
33
|
+
*
|
|
34
|
+
* Network: this needs internet. The hosts above must be reachable.
|
|
35
|
+
*/
|
|
36
|
+
import fs from "node:fs";
|
|
37
|
+
import path from "node:path";
|
|
38
|
+
import { fileURLToPath } from "node:url";
|
|
39
|
+
|
|
40
|
+
export const SOURCES = ["openverse", "met", "commons"];
|
|
41
|
+
export const MAX_BYTES = 15 * 1024 * 1024;
|
|
42
|
+
export const IMAGE_TYPES = { "image/jpeg": "jpg", "image/png": "png", "image/webp": "webp" };
|
|
43
|
+
const UA = "bads-source-images/1.0 (design-system tooling; contact: see the project's repository)";
|
|
44
|
+
|
|
45
|
+
/** Classify a license string from any source into one code. */
|
|
46
|
+
export function licenseCode(raw) {
|
|
47
|
+
const s = String(raw || "").toLowerCase().replace(/[_\s]+/g, "-");
|
|
48
|
+
if (!s) return "unknown";
|
|
49
|
+
if (/(^|-)nc(-|$)|noncommercial/.test(s)) return "nc";
|
|
50
|
+
if (/(^|-)nd(-|$)|noderiv/.test(s)) return "nd";
|
|
51
|
+
if (/cc0|cc-zero|zero|publicdomain\/zero/.test(s)) return "cc0";
|
|
52
|
+
if (/(^|-)pdm(-|$)|public-?domain/.test(s)) return "pdm";
|
|
53
|
+
if (/by-sa|sharealike/.test(s)) return "by-sa";
|
|
54
|
+
if (/(^|-)by(-|$)|attribution/.test(s)) return "by";
|
|
55
|
+
return "unknown";
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function isAllowed(code, { allowSa = false } = {}) {
|
|
59
|
+
return ["cc0", "pdm", "by"].includes(code) || (allowSa && code === "by-sa");
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const stripHtml = (s) => String(s || "").replace(/<[^>]*>/g, "").replace(/&/g, "&").replace(/"/g, '"').replace(/'/g, "'").replace(/\s+/g, " ").trim();
|
|
63
|
+
export const slugify = (s) => String(s || "image").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "").slice(0, 60) || "image";
|
|
64
|
+
|
|
65
|
+
/** The credit line a page should show next to the picture. */
|
|
66
|
+
export function attributionLine(c) {
|
|
67
|
+
if (c.license === "cc0" || c.license === "pdm") return `${c.title}${c.creator ? ` by ${c.creator}` : ""} (${c.sourceName}, public domain)`;
|
|
68
|
+
const lic = { by: "CC BY", "by-sa": "CC BY-SA" }[c.license] || c.license;
|
|
69
|
+
return `"${c.title}"${c.creator ? ` by ${c.creator}` : ""}, ${lic}${c.licenseUrl ? ` (${c.licenseUrl})` : ""}, via ${c.sourceName}`;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async function getJson(fetchFn, url) {
|
|
73
|
+
const res = await fetchFn(url, { headers: { "User-Agent": UA, Accept: "application/json" } });
|
|
74
|
+
if (!res.ok) throw new Error(`${new URL(url).host} answered ${res.status}`);
|
|
75
|
+
return res.json();
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export async function searchOpenverse(q, { fetch: f = fetch, count = 6 } = {}) {
|
|
79
|
+
const url = `https://api.openverse.org/v1/images/?${new URLSearchParams({ q, license_type: "commercial", category: "photograph", page_size: String(Math.min(20, count * 3)) })}`;
|
|
80
|
+
const data = await getJson(f, url);
|
|
81
|
+
return (data.results || []).filter((r) => r.url).map((r) => ({
|
|
82
|
+
source: "openverse", sourceName: r.source || "Openverse", id: String(r.id), title: stripHtml(r.title) || "Untitled", creator: stripHtml(r.creator),
|
|
83
|
+
license: licenseCode(r.license), licenseUrl: r.license_url || "", landingUrl: r.foreign_landing_url || "", imageUrl: r.url, width: r.width, height: r.height,
|
|
84
|
+
}));
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export async function searchMet(q, { fetch: f = fetch, count = 6 } = {}) {
|
|
88
|
+
const found = await getJson(f, `https://collectionapi.metmuseum.org/public/collection/v1/search?${new URLSearchParams({ q, hasImages: "true", isPublicDomain: "true" })}`);
|
|
89
|
+
const ids = (found.objectIDs || []).slice(0, count * 2);
|
|
90
|
+
const out = [];
|
|
91
|
+
for (const id of ids) {
|
|
92
|
+
try {
|
|
93
|
+
const o = await getJson(f, `https://collectionapi.metmuseum.org/public/collection/v1/objects/${id}`);
|
|
94
|
+
if (!o.isPublicDomain || !o.primaryImage) continue;
|
|
95
|
+
out.push({ source: "met", sourceName: "The Metropolitan Museum of Art", id: String(id), title: o.title || "Untitled", creator: o.artistDisplayName || "", license: "pdm", licenseUrl: "https://www.metmuseum.org/about-the-met/policies-and-documents/open-access", landingUrl: o.objectURL || "", imageUrl: o.primaryImage, width: undefined, height: undefined });
|
|
96
|
+
} catch { /* one bad object shouldn't sink the search */ }
|
|
97
|
+
}
|
|
98
|
+
return out;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export async function searchCommons(q, { fetch: f = fetch, count = 6 } = {}) {
|
|
102
|
+
const params = new URLSearchParams({ action: "query", generator: "search", gsrnamespace: "6", gsrsearch: `${q} filetype:bitmap`, gsrlimit: String(Math.min(30, count * 3)), prop: "imageinfo", iiprop: "url|extmetadata|size|mime", iiurlwidth: "1600", format: "json", origin: "*" });
|
|
103
|
+
const data = await getJson(f, `https://commons.wikimedia.org/w/api.php?${params}`);
|
|
104
|
+
return Object.values(data.query?.pages || {}).map((p) => {
|
|
105
|
+
const ii = p.imageinfo?.[0];
|
|
106
|
+
if (!ii || !(ii.mime in IMAGE_TYPES)) return null;
|
|
107
|
+
const m = ii.extmetadata || {};
|
|
108
|
+
const lic = m.LicenseShortName?.value || m.License?.value || "";
|
|
109
|
+
return { source: "commons", sourceName: "Wikimedia Commons", id: String(p.pageid), title: stripHtml(p.title).replace(/^File:/, "").replace(/\.[a-z]+$/i, ""), creator: stripHtml(m.Artist?.value), license: licenseCode(lic), licenseUrl: m.LicenseUrl?.value || "", landingUrl: ii.descriptionurl || "", imageUrl: ii.thumburl || ii.url, width: ii.thumbwidth || ii.width, height: ii.thumbheight || ii.height };
|
|
110
|
+
}).filter(Boolean);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const SEARCHERS = { openverse: searchOpenverse, met: searchMet, commons: searchCommons };
|
|
114
|
+
|
|
115
|
+
/** Search the chosen sources, drop anything the license rules reject, and report why. */
|
|
116
|
+
export async function search(q, { sources = SOURCES, count = 6, allowSa = false, fetch: f = fetch } = {}) {
|
|
117
|
+
const candidates = [], rejected = { license: 0 }, errors = [];
|
|
118
|
+
for (const s of sources) {
|
|
119
|
+
try {
|
|
120
|
+
for (const c of await SEARCHERS[s](q, { fetch: f, count })) {
|
|
121
|
+
if (isAllowed(c.license, { allowSa })) candidates.push(c);
|
|
122
|
+
else rejected.license += 1;
|
|
123
|
+
}
|
|
124
|
+
} catch (e) { errors.push(`${s}: ${e.message}`); }
|
|
125
|
+
}
|
|
126
|
+
// Spread across sources, so one source with many hits doesn't crowd out the rest.
|
|
127
|
+
const bySource = sources.map((s) => candidates.filter((c) => c.source === s));
|
|
128
|
+
const picked = [];
|
|
129
|
+
for (let i = 0; picked.length < count && bySource.some((l) => i < l.length); i++) for (const l of bySource) if (l[i] && picked.length < count) picked.push(l[i]);
|
|
130
|
+
return { candidates: picked, rejected, errors };
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** Save one candidate. Throws on a wrong type or an oversize file, and never leaves a partial file. */
|
|
134
|
+
export async function download(c, dir, { fetch: f = fetch } = {}) {
|
|
135
|
+
const res = await f(c.imageUrl, { headers: { "User-Agent": UA } });
|
|
136
|
+
if (!res.ok) throw new Error(`download answered ${res.status}`);
|
|
137
|
+
const type = (res.headers.get("content-type") || "").split(";")[0].trim().toLowerCase();
|
|
138
|
+
if (!(type in IMAGE_TYPES)) throw new Error(`unexpected type "${type}", only jpeg, png and webp are saved`);
|
|
139
|
+
const buf = Buffer.from(await res.arrayBuffer());
|
|
140
|
+
if (buf.length > MAX_BYTES) throw new Error(`${(buf.length / 1048576).toFixed(1)} MB is over the ${MAX_BYTES / 1048576} MB limit`);
|
|
141
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
142
|
+
const file = path.join(dir, `${c.source}-${slugify(c.title)}-${slugify(c.id).slice(0, 12)}.${IMAGE_TYPES[type]}`);
|
|
143
|
+
fs.writeFileSync(file, buf);
|
|
144
|
+
return file;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** Add an entry to credits.json, replacing one for the same file. */
|
|
148
|
+
export function recordCredit(dir, c, file, now = new Date()) {
|
|
149
|
+
const p = path.join(dir, "credits.json");
|
|
150
|
+
const all = fs.existsSync(p) ? JSON.parse(fs.readFileSync(p, "utf8")) : [];
|
|
151
|
+
const entry = { file: path.basename(file), title: c.title, creator: c.creator, license: c.license, licenseUrl: c.licenseUrl, source: c.sourceName, landingUrl: c.landingUrl, attribution: attributionLine(c), retrievedAt: now.toISOString().slice(0, 10) };
|
|
152
|
+
fs.writeFileSync(p, JSON.stringify([...all.filter((e) => e.file !== entry.file), entry], null, 2) + "\n");
|
|
153
|
+
return entry;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
async function main(argv) {
|
|
157
|
+
const arg = (n, d) => { const i = argv.indexOf(n); return i >= 0 ? argv[i + 1] : d; };
|
|
158
|
+
const q = arg("--query");
|
|
159
|
+
if (!q) { console.error('usage: bads-source-images --query "..." [--download] [--source openverse,met,commons] [--count 6] [--out public/images/sourced] [--allow-sa]'); return 2; }
|
|
160
|
+
const sources = arg("--source", SOURCES.join(",")).split(",").map((s) => s.trim()).filter(Boolean);
|
|
161
|
+
const bad = sources.filter((s) => !SOURCES.includes(s));
|
|
162
|
+
if (bad.length) { console.error(`unknown source: ${bad.join(", ")}. Use ${SOURCES.join(", ")}.`); return 2; }
|
|
163
|
+
const count = Number(arg("--count", 6)), out = path.resolve(arg("--out", "public/images/sourced")), allowSa = argv.includes("--allow-sa");
|
|
164
|
+
const { candidates, rejected, errors } = await search(q, { sources, count, allowSa });
|
|
165
|
+
for (const e of errors) console.error(` ! ${e}`);
|
|
166
|
+
if (!candidates.length) { console.log(`No usable pictures for "${q}".${rejected.license ? ` ${rejected.license} found with a license that isn't allowed.` : ""}${errors.length ? " Some sources failed (above)." : ""}`); return errors.length === sources.length ? 1 : 0; }
|
|
167
|
+
console.log(`${candidates.length} candidate${candidates.length === 1 ? "" : "s"} for "${q}" (${rejected.license} skipped for license):\n`);
|
|
168
|
+
for (const [i, c] of candidates.entries()) {
|
|
169
|
+
console.log(`${i + 1}. ${c.title}${c.creator ? ` — ${c.creator}` : ""}\n ${c.sourceName} · ${c.license.toUpperCase()}${c.width ? ` · ${c.width}×${c.height}` : ""}\n ${c.landingUrl || c.imageUrl}`);
|
|
170
|
+
if (argv.includes("--download")) {
|
|
171
|
+
try { const file = await download(c, out); recordCredit(out, c, file); console.log(` saved ${path.relative(process.cwd(), file)}`); } catch (e) { console.log(` not saved: ${e.message}`); }
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
console.log(argv.includes("--download")
|
|
175
|
+
? `\nCredits are in ${path.relative(process.cwd(), path.join(out, "credits.json"))}. Show each credit near its picture, write real alt text, and check the picture fits the client.`
|
|
176
|
+
: "\nNothing saved. Add --download to save these with their credits.");
|
|
177
|
+
return 0;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if (process.argv[1] && fileURLToPath(import.meta.url) === path.resolve(process.argv[1])) process.exit(await main(process.argv.slice(2)));
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* ux-tells — open a page in a real browser at four widths (320 is WCAG reflow) and fail it on the
|
|
4
|
+
* signals that make a page read as generated: gradient text, indigo gradients,
|
|
5
|
+
* stacks of glass panels, glows, the stock three-icon-card row, a pill above the
|
|
6
|
+
* headline, decorative emoji, pulsing dots, placeholder copy and images, and
|
|
7
|
+
* sideways scrolling, plus four layout tells measured from the rendered boxes (a crowded heading, text
|
|
8
|
+
* cramped in its box, text painted under another element, a wrapped or clipped button label). It saves a screenshot of each width so someone can look.
|
|
9
|
+
*
|
|
10
|
+
* It reads computed styles, so it catches what lint-slop's source scan can't:
|
|
11
|
+
* classes built at runtime and the effect of the cascade. It runs on any URL, so
|
|
12
|
+
* a client's marketing page, a preview route, or a deployed site all work.
|
|
13
|
+
* Reduced motion is emulated, so a reading doesn't depend on an animation frame.
|
|
14
|
+
*
|
|
15
|
+
* Usage:
|
|
16
|
+
* bads-ux-tells <url> [--widths 320,375,768,1280] [--out .ux-tells] [--json] [--warn]
|
|
17
|
+
*
|
|
18
|
+
* Exit 1 when any banned tell is found (0 with --warn). Warned tells are listed
|
|
19
|
+
* and need a reason, not a fix. Rules and rationale: lib/tells.mjs.
|
|
20
|
+
*
|
|
21
|
+
* Needs Playwright and a Chromium: `pnpm install` in the repo, or set PW_CHROMIUM.
|
|
22
|
+
*/
|
|
23
|
+
import fs from "node:fs";
|
|
24
|
+
import path from "node:path";
|
|
25
|
+
import { fileURLToPath } from "node:url";
|
|
26
|
+
import { WIDTHS, TELLS, probeSource, probeLayoutSource, classify, merge } from "./lib/tells.mjs";
|
|
27
|
+
|
|
28
|
+
function chromiumExecutable() {
|
|
29
|
+
if (process.env.PW_CHROMIUM && fs.existsSync(process.env.PW_CHROMIUM)) return process.env.PW_CHROMIUM;
|
|
30
|
+
for (const c of ["/opt/pw-browsers/chromium-1194/chrome-linux/chrome", "/opt/pw-browsers/chromium/chrome-linux/chrome"]) if (fs.existsSync(c)) return c;
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Check one URL at each width. Returns { findings, screenshots }. */
|
|
35
|
+
export async function check(url, { widths = WIDTHS, out = ".ux-tells", chromium } = {}) {
|
|
36
|
+
if (!chromium) ({ chromium } = await import("playwright"));
|
|
37
|
+
fs.mkdirSync(out, { recursive: true });
|
|
38
|
+
const exe = chromiumExecutable();
|
|
39
|
+
const browser = await chromium.launch(exe ? { executablePath: exe } : {});
|
|
40
|
+
const perWidth = [], screenshots = [];
|
|
41
|
+
try {
|
|
42
|
+
for (const width of widths) {
|
|
43
|
+
const ctx = await browser.newContext({ viewport: { width, height: 900 }, reducedMotion: "reduce", deviceScaleFactor: 1 });
|
|
44
|
+
const page = await ctx.newPage();
|
|
45
|
+
const res = await page.goto(url, { waitUntil: "networkidle", timeout: 60000 }).catch(() => null);
|
|
46
|
+
if (!res || !res.ok()) { await ctx.close(); throw new Error(`could not load ${url} at ${width}px`); }
|
|
47
|
+
await page.evaluate(() => document.fonts && document.fonts.ready);
|
|
48
|
+
const facts = { ...(await page.evaluate(probeSource())), ...(await page.evaluate(probeLayoutSource())) };
|
|
49
|
+
perWidth.push(classify(facts, width));
|
|
50
|
+
for (const [kind, full] of [["fold", false], ["page", true]]) {
|
|
51
|
+
const file = path.join(out, `${width}-${kind}.jpg`);
|
|
52
|
+
await page.screenshot({ path: file, fullPage: full, type: "jpeg", quality: 80 });
|
|
53
|
+
screenshots.push(file);
|
|
54
|
+
}
|
|
55
|
+
await ctx.close();
|
|
56
|
+
}
|
|
57
|
+
} finally { await browser.close(); }
|
|
58
|
+
return { findings: merge(perWidth), screenshots };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async function main(argv) {
|
|
62
|
+
const url = argv.find((a) => /^https?:\/\/|^file:\/\//.test(a));
|
|
63
|
+
if (!url) { console.error("usage: bads-ux-tells <url> [--widths 320,375,768,1280] [--out .ux-tells] [--json] [--warn]"); return 2; }
|
|
64
|
+
const arg = (n, d) => { const i = argv.indexOf(n); return i >= 0 ? argv[i + 1] : d; };
|
|
65
|
+
const widths = arg("--widths", WIDTHS.join(",")).split(",").map(Number).filter((n) => n >= 280 && n <= 3000);
|
|
66
|
+
let result;
|
|
67
|
+
try { result = await check(url, { widths, out: arg("--out", ".ux-tells") }); } catch (e) { console.error(`ux-tells: ${e.message}`); return 2; }
|
|
68
|
+
const banned = result.findings.filter((f) => f.status === "banned"), warned = result.findings.filter((f) => f.status === "warned");
|
|
69
|
+
if (argv.includes("--json")) console.log(JSON.stringify(result, null, 2));
|
|
70
|
+
else {
|
|
71
|
+
console.log(`ux-tells ${url} (${widths.join(", ")}px)`);
|
|
72
|
+
for (const f of [...banned, ...warned]) console.log(` ${f.status === "banned" ? "✗ banned" : "⚠ warned"} ${f.name} [${f.code}] at ${f.widths.join("/")}px: ${f.detail}\n ${f.why}`);
|
|
73
|
+
console.log(banned.length || warned.length ? "" : " No tells found.");
|
|
74
|
+
console.log(`${banned.length} banned, ${warned.length} warned. ${TELLS.length} rules. Screenshots: ${path.dirname(result.screenshots[0])}`);
|
|
75
|
+
console.log("Look at the screenshots too. This finds the objective tells, and says nothing about whether the page is any good.");
|
|
76
|
+
}
|
|
77
|
+
return banned.length && !argv.includes("--warn") ? 1 : 0;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (process.argv[1] && fileURLToPath(import.meta.url) === path.resolve(process.argv[1])) process.exit(await main(process.argv.slice(2)));
|
package/scripts/wcag-audit.cjs
CHANGED
|
@@ -124,7 +124,7 @@ const LARGE_FLOOR = aa ? 3.0 : 4.5;
|
|
|
124
124
|
// library is generally built to AA, not AAA, and a red pipeline over a
|
|
125
125
|
// palette BADS didn't choose is a bad way to open that conversation. See
|
|
126
126
|
// docs/superpowers/specs/2026-09-10-client-owned-components-design.md →
|
|
127
|
-
// "Accessibility floor: flag, do not enforce" and
|
|
127
|
+
// "Accessibility floor: flag, do not enforce" and AGENTS.md → Accessibility
|
|
128
128
|
// Floor. readSourceOfTruth() never throws and defaults to "bads" with no
|
|
129
129
|
// identity file, so upstream BADS and "bads"-owned forks are unaffected.
|
|
130
130
|
//
|
|
@@ -295,7 +295,7 @@ function resolveValue(value, modeTokens, depth) {
|
|
|
295
295
|
// these fail AAA, the audit emits a warning instead of an error: the picker
|
|
296
296
|
// surfaces the same warning in-product and clients can ship brand colors that
|
|
297
297
|
// don't meet AAA as long as they accept the documented trade-off (see
|
|
298
|
-
//
|
|
298
|
+
// AGENTS.md → Accessibility Floor).
|
|
299
299
|
const PAIRS = [
|
|
300
300
|
['foreground', 'background', 'body text on page'],
|
|
301
301
|
['card-foreground', 'card', 'text on card'],
|
|
@@ -571,10 +571,31 @@ if (DOWNGRADE_AAA) {
|
|
|
571
571
|
}
|
|
572
572
|
}
|
|
573
573
|
|
|
574
|
+
// Every theme token resolved to a hex per mode, so a consumer of --json (the
|
|
575
|
+
// sticker sheet's token table) reads the audit's own resolution instead of
|
|
576
|
+
// re-implementing oklch math. Translucent tokens are flattened over white and
|
|
577
|
+
// carry `alpha`; unresolvable ones (oklch(from ...)) are omitted.
|
|
578
|
+
function resolvedTokens() {
|
|
579
|
+
const out = {};
|
|
580
|
+
for (const mode of ['light', 'dark']) {
|
|
581
|
+
out[mode] = {};
|
|
582
|
+
for (const [key, tok] of Object.entries(tokens.theme[mode])) {
|
|
583
|
+
if (!tok || typeof tok !== 'object' || tok.$type !== 'color') continue;
|
|
584
|
+
const raw = resolveValue(tok.$value, tokens.theme[mode]);
|
|
585
|
+
if (!raw) continue;
|
|
586
|
+
const entry = { hex: toHex(flattenOver(raw, [1, 1, 1])) };
|
|
587
|
+
if (raw.length === 4 && raw[3] < 1) entry.alpha = Number(raw[3].toFixed(3));
|
|
588
|
+
out[mode][key] = entry;
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
return out;
|
|
592
|
+
}
|
|
593
|
+
|
|
574
594
|
if (json) {
|
|
575
595
|
console.log(JSON.stringify({
|
|
576
596
|
floor: { normal: NORMAL_FLOOR, large: LARGE_FLOOR },
|
|
577
597
|
clientOwned: CLIENT_OWNED,
|
|
598
|
+
tokens: resolvedTokens(),
|
|
578
599
|
results: all,
|
|
579
600
|
runtimeMutated: brandResults,
|
|
580
601
|
staleExceptions,
|
|
@@ -652,14 +673,14 @@ if (json) {
|
|
|
652
673
|
if (warned.length || brandWarnings) {
|
|
653
674
|
console.log(
|
|
654
675
|
`\nWarnings are brand-derived pairs below AAA. The brand picker surfaces` +
|
|
655
|
-
` the same warning in-product (see
|
|
676
|
+
` the same warning in-product (see AGENTS.md → Accessibility Floor). Not blocking.`,
|
|
656
677
|
);
|
|
657
678
|
}
|
|
658
679
|
if (clientDowngraded) {
|
|
659
680
|
console.log(
|
|
660
681
|
`\n${clientDowngraded} pair${clientDowngraded === 1 ? '' : 's'} below the AAA floor ${clientDowngraded === 1 ? 'is' : 'are'} ` +
|
|
661
682
|
`${CLIENT_OWNED_NOTE} (sourceOfTruth.components === "client"). Your palette is being held to AA, ` +
|
|
662
|
-
`not AAA — see
|
|
683
|
+
`not AAA — see AGENTS.md → Accessibility Floor. Not blocking.`,
|
|
663
684
|
);
|
|
664
685
|
}
|
|
665
686
|
if (failed.length) process.exit(1);
|
package/src/api/brand-colors.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import fs from "node:fs/promises";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { NextResponse } from "next/server";
|
|
4
|
+
import { refuseUnsafeWrite } from "./dev-write-guard";
|
|
4
5
|
|
|
5
6
|
const COLORS_PATH = path.join(process.cwd(), "brand-colors.json");
|
|
6
7
|
|
|
@@ -63,6 +64,8 @@ export async function POST(request: Request) {
|
|
|
63
64
|
if (process.env.NODE_ENV !== "development") {
|
|
64
65
|
return NextResponse.json({ ok: false, error: "dev-only" }, { status: 403 });
|
|
65
66
|
}
|
|
67
|
+
const refused = refuseUnsafeWrite(request);
|
|
68
|
+
if (refused) return refused;
|
|
66
69
|
|
|
67
70
|
let op: Op;
|
|
68
71
|
try {
|
package/src/api/brand-fonts.ts
CHANGED
|
@@ -2,6 +2,7 @@ import fs from "node:fs/promises";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { spawn } from "node:child_process";
|
|
4
4
|
import { NextResponse } from "next/server";
|
|
5
|
+
import { refuseUnsafeWrite } from "./dev-write-guard";
|
|
5
6
|
|
|
6
7
|
const FONTS_PATH = path.join(process.cwd(), "brand-fonts.json");
|
|
7
8
|
// Canonical location — ships with the npm package via the `./fonts/*` export.
|
|
@@ -120,6 +121,8 @@ export async function POST(request: Request) {
|
|
|
120
121
|
if (process.env.NODE_ENV !== "development") {
|
|
121
122
|
return NextResponse.json({ ok: false, error: "dev-only" }, { status: 403 });
|
|
122
123
|
}
|
|
124
|
+
const refused = refuseUnsafeWrite(request);
|
|
125
|
+
if (refused) return refused;
|
|
123
126
|
|
|
124
127
|
const contentType = request.headers.get("content-type") ?? "";
|
|
125
128
|
|
package/src/api/brand-mark.ts
CHANGED
|
@@ -2,6 +2,7 @@ import fs from "node:fs/promises";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { NextResponse } from "next/server";
|
|
4
4
|
import { sanitizeSvg } from "@behavioral-agentic-design-system/core/lib/svg-sanitize";
|
|
5
|
+
import { refuseUnsafeWrite } from "./dev-write-guard";
|
|
5
6
|
|
|
6
7
|
const MARK_PATH = path.join(process.cwd(), "brand-mark.json");
|
|
7
8
|
const PUBLIC_PATH = path.join(process.cwd(), "public", "brand-mark.svg");
|
|
@@ -58,6 +59,8 @@ export async function POST(request: Request) {
|
|
|
58
59
|
if (process.env.NODE_ENV !== "development") {
|
|
59
60
|
return NextResponse.json({ ok: false, error: "dev-only" }, { status: 403 });
|
|
60
61
|
}
|
|
62
|
+
const refused = refuseUnsafeWrite(request);
|
|
63
|
+
if (refused) return refused;
|
|
61
64
|
|
|
62
65
|
let body: { svg?: string };
|
|
63
66
|
try {
|
|
@@ -116,10 +119,12 @@ export async function POST(request: Request) {
|
|
|
116
119
|
});
|
|
117
120
|
}
|
|
118
121
|
|
|
119
|
-
export async function DELETE() {
|
|
122
|
+
export async function DELETE(request: Request) {
|
|
120
123
|
if (process.env.NODE_ENV !== "development") {
|
|
121
124
|
return NextResponse.json({ ok: false, error: "dev-only" }, { status: 403 });
|
|
122
125
|
}
|
|
126
|
+
const refused = refuseUnsafeWrite(request);
|
|
127
|
+
if (refused) return refused;
|
|
123
128
|
|
|
124
129
|
let existing: MarkFile;
|
|
125
130
|
try {
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// Who may call a dev-only write route.
|
|
2
|
+
//
|
|
3
|
+
// WHY THIS EXISTS. These routes write files on your computer (tokens, docs, fonts, the brand mark) and one of
|
|
4
|
+
// them runs `git commit`. A page open in the same browser can send requests to localhost, and a hostile name
|
|
5
|
+
// that points at 127.0.0.1 (DNS rebinding) reaches the dev server as if it were local. The NODE_ENV check alone
|
|
6
|
+
// answers neither. This is the same Host / Origin / content-type reasoning as tools/comments/server/comments-guard.mjs,
|
|
7
|
+
// without that guard's custom header, so the app's own same-origin fetches keep working unchanged.
|
|
8
|
+
//
|
|
9
|
+
// 1. Host must be localhost, 127.0.0.1 or [::1]. A rebound name arrives with its own name here and is refused.
|
|
10
|
+
// 2. Origin when present (every request a web page makes carries one) must be the same origin as Host.
|
|
11
|
+
// 3. Fetch Sec-Fetch-Site, when present, must be same-origin or none.
|
|
12
|
+
// 4. Type a body must be application/json or multipart/form-data. A cross-site form post cannot send JSON.
|
|
13
|
+
//
|
|
14
|
+
// A request from curl has no Origin and passes gates 2 and 3, so local tools still work.
|
|
15
|
+
//
|
|
16
|
+
// KEEP IN SYNC with app/api/_lib/dev-write-guard.ts: app/api routes are inlined copies of these handlers
|
|
17
|
+
// (see app/api/layers/file/route.ts for why), so they cannot import across the workspace.
|
|
18
|
+
|
|
19
|
+
const LOCAL_HOST = /^(localhost|127\.0\.0\.1|\[::1\])(:\d{1,5})?$/;
|
|
20
|
+
const BODY_TYPE = /^(application\/json|multipart\/form-data)\s*(;|$)/i;
|
|
21
|
+
|
|
22
|
+
/** A 403/415 Response when the request may not write, or null when it may go on. */
|
|
23
|
+
export function refuseUnsafeWrite(request: Request): Response | null {
|
|
24
|
+
const h = request.headers;
|
|
25
|
+
const host = h.get("host") ?? "";
|
|
26
|
+
if (!LOCAL_HOST.test(host)) return deny(403, "This route only answers requests addressed to localhost.");
|
|
27
|
+
|
|
28
|
+
const origin = h.get("origin");
|
|
29
|
+
if (origin !== null) {
|
|
30
|
+
let originHost = "";
|
|
31
|
+
try {
|
|
32
|
+
originHost = new URL(origin).host;
|
|
33
|
+
} catch {
|
|
34
|
+
// An unparseable Origin (including the literal "null") is never a local page.
|
|
35
|
+
}
|
|
36
|
+
if (originHost !== host) return deny(403, "This route only answers pages served from this server.");
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const site = h.get("sec-fetch-site");
|
|
40
|
+
if (site !== null && site !== "same-origin" && site !== "none") {
|
|
41
|
+
return deny(403, "This route only answers pages served from this server.");
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const hasBody = request.method === "POST" || request.method === "PUT" || request.method === "PATCH";
|
|
45
|
+
if (hasBody && !BODY_TYPE.test(h.get("content-type") ?? "")) {
|
|
46
|
+
return deny(415, "Send application/json.");
|
|
47
|
+
}
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function deny(status: number, error: string): Response {
|
|
52
|
+
return Response.json({ ok: false, error }, { status });
|
|
53
|
+
}
|
package/src/api/layers/file.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
2
|
import fs from "node:fs";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { promisify } from "node:util";
|
|
5
|
+
import { refuseUnsafeWrite } from "../dev-write-guard";
|
|
5
6
|
|
|
6
|
-
const
|
|
7
|
+
const execFileAsync = promisify(execFile);
|
|
7
8
|
const ROOT = process.cwd();
|
|
8
9
|
|
|
9
10
|
// Read allowlist. Reads are public (open-source docs) so we expand freely to
|
|
@@ -22,6 +23,7 @@ const ALLOWED_ROOT_MD = new Set([
|
|
|
22
23
|
"CLAUDE.md",
|
|
23
24
|
"CAPABILITIES.md",
|
|
24
25
|
"AGENTS.md",
|
|
26
|
+
"GEMINI.md",
|
|
25
27
|
"ATOMIC_DESIGN.md",
|
|
26
28
|
"BADS_SYNC.md",
|
|
27
29
|
"CHANGELOG.md",
|
|
@@ -48,6 +50,7 @@ function isAllowed(rel: string) {
|
|
|
48
50
|
if (norm === "packages/core/src/tokens.json") return true;
|
|
49
51
|
if (/^layer-[\w-]+\//.test(norm) && /\.(md|json)$/.test(norm)) return true;
|
|
50
52
|
if (/^docs\/[\w.-]+\.md$/.test(norm)) return true;
|
|
53
|
+
if (/^docs\/agent-rules\/[\w.-]+\.(md|json)$/.test(norm)) return true;
|
|
51
54
|
if (/^disciplines\/[\w./-]+\.(md|json)$/.test(norm)) return true;
|
|
52
55
|
if (/^prompts\/[\w.-]+\.md$/.test(norm)) return true;
|
|
53
56
|
if (/^\.claude\/skills\/[\w.-]+\/SKILL\.md$/.test(norm)) return true;
|
|
@@ -78,6 +81,8 @@ export async function POST(request: Request) {
|
|
|
78
81
|
if (process.env.NODE_ENV !== "development") {
|
|
79
82
|
return Response.json({ error: "dev-only" }, { status: 403 });
|
|
80
83
|
}
|
|
84
|
+
const refused = refuseUnsafeWrite(request);
|
|
85
|
+
if (refused) return refused;
|
|
81
86
|
try {
|
|
82
87
|
const body = (await request.json()) as {
|
|
83
88
|
path: string;
|
|
@@ -93,10 +98,10 @@ export async function POST(request: Request) {
|
|
|
93
98
|
|
|
94
99
|
if (body.commit !== false) {
|
|
95
100
|
const message = body.message?.trim() || `docs: edit ${body.path}`;
|
|
96
|
-
await
|
|
101
|
+
await execFileAsync("git", ["add", "--", body.path], { cwd: ROOT });
|
|
97
102
|
// --allow-empty so saves with no diff don't error; precommit hook still runs.
|
|
98
103
|
try {
|
|
99
|
-
await
|
|
104
|
+
await execFileAsync("git", ["commit", "-m", message], { cwd: ROOT });
|
|
100
105
|
} catch (e) {
|
|
101
106
|
// No diff is fine. Anything else surfaces as an error.
|
|
102
107
|
const msg = e instanceof Error ? e.message : String(e);
|