rungate 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (196) hide show
  1. package/.claude/agents/aditi.md +47 -0
  2. package/.claude/agents/marcus.md +50 -0
  3. package/.claude/agents/quinn.md +58 -0
  4. package/.claude/agents/rook.md +47 -0
  5. package/.claude/agents/serena.md +46 -0
  6. package/.claude/rungate.json +11 -0
  7. package/.fallowrc.json +28 -0
  8. package/.github/copilot-instructions.md +20 -0
  9. package/.rungate/conformity-findings.json +648 -0
  10. package/AGENTS.md +106 -0
  11. package/CODE-MAP.md +50 -0
  12. package/HARNESS.md +88 -0
  13. package/bun.lock +26 -0
  14. package/bunfig.toml +2 -0
  15. package/config/brief-policies.json +28 -0
  16. package/config/ceremony-profiles.json +212 -0
  17. package/config/consumer-cascade-map.json +24 -0
  18. package/config/doc-cascade-map.json +24 -0
  19. package/config/eval.json +84 -0
  20. package/config/profiles/account-plan.yaml +36 -0
  21. package/config/profiles/campaign.yaml +94 -0
  22. package/config/prove-evidence.schema.json +65 -0
  23. package/config/spec-policies.json +36 -0
  24. package/config/workflow-schema.json +281 -0
  25. package/gates/SCHEMA-GUIDE.md +121 -0
  26. package/gates/ac-quality.test.ts +106 -0
  27. package/gates/adversarial.test.ts +274 -0
  28. package/gates/brief-assembler.test.ts +429 -0
  29. package/gates/brief-assembler.ts +334 -0
  30. package/gates/bunfig.toml +2 -0
  31. package/gates/chain.test.ts +91 -0
  32. package/gates/e2e-smoke.test.ts +234 -0
  33. package/gates/error-classifier.test.ts +249 -0
  34. package/gates/error-classifier.ts +89 -0
  35. package/gates/orchestrator.test.ts +950 -0
  36. package/gates/orchestrator.ts +569 -0
  37. package/gates/preload.ts +77 -0
  38. package/gates/prompts/ac-adversary.md +20 -0
  39. package/gates/prompts/evidence-validator.md +22 -0
  40. package/gates/prompts/prove-reproducer.md +53 -0
  41. package/gates/prove.test.ts +164 -0
  42. package/gates/run-gate.ts +936 -0
  43. package/gates/schema-parity.test.ts +197 -0
  44. package/gates/schema.ts +362 -0
  45. package/gates/self-heal.test.ts +511 -0
  46. package/gates/self-heal.ts +121 -0
  47. package/gates/ship-orchestrator.test.ts +379 -0
  48. package/gates/ship-orchestrator.ts +363 -0
  49. package/gates/test-fixtures/broken-no-environments.json +60 -0
  50. package/gates/test-fixtures/valid-standard.json +54 -0
  51. package/gates/test-utils.ts +43 -0
  52. package/gates/witness.ts +220 -0
  53. package/gates/workflow.test.ts +1053 -0
  54. package/hooks/AgentBriefGuard.hook.ts +586 -0
  55. package/hooks/AgentVerdictCapture.hook.ts +134 -0
  56. package/hooks/AutoVerifyGate.hook.ts +76 -0
  57. package/hooks/GateEnforcement.hook.ts +273 -0
  58. package/hooks/IssueCloseGuard.hook.ts +116 -0
  59. package/hooks/MergeGuard.hook.ts +55 -0
  60. package/hooks/StaleTTLCleanup.hook.ts +133 -0
  61. package/hooks/VerifyPhaseLock.hook.ts +81 -0
  62. package/hooks/WorkflowStateGuard.hook.ts +37 -0
  63. package/hooks/lib/agentDetection.ts +70 -0
  64. package/hooks/lib/findWorkflow.ts +101 -0
  65. package/hooks/lib/parseStdin.ts +37 -0
  66. package/hooks/lib/paths.ts +111 -0
  67. package/hooks/lib/utils.ts +81 -0
  68. package/lib/conformity.ts +959 -0
  69. package/lib/paths.ts +23 -0
  70. package/lib/rungate-schema.ts +60 -0
  71. package/lib/signal-phrases.ts +7 -0
  72. package/package.json +20 -0
  73. package/prompts/ac-adversary.md +20 -0
  74. package/prompts/ac-format.md +34 -0
  75. package/prompts/aditi.md +29 -0
  76. package/prompts/blast-radius.md +29 -0
  77. package/prompts/coding-principles.md +34 -0
  78. package/prompts/container-rebuild.md +29 -0
  79. package/prompts/container-verify.md +28 -0
  80. package/prompts/discovery.md +27 -0
  81. package/prompts/environment.md +28 -0
  82. package/prompts/escalation-decision-tree.md +38 -0
  83. package/prompts/evidence-hierarchy.md +31 -0
  84. package/prompts/evidence-validator.md +22 -0
  85. package/prompts/marcus.md +29 -0
  86. package/prompts/prevention.md +26 -0
  87. package/prompts/prove-reproducer.md +43 -0
  88. package/prompts/quinn-decision-tree.md +31 -0
  89. package/prompts/quinn-ui-brief.md +106 -0
  90. package/prompts/quinn.md +29 -0
  91. package/prompts/rca.md +28 -0
  92. package/prompts/read-before-write.md +30 -0
  93. package/prompts/regression.md +26 -0
  94. package/prompts/rook.md +29 -0
  95. package/prompts/serena.md +28 -0
  96. package/prompts/testing-strategy.md +34 -0
  97. package/reference/migration-manifest.json +554 -0
  98. package/reference/prompts/agent-aditi.md +38 -0
  99. package/reference/prompts/agent-marcus.md +38 -0
  100. package/reference/prompts/agent-quinn.md +38 -0
  101. package/reference/prompts/agent-rook.md +37 -0
  102. package/reference/prompts/agent-serena.md +37 -0
  103. package/reference/prompts/council-skill.md +170 -0
  104. package/reference/prompts/goal-skill.md +235 -0
  105. package/reference/prompts/prove-skill.md +283 -0
  106. package/reference/prompts/quinn-standard.md +246 -0
  107. package/reference/prompts/ship-convergence.md +65 -0
  108. package/reference/prompts/ship-escalation.md +43 -0
  109. package/reference/prompts/ship-iteration.md +382 -0
  110. package/reference/prompts/ship-pending-patches.md +246 -0
  111. package/reference/prompts/ship-reference.md +250 -0
  112. package/reference/prompts/ship-skill.md +347 -0
  113. package/reference/prompts/ship-templates.md +215 -0
  114. package/reference/scripts/batch-status.sh +68 -0
  115. package/reference/scripts/chain-compat-check.sh +67 -0
  116. package/reference/scripts/context-audit.sh +314 -0
  117. package/reference/scripts/dead-export-check.sh +61 -0
  118. package/reference/scripts/generate-qc-tables.sh +92 -0
  119. package/reference/scripts/harness-init.sh +111 -0
  120. package/reference/scripts/pai-054-baseline-check.sh +40 -0
  121. package/reference/scripts/prove-smoke-test.sh +112 -0
  122. package/reference/scripts/setup-keychain-salt.sh +12 -0
  123. package/reference/scripts/skill-optimizer-friday.sh +88 -0
  124. package/reference/scripts/skill-qc-test.sh +351 -0
  125. package/reference/scripts/skill-synthesize-tonight.sh +66 -0
  126. package/reference/specs/HARNESS-EXTRACTION-SPEC.md +263 -0
  127. package/reference/specs/harness-v3-bash-deletion-plan.md +65 -0
  128. package/reference/specs/harness-v3-migration-plan.md +188 -0
  129. package/scripts/decision-reconcile.sh +74 -0
  130. package/scripts/decision-reconcile.ts +152 -0
  131. package/scripts/extract-constraints.ts +260 -0
  132. package/scripts/generate-code-map.ts +339 -0
  133. package/scripts/git-hooks/pre-commit +76 -0
  134. package/scripts/git-hooks/pre-push +271 -0
  135. package/scripts/harness-skill-check.sh +52 -0
  136. package/scripts/lib/gap-emit.sh +65 -0
  137. package/scripts/lib/jq-update.sh +30 -0
  138. package/scripts/lib/resolve-slug.sh +30 -0
  139. package/scripts/lib/verify-spec-compliance.sh +102 -0
  140. package/scripts/prove-backfill.sh +87 -0
  141. package/scripts/scaffold-project.ts +1488 -0
  142. package/scripts/scaffold-rungate-config.ts +91 -0
  143. package/scripts/self-containment-check.sh +109 -0
  144. package/scripts/skill-qc-validator.sh +402 -0
  145. package/scripts/slug-resolver.sh +14 -0
  146. package/scripts/sync-spec-tests.ts +236 -0
  147. package/specs/BOOTSTRAP-DATA-FLOW-SPEC.md +2493 -0
  148. package/specs/BOOTSTRAP-TEST-PLAN.md +571 -0
  149. package/specs/HARNESS-GATES.md +256 -0
  150. package/specs/HARNESS-SKILL-CHAIN.md +286 -0
  151. package/specs/HARNESS-SKILL-CONTRACT.md +93 -0
  152. package/specs/HARNESS-STANDARD.md +488 -0
  153. package/specs/SPEC-TEMPLATE.md +53 -0
  154. package/specs/bootstrap-data-flow.png +0 -0
  155. package/specs/harness-automation-matrix.md +314 -0
  156. package/specs/harness-automation-matrix.rules.json +64 -0
  157. package/test/anti.test.ts +80 -0
  158. package/test/contract-negative.test.ts +86 -0
  159. package/test/contract.test.ts +158 -0
  160. package/test/external-deps.test.ts +48 -0
  161. package/test/fixtures/golden-project/.env.example +3 -0
  162. package/test/fixtures/golden-project/Makefile +7 -0
  163. package/test/fixtures/golden-project/docs/adr/ADR-001-framework.md +23 -0
  164. package/test/fixtures/golden-project/docs/setup-guide.md +10 -0
  165. package/test/fixtures/golden-project/package.json +10 -0
  166. package/test/fixtures/golden-project/specs/api-spec.md +20 -0
  167. package/test/fixtures/golden-project/src/auth.ts +8 -0
  168. package/test/fixtures/golden-project/src/db.ts +11 -0
  169. package/test/fixtures/golden-project/src/index.ts +19 -0
  170. package/test/fixtures/golden-project/src/utils/format.ts +3 -0
  171. package/test/fixtures/golden-project/test/auth.test.ts +15 -0
  172. package/test/fixtures/golden-project/tsconfig.json +12 -0
  173. package/test/meta-sc-coverage.test.ts +159 -0
  174. package/test/phase-0.test.ts +846 -0
  175. package/test/phase-1.test.ts +617 -0
  176. package/test/phase-2.test.ts +620 -0
  177. package/test/phase-3.test.ts +99 -0
  178. package/test/scaffold-conformity.test.ts +8 -0
  179. package/test/schema-canary.test.ts +51 -0
  180. package/test/spec-compliance-auto.test.ts +64 -0
  181. package/test/spec-compliance.test.ts +295 -0
  182. package/test/spec-discovery.test.ts +68 -0
  183. package/test/spec-drift.test.ts +5 -0
  184. package/test/structure.test.ts +165 -0
  185. package/test/unit/agent-brief-guard-ship.test.ts +293 -0
  186. package/test/unit/extract-constraints.test.ts +145 -0
  187. package/test/unit/issue-close-guard.test.ts +204 -0
  188. package/test/unit/scaffold-project.test.ts +417 -0
  189. package/test/unit/skill-cooccurrence.test.ts +177 -0
  190. package/test/unit/skill-sequence-logger.test.ts +244 -0
  191. package/test/unit/workflow-state-guard.test.ts +95 -0
  192. package/workflows/batch-ship.js +295 -0
  193. package/workflows/council.js +481 -0
  194. package/workflows/prove.js +560 -0
  195. package/workflows/ship.js +789 -0
  196. package/workflows/verify.js +236 -0
