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,227 @@
1
+ #!/usr/bin/env python3
2
+ """Audit and simulate repair of bounded local geometries with optional new output."""
3
+
4
+ from __future__ import annotations
5
+
6
+ import argparse
7
+ import hashlib
8
+ import sys
9
+ from typing import Any
10
+
11
+ from _common import (
12
+ DEFAULT_MAX_FEATURES,
13
+ DEFAULT_MAX_INPUT_BYTES,
14
+ DEFAULT_MAX_OUTPUT_BYTES,
15
+ CliError,
16
+ checked_input_file,
17
+ checked_output_file,
18
+ crs_summary,
19
+ duplicate_column_state,
20
+ emit_json,
21
+ fail_json,
22
+ finite_number,
23
+ geometry_state,
24
+ load_geodataframe,
25
+ native_versions,
26
+ package_versions,
27
+ positive_int,
28
+ sha256_file,
29
+ write_new_geopackage,
30
+ )
31
+
32
+ TOOL = "geometry_validity_report"
33
+
34
+
35
+ def build_parser() -> argparse.ArgumentParser:
36
+ parser = argparse.ArgumentParser(
37
+ description=(
38
+ "Audit null/empty/invalid geometry and simulate make_valid locally. "
39
+ "Default is dry-run; --repair-output writes only a new GeoPackage."
40
+ ),
41
+ epilog=(
42
+ "No coordinates, paths, IDs, or validity-reason coordinates are emitted. "
43
+ "URLs, archives, symlinks, traversal, and overwrite are rejected."
44
+ ),
45
+ )
46
+ parser.add_argument("input", help="Allowlisted local GDAL vector file")
47
+ parser.add_argument("--root", default=".", help="Existing local I/O root")
48
+ parser.add_argument("--layer", help="Exact input layer name")
49
+ parser.add_argument("--id-column", help="Optional stable ID column to audit")
50
+ parser.add_argument(
51
+ "--method",
52
+ choices=("linework", "structure"),
53
+ default="linework",
54
+ help="Shapely make_valid algorithm (default: linework)",
55
+ )
56
+ parser.add_argument(
57
+ "--drop-collapsed",
58
+ action="store_true",
59
+ help="For structure repair only, drop lower-dimensional collapsed parts",
60
+ )
61
+ parser.add_argument(
62
+ "--precision-grid",
63
+ help=(
64
+ "Optional positive post-repair precision grid in projected CRS units; "
65
+ "geographic or missing CRS is rejected"
66
+ ),
67
+ )
68
+ parser.add_argument(
69
+ "--repair-output",
70
+ help="Optional new .gpkg path; existing paths are never overwritten",
71
+ )
72
+ parser.add_argument(
73
+ "--max-input-bytes",
74
+ type=positive_int,
75
+ default=DEFAULT_MAX_INPUT_BYTES,
76
+ )
77
+ parser.add_argument(
78
+ "--max-output-bytes",
79
+ type=positive_int,
80
+ default=DEFAULT_MAX_OUTPUT_BYTES,
81
+ )
82
+ parser.add_argument(
83
+ "--max-features",
84
+ type=positive_int,
85
+ default=DEFAULT_MAX_FEATURES,
86
+ )
87
+ return parser
88
+
89
+
90
+ def _type_transition_count(before: Any, after: Any) -> int:
91
+ before_types = [
92
+ "missing" if value is None else str(value) for value in before.geom_type
93
+ ]
94
+ after_types = [
95
+ "missing" if value is None else str(value) for value in after.geom_type
96
+ ]
97
+ return sum(left != right for left, right in zip(before_types, after_types))
98
+
99
+
100
+ def report(args: argparse.Namespace) -> dict[str, Any]:
101
+ if args.drop_collapsed and args.method != "structure":
102
+ raise CliError("--drop-collapsed is valid only with --method structure")
103
+ path = checked_input_file(
104
+ args.input,
105
+ root=args.root,
106
+ max_bytes=args.max_input_bytes,
107
+ )
108
+ frame = load_geodataframe(
109
+ path,
110
+ layer=args.layer,
111
+ max_features=args.max_features,
112
+ )
113
+ before_geometry = frame.geometry.copy()
114
+ before = geometry_state(frame)
115
+ id_state = duplicate_column_state(frame, args.id_column)
116
+ crs = crs_summary(frame.crs)
117
+
118
+ grid_size: float | None = None
119
+ if args.precision_grid is not None:
120
+ grid_size = finite_number(args.precision_grid, name="precision_grid")
121
+ if grid_size <= 0:
122
+ raise CliError("precision_grid must be greater than zero")
123
+ if not crs["present"] or crs["geographic"] or not crs["projected"]:
124
+ raise CliError("precision_grid requires a known projected CRS")
125
+
126
+ repaired_frame = frame.copy()
127
+ repaired_geometry = repaired_frame.geometry.make_valid(
128
+ method=args.method,
129
+ keep_collapsed=not args.drop_collapsed,
130
+ )
131
+ if grid_size is not None:
132
+ repaired_geometry = repaired_geometry.set_precision(
133
+ grid_size,
134
+ mode="valid_output",
135
+ )
136
+ repaired_frame = repaired_frame.set_geometry(repaired_geometry)
137
+ simulated = geometry_state(repaired_frame)
138
+
139
+ output_report: dict[str, Any] = {
140
+ "requested": args.repair_output is not None,
141
+ "written": False,
142
+ "path_emitted": False,
143
+ "basename_sha256": None,
144
+ "sha256": None,
145
+ "roundtrip_verified": False,
146
+ }
147
+ if args.repair_output is not None:
148
+ destination = checked_output_file(
149
+ args.repair_output,
150
+ root=args.root,
151
+ allowed_suffixes={".gpkg"},
152
+ )
153
+ write_new_geopackage(
154
+ repaired_frame,
155
+ destination,
156
+ max_output_bytes=args.max_output_bytes,
157
+ )
158
+ roundtrip = load_geodataframe(
159
+ destination,
160
+ layer="repaired",
161
+ max_features=args.max_features,
162
+ )
163
+ roundtrip_state = geometry_state(roundtrip)
164
+ if roundtrip_state != simulated:
165
+ destination.unlink(missing_ok=True)
166
+ raise CliError("roundtrip geometry-state verification failed; output removed")
167
+ output_report = {
168
+ "requested": True,
169
+ "written": True,
170
+ "path_emitted": False,
171
+ "basename_sha256": hashlib.sha256(
172
+ destination.name.encode("utf-8")
173
+ ).hexdigest(),
174
+ "sha256": sha256_file(destination),
175
+ "roundtrip_verified": True,
176
+ }
177
+
178
+ return {
179
+ "ok": True,
180
+ "tool": TOOL,
181
+ "dry_run": args.repair_output is None,
182
+ "source": {
183
+ "primary_file_sha256": sha256_file(path),
184
+ "primary_file_bytes": path.stat().st_size,
185
+ "path_emitted": False,
186
+ },
187
+ "crs": crs,
188
+ "stable_id_audit": id_state,
189
+ "before": before,
190
+ "simulated_after": simulated,
191
+ "repair_contract": {
192
+ "method": args.method,
193
+ "keep_collapsed": not args.drop_collapsed,
194
+ "precision_grid": grid_size,
195
+ "precision_grid_units": (
196
+ "source_projected_crs_units" if grid_size is not None else None
197
+ ),
198
+ "type_transition_rows": _type_transition_count(
199
+ before_geometry,
200
+ repaired_geometry,
201
+ ),
202
+ "source_modified": False,
203
+ },
204
+ "output": output_report,
205
+ "network_accessed": False,
206
+ "coordinates_emitted": False,
207
+ "identifiers_emitted": False,
208
+ "stack": {"packages": package_versions(), "native": native_versions()},
209
+ "warnings": [
210
+ "Repair can change type, dimension, component count, area, and emptiness.",
211
+ "Validity reasons were reduced to categories; defect coordinates were not emitted.",
212
+ "A written GeoPackage retains source attributes and coordinates and remains sensitive.",
213
+ ],
214
+ }
215
+
216
+
217
+ def main(argv: list[str] | None = None) -> int:
218
+ args = build_parser().parse_args(argv)
219
+ try:
220
+ emit_json(report(args))
221
+ return 0
222
+ except Exception as exc: # noqa: BLE001 - errors are redacted at CLI boundary
223
+ return fail_json(TOOL, exc)
224
+
225
+
226
+ if __name__ == "__main__":
227
+ sys.exit(main())
@@ -0,0 +1,230 @@
1
+ #!/usr/bin/env python3
2
+ """Produce a deterministic privacy/generalization checklist without reading data."""
3
+
4
+ from __future__ import annotations
5
+
6
+ import argparse
7
+ import sys
8
+
9
+ from _common import CliError, emit_json, fail_json, finite_number, positive_int
10
+
11
+ TOOL = "sensitive_coordinates_checklist"
12
+ SENSITIVE_FLAGS = (
13
+ "precise_points",
14
+ "contains_addresses",
15
+ "trajectories",
16
+ "parcel_boundaries",
17
+ "rare_categories",
18
+ "linked_identifiers",
19
+ )
20
+
21
+
22
+ def build_parser() -> argparse.ArgumentParser:
23
+ parser = argparse.ArgumentParser(
24
+ description=(
25
+ "Generate a conservative coordinate/privacy/generalization release "
26
+ "checklist. No file, environment variable, coordinate, or network is read."
27
+ ),
28
+ epilog=(
29
+ "This is a technical review aid, not a legal, ethical, or regulatory "
30
+ "compliance determination. Exact coordinates and addresses can reidentify."
31
+ ),
32
+ )
33
+ parser.add_argument(
34
+ "--audience",
35
+ choices=("private-analysis", "restricted-team", "public"),
36
+ default="private-analysis",
37
+ )
38
+ parser.add_argument("--public-output", action="store_true")
39
+ parser.add_argument("--precise-points", action="store_true")
40
+ parser.add_argument("--contains-addresses", action="store_true")
41
+ parser.add_argument("--trajectories", action="store_true")
42
+ parser.add_argument("--parcel-boundaries", action="store_true")
43
+ parser.add_argument("--rare-categories", action="store_true")
44
+ parser.add_argument("--linked-identifiers", action="store_true")
45
+ parser.add_argument(
46
+ "--generalization",
47
+ action="append",
48
+ choices=(
49
+ "aggregate",
50
+ "coarsen-coordinates",
51
+ "simplify",
52
+ "suppress-small-groups",
53
+ "remove-sensitive-fields",
54
+ "mask-extent",
55
+ ),
56
+ default=[],
57
+ help="Applied/proposed control; repeat for multiple controls",
58
+ )
59
+ parser.add_argument(
60
+ "--minimum-group-size",
61
+ type=positive_int,
62
+ help="Smallest released aggregate group; not a compliance threshold",
63
+ )
64
+ parser.add_argument(
65
+ "--tolerance",
66
+ help="Optional positive generalization tolerance; value is not echoed",
67
+ )
68
+ crs = parser.add_mutually_exclusive_group()
69
+ crs.add_argument(
70
+ "--projected-linear-crs",
71
+ action="store_true",
72
+ help="Attest tolerance uses a reviewed projected linear CRS",
73
+ )
74
+ crs.add_argument(
75
+ "--geographic-crs",
76
+ action="store_true",
77
+ help="Mark coordinates/tolerance as angular longitude-latitude",
78
+ )
79
+ parser.add_argument("--direct-identifiers-removed", action="store_true")
80
+ parser.add_argument("--attribute-review-complete", action="store_true")
81
+ parser.add_argument("--reidentification-review-complete", action="store_true")
82
+ parser.add_argument("--visual-review-complete", action="store_true")
83
+ parser.add_argument("--provenance-recorded", action="store_true")
84
+ parser.add_argument("--tile-and-cdn-access-disabled", action="store_true")
85
+ return parser
86
+
87
+
88
+ def checklist(args: argparse.Namespace) -> dict:
89
+ public = bool(args.public_output or args.audience == "public")
90
+ flags = {name: bool(getattr(args, name)) for name in SENSITIVE_FLAGS}
91
+ sensitive = any(flags.values())
92
+ controls = sorted(set(args.generalization))
93
+ blockers: list[str] = []
94
+ warnings: list[str] = []
95
+
96
+ tolerance_provided = args.tolerance is not None
97
+ if tolerance_provided:
98
+ tolerance = finite_number(args.tolerance, name="tolerance")
99
+ if tolerance <= 0:
100
+ raise CliError("tolerance must be greater than zero")
101
+ if not args.projected_linear_crs:
102
+ blockers.append(
103
+ "a numeric generalization tolerance requires a reviewed projected linear CRS"
104
+ )
105
+ if args.geographic_crs and any(
106
+ item in controls for item in ("coarsen-coordinates", "simplify")
107
+ ):
108
+ blockers.append(
109
+ "angular-coordinate generalization needs an explicit distortion-aware design"
110
+ )
111
+
112
+ if public and sensitive:
113
+ if not controls:
114
+ blockers.append("public sensitive geodata requires documented generalization")
115
+ if not args.direct_identifiers_removed:
116
+ blockers.append("remove direct identifiers before public release")
117
+ if not args.attribute_review_complete:
118
+ blockers.append("complete an attribute disclosure review")
119
+ if not args.reidentification_review_complete:
120
+ blockers.append("complete a linkage/reidentification review")
121
+ if not args.visual_review_complete:
122
+ blockers.append("inspect the rendered and serialized outputs")
123
+ if not args.provenance_recorded:
124
+ blockers.append("record source and generalization provenance")
125
+ if public and not args.tile_and_cdn_access_disabled:
126
+ blockers.append(
127
+ "disable or explicitly approve tile/CDN access for the public artifact"
128
+ )
129
+ if args.contains_addresses and "remove-sensitive-fields" not in controls:
130
+ blockers.append("exact addresses require removal from released attributes")
131
+ if args.trajectories and "aggregate" not in controls:
132
+ blockers.append("trajectories require aggregation or a separately reviewed model")
133
+ spatial_controls = {
134
+ "aggregate",
135
+ "coarsen-coordinates",
136
+ "mask-extent",
137
+ "simplify",
138
+ }
139
+ if (
140
+ (args.precise_points or args.parcel_boundaries)
141
+ and public
142
+ and not set(controls) & spatial_controls
143
+ ):
144
+ blockers.append("exact geometry needs spatial generalization before release")
145
+ if (
146
+ (args.rare_categories or args.linked_identifiers)
147
+ and public
148
+ and "suppress-small-groups" not in controls
149
+ ):
150
+ blockers.append("small/rare linked groups require suppression review")
151
+
152
+ if args.minimum_group_size is None and public and sensitive:
153
+ blockers.append("define and review a minimum released aggregate group size")
154
+ elif args.minimum_group_size is not None:
155
+ if args.minimum_group_size < 5:
156
+ warnings.append(
157
+ "The declared group size is very small; no universal threshold guarantees privacy."
158
+ )
159
+ if "suppress-small-groups" not in controls:
160
+ warnings.append(
161
+ "A group-size value was supplied without the suppress-small-groups control."
162
+ )
163
+
164
+ if not sensitive:
165
+ warnings.append(
166
+ "No sensitivity flags were selected; verify that classification is complete."
167
+ )
168
+ if not public:
169
+ warnings.append(
170
+ "Restricted handling still needs access control, retention, and audit policy."
171
+ )
172
+ warnings.extend(
173
+ [
174
+ "Jittering alone is not anonymization and can preserve reidentifiable patterns.",
175
+ "Rasterization, simplification, or coordinate rounding alone does not remove sensitive attributes.",
176
+ "HTML/SVG/GeoJSON can embed exact coordinates and properties beyond what is visibly rendered.",
177
+ ]
178
+ )
179
+
180
+ return {
181
+ "ok": not blockers,
182
+ "tool": TOOL,
183
+ "not_a_compliance_determination": True,
184
+ "audience": "public" if public else args.audience,
185
+ "sensitivity": {
186
+ "any_flagged": sensitive,
187
+ "categories": flags,
188
+ },
189
+ "controls": controls,
190
+ "minimum_group_size_declared": args.minimum_group_size is not None,
191
+ "tolerance": {
192
+ "provided": tolerance_provided,
193
+ "value_emitted": False,
194
+ "projected_linear_crs_attested": bool(args.projected_linear_crs),
195
+ "geographic_crs_flagged": bool(args.geographic_crs),
196
+ },
197
+ "review_attestations": {
198
+ "direct_identifiers_removed": bool(args.direct_identifiers_removed),
199
+ "attribute_review_complete": bool(args.attribute_review_complete),
200
+ "reidentification_review_complete": bool(
201
+ args.reidentification_review_complete
202
+ ),
203
+ "visual_review_complete": bool(args.visual_review_complete),
204
+ "provenance_recorded": bool(args.provenance_recorded),
205
+ "tile_and_cdn_access_disabled": bool(
206
+ args.tile_and_cdn_access_disabled
207
+ ),
208
+ },
209
+ "blockers": blockers,
210
+ "warnings": warnings,
211
+ "files_opened": False,
212
+ "environment_read": False,
213
+ "network_accessed": False,
214
+ "coordinates_emitted": False,
215
+ "identifiers_emitted": False,
216
+ }
217
+
218
+
219
+ def main(argv: list[str] | None = None) -> int:
220
+ args = build_parser().parse_args(argv)
221
+ try:
222
+ report = checklist(args)
223
+ emit_json(report)
224
+ return 0 if report["ok"] else 2
225
+ except Exception as exc: # noqa: BLE001 - errors are redacted at CLI boundary
226
+ return fail_json(TOOL, exc)
227
+
228
+
229
+ if __name__ == "__main__":
230
+ sys.exit(main())