@lifeaitools/rdc-skills 0.24.41 → 0.25.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/.claude/settings.json +15 -15
- package/.claude-plugin/marketplace.json +21 -21
- package/.claude-plugin/plugin.json +1518 -1371
- package/.github/workflows/publish.yml +34 -34
- package/.github/workflows/self-test.yml +58 -58
- package/CHANGELOG.md +310 -310
- package/LICENSE +21 -21
- package/MANIFEST.md +221 -221
- package/README.md +375 -376
- package/README.sandbox.md +3 -3
- package/assets/watcher/viewer.html +164 -164
- package/bin/rdc-skills-mcp.mjs +316 -316
- package/commands/build.md +183 -183
- package/commands/collab.md +180 -180
- package/commands/deploy.md +152 -152
- package/commands/design.md +31 -31
- package/commands/edit.md +28 -28
- package/commands/fixit.md +150 -124
- package/commands/handoff.md +173 -173
- package/commands/help.md +95 -95
- package/commands/overnight.md +220 -220
- package/commands/plan.md +158 -158
- package/commands/preplan.md +131 -131
- package/commands/prototype.md +145 -145
- package/commands/release.md +49 -49
- package/commands/report.md +99 -99
- package/commands/review.md +120 -120
- package/commands/self-test.md +113 -113
- package/commands/status.md +86 -86
- package/commands/watch.md +98 -98
- package/commands/workitems.md +137 -137
- package/git-sha.json +1 -1
- package/guides/agent-bootstrap.md +295 -295
- package/guides/agents/backend.md +104 -104
- package/guides/agents/content.md +94 -94
- package/guides/agents/cs2.md +56 -56
- package/guides/agents/data.md +87 -87
- package/guides/agents/design.md +77 -77
- package/guides/agents/frontend.md +92 -92
- package/guides/agents/infrastructure.md +81 -81
- package/guides/agents/setup.md +281 -281
- package/guides/agents/verify.md +151 -151
- package/guides/agents/viz.md +106 -106
- package/guides/backend.md +146 -146
- package/guides/content.md +147 -147
- package/guides/cs2.md +190 -190
- package/guides/data.md +123 -123
- package/guides/design.md +116 -116
- package/guides/engineering-behavior.md +43 -43
- package/guides/escalation-protocol.md +125 -125
- package/guides/frontend.md +151 -151
- package/guides/history-md-spec.md +297 -297
- package/guides/infrastructure.md +179 -179
- package/guides/lessons-learned-spec.md +145 -151
- package/guides/output-contract.md +108 -108
- package/guides/publish-md-spec.md +289 -289
- package/guides/rdc-skills-startup.md +30 -30
- package/guides/verify.md +11 -11
- package/hooks/check-cwd.js +31 -31
- package/hooks/check-rdc-environment.js +164 -164
- package/hooks/check-services.js +6 -6
- package/hooks/check-stale-work-items.js +19 -19
- package/hooks/foreground-process-gate.js +128 -128
- package/hooks/gate-watchdog-selfcheck.js +257 -257
- package/hooks/hook-logger.js +25 -25
- package/hooks/lib/run-evidence-gate.mjs +241 -241
- package/hooks/no-stop-open-epics.js +127 -127
- package/hooks/post-tool-batch-gate.js +203 -203
- package/hooks/post-work-check.js +21 -21
- package/hooks/postcompact-log.js +13 -13
- package/hooks/precompact-log.js +13 -13
- package/hooks/rate-limit-retry.js +46 -46
- package/hooks/rdc-invocation-marker.js +157 -157
- package/hooks/rdc-output-contract-gate.js +94 -94
- package/hooks/require-work-item-on-commit.js +294 -294
- package/hooks/restart-brief.js +19 -19
- package/hooks/run-hidden-hook.ps1 +47 -47
- package/hooks/task-completed-gate.js +274 -274
- package/hooks/work-item-exit-gate.js +944 -944
- package/lib/catalog.mjs +236 -236
- package/lib/cloud-rewrite.mjs +155 -155
- package/package.json +57 -57
- package/rules/work-items-rpc.md +520 -520
- package/scaffold/templates/HISTORY.md.template +39 -39
- package/scaffold/templates/PUBLISH.md.template +21 -21
- package/scaffold/templates/brochure-studio-default.html +70 -70
- package/scripts/acceptance.mjs +502 -502
- package/scripts/fixtures/guides/bad-guide.md +15 -15
- package/scripts/fixtures/guides-clean/good-guide.md +16 -16
- package/scripts/install-rdc-skills.js +1289 -1289
- package/scripts/install.ps1 +202 -202
- package/scripts/install.sh +132 -132
- package/scripts/lib/assertions.mjs +287 -287
- package/scripts/lib/manifest-schema.mjs +754 -754
- package/scripts/lib/runner.mjs +465 -465
- package/scripts/lib/sandbox.mjs +435 -435
- package/scripts/prepack.mjs +32 -32
- package/scripts/rdc-brochure.mjs +482 -482
- package/scripts/rdc-design-cli.mjs +134 -134
- package/scripts/rebuild-mcp.mjs +107 -107
- package/scripts/self-test.mjs +1460 -1460
- package/scripts/stamp-git-sha.mjs +29 -29
- package/scripts/test-guide-validator.mjs +196 -196
- package/scripts/test-rdc-hooks.mjs +145 -145
- package/scripts/uninstall.ps1 +77 -77
- package/scripts/uninstall.sh +69 -69
- package/scripts/update.ps1 +43 -43
- package/scripts/update.sh +43 -43
- package/scripts/validate-place-histories.js +461 -461
- package/scripts/validate-publish-manifests.js +502 -424
- package/scripts/watch-init.mjs +100 -100
- package/skills/brochure/SKILL.md +107 -107
- package/skills/build/SKILL.md +563 -563
- package/skills/channel-formatter/SKILL.md +538 -533
- package/skills/co-develop/SKILL.md +196 -196
- package/skills/collab/SKILL.md +239 -239
- package/skills/convert/SKILL.md +167 -140
- package/skills/deploy/SKILL.md +541 -541
- package/skills/design/SKILL.md +211 -211
- package/skills/design/reference/ownership.md +16 -16
- package/skills/design/reference/rampa.md +92 -92
- package/skills/design/reference/studio-model.md +153 -153
- package/skills/edit/SKILL.md +98 -98
- package/skills/fixit/SKILL.md +203 -165
- package/skills/fs-mcp/SKILL.md +148 -148
- package/skills/handoff/SKILL.md +236 -236
- package/skills/help/SKILL.md +143 -143
- package/skills/housekeeping/SKILL.md +160 -219
- package/skills/lifeai-brochure-author/SKILL.md +340 -340
- package/skills/onramp/SKILL.md +248 -0
- package/skills/overnight/SKILL.md +251 -251
- package/skills/plan/SKILL.md +345 -345
- package/skills/preplan/SKILL.md +90 -90
- package/skills/prototype/SKILL.md +150 -150
- package/skills/rdc-brochurify/SKILL.md +245 -245
- package/skills/rdc-extract-verifier-rules/SKILL.md +191 -191
- package/skills/release/SKILL.md +140 -140
- package/skills/report/SKILL.md +100 -100
- package/skills/review/SKILL.md +152 -152
- package/skills/rpms-filemap/SKILL.cloud.md +111 -111
- package/skills/rpms-filemap/SKILL.md +111 -111
- package/skills/self-test/SKILL.md +132 -132
- package/skills/status/SKILL.md +99 -99
- package/skills/terminal-config/SKILL.md +62 -62
- package/skills/tests/MATRIX.md +54 -54
- package/skills/tests/README.md +47 -47
- package/skills/tests/onramp.test.json +87 -0
- package/skills/tests/rdc-brochure.test.json +34 -34
- package/skills/tests/rdc-build.test.json +36 -36
- package/skills/tests/rdc-channel-formatter.test.json +45 -45
- package/skills/tests/rdc-co-develop.test.json +29 -29
- package/skills/tests/rdc-collab.test.json +29 -29
- package/skills/tests/rdc-convert.test.json +35 -35
- package/skills/tests/rdc-deploy.test.json +30 -30
- package/skills/tests/rdc-design.test.json +27 -27
- package/skills/tests/rdc-edit.test.json +29 -29
- package/skills/tests/rdc-fixit.test.json +36 -36
- package/skills/tests/rdc-fs-mcp.test.json +36 -36
- package/skills/tests/rdc-handoff.test.json +28 -28
- package/skills/tests/rdc-help.test.json +29 -29
- package/skills/tests/rdc-housekeeping.test.json +28 -32
- package/skills/tests/rdc-lifeai-brochure-author.test.json +35 -35
- package/skills/tests/rdc-overnight.test.json +37 -37
- package/skills/tests/rdc-plan.test.json +27 -27
- package/skills/tests/rdc-preplan.test.json +31 -31
- package/skills/tests/rdc-prototype.test.json +28 -28
- package/skills/tests/rdc-rdc-brochurify.test.json +23 -23
- package/skills/tests/rdc-rdc-extract-verifier-rules.test.json +34 -34
- package/skills/tests/rdc-release.test.json +29 -29
- package/skills/tests/rdc-report.test.json +28 -28
- package/skills/tests/rdc-review.test.json +29 -29
- package/skills/tests/rdc-rpms-filemap.test.json +28 -28
- package/skills/tests/rdc-self-test.test.json +24 -24
- package/skills/tests/rdc-status.test.json +29 -29
- package/skills/tests/rdc-terminal-config.test.json +29 -29
- package/skills/tests/rdc-watch.test.json +24 -24
- package/skills/tests/rdc-workitems.test.json +27 -27
- package/skills/watch/SKILL.md +97 -97
- package/skills/workitems/SKILL.md +151 -151
- package/tests/acceptance.test.mjs +59 -59
- package/tests/channel-formatter.contract.test.mjs +251 -251
- package/tests/curl-surface.test.mjs +289 -289
- package/tests/harness-gates.test.mjs +325 -325
- package/tests/help-surface.test.mjs +61 -61
- package/tests/install-rdc-skills.test.mjs +49 -49
- package/tests/manifest-contract-fields.test.mjs +78 -78
- package/tests/mcp.test.mjs +271 -271
- package/tests/rdc-brochure.test.mjs +125 -125
- package/tests/require-work-item-on-commit.test.mjs +162 -162
- package/tests/run-evidence-gate.test.mjs +82 -82
- package/tests/skill-test-matrix.test.mjs +66 -66
- package/tests/validate-skills.js +27 -27
- package/tests/work-item-exit-gate-l2.test.mjs +368 -368
- package/tests/work-item-exit-gate-l3.test.mjs +197 -197
- package/RELEASE.md +0 -42
- package/tests/housekeeping-lessons-triage.test.mjs +0 -49
- package/tests/lessons-pipeline-contract.test.mjs +0 -26
- package/tests/release-contract.test.mjs +0 -16
|
@@ -1,461 +1,461 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* validate-place-histories.js
|
|
4
|
-
* HISTORY.md convention validator for Place Fund real-estate / conservation projects.
|
|
5
|
-
*
|
|
6
|
-
* Queries prt_projects with the trigger predicate, checks places/<slug>/HISTORY.md
|
|
7
|
-
* presence and schema validity for each qualifying row.
|
|
8
|
-
*
|
|
9
|
-
* Usage:
|
|
10
|
-
* node scripts/validate-place-histories.js [--mode warn|fail] [--slug <name>] [--json]
|
|
11
|
-
*
|
|
12
|
-
* Exit codes:
|
|
13
|
-
* 0 — all checks passed (or warn mode with only warnings)
|
|
14
|
-
* 1 — one or more FAIL lines (hard error)
|
|
15
|
-
* 2 — invocation error (bad args)
|
|
16
|
-
*
|
|
17
|
-
* Trigger predicate:
|
|
18
|
-
* project_type IN ('ranch','eco-hospitality','mixed','conservation',
|
|
19
|
-
* 'regenerative-agriculture','real-estate','development')
|
|
20
|
-
* AND name IS NOT NULL
|
|
21
|
-
* AND (location_state IS NOT NULL OR location_city IS NOT NULL OR country IS NOT NULL
|
|
22
|
-
* OR total_acres IS NOT NULL OR lat IS NOT NULL
|
|
23
|
-
* OR EXISTS (SELECT 1 FROM geo_projects WHERE prt_project_id = prt_projects.id))
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
'use strict';
|
|
27
|
-
|
|
28
|
-
const fs = require('fs');
|
|
29
|
-
const path = require('path');
|
|
30
|
-
const https = require('https');
|
|
31
|
-
const http = require('http');
|
|
32
|
-
|
|
33
|
-
// ---------------------------------------------------------------------------
|
|
34
|
-
// CLI argument parsing
|
|
35
|
-
// ---------------------------------------------------------------------------
|
|
36
|
-
|
|
37
|
-
const args = process.argv.slice(2);
|
|
38
|
-
let mode = 'warn'; // warn | fail
|
|
39
|
-
let slugFilter = null; // --slug <name>
|
|
40
|
-
let jsonOutput = false; // --json
|
|
41
|
-
|
|
42
|
-
for (let i = 0; i < args.length; i++) {
|
|
43
|
-
const a = args[i];
|
|
44
|
-
if (a === '--mode') {
|
|
45
|
-
const v = args[++i];
|
|
46
|
-
if (v !== 'warn' && v !== 'fail') {
|
|
47
|
-
console.error('ERROR: --mode must be warn or fail');
|
|
48
|
-
process.exit(2);
|
|
49
|
-
}
|
|
50
|
-
mode = v;
|
|
51
|
-
} else if (a === '--slug') {
|
|
52
|
-
slugFilter = args[++i];
|
|
53
|
-
if (!slugFilter) {
|
|
54
|
-
console.error('ERROR: --slug requires a value');
|
|
55
|
-
process.exit(2);
|
|
56
|
-
}
|
|
57
|
-
} else if (a === '--json') {
|
|
58
|
-
jsonOutput = true;
|
|
59
|
-
} else {
|
|
60
|
-
console.error(`ERROR: unknown argument: ${a}`);
|
|
61
|
-
process.exit(2);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// ---------------------------------------------------------------------------
|
|
66
|
-
// Constants
|
|
67
|
-
// ---------------------------------------------------------------------------
|
|
68
|
-
|
|
69
|
-
const MONOREPO_ROOT = 'C:/Dev/regen-root';
|
|
70
|
-
const CLAUTH_BASE = 'http://127.0.0.1:52437';
|
|
71
|
-
const SUPABASE_PROJECT_HOST = 'uvojezuorjgqzmhhgluu.supabase.co';
|
|
72
|
-
|
|
73
|
-
// project_types that trigger HISTORY.md requirement
|
|
74
|
-
const TRIGGERING_PROJECT_TYPES = new Set([
|
|
75
|
-
'ranch',
|
|
76
|
-
'eco-hospitality',
|
|
77
|
-
'mixed',
|
|
78
|
-
'conservation',
|
|
79
|
-
'regenerative-agriculture',
|
|
80
|
-
'real-estate',
|
|
81
|
-
'development',
|
|
82
|
-
]);
|
|
83
|
-
|
|
84
|
-
// Required frontmatter fields in HISTORY.md
|
|
85
|
-
const REQUIRED_FRONTMATTER_FIELDS = [
|
|
86
|
-
'schema_version',
|
|
87
|
-
'prt_slug',
|
|
88
|
-
'project_type',
|
|
89
|
-
'location',
|
|
90
|
-
'steward',
|
|
91
|
-
'research_status',
|
|
92
|
-
'last_reviewed',
|
|
93
|
-
'contributors',
|
|
94
|
-
];
|
|
95
|
-
|
|
96
|
-
const ALLOWED_SCHEMA_VERSIONS = ['1.0'];
|
|
97
|
-
|
|
98
|
-
const ALLOWED_RESEARCH_STATUSES = ['draft', 'in-research', 'peer-reviewed', 'published'];
|
|
99
|
-
|
|
100
|
-
// Required body section headings (## heading, exact text)
|
|
101
|
-
const REQUIRED_SECTIONS = [
|
|
102
|
-
'## Land lineage',
|
|
103
|
-
'## Stewardship transitions',
|
|
104
|
-
'## Ecological context',
|
|
105
|
-
'## Cultural significance',
|
|
106
|
-
'## Regulatory record',
|
|
107
|
-
];
|
|
108
|
-
|
|
109
|
-
// ---------------------------------------------------------------------------
|
|
110
|
-
// Result tracking
|
|
111
|
-
// ---------------------------------------------------------------------------
|
|
112
|
-
|
|
113
|
-
const results = [];
|
|
114
|
-
let hasHardFail = false;
|
|
115
|
-
|
|
116
|
-
function emit(level, slug, message, detail) {
|
|
117
|
-
const entry = { level, slug, message, detail: detail || null };
|
|
118
|
-
results.push(entry);
|
|
119
|
-
if (level === 'FAIL') hasHardFail = true;
|
|
120
|
-
if (!jsonOutput) {
|
|
121
|
-
const prefix = level === 'FAIL' ? '✗ FAIL' : level === 'WARN' ? '⚠ WARN' : '✓ PASS';
|
|
122
|
-
console.log(`${prefix} [${slug}] ${message}${detail ? ` — ${detail}` : ''}`);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
// ---------------------------------------------------------------------------
|
|
127
|
-
// HTTP helpers
|
|
128
|
-
// ---------------------------------------------------------------------------
|
|
129
|
-
|
|
130
|
-
/** Fetch plain text from clauth daemon (never prints value) */
|
|
131
|
-
function fetchClauth(service) {
|
|
132
|
-
return new Promise((resolve, reject) => {
|
|
133
|
-
const req = http.get(`${CLAUTH_BASE}/v/${service}`, (res) => {
|
|
134
|
-
let buf = '';
|
|
135
|
-
res.on('data', (c) => (buf += c));
|
|
136
|
-
res.on('end', () => {
|
|
137
|
-
if (res.statusCode !== 200) {
|
|
138
|
-
reject(new Error(`clauth /v/${service} → HTTP ${res.statusCode}`));
|
|
139
|
-
} else {
|
|
140
|
-
resolve(buf.trim());
|
|
141
|
-
}
|
|
142
|
-
});
|
|
143
|
-
});
|
|
144
|
-
req.on('error', reject);
|
|
145
|
-
req.setTimeout(5000, () => { req.destroy(); reject(new Error('clauth timeout')); });
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
/** REST GET against Supabase with anon key */
|
|
150
|
-
function supabaseGet(anonKey, qpath) {
|
|
151
|
-
return new Promise((resolve, reject) => {
|
|
152
|
-
const options = {
|
|
153
|
-
hostname: SUPABASE_PROJECT_HOST,
|
|
154
|
-
path: qpath,
|
|
155
|
-
method: 'GET',
|
|
156
|
-
headers: {
|
|
157
|
-
'apikey': anonKey,
|
|
158
|
-
'Authorization': `Bearer ${anonKey}`,
|
|
159
|
-
'Content-Type': 'application/json',
|
|
160
|
-
'Accept': 'application/json',
|
|
161
|
-
},
|
|
162
|
-
};
|
|
163
|
-
const req = https.request(options, (res) => {
|
|
164
|
-
let buf = '';
|
|
165
|
-
res.on('data', (c) => (buf += c));
|
|
166
|
-
res.on('end', () => {
|
|
167
|
-
if (res.statusCode !== 200) {
|
|
168
|
-
reject(new Error(`Supabase REST ${qpath} → HTTP ${res.statusCode}: ${buf.slice(0, 200)}`));
|
|
169
|
-
} else {
|
|
170
|
-
try {
|
|
171
|
-
resolve(JSON.parse(buf));
|
|
172
|
-
} catch (e) {
|
|
173
|
-
reject(new Error(`JSON parse error: ${e.message}`));
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
});
|
|
177
|
-
});
|
|
178
|
-
req.on('error', reject);
|
|
179
|
-
req.setTimeout(10000, () => { req.destroy(); reject(new Error('Supabase timeout')); });
|
|
180
|
-
req.end();
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
// ---------------------------------------------------------------------------
|
|
185
|
-
// YAML frontmatter parser (minimal — no external dep)
|
|
186
|
-
// ---------------------------------------------------------------------------
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* Parse YAML frontmatter from a HISTORY.md string.
|
|
190
|
-
* Handles scalars, inline arrays ([a, b]), quoted strings, and nested objects
|
|
191
|
-
* (single-level indent under a key: followed by child key: value lines).
|
|
192
|
-
* Returns null if no frontmatter delimiters found.
|
|
193
|
-
*/
|
|
194
|
-
function parseFrontmatter(content) {
|
|
195
|
-
const fmMatch = content.match(/^---\r?\n([\s\S]*?)\r?\n---/);
|
|
196
|
-
if (!fmMatch) return null;
|
|
197
|
-
|
|
198
|
-
const yaml = fmMatch[1];
|
|
199
|
-
const result = {};
|
|
200
|
-
const lines = yaml.split(/\r?\n/);
|
|
201
|
-
|
|
202
|
-
let i = 0;
|
|
203
|
-
while (i < lines.length) {
|
|
204
|
-
const line = lines[i];
|
|
205
|
-
|
|
206
|
-
// Top-level key
|
|
207
|
-
const kv = line.match(/^([a-zA-Z_][a-zA-Z0-9_]*):\s*(.*)$/);
|
|
208
|
-
if (!kv) { i++; continue; }
|
|
209
|
-
|
|
210
|
-
const key = kv[1];
|
|
211
|
-
let value = kv[2].trim();
|
|
212
|
-
|
|
213
|
-
// Inline array: [a, b, c] or []
|
|
214
|
-
if (value.startsWith('[') && value.endsWith(']')) {
|
|
215
|
-
const inner = value.slice(1, -1).trim();
|
|
216
|
-
result[key] = inner ? inner.split(',').map((s) => s.trim().replace(/^["']|["']$/g, '')) : [];
|
|
217
|
-
i++;
|
|
218
|
-
continue;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
// Quoted string
|
|
222
|
-
if ((value.startsWith('"') && value.endsWith('"')) ||
|
|
223
|
-
(value.startsWith("'") && value.endsWith("'"))) {
|
|
224
|
-
result[key] = value.slice(1, -1);
|
|
225
|
-
i++;
|
|
226
|
-
continue;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
// Empty value — may be start of nested object
|
|
230
|
-
if (value === '') {
|
|
231
|
-
// Peek ahead for indented child lines
|
|
232
|
-
const nested = {};
|
|
233
|
-
let j = i + 1;
|
|
234
|
-
while (j < lines.length) {
|
|
235
|
-
const child = lines[j].match(/^ ([a-zA-Z_][a-zA-Z0-9_]*):\s*(.*)$/);
|
|
236
|
-
if (!child) break;
|
|
237
|
-
let cv = child[2].trim();
|
|
238
|
-
if ((cv.startsWith('"') && cv.endsWith('"')) ||
|
|
239
|
-
(cv.startsWith("'") && cv.endsWith("'"))) {
|
|
240
|
-
cv = cv.slice(1, -1);
|
|
241
|
-
}
|
|
242
|
-
// Inline array under nested key
|
|
243
|
-
if (cv.startsWith('[') && cv.endsWith(']')) {
|
|
244
|
-
const inner2 = cv.slice(1, -1).trim();
|
|
245
|
-
nested[child[1]] = inner2 ? inner2.split(',').map((s) => s.trim().replace(/^["']|["']$/g, '')) : [];
|
|
246
|
-
} else {
|
|
247
|
-
nested[child[1]] = cv;
|
|
248
|
-
}
|
|
249
|
-
j++;
|
|
250
|
-
}
|
|
251
|
-
if (j > i + 1) {
|
|
252
|
-
result[key] = nested;
|
|
253
|
-
i = j;
|
|
254
|
-
} else {
|
|
255
|
-
result[key] = value;
|
|
256
|
-
i++;
|
|
257
|
-
}
|
|
258
|
-
continue;
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
result[key] = value;
|
|
262
|
-
i++;
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
return result;
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
// ---------------------------------------------------------------------------
|
|
269
|
-
// Slug → filesystem directory name
|
|
270
|
-
// Preserves DB slug but lowercases for the directory path.
|
|
271
|
-
// ---------------------------------------------------------------------------
|
|
272
|
-
|
|
273
|
-
function slugToDir(slug) {
|
|
274
|
-
return slug.toLowerCase();
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
// ---------------------------------------------------------------------------
|
|
278
|
-
// Validation logic for a single project row
|
|
279
|
-
// ---------------------------------------------------------------------------
|
|
280
|
-
|
|
281
|
-
function validateProject(slug) {
|
|
282
|
-
const dirName = slugToDir(slug);
|
|
283
|
-
const historyPath = path.join(MONOREPO_ROOT, 'places', dirName, 'HISTORY.md');
|
|
284
|
-
|
|
285
|
-
if (!fs.existsSync(historyPath)) {
|
|
286
|
-
if (mode === 'fail') {
|
|
287
|
-
emit('FAIL', slug, 'HISTORY.md missing', historyPath);
|
|
288
|
-
} else {
|
|
289
|
-
emit('WARN', slug, 'HISTORY.md missing', historyPath);
|
|
290
|
-
}
|
|
291
|
-
return null;
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
const content = fs.readFileSync(historyPath, 'utf8');
|
|
295
|
-
|
|
296
|
-
// 1. Parse frontmatter
|
|
297
|
-
const fm = parseFrontmatter(content);
|
|
298
|
-
if (!fm) {
|
|
299
|
-
emit('FAIL', slug, 'HISTORY.md has no YAML frontmatter (missing --- delimiters)', historyPath);
|
|
300
|
-
return null;
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
let ok = true;
|
|
304
|
-
|
|
305
|
-
// 2. Required frontmatter fields
|
|
306
|
-
for (const field of REQUIRED_FRONTMATTER_FIELDS) {
|
|
307
|
-
const val = fm[field];
|
|
308
|
-
if (val === undefined || val === null || val === '') {
|
|
309
|
-
emit('FAIL', slug, `HISTORY.md missing required field: ${field}`, historyPath);
|
|
310
|
-
ok = false;
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
// 3. schema_version
|
|
315
|
-
if (fm.schema_version && !ALLOWED_SCHEMA_VERSIONS.includes(fm.schema_version)) {
|
|
316
|
-
emit('FAIL', slug, `HISTORY.md schema_version "${fm.schema_version}" not in allowed set: ${ALLOWED_SCHEMA_VERSIONS.join(', ')}`, historyPath);
|
|
317
|
-
ok = false;
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
// 4. research_status enum
|
|
321
|
-
if (fm.research_status && !ALLOWED_RESEARCH_STATUSES.includes(fm.research_status)) {
|
|
322
|
-
emit('FAIL', slug, `HISTORY.md research_status "${fm.research_status}" not in allowed set: ${ALLOWED_RESEARCH_STATUSES.join(', ')}`, historyPath);
|
|
323
|
-
ok = false;
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
// 5. prt_slug must match the DB slug (case-sensitive)
|
|
327
|
-
if (fm.prt_slug !== undefined && fm.prt_slug !== slug) {
|
|
328
|
-
emit('WARN', slug, `HISTORY.md prt_slug "${fm.prt_slug}" does not match DB slug "${slug}" — check for case drift`, historyPath);
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
// 6. contributors must be an array (even if empty)
|
|
332
|
-
if (fm.contributors !== undefined && !Array.isArray(fm.contributors)) {
|
|
333
|
-
emit('FAIL', slug, 'HISTORY.md contributors must be an array (use [] for empty)', historyPath);
|
|
334
|
-
ok = false;
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
// 7. location must be a non-null object
|
|
338
|
-
if (fm.location !== undefined && (typeof fm.location !== 'object' || Array.isArray(fm.location))) {
|
|
339
|
-
emit('FAIL', slug, 'HISTORY.md location must be a nested YAML object block', historyPath);
|
|
340
|
-
ok = false;
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
// 8. Required body sections
|
|
344
|
-
for (const section of REQUIRED_SECTIONS) {
|
|
345
|
-
// Match heading with possible trailing whitespace or \r
|
|
346
|
-
const re = new RegExp(`^${section.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\s*$`, 'm');
|
|
347
|
-
if (!re.test(content)) {
|
|
348
|
-
emit('FAIL', slug, `HISTORY.md missing required section: "${section}"`, historyPath);
|
|
349
|
-
ok = false;
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
if (ok) {
|
|
354
|
-
emit('PASS', slug, `HISTORY.md valid (research_status: ${fm.research_status || 'unknown'})`, historyPath);
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
return { fm, historyPath };
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
// ---------------------------------------------------------------------------
|
|
361
|
-
// Apply trigger predicate client-side (fetch all, filter here)
|
|
362
|
-
// ---------------------------------------------------------------------------
|
|
363
|
-
|
|
364
|
-
function matchesTriggerPredicate(row) {
|
|
365
|
-
if (!TRIGGERING_PROJECT_TYPES.has(row.project_type)) return false;
|
|
366
|
-
if (!row.name) return false;
|
|
367
|
-
// geo_projects is an embedded resource array from PostgREST; non-empty = GIS data exists
|
|
368
|
-
const hasGeoProject = Array.isArray(row.geo_projects) && row.geo_projects.length > 0;
|
|
369
|
-
return (
|
|
370
|
-
row.location_state !== null ||
|
|
371
|
-
row.location_city !== null ||
|
|
372
|
-
row.country !== null ||
|
|
373
|
-
row.total_acres !== null ||
|
|
374
|
-
row.lat !== null ||
|
|
375
|
-
hasGeoProject
|
|
376
|
-
);
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
// ---------------------------------------------------------------------------
|
|
380
|
-
// Main
|
|
381
|
-
// ---------------------------------------------------------------------------
|
|
382
|
-
|
|
383
|
-
async function main() {
|
|
384
|
-
if (!jsonOutput) {
|
|
385
|
-
console.log(`\nvalidate-place-histories — mode=${mode}${slugFilter ? ` slug=${slugFilter}` : ''}\n`);
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
// 1. Get Supabase anon key from clauth
|
|
389
|
-
let anonKey;
|
|
390
|
-
try {
|
|
391
|
-
anonKey = await fetchClauth('supabase-anon');
|
|
392
|
-
} catch (err) {
|
|
393
|
-
console.error(`ERROR: cannot reach clauth daemon — ${err.message}`);
|
|
394
|
-
console.error('Fix: ensure clauth daemon is running at http://127.0.0.1:52437');
|
|
395
|
-
process.exit(1);
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
// 2. Query prt_projects — fetch triggering columns for all non-template rows
|
|
399
|
-
let rows;
|
|
400
|
-
try {
|
|
401
|
-
let qpath = '/rest/v1/prt_projects?is_template=neq.true&select=slug,name,project_type,location_state,location_city,country,total_acres,lat,geo_projects(id)&order=slug.asc';
|
|
402
|
-
if (slugFilter) {
|
|
403
|
-
qpath += `&slug=eq.${encodeURIComponent(slugFilter)}`;
|
|
404
|
-
}
|
|
405
|
-
rows = await supabaseGet(anonKey, qpath);
|
|
406
|
-
} catch (err) {
|
|
407
|
-
console.error(`ERROR: Supabase query failed — ${err.message}`);
|
|
408
|
-
process.exit(1);
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
if (!Array.isArray(rows)) {
|
|
412
|
-
console.error('ERROR: unexpected response format from Supabase');
|
|
413
|
-
process.exit(1);
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
// 3. Apply trigger predicate client-side
|
|
417
|
-
const triggeringRows = rows.filter(matchesTriggerPredicate);
|
|
418
|
-
|
|
419
|
-
if (triggeringRows.length === 0) {
|
|
420
|
-
if (!jsonOutput) {
|
|
421
|
-
console.log(
|
|
422
|
-
slugFilter
|
|
423
|
-
? `No triggering prt_projects row found for slug: ${slugFilter}`
|
|
424
|
-
: 'No prt_projects rows match the trigger predicate.'
|
|
425
|
-
);
|
|
426
|
-
}
|
|
427
|
-
process.exit(0);
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
if (!jsonOutput) {
|
|
431
|
-
console.log(`Found ${triggeringRows.length} triggering project(s) (from ${rows.length} total non-template rows)...\n`);
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
// 4. Validate each
|
|
435
|
-
for (const row of triggeringRows) {
|
|
436
|
-
validateProject(row.slug);
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
// 5. Summary
|
|
440
|
-
const passCount = results.filter((r) => r.level === 'PASS').length;
|
|
441
|
-
const warnCount = results.filter((r) => r.level === 'WARN').length;
|
|
442
|
-
const failCount = results.filter((r) => r.level === 'FAIL').length;
|
|
443
|
-
|
|
444
|
-
if (jsonOutput) {
|
|
445
|
-
console.log(JSON.stringify({ mode, results, summary: { pass: passCount, warn: warnCount, fail: failCount } }, null, 2));
|
|
446
|
-
} else {
|
|
447
|
-
console.log(`\nSummary: ${passCount} PASS · ${warnCount} WARN · ${failCount} FAIL`);
|
|
448
|
-
if (hasHardFail) {
|
|
449
|
-
console.log('Result: FAIL\n');
|
|
450
|
-
} else {
|
|
451
|
-
console.log(warnCount > 0 ? 'Result: WARN (exit 0 in warn mode)\n' : 'Result: PASS\n');
|
|
452
|
-
}
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
process.exit(hasHardFail ? 1 : 0);
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
main().catch((err) => {
|
|
459
|
-
console.error(`FATAL: ${err.message}`);
|
|
460
|
-
process.exit(1);
|
|
461
|
-
});
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* validate-place-histories.js
|
|
4
|
+
* HISTORY.md convention validator for Place Fund real-estate / conservation projects.
|
|
5
|
+
*
|
|
6
|
+
* Queries prt_projects with the trigger predicate, checks places/<slug>/HISTORY.md
|
|
7
|
+
* presence and schema validity for each qualifying row.
|
|
8
|
+
*
|
|
9
|
+
* Usage:
|
|
10
|
+
* node scripts/validate-place-histories.js [--mode warn|fail] [--slug <name>] [--json]
|
|
11
|
+
*
|
|
12
|
+
* Exit codes:
|
|
13
|
+
* 0 — all checks passed (or warn mode with only warnings)
|
|
14
|
+
* 1 — one or more FAIL lines (hard error)
|
|
15
|
+
* 2 — invocation error (bad args)
|
|
16
|
+
*
|
|
17
|
+
* Trigger predicate:
|
|
18
|
+
* project_type IN ('ranch','eco-hospitality','mixed','conservation',
|
|
19
|
+
* 'regenerative-agriculture','real-estate','development')
|
|
20
|
+
* AND name IS NOT NULL
|
|
21
|
+
* AND (location_state IS NOT NULL OR location_city IS NOT NULL OR country IS NOT NULL
|
|
22
|
+
* OR total_acres IS NOT NULL OR lat IS NOT NULL
|
|
23
|
+
* OR EXISTS (SELECT 1 FROM geo_projects WHERE prt_project_id = prt_projects.id))
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
'use strict';
|
|
27
|
+
|
|
28
|
+
const fs = require('fs');
|
|
29
|
+
const path = require('path');
|
|
30
|
+
const https = require('https');
|
|
31
|
+
const http = require('http');
|
|
32
|
+
|
|
33
|
+
// ---------------------------------------------------------------------------
|
|
34
|
+
// CLI argument parsing
|
|
35
|
+
// ---------------------------------------------------------------------------
|
|
36
|
+
|
|
37
|
+
const args = process.argv.slice(2);
|
|
38
|
+
let mode = 'warn'; // warn | fail
|
|
39
|
+
let slugFilter = null; // --slug <name>
|
|
40
|
+
let jsonOutput = false; // --json
|
|
41
|
+
|
|
42
|
+
for (let i = 0; i < args.length; i++) {
|
|
43
|
+
const a = args[i];
|
|
44
|
+
if (a === '--mode') {
|
|
45
|
+
const v = args[++i];
|
|
46
|
+
if (v !== 'warn' && v !== 'fail') {
|
|
47
|
+
console.error('ERROR: --mode must be warn or fail');
|
|
48
|
+
process.exit(2);
|
|
49
|
+
}
|
|
50
|
+
mode = v;
|
|
51
|
+
} else if (a === '--slug') {
|
|
52
|
+
slugFilter = args[++i];
|
|
53
|
+
if (!slugFilter) {
|
|
54
|
+
console.error('ERROR: --slug requires a value');
|
|
55
|
+
process.exit(2);
|
|
56
|
+
}
|
|
57
|
+
} else if (a === '--json') {
|
|
58
|
+
jsonOutput = true;
|
|
59
|
+
} else {
|
|
60
|
+
console.error(`ERROR: unknown argument: ${a}`);
|
|
61
|
+
process.exit(2);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// ---------------------------------------------------------------------------
|
|
66
|
+
// Constants
|
|
67
|
+
// ---------------------------------------------------------------------------
|
|
68
|
+
|
|
69
|
+
const MONOREPO_ROOT = 'C:/Dev/regen-root';
|
|
70
|
+
const CLAUTH_BASE = 'http://127.0.0.1:52437';
|
|
71
|
+
const SUPABASE_PROJECT_HOST = 'uvojezuorjgqzmhhgluu.supabase.co';
|
|
72
|
+
|
|
73
|
+
// project_types that trigger HISTORY.md requirement
|
|
74
|
+
const TRIGGERING_PROJECT_TYPES = new Set([
|
|
75
|
+
'ranch',
|
|
76
|
+
'eco-hospitality',
|
|
77
|
+
'mixed',
|
|
78
|
+
'conservation',
|
|
79
|
+
'regenerative-agriculture',
|
|
80
|
+
'real-estate',
|
|
81
|
+
'development',
|
|
82
|
+
]);
|
|
83
|
+
|
|
84
|
+
// Required frontmatter fields in HISTORY.md
|
|
85
|
+
const REQUIRED_FRONTMATTER_FIELDS = [
|
|
86
|
+
'schema_version',
|
|
87
|
+
'prt_slug',
|
|
88
|
+
'project_type',
|
|
89
|
+
'location',
|
|
90
|
+
'steward',
|
|
91
|
+
'research_status',
|
|
92
|
+
'last_reviewed',
|
|
93
|
+
'contributors',
|
|
94
|
+
];
|
|
95
|
+
|
|
96
|
+
const ALLOWED_SCHEMA_VERSIONS = ['1.0'];
|
|
97
|
+
|
|
98
|
+
const ALLOWED_RESEARCH_STATUSES = ['draft', 'in-research', 'peer-reviewed', 'published'];
|
|
99
|
+
|
|
100
|
+
// Required body section headings (## heading, exact text)
|
|
101
|
+
const REQUIRED_SECTIONS = [
|
|
102
|
+
'## Land lineage',
|
|
103
|
+
'## Stewardship transitions',
|
|
104
|
+
'## Ecological context',
|
|
105
|
+
'## Cultural significance',
|
|
106
|
+
'## Regulatory record',
|
|
107
|
+
];
|
|
108
|
+
|
|
109
|
+
// ---------------------------------------------------------------------------
|
|
110
|
+
// Result tracking
|
|
111
|
+
// ---------------------------------------------------------------------------
|
|
112
|
+
|
|
113
|
+
const results = [];
|
|
114
|
+
let hasHardFail = false;
|
|
115
|
+
|
|
116
|
+
function emit(level, slug, message, detail) {
|
|
117
|
+
const entry = { level, slug, message, detail: detail || null };
|
|
118
|
+
results.push(entry);
|
|
119
|
+
if (level === 'FAIL') hasHardFail = true;
|
|
120
|
+
if (!jsonOutput) {
|
|
121
|
+
const prefix = level === 'FAIL' ? '✗ FAIL' : level === 'WARN' ? '⚠ WARN' : '✓ PASS';
|
|
122
|
+
console.log(`${prefix} [${slug}] ${message}${detail ? ` — ${detail}` : ''}`);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// ---------------------------------------------------------------------------
|
|
127
|
+
// HTTP helpers
|
|
128
|
+
// ---------------------------------------------------------------------------
|
|
129
|
+
|
|
130
|
+
/** Fetch plain text from clauth daemon (never prints value) */
|
|
131
|
+
function fetchClauth(service) {
|
|
132
|
+
return new Promise((resolve, reject) => {
|
|
133
|
+
const req = http.get(`${CLAUTH_BASE}/v/${service}`, (res) => {
|
|
134
|
+
let buf = '';
|
|
135
|
+
res.on('data', (c) => (buf += c));
|
|
136
|
+
res.on('end', () => {
|
|
137
|
+
if (res.statusCode !== 200) {
|
|
138
|
+
reject(new Error(`clauth /v/${service} → HTTP ${res.statusCode}`));
|
|
139
|
+
} else {
|
|
140
|
+
resolve(buf.trim());
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
req.on('error', reject);
|
|
145
|
+
req.setTimeout(5000, () => { req.destroy(); reject(new Error('clauth timeout')); });
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** REST GET against Supabase with anon key */
|
|
150
|
+
function supabaseGet(anonKey, qpath) {
|
|
151
|
+
return new Promise((resolve, reject) => {
|
|
152
|
+
const options = {
|
|
153
|
+
hostname: SUPABASE_PROJECT_HOST,
|
|
154
|
+
path: qpath,
|
|
155
|
+
method: 'GET',
|
|
156
|
+
headers: {
|
|
157
|
+
'apikey': anonKey,
|
|
158
|
+
'Authorization': `Bearer ${anonKey}`,
|
|
159
|
+
'Content-Type': 'application/json',
|
|
160
|
+
'Accept': 'application/json',
|
|
161
|
+
},
|
|
162
|
+
};
|
|
163
|
+
const req = https.request(options, (res) => {
|
|
164
|
+
let buf = '';
|
|
165
|
+
res.on('data', (c) => (buf += c));
|
|
166
|
+
res.on('end', () => {
|
|
167
|
+
if (res.statusCode !== 200) {
|
|
168
|
+
reject(new Error(`Supabase REST ${qpath} → HTTP ${res.statusCode}: ${buf.slice(0, 200)}`));
|
|
169
|
+
} else {
|
|
170
|
+
try {
|
|
171
|
+
resolve(JSON.parse(buf));
|
|
172
|
+
} catch (e) {
|
|
173
|
+
reject(new Error(`JSON parse error: ${e.message}`));
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
req.on('error', reject);
|
|
179
|
+
req.setTimeout(10000, () => { req.destroy(); reject(new Error('Supabase timeout')); });
|
|
180
|
+
req.end();
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// ---------------------------------------------------------------------------
|
|
185
|
+
// YAML frontmatter parser (minimal — no external dep)
|
|
186
|
+
// ---------------------------------------------------------------------------
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Parse YAML frontmatter from a HISTORY.md string.
|
|
190
|
+
* Handles scalars, inline arrays ([a, b]), quoted strings, and nested objects
|
|
191
|
+
* (single-level indent under a key: followed by child key: value lines).
|
|
192
|
+
* Returns null if no frontmatter delimiters found.
|
|
193
|
+
*/
|
|
194
|
+
function parseFrontmatter(content) {
|
|
195
|
+
const fmMatch = content.match(/^---\r?\n([\s\S]*?)\r?\n---/);
|
|
196
|
+
if (!fmMatch) return null;
|
|
197
|
+
|
|
198
|
+
const yaml = fmMatch[1];
|
|
199
|
+
const result = {};
|
|
200
|
+
const lines = yaml.split(/\r?\n/);
|
|
201
|
+
|
|
202
|
+
let i = 0;
|
|
203
|
+
while (i < lines.length) {
|
|
204
|
+
const line = lines[i];
|
|
205
|
+
|
|
206
|
+
// Top-level key
|
|
207
|
+
const kv = line.match(/^([a-zA-Z_][a-zA-Z0-9_]*):\s*(.*)$/);
|
|
208
|
+
if (!kv) { i++; continue; }
|
|
209
|
+
|
|
210
|
+
const key = kv[1];
|
|
211
|
+
let value = kv[2].trim();
|
|
212
|
+
|
|
213
|
+
// Inline array: [a, b, c] or []
|
|
214
|
+
if (value.startsWith('[') && value.endsWith(']')) {
|
|
215
|
+
const inner = value.slice(1, -1).trim();
|
|
216
|
+
result[key] = inner ? inner.split(',').map((s) => s.trim().replace(/^["']|["']$/g, '')) : [];
|
|
217
|
+
i++;
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// Quoted string
|
|
222
|
+
if ((value.startsWith('"') && value.endsWith('"')) ||
|
|
223
|
+
(value.startsWith("'") && value.endsWith("'"))) {
|
|
224
|
+
result[key] = value.slice(1, -1);
|
|
225
|
+
i++;
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// Empty value — may be start of nested object
|
|
230
|
+
if (value === '') {
|
|
231
|
+
// Peek ahead for indented child lines
|
|
232
|
+
const nested = {};
|
|
233
|
+
let j = i + 1;
|
|
234
|
+
while (j < lines.length) {
|
|
235
|
+
const child = lines[j].match(/^ ([a-zA-Z_][a-zA-Z0-9_]*):\s*(.*)$/);
|
|
236
|
+
if (!child) break;
|
|
237
|
+
let cv = child[2].trim();
|
|
238
|
+
if ((cv.startsWith('"') && cv.endsWith('"')) ||
|
|
239
|
+
(cv.startsWith("'") && cv.endsWith("'"))) {
|
|
240
|
+
cv = cv.slice(1, -1);
|
|
241
|
+
}
|
|
242
|
+
// Inline array under nested key
|
|
243
|
+
if (cv.startsWith('[') && cv.endsWith(']')) {
|
|
244
|
+
const inner2 = cv.slice(1, -1).trim();
|
|
245
|
+
nested[child[1]] = inner2 ? inner2.split(',').map((s) => s.trim().replace(/^["']|["']$/g, '')) : [];
|
|
246
|
+
} else {
|
|
247
|
+
nested[child[1]] = cv;
|
|
248
|
+
}
|
|
249
|
+
j++;
|
|
250
|
+
}
|
|
251
|
+
if (j > i + 1) {
|
|
252
|
+
result[key] = nested;
|
|
253
|
+
i = j;
|
|
254
|
+
} else {
|
|
255
|
+
result[key] = value;
|
|
256
|
+
i++;
|
|
257
|
+
}
|
|
258
|
+
continue;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
result[key] = value;
|
|
262
|
+
i++;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
return result;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// ---------------------------------------------------------------------------
|
|
269
|
+
// Slug → filesystem directory name
|
|
270
|
+
// Preserves DB slug but lowercases for the directory path.
|
|
271
|
+
// ---------------------------------------------------------------------------
|
|
272
|
+
|
|
273
|
+
function slugToDir(slug) {
|
|
274
|
+
return slug.toLowerCase();
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
// ---------------------------------------------------------------------------
|
|
278
|
+
// Validation logic for a single project row
|
|
279
|
+
// ---------------------------------------------------------------------------
|
|
280
|
+
|
|
281
|
+
function validateProject(slug) {
|
|
282
|
+
const dirName = slugToDir(slug);
|
|
283
|
+
const historyPath = path.join(MONOREPO_ROOT, 'places', dirName, 'HISTORY.md');
|
|
284
|
+
|
|
285
|
+
if (!fs.existsSync(historyPath)) {
|
|
286
|
+
if (mode === 'fail') {
|
|
287
|
+
emit('FAIL', slug, 'HISTORY.md missing', historyPath);
|
|
288
|
+
} else {
|
|
289
|
+
emit('WARN', slug, 'HISTORY.md missing', historyPath);
|
|
290
|
+
}
|
|
291
|
+
return null;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
const content = fs.readFileSync(historyPath, 'utf8');
|
|
295
|
+
|
|
296
|
+
// 1. Parse frontmatter
|
|
297
|
+
const fm = parseFrontmatter(content);
|
|
298
|
+
if (!fm) {
|
|
299
|
+
emit('FAIL', slug, 'HISTORY.md has no YAML frontmatter (missing --- delimiters)', historyPath);
|
|
300
|
+
return null;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
let ok = true;
|
|
304
|
+
|
|
305
|
+
// 2. Required frontmatter fields
|
|
306
|
+
for (const field of REQUIRED_FRONTMATTER_FIELDS) {
|
|
307
|
+
const val = fm[field];
|
|
308
|
+
if (val === undefined || val === null || val === '') {
|
|
309
|
+
emit('FAIL', slug, `HISTORY.md missing required field: ${field}`, historyPath);
|
|
310
|
+
ok = false;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
// 3. schema_version
|
|
315
|
+
if (fm.schema_version && !ALLOWED_SCHEMA_VERSIONS.includes(fm.schema_version)) {
|
|
316
|
+
emit('FAIL', slug, `HISTORY.md schema_version "${fm.schema_version}" not in allowed set: ${ALLOWED_SCHEMA_VERSIONS.join(', ')}`, historyPath);
|
|
317
|
+
ok = false;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// 4. research_status enum
|
|
321
|
+
if (fm.research_status && !ALLOWED_RESEARCH_STATUSES.includes(fm.research_status)) {
|
|
322
|
+
emit('FAIL', slug, `HISTORY.md research_status "${fm.research_status}" not in allowed set: ${ALLOWED_RESEARCH_STATUSES.join(', ')}`, historyPath);
|
|
323
|
+
ok = false;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
// 5. prt_slug must match the DB slug (case-sensitive)
|
|
327
|
+
if (fm.prt_slug !== undefined && fm.prt_slug !== slug) {
|
|
328
|
+
emit('WARN', slug, `HISTORY.md prt_slug "${fm.prt_slug}" does not match DB slug "${slug}" — check for case drift`, historyPath);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
// 6. contributors must be an array (even if empty)
|
|
332
|
+
if (fm.contributors !== undefined && !Array.isArray(fm.contributors)) {
|
|
333
|
+
emit('FAIL', slug, 'HISTORY.md contributors must be an array (use [] for empty)', historyPath);
|
|
334
|
+
ok = false;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// 7. location must be a non-null object
|
|
338
|
+
if (fm.location !== undefined && (typeof fm.location !== 'object' || Array.isArray(fm.location))) {
|
|
339
|
+
emit('FAIL', slug, 'HISTORY.md location must be a nested YAML object block', historyPath);
|
|
340
|
+
ok = false;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
// 8. Required body sections
|
|
344
|
+
for (const section of REQUIRED_SECTIONS) {
|
|
345
|
+
// Match heading with possible trailing whitespace or \r
|
|
346
|
+
const re = new RegExp(`^${section.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\s*$`, 'm');
|
|
347
|
+
if (!re.test(content)) {
|
|
348
|
+
emit('FAIL', slug, `HISTORY.md missing required section: "${section}"`, historyPath);
|
|
349
|
+
ok = false;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
if (ok) {
|
|
354
|
+
emit('PASS', slug, `HISTORY.md valid (research_status: ${fm.research_status || 'unknown'})`, historyPath);
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
return { fm, historyPath };
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
// ---------------------------------------------------------------------------
|
|
361
|
+
// Apply trigger predicate client-side (fetch all, filter here)
|
|
362
|
+
// ---------------------------------------------------------------------------
|
|
363
|
+
|
|
364
|
+
function matchesTriggerPredicate(row) {
|
|
365
|
+
if (!TRIGGERING_PROJECT_TYPES.has(row.project_type)) return false;
|
|
366
|
+
if (!row.name) return false;
|
|
367
|
+
// geo_projects is an embedded resource array from PostgREST; non-empty = GIS data exists
|
|
368
|
+
const hasGeoProject = Array.isArray(row.geo_projects) && row.geo_projects.length > 0;
|
|
369
|
+
return (
|
|
370
|
+
row.location_state !== null ||
|
|
371
|
+
row.location_city !== null ||
|
|
372
|
+
row.country !== null ||
|
|
373
|
+
row.total_acres !== null ||
|
|
374
|
+
row.lat !== null ||
|
|
375
|
+
hasGeoProject
|
|
376
|
+
);
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
// ---------------------------------------------------------------------------
|
|
380
|
+
// Main
|
|
381
|
+
// ---------------------------------------------------------------------------
|
|
382
|
+
|
|
383
|
+
async function main() {
|
|
384
|
+
if (!jsonOutput) {
|
|
385
|
+
console.log(`\nvalidate-place-histories — mode=${mode}${slugFilter ? ` slug=${slugFilter}` : ''}\n`);
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
// 1. Get Supabase anon key from clauth
|
|
389
|
+
let anonKey;
|
|
390
|
+
try {
|
|
391
|
+
anonKey = await fetchClauth('supabase-anon');
|
|
392
|
+
} catch (err) {
|
|
393
|
+
console.error(`ERROR: cannot reach clauth daemon — ${err.message}`);
|
|
394
|
+
console.error('Fix: ensure clauth daemon is running at http://127.0.0.1:52437');
|
|
395
|
+
process.exit(1);
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
// 2. Query prt_projects — fetch triggering columns for all non-template rows
|
|
399
|
+
let rows;
|
|
400
|
+
try {
|
|
401
|
+
let qpath = '/rest/v1/prt_projects?is_template=neq.true&select=slug,name,project_type,location_state,location_city,country,total_acres,lat,geo_projects(id)&order=slug.asc';
|
|
402
|
+
if (slugFilter) {
|
|
403
|
+
qpath += `&slug=eq.${encodeURIComponent(slugFilter)}`;
|
|
404
|
+
}
|
|
405
|
+
rows = await supabaseGet(anonKey, qpath);
|
|
406
|
+
} catch (err) {
|
|
407
|
+
console.error(`ERROR: Supabase query failed — ${err.message}`);
|
|
408
|
+
process.exit(1);
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
if (!Array.isArray(rows)) {
|
|
412
|
+
console.error('ERROR: unexpected response format from Supabase');
|
|
413
|
+
process.exit(1);
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
// 3. Apply trigger predicate client-side
|
|
417
|
+
const triggeringRows = rows.filter(matchesTriggerPredicate);
|
|
418
|
+
|
|
419
|
+
if (triggeringRows.length === 0) {
|
|
420
|
+
if (!jsonOutput) {
|
|
421
|
+
console.log(
|
|
422
|
+
slugFilter
|
|
423
|
+
? `No triggering prt_projects row found for slug: ${slugFilter}`
|
|
424
|
+
: 'No prt_projects rows match the trigger predicate.'
|
|
425
|
+
);
|
|
426
|
+
}
|
|
427
|
+
process.exit(0);
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
if (!jsonOutput) {
|
|
431
|
+
console.log(`Found ${triggeringRows.length} triggering project(s) (from ${rows.length} total non-template rows)...\n`);
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
// 4. Validate each
|
|
435
|
+
for (const row of triggeringRows) {
|
|
436
|
+
validateProject(row.slug);
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
// 5. Summary
|
|
440
|
+
const passCount = results.filter((r) => r.level === 'PASS').length;
|
|
441
|
+
const warnCount = results.filter((r) => r.level === 'WARN').length;
|
|
442
|
+
const failCount = results.filter((r) => r.level === 'FAIL').length;
|
|
443
|
+
|
|
444
|
+
if (jsonOutput) {
|
|
445
|
+
console.log(JSON.stringify({ mode, results, summary: { pass: passCount, warn: warnCount, fail: failCount } }, null, 2));
|
|
446
|
+
} else {
|
|
447
|
+
console.log(`\nSummary: ${passCount} PASS · ${warnCount} WARN · ${failCount} FAIL`);
|
|
448
|
+
if (hasHardFail) {
|
|
449
|
+
console.log('Result: FAIL\n');
|
|
450
|
+
} else {
|
|
451
|
+
console.log(warnCount > 0 ? 'Result: WARN (exit 0 in warn mode)\n' : 'Result: PASS\n');
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
process.exit(hasHardFail ? 1 : 0);
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
main().catch((err) => {
|
|
459
|
+
console.error(`FATAL: ${err.message}`);
|
|
460
|
+
process.exit(1);
|
|
461
|
+
});
|