@lifeaitools/rdc-skills 0.8.7

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 (97) hide show
  1. package/.claude/settings.json +15 -0
  2. package/.claude-plugin/marketplace.json +21 -0
  3. package/.claude-plugin/plugin.json +11 -0
  4. package/.github/workflows/publish.yml +25 -0
  5. package/.github/workflows/self-test.yml +53 -0
  6. package/CHANGELOG.md +246 -0
  7. package/LICENSE +21 -0
  8. package/MANIFEST.md +190 -0
  9. package/README.md +188 -0
  10. package/README.sandbox.md +3 -0
  11. package/assets/watcher/viewer.html +164 -0
  12. package/commands/build.md +183 -0
  13. package/commands/collab.md +180 -0
  14. package/commands/deploy.md +138 -0
  15. package/commands/fixit.md +112 -0
  16. package/commands/handoff.md +173 -0
  17. package/commands/help.md +88 -0
  18. package/commands/overnight.md +220 -0
  19. package/commands/plan.md +158 -0
  20. package/commands/preplan.md +131 -0
  21. package/commands/prototype.md +145 -0
  22. package/commands/release.md +159 -0
  23. package/commands/report.md +99 -0
  24. package/commands/review.md +120 -0
  25. package/commands/self-test.md +107 -0
  26. package/commands/status.md +86 -0
  27. package/commands/watch.md +92 -0
  28. package/commands/workitems.md +132 -0
  29. package/guides/.gitkeep +0 -0
  30. package/guides/agent-bootstrap.md +191 -0
  31. package/guides/agents/backend.md +104 -0
  32. package/guides/agents/content.md +94 -0
  33. package/guides/agents/cs2.md +56 -0
  34. package/guides/agents/data.md +87 -0
  35. package/guides/agents/design.md +77 -0
  36. package/guides/agents/frontend.md +92 -0
  37. package/guides/agents/infrastructure.md +81 -0
  38. package/guides/agents/setup.md +279 -0
  39. package/guides/agents/verify.md +132 -0
  40. package/guides/agents/viz.md +106 -0
  41. package/guides/backend.md +146 -0
  42. package/guides/content.md +147 -0
  43. package/guides/cs2.md +190 -0
  44. package/guides/data.md +123 -0
  45. package/guides/design.md +116 -0
  46. package/guides/frontend.md +151 -0
  47. package/guides/infrastructure.md +179 -0
  48. package/guides/output-contract.md +98 -0
  49. package/hooks/no-stop-open-epics.js +125 -0
  50. package/package.json +31 -0
  51. package/rules/work-items-rpc.md +399 -0
  52. package/scripts/install-rdc-skills.js +559 -0
  53. package/scripts/install.ps1 +165 -0
  54. package/scripts/install.sh +132 -0
  55. package/scripts/lib/assertions.mjs +264 -0
  56. package/scripts/lib/manifest-schema.mjs +607 -0
  57. package/scripts/lib/runner.mjs +429 -0
  58. package/scripts/lib/sandbox.mjs +435 -0
  59. package/scripts/self-test.mjs +1108 -0
  60. package/scripts/uninstall.ps1 +77 -0
  61. package/scripts/uninstall.sh +69 -0
  62. package/scripts/update.ps1 +43 -0
  63. package/scripts/update.sh +43 -0
  64. package/scripts/watch-init.mjs +100 -0
  65. package/skills/.gitkeep +0 -0
  66. package/skills/build/SKILL.md +238 -0
  67. package/skills/collab/SKILL.md +218 -0
  68. package/skills/deploy/SKILL.md +144 -0
  69. package/skills/fixit/SKILL.md +112 -0
  70. package/skills/handoff/SKILL.md +175 -0
  71. package/skills/help/SKILL.md +101 -0
  72. package/skills/overnight/SKILL.md +220 -0
  73. package/skills/plan/SKILL.md +96 -0
  74. package/skills/preplan/SKILL.md +87 -0
  75. package/skills/prototype/SKILL.md +151 -0
  76. package/skills/release/SKILL.md +221 -0
  77. package/skills/report/SKILL.md +101 -0
  78. package/skills/review/SKILL.md +120 -0
  79. package/skills/self-test/SKILL.md +127 -0
  80. package/skills/status/SKILL.md +86 -0
  81. package/skills/tests/README.md +29 -0
  82. package/skills/tests/rdc-build.test.json +22 -0
  83. package/skills/tests/rdc-deploy.test.json +15 -0
  84. package/skills/tests/rdc-fixit.test.json +21 -0
  85. package/skills/tests/rdc-handoff.test.json +14 -0
  86. package/skills/tests/rdc-overnight.test.json +21 -0
  87. package/skills/tests/rdc-plan.test.json +14 -0
  88. package/skills/tests/rdc-preplan.test.json +15 -0
  89. package/skills/tests/rdc-prototype.test.json +14 -0
  90. package/skills/tests/rdc-release.test.json +15 -0
  91. package/skills/tests/rdc-report.test.json +14 -0
  92. package/skills/tests/rdc-review.test.json +14 -0
  93. package/skills/tests/rdc-status.test.json +16 -0
  94. package/skills/tests/rdc-workitems.test.json +15 -0
  95. package/skills/watch/SKILL.md +92 -0
  96. package/skills/workitems/SKILL.md +147 -0
  97. package/tests/validate-skills.js +183 -0
