rungate 0.2.1 → 0.4.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 (129) hide show
  1. package/bin/rungate.ts +70 -0
  2. package/lib/aes-calculator.ts +66 -0
  3. package/lib/agent-audit.ts +139 -0
  4. package/lib/agent-brief-validation.ts +359 -0
  5. package/lib/agents-md-refs.ts +90 -0
  6. package/lib/bash-file-read.ts +197 -0
  7. package/lib/behavioral-cache.ts +78 -0
  8. package/lib/branch-cleanup.ts +234 -0
  9. package/lib/brief-context-parser.ts +35 -0
  10. package/lib/brief-precedence.ts +114 -0
  11. package/lib/canary.ts +117 -0
  12. package/lib/check-registry.ts +226 -0
  13. package/lib/ci-checkout.ts +426 -0
  14. package/lib/cli-commands.ts +137 -0
  15. package/lib/compliance-backfill.ts +232 -0
  16. package/lib/compliance-report.ts +605 -0
  17. package/lib/compliance.ts +361 -0
  18. package/lib/config-loader.ts +255 -0
  19. package/lib/config-readers.ts +86 -0
  20. package/lib/conformity.ts +2161 -137
  21. package/lib/container-provenance.ts +230 -0
  22. package/lib/create-brief.ts +150 -0
  23. package/lib/create-sc.ts +267 -0
  24. package/lib/decomposition-waves.ts +197 -0
  25. package/lib/deep-merge.ts +69 -0
  26. package/lib/dev-liveness.ts +214 -0
  27. package/lib/directive-extractor.ts +210 -0
  28. package/lib/distribution-standing.ts +113 -0
  29. package/lib/doc-hygiene.ts +238 -0
  30. package/lib/eval-criteria.ts +6 -0
  31. package/lib/evidence-portability.ts +123 -0
  32. package/lib/evidence-prevalidator.ts +390 -0
  33. package/lib/evidence-required.ts +150 -0
  34. package/lib/evidence-satisfiability.ts +288 -0
  35. package/lib/frontmatter.ts +163 -0
  36. package/lib/gap-scanner.ts +348 -0
  37. package/lib/gate-check-audit.ts +190 -0
  38. package/lib/gate-enforcement.ts +366 -0
  39. package/lib/generators/agent-briefs.ts +136 -0
  40. package/lib/generators/agents-md.ts +511 -0
  41. package/lib/generators/code-map.ts +60 -0
  42. package/lib/generators/types.ts +184 -0
  43. package/lib/git-ref-normalizer.ts +107 -0
  44. package/lib/github.ts +539 -0
  45. package/lib/harness-identity.ts +63 -0
  46. package/lib/hill-climb.ts +164 -0
  47. package/lib/instruction-effectiveness.ts +131 -0
  48. package/lib/issue-closure-audit.ts +225 -0
  49. package/lib/issue-create-override.ts +343 -0
  50. package/lib/issue-extraction.ts +368 -0
  51. package/lib/js-top-level-code.ts +250 -0
  52. package/lib/liveness-contradiction.ts +149 -0
  53. package/lib/organize.ts +505 -0
  54. package/lib/paths.ts +197 -6
  55. package/lib/phase2-decomposition.ts +270 -0
  56. package/lib/post-fix-verify.ts +157 -0
  57. package/lib/prior-branch.ts +512 -0
  58. package/lib/project-state-shape.ts +166 -0
  59. package/lib/promote-outputs.ts +156 -0
  60. package/lib/prove-label-gate.ts +128 -0
  61. package/lib/reachability.ts +302 -0
  62. package/lib/release-preflight.ts +288 -0
  63. package/lib/rule-health-pipeline.ts +264 -0
  64. package/lib/rule-health-trend.ts +161 -0
  65. package/lib/rule-provenance.ts +149 -0
  66. package/lib/rule-registry.ts +128 -0
  67. package/lib/rungate-schema.ts +127 -5
  68. package/lib/sc-claim-forms.ts +179 -0
  69. package/lib/sc-cover.ts +150 -0
  70. package/lib/sc-guard.ts +157 -0
  71. package/lib/sc-ids.ts +344 -0
  72. package/lib/scaffold/defaults.ts +165 -0
  73. package/lib/scaffold/managed-workflow.ts +370 -0
  74. package/lib/scaffold/owned-files.ts +265 -0
  75. package/lib/scaffold/pre-push-hook.ts +165 -0
  76. package/lib/scaffold/steps.ts +2621 -0
  77. package/lib/scanner.ts +701 -0
  78. package/lib/scope-denylist.ts +258 -0
  79. package/lib/screenshot-upload.ts +73 -0
  80. package/lib/secret-patterns.ts +112 -0
  81. package/lib/security-verdict.ts +616 -0
  82. package/lib/signal-phrases.ts +1 -0
  83. package/lib/spec-change-conformity.ts +80 -0
  84. package/lib/spec-files.ts +62 -0
  85. package/lib/spec-registry.ts +133 -0
  86. package/lib/spec-updater.ts +96 -0
  87. package/lib/stale-cleanup.ts +224 -0
  88. package/lib/stale-issue-scanner.ts +36 -0
  89. package/lib/strip-js-comments.ts +269 -0
  90. package/lib/suite-measurement.ts +228 -0
  91. package/lib/task-completion-checks.ts +224 -0
  92. package/lib/test-suite-lock.ts +1136 -0
  93. package/lib/transcript-checker.ts +1140 -0
  94. package/lib/typescript-project.ts +233 -0
  95. package/lib/validators/spec-validators.ts +171 -0
  96. package/lib/verdict-capture.ts +73 -0
  97. package/lib/verified-push.ts +535 -0
  98. package/lib/workflow-security.ts +174 -0
  99. package/lib/worktree-cleanup.ts +432 -0
  100. package/lib/worktree-collect.ts +283 -0
  101. package/lib/worktree-isolation.ts +82 -0
  102. package/lib/worktree-repo.ts +300 -0
  103. package/package.json +27 -3
  104. package/prompts/ac-adversary.md +14 -2
  105. package/prompts/aditi.md +5 -0
  106. package/prompts/blast-radius.md +5 -0
  107. package/prompts/container-verify.md +5 -0
  108. package/prompts/discovery.md +4 -0
  109. package/prompts/environment.md +5 -0
  110. package/prompts/evidence-hierarchy.md +5 -0
  111. package/prompts/evidence-validator.md +11 -0
  112. package/prompts/marcus.md +5 -0
  113. package/prompts/prevention.md +5 -0
  114. package/prompts/prove-reproducer.md +12 -0
  115. package/prompts/quinn-decision-tree.md +5 -0
  116. package/prompts/quinn-ui-brief.md +5 -0
  117. package/prompts/quinn.md +5 -0
  118. package/prompts/rca.md +5 -0
  119. package/prompts/read-before-write.md +4 -0
  120. package/prompts/regression.md +5 -0
  121. package/prompts/serena.md +5 -0
  122. package/scripts/audit-specs.ts +464 -0
  123. package/scripts/convert-spec.ts +293 -0
  124. package/scripts/create-sc.ts +92 -0
  125. package/scripts/create-spec.ts +166 -0
  126. package/scripts/extract-constraints.ts +4 -3
  127. package/scripts/generate-code-map.ts +1 -1
  128. package/scripts/scaffold-project.ts +138 -1426
  129. package/scripts/sync-spec-tests.ts +211 -126
