terraproof 0.0.0-stage → 0.4.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.
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,493 @@
1
+ #!/usr/bin/env python3
2
+ """Build and screen against dated publication-export planning snapshots."""
3
+
4
+ from __future__ import annotations
5
+
6
+ import argparse
7
+ import json
8
+ import math
9
+ import sys
10
+ from pathlib import Path
11
+ from typing import Any
12
+
13
+ from _common import CliError, emit_json, positive_float
14
+
15
+ SCHEMA_VERSION = "1.0"
16
+ PROFILE_PATH = Path(__file__).resolve().parents[1] / "assets" / "publisher_profiles.json"
17
+
18
+
19
+ def load_profiles() -> dict[str, Any]:
20
+ try:
21
+ document = json.loads(PROFILE_PATH.read_text(encoding="utf-8"))
22
+ except (OSError, json.JSONDecodeError) as exc:
23
+ raise CliError(f"cannot load publisher profile asset: {exc}") from exc
24
+ if not isinstance(document.get("profiles"), dict):
25
+ raise CliError("publisher profile asset does not contain profiles")
26
+ return document
27
+
28
+
29
+ def build_plan(
30
+ publisher: str,
31
+ *,
32
+ figure_type: str,
33
+ width: str | None = None,
34
+ phase: str | None = None,
35
+ ) -> dict[str, Any]:
36
+ """Build an explicit plan without exporting or claiming compliance."""
37
+ document = load_profiles()
38
+ try:
39
+ profile = document["profiles"][publisher]
40
+ except KeyError as exc:
41
+ raise CliError(
42
+ f"unknown publisher profile {publisher!r}; "
43
+ f"available: {', '.join(sorted(document['profiles']))}"
44
+ ) from exc
45
+ widths = profile.get("widths_mm") or {}
46
+ if width is not None and width not in widths:
47
+ raise CliError(
48
+ f"unknown width {width!r} for {publisher}; "
49
+ f"available: {', '.join(sorted(widths))}"
50
+ )
51
+ format_map = profile.get("formats") or {}
52
+ dpi_map = profile.get("raster_dpi") or {}
53
+ available_types = sorted(set(format_map) | set(dpi_map))
54
+ if figure_type not in available_types and available_types:
55
+ raise CliError(
56
+ f"unknown figure type {figure_type!r} for {publisher}; "
57
+ f"available: {', '.join(available_types)}"
58
+ )
59
+
60
+ profile_phase = profile.get("phase")
61
+ phase_matches = phase is None or phase == profile_phase
62
+ selected_width = float(widths[width]) if width is not None else None
63
+ return {
64
+ "schema_version": SCHEMA_VERSION,
65
+ "publisher": publisher,
66
+ "label": profile["label"],
67
+ "scope": profile["scope"],
68
+ "profile_accessed": document["accessed"],
69
+ "profile_phase": profile_phase,
70
+ "requested_phase": phase,
71
+ "phase_matches_snapshot": phase_matches,
72
+ "journal_specific": profile.get("journal_specific"),
73
+ "figure_type": figure_type,
74
+ "width": {
75
+ "name": width,
76
+ "millimeters": selected_width,
77
+ "available": widths,
78
+ },
79
+ "max_height_mm": profile.get("max_height_mm"),
80
+ "formats": format_map.get(figure_type) if format_map else None,
81
+ "raster_dpi": dpi_map.get(figure_type) if dpi_map else None,
82
+ "color_modes": profile.get("color_modes"),
83
+ "preferred_color_mode": profile.get("preferred_color_mode"),
84
+ "max_file_bytes": profile.get("max_file_bytes"),
85
+ "max_file_bytes_exclusive": profile.get("max_file_bytes_exclusive"),
86
+ "width_range_px_at_300_dpi": profile.get("width_range_px_at_300_dpi"),
87
+ "max_height_px_at_300_dpi": profile.get("max_height_px_at_300_dpi"),
88
+ "sources": profile["sources"],
89
+ "notes": profile.get("notes", []),
90
+ "notice": document["notice"],
91
+ }
92
+
93
+
94
+ def _finding(
95
+ name: str,
96
+ status: str,
97
+ *,
98
+ actual: Any,
99
+ expected: Any,
100
+ detail: str,
101
+ ) -> dict[str, Any]:
102
+ return {
103
+ "name": name,
104
+ "status": status,
105
+ "actual": actual,
106
+ "expected": expected,
107
+ "detail": detail,
108
+ }
109
+
110
+
111
+ def _normalized_mode(mode: str | None) -> str | None:
112
+ if mode is None:
113
+ return None
114
+ if mode in {"RGB", "RGBA"}:
115
+ return "RGB"
116
+ if mode in {"L", "LA", "1", "I", "I;16", "F"}:
117
+ return "L"
118
+ return mode
119
+
120
+
121
+ def _effective_dimensions(
122
+ metadata: dict[str, Any], target_width_mm: float | None
123
+ ) -> tuple[float | None, float | None, float | None]:
124
+ """Return effective DPI, width mm, and height mm."""
125
+ width_px = metadata.get("width_px")
126
+ height_px = metadata.get("height_px")
127
+ if target_width_mm is not None and width_px:
128
+ dpi = float(width_px) / (target_width_mm / 25.4)
129
+ height_mm = (
130
+ float(height_px) / float(width_px) * target_width_mm
131
+ if height_px
132
+ else None
133
+ )
134
+ return dpi, target_width_mm, height_mm
135
+ width_mm = metadata.get("width_mm") or metadata.get("width_mm_from_metadata")
136
+ height_mm = metadata.get("height_mm") or metadata.get("height_mm_from_metadata")
137
+ dpi_values = [
138
+ float(value)
139
+ for value in (metadata.get("dpi_x"), metadata.get("dpi_y"))
140
+ if value
141
+ ]
142
+ return (
143
+ min(dpi_values) if dpi_values else None,
144
+ float(width_mm) if width_mm is not None else None,
145
+ float(height_mm) if height_mm is not None else None,
146
+ )
147
+
148
+
149
+ def validate_against_plan(
150
+ plan: dict[str, Any],
151
+ input_path: str | Path,
152
+ *,
153
+ width_tolerance_mm: float = 1.0,
154
+ ) -> dict[str, Any]:
155
+ """Screen inspectable file properties against one explicit plan."""
156
+ try:
157
+ from image_metadata import inspect_file
158
+ except ImportError as exc:
159
+ raise CliError(f"cannot import image_metadata.py: {exc}") from exc
160
+ inspected = inspect_file(input_path)
161
+ metadata = inspected["metadata"]
162
+ findings: list[dict[str, Any]] = []
163
+
164
+ formats = plan.get("formats")
165
+ actual_format = str(metadata.get("format", "")).lower()
166
+ if formats is None:
167
+ findings.append(
168
+ _finding(
169
+ "format",
170
+ "unknown",
171
+ actual=actual_format,
172
+ expected=None,
173
+ detail="The profile does not state a universal format for this type.",
174
+ )
175
+ )
176
+ elif not formats:
177
+ findings.append(
178
+ _finding(
179
+ "format",
180
+ "unknown",
181
+ actual=actual_format,
182
+ expected=[],
183
+ detail="No raster format was stated on the cited profile page.",
184
+ )
185
+ )
186
+ else:
187
+ findings.append(
188
+ _finding(
189
+ "format",
190
+ "pass" if actual_format in formats else "fail",
191
+ actual=actual_format,
192
+ expected=formats,
193
+ detail="Compared with formats explicitly recorded in the snapshot.",
194
+ )
195
+ )
196
+
197
+ target_width = plan["width"]["millimeters"]
198
+ effective_dpi, effective_width, effective_height = _effective_dimensions(
199
+ metadata, target_width
200
+ )
201
+ dpi_rule = plan.get("raster_dpi")
202
+ if metadata.get("kind") == "raster" and dpi_rule:
203
+ if effective_dpi is None:
204
+ dpi_status = "unknown"
205
+ elif (
206
+ dpi_rule.get("min") is not None
207
+ and effective_dpi < float(dpi_rule["min"])
208
+ and not math.isclose(
209
+ effective_dpi,
210
+ float(dpi_rule["min"]),
211
+ rel_tol=1e-12,
212
+ abs_tol=1e-9,
213
+ )
214
+ ):
215
+ dpi_status = "fail"
216
+ elif (
217
+ dpi_rule.get("min_exclusive") is not None
218
+ and effective_dpi <= float(dpi_rule["min_exclusive"])
219
+ ):
220
+ dpi_status = "fail"
221
+ elif (
222
+ dpi_rule.get("max") is not None
223
+ and effective_dpi > float(dpi_rule["max"])
224
+ and not math.isclose(
225
+ effective_dpi,
226
+ float(dpi_rule["max"]),
227
+ rel_tol=1e-12,
228
+ abs_tol=1e-9,
229
+ )
230
+ ):
231
+ dpi_status = "fail"
232
+ else:
233
+ dpi_status = "pass"
234
+ findings.append(
235
+ _finding(
236
+ "effective_raster_dpi",
237
+ dpi_status,
238
+ actual=effective_dpi,
239
+ expected=dpi_rule,
240
+ detail=(
241
+ "Calculated at the selected final width when supplied; "
242
+ "otherwise uses embedded DPI metadata. Upsampling is not "
243
+ "evidence of added detail."
244
+ ),
245
+ )
246
+ )
247
+ elif dpi_rule and metadata.get("kind") != "raster":
248
+ findings.append(
249
+ _finding(
250
+ "effective_raster_dpi",
251
+ "unknown",
252
+ actual=None,
253
+ expected=dpi_rule,
254
+ detail=(
255
+ "Vector-container DPI is not meaningful and embedded raster "
256
+ "objects were not individually inspected."
257
+ ),
258
+ )
259
+ )
260
+ else:
261
+ findings.append(
262
+ _finding(
263
+ "effective_raster_dpi",
264
+ "unknown",
265
+ actual=effective_dpi,
266
+ expected=dpi_rule,
267
+ detail="No binding DPI rule was recorded for this figure type.",
268
+ )
269
+ )
270
+
271
+ if target_width is not None:
272
+ if effective_width is None:
273
+ width_status = "unknown"
274
+ else:
275
+ width_status = (
276
+ "pass"
277
+ if abs(effective_width - target_width) <= width_tolerance_mm
278
+ else "fail"
279
+ )
280
+ findings.append(
281
+ _finding(
282
+ "final_width_mm",
283
+ width_status,
284
+ actual=effective_width,
285
+ expected={
286
+ "target": target_width,
287
+ "tolerance": width_tolerance_mm,
288
+ },
289
+ detail=(
290
+ "Raster inputs are evaluated at the requested target width; "
291
+ "vector containers use their page dimensions."
292
+ ),
293
+ )
294
+ )
295
+
296
+ max_height = plan.get("max_height_mm")
297
+ if max_height is not None:
298
+ findings.append(
299
+ _finding(
300
+ "final_height_mm",
301
+ (
302
+ "unknown"
303
+ if effective_height is None
304
+ else (
305
+ "pass"
306
+ if effective_height <= float(max_height)
307
+ else "fail"
308
+ )
309
+ ),
310
+ actual=effective_height,
311
+ expected={"max": max_height},
312
+ detail="Height includes the exported page/canvas, not a caption.",
313
+ )
314
+ )
315
+
316
+ pixel_range = plan.get("width_range_px_at_300_dpi")
317
+ if pixel_range and metadata.get("width_px") is not None:
318
+ actual_width_px = int(metadata["width_px"])
319
+ findings.append(
320
+ _finding(
321
+ "pixel_width_snapshot",
322
+ (
323
+ "pass"
324
+ if int(pixel_range[0]) <= actual_width_px <= int(pixel_range[1])
325
+ else "fail"
326
+ ),
327
+ actual=actual_width_px,
328
+ expected={"min": pixel_range[0], "max": pixel_range[1]},
329
+ detail="This publisher expresses its width range at 300 dpi.",
330
+ )
331
+ )
332
+
333
+ max_bytes = plan.get("max_file_bytes")
334
+ max_bytes_exclusive = plan.get("max_file_bytes_exclusive")
335
+ if max_bytes is not None or max_bytes_exclusive is not None:
336
+ actual_bytes = inspected["input"]["size_bytes"]
337
+ if max_bytes_exclusive is not None:
338
+ size_status = (
339
+ "pass" if actual_bytes < int(max_bytes_exclusive) else "fail"
340
+ )
341
+ expected_size = {"less_than": max_bytes_exclusive}
342
+ else:
343
+ size_status = "pass" if actual_bytes <= int(max_bytes) else "fail"
344
+ expected_size = {"max": max_bytes}
345
+ findings.append(
346
+ _finding(
347
+ "file_size",
348
+ size_status,
349
+ actual=actual_bytes,
350
+ expected=expected_size,
351
+ detail="Compared with the dated snapshot's file-size limit.",
352
+ )
353
+ )
354
+
355
+ allowed_modes = plan.get("color_modes")
356
+ actual_mode = metadata.get("mode")
357
+ if allowed_modes:
358
+ normalized_mode = _normalized_mode(actual_mode)
359
+ findings.append(
360
+ _finding(
361
+ "color_mode",
362
+ (
363
+ "unknown"
364
+ if normalized_mode is None
365
+ else (
366
+ "pass"
367
+ if normalized_mode in allowed_modes
368
+ else "fail"
369
+ )
370
+ ),
371
+ actual=actual_mode,
372
+ expected=allowed_modes,
373
+ detail=(
374
+ "Raster mode is screened coarsely. ICC profiles and print "
375
+ "conversion require separate color-management review."
376
+ ),
377
+ )
378
+ )
379
+
380
+ if metadata.get("has_alpha") is True:
381
+ findings.append(
382
+ _finding(
383
+ "transparency",
384
+ "review",
385
+ actual=True,
386
+ expected="verify against target journal/background",
387
+ detail=(
388
+ "The raster has alpha/transparency. Blending can change "
389
+ "contrast, and no universal publisher rule is assumed."
390
+ ),
391
+ )
392
+ )
393
+
394
+ counts = {
395
+ status: sum(item["status"] == status for item in findings)
396
+ for status in ("pass", "fail", "review", "unknown")
397
+ }
398
+ return {
399
+ "schema_version": SCHEMA_VERSION,
400
+ "plan": plan,
401
+ "inspection": inspected,
402
+ "findings": findings,
403
+ "screening_summary": counts,
404
+ "notice": (
405
+ "This screen compares only machine-readable properties with a dated "
406
+ "profile. It cannot certify journal acceptance, font appearance, "
407
+ "embedded-raster quality, accessibility, or scientific integrity."
408
+ ),
409
+ }
410
+
411
+
412
+ def build_parser() -> argparse.ArgumentParser:
413
+ parser = argparse.ArgumentParser(
414
+ description=(
415
+ "Plan publication export from dated official-source snapshots and "
416
+ "optionally screen a local file. No network access is used."
417
+ )
418
+ )
419
+ parser.add_argument("--list", action="store_true", help="list profiles")
420
+ parser.add_argument("--publisher", help="publisher/profile key")
421
+ parser.add_argument(
422
+ "--figure-type",
423
+ default="combination",
424
+ help="figure type in the selected profile (default: combination)",
425
+ )
426
+ parser.add_argument("--width", help="named final width from the profile")
427
+ parser.add_argument(
428
+ "--phase", help="your submission phase, for an explicit scope check"
429
+ )
430
+ parser.add_argument("--input", help="optional local file to screen")
431
+ parser.add_argument(
432
+ "--width-tolerance-mm",
433
+ type=positive_float,
434
+ default=1.0,
435
+ help="vector/page width tolerance (default: 1.0)",
436
+ )
437
+ parser.add_argument("--output", help="optional JSON output path")
438
+ parser.add_argument("--force", action="store_true")
439
+ return parser
440
+
441
+
442
+ def main(argv: list[str] | None = None) -> int:
443
+ parser = build_parser()
444
+ try:
445
+ args = parser.parse_args(argv)
446
+ document = load_profiles()
447
+ if args.list:
448
+ emit_json(
449
+ {
450
+ "schema_version": SCHEMA_VERSION,
451
+ "accessed": document["accessed"],
452
+ "profiles": {
453
+ name: {
454
+ "label": profile["label"],
455
+ "scope": profile["scope"],
456
+ "phase": profile["phase"],
457
+ "sources": profile["sources"],
458
+ }
459
+ for name, profile in sorted(document["profiles"].items())
460
+ },
461
+ "notice": document["notice"],
462
+ },
463
+ output=args.output,
464
+ force=args.force,
465
+ )
466
+ return 0
467
+ if not args.publisher:
468
+ parser.error("--publisher is required unless --list is used")
469
+ plan = build_plan(
470
+ args.publisher,
471
+ figure_type=args.figure_type,
472
+ width=args.width,
473
+ phase=args.phase,
474
+ )
475
+ result = (
476
+ validate_against_plan(
477
+ plan,
478
+ args.input,
479
+ width_tolerance_mm=args.width_tolerance_mm,
480
+ )
481
+ if args.input
482
+ else plan
483
+ )
484
+ emit_json(result, output=args.output, force=args.force)
485
+ if args.input:
486
+ return 1 if result["screening_summary"]["fail"] else 0
487
+ return 0
488
+ except CliError as exc:
489
+ parser.exit(2, f"error: {exc}\n")
490
+
491
+
492
+ if __name__ == "__main__":
493
+ sys.exit(main())