@@ -0,0 +1,429 @@
1
+ // runner.mjs — Tier 2 per-skill test orchestration.
2
+ //
3
+ // Public API:
4
+ // runManifest(manifest, { runId, supabaseBranchRef?, timeout?, claudeBin? })
5
+ // → { skill, pass, duration_ms, observed?, failures?, error? }
6
+ //
7
+ // Flow per manifest:
8
+ // 1. Create a worktree at .rdc-sandbox/<runId>/<skill-slug>/
9
+ // 2. Write precondition_files into the worktree
10
+ // 3. Snapshot HEAD sha + work_items rowcount (via Supabase branch if given)
11
+ // 4. Spawn `claude --print "<prompt>" --output-format stream-json`
12
+ // - cwd = worktree
13
+ // - env = { ...process.env, ...fixture.env, RDC_TEST: "1" }
14
+ // - timeout kills the child on overrun
15
+ // 5. Compute observed delta: commits since snapshot, files changed, work_items delta
16
+ // 6. Call evaluateAssertions
17
+ // 7. Return structured result — never throws (caller-friendly).
18
+ //
19
+ // Cleanup is the caller's responsibility (runner does NOT remove the worktree,
20
+ // so the caller can inspect on failure before teardown).
21
+
22
+ import { spawn, execFileSync } from "node:child_process";
23
+ import { writeFileSync, mkdirSync, existsSync } from "node:fs";
24
+ import { join, dirname, resolve } from "node:path";
25
+ import { fileURLToPath } from "node:url";
26
+ import { createWorktree } from "./sandbox.mjs";
27
+ import { evaluateAssertions } from "./assertions.mjs";
28
+
29
+ const DEFAULT_TIMEOUT_MS = 240_000;
30
+
31
+ function nowMs() {
32
+ return Date.now();
33
+ }
34
+
35
+ /** Run a git command inside `cwd`, return trimmed stdout or "". Never throws. */
36
+ function gitIn(cwd, args) {
37
+ try {
38
+ return execFileSync("git", args, {
39
+ cwd,
40
+ encoding: "utf8",
41
+ stdio: ["ignore", "pipe", "pipe"],
42
+ }).trim();
43
+ } catch {
44
+ return "";
45
+ }
46
+ }
47
+
48
+ function snapshotHead(cwd) {
49
+ return gitIn(cwd, ["rev-parse", "HEAD"]);
50
+ }
51
+
52
+ function commitsSince(cwd, baseSha) {
53
+ if (!baseSha) return [];
54
+ const out = gitIn(cwd, ["log", `${baseSha}..HEAD`, "--pretty=format:%H%x1f%s%x1f%b%x1e"]);
55
+ if (!out) return [];
56
+ return out
57
+ .split("\x1e")
58
+ .map((s) => s.trim())
59
+ .filter(Boolean)
60
+ .map((entry) => {
61
+ const [sha, subject, body] = entry.split("\x1f");
62
+ return { sha: sha || "", subject: subject || "", body: body || "" };
63
+ });
64
+ }
65
+
66
+ function filesModifiedSince(cwd, baseSha) {
67
+ if (!baseSha) return [];
68
+ const tracked = gitIn(cwd, ["diff", "--name-only", `${baseSha}..HEAD`]);
69
+ const untracked = gitIn(cwd, ["ls-files", "--others", "--exclude-standard"]);
70
+ const set = new Set();
71
+ for (const line of (tracked + "\n" + untracked).split(/\r?\n/)) {
72
+ const p = line.trim();
73
+ if (p) set.add(p.replace(/\\/g, "/"));
74
+ }
75
+ return [...set];
76
+ }
77
+
78
+ function writePreconditionFiles(worktreePath, files) {
79
+ if (!Array.isArray(files)) return;
80
+ for (const pf of files) {
81
+ if (!pf || typeof pf.path !== "string") continue;
82
+ const abs = join(worktreePath, pf.path);
83
+ mkdirSync(dirname(abs), { recursive: true });
84
+ writeFileSync(abs, typeof pf.content === "string" ? pf.content : "");
85
+ }
86
+ }
87
+
88
+ /** Spawn `claude --print ...` with a hard timeout. Resolves to {exit, stdout, stderr, timedOut}. */
89
+ function spawnClaude({ claudeBin, prompt, cwd, env, timeoutMs }) {
90
+ return new Promise((resolve) => {
91
+ let settled = false;
92
+ let stdout = "";
93
+ let stderr = "";
94
+ let child;
95
+ try {
96
+ // shell: true is required on Windows so `.cmd`/`.bat` shims (npm global
97
+ // wrappers like `claude`) resolve. On Unix shell: true routes through sh,
98
+ // which is harmless here. Because the shell interprets args, we wrap the
99
+ // prompt with JSON.stringify so spaces/quotes/metacharacters in the
100
+ // fixture prompt become a single shell-quoted token.
101
+ const safePrompt = JSON.stringify(prompt ?? "");
102
+ child = spawn(
103
+ claudeBin,
104
+ ["--print", safePrompt, "--output-format", "stream-json", "--verbose", "--dangerously-skip-permissions"],
105
+ { cwd, env, shell: true, windowsHide: true, stdio: ["ignore", "pipe", "pipe"] },
106
+ );
107
+ } catch (e) {
108
+ resolve({ exit: -1, stdout: "", stderr: `spawn failed: ${e.message}`, timedOut: false });
109
+ return;
110
+ }
111
+ const timer = setTimeout(() => {
112
+ if (settled) return;
113
+ try { child.kill("SIGKILL"); } catch {}
114
+ settled = true;
115
+ resolve({ exit: -1, stdout, stderr, timedOut: true });
116
+ }, timeoutMs);
117
+ child.stdout.on("data", (d) => { stdout += d.toString(); });
118
+ child.stderr.on("data", (d) => { stderr += d.toString(); });
119
+ child.on("error", (e) => {
120
+ if (settled) return;
121
+ clearTimeout(timer);
122
+ settled = true;
123
+ resolve({ exit: -1, stdout, stderr: stderr + `\nspawn error: ${e.message}`, timedOut: false });
124
+ });
125
+ child.on("close", (code) => {
126
+ if (settled) return;
127
+ clearTimeout(timer);
128
+ settled = true;
129
+ resolve({ exit: code == null ? -1 : code, stdout, stderr, timedOut: false });
130
+ });
131
+ });
132
+ }
133
+
134
+ // ─── work_items fetch (live) ────────────────────────────────────────────────
135
+ //
136
+ // These helpers talk to the Supabase PostgREST endpoint on the branch created
137
+ // by sandbox.createSupabaseTestBranch. They never throw — on any error (missing
138
+ // creds, network, bad response) they log a one-line warning and return a safe
139
+ // empty value so the runner degrades gracefully in environments without a
140
+ // live branch.
141
+ //
142
+ // supabaseBranchRef shape: { branchId, connectionString, apiUrl, anonKey }
143
+
144
+ /** Parse a PostgREST Content-Range header like "0-0/42" → 42. "*\/0" → 0. */
145
+ export function parseContentRange(header) {
146
+ if (typeof header !== "string" || header.length === 0) return 0;
147
+ const m = header.match(/\/(\d+|\*)\s*$/);
148
+ if (!m) return 0;
149
+ if (m[1] === "*") return 0;
150
+ const n = parseInt(m[1], 10);
151
+ return Number.isFinite(n) ? n : 0;
152
+ }
153
+
154
+ function hasBranchCreds(ref) {
155
+ return !!(ref && typeof ref === "object" && ref.apiUrl && ref.anonKey);
156
+ }
157
+
158
+ export async function fetchWorkItemsCount(supabaseBranchRef) {
159
+ if (!hasBranchCreds(supabaseBranchRef)) {
160
+ if (supabaseBranchRef) {
161
+ console.error(
162
+ "fetchWorkItemsCount: supabaseBranchRef missing apiUrl/anonKey — returning 0",
163
+ );
164
+ }
165
+ return 0;
166
+ }
167
+ const { apiUrl, anonKey } = supabaseBranchRef;
168
+ try {
169
+ const res = await fetch(`${apiUrl}/rest/v1/work_items?select=id`, {
170
+ headers: {
171
+ apikey: anonKey,
172
+ Authorization: `Bearer ${anonKey}`,
173
+ Prefer: "count=exact",
174
+ Range: "0-0",
175
+ "Range-Unit": "items",
176
+ },
177
+ });
178
+ if (!res.ok && res.status !== 206) {
179
+ console.error(
180
+ `fetchWorkItemsCount: HTTP ${res.status}: ${(await res.text()).slice(0, 200)}`,
181
+ );
182
+ return 0;
183
+ }
184
+ const cr = res.headers.get("content-range") || res.headers.get("Content-Range");
185
+ return parseContentRange(cr || "");
186
+ } catch (e) {
187
+ console.error(`fetchWorkItemsCount: ${e.message}`);
188
+ return 0;
189
+ }
190
+ }
191
+
192
+ /**
193
+ * Fetch metadata for the N newest work_items created since the snapshot.
194
+ * Returns an array of { id, status, labels } (matching the shape consumed by
195
+ * assertions.checkWorkItemsCreated). Never throws.
196
+ */
197
+ export async function fetchWorkItemsDelta(supabaseBranchRef, snapshotCount) {
198
+ if (!hasBranchCreds(supabaseBranchRef)) return [];
199
+ const currentCount = await fetchWorkItemsCount(supabaseBranchRef);
200
+ const delta = currentCount - (Number(snapshotCount) || 0);
201
+ if (delta <= 0) return [];
202
+
203
+ const { apiUrl, anonKey } = supabaseBranchRef;
204
+ try {
205
+ const url =
206
+ `${apiUrl}/rest/v1/work_items` +
207
+ `?select=id,status,labels&order=created_at.desc&limit=${delta}`;
208
+ const res = await fetch(url, {
209
+ headers: {
210
+ apikey: anonKey,
211
+ Authorization: `Bearer ${anonKey}`,
212
+ },
213
+ });
214
+ if (!res.ok) {
215
+ console.error(
216
+ `fetchWorkItemsDelta: HTTP ${res.status}: ${(await res.text()).slice(0, 200)}`,
217
+ );
218
+ return [];
219
+ }
220
+ const body = await res.json();
221
+ if (!Array.isArray(body)) return [];
222
+ return body.map((wi) => ({
223
+ id: wi?.id,
224
+ status: wi?.status,
225
+ labels: Array.isArray(wi?.labels) ? wi.labels : [],
226
+ }));
227
+ } catch (e) {
228
+ console.error(`fetchWorkItemsDelta: ${e.message}`);
229
+ return [];
230
+ }
231
+ }
232
+
233
+ export async function runManifest(manifest, opts = {}) {
234
+ const started = nowMs();
235
+ const skill = manifest?.skill || "<unknown>";
236
+ const {
237
+ runId,
238
+ supabaseBranchRef = null,
239
+ timeout = manifest?.timeout_ms || DEFAULT_TIMEOUT_MS,
240
+ claudeBin = process.env.CLAUDE_BIN || "claude",
241
+ // projectCwd: the repo claude --print will commit to (regen-root).
242
+ // Worktrees are created FROM this repo so git state tracking is correct.
243
+ // claude runs inside the worktree (not projectCwd directly) so each skill
244
+ // gets an isolated branch and commits don't pollute the working tree.
245
+ projectCwd = process.env.REGEN_ROOT || process.cwd(),
246
+ } = opts;
247
+
248
+ if (!runId) {
249
+ return { skill, pass: false, duration_ms: 0, error: "runManifest: runId is required" };
250
+ }
251
+
252
+ // Create worktree FROM projectCwd (regen-root), not from rdc-skills.
253
+ // This ensures commits made by claude land in the worktree branch and
254
+ // are visible to commitsSince() / filesModifiedSince().
255
+ let worktree;
256
+ try {
257
+ worktree = createWorktree(runId, skill, projectCwd);
258
+ } catch (e) {
259
+ return { skill, pass: false, duration_ms: nowMs() - started, error: `worktree: ${e.message}` };
260
+ }
261
+
262
+ // Write precondition files into the worktree (isolated copy of projectCwd).
263
+ try {
264
+ writePreconditionFiles(worktree.path, manifest.fixture?.precondition_files);
265
+ } catch (e) {
266
+ return { skill, pass: false, duration_ms: nowMs() - started, error: `precondition_files: ${e.message}` };
267
+ }
268
+
269
+ // Commit precondition files so HEAD snapshot is stable before claude runs.
270
+ try {
271
+ gitIn(worktree.path, ["add", "-A"]);
272
+ const status = gitIn(worktree.path, ["status", "--porcelain"]);
273
+ if (status) {
274
+ execFileSync("git", ["-c", "user.email=test@rdc", "-c", "user.name=rdc-test", "commit", "-m", "test: precondition"], {
275
+ cwd: worktree.path,
276
+ stdio: "ignore",
277
+ });
278
+ }
279
+ } catch {
280
+ // non-fatal — snapshot will still work against whatever HEAD is
281
+ }
282
+
283
+ const headBefore = snapshotHead(worktree.path);
284
+ const wiCountBefore = await fetchWorkItemsCount(supabaseBranchRef);
285
+
286
+ // Start from process.env but scrub any inherited CLAUDE_* vars — the child
287
+ // claude process should not see parent session context. Then set RDC_TEST
288
+ // and overlay fixture env.
289
+ const env = { ...process.env };
290
+ for (const key of Object.keys(env)) {
291
+ if (key.startsWith("CLAUDE_")) delete env[key];
292
+ }
293
+ env.RDC_TEST = "1";
294
+ Object.assign(env, manifest.fixture?.env || {});
295
+
296
+ // Run claude inside the worktree — commits land there, git tracking is correct,
297
+ // and parallel skills each get their own isolated branch with no file conflicts.
298
+ let spawnRes;
299
+ try {
300
+ spawnRes = await spawnClaude({
301
+ claudeBin,
302
+ prompt: manifest.fixture?.prompt || "",
303
+ cwd: worktree.path,
304
+ env,
305
+ timeoutMs: timeout,
306
+ });
307
+ } catch (e) {
308
+ return {
309
+ skill,
310
+ pass: false,
311
+ duration_ms: nowMs() - started,
312
+ error: `spawn claude: ${e.message}`,
313
+ };
314
+ }
315
+
316
+ const commits = commitsSince(worktree.path, headBefore);
317
+ const files_modified = filesModifiedSince(worktree.path, headBefore);
318
+ const work_items_delta = await fetchWorkItemsDelta(supabaseBranchRef, wiCountBefore);
319
+
320
+ const observed = {
321
+ exit_code: spawnRes.exit,
322
+ stdout: spawnRes.stdout,
323
+ stderr: spawnRes.stderr,
324
+ files_modified,
325
+ commits,
326
+ work_items_delta,
327
+ timed_out: spawnRes.timedOut,
328
+ };
329
+
330
+ const evalRes = evaluateAssertions(manifest.assertions || {}, observed);
331
+ let pass = evalRes.pass;
332
+ const failures = [...evalRes.failures];
333
+ if (spawnRes.timedOut) {
334
+ pass = false;
335
+ failures.unshift({ predicate: "timeout", message: `child killed after ${timeout}ms` });
336
+ }
337
+
338
+ return {
339
+ skill,
340
+ pass,
341
+ duration_ms: nowMs() - started,
342
+ observed,
343
+ failures,
344
+ worktree: worktree.path,
345
+ };
346
+ }
347
+
348
+ // ─── self-test ──────────────────────────────────────────────────────────────
349
+
350
+ const __isMain = (() => {
351
+ try {
352
+ return fileURLToPath(import.meta.url) === resolve(process.argv[1] || "");
353
+ } catch {
354
+ return false;
355
+ }
356
+ })();
357
+
358
+ if (__isMain) {
359
+ let passed = 0;
360
+ let total = 0;
361
+ function t(desc, ok) {
362
+ total++;
363
+ if (ok) passed++;
364
+ console.log(`${ok ? "PASS" : "FAIL"} ${desc}`);
365
+ }
366
+
367
+ console.log("\nrunner.mjs self-test\n");
368
+
369
+ // parseContentRange
370
+ t("parseContentRange '0-0/42' → 42", parseContentRange("0-0/42") === 42);
371
+ t("parseContentRange '0-0/0' → 0", parseContentRange("0-0/0") === 0);
372
+ t("parseContentRange '*/0' → 0", parseContentRange("*/0") === 0);
373
+ t("parseContentRange '0-24/100' → 100", parseContentRange("0-24/100") === 100);
374
+ t("parseContentRange '' → 0", parseContentRange("") === 0);
375
+ t("parseContentRange null → 0", parseContentRange(null) === 0);
376
+ t("parseContentRange 'garbage' → 0", parseContentRange("garbage") === 0);
377
+
378
+ // fetch helpers graceful-degrade path
379
+ (async () => {
380
+ const c0 = await fetchWorkItemsCount(null);
381
+ t("fetchWorkItemsCount(null) → 0", c0 === 0);
382
+ const c1 = await fetchWorkItemsCount({ branchId: "x" }); // missing apiUrl/anonKey
383
+ t("fetchWorkItemsCount(no-creds) → 0", c1 === 0);
384
+ const d0 = await fetchWorkItemsDelta(null, 0);
385
+ t(
386
+ "fetchWorkItemsDelta(null, 0) → []",
387
+ Array.isArray(d0) && d0.length === 0,
388
+ );
389
+
390
+ // evaluateAssertions with observed work_items_delta matching manifest
391
+ const observed = {
392
+ exit_code: 0,
393
+ stdout: "",
394
+ stderr: "",
395
+ files_modified: [],
396
+ commits: [],
397
+ work_items_delta: [{ id: "w1", status: "done", labels: ["fixit"] }],
398
+ timed_out: false,
399
+ };
400
+ const r = evaluateAssertions(
401
+ {
402
+ exit_code: 0,
403
+ work_items_created: {
404
+ min: 1,
405
+ max: 1,
406
+ status: "done",
407
+ labels_include: ["fixit"],
408
+ },
409
+ },
410
+ observed,
411
+ );
412
+ t("evaluateAssertions: matching work_items → pass", r.pass === true);
413
+
414
+ const r2 = evaluateAssertions(
415
+ {
416
+ work_items_created: { min: 1, labels_include: ["missing"] },
417
+ },
418
+ observed,
419
+ );
420
+ t(
421
+ "evaluateAssertions: label mismatch → fail",
422
+ r2.pass === false &&
423
+ r2.failures.some((f) => f.predicate === "work_items_created"),
424
+ );
425
+
426
+ console.log(`\n${passed}/${total} passed\n`);
427
+ process.exit(passed === total ? 0 : 1);
428
+ })();
429
+ }