@lifeaitools/rdc-skills 0.24.38 → 0.24.41

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 (196) hide show
  1. package/.claude/settings.json +15 -15
  2. package/.claude-plugin/marketplace.json +21 -21
  3. package/.claude-plugin/plugin.json +1371 -1371
  4. package/.github/workflows/publish.yml +34 -34
  5. package/.github/workflows/self-test.yml +58 -58
  6. package/CHANGELOG.md +310 -310
  7. package/LICENSE +21 -21
  8. package/MANIFEST.md +221 -221
  9. package/README.md +376 -375
  10. package/README.sandbox.md +3 -3
  11. package/RELEASE.md +42 -0
  12. package/assets/watcher/viewer.html +164 -164
  13. package/bin/rdc-skills-mcp.mjs +316 -316
  14. package/commands/build.md +183 -183
  15. package/commands/collab.md +180 -180
  16. package/commands/deploy.md +152 -152
  17. package/commands/design.md +31 -31
  18. package/commands/edit.md +28 -28
  19. package/commands/fixit.md +124 -124
  20. package/commands/handoff.md +173 -173
  21. package/commands/help.md +95 -95
  22. package/commands/overnight.md +220 -220
  23. package/commands/plan.md +158 -158
  24. package/commands/preplan.md +131 -131
  25. package/commands/prototype.md +145 -145
  26. package/commands/release.md +49 -49
  27. package/commands/report.md +99 -99
  28. package/commands/review.md +120 -120
  29. package/commands/self-test.md +113 -113
  30. package/commands/status.md +86 -86
  31. package/commands/watch.md +98 -98
  32. package/commands/workitems.md +137 -137
  33. package/git-sha.json +1 -1
  34. package/guides/agent-bootstrap.md +295 -295
  35. package/guides/agents/backend.md +104 -104
  36. package/guides/agents/content.md +94 -94
  37. package/guides/agents/cs2.md +56 -56
  38. package/guides/agents/data.md +87 -87
  39. package/guides/agents/design.md +77 -77
  40. package/guides/agents/frontend.md +92 -92
  41. package/guides/agents/infrastructure.md +81 -81
  42. package/guides/agents/setup.md +281 -281
  43. package/guides/agents/verify.md +151 -151
  44. package/guides/agents/viz.md +106 -106
  45. package/guides/backend.md +146 -146
  46. package/guides/content.md +147 -147
  47. package/guides/cs2.md +190 -190
  48. package/guides/data.md +123 -123
  49. package/guides/design.md +116 -116
  50. package/guides/engineering-behavior.md +43 -43
  51. package/guides/escalation-protocol.md +125 -125
  52. package/guides/frontend.md +151 -151
  53. package/guides/history-md-spec.md +297 -297
  54. package/guides/infrastructure.md +179 -179
  55. package/guides/lessons-learned-spec.md +151 -145
  56. package/guides/output-contract.md +108 -108
  57. package/guides/publish-md-spec.md +289 -289
  58. package/guides/rdc-skills-startup.md +30 -30
  59. package/guides/verify.md +11 -11
  60. package/hooks/check-cwd.js +31 -31
  61. package/hooks/check-rdc-environment.js +164 -164
  62. package/hooks/check-services.js +6 -6
  63. package/hooks/check-stale-work-items.js +19 -19
  64. package/hooks/foreground-process-gate.js +128 -128
  65. package/hooks/gate-watchdog-selfcheck.js +257 -257
  66. package/hooks/hook-logger.js +25 -25
  67. package/hooks/lib/run-evidence-gate.mjs +241 -241
  68. package/hooks/no-stop-open-epics.js +127 -127
  69. package/hooks/post-tool-batch-gate.js +203 -203
  70. package/hooks/post-work-check.js +21 -21
  71. package/hooks/postcompact-log.js +13 -13
  72. package/hooks/precompact-log.js +13 -13
  73. package/hooks/rate-limit-retry.js +46 -46
  74. package/hooks/rdc-invocation-marker.js +157 -157
  75. package/hooks/rdc-output-contract-gate.js +94 -94
  76. package/hooks/require-work-item-on-commit.js +294 -294
  77. package/hooks/restart-brief.js +19 -19
  78. package/hooks/run-hidden-hook.ps1 +47 -47
  79. package/hooks/task-completed-gate.js +274 -274
  80. package/hooks/work-item-exit-gate.js +944 -944
  81. package/lib/catalog.mjs +236 -236
  82. package/lib/cloud-rewrite.mjs +155 -155
  83. package/package.json +57 -56
  84. package/rules/work-items-rpc.md +520 -520
  85. package/scaffold/templates/HISTORY.md.template +39 -39
  86. package/scaffold/templates/PUBLISH.md.template +21 -21
  87. package/scaffold/templates/brochure-studio-default.html +70 -70
  88. package/scripts/acceptance.mjs +502 -502
  89. package/scripts/fixtures/guides/bad-guide.md +15 -15
  90. package/scripts/fixtures/guides-clean/good-guide.md +16 -16
  91. package/scripts/install-rdc-skills.js +1289 -1289
  92. package/scripts/install.ps1 +202 -202
  93. package/scripts/install.sh +132 -132
  94. package/scripts/lib/assertions.mjs +287 -287
  95. package/scripts/lib/manifest-schema.mjs +754 -754
  96. package/scripts/lib/runner.mjs +465 -465
  97. package/scripts/lib/sandbox.mjs +435 -435
  98. package/scripts/prepack.mjs +32 -32
  99. package/scripts/rdc-brochure.mjs +482 -464
  100. package/scripts/rdc-design-cli.mjs +134 -134
  101. package/scripts/rebuild-mcp.mjs +107 -107
  102. package/scripts/self-test.mjs +1460 -1460
  103. package/scripts/stamp-git-sha.mjs +29 -29
  104. package/scripts/test-guide-validator.mjs +196 -196
  105. package/scripts/test-rdc-hooks.mjs +145 -145
  106. package/scripts/uninstall.ps1 +77 -77
  107. package/scripts/uninstall.sh +69 -69
  108. package/scripts/update.ps1 +43 -43
  109. package/scripts/update.sh +43 -43
  110. package/scripts/validate-place-histories.js +461 -461
  111. package/scripts/validate-publish-manifests.js +424 -424
  112. package/scripts/watch-init.mjs +100 -100
  113. package/skills/brochure/SKILL.md +107 -107
  114. package/skills/build/SKILL.md +563 -563
  115. package/skills/channel-formatter/SKILL.md +533 -533
  116. package/skills/co-develop/SKILL.md +196 -196
  117. package/skills/collab/SKILL.md +239 -239
  118. package/skills/convert/SKILL.md +140 -140
  119. package/skills/deploy/SKILL.md +541 -541
  120. package/skills/design/SKILL.md +211 -211
  121. package/skills/design/reference/ownership.md +16 -16
  122. package/skills/design/reference/rampa.md +92 -92
  123. package/skills/design/reference/studio-model.md +153 -153
  124. package/skills/edit/SKILL.md +98 -98
  125. package/skills/fixit/SKILL.md +165 -165
  126. package/skills/fs-mcp/SKILL.md +148 -148
  127. package/skills/handoff/SKILL.md +236 -200
  128. package/skills/help/SKILL.md +143 -143
  129. package/skills/housekeeping/SKILL.md +219 -160
  130. package/skills/lifeai-brochure-author/SKILL.md +340 -340
  131. package/skills/overnight/SKILL.md +251 -251
  132. package/skills/plan/SKILL.md +345 -345
  133. package/skills/preplan/SKILL.md +90 -90
  134. package/skills/prototype/SKILL.md +150 -150
  135. package/skills/rdc-brochurify/SKILL.md +245 -245
  136. package/skills/rdc-extract-verifier-rules/SKILL.md +191 -191
  137. package/skills/release/SKILL.md +140 -140
  138. package/skills/report/SKILL.md +100 -100
  139. package/skills/review/SKILL.md +152 -152
  140. package/skills/rpms-filemap/SKILL.cloud.md +111 -111
  141. package/skills/rpms-filemap/SKILL.md +111 -111
  142. package/skills/self-test/SKILL.md +132 -132
  143. package/skills/status/SKILL.md +99 -99
  144. package/skills/terminal-config/SKILL.md +62 -62
  145. package/skills/tests/MATRIX.md +54 -54
  146. package/skills/tests/README.md +47 -47
  147. package/skills/tests/rdc-brochure.test.json +34 -34
  148. package/skills/tests/rdc-build.test.json +36 -36
  149. package/skills/tests/rdc-channel-formatter.test.json +45 -45
  150. package/skills/tests/rdc-co-develop.test.json +29 -29
  151. package/skills/tests/rdc-collab.test.json +29 -29
  152. package/skills/tests/rdc-convert.test.json +35 -35
  153. package/skills/tests/rdc-deploy.test.json +30 -30
  154. package/skills/tests/rdc-design.test.json +27 -27
  155. package/skills/tests/rdc-edit.test.json +29 -29
  156. package/skills/tests/rdc-fixit.test.json +36 -36
  157. package/skills/tests/rdc-fs-mcp.test.json +36 -36
  158. package/skills/tests/rdc-handoff.test.json +28 -28
  159. package/skills/tests/rdc-help.test.json +29 -29
  160. package/skills/tests/rdc-housekeeping.test.json +32 -28
  161. package/skills/tests/rdc-lifeai-brochure-author.test.json +35 -35
  162. package/skills/tests/rdc-overnight.test.json +37 -37
  163. package/skills/tests/rdc-plan.test.json +27 -27
  164. package/skills/tests/rdc-preplan.test.json +31 -31
  165. package/skills/tests/rdc-prototype.test.json +28 -28
  166. package/skills/tests/rdc-rdc-brochurify.test.json +23 -23
  167. package/skills/tests/rdc-rdc-extract-verifier-rules.test.json +34 -34
  168. package/skills/tests/rdc-release.test.json +29 -29
  169. package/skills/tests/rdc-report.test.json +28 -28
  170. package/skills/tests/rdc-review.test.json +29 -29
  171. package/skills/tests/rdc-rpms-filemap.test.json +28 -28
  172. package/skills/tests/rdc-self-test.test.json +24 -24
  173. package/skills/tests/rdc-status.test.json +29 -29
  174. package/skills/tests/rdc-terminal-config.test.json +29 -29
  175. package/skills/tests/rdc-watch.test.json +24 -24
  176. package/skills/tests/rdc-workitems.test.json +27 -27
  177. package/skills/watch/SKILL.md +97 -97
  178. package/skills/workitems/SKILL.md +151 -151
  179. package/tests/acceptance.test.mjs +59 -59
  180. package/tests/channel-formatter.contract.test.mjs +251 -251
  181. package/tests/curl-surface.test.mjs +289 -289
  182. package/tests/harness-gates.test.mjs +325 -325
  183. package/tests/help-surface.test.mjs +61 -61
  184. package/tests/housekeeping-lessons-triage.test.mjs +49 -0
  185. package/tests/install-rdc-skills.test.mjs +49 -49
  186. package/tests/lessons-pipeline-contract.test.mjs +26 -0
  187. package/tests/manifest-contract-fields.test.mjs +78 -78
  188. package/tests/mcp.test.mjs +271 -271
  189. package/tests/rdc-brochure.test.mjs +125 -0
  190. package/tests/release-contract.test.mjs +16 -0
  191. package/tests/require-work-item-on-commit.test.mjs +162 -162
  192. package/tests/run-evidence-gate.test.mjs +82 -82
  193. package/tests/skill-test-matrix.test.mjs +66 -66
  194. package/tests/validate-skills.js +27 -27
  195. package/tests/work-item-exit-gate-l2.test.mjs +368 -368
  196. package/tests/work-item-exit-gate-l3.test.mjs +197 -197