@@ -0,0 +1,224 @@
1
+ /**
2
+ * Task Completion Quality Checks
3
+ *
4
+ * Quality gates that run before allowing task completion.
5
+ * Used by TaskCompleted hook to ensure work meets minimum standards.
6
+ *
7
+ * Issue: #579
8
+ */
9
+
10
+ import { spawnSync } from 'child_process';
11
+ import { existsSync, readFileSync } from 'fs';
12
+ import { join } from 'path';
13
+
14
+ import { tryLoadRungateConfig } from './config-loader';
15
+
16
+ export interface CompletionCheckResult {
17
+ passed: boolean;
18
+ blockers: string[];
19
+ warnings: string[];
20
+ }
21
+
22
+ /**
23
+ * Run test suite and check for failures.
24
+ * Returns blocker if tests fail, warning if tests can't run.
25
+ */
26
+ export function checkTests(projectRoot: string): CompletionCheckResult {
27
+ const blockers: string[] = [];
28
+ const warnings: string[] = [];
29
+
30
+ try {
31
+ const result = spawnSync('bun', ['test'], {
32
+ cwd: projectRoot,
33
+ encoding: 'utf-8',
34
+ timeout: 120000, // 2 minute timeout
35
+ });
36
+
37
+ // Parse test output for failures
38
+ // Combine stdout and stderr as bun test may use either
39
+ const output = (result.stdout || '') + (result.stderr || '');
40
+ const failMatch = output.match(/(\d+) fail/);
41
+ const passMatch = output.match(/(\d+) pass/);
42
+
43
+ // Check for failures first
44
+ if (failMatch) {
45
+ const failCount = parseInt(failMatch[1], 10);
46
+ if (failCount > 0) {
47
+ blockers.push(`Test suite has ${failCount} failing test(s). Fix failures before completing task.`);
48
+ }
49
+ }
50
+
51
+ // If exit code is non-zero, treat it as a failure even if we can't parse the output
52
+ if (result.status !== 0 && blockers.length === 0) {
53
+ // Look for test failure patterns (not just any error)
54
+ if (output.match(/\(fail\)/i) || output.match(/test.*failed/i)) {
55
+ blockers.push('Test suite failed with errors. Check test output for details.');
56
+ } else if (output.match(/no test files found/i) || output.match(/0 tests/i)) {
57
+ warnings.push('No test files found or tests defined.');
58
+ } else {
59
+ warnings.push('Test command exited with non-zero status, but no explicit failures found.');
60
+ }
61
+ }
62
+
63
+ if (passMatch) {
64
+ const passCount = parseInt(passMatch[1], 10);
65
+ if (passCount === 0 && blockers.length === 0 && result.status === 0) {
66
+ warnings.push('No tests passed — possible test suite issue.');
67
+ }
68
+ }
69
+ } catch (err) {
70
+ warnings.push(`Could not run tests: ${err instanceof Error ? err.message : String(err)}`);
71
+ }
72
+
73
+ return {
74
+ passed: blockers.length === 0,
75
+ blockers,
76
+ warnings,
77
+ };
78
+ }
79
+
80
+ /**
81
+ * Check for uncommitted changes.
82
+ * Returns warning if there are uncommitted files.
83
+ */
84
+ export function checkUncommittedChanges(projectRoot: string): CompletionCheckResult {
85
+ const warnings: string[] = [];
86
+
87
+ try {
88
+ const result = spawnSync('git', ['status', '--porcelain'], {
89
+ cwd: projectRoot,
90
+ encoding: 'utf-8',
91
+ });
92
+
93
+ const output = (result.stdout || '').trim();
94
+ if (output) {
95
+ const lines = output.split('\n');
96
+ warnings.push(`${lines.length} uncommitted file(s). Consider committing work before completing task.`);
97
+ }
98
+ } catch (err) {
99
+ // Not in a git repo or git not available — skip check
100
+ }
101
+
102
+ return {
103
+ passed: true, // Warnings don't block
104
+ blockers: [],
105
+ warnings,
106
+ };
107
+ }
108
+
109
+ /**
110
+ * Run conformity checks if the project is scaffolded.
111
+ * Returns blocker if conformity fails.
112
+ */
113
+ export function checkConformity(projectRoot: string): CompletionCheckResult {
114
+ const blockers: string[] = [];
115
+ const warnings: string[] = [];
116
+
117
+ // Either layout counts as scaffolded. The old existence check named the
118
+ // monolith only, so every consumer that followed the documented migration
119
+ // to `.claude/rungate/` stopped having its conformity suite run here —
120
+ // silently, reporting passed.
121
+ //
122
+ // The throw is CAUGHT and converted to a blocker, which is the one place in
123
+ // this migration that is not simply "let the loader throw". This function is
124
+ // reached from `hooks/TaskCompleted.hook.ts`, which has no catch of its own,
125
+ // and a hook that exits 1 is neither allow (0) nor block (2) — so an
126
+ // escaping throw would disable the entire completion gate, not just this
127
+ // check, on one unparseable byte. Blocking keeps ADR-001 D2's distinction
128
+ // (a corrupt config is never a missing config) and keeps the gate closed.
129
+ let configured: boolean;
130
+ try {
131
+ configured = tryLoadRungateConfig(projectRoot) !== null;
132
+ } catch (err: unknown) {
133
+ // The CLASS, not the message. `JSON.parse` quotes a token from the file it
134
+ // failed on — "Unexpected identifier \"ghp_…\"" — and a config can hold
135
+ // credentials, so the parser's text is a channel out of the file and into
136
+ // this blocker, which is printed to stderr and captured in transcripts.
137
+ // The reproduction command is the replacement for the detail: it gives the
138
+ // operator the full message on their own terminal, where the config
139
+ // already is.
140
+ const kind = err instanceof Error && err.name ? err.name : "error";
141
+ // No runnable command in the text, and the path is JSON-quoted.
142
+ //
143
+ // The first draft printed `bun -e '…${projectRoot}…'` for the operator to
144
+ // paste, which the push review called command injection and is: this is a
145
+ // library function, the root reaches it from the caller, and a path
146
+ // carrying `'; rm -rf ~; '` would have been printed as a command a human
147
+ // is being told to run. A refusal that hands someone a line to paste is
148
+ // an execution path with a person in the middle of it.
149
+ //
150
+ // `JSON.stringify` on the path escapes quotes and newlines, so a crafted
151
+ // root cannot end the sentence and forge a second one either.
152
+ return {
153
+ passed: false,
154
+ blockers: [
155
+ `rungate config under ${JSON.stringify(join(projectRoot, '.claude'))} could not be read ` +
156
+ `(${kind}), so conformity did not run — a config that exists and cannot be parsed is ` +
157
+ `not an unconfigured project. Load that root with loadRungateConfig from ` +
158
+ `lib/config-loader.ts to see the parser's own message.`,
159
+ ],
160
+ warnings: [],
161
+ };
162
+ }
163
+ if (!configured) {
164
+ // No rungate config — skip conformity check
165
+ return { passed: true, blockers: [], warnings: [] };
166
+ }
167
+
168
+ try {
169
+ const result = spawnSync('bun', ['test', 'test/scaffold-conformity.test.ts'], {
170
+ cwd: projectRoot,
171
+ encoding: 'utf-8',
172
+ timeout: 60000, // 1 minute timeout
173
+ });
174
+
175
+ const output = result.stdout || result.stderr || '';
176
+ const failMatch = output.match(/(\d+) fail/);
177
+
178
+ if (failMatch) {
179
+ const failCount = parseInt(failMatch[1], 10);
180
+ if (failCount > 0) {
181
+ blockers.push(`Conformity check has ${failCount} failing check(s). Fix conformity issues before completing task.`);
182
+ }
183
+ }
184
+
185
+ if (result.status !== 0 && blockers.length === 0) {
186
+ warnings.push('Conformity check exited with non-zero status, but no explicit failures found.');
187
+ }
188
+ } catch (err) {
189
+ warnings.push(`Could not run conformity checks: ${err instanceof Error ? err.message : String(err)}`);
190
+ }
191
+
192
+ return {
193
+ passed: blockers.length === 0,
194
+ blockers,
195
+ warnings,
196
+ };
197
+ }
198
+
199
+ /**
200
+ * Run all completion checks and aggregate results.
201
+ */
202
+ export function runAllCompletionChecks(projectRoot: string): CompletionCheckResult {
203
+ const testResult = checkTests(projectRoot);
204
+ const gitResult = checkUncommittedChanges(projectRoot);
205
+ const conformityResult = checkConformity(projectRoot);
206
+
207
+ const allBlockers = [
208
+ ...testResult.blockers,
209
+ ...gitResult.blockers,
210
+ ...conformityResult.blockers,
211
+ ];
212
+
213
+ const allWarnings = [
214
+ ...testResult.warnings,
215
+ ...gitResult.warnings,
216
+ ...conformityResult.warnings,
217
+ ];
218
+
219
+ return {
220
+ passed: allBlockers.length === 0,
221
+ blockers: allBlockers,
222
+ warnings: allWarnings,
223
+ };
224
+ }