@@ -0,0 +1,91 @@
1
+ #!/usr/bin/env bun
2
+ // scaffold-rungate-config.ts -- Generate starter .claude/rungate.json
3
+ // Usage: scaffold-rungate-config.ts /path/to/project
4
+
5
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
6
+ import { join } from "path";
7
+ import { execSync } from "child_process";
8
+
9
+ const projectRoot = process.argv[2];
10
+ if (!projectRoot) {
11
+ console.error("Usage: scaffold-rungate-config.ts /path/to/project");
12
+ process.exit(1);
13
+ }
14
+
15
+ const target = join(projectRoot, ".claude", "rungate.json");
16
+
17
+ if (existsSync(target)) {
18
+ console.log(`EXISTS: ${target} — not overwriting`);
19
+ process.exit(0);
20
+ }
21
+
22
+ // Infer codeCommittedPaths
23
+ const paths: string[] = [];
24
+ for (const d of ["src", "lib", "app", "config", "test", "tests", "spec"]) {
25
+ if (existsSync(join(projectRoot, d))) paths.push(`${d}/`);
26
+ }
27
+ for (const f of ["package.json", "Makefile", "docker-compose.yml", "tsconfig.json"]) {
28
+ if (existsSync(join(projectRoot, f))) paths.push(f);
29
+ }
30
+ if (paths.length === 0) paths.push("./");
31
+
32
+ // Infer dev command
33
+ let devCmd: string | null = null;
34
+ const pkgPath = join(projectRoot, "package.json");
35
+ const makefilePath = join(projectRoot, "Makefile");
36
+ const hasPkg = existsSync(pkgPath);
37
+ const hasMakefile = existsSync(makefilePath);
38
+
39
+ if (hasPkg) {
40
+ const pkg = readFileSync(pkgPath, "utf-8");
41
+ if (pkg.includes('"dev"')) devCmd = "npm run dev";
42
+ else if (pkg.includes('"start"')) devCmd = "npm start";
43
+ } else if (hasMakefile) {
44
+ const mf = readFileSync(makefilePath, "utf-8");
45
+ if (/^dev/m.test(mf)) devCmd = "make dev";
46
+ }
47
+
48
+ // Infer test command
49
+ let testCmd: string | null = null;
50
+ if (hasPkg) {
51
+ const pkg = readFileSync(pkgPath, "utf-8");
52
+ if (pkg.includes('"test"')) testCmd = "bun test --timeout 30000";
53
+ }
54
+
55
+ // Infer rebuild command
56
+ let rebuildCmd: string | null = null;
57
+ if (hasMakefile) {
58
+ const mf = readFileSync(makefilePath, "utf-8");
59
+ if (/^rebuild/m.test(mf)) rebuildCmd = "make rebuild";
60
+ }
61
+
62
+ // Infer issueRepo from git remote
63
+ let issueRepo = "";
64
+ if (existsSync(join(projectRoot, ".git"))) {
65
+ try {
66
+ const remote = execSync("git remote get-url origin", {
67
+ cwd: projectRoot,
68
+ encoding: "utf-8",
69
+ }).trim();
70
+ if (remote) {
71
+ issueRepo = remote.replace(/.*github\.com[:/]/, "").replace(/\.git$/, "");
72
+ }
73
+ } catch {
74
+ // no remote configured
75
+ }
76
+ }
77
+
78
+ mkdirSync(join(projectRoot, ".claude"), { recursive: true });
79
+
80
+ const config = {
81
+ description: "Auto-generated project harness config",
82
+ codeCommittedPaths: paths,
83
+ issueRepo,
84
+ dev: { command: devCmd },
85
+ test: { command: testCmd },
86
+ prod: { rebuild: rebuildCmd },
87
+ };
88
+
89
+ writeFileSync(target, JSON.stringify(config, null, 2) + "\n");
90
+ console.log(`CREATED: ${target}`);
91
+ console.log(readFileSync(target, "utf-8"));
@@ -0,0 +1,109 @@
1
+ #!/bin/bash
2
+ # Self-containment check for rungate repo
3
+ # Run from repo root: bash scripts/self-containment-check.sh
4
+ # Exit 0 = clean, Exit 1 = leaks found
5
+
6
+ set -euo pipefail
7
+ FAIL=0
8
+
9
+ echo "=== Rungate Self-Containment Check ==="
10
+ echo ""
11
+
12
+ # 1. No external path references in production code
13
+ echo "1. External path references (production code only):"
14
+ EXTERNAL=$(grep -rn '/Users/jhorn\|~/.claude\|~/.pai' --include="*.ts" --include="*.js" . 2>/dev/null \
15
+ | grep -v node_modules | grep -v ".git/" | grep -v "test/" | grep -v "reference/" \
16
+ | grep -v " \* \|^.*://\|// " || true)
17
+ if [ -n "$EXTERNAL" ]; then
18
+ echo " FAIL — found external paths:"
19
+ echo "$EXTERNAL" | sed 's/^/ /'
20
+ FAIL=1
21
+ else
22
+ echo " PASS — zero external paths in production code"
23
+ fi
24
+ echo ""
25
+
26
+ # 2. No old name references
27
+ echo "2. Old name references (pai-work, PAI_WORK_DIR, project-harness, pai-harness):"
28
+ OLD_NAMES=$(grep -rn 'pai-work\|PAI_WORK_DIR\|project-harness\|pai-harness' \
29
+ --include="*.ts" --include="*.js" --include="*.json" --include="*.sh" . 2>/dev/null \
30
+ | grep -v node_modules | grep -v ".git/" | grep -v "reference/migration" \
31
+ | grep -v "RUNGATE_WORK_DIR.*PAI_WORK_DIR" \
32
+ | grep -v "fallback\|legacy\|deprecated" \
33
+ | grep -v "self-containment-check" || true)
34
+ if [ -n "$OLD_NAMES" ]; then
35
+ echo " FAIL — found old names:"
36
+ echo "$OLD_NAMES" | sed 's/^/ /'
37
+ FAIL=1
38
+ else
39
+ echo " PASS — zero old name references"
40
+ fi
41
+ echo ""
42
+
43
+ # 3. Old names in specs/docs
44
+ echo "3. Old name references in specs/docs:"
45
+ OLD_DOCS=$(grep -rn 'pai-work\|PAI_WORK_DIR\|project-harness\|pai-harness' \
46
+ --include="*.md" . 2>/dev/null \
47
+ | grep -v node_modules | grep -v ".git/" | grep -v "reference/migration" || true)
48
+ if [ -n "$OLD_DOCS" ]; then
49
+ echo " FAIL — found old names in docs:"
50
+ echo "$OLD_DOCS" | wc -l | xargs -I{} echo " {} references remaining"
51
+ FAIL=1
52
+ else
53
+ echo " PASS — zero old name references in docs"
54
+ fi
55
+ echo ""
56
+
57
+ # 4. Agent briefs exist
58
+ echo "4. Agent briefs in .claude/agents/:"
59
+ for agent in marcus quinn rook serena aditi; do
60
+ if [ -f ".claude/agents/${agent}.md" ]; then
61
+ echo " PASS — ${agent}.md exists"
62
+ else
63
+ echo " FAIL — ${agent}.md missing"
64
+ FAIL=1
65
+ fi
66
+ done
67
+ echo ""
68
+
69
+ # 5. Prompt templates exist
70
+ echo "5. Prompt templates in prompts/:"
71
+ if [ -d "prompts" ] && [ "$(ls prompts/*.md 2>/dev/null | wc -l)" -gt 0 ]; then
72
+ echo " PASS — $(ls prompts/*.md | wc -l) templates found"
73
+ else
74
+ echo " WARN — no prompts/ directory or no templates"
75
+ fi
76
+ echo ""
77
+
78
+ # 6. Package.json name
79
+ echo "6. Package name:"
80
+ PKG_NAME=$(python3 -c "import json; print(json.load(open('package.json'))['name'])" 2>/dev/null)
81
+ if [ "$PKG_NAME" = "rungate" ]; then
82
+ echo " PASS — package.json name is 'rungate'"
83
+ else
84
+ echo " FAIL — package.json name is '${PKG_NAME}', expected 'rungate'"
85
+ FAIL=1
86
+ fi
87
+ echo ""
88
+
89
+ # 7. Config file name
90
+ echo "7. Config file:"
91
+ if [ -f ".claude/rungate.json" ]; then
92
+ echo " PASS — .claude/rungate.json exists"
93
+ elif [ -f ".claude/project-harness.json" ]; then
94
+ echo " FAIL — still using project-harness.json (not renamed)"
95
+ FAIL=1
96
+ else
97
+ echo " WARN — no config file found"
98
+ fi
99
+ echo ""
100
+
101
+ # Summary
102
+ echo "=== Summary ==="
103
+ if [ $FAIL -eq 0 ]; then
104
+ echo "PASS — repo is self-contained"
105
+ exit 0
106
+ else
107
+ echo "FAIL — leaks found (see above)"
108
+ exit 1
109
+ fi
@@ -0,0 +1,402 @@
1
+ #!/usr/bin/env bash
2
+ # skill-qc-validator.sh — Data-driven QC validator
3
+ # Reads check definitions from skill-qc-checks.json, runs them generically.
4
+ # The script never hardcodes skill names — all skill-specific logic lives in the JSON config.
5
+ #
6
+ # Usage: skill-qc-validator.sh --skill SKILL --issue NUM --slug SLUG [--repo REPO] [--project-root PATH]
7
+ set -u
8
+
9
+ # ─── Arg parsing ───────────────────────────────────────────────
10
+ SKILL="" ISSUE="" SLUG="" REPO="hornjason/pai-config" PROJECT_ROOT="$HOME/.claude"
11
+
12
+ while [[ $# -gt 0 ]]; do
13
+ case "$1" in
14
+ --skill) SKILL="$2"; shift 2 ;;
15
+ --issue) ISSUE="$2"; shift 2 ;;
16
+ --slug) SLUG="$2"; shift 2 ;;
17
+ --repo) REPO="$2"; shift 2 ;;
18
+ --project-root) PROJECT_ROOT="$2"; shift 2 ;;
19
+ *) echo "Unknown arg: $1" >&2; exit 1 ;;
20
+ esac
21
+ done
22
+
23
+ if [[ -z "$SKILL" || -z "$ISSUE" || -z "$SLUG" ]]; then
24
+ echo "Usage: skill-qc-validator.sh --skill SKILL --issue NUM --slug SLUG [--repo REPO] [--project-root PATH]" >&2
25
+ exit 1
26
+ fi
27
+
28
+ WORK_DIR="${RUNGATE_WORK_DIR:-$HOME/.rungate}/$SLUG"
29
+
30
+ # Auto-detect repo from workflow-state.json if not explicitly provided
31
+ if [[ "$REPO" == "hornjason/pai-config" && -f "$WORK_DIR/workflow-state.json" ]]; then
32
+ DETECTED_REPO=$(jq -r '.issueRepo // .repo // empty' "$WORK_DIR/workflow-state.json" 2>/dev/null)
33
+ if [[ -n "$DETECTED_REPO" ]]; then
34
+ REPO="$DETECTED_REPO"
35
+ fi
36
+ fi
37
+
38
+ CONFIG="$(cd "$(dirname "$0")/.." && pwd)/schemas/skill-qc-checks.json"
39
+
40
+ # Fallback: try home dir
41
+ if [[ ! -f "$CONFIG" ]]; then
42
+ CONFIG="$HOME/.claude/schemas/skill-qc-checks.json"
43
+ fi
44
+
45
+ [[ -f "$CONFIG" ]] || { echo "ERROR: Config not found: $CONFIG" >&2; exit 1; }
46
+ command -v jq >/dev/null 2>&1 || { echo "ERROR: jq is required" >&2; exit 1; }
47
+
48
+ # ─── Temp dir for jq filter files ──────────────────────────────
49
+ QC_TMPDIR=$(mktemp -d)
50
+ trap 'rm -rf "$QC_TMPDIR"' EXIT
51
+
52
+ # ─── Counters ──────────────────────────────────────────────────
53
+ PASS_COUNT=0
54
+ FAIL_COUNT=0
55
+ SKIP_COUNT=0
56
+ WARN_COUNT=0
57
+
58
+ # ─── Variable substitution in command strings ──────────────────
59
+ subst_vars() {
60
+ local s="$1"
61
+ s="${s//\$ISSUE/$ISSUE}"
62
+ s="${s//\$SLUG/$SLUG}"
63
+ s="${s//\$REPO/$REPO}"
64
+ s="${s//\$WORK_DIR/$WORK_DIR}"
65
+ s="${s//\$PROJECT_ROOT/$PROJECT_ROOT}"
66
+ printf '%s' "$s"
67
+ }
68
+
69
+ # ─── Run jq filter from string (avoids shell quoting issues) ──
70
+ run_jq_filter() {
71
+ local filter="$1" file="$2"
72
+ printf '%s\n' "$filter" > "$QC_TMPDIR/jqf"
73
+ jq -rf "$QC_TMPDIR/jqf" "$file" 2>/dev/null
74
+ }
75
+
76
+ # ─── Result recording ─────────────────────────────────────────
77
+ do_result() {
78
+ local status="$1" id="$2" desc="$3" sev="$4" detail="$5"
79
+
80
+ # WARN severity always prints WARN regardless of pass/fail
81
+ if [[ "$sev" == "WARN" ]]; then
82
+ if [[ -n "$detail" ]]; then
83
+ printf "%-4s WARN %s -- %s\n" "$id" "$desc" "$detail"
84
+ else
85
+ printf "%-4s WARN %s\n" "$id" "$desc"
86
+ fi
87
+ WARN_COUNT=$((WARN_COUNT + 1))
88
+ return
89
+ fi
90
+
91
+ if [[ "$status" == "PASS" ]]; then
92
+ printf "%-4s PASS %s\n" "$id" "$desc"
93
+ PASS_COUNT=$((PASS_COUNT + 1))
94
+ else
95
+ if [[ -n "$detail" ]]; then
96
+ printf "%-4s FAIL %s -- %s\n" "$id" "$desc" "$detail"
97
+ else
98
+ printf "%-4s FAIL %s\n" "$id" "$desc"
99
+ fi
100
+ FAIL_COUNT=$((FAIL_COUNT + 1))
101
+ fi
102
+ }
103
+
104
+ do_skip() {
105
+ local id="$1" desc="$2"
106
+ printf "%-4s SKIP %s\n" "$id" "$desc"
107
+ SKIP_COUNT=$((SKIP_COUNT + 1))
108
+ }
109
+
110
+ # ─── Expect evaluation for command-type checks ────────────────
111
+ eval_expect() {
112
+ local op="$1" value="$2" raw_output="$3" exit_code="$4"
113
+ local trimmed
114
+ trimmed=$(printf '%s' "$raw_output" | tail -1 | tr -d '[:space:]')
115
+
116
+ case "$op" in
117
+ exit-0)
118
+ [[ "$exit_code" -eq 0 ]]
119
+ ;;
120
+ non-empty)
121
+ [[ -n "$trimmed" ]]
122
+ ;;
123
+ contains)
124
+ printf '%s' "$raw_output" | grep -qF "$value"
125
+ ;;
126
+ ">=")
127
+ local num="${trimmed:-0}"
128
+ # Ensure numeric
129
+ [[ "$num" =~ ^-?[0-9]+$ ]] || num=0
130
+ [[ "$num" -ge "${value:-0}" ]] 2>/dev/null
131
+ ;;
132
+ "==")
133
+ [[ "$trimmed" == "$value" ]]
134
+ ;;
135
+ "!=")
136
+ [[ "$trimmed" != "$value" ]]
137
+ ;;
138
+ *)
139
+ return 1
140
+ ;;
141
+ esac
142
+ }
143
+
144
+ # ─── Verify checks exist for this skill ───────────────────────
145
+ check_count=$(jq "[.checks[] | select(.skill == \"$SKILL\")] | length" "$CONFIG")
146
+ if [[ "$check_count" -eq 0 ]]; then
147
+ echo "No checks found for skill: $SKILL" >&2
148
+ exit 1
149
+ fi
150
+
151
+ echo "=== Skill QC: $SKILL ($check_count checks) ==="
152
+
153
+ # ─── Main loop: process each check ────────────────────────────
154
+ while IFS= read -r check || [[ -n "$check" ]]; do
155
+ id=$(jq -r '.id' <<< "$check")
156
+ desc=$(jq -r '.description' <<< "$check")
157
+ chk_type=$(jq -r '.type' <<< "$check")
158
+ severity=$(jq -r '.severity // "FAIL"' <<< "$check")
159
+
160
+ # ── Skip gate-runner checks when called from within a gate (prevents recursion) ──
161
+ chk_cmd=$(jq -r '.command // empty' <<< "$check")
162
+ if [[ -n "${GATE_RUNNER_ACTIVE:-}" && "$chk_cmd" == *"gate-runner.sh"* ]]; then
163
+ do_skip "$id" "$desc (gate-runner recursion guard)"
164
+ continue
165
+ fi
166
+
167
+ # ── Evaluate skipWhen ──
168
+ skip_kind=$(jq -r '.skipWhen | type' <<< "$check")
169
+ if [[ "$skip_kind" == "object" ]]; then
170
+ skip_cmd=$(jq -r '.skipWhen.command // empty' <<< "$check")
171
+ if [[ -n "$skip_cmd" ]]; then
172
+ skip_cmd=$(subst_vars "$skip_cmd")
173
+ if eval "$skip_cmd" 2>/dev/null; then
174
+ do_skip "$id" "$desc"
175
+ continue
176
+ fi
177
+ fi
178
+ fi
179
+
180
+ # ── Run check by type ──
181
+ case "$chk_type" in
182
+
183
+ command)
184
+ cmd=$(jq -r '.command' <<< "$check")
185
+ cmd=$(subst_vars "$cmd")
186
+ op=$(jq -r '.expect.op' <<< "$check")
187
+ value=$(jq -r '.expect.value // empty' <<< "$check")
188
+
189
+ raw_output=$(eval "$cmd" 2>/dev/null)
190
+ cmd_exit=$?
191
+
192
+ if eval_expect "$op" "$value" "$raw_output" "$cmd_exit"; then
193
+ do_result "PASS" "$id" "$desc" "$severity" ""
194
+ else
195
+ # Build detail from output
196
+ detail_line=$(printf '%s' "$raw_output" | tail -1 | tr -d '[:space:]')
197
+ case "$op" in
198
+ ">="| "=="|"!=") do_result "FAIL" "$id" "$desc" "$severity" "got $detail_line" ;;
199
+ contains) do_result "FAIL" "$id" "$desc" "$severity" "output missing expected string" ;;
200
+ non-empty) do_result "FAIL" "$id" "$desc" "$severity" "empty output" ;;
201
+ exit-0) do_result "FAIL" "$id" "$desc" "$severity" "exit code $cmd_exit" ;;
202
+ *) do_result "FAIL" "$id" "$desc" "$severity" "" ;;
203
+ esac
204
+ fi
205
+ ;;
206
+
207
+ jq)
208
+ source_name=$(jq -r '.source' <<< "$check")
209
+ query=$(jq -r '.query' <<< "$check")
210
+ op=$(jq -r '.expect.op' <<< "$check")
211
+ value=$(jq -r '.expect.value // empty' <<< "$check")
212
+ source_file="$WORK_DIR/$source_name"
213
+
214
+ if [[ ! -f "$source_file" ]]; then
215
+ do_result "FAIL" "$id" "$desc" "$severity" "source file not found: $source_name"
216
+ continue
217
+ fi
218
+
219
+ result=$(run_jq_filter "$query" "$source_file")
220
+
221
+ case "$op" in
222
+ not-null)
223
+ if [[ "$result" != "null" && -n "$result" ]]; then
224
+ do_result "PASS" "$id" "$desc" "$severity" ""
225
+ else
226
+ do_result "FAIL" "$id" "$desc" "$severity" "got null"
227
+ fi
228
+ ;;
229
+ length-gte)
230
+ result_clean=$(printf '%s' "$result" | tr -d '[:space:]')
231
+ if [[ ${#result_clean} -ge ${value:-0} ]]; then
232
+ do_result "PASS" "$id" "$desc" "$severity" ""
233
+ else
234
+ do_result "FAIL" "$id" "$desc" "$severity" "length ${#result_clean} < $value"
235
+ fi
236
+ ;;
237
+ *)
238
+ do_result "FAIL" "$id" "$desc" "$severity" "unknown jq op: $op"
239
+ ;;
240
+ esac
241
+ ;;
242
+
243
+ jq-count)
244
+ source_name=$(jq -r '.source' <<< "$check")
245
+ query=$(jq -r '.query' <<< "$check")
246
+ op=$(jq -r '.expect.op' <<< "$check")
247
+ value=$(jq -r '.expect.value // empty' <<< "$check")
248
+ source_file="$WORK_DIR/$source_name"
249
+
250
+ if [[ ! -f "$source_file" ]]; then
251
+ do_result "FAIL" "$id" "$desc" "$severity" "source file not found: $source_name"
252
+ continue
253
+ fi
254
+
255
+ count=$(run_jq_filter "$query | length" "$source_file")
256
+ count="${count:-0}"
257
+ [[ "$count" =~ ^[0-9]+$ ]] || count=0
258
+
259
+ if eval_expect "$op" "$value" "$count" "0"; then
260
+ do_result "PASS" "$id" "$desc" "$severity" ""
261
+ else
262
+ do_result "FAIL" "$id" "$desc" "$severity" "count=$count"
263
+ fi
264
+ ;;
265
+
266
+ jq-each)
267
+ source_name=$(jq -r '.source' <<< "$check")
268
+ query=$(jq -r '.query' <<< "$check")
269
+ test_kind=$(jq -r '.test' <<< "$check")
270
+ source_file="$WORK_DIR/$source_name"
271
+
272
+ if [[ ! -f "$source_file" ]]; then
273
+ do_result "FAIL" "$id" "$desc" "$severity" "source file not found: $source_name"
274
+ continue
275
+ fi
276
+
277
+ elements=$(run_jq_filter "$query" "$source_file")
278
+
279
+ if [[ -z "$elements" ]]; then
280
+ do_result "FAIL" "$id" "$desc" "$severity" "no elements returned by query"
281
+ continue
282
+ fi
283
+
284
+ all_pass=true
285
+ fail_detail=""
286
+
287
+ while IFS= read -r elem; do
288
+ [[ -z "$elem" ]] && continue
289
+
290
+ if [[ "$elem" == "null" ]]; then
291
+ all_pass=false
292
+ fail_detail="null or missing field"
293
+ break
294
+ fi
295
+
296
+ case "$test_kind" in
297
+ file-exists)
298
+ # Resolve relative paths against WORK_DIR
299
+ check_path="$elem"
300
+ if [[ "$check_path" != /* ]]; then
301
+ check_path="$WORK_DIR/$check_path"
302
+ fi
303
+ if [[ ! -f "$check_path" ]]; then
304
+ all_pass=false
305
+ fail_detail="file not found: $elem"
306
+ break
307
+ fi
308
+ ;;
309
+ in-enum)
310
+ found=false
311
+ while IFS= read -r enum_val; do
312
+ if [[ "$elem" == "$enum_val" ]]; then
313
+ found=true
314
+ break
315
+ fi
316
+ done < <(jq -r '.enum[]' <<< "$check")
317
+ if ! $found; then
318
+ all_pass=false
319
+ fail_detail="'$elem' not in allowed enum"
320
+ break
321
+ fi
322
+ ;;
323
+ *)
324
+ all_pass=false
325
+ fail_detail="unknown test type: $test_kind"
326
+ break
327
+ ;;
328
+ esac
329
+ done <<< "$elements"
330
+
331
+ if $all_pass; then
332
+ do_result "PASS" "$id" "$desc" "$severity" ""
333
+ else
334
+ do_result "FAIL" "$id" "$desc" "$severity" "$fail_detail"
335
+ fi
336
+ ;;
337
+
338
+ computed)
339
+ source_name=$(jq -r '.source' <<< "$check")
340
+ jq_test=$(jq -r '.jq_test' <<< "$check")
341
+ source_file="$WORK_DIR/$source_name"
342
+
343
+ if [[ ! -f "$source_file" ]]; then
344
+ do_result "FAIL" "$id" "$desc" "$severity" "source file not found: $source_name"
345
+ continue
346
+ fi
347
+
348
+ result=$(run_jq_filter "$jq_test" "$source_file")
349
+
350
+ if [[ -z "$result" ]]; then
351
+ do_result "FAIL" "$id" "$desc" "$severity" "jq evaluation failed"
352
+ elif [[ "$result" == "PASS" ]]; then
353
+ do_result "PASS" "$id" "$desc" "$severity" ""
354
+ else
355
+ do_result "FAIL" "$id" "$desc" "$severity" "computed: $result"
356
+ fi
357
+ ;;
358
+
359
+ grep)
360
+ source_name=$(jq -r '.source' <<< "$check")
361
+ pattern=$(jq -r '.pattern' <<< "$check")
362
+ op=$(jq -r '.expect.op' <<< "$check")
363
+ value=$(jq -r '.expect.value // empty' <<< "$check")
364
+ source_file="$WORK_DIR/$source_name"
365
+
366
+ if [[ ! -f "$source_file" ]]; then
367
+ do_result "FAIL" "$id" "$desc" "$severity" "source file not found: $source_name"
368
+ continue
369
+ fi
370
+
371
+ pattern=$(subst_vars "$pattern")
372
+ count=$(grep -c "$pattern" "$source_file" 2>/dev/null || echo "0")
373
+
374
+ if eval_expect "$op" "$value" "$count" "0"; then
375
+ do_result "PASS" "$id" "$desc" "$severity" ""
376
+ else
377
+ do_result "FAIL" "$id" "$desc" "$severity" "matches=$count"
378
+ fi
379
+ ;;
380
+
381
+ file-exists)
382
+ path=$(jq -r '.path' <<< "$check")
383
+ path=$(subst_vars "$path")
384
+
385
+ if [[ -f "$path" ]]; then
386
+ do_result "PASS" "$id" "$desc" "$severity" ""
387
+ else
388
+ do_result "FAIL" "$id" "$desc" "$severity" "not found: $path"
389
+ fi
390
+ ;;
391
+
392
+ *)
393
+ do_result "FAIL" "$id" "$desc" "$severity" "unknown check type: $chk_type"
394
+ ;;
395
+ esac
396
+
397
+ done < <(jq -c ".checks[] | select(.skill == \"$SKILL\")" "$CONFIG")
398
+
399
+ # ─── Summary ──────────────────────────────────────────────────
400
+ echo ""
401
+ echo "$SKILL QC: $PASS_COUNT pass, $FAIL_COUNT fail, $SKIP_COUNT skip, $WARN_COUNT warn"
402
+ [[ $FAIL_COUNT -eq 0 ]]
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env bash
2
+ # slug-resolver.sh — Maps repo identifier to short slug. Deterministic — no LLM judgment.
3
+ # Usage: bash slug-resolver.sh <repo-identifier>
4
+ # Input: "hornjason/pai-config" or "hornjason/asaCommandCenter" or full git URL
5
+ # Output: short name (e.g., "pai", "ddb")
6
+ # Thin caller — mapping logic lives in scripts/lib/resolve-slug.sh
7
+ set -euo pipefail
8
+
9
+ REPO="${1:?Usage: slug-resolver.sh <repo-identifier>}"
10
+
11
+ SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
12
+ source "$SCRIPT_DIR/lib/resolve-slug.sh"
13
+
14
+ resolve_slug_from_repo "$REPO"