terraproof 0.5.1 → 0.7.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/README.md CHANGED
@@ -1,150 +1,165 @@
1
- # Terraproof
2
-
3
- > Evidence-graded skills, tools, and checks for mapping and remote-sensing AI agents. *By Geova.*
4
-
5
- [![npm](https://img.shields.io/npm/v/terraproof)](https://www.npmjs.com/package/terraproof) [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
6
-
7
- Terraproof helps AI coding agents do geospatial work they can prove. It gives an agent three things:
8
-
9
- - **Skills.** 24 focused guides (GDAL, CRS and units, satellite preprocessing, SAR, spectral indices, time series, accuracy assessment, and more), split into sections an agent can load one at a time.
10
- - **A router.** It picks the smallest useful set of skills for a task, in English or Arabic, and explains why.
11
- - **Checks with an evidence grade.** They inspect the real datasets an agent produced (CRS, nodata, value ranges, geometry, COG layout, provenance) and grade the result as decision-grade, review required, or advisory only.
12
-
13
- Everything runs locally and offline. No model API key is needed.
14
-
15
- **Status:** experimental (v0.5.1). See [Evaluation status](#evaluation-status) for what has and has not been measured.
16
-
17
- ---
18
-
19
- ## Quick start
20
-
21
- Route a task with the published CLI (Node.js 20+):
22
-
23
- ```bash
24
- npx terraproof route "Reproject a GeoTIFF to EPSG:3857 and build a COG with GDAL"
25
- npx terraproof route "Download Sentinel-2 from a STAC catalog, compute NDVI, and map the change with MapLibre" --format json
26
- ```
27
-
28
- Then check the data the work produced with the Python package (Python 3.10+, from a clone):
29
-
30
- ```bash
31
- git clone https://github.com/esmailhussien/terraproof.git
32
- cd terraproof
33
- python -m venv .venv
34
- .venv/bin/python -m pip install -e ".[mcp]" # Windows: .venv\Scripts\python -m pip install -e ".[mcp]"
35
-
36
- python -m terraproof check ndvi.tif --expect index --format md
37
- python -m terraproof check outputs/clip.gpkg --compare-to data/parcels.gpkg --format md --lang ar --out report_ar.md
38
- ```
39
-
40
- The exit code is the grade: `0` decision-grade, `2` review required, `3` advisory only, `1` usage error.
41
-
42
- ---
43
-
44
- ## Python checks
45
-
46
- `python -m terraproof` reads local vector, raster and STAC Item files and makes no network calls.
47
-
48
- | Command | What it does |
49
- |---|---|
50
- | `inspect PATH` | Profile one dataset: CRS and units, schema or bands, dtype, nodata, extent, counts. |
51
- | `check PATHS` | Run the applicable checks and write a JSON or Markdown evidence report (English or Arabic). |
52
- | `preflight PATHS --plan plan.json` | Check a declared processing plan against the real inputs before running it. |
53
- | `manifest write` / `manifest verify` | Record and verify a deterministic run manifest (inputs, outputs, parameters). |
54
- | `route "TASK" [--data PATH]` | Retrieve the skill sections worth reading, using the task text and inspected datasets. |
55
-
56
- Checks cover CRS and units, geometry validity and GeoJSON winding, record counts, raster nodata, resampling, grid alignment and COG layout, reflectance and index ranges, scale/offset applied once, cloud masking, temporal scope, SAR domain, area-adjusted accuracy, and STAC provenance. A check that does not apply is left out; one that applies but cannot run is reported as `not-run`.
57
-
58
- | Grade | Arabic label | Meaning |
59
- |---|---|---|
60
- | Decision-grade | جاهز للقرار | Every check that ran passed. |
61
- | Review required | يحتاج مراجعة | At least one check warned; none failed or could not run. |
62
- | Advisory only | استرشادي فقط | At least one check failed or could not run, or no check ran. |
63
-
64
- The grade describes the data path and the checks that ran. It is not a certification of survey, engineering, legal, or safety fitness.
65
-
66
- ---
67
-
68
- ## Use it from your agent
69
-
70
- ### MCP server
71
-
72
- ```bash
73
- python -m terraproof.mcp # stdio server; needs the `mcp` extra
74
- ```
75
-
76
- It is read-only and offline, with six tools: `preflight`, `inspect_dataset`, `run_checks`, `list_skills`, `load_section`, and `find_guidance`. CLI and MCP return the same reports.
77
-
78
- ### Install into a project
79
-
80
- ```bash
81
- python -m terraproof.install --agent claude --task "NDVI change for 2020-2024" --target DIR --with-mcp
82
- python -m terraproof.install --agent cursor --skills gdal,crs-and-units --target DIR --dry-run
83
- ```
84
-
85
- | `--agent` | Skills are written to | MCP config (`--with-mcp`) |
86
- |---|---|---|
87
- | `claude` | `.claude/skills/<skill>/` | `.mcp.json` |
88
- | `codex` | `.agents/skills/<skill>/` and `AGENTS.md` | `.codex/config.toml` |
89
- | `cursor` | `.cursor/rules/terraproof-<skill>.mdc` | `.cursor/mcp.json` |
90
- | `gemini` | `GEMINI.md` | `.gemini/settings.json` |
91
- | `copilot` | `.github/instructions/terraproof-<skill>.instructions.md` | `.vscode/mcp.json` |
92
- | `opencode` | `AGENTS.md` | `opencode.json` |
93
-
94
- The installer only writes inside `--target`, merges existing configs, and is idempotent. Some hosts need you to approve or trust the project before its MCP server connects (Claude Code shows it as "Pending approval"; Codex and Gemini load project config only in trusted folders). Writing the files does not prove the agent loaded or followed them.
95
-
96
- ### Route and export with the Node CLI
97
-
98
- ```bash
99
- npx terraproof route "Design a PostGIS schema for GPS tracks" --collection gis --dry-run
100
- npx terraproof bundle "TASK" --out context.md # one reviewable context file
101
- npx terraproof apply "TASK" --target ./demo/.agents/skills --dry-run # export skill folders
102
- npx terraproof validate
103
- ```
104
-
105
- `apply` and `bundle --out` overwrite files without asking, so start in a disposable folder. Routing is deterministic keyword and section scoring, not semantic understanding; review the selection before you use it. Details: [`router/README.md`](router/README.md) and [`routing/ROUTER_DESIGN.md`](routing/ROUTER_DESIGN.md).
106
-
107
- ---
108
-
109
- ## Skills
110
-
111
- | Area | Skills |
112
- |---|---|
113
- | Process | `brainstorming`, `writing-plans`, `systematic-debugging`, `verification` |
114
- | Mapping and GIS | `gdal`, `crs-and-units`, `raster-processing`, `vector-quality`, `geopandas`, `design-postgis-tables`, `geoparquet-validation`, `geospatial-frontend`, `networkx` |
115
- | Remote sensing | `satellite-preprocessing`, `spectral-indices`, `sar-basics`, `time-series-and-change`, `accuracy-assessment`, `geomaster`, `geozarr` |
116
- | Data access | `geospatial-data-discovery`, `stac-and-cloud-access` |
117
- | Analysis and figures | `statistical-analysis`, `scientific-visualization` |
118
-
119
- Each skill lives in `skills/<name>/` with a `SKILL.md`, references, and a `skill.json` routing manifest. Preset collections (`gis`, `remote-sensing`, `data-analysis`, `production`) are in [`routing/collections.json`](routing/collections.json).
120
-
121
- ---
122
-
123
- ## Evaluation status
124
-
125
- - **Checks:** 27 executable eval tasks with independent oracles pass with 0 false passes. 15 seeded wrong outputs are still caught only by the oracle, not by the checks (declared blind spots). See [`evals/README.md`](evals/README.md).
126
- - **Routing:** an independent, frozen 160-item set (v5) passed once in both languages: English recall 0.97 with 3.75 wrong picks per 100, Arabic recall 0.96 with 2.5. Earlier independent sets (v3, v4) failed and stay on record. The v5 set was written by an AI agent, not reviewed by an expert.
127
- - **Agent lift:** in a 54-run Claude Code comparison on 9 tasks, runs with Terraproof passed 27/27 and runs without it 21/27. The pre-specified test is **not significant** (p = 0.125), and five tasks passed either way, so no lift is claimed. The clearest single result is Landsat QA masking (3/3 with, 0/3 without). See [`docs/plans/Terraproof_Phase5_PLAN.md`](docs/plans/Terraproof_Phase5_PLAN.md).
128
- - **Real hosts:** tool use through MCP has been verified with Codex and Claude Code. Cursor, Copilot and OpenCode are unit-tested against their documented layouts only.
129
-
130
- ---
131
-
132
- ## Repository
133
-
134
- | Path | Contents |
135
- |---|---|
136
- | `skills/` | The 24 skills |
137
- | `routing/` | Generated skill registry, check catalog, rules, and collections |
138
- | `router/` | TypeScript router and CLI (the npm package) |
139
- | `src/terraproof/` | Python package: inspectors, checks, reports, router, MCP server, installers, evals |
140
- | `evals/` | Eval task specs and routing sets |
141
- | `tests/` | Router, Python, package, and release-validation tests |
142
- | `instructions/` | Universal engineering rules shipped with the skills |
143
- | `docs/` | [Release checklist](docs/RELEASE_CHECKLIST.md) and [design plans](docs/plans/) |
144
- | `sources/`, `third_party/` | Upstream attribution and licenses |
145
-
146
- To contribute, see [`CONTRIBUTING.md`](CONTRIBUTING.md). Changes are listed in [`CHANGELOG.md`](CHANGELOG.md).
147
-
148
- ## License
149
-
150
- [MIT](LICENSE). Vendored and adapted components keep their upstream licenses (MIT, Apache-2.0, 3-clause BSD), documented in `third_party/` and [`sources/SOURCES.md`](sources/SOURCES.md).
1
+ # Terraproof
2
+
3
+ > Evidence-graded skills, tools, and checks for mapping and remote-sensing AI agents. *By Geova.*
4
+
5
+ [![npm](https://img.shields.io/npm/v/terraproof)](https://www.npmjs.com/package/terraproof) [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
6
+
7
+ Terraproof helps AI coding agents do geospatial work they can prove. It gives an agent three things:
8
+
9
+ - **Skills.** 24 focused guides (GDAL, CRS and units, satellite preprocessing, SAR, spectral indices, time series, accuracy assessment, and more), split into sections an agent can load one at a time.
10
+ - **A router.** It picks the smallest useful set of skills for a task, in English or Arabic, and explains why.
11
+ - **Checks with an evidence grade.** They inspect the real datasets an agent produced (CRS, nodata, value ranges, geometry, COG layout, provenance) and grade the result as decision-grade, review required, or advisory only.
12
+
13
+ Everything runs locally and offline. No model API key is needed.
14
+
15
+ **Status:** experimental (v0.7.0). See [Evaluation status](#evaluation-status) for what has and has not been measured.
16
+
17
+ ---
18
+
19
+ ## Quick start
20
+
21
+ Route a task with the published CLI (Node.js 20+):
22
+
23
+ ```bash
24
+ npx terraproof route "Reproject a GeoTIFF to EPSG:3857 and build a COG with GDAL"
25
+ npx terraproof route "Download Sentinel-2 from a STAC catalog, compute NDVI, and map the change with MapLibre" --format json
26
+ ```
27
+
28
+ Then check the data the work produced with the Python package (Python 3.10+, from a clone):
29
+
30
+ ```bash
31
+ git clone https://github.com/esmailhussien/terraproof.git
32
+ cd terraproof
33
+ python -m venv .venv
34
+ .venv/bin/python -m pip install -e ".[mcp]" # Windows: .venv\Scripts\python -m pip install -e ".[mcp]"
35
+
36
+ python -m terraproof check ndvi.tif --expect index --format md
37
+ python -m terraproof check outputs/clip.gpkg --compare-to data/parcels.gpkg --format md --lang ar --out report_ar.md
38
+ ```
39
+
40
+ The exit code is the grade: `0` decision-grade, `2` review required, `3` advisory only, `1` usage error.
41
+
42
+ ---
43
+
44
+ ## Python checks
45
+
46
+ `python -m terraproof` reads local vector, raster and STAC Item files and makes no network calls.
47
+
48
+ | Command | What it does |
49
+ |---|---|
50
+ | `inspect PATH` | Profile one dataset: CRS and units, schema or bands, dtype, nodata, extent, counts. |
51
+ | `check PATHS` | Run the applicable checks and write a JSON or Markdown evidence report (English or Arabic). |
52
+ | `preflight PATHS --plan plan.json` | Check a declared processing plan against the real inputs before running it. |
53
+ | `manifest write` / `manifest verify` | Record and verify a deterministic run manifest (inputs, outputs, parameters). |
54
+ | `route "TASK" [--data PATH]` | Retrieve the skill sections worth reading, using the task text and inspected datasets. |
55
+
56
+ Checks cover CRS and units, geometry validity and GeoJSON winding, record counts, raster nodata, resampling, grid alignment and COG layout, reflectance and index ranges, scale/offset applied once, cloud masking, temporal scope, SAR domain, area-adjusted accuracy, and STAC provenance. A check that does not apply is left out; one that applies but cannot run is reported as `not-run`.
57
+
58
+ | Grade | Arabic label | Meaning |
59
+ |---|---|---|
60
+ | Decision-grade | جاهز للقرار | Every check that ran passed. |
61
+ | Review required | يحتاج مراجعة | At least one check warned; none failed or could not run. |
62
+ | Advisory only | استرشادي فقط | At least one check failed or could not run, or no check ran. |
63
+
64
+ The grade describes the data path and the checks that ran. It is not a certification of survey, engineering, legal, or safety fitness.
65
+
66
+ ### Verify NDVI against its source bands
67
+
68
+ ```bash
69
+ python -m terraproof check outputs/ndvi.tif --index-formula ndvi --nir inputs/nir.tif --red inputs/red.tif
70
+ ```
71
+
72
+ This opt-in check compares every output cell with `(NIR-red)/(NIR+red)`, using each
73
+ raster's own scale/offset metadata. Supply single-band rasters on the same grid;
74
+ source-band roles and calibration must be declared correctly. Missing source data
75
+ and a zero denominator cannot become valid output values. Extra output masking
76
+ warns because its QA policy is not verified here. Source files are included in the
77
+ evidence report and must be covered when a provenance manifest is supplied.
78
+ See [the full contract and limits](docs/INDEX_FORMULA.md).
79
+
80
+ ---
81
+
82
+ ## Use it from your agent
83
+
84
+ ### MCP server
85
+
86
+ ```bash
87
+ python -m terraproof.mcp # stdio server; needs the `mcp` extra
88
+ ```
89
+
90
+ It is read-only and offline, with six tools: `preflight`, `inspect_dataset`, `run_checks`, `list_skills`, `load_section`, and `find_guidance`. CLI and MCP return the same reports.
91
+
92
+ ### Install into a project
93
+
94
+ ```bash
95
+ python -m terraproof.install --agent claude --task "NDVI change for 2020-2024" --target DIR --with-mcp
96
+ python -m terraproof.install --agent cursor --skills gdal,crs-and-units --target DIR --dry-run
97
+ ```
98
+
99
+ | `--agent` | Skills are written to | MCP config (`--with-mcp`) |
100
+ |---|---|---|
101
+ | `claude` | `.claude/skills/<skill>/` | `.mcp.json` |
102
+ | `codex` | `.agents/skills/<skill>/` and `AGENTS.md` | `.codex/config.toml` |
103
+ | `cursor` | `.cursor/rules/terraproof-<skill>.mdc` | `.cursor/mcp.json` |
104
+ | `gemini` | `GEMINI.md` | `.gemini/settings.json` |
105
+ | `copilot` | `.github/instructions/terraproof-<skill>.instructions.md` | `.vscode/mcp.json` |
106
+ | `opencode` | `AGENTS.md` | `opencode.json` |
107
+
108
+ The installer only writes inside `--target`, merges existing configs, and is idempotent. Some hosts need you to approve or trust the project before its MCP server connects (Claude Code shows it as "Pending approval"; Codex and Gemini load project config only in trusted folders). Writing the files does not prove the agent loaded or followed them.
109
+
110
+ ### Route and export with the Node CLI
111
+
112
+ ```bash
113
+ npx terraproof route "Design a PostGIS schema for GPS tracks" --collection gis --dry-run
114
+ npx terraproof bundle "TASK" --out context.md # one reviewable context file
115
+ npx terraproof apply "TASK" --target ./demo/.agents/skills --dry-run # export skill folders
116
+ npx terraproof validate
117
+ ```
118
+
119
+ `apply` and `bundle --out` overwrite files without asking, so start in a disposable folder. Routing is deterministic keyword and section scoring, not semantic understanding; review the selection before you use it. Details: [`router/README.md`](router/README.md) and [`routing/ROUTER_DESIGN.md`](routing/ROUTER_DESIGN.md).
120
+
121
+ ---
122
+
123
+ ## Skills
124
+
125
+ | Area | Skills |
126
+ |---|---|
127
+ | Process | `brainstorming`, `writing-plans`, `systematic-debugging`, `verification` |
128
+ | Mapping and GIS | `gdal`, `crs-and-units`, `raster-processing`, `vector-quality`, `geopandas`, `design-postgis-tables`, `geoparquet-validation`, `geospatial-frontend`, `networkx` |
129
+ | Remote sensing | `satellite-preprocessing`, `spectral-indices`, `sar-basics`, `time-series-and-change`, `accuracy-assessment`, `geomaster`, `geozarr` |
130
+ | Data access | `geospatial-data-discovery`, `stac-and-cloud-access` |
131
+ | Analysis and figures | `statistical-analysis`, `scientific-visualization` |
132
+
133
+ Each skill lives in `skills/<name>/` with a `SKILL.md`, references, and a `skill.json` routing manifest. Preset collections (`gis`, `remote-sensing`, `data-analysis`, `production`) are in [`routing/collections.json`](routing/collections.json).
134
+
135
+ ---
136
+
137
+ ## Evaluation status
138
+
139
+ - **Checks:** 33 executable eval tasks with independent oracles pass with 0 false passes. Of 50 seeded wrong outputs, production checks reject 25; the other 25 are caught only by the independent oracle (declared blind spots). Passing the benchmark does not mean the production checks catch every wrong output. See [`evals/README.md`](evals/README.md).
140
+ - **Routing:** an independent, frozen 160-item set (v5) passed once in both languages: English recall 0.97 with 3.75 wrong picks per 100, Arabic recall 0.96 with 2.5. Earlier independent sets (v3, v4) failed and stay on record. The v5 set was written by an AI agent, not reviewed by an expert.
141
+ - **Agent lift:** in a 54-run Claude Code comparison on 9 tasks, runs with Terraproof passed 27/27 and runs without it 21/27. The pre-specified test is **not significant** (p = 0.125), and five tasks passed either way, so no lift is claimed. The clearest single result is Landsat QA masking (3/3 with, 0/3 without). See [`docs/plans/Terraproof_Phase5_PLAN.md`](docs/plans/Terraproof_Phase5_PLAN.md).
142
+ - **Harder cohort:** a one-repeat Claude Code screen passed all six tasks both with and without Terraproof. That small screen shows no observed benefit and is separate from the original nine-task study. API pilots are exploratory and do not establish lift.
143
+ - **Real hosts:** tool use through MCP has been verified with Codex and Claude Code. Cursor, Copilot and OpenCode are unit-tested against their documented layouts only.
144
+
145
+ ---
146
+
147
+ ## Repository
148
+
149
+ | Path | Contents |
150
+ |---|---|
151
+ | `skills/` | The 24 skills |
152
+ | `routing/` | Generated skill registry, check catalog, rules, and collections |
153
+ | `router/` | TypeScript router and CLI (the npm package) |
154
+ | `src/terraproof/` | Python package: inspectors, checks, reports, router, MCP server, installers, evals |
155
+ | `evals/` | Eval task specs and routing sets |
156
+ | `tests/` | Router, Python, package, and release-validation tests |
157
+ | `instructions/` | Universal engineering rules shipped with the skills |
158
+ | `docs/` | [Release checklist](docs/RELEASE_CHECKLIST.md) and [design plans](docs/plans/) |
159
+ | `sources/`, `third_party/` | Upstream attribution and licenses |
160
+
161
+ To contribute, see [`CONTRIBUTING.md`](CONTRIBUTING.md). Changes are listed in [`CHANGELOG.md`](CHANGELOG.md).
162
+
163
+ ## License
164
+
165
+ [MIT](LICENSE). Vendored and adapted components keep their upstream licenses (MIT, Apache-2.0, 3-clause BSD), documented in `third_party/` and [`sources/SOURCES.md`](sources/SOURCES.md).
package/package.json CHANGED
@@ -1,67 +1,67 @@
1
- {
2
- "name": "terraproof",
3
- "version": "0.5.1",
4
- "description": "evidence-graded skills, tools, and checks for mapping and remote-sensing AI agents. By Geova.",
5
- "type": "module",
6
- "main": "./dist/router/index.js",
7
- "exports": {
8
- ".": "./dist/router/index.js",
9
- "./router": "./dist/router/index.js",
10
- "./routing": "./routing/registry.json"
11
- },
12
- "bin": {
13
- "terraproof": "bin/terraproof.js"
14
- },
15
- "scripts": {
16
- "build": "tsc -p tsconfig.build.json",
17
- "prepack": "npm run build",
18
- "route": "node router/index.ts route",
19
- "validate": "node router/index.ts validate",
20
- "registry:build": "node router/build-registry.ts",
21
- "registry:check": "node router/build-registry.ts --check",
22
- "test:router": "node tests/router/run.ts",
23
- "test:validate": "python tests/validate_repo.py",
24
- "test:package": "node tests/package/smoke.mjs",
25
- "test": "node tests/router/run.ts",
26
- "typecheck": "tsc --noEmit"
27
- },
28
- "repository": {
29
- "type": "git",
30
- "url": "git+https://github.com/esmailhussien/terraproof.git"
31
- },
32
- "homepage": "https://github.com/esmailhussien/terraproof#readme",
33
- "bugs": {
34
- "url": "https://github.com/esmailhussien/terraproof/issues"
35
- },
36
- "engines": {
37
- "node": ">=20"
38
- },
39
- "files": [
40
- "bin",
41
- "dist",
42
- "routing",
43
- "skills",
44
- "instructions",
45
- "third_party",
46
- "sources",
47
- "README.md",
48
- "LICENSE"
49
- ],
50
- "keywords": [
51
- "ai",
52
- "agent",
53
- "skills",
54
- "router",
55
- "geospatial",
56
- "gis",
57
- "remote-sensing",
58
- "earth-observation",
59
- "mapping"
60
- ],
61
- "author": "Terraproof Contributors",
62
- "license": "MIT",
63
- "devDependencies": {
64
- "typescript": "^5.7.0",
65
- "@types/node": "^22.0.0"
66
- }
67
- }
1
+ {
2
+ "name": "terraproof",
3
+ "version": "0.7.0",
4
+ "description": "evidence-graded skills, tools, and checks for mapping and remote-sensing AI agents. By Geova.",
5
+ "type": "module",
6
+ "main": "./dist/router/index.js",
7
+ "exports": {
8
+ ".": "./dist/router/index.js",
9
+ "./router": "./dist/router/index.js",
10
+ "./routing": "./routing/registry.json"
11
+ },
12
+ "bin": {
13
+ "terraproof": "bin/terraproof.js"
14
+ },
15
+ "scripts": {
16
+ "build": "tsc -p tsconfig.build.json",
17
+ "prepack": "npm run build",
18
+ "route": "node router/index.ts route",
19
+ "validate": "node router/index.ts validate",
20
+ "registry:build": "node router/build-registry.ts",
21
+ "registry:check": "node router/build-registry.ts --check",
22
+ "test:router": "node tests/router/run.ts",
23
+ "test:validate": "python tests/validate_repo.py",
24
+ "test:package": "node tests/package/smoke.mjs",
25
+ "test": "node tests/router/run.ts",
26
+ "typecheck": "tsc --noEmit"
27
+ },
28
+ "repository": {
29
+ "type": "git",
30
+ "url": "git+https://github.com/esmailhussien/terraproof.git"
31
+ },
32
+ "homepage": "https://github.com/esmailhussien/terraproof#readme",
33
+ "bugs": {
34
+ "url": "https://github.com/esmailhussien/terraproof/issues"
35
+ },
36
+ "engines": {
37
+ "node": ">=20"
38
+ },
39
+ "files": [
40
+ "bin",
41
+ "dist",
42
+ "routing",
43
+ "skills",
44
+ "instructions",
45
+ "third_party",
46
+ "sources",
47
+ "README.md",
48
+ "LICENSE"
49
+ ],
50
+ "keywords": [
51
+ "ai",
52
+ "agent",
53
+ "skills",
54
+ "router",
55
+ "geospatial",
56
+ "gis",
57
+ "remote-sensing",
58
+ "earth-observation",
59
+ "mapping"
60
+ ],
61
+ "author": "Terraproof Contributors",
62
+ "license": "MIT",
63
+ "devDependencies": {
64
+ "typescript": "^5.7.0",
65
+ "@types/node": "^22.0.0"
66
+ }
67
+ }
@@ -73,6 +73,10 @@
73
73
  "family": "rs",
74
74
  "description": "Every STAC item datetime, or the whole start/end interval, falls inside a declared time range; items without a usable acquisition time are not-run."
75
75
  },
76
+ "terrain.slope_consistent": {
77
+ "family": "terrain",
78
+ "description": "A slope-in-degrees raster matches central differences on its DEM (passed with --dem) using the DEM's declared vertical unit and real pixel spacing; matching the slope with vertical units ignored or square pixels assumed fails, matching neither warns, and geographic or unaligned grids are not-run."
79
+ },
76
80
  "sar.value_domain": {
77
81
  "family": "sar",
78
82
  "description": "Sampled backscatter values lie in the domain declared by the expected scale (sigma0-db within [-50, 15] dB; sigma0-linear non-negative with p99 <= 5). Flags decibel/linear confusion as one possible cause; not a calibration check."
@@ -120,6 +124,10 @@
120
124
  "preflight.output_units": {
121
125
  "family": "preflight",
122
126
  "description": "Plan check: the output CRS units match the measurement units the plan requests, so a metric result is not written in degrees or the reverse."
127
+ },
128
+ "rs.index_formula": {
129
+ "family": "rs",
130
+ "description": "Opt-in NDVI comparison with declared red/NIR sources, their scale/offset and joint valid support; extra masking warns."
123
131
  }
124
132
  }
125
133
  }
@@ -410,7 +410,8 @@
410
410
  "crs.consistent",
411
411
  "raster.nodata_declared",
412
412
  "raster.resampling",
413
- "raster.cog_layout"
413
+ "raster.cog_layout",
414
+ "terrain.slope_consistent"
414
415
  ]
415
416
  },
416
417
  "geomaster": {
@@ -61,6 +61,7 @@
61
61
  "crs.consistent",
62
62
  "raster.nodata_declared",
63
63
  "raster.resampling",
64
- "raster.cog_layout"
64
+ "raster.cog_layout",
65
+ "terrain.slope_consistent"
65
66
  ]
66
67
  }
@@ -178,24 +178,53 @@ union = gpd.overlay(gdf1, gdf2, how='union')
178
178
  ### Terrain Analysis
179
179
 
180
180
  ```python
181
- def terrain_metrics(dem_path):
182
- """Calculate slope, aspect, hillshade from DEM."""
183
- with rasterio.open(dem_path) as src:
184
- dem = src.read(1)
181
+ # Vertical units to metres; extend for your data. None means "assume metres".
182
+ Z_TO_METRES = {None: 1.0, "": 1.0, "m": 1.0, "metre": 1.0, "meter": 1.0, "metres": 1.0, "meters": 1.0,
183
+ "ft": 0.3048, "foot": 0.3048, "feet": 0.3048, "us-ft": 1200 / 3937, "us survey foot": 1200 / 3937}
185
184
 
186
- dy, dx = np.gradient(dem)
187
- slope = np.arctan(np.sqrt(dx**2 + dy**2)) * 180 / np.pi
188
- aspect = (90 - np.arctan2(-dy, dx) * 180 / np.pi) % 360
185
+ def terrain_metrics(dem_path, z_factor=None, azimuth=315.0, altitude=45.0):
186
+ """Slope (degrees), aspect (compass degrees the slope faces) and hillshade from a projected DEM.
189
187
 
190
- # Hillshade
191
- az_rad, alt_rad = np.radians(315), np.radians(45)
192
- hillshade = (np.sin(alt_rad) * np.sin(np.radians(slope)) +
193
- np.cos(alt_rad) * np.cos(np.radians(slope)) *
194
- np.cos(np.radians(aspect) - az_rad))
188
+ Gradients use the real pixel size from the transform (pixels are often not square), and
189
+ elevations are converted to metres from the band unit unless z_factor is given.
190
+ Nodata becomes NaN, so cells next to nodata are NaN too; flat cells have no aspect.
191
+ """
192
+ with rasterio.open(dem_path) as src:
193
+ if src.crs is None or src.crs.is_geographic:
194
+ raise ValueError("reproject the DEM to a projected CRS in metres first")
195
+ if src.crs.linear_units_factor[1] != 1.0:
196
+ raise ValueError("the CRS units are not metres; reproject or rescale the horizontal units")
197
+ a, b, _, d, e, _ = tuple(src.transform)[:6]
198
+ if b or d:
199
+ raise ValueError("resample a rotated or sheared DEM to a north-up grid first")
200
+ dem = src.read(1, masked=True).astype("float64").filled(np.nan)
201
+ unit = (src.units[0] or "").strip().lower() if src.units else None
202
+ if z_factor is None:
203
+ if unit not in Z_TO_METRES:
204
+ raise ValueError(f"unknown elevation unit {unit!r}; pass z_factor")
205
+ z_factor = Z_TO_METRES[unit]
206
+
207
+ # Signed spacing: one row step moves e metres north (e < 0 on north-up grids), one column a metres east.
208
+ dz_dnorth, dz_deast = np.gradient(dem * z_factor, e, a)
209
+ slope = np.degrees(np.arctan(np.hypot(dz_deast, dz_dnorth)))
210
+ aspect = np.degrees(np.arctan2(-dz_deast, -dz_dnorth)) % 360 # downslope direction, clockwise from north
211
+ aspect[slope == 0] = np.nan
212
+ # A central difference skips the centre cell, so nodata cells themselves must be masked explicitly.
213
+ slope[np.isnan(dem)] = np.nan
214
+ aspect[np.isnan(dem)] = np.nan
215
+
216
+ # Hillshade (Burrough & McDonnell): zenith = 90 - altitude; 0 = shadow, 1 = facing the sun.
217
+ s, alt = np.radians(slope), np.radians(altitude)
218
+ facing = np.cos(np.radians(azimuth) - np.radians(np.nan_to_num(aspect)))
219
+ hillshade = np.clip(np.sin(alt) * np.cos(s) + np.cos(alt) * np.sin(s) * facing, 0, 1)
195
220
 
196
221
  return slope, aspect, hillshade
197
222
  ```
198
223
 
224
+ Check the DEM before trusting any terrain metric: projected CRS in metres, north-up grid, the
225
+ band's vertical unit, and the real pixel size (`src.res`). A geographic DEM (degrees) or a
226
+ feet-vs-metres mismatch gives slopes that look plausible but are wrong.
227
+
199
228
  ### Network Analysis
200
229
 
201
230
  ```python
@@ -18,4 +18,17 @@ This skill is derived from the `geomaster` skill in `K-Dense-AI/scientific-agent
18
18
  Initial import:
19
19
  - Local behavioral modifications: none (faithful vendoring, byte-for-byte identical to upstream).
20
20
 
21
- Any future AgentLayer modifications must be documented here.
21
+ 2026-10-24, terrain slope correctness fix (Terraproof):
22
+ - `SKILL.md`, section "Terrain Analysis": `terrain_metrics()` is rewritten. The upstream version called
23
+ `np.gradient(dem)` with no spacing, so it assumed 1-unit square pixels and equal vertical and horizontal
24
+ units, and its hillshade swapped the sine and cosine of the slope. The local version uses the signed pixel
25
+ size from the transform, converts the band's vertical unit to metres (or a given `z_factor`), refuses
26
+ geographic, non-metre, rotated or sheared grids, masks nodata as NaN, leaves flat cells without aspect, and
27
+ uses the standard hillshade formula. A short checklist follows the code.
28
+ - `references/code-examples.md`, example 68: the same `np.gradient(dem)` example is replaced by a pointer to
29
+ `terrain_metrics()` and the reason.
30
+ - Found by an independent review (Codex, 2026-10-24) while authoring the `terrain-slope-map` eval task.
31
+ Covered by `tests/python/test_skill_snippets.py`, which runs the snippet on synthetic DEMs.
32
+ - All other content is unchanged from upstream.
33
+
34
+ Any future modifications must be documented here.
@@ -358,24 +358,11 @@ def map_flood(dem_path, flood_level, output_path):
358
358
 
359
359
  ```python
360
360
  # 68. Slope and aspect from DEM
361
- def terrain_analysis(dem_path):
362
- import numpy as np
363
- from scipy import ndimage
364
-
365
- with rasterio.open(dem_path) as src:
366
- dem = src.read(1)
367
-
368
- # Calculate gradients
369
- dy, dx = np.gradient(dem)
370
-
371
- # Slope in degrees
372
- slope = np.arctan(np.sqrt(dx**2 + dy**2)) * 180 / np.pi
373
-
374
- # Aspect
375
- aspect = np.arctan2(-dy, dx) * 180 / np.pi
376
- aspect = (90 - aspect) % 360
377
-
378
- return slope, aspect
361
+ # Use terrain_metrics() in ../SKILL.md (section "Terrain Analysis"). It takes the real pixel size
362
+ # from the transform, converts vertical units to metres, refuses geographic or rotated grids and
363
+ # masks nodata. np.gradient(dem) without spacing assumes 1-unit square pixels and equal vertical
364
+ # and horizontal units, which gives wrong slopes for almost every real DEM.
365
+ slope, aspect, hillshade = terrain_metrics("dem.tif")
379
366
  ```
380
367
 
381
368
  ## Additional Examples (70-100)
@@ -160,7 +160,7 @@ This file tracks upstream repositories, specifications, and references evaluated
160
160
  - **Local AgentLayer Paths:**
161
161
  - Production Skill: [skills/geomaster/](../skills/geomaster/) (`SKILL.md`, `UPSTREAM.md`)
162
162
  - License/Notice: [third_party/kdense-scientific-agent-skills/](../third_party/kdense-scientific-agent-skills/) (`LICENSE`, `NOTICE.md`)
163
- - **Modification Status:** Unchanged (byte-for-byte faithful vendoring).
163
+ - **Modification Status:** Modified locally (2026-10-24): the `SKILL.md` "Terrain Analysis" snippet and `references/code-examples.md` example 68 are corrected to use real pixel spacing and vertical units (see [skills/geomaster/UPSTREAM.md](../skills/geomaster/UPSTREAM.md)). Everything else is unchanged from upstream.
164
164
 
165
165
  ### design-postgis-tables
166
166