@@ -1,424 +1,424 @@
1
- #!/usr/bin/env node
2
- /**
3
- * validate-publish-manifests.js
4
- * WP-6: PUBLISH.md convention validator for rdc-skills
5
- *
6
- * Queries app_deployments (active rows), checks PUBLISH.md presence + schema
7
- * for each registered deployable target.
8
- *
9
- * Usage:
10
- * node scripts/validate-publish-manifests.js [--mode warn|fail] [--slug <name>] [--json] [--strict]
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
-
18
- 'use strict';
19
-
20
- const fs = require('fs');
21
- const path = require('path');
22
- const https = require('https');
23
- const http = require('http');
24
-
25
- // ---------------------------------------------------------------------------
26
- // CLI argument parsing
27
- // ---------------------------------------------------------------------------
28
-
29
- const args = process.argv.slice(2);
30
- let mode = 'warn'; // warn | fail
31
- let slugFilter = null; // --slug <name>
32
- let jsonOutput = false; // --json
33
- let strict = false; // --strict (same as --mode fail)
34
-
35
- for (let i = 0; i < args.length; i++) {
36
- const a = args[i];
37
- if (a === '--mode') {
38
- const v = args[++i];
39
- if (v !== 'warn' && v !== 'fail') {
40
- console.error('ERROR: --mode must be warn or fail');
41
- process.exit(2);
42
- }
43
- mode = v;
44
- } else if (a === '--slug') {
45
- slugFilter = args[++i];
46
- if (!slugFilter) {
47
- console.error('ERROR: --slug requires a value');
48
- process.exit(2);
49
- }
50
- } else if (a === '--json') {
51
- jsonOutput = true;
52
- } else if (a === '--strict') {
53
- strict = true;
54
- mode = 'fail';
55
- } else {
56
- console.error(`ERROR: unknown argument: ${a}`);
57
- process.exit(2);
58
- }
59
- }
60
-
61
- // ---------------------------------------------------------------------------
62
- // Constants
63
- // ---------------------------------------------------------------------------
64
-
65
- const MONOREPO_ROOT = 'C:/Dev/regen-root';
66
- const CLAUTH_BASE = 'http://127.0.0.1:52437';
67
-
68
- // Ordered list of root-relative prefixes to probe when looking for app source
69
- const MONOREPO_SEARCH_DIRS = ['apps', 'sites', 'models', 'mcp-servers', 'packages'];
70
-
71
- const REQUIRED_FRONTMATTER_FIELDS = ['schema_version', 'entity_slug', 'artifact_type', 'environments', 'status'];
72
- const ALLOWED_ARTIFACT_TYPES = ['website', 'api', 'package', 'worker', 'mcp-server'];
73
- const ALLOWED_STATUSES = ['active', 'draft', 'deprecated'];
74
- const ALLOWED_ENVIRONMENTS = ['dev', 'prod'];
75
- const ALLOWED_SCHEMA_VERSIONS = ['1.0'];
76
-
77
- // Supabase project and REST base
78
- const SUPABASE_PROJECT_HOST = 'uvojezuorjgqzmhhgluu.supabase.co';
79
-
80
- // ---------------------------------------------------------------------------
81
- // Result tracking
82
- // ---------------------------------------------------------------------------
83
-
84
- const results = [];
85
- let hasHardFail = false;
86
-
87
- function emit(level, slug, message, detail) {
88
- const entry = { level, slug, message, detail: detail || null };
89
- results.push(entry);
90
- if (level === 'FAIL') hasHardFail = true;
91
- if (!jsonOutput) {
92
- const prefix = level === 'FAIL' ? '✗ FAIL' : level === 'WARN' ? '⚠ WARN' : '✓ PASS';
93
- console.log(`${prefix} [${slug}] ${message}${detail ? ` — ${detail}` : ''}`);
94
- }
95
- }
96
-
97
- // ---------------------------------------------------------------------------
98
- // HTTP helpers
99
- // ---------------------------------------------------------------------------
100
-
101
- /** Fetch plain text from clauth daemon (never prints value) */
102
- function fetchClauth(service) {
103
- return new Promise((resolve, reject) => {
104
- const req = http.get(`${CLAUTH_BASE}/v/${service}`, (res) => {
105
- let buf = '';
106
- res.on('data', (c) => (buf += c));
107
- res.on('end', () => {
108
- if (res.statusCode !== 200) {
109
- reject(new Error(`clauth /v/${service} → HTTP ${res.statusCode}`));
110
- } else {
111
- resolve(buf.trim());
112
- }
113
- });
114
- });
115
- req.on('error', reject);
116
- req.setTimeout(5000, () => { req.destroy(); reject(new Error('clauth timeout')); });
117
- });
118
- }
119
-
120
- /** REST GET against Supabase with anon key */
121
- function supabaseGet(anonKey, path) {
122
- return new Promise((resolve, reject) => {
123
- const options = {
124
- hostname: SUPABASE_PROJECT_HOST,
125
- path,
126
- method: 'GET',
127
- headers: {
128
- 'apikey': anonKey,
129
- 'Authorization': `Bearer ${anonKey}`,
130
- 'Content-Type': 'application/json',
131
- 'Accept': 'application/json',
132
- },
133
- };
134
- const req = https.request(options, (res) => {
135
- let buf = '';
136
- res.on('data', (c) => (buf += c));
137
- res.on('end', () => {
138
- if (res.statusCode !== 200) {
139
- reject(new Error(`Supabase REST ${path} → HTTP ${res.statusCode}: ${buf.slice(0, 200)}`));
140
- } else {
141
- try {
142
- resolve(JSON.parse(buf));
143
- } catch (e) {
144
- reject(new Error(`JSON parse error: ${e.message}`));
145
- }
146
- }
147
- });
148
- });
149
- req.on('error', reject);
150
- req.setTimeout(10000, () => { req.destroy(); reject(new Error('Supabase timeout')); });
151
- req.end();
152
- });
153
- }
154
-
155
- // ---------------------------------------------------------------------------
156
- // YAML frontmatter parser (minimal — no external dep required)
157
- // ---------------------------------------------------------------------------
158
-
159
- /**
160
- * Parse YAML frontmatter from a PUBLISH.md string.
161
- * Only handles scalar values, arrays on same line ([a, b, c]), and quoted strings.
162
- * Returns null if no frontmatter delimiters found.
163
- */
164
- function parseFrontmatter(content) {
165
- const fmMatch = content.match(/^---\r?\n([\s\S]*?)\r?\n---/);
166
- if (!fmMatch) return null;
167
-
168
- const yaml = fmMatch[1];
169
- const result = {};
170
-
171
- for (const line of yaml.split(/\r?\n/)) {
172
- const kv = line.match(/^([a-zA-Z_][a-zA-Z0-9_]*):\s*(.*)$/);
173
- if (!kv) continue;
174
-
175
- const key = kv[1];
176
- let value = kv[2].trim();
177
-
178
- // Array: [a, b, c] or [a] or []
179
- if (value.startsWith('[') && value.endsWith(']')) {
180
- const inner = value.slice(1, -1).trim();
181
- result[key] = inner ? inner.split(',').map((s) => s.trim().replace(/^["']|["']$/g, '')) : [];
182
- continue;
183
- }
184
-
185
- // Quoted string
186
- if ((value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'") && value.endsWith("'"))) {
187
- result[key] = value.slice(1, -1);
188
- continue;
189
- }
190
-
191
- result[key] = value;
192
- }
193
-
194
- return result;
195
- }
196
-
197
- /**
198
- * Extract surface section IDs from PUBLISH.md content.
199
- * Looks for <!-- SURFACE:<id> --> markers.
200
- */
201
- function parseSurfaceIds(content) {
202
- const ids = [];
203
- const re = /<!--\s*SURFACE:([a-zA-Z0-9_-]+)\s*-->/g;
204
- let m;
205
- while ((m = re.exec(content)) !== null) {
206
- ids.push(m[1]);
207
- }
208
- return ids;
209
- }
210
-
211
- /**
212
- * Extract watch_paths from a named surface section.
213
- * Returns array of watch_path strings (may be empty).
214
- */
215
- function parseSurfaceWatchPaths(content, surfaceId) {
216
- const re = new RegExp(`<!--\\s*SURFACE:${surfaceId}\\s*-->[\\s\\S]*?<!--\\s*/SURFACE:${surfaceId}\\s*-->`, 'i');
217
- const section = content.match(re);
218
- if (!section) return [];
219
-
220
- const block = section[0];
221
- const watchPathsMatch = block.match(/watch_paths:\s*\r?\n((?:\s+-\s+.+\r?\n?)*)/);
222
- if (!watchPathsMatch) return [];
223
-
224
- return watchPathsMatch[1]
225
- .split(/\r?\n/)
226
- .map((l) => l.replace(/^\s+-\s+/, '').trim())
227
- .filter(Boolean);
228
- }
229
-
230
- // ---------------------------------------------------------------------------
231
- // Path resolution
232
- // ---------------------------------------------------------------------------
233
-
234
- /**
235
- * Derive the local filesystem path where we'd expect PUBLISH.md for a given app_slug.
236
- * Probes MONOREPO_SEARCH_DIRS in order, returning the first hit.
237
- * Returns null if no directory found (standalone or unknown).
238
- */
239
- function resolveAppRoot(slug) {
240
- for (const dir of MONOREPO_SEARCH_DIRS) {
241
- const candidate = path.join(MONOREPO_ROOT, dir, slug);
242
- if (fs.existsSync(candidate)) return candidate;
243
- }
244
- return null;
245
- }
246
-
247
- // ---------------------------------------------------------------------------
248
- // Validation logic for a single app row
249
- // ---------------------------------------------------------------------------
250
-
251
- function validateApp(slug) {
252
- const appRoot = resolveAppRoot(slug);
253
-
254
- if (!appRoot) {
255
- // Could be standalone repo — skip with note in v1
256
- emit('WARN', slug, 'app root not found in monorepo — may be standalone repo, skipping (v1 scope)');
257
- return null;
258
- }
259
-
260
- const publishPath = path.join(appRoot, 'PUBLISH.md');
261
-
262
- if (!fs.existsSync(publishPath)) {
263
- if (mode === 'fail') {
264
- emit('FAIL', slug, 'PUBLISH.md missing', publishPath);
265
- } else {
266
- emit('WARN', slug, 'PUBLISH.md missing', publishPath);
267
- }
268
- return null;
269
- }
270
-
271
- // File exists — parse and validate
272
- const content = fs.readFileSync(publishPath, 'utf8');
273
- const fm = parseFrontmatter(content);
274
-
275
- if (!fm) {
276
- emit('FAIL', slug, 'PUBLISH.md has no YAML frontmatter (missing --- delimiters)', publishPath);
277
- return null;
278
- }
279
-
280
- let ok = true;
281
-
282
- // Check required fields
283
- for (const field of REQUIRED_FRONTMATTER_FIELDS) {
284
- if (fm[field] === undefined || fm[field] === null || fm[field] === '') {
285
- emit('FAIL', slug, `PUBLISH.md missing required field: ${field}`, publishPath);
286
- ok = false;
287
- }
288
- }
289
-
290
- // schema_version
291
- if (fm.schema_version && !ALLOWED_SCHEMA_VERSIONS.includes(fm.schema_version)) {
292
- emit('FAIL', slug, `PUBLISH.md schema_version "${fm.schema_version}" not in allowed set: ${ALLOWED_SCHEMA_VERSIONS.join(', ')}`, publishPath);
293
- ok = false;
294
- }
295
-
296
- // artifact_type
297
- if (fm.artifact_type && !ALLOWED_ARTIFACT_TYPES.includes(fm.artifact_type)) {
298
- emit('FAIL', slug, `PUBLISH.md artifact_type "${fm.artifact_type}" not in allowed set: ${ALLOWED_ARTIFACT_TYPES.join(', ')}`, publishPath);
299
- ok = false;
300
- }
301
-
302
- // status
303
- if (fm.status && !ALLOWED_STATUSES.includes(fm.status)) {
304
- emit('FAIL', slug, `PUBLISH.md status "${fm.status}" not in allowed set: ${ALLOWED_STATUSES.join(', ')}`, publishPath);
305
- ok = false;
306
- }
307
-
308
- // environments — must be array, at least one, each in allowed set
309
- if (fm.environments !== undefined) {
310
- if (!Array.isArray(fm.environments) || fm.environments.length === 0) {
311
- emit('FAIL', slug, 'PUBLISH.md environments must be a non-empty array', publishPath);
312
- ok = false;
313
- } else {
314
- for (const env of fm.environments) {
315
- if (!ALLOWED_ENVIRONMENTS.includes(env)) {
316
- emit('FAIL', slug, `PUBLISH.md environments contains unknown value: "${env}"`, publishPath);
317
- ok = false;
318
- }
319
- }
320
- }
321
- }
322
-
323
- // Surface sections — at least one required
324
- const surfaceIds = parseSurfaceIds(content);
325
- if (surfaceIds.length === 0) {
326
- emit('FAIL', slug, 'PUBLISH.md has no <!-- SURFACE:<id> --> sections', publishPath);
327
- ok = false;
328
- } else {
329
- // Each surface must have watch_paths
330
- for (const sid of surfaceIds) {
331
- const wp = parseSurfaceWatchPaths(content, sid);
332
- if (wp.length === 0) {
333
- emit('FAIL', slug, `PUBLISH.md surface "${sid}" has no watch_paths entries`, publishPath);
334
- ok = false;
335
- }
336
- }
337
- }
338
-
339
- if (ok) {
340
- emit('PASS', slug, 'PUBLISH.md valid', `${surfaceIds.length} surface(s): ${surfaceIds.join(', ')}`);
341
- }
342
-
343
- return { fm, surfaceIds, publishPath };
344
- }
345
-
346
- // ---------------------------------------------------------------------------
347
- // Main
348
- // ---------------------------------------------------------------------------
349
-
350
- async function main() {
351
- if (!jsonOutput) {
352
- console.log(`\nvalidate-publish-manifests — mode=${mode}${slugFilter ? ` slug=${slugFilter}` : ''}\n`);
353
- }
354
-
355
- // 1. Get Supabase anon key from clauth
356
- let anonKey;
357
- try {
358
- anonKey = await fetchClauth('supabase-anon');
359
- } catch (err) {
360
- console.error(`ERROR: cannot reach clauth daemon — ${err.message}`);
361
- console.error('Fix: ensure clauth daemon is running at http://127.0.0.1:52437');
362
- process.exit(1);
363
- }
364
-
365
- // 2. Query app_deployments for active rows
366
- let rows;
367
- try {
368
- let qpath = '/rest/v1/app_deployments?status=eq.active&select=app_slug,environment,url&order=app_slug.asc';
369
- if (slugFilter) {
370
- qpath += `&app_slug=eq.${encodeURIComponent(slugFilter)}`;
371
- }
372
- rows = await supabaseGet(anonKey, qpath);
373
- } catch (err) {
374
- console.error(`ERROR: Supabase query failed — ${err.message}`);
375
- process.exit(1);
376
- }
377
-
378
- if (!Array.isArray(rows) || rows.length === 0) {
379
- if (!jsonOutput) {
380
- console.log(slugFilter ? `No active app_deployments row found for slug: ${slugFilter}` : 'No active app_deployments rows found.');
381
- }
382
- process.exit(0);
383
- }
384
-
385
- // Deduplicate slugs (same app_slug may have dev + prod rows)
386
- const slugsSeen = new Set();
387
- const uniqueRows = rows.filter((r) => {
388
- if (slugsSeen.has(r.app_slug)) return false;
389
- slugsSeen.add(r.app_slug);
390
- return true;
391
- });
392
-
393
- if (!jsonOutput) {
394
- console.log(`Checking ${uniqueRows.length} unique app slug(s) from ${rows.length} active app_deployments row(s)...\n`);
395
- }
396
-
397
- // 3. Validate each slug
398
- for (const row of uniqueRows) {
399
- validateApp(row.app_slug);
400
- }
401
-
402
- // 4. Summary
403
- const passCount = results.filter((r) => r.level === 'PASS').length;
404
- const warnCount = results.filter((r) => r.level === 'WARN').length;
405
- const failCount = results.filter((r) => r.level === 'FAIL').length;
406
-
407
- if (jsonOutput) {
408
- console.log(JSON.stringify({ mode, results, summary: { pass: passCount, warn: warnCount, fail: failCount } }, null, 2));
409
- } else {
410
- console.log(`\nSummary: ${passCount} PASS · ${warnCount} WARN · ${failCount} FAIL`);
411
- if (hasHardFail) {
412
- console.log('Result: FAIL\n');
413
- } else {
414
- console.log(warnCount > 0 ? 'Result: WARN (exit 0 in warn mode)\n' : 'Result: PASS\n');
415
- }
416
- }
417
-
418
- process.exit(hasHardFail ? 1 : 0);
419
- }
420
-
421
- main().catch((err) => {
422
- console.error(`FATAL: ${err.message}`);
423
- process.exit(1);
424
- });
1
+ #!/usr/bin/env node
2
+ /**
3
+ * validate-publish-manifests.js
4
+ * WP-6: PUBLISH.md convention validator for rdc-skills
5
+ *
6
+ * Queries app_deployments (active rows), checks PUBLISH.md presence + schema
7
+ * for each registered deployable target.
8
+ *
9
+ * Usage:
10
+ * node scripts/validate-publish-manifests.js [--mode warn|fail] [--slug <name>] [--json] [--strict]
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
+
18
+ 'use strict';
19
+
20
+ const fs = require('fs');
21
+ const path = require('path');
22
+ const https = require('https');
23
+ const http = require('http');
24
+
25
+ // ---------------------------------------------------------------------------
26
+ // CLI argument parsing
27
+ // ---------------------------------------------------------------------------
28
+
29
+ const args = process.argv.slice(2);
30
+ let mode = 'warn'; // warn | fail
31
+ let slugFilter = null; // --slug <name>
32
+ let jsonOutput = false; // --json
33
+ let strict = false; // --strict (same as --mode fail)
34
+
35
+ for (let i = 0; i < args.length; i++) {
36
+ const a = args[i];
37
+ if (a === '--mode') {
38
+ const v = args[++i];
39
+ if (v !== 'warn' && v !== 'fail') {
40
+ console.error('ERROR: --mode must be warn or fail');
41
+ process.exit(2);
42
+ }
43
+ mode = v;
44
+ } else if (a === '--slug') {
45
+ slugFilter = args[++i];
46
+ if (!slugFilter) {
47
+ console.error('ERROR: --slug requires a value');
48
+ process.exit(2);
49
+ }
50
+ } else if (a === '--json') {
51
+ jsonOutput = true;
52
+ } else if (a === '--strict') {
53
+ strict = true;
54
+ mode = 'fail';
55
+ } else {
56
+ console.error(`ERROR: unknown argument: ${a}`);
57
+ process.exit(2);
58
+ }
59
+ }
60
+
61
+ // ---------------------------------------------------------------------------
62
+ // Constants
63
+ // ---------------------------------------------------------------------------
64
+
65
+ const MONOREPO_ROOT = 'C:/Dev/regen-root';
66
+ const CLAUTH_BASE = 'http://127.0.0.1:52437';
67
+
68
+ // Ordered list of root-relative prefixes to probe when looking for app source
69
+ const MONOREPO_SEARCH_DIRS = ['apps', 'sites', 'models', 'mcp-servers', 'packages'];
70
+
71
+ const REQUIRED_FRONTMATTER_FIELDS = ['schema_version', 'entity_slug', 'artifact_type', 'environments', 'status'];
72
+ const ALLOWED_ARTIFACT_TYPES = ['website', 'api', 'package', 'worker', 'mcp-server'];
73
+ const ALLOWED_STATUSES = ['active', 'draft', 'deprecated'];
74
+ const ALLOWED_ENVIRONMENTS = ['dev', 'prod'];
75
+ const ALLOWED_SCHEMA_VERSIONS = ['1.0'];
76
+
77
+ // Supabase project and REST base
78
+ const SUPABASE_PROJECT_HOST = 'uvojezuorjgqzmhhgluu.supabase.co';
79
+
80
+ // ---------------------------------------------------------------------------
81
+ // Result tracking
82
+ // ---------------------------------------------------------------------------
83
+
84
+ const results = [];
85
+ let hasHardFail = false;
86
+
87
+ function emit(level, slug, message, detail) {
88
+ const entry = { level, slug, message, detail: detail || null };
89
+ results.push(entry);
90
+ if (level === 'FAIL') hasHardFail = true;
91
+ if (!jsonOutput) {
92
+ const prefix = level === 'FAIL' ? '✗ FAIL' : level === 'WARN' ? '⚠ WARN' : '✓ PASS';
93
+ console.log(`${prefix} [${slug}] ${message}${detail ? ` — ${detail}` : ''}`);
94
+ }
95
+ }
96
+
97
+ // ---------------------------------------------------------------------------
98
+ // HTTP helpers
99
+ // ---------------------------------------------------------------------------
100
+
101
+ /** Fetch plain text from clauth daemon (never prints value) */
102
+ function fetchClauth(service) {
103
+ return new Promise((resolve, reject) => {
104
+ const req = http.get(`${CLAUTH_BASE}/v/${service}`, (res) => {
105
+ let buf = '';
106
+ res.on('data', (c) => (buf += c));
107
+ res.on('end', () => {
108
+ if (res.statusCode !== 200) {
109
+ reject(new Error(`clauth /v/${service} → HTTP ${res.statusCode}`));
110
+ } else {
111
+ resolve(buf.trim());
112
+ }
113
+ });
114
+ });
115
+ req.on('error', reject);
116
+ req.setTimeout(5000, () => { req.destroy(); reject(new Error('clauth timeout')); });
117
+ });
118
+ }
119
+
120
+ /** REST GET against Supabase with anon key */
121
+ function supabaseGet(anonKey, path) {
122
+ return new Promise((resolve, reject) => {
123
+ const options = {
124
+ hostname: SUPABASE_PROJECT_HOST,
125
+ path,
126
+ method: 'GET',
127
+ headers: {
128
+ 'apikey': anonKey,
129
+ 'Authorization': `Bearer ${anonKey}`,
130
+ 'Content-Type': 'application/json',
131
+ 'Accept': 'application/json',
132
+ },
133
+ };
134
+ const req = https.request(options, (res) => {
135
+ let buf = '';
136
+ res.on('data', (c) => (buf += c));
137
+ res.on('end', () => {
138
+ if (res.statusCode !== 200) {
139
+ reject(new Error(`Supabase REST ${path} → HTTP ${res.statusCode}: ${buf.slice(0, 200)}`));
140
+ } else {
141
+ try {
142
+ resolve(JSON.parse(buf));
143
+ } catch (e) {
144
+ reject(new Error(`JSON parse error: ${e.message}`));
145
+ }
146
+ }
147
+ });
148
+ });
149
+ req.on('error', reject);
150
+ req.setTimeout(10000, () => { req.destroy(); reject(new Error('Supabase timeout')); });
151
+ req.end();
152
+ });
153
+ }
154
+
155
+ // ---------------------------------------------------------------------------
156
+ // YAML frontmatter parser (minimal — no external dep required)
157
+ // ---------------------------------------------------------------------------
158
+
159
+ /**
160
+ * Parse YAML frontmatter from a PUBLISH.md string.
161
+ * Only handles scalar values, arrays on same line ([a, b, c]), and quoted strings.
162
+ * Returns null if no frontmatter delimiters found.
163
+ */
164
+ function parseFrontmatter(content) {
165
+ const fmMatch = content.match(/^---\r?\n([\s\S]*?)\r?\n---/);
166
+ if (!fmMatch) return null;
167
+
168
+ const yaml = fmMatch[1];
169
+ const result = {};
170
+
171
+ for (const line of yaml.split(/\r?\n/)) {
172
+ const kv = line.match(/^([a-zA-Z_][a-zA-Z0-9_]*):\s*(.*)$/);
173
+ if (!kv) continue;
174
+
175
+ const key = kv[1];
176
+ let value = kv[2].trim();
177
+
178
+ // Array: [a, b, c] or [a] or []
179
+ if (value.startsWith('[') && value.endsWith(']')) {
180
+ const inner = value.slice(1, -1).trim();
181
+ result[key] = inner ? inner.split(',').map((s) => s.trim().replace(/^["']|["']$/g, '')) : [];
182
+ continue;
183
+ }
184
+
185
+ // Quoted string
186
+ if ((value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'") && value.endsWith("'"))) {
187
+ result[key] = value.slice(1, -1);
188
+ continue;
189
+ }
190
+
191
+ result[key] = value;
192
+ }
193
+
194
+ return result;
195
+ }
196
+
197
+ /**
198
+ * Extract surface section IDs from PUBLISH.md content.
199
+ * Looks for <!-- SURFACE:<id> --> markers.
200
+ */
201
+ function parseSurfaceIds(content) {
202
+ const ids = [];
203
+ const re = /<!--\s*SURFACE:([a-zA-Z0-9_-]+)\s*-->/g;
204
+ let m;
205
+ while ((m = re.exec(content)) !== null) {
206
+ ids.push(m[1]);
207
+ }
208
+ return ids;
209
+ }
210
+
211
+ /**
212
+ * Extract watch_paths from a named surface section.
213
+ * Returns array of watch_path strings (may be empty).
214
+ */
215
+ function parseSurfaceWatchPaths(content, surfaceId) {
216
+ const re = new RegExp(`<!--\\s*SURFACE:${surfaceId}\\s*-->[\\s\\S]*?<!--\\s*/SURFACE:${surfaceId}\\s*-->`, 'i');
217
+ const section = content.match(re);
218
+ if (!section) return [];
219
+
220
+ const block = section[0];
221
+ const watchPathsMatch = block.match(/watch_paths:\s*\r?\n((?:\s+-\s+.+\r?\n?)*)/);
222
+ if (!watchPathsMatch) return [];
223
+
224
+ return watchPathsMatch[1]
225
+ .split(/\r?\n/)
226
+ .map((l) => l.replace(/^\s+-\s+/, '').trim())
227
+ .filter(Boolean);
228
+ }
229
+
230
+ // ---------------------------------------------------------------------------
231
+ // Path resolution
232
+ // ---------------------------------------------------------------------------
233
+
234
+ /**
235
+ * Derive the local filesystem path where we'd expect PUBLISH.md for a given app_slug.
236
+ * Probes MONOREPO_SEARCH_DIRS in order, returning the first hit.
237
+ * Returns null if no directory found (standalone or unknown).
238
+ */
239
+ function resolveAppRoot(slug) {
240
+ for (const dir of MONOREPO_SEARCH_DIRS) {
241
+ const candidate = path.join(MONOREPO_ROOT, dir, slug);
242
+ if (fs.existsSync(candidate)) return candidate;
243
+ }
244
+ return null;
245
+ }
246
+
247
+ // ---------------------------------------------------------------------------
248
+ // Validation logic for a single app row
249
+ // ---------------------------------------------------------------------------
250
+
251
+ function validateApp(slug) {
252
+ const appRoot = resolveAppRoot(slug);
253
+
254
+ if (!appRoot) {
255
+ // Could be standalone repo — skip with note in v1
256
+ emit('WARN', slug, 'app root not found in monorepo — may be standalone repo, skipping (v1 scope)');
257
+ return null;
258
+ }
259
+
260
+ const publishPath = path.join(appRoot, 'PUBLISH.md');
261
+
262
+ if (!fs.existsSync(publishPath)) {
263
+ if (mode === 'fail') {
264
+ emit('FAIL', slug, 'PUBLISH.md missing', publishPath);
265
+ } else {
266
+ emit('WARN', slug, 'PUBLISH.md missing', publishPath);
267
+ }
268
+ return null;
269
+ }
270
+
271
+ // File exists — parse and validate
272
+ const content = fs.readFileSync(publishPath, 'utf8');
273
+ const fm = parseFrontmatter(content);
274
+
275
+ if (!fm) {
276
+ emit('FAIL', slug, 'PUBLISH.md has no YAML frontmatter (missing --- delimiters)', publishPath);
277
+ return null;
278
+ }
279
+
280
+ let ok = true;
281
+
282
+ // Check required fields
283
+ for (const field of REQUIRED_FRONTMATTER_FIELDS) {
284
+ if (fm[field] === undefined || fm[field] === null || fm[field] === '') {
285
+ emit('FAIL', slug, `PUBLISH.md missing required field: ${field}`, publishPath);
286
+ ok = false;
287
+ }
288
+ }
289
+
290
+ // schema_version
291
+ if (fm.schema_version && !ALLOWED_SCHEMA_VERSIONS.includes(fm.schema_version)) {
292
+ emit('FAIL', slug, `PUBLISH.md schema_version "${fm.schema_version}" not in allowed set: ${ALLOWED_SCHEMA_VERSIONS.join(', ')}`, publishPath);
293
+ ok = false;
294
+ }
295
+
296
+ // artifact_type
297
+ if (fm.artifact_type && !ALLOWED_ARTIFACT_TYPES.includes(fm.artifact_type)) {
298
+ emit('FAIL', slug, `PUBLISH.md artifact_type "${fm.artifact_type}" not in allowed set: ${ALLOWED_ARTIFACT_TYPES.join(', ')}`, publishPath);
299
+ ok = false;
300
+ }
301
+
302
+ // status
303
+ if (fm.status && !ALLOWED_STATUSES.includes(fm.status)) {
304
+ emit('FAIL', slug, `PUBLISH.md status "${fm.status}" not in allowed set: ${ALLOWED_STATUSES.join(', ')}`, publishPath);
305
+ ok = false;
306
+ }
307
+
308
+ // environments — must be array, at least one, each in allowed set
309
+ if (fm.environments !== undefined) {
310
+ if (!Array.isArray(fm.environments) || fm.environments.length === 0) {
311
+ emit('FAIL', slug, 'PUBLISH.md environments must be a non-empty array', publishPath);
312
+ ok = false;
313
+ } else {
314
+ for (const env of fm.environments) {
315
+ if (!ALLOWED_ENVIRONMENTS.includes(env)) {
316
+ emit('FAIL', slug, `PUBLISH.md environments contains unknown value: "${env}"`, publishPath);
317
+ ok = false;
318
+ }
319
+ }
320
+ }
321
+ }
322
+
323
+ // Surface sections — at least one required
324
+ const surfaceIds = parseSurfaceIds(content);
325
+ if (surfaceIds.length === 0) {
326
+ emit('FAIL', slug, 'PUBLISH.md has no <!-- SURFACE:<id> --> sections', publishPath);
327
+ ok = false;
328
+ } else {
329
+ // Each surface must have watch_paths
330
+ for (const sid of surfaceIds) {
331
+ const wp = parseSurfaceWatchPaths(content, sid);
332
+ if (wp.length === 0) {
333
+ emit('FAIL', slug, `PUBLISH.md surface "${sid}" has no watch_paths entries`, publishPath);
334
+ ok = false;
335
+ }
336
+ }
337
+ }
338
+
339
+ if (ok) {
340
+ emit('PASS', slug, 'PUBLISH.md valid', `${surfaceIds.length} surface(s): ${surfaceIds.join(', ')}`);
341
+ }
342
+
343
+ return { fm, surfaceIds, publishPath };
344
+ }
345
+
346
+ // ---------------------------------------------------------------------------
347
+ // Main
348
+ // ---------------------------------------------------------------------------
349
+
350
+ async function main() {
351
+ if (!jsonOutput) {
352
+ console.log(`\nvalidate-publish-manifests — mode=${mode}${slugFilter ? ` slug=${slugFilter}` : ''}\n`);
353
+ }
354
+
355
+ // 1. Get Supabase anon key from clauth
356
+ let anonKey;
357
+ try {
358
+ anonKey = await fetchClauth('supabase-anon');
359
+ } catch (err) {
360
+ console.error(`ERROR: cannot reach clauth daemon — ${err.message}`);
361
+ console.error('Fix: ensure clauth daemon is running at http://127.0.0.1:52437');
362
+ process.exit(1);
363
+ }
364
+
365
+ // 2. Query app_deployments for active rows
366
+ let rows;
367
+ try {
368
+ let qpath = '/rest/v1/app_deployments?status=eq.active&select=app_slug,environment,url&order=app_slug.asc';
369
+ if (slugFilter) {
370
+ qpath += `&app_slug=eq.${encodeURIComponent(slugFilter)}`;
371
+ }
372
+ rows = await supabaseGet(anonKey, qpath);
373
+ } catch (err) {
374
+ console.error(`ERROR: Supabase query failed — ${err.message}`);
375
+ process.exit(1);
376
+ }
377
+
378
+ if (!Array.isArray(rows) || rows.length === 0) {
379
+ if (!jsonOutput) {
380
+ console.log(slugFilter ? `No active app_deployments row found for slug: ${slugFilter}` : 'No active app_deployments rows found.');
381
+ }
382
+ process.exit(0);
383
+ }
384
+
385
+ // Deduplicate slugs (same app_slug may have dev + prod rows)
386
+ const slugsSeen = new Set();
387
+ const uniqueRows = rows.filter((r) => {
388
+ if (slugsSeen.has(r.app_slug)) return false;
389
+ slugsSeen.add(r.app_slug);
390
+ return true;
391
+ });
392
+
393
+ if (!jsonOutput) {
394
+ console.log(`Checking ${uniqueRows.length} unique app slug(s) from ${rows.length} active app_deployments row(s)...\n`);
395
+ }
396
+
397
+ // 3. Validate each slug
398
+ for (const row of uniqueRows) {
399
+ validateApp(row.app_slug);
400
+ }
401
+
402
+ // 4. Summary
403
+ const passCount = results.filter((r) => r.level === 'PASS').length;
404
+ const warnCount = results.filter((r) => r.level === 'WARN').length;
405
+ const failCount = results.filter((r) => r.level === 'FAIL').length;
406
+
407
+ if (jsonOutput) {
408
+ console.log(JSON.stringify({ mode, results, summary: { pass: passCount, warn: warnCount, fail: failCount } }, null, 2));
409
+ } else {
410
+ console.log(`\nSummary: ${passCount} PASS · ${warnCount} WARN · ${failCount} FAIL`);
411
+ if (hasHardFail) {
412
+ console.log('Result: FAIL\n');
413
+ } else {
414
+ console.log(warnCount > 0 ? 'Result: WARN (exit 0 in warn mode)\n' : 'Result: PASS\n');
415
+ }
416
+ }
417
+
418
+ process.exit(hasHardFail ? 1 : 0);
419
+ }
420
+
421
+ main().catch((err) => {
422
+ console.error(`FATAL: ${err.message}`);
423
+ process.exit(1);
424
+ });