terraproof 0.0.0-stage → 0.4.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.
Files changed (182) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +356 -2
  3. package/bin/terraproof.js +4 -0
  4. package/dist/router/apply.js +147 -0
  5. package/dist/router/classify.js +111 -0
  6. package/dist/router/explain.js +9 -0
  7. package/dist/router/index.js +272 -0
  8. package/dist/router/resolve.js +239 -0
  9. package/dist/router/score.js +60 -0
  10. package/dist/router/types.js +1 -0
  11. package/dist/router/validate.js +81 -0
  12. package/instructions/engineering.md +14 -0
  13. package/instructions/security.md +14 -0
  14. package/instructions/simplicity.md +13 -0
  15. package/package.json +65 -4
  16. package/routing/DOMAIN_ROUTING.md +161 -0
  17. package/routing/ROUTER_DESIGN.md +173 -0
  18. package/routing/SKILL_MANIFEST.md +86 -0
  19. package/routing/checks.json +121 -0
  20. package/routing/collections.json +47 -0
  21. package/routing/registry.json +2211 -0
  22. package/routing/rules.json +64 -0
  23. package/skills/accuracy-assessment/SKILL.md +213 -0
  24. package/skills/accuracy-assessment/UPSTREAM.md +7 -0
  25. package/skills/accuracy-assessment/references/stratified-estimator.md +127 -0
  26. package/skills/accuracy-assessment/skill.json +103 -0
  27. package/skills/brainstorming/SKILL.md +250 -0
  28. package/skills/brainstorming/UPSTREAM.md +29 -0
  29. package/skills/brainstorming/scripts/frame-template.html +213 -0
  30. package/skills/brainstorming/scripts/helper.js +167 -0
  31. package/skills/brainstorming/scripts/server.cjs +723 -0
  32. package/skills/brainstorming/scripts/start-server.sh +209 -0
  33. package/skills/brainstorming/scripts/stop-server.sh +120 -0
  34. package/skills/brainstorming/skill.json +73 -0
  35. package/skills/brainstorming/spec-document-reviewer-prompt.md +49 -0
  36. package/skills/brainstorming/visual-companion.md +299 -0
  37. package/skills/crs-and-units/SKILL.md +200 -0
  38. package/skills/crs-and-units/UPSTREAM.md +7 -0
  39. package/skills/crs-and-units/skill.json +74 -0
  40. package/skills/design-postgis-tables/SKILL.md +494 -0
  41. package/skills/design-postgis-tables/UPSTREAM.md +21 -0
  42. package/skills/design-postgis-tables/skill.json +90 -0
  43. package/skills/gdal/SKILL.md +125 -0
  44. package/skills/gdal/UPSTREAM.md +22 -0
  45. package/skills/gdal/references/gdal-recipes.md +103 -0
  46. package/skills/gdal/skill.json +66 -0
  47. package/skills/geomaster/README.md +105 -0
  48. package/skills/geomaster/SKILL.md +366 -0
  49. package/skills/geomaster/UPSTREAM.md +21 -0
  50. package/skills/geomaster/references/advanced-gis.md +376 -0
  51. package/skills/geomaster/references/big-data.md +363 -0
  52. package/skills/geomaster/references/code-examples.md +531 -0
  53. package/skills/geomaster/references/coordinate-systems.md +364 -0
  54. package/skills/geomaster/references/core-libraries.md +273 -0
  55. package/skills/geomaster/references/data-sources.md +330 -0
  56. package/skills/geomaster/references/gis-software.md +369 -0
  57. package/skills/geomaster/references/industry-applications.md +420 -0
  58. package/skills/geomaster/references/machine-learning.md +462 -0
  59. package/skills/geomaster/references/programming-languages.md +456 -0
  60. package/skills/geomaster/references/remote-sensing.md +370 -0
  61. package/skills/geomaster/references/scientific-domains.md +416 -0
  62. package/skills/geomaster/references/specialized-topics.md +428 -0
  63. package/skills/geomaster/references/troubleshooting.md +439 -0
  64. package/skills/geomaster/skill.json +157 -0
  65. package/skills/geopandas/SKILL.md +250 -0
  66. package/skills/geopandas/UPSTREAM.md +22 -0
  67. package/skills/geopandas/references/crs-management.md +231 -0
  68. package/skills/geopandas/references/data-io.md +323 -0
  69. package/skills/geopandas/references/data-structures.md +207 -0
  70. package/skills/geopandas/references/geometric-operations.md +262 -0
  71. package/skills/geopandas/references/spatial-analysis.md +294 -0
  72. package/skills/geopandas/references/visualization.md +230 -0
  73. package/skills/geopandas/scripts/_common.py +605 -0
  74. package/skills/geopandas/scripts/crs_reprojection_plan.py +210 -0
  75. package/skills/geopandas/scripts/export_plan.py +305 -0
  76. package/skills/geopandas/scripts/geometry_validity_report.py +227 -0
  77. package/skills/geopandas/scripts/sensitive_coordinates_checklist.py +230 -0
  78. package/skills/geopandas/scripts/spatial_join_audit.py +368 -0
  79. package/skills/geopandas/scripts/vector_inventory.py +140 -0
  80. package/skills/geopandas/skill.json +116 -0
  81. package/skills/geoparquet-validation/SKILL.md +125 -0
  82. package/skills/geoparquet-validation/UPSTREAM.md +24 -0
  83. package/skills/geoparquet-validation/references/distribution-best-practices.md +118 -0
  84. package/skills/geoparquet-validation/references/gpio-commands.md +264 -0
  85. package/skills/geoparquet-validation/references/tool-comparison.md +155 -0
  86. package/skills/geoparquet-validation/skill.json +71 -0
  87. package/skills/geospatial-data-discovery/SKILL.md +49 -0
  88. package/skills/geospatial-data-discovery/UPSTREAM.md +15 -0
  89. package/skills/geospatial-data-discovery/skill.json +51 -0
  90. package/skills/geospatial-frontend/SKILL.md +86 -0
  91. package/skills/geospatial-frontend/UPSTREAM.md +23 -0
  92. package/skills/geospatial-frontend/references/design-system.md +283 -0
  93. package/skills/geospatial-frontend/references/user-preferences.md +96 -0
  94. package/skills/geospatial-frontend/skill.json +87 -0
  95. package/skills/geozarr/SKILL.md +244 -0
  96. package/skills/geozarr/UPSTREAM.md +21 -0
  97. package/skills/geozarr/skill.json +97 -0
  98. package/skills/networkx/SKILL.md +440 -0
  99. package/skills/networkx/UPSTREAM.md +22 -0
  100. package/skills/networkx/references/algorithms.md +384 -0
  101. package/skills/networkx/references/generators.md +385 -0
  102. package/skills/networkx/references/graph-basics.md +284 -0
  103. package/skills/networkx/references/io.md +457 -0
  104. package/skills/networkx/references/visualization.md +531 -0
  105. package/skills/networkx/skill.json +93 -0
  106. package/skills/raster-processing/SKILL.md +222 -0
  107. package/skills/raster-processing/UPSTREAM.md +7 -0
  108. package/skills/raster-processing/skill.json +81 -0
  109. package/skills/sar-basics/SKILL.md +202 -0
  110. package/skills/sar-basics/UPSTREAM.md +7 -0
  111. package/skills/sar-basics/references/calibration-lut.md +98 -0
  112. package/skills/sar-basics/skill.json +97 -0
  113. package/skills/satellite-preprocessing/SKILL.md +241 -0
  114. package/skills/satellite-preprocessing/UPSTREAM.md +7 -0
  115. package/skills/satellite-preprocessing/skill.json +84 -0
  116. package/skills/scientific-visualization/SKILL.md +285 -0
  117. package/skills/scientific-visualization/UPSTREAM.md +25 -0
  118. package/skills/scientific-visualization/assets/color_palettes.py +263 -0
  119. package/skills/scientific-visualization/assets/nature.mplstyle +68 -0
  120. package/skills/scientific-visualization/assets/presentation.mplstyle +68 -0
  121. package/skills/scientific-visualization/assets/publication.mplstyle +77 -0
  122. package/skills/scientific-visualization/assets/publisher_profiles.json +269 -0
  123. package/skills/scientific-visualization/references/color_palettes.md +227 -0
  124. package/skills/scientific-visualization/references/journal_requirements.md +169 -0
  125. package/skills/scientific-visualization/references/matplotlib_examples.md +336 -0
  126. package/skills/scientific-visualization/references/publication_guidelines.md +196 -0
  127. package/skills/scientific-visualization/references/sources.md +76 -0
  128. package/skills/scientific-visualization/scripts/_common.py +136 -0
  129. package/skills/scientific-visualization/scripts/export_plan.py +493 -0
  130. package/skills/scientific-visualization/scripts/figure_export.py +642 -0
  131. package/skills/scientific-visualization/scripts/image_metadata.py +731 -0
  132. package/skills/scientific-visualization/scripts/palette_audit.py +327 -0
  133. package/skills/scientific-visualization/scripts/style_presets.py +501 -0
  134. package/skills/scientific-visualization/scripts/style_preview.py +232 -0
  135. package/skills/scientific-visualization/skill.json +95 -0
  136. package/skills/spectral-indices/SKILL.md +235 -0
  137. package/skills/spectral-indices/UPSTREAM.md +7 -0
  138. package/skills/spectral-indices/skill.json +88 -0
  139. package/skills/stac-and-cloud-access/SKILL.md +209 -0
  140. package/skills/stac-and-cloud-access/UPSTREAM.md +7 -0
  141. package/skills/stac-and-cloud-access/references/run-manifest.md +94 -0
  142. package/skills/stac-and-cloud-access/skill.json +98 -0
  143. package/skills/statistical-analysis/SKILL.md +446 -0
  144. package/skills/statistical-analysis/UPSTREAM.md +24 -0
  145. package/skills/statistical-analysis/references/assumptions_and_diagnostics.md +379 -0
  146. package/skills/statistical-analysis/references/bayesian_statistics.md +686 -0
  147. package/skills/statistical-analysis/references/effect_sizes_and_power.md +649 -0
  148. package/skills/statistical-analysis/references/reporting_standards.md +482 -0
  149. package/skills/statistical-analysis/references/test_selection_guide.md +129 -0
  150. package/skills/statistical-analysis/scripts/assumption_checks.py +652 -0
  151. package/skills/statistical-analysis/skill.json +127 -0
  152. package/skills/systematic-debugging/SKILL.md +283 -0
  153. package/skills/systematic-debugging/UPSTREAM.md +28 -0
  154. package/skills/systematic-debugging/condition-based-waiting-example.ts +158 -0
  155. package/skills/systematic-debugging/condition-based-waiting.md +115 -0
  156. package/skills/systematic-debugging/defense-in-depth.md +122 -0
  157. package/skills/systematic-debugging/find-polluter.sh +72 -0
  158. package/skills/systematic-debugging/root-cause-tracing.md +169 -0
  159. package/skills/systematic-debugging/skill.json +88 -0
  160. package/skills/time-series-and-change/SKILL.md +217 -0
  161. package/skills/time-series-and-change/UPSTREAM.md +7 -0
  162. package/skills/time-series-and-change/references/change-methods.md +42 -0
  163. package/skills/time-series-and-change/skill.json +116 -0
  164. package/skills/vector-quality/SKILL.md +204 -0
  165. package/skills/vector-quality/UPSTREAM.md +7 -0
  166. package/skills/vector-quality/skill.json +82 -0
  167. package/skills/verification/SKILL.md +120 -0
  168. package/skills/verification/UPSTREAM.md +31 -0
  169. package/skills/verification/skill.json +67 -0
  170. package/skills/writing-plans/SKILL.md +171 -0
  171. package/skills/writing-plans/UPSTREAM.md +23 -0
  172. package/skills/writing-plans/plan-document-reviewer-prompt.md +49 -0
  173. package/skills/writing-plans/skill.json +80 -0
  174. package/sources/SOURCES.md +374 -0
  175. package/third_party/isaaccorley-geospatial-skills/LICENSE +176 -0
  176. package/third_party/isaaccorley-geospatial-skills/NOTICE.md +17 -0
  177. package/third_party/kdense-scientific-agent-skills/LICENSE +21 -0
  178. package/third_party/kdense-scientific-agent-skills/NOTICE.md +19 -0
  179. package/third_party/superpowers/LICENSE +21 -0
  180. package/third_party/superpowers/NOTICE.md +17 -0
  181. package/third_party/timescale-pg-aiguide/LICENSE +176 -0
  182. package/third_party/timescale-pg-aiguide/NOTICE.md +14 -0
@@ -0,0 +1,327 @@
1
+ #!/usr/bin/env python3
2
+ """Audit palette contrast and heuristic grayscale distinguishability.
3
+
4
+ WCAG contrast calculations are exact for the supplied sRGB values. Whether a
5
+ specific WCAG success criterion applies depends on how a color is used. The
6
+ grayscale delta-L* threshold is a screening heuristic, not a standard.
7
+ """
8
+
9
+ from __future__ import annotations
10
+
11
+ import argparse
12
+ import importlib.util
13
+ import itertools
14
+ import math
15
+ import sys
16
+ from pathlib import Path
17
+ from types import ModuleType
18
+ from typing import Any, Iterable
19
+
20
+ from _common import CliError, emit_json, positive_float
21
+
22
+ SCHEMA_VERSION = "1.0"
23
+ DEFAULT_BACKGROUND = "#FFFFFF"
24
+ DEFAULT_GRAYSCALE_DELTA = 10.0
25
+ ROLE_THRESHOLDS = {
26
+ "graphical": 3.0,
27
+ "large-text": 3.0,
28
+ "normal-text": 4.5,
29
+ "enhanced-text": 7.0,
30
+ }
31
+
32
+
33
+ def parse_hex_color(value: str) -> tuple[int, int, int]:
34
+ """Parse an opaque six-digit sRGB color."""
35
+ normalized = value.strip().lstrip("#")
36
+ if len(normalized) != 6:
37
+ raise CliError(f"expected six-digit hex color, got {value!r}")
38
+ try:
39
+ channels = tuple(int(normalized[index : index + 2], 16) for index in (0, 2, 4))
40
+ except ValueError as exc:
41
+ raise CliError(f"invalid hex color: {value!r}") from exc
42
+ return channels # type: ignore[return-value]
43
+
44
+
45
+ def canonical_hex(rgb: tuple[int, int, int]) -> str:
46
+ return "#" + "".join(f"{channel:02X}" for channel in rgb)
47
+
48
+
49
+ def _linear_channel(channel: int) -> float:
50
+ encoded = channel / 255.0
51
+ return encoded / 12.92 if encoded <= 0.04045 else ((encoded + 0.055) / 1.055) ** 2.4
52
+
53
+
54
+ def relative_luminance(rgb: tuple[int, int, int]) -> float:
55
+ """Return WCAG relative luminance for an sRGB color."""
56
+ red, green, blue = (_linear_channel(channel) for channel in rgb)
57
+ return 0.2126 * red + 0.7152 * green + 0.0722 * blue
58
+
59
+
60
+ def contrast_ratio(
61
+ first: tuple[int, int, int], second: tuple[int, int, int]
62
+ ) -> float:
63
+ """Return WCAG contrast ratio for two opaque sRGB colors."""
64
+ first_luminance = relative_luminance(first)
65
+ second_luminance = relative_luminance(second)
66
+ lighter = max(first_luminance, second_luminance)
67
+ darker = min(first_luminance, second_luminance)
68
+ return (lighter + 0.05) / (darker + 0.05)
69
+
70
+
71
+ def cie_lstar(rgb: tuple[int, int, int]) -> float:
72
+ """Return CIE L* from sRGB/D65, used for grayscale screening."""
73
+ luminance = relative_luminance(rgb)
74
+ delta = 6.0 / 29.0
75
+ if luminance > delta**3:
76
+ transformed = luminance ** (1.0 / 3.0)
77
+ else:
78
+ transformed = luminance / (3.0 * delta**2) + 4.0 / 29.0
79
+ return 116.0 * transformed - 16.0
80
+
81
+
82
+ def _load_palette_asset() -> ModuleType:
83
+ asset = Path(__file__).resolve().parents[1] / "assets" / "color_palettes.py"
84
+ spec = importlib.util.spec_from_file_location(
85
+ "_scientific_visualization_color_palettes", asset
86
+ )
87
+ if spec is None or spec.loader is None:
88
+ raise CliError(f"cannot load bundled palette asset: {asset}")
89
+ module = importlib.util.module_from_spec(spec)
90
+ spec.loader.exec_module(module)
91
+ return module
92
+
93
+
94
+ def bundled_palettes() -> dict[str, list[str]]:
95
+ """Load bundled palettes without importing Matplotlib."""
96
+ module = _load_palette_asset()
97
+ palettes = getattr(module, "PALETTES", None)
98
+ if not isinstance(palettes, dict):
99
+ raise CliError("bundled color_palettes.py does not define PALETTES")
100
+ normalized: dict[str, list[str]] = {}
101
+ for name, colors in palettes.items():
102
+ if isinstance(name, str) and isinstance(colors, (list, tuple)):
103
+ normalized[name] = [canonical_hex(parse_hex_color(item)) for item in colors]
104
+ return normalized
105
+
106
+
107
+ def audit_palette(
108
+ colors: Iterable[str],
109
+ *,
110
+ background: str = DEFAULT_BACKGROUND,
111
+ role: str = "graphical",
112
+ contrast_threshold: float | None = None,
113
+ grayscale_min_delta: float = DEFAULT_GRAYSCALE_DELTA,
114
+ name: str | None = None,
115
+ ) -> dict[str, Any]:
116
+ """Return deterministic palette contrast and grayscale screening results."""
117
+ if role not in ROLE_THRESHOLDS and contrast_threshold is None:
118
+ raise CliError(
119
+ f"unknown role {role!r}; provide an explicit contrast threshold"
120
+ )
121
+ threshold = (
122
+ float(contrast_threshold)
123
+ if contrast_threshold is not None
124
+ else ROLE_THRESHOLDS[role]
125
+ )
126
+ if not math.isfinite(threshold) or threshold <= 1:
127
+ raise CliError("contrast threshold must be finite and greater than 1")
128
+ if not math.isfinite(grayscale_min_delta) or grayscale_min_delta <= 0:
129
+ raise CliError("grayscale delta threshold must be positive and finite")
130
+
131
+ canonical = [canonical_hex(parse_hex_color(color)) for color in colors]
132
+ if not canonical:
133
+ raise CliError("at least one color is required")
134
+ if len(canonical) > 32:
135
+ raise CliError("palette is limited to 32 colors")
136
+ background_rgb = parse_hex_color(background)
137
+ background_hex = canonical_hex(background_rgb)
138
+
139
+ color_records: list[dict[str, Any]] = []
140
+ parsed: list[tuple[int, int, int]] = []
141
+ for index, color in enumerate(canonical):
142
+ rgb = parse_hex_color(color)
143
+ parsed.append(rgb)
144
+ ratio = contrast_ratio(rgb, background_rgb)
145
+ color_records.append(
146
+ {
147
+ "index": index,
148
+ "hex": color,
149
+ "rgb": list(rgb),
150
+ "relative_luminance": round(relative_luminance(rgb), 6),
151
+ "cie_lstar": round(cie_lstar(rgb), 3),
152
+ "contrast_against_background": round(ratio, 3),
153
+ "background_screen": "pass" if ratio >= threshold else "review",
154
+ }
155
+ )
156
+
157
+ pair_records: list[dict[str, Any]] = []
158
+ for first, second in itertools.combinations(range(len(parsed)), 2):
159
+ first_rgb = parsed[first]
160
+ second_rgb = parsed[second]
161
+ delta = abs(cie_lstar(first_rgb) - cie_lstar(second_rgb))
162
+ pair_records.append(
163
+ {
164
+ "first_index": first,
165
+ "second_index": second,
166
+ "first_hex": canonical[first],
167
+ "second_hex": canonical[second],
168
+ "contrast_ratio": round(contrast_ratio(first_rgb, second_rgb), 3),
169
+ "grayscale_delta_lstar": round(delta, 3),
170
+ "grayscale_screen": (
171
+ "pass" if delta >= grayscale_min_delta else "review"
172
+ ),
173
+ }
174
+ )
175
+
176
+ background_reviews = sum(
177
+ item["background_screen"] == "review" for item in color_records
178
+ )
179
+ grayscale_reviews = sum(
180
+ item["grayscale_screen"] == "review" for item in pair_records
181
+ )
182
+ return {
183
+ "schema_version": SCHEMA_VERSION,
184
+ "palette": {
185
+ "name": name,
186
+ "colors": color_records,
187
+ "color_count": len(color_records),
188
+ },
189
+ "background": background_hex,
190
+ "contrast_screen": {
191
+ "role": role,
192
+ "threshold": threshold,
193
+ "review_count": background_reviews,
194
+ "basis": (
195
+ "WCAG 2.2 contrast mathematics. Applicability depends on use; "
196
+ "for example, SC 1.4.11 covers graphical objects required to "
197
+ "understand web content."
198
+ ),
199
+ },
200
+ "grayscale_screen": {
201
+ "minimum_delta_lstar": grayscale_min_delta,
202
+ "review_count": grayscale_reviews,
203
+ "pair_count": len(pair_records),
204
+ "basis": (
205
+ "Heuristic CIE L* separation after removing hue. It does not "
206
+ "predict all viewing, printing, or color-vision conditions."
207
+ ),
208
+ },
209
+ "pairs": pair_records,
210
+ "notice": (
211
+ "No palette can establish accessibility by itself. Preserve labels "
212
+ "and add redundant encodings such as markers, line styles, direct "
213
+ "labels, or patterns; evaluate the rendered figure in context."
214
+ ),
215
+ }
216
+
217
+
218
+ def build_parser() -> argparse.ArgumentParser:
219
+ parser = argparse.ArgumentParser(
220
+ description=(
221
+ "Audit sRGB palette contrast against a background and screen "
222
+ "pairwise grayscale distinguishability. No network is used."
223
+ )
224
+ )
225
+ source = parser.add_mutually_exclusive_group(required=False)
226
+ source.add_argument(
227
+ "--palette", help="bundled palette name (use --list-palettes)"
228
+ )
229
+ source.add_argument(
230
+ "--color",
231
+ action="append",
232
+ default=[],
233
+ help="six-digit hex color; repeat for each palette color",
234
+ )
235
+ parser.add_argument(
236
+ "--list-palettes",
237
+ action="store_true",
238
+ help="print bundled palette names and exit",
239
+ )
240
+ parser.add_argument("--background", default=DEFAULT_BACKGROUND)
241
+ parser.add_argument(
242
+ "--role",
243
+ choices=sorted(ROLE_THRESHOLDS),
244
+ default="graphical",
245
+ help="select the WCAG contrast screening threshold",
246
+ )
247
+ parser.add_argument(
248
+ "--contrast-threshold",
249
+ type=positive_float,
250
+ help="override the role threshold",
251
+ )
252
+ parser.add_argument(
253
+ "--grayscale-min-delta",
254
+ type=positive_float,
255
+ default=DEFAULT_GRAYSCALE_DELTA,
256
+ help=(
257
+ "heuristic minimum CIE L* separation "
258
+ f"(default: {DEFAULT_GRAYSCALE_DELTA})"
259
+ ),
260
+ )
261
+ parser.add_argument(
262
+ "--fail-on",
263
+ choices=("none", "background", "grayscale", "any"),
264
+ default="none",
265
+ help="return exit 1 for selected review findings (default: none)",
266
+ )
267
+ parser.add_argument("--output", help="optional JSON report path")
268
+ parser.add_argument(
269
+ "--force", action="store_true", help="overwrite an existing JSON report"
270
+ )
271
+ return parser
272
+
273
+
274
+ def main(argv: list[str] | None = None) -> int:
275
+ parser = build_parser()
276
+ try:
277
+ args = parser.parse_args(argv)
278
+ palettes = bundled_palettes()
279
+ if args.list_palettes:
280
+ emit_json(
281
+ {
282
+ "schema_version": SCHEMA_VERSION,
283
+ "palettes": {
284
+ name: {"count": len(colors), "colors": colors}
285
+ for name, colors in sorted(palettes.items())
286
+ },
287
+ },
288
+ output=args.output,
289
+ force=args.force,
290
+ )
291
+ return 0
292
+ if args.palette:
293
+ if args.palette not in palettes:
294
+ raise CliError(
295
+ f"unknown palette {args.palette!r}; "
296
+ f"available: {', '.join(sorted(palettes))}"
297
+ )
298
+ colors = palettes[args.palette]
299
+ palette_name = args.palette
300
+ else:
301
+ colors = args.color
302
+ palette_name = "custom"
303
+ if not colors:
304
+ raise CliError("provide --palette or at least one --color")
305
+
306
+ report = audit_palette(
307
+ colors,
308
+ background=args.background,
309
+ role=args.role,
310
+ contrast_threshold=args.contrast_threshold,
311
+ grayscale_min_delta=args.grayscale_min_delta,
312
+ name=palette_name,
313
+ )
314
+ emit_json(report, output=args.output, force=args.force)
315
+ background_review = report["contrast_screen"]["review_count"] > 0
316
+ grayscale_review = report["grayscale_screen"]["review_count"] > 0
317
+ should_fail = (
318
+ (args.fail_on in {"background", "any"} and background_review)
319
+ or (args.fail_on in {"grayscale", "any"} and grayscale_review)
320
+ )
321
+ return 1 if should_fail else 0
322
+ except CliError as exc:
323
+ parser.exit(2, f"error: {exc}\n")
324
+
325
+
326
+ if __name__ == "__main__":
327
+ sys.exit(main())