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,165 @@
1
+ /**
2
+ * The generated `.git/hooks/pre-push`, as one binding (#397).
3
+ *
4
+ * It lived as a template literal inside `createGitHooks`, where nothing could
5
+ * run it. The hook is a shell script with an exit code, so
6
+ * `.claude/rules/checks-must-be-able-to-fail.md`'s worked pattern applies
7
+ * directly: route every refusal through one exit-code constant and drive the
8
+ * script against planted fixture repositories. That is what
9
+ * `test/pre-push-hook.test.ts` does, and it is why this is a module rather
10
+ * than a string in the middle of a 2,400-line generator.
11
+ *
12
+ * ## What was wrong
13
+ *
14
+ * The hook could not PASS in any consumer whose `bun.lock` is gitignored, and
15
+ * it failed closed with "Conformity tests failed against the commits being
16
+ * pushed" — which is not what happened. Found on agentgrit on 2026-10-14
17
+ * with conformity at 43 pass, 0 fail in the working tree and the push
18
+ * rejected.
19
+ *
20
+ * The lockfile comparison read `$tmp/bun.lock`, which comes from the git
21
+ * checkout. A gitignored lockfile is never in the checkout, so the `cmp`
22
+ * branch could not be taken and every push fell through to
23
+ * `bun install --frozen-lockfile` with no lockfile to freeze against. For a
24
+ * consumer with a `file:` or `link:` dependency on a sibling directory it
25
+ * then failed a second, independent way: a relative path does not resolve
26
+ * from `/tmp`.
27
+ *
28
+ * `.claude/rules/checks-must-be-able-to-fail.md` is about guards that cannot
29
+ * fail. This is the inverse and the damage is the same shape, because the
30
+ * message is wrong either way — a developer reading "conformity failed" goes
31
+ * and looks at conformity, which is green.
32
+ *
33
+ * ## The three outcomes, and why UNMEASURED blocks
34
+ *
35
+ * | what happened | exit | message |
36
+ * |---|---|---|
37
+ * | conformity ran and failed | refuse | the conformity message |
38
+ * | the suite could not be run at all | refuse | UNMEASURED, naming the cause |
39
+ * | conformity ran and passed | 0 | — |
40
+ *
41
+ * UNMEASURED blocks, and that is a decision rather than an accident of
42
+ * control flow. A pre-push gate that waves a commit through when it could not
43
+ * check is the fail-open this repo keeps finding; `SKIP` is indistinguishable
44
+ * from success and `UNMEASURED` is not
45
+ * (`.claude/rules/config-access.md`). What makes it tolerable is that it says
46
+ * which of the two happened and names `--no-verify` itself, so the developer
47
+ * is not hunting a green suite for a failure that never occurred.
48
+ */
49
+
50
+ /** The ONE exit code every refusal routes through. Asserted to appear once. */
51
+ export const PRE_PUSH_REFUSE_EXIT = 1;
52
+
53
+ export const PRE_PUSH_MANAGED_MARKER = "# Managed by rungate — conformity check before push";
54
+
55
+ /**
56
+ * The conformity suite the hook runs. One literal, so the test that plants a
57
+ * passing and a failing fixture writes the same path the hook reads.
58
+ */
59
+ export const PRE_PUSH_SUITE = "test/scaffold-conformity.test.ts";
60
+
61
+ export function prePushHookScript(): string {
62
+ return `#!/bin/sh
63
+ ${PRE_PUSH_MANAGED_MARKER}
64
+ #
65
+ # Three outcomes, not two: conformity FAILED, conformity could not be RUN,
66
+ # and conformity passed. The first two used to share a message and a status
67
+ # variable, so an install that could not happen was reported as a test that
68
+ # did not pass (#397).
69
+ REFUSE=${PRE_PUSH_REFUSE_EXIT}
70
+ ZERO=0000000000000000000000000000000000000000
71
+ TOPLEVEL=$(git rev-parse --show-toplevel) || exit $REFUSE
72
+ conformity=0
73
+ unmeasured=0
74
+ why=""
75
+
76
+ while read -r _lref lsha _rref _rsha; do
77
+ # Branch deletion: there is no commit to check out.
78
+ [ "$lsha" = "$ZERO" ] && continue
79
+
80
+ tmp=$(mktemp -d) || exit $REFUSE
81
+ if ! git worktree add --detach --quiet "$tmp" "$lsha"; then
82
+ unmeasured=1
83
+ why="the pushed commit $lsha could not be checked out"
84
+ rm -rf "$tmp"
85
+ break
86
+ fi
87
+
88
+ # Which node_modules the pushed commit expects.
89
+ #
90
+ # The old test was \`[ -f "$tmp/bun.lock" ] && cmp -s ...\`, which treats "the
91
+ # checkout has no lockfile" as "the dependencies differ" and installs. But a
92
+ # lockfile absent from the checkout is a lockfile git does not track — it is
93
+ # gitignored, or the project has none — and then there is nothing in this
94
+ # push that can change the dependency graph. The working tree's modules are
95
+ # the right ones by definition, and installing is both slower and less
96
+ # accurate.
97
+ if [ ! -f "$tmp/bun.lock" ]; then
98
+ ln -s "$TOPLEVEL/node_modules" "$tmp/node_modules" 2>/dev/null
99
+ elif [ -f "$TOPLEVEL/bun.lock" ] && cmp -s "$TOPLEVEL/bun.lock" "$tmp/bun.lock"; then
100
+ ln -s "$TOPLEVEL/node_modules" "$tmp/node_modules" 2>/dev/null
101
+ else
102
+ echo "pre-push: dependencies differ from the working tree — installing from the pushed lockfile" >&2
103
+ if ! ( cd "$tmp" && bun install --frozen-lockfile ) >&2; then
104
+ # NOT a conformity result. A relative \`file:\`/\`link:\` dependency does
105
+ # not resolve from a temp directory, and a lockfile that cannot be
106
+ # frozen is an environment fault in this hook's own sandbox.
107
+ unmeasured=1
108
+ why="dependencies could not be installed in the temporary checkout"
109
+ fi
110
+ fi
111
+
112
+ if [ "$unmeasured" -eq 0 ]; then
113
+ out=$( cd "$tmp" && bun test ${PRE_PUSH_SUITE} 2>&1 )
114
+ rc=$?
115
+ echo "$out" >&2
116
+
117
+ # A suite that FAILED and a suite that never RAN both exit non-zero: a
118
+ # missing file, an unresolvable import, and a red assertion are one exit
119
+ # code. Two things in bun's summary tell them apart, and both are needed.
120
+ #
121
+ # Counted tests. The summary prints \`N pass\` / \`N fail\`; a file that is
122
+ # not there prints neither. Zero counted tests is UNMEASURED even when the
123
+ # exit code is 0, because a suite passing vacuously is exactly what
124
+ # .claude/rules/checks-must-be-able-to-fail.md exists to catch.
125
+ #
126
+ # Counted ERRORS. A module that will not resolve is reported as \`1 fail\`
127
+ # AND \`1 error\` — measured on bun 1.3.14 — so the counted-tests test
128
+ # alone calls it a conformity failure, which is the wrong half of the
129
+ # distinction this hook exists to draw. A red assertion prints no error
130
+ # line at all. An unhandled error between tests means the suite did not
131
+ # run as written, whatever the fail count says.
132
+ if echo "$out" | grep -qE '^[[:space:]]*[1-9][0-9]* error'; then
133
+ unmeasured=1
134
+ why="the conformity suite did not load (an unhandled error, usually an import that will not resolve)"
135
+ elif echo "$out" | grep -qE '^[[:space:]]*[1-9][0-9]* (pass|fail)'; then
136
+ [ "$rc" -ne 0 ] && conformity=1
137
+ else
138
+ unmeasured=1
139
+ why="the conformity suite ran no tests (the file is not in the pushed commit, or it declares none)"
140
+ fi
141
+ fi
142
+
143
+ # Always clean up. An early exit here would leak a worktree on every failed
144
+ # push, which is how #68 reached 39 stale worktrees and 243 MB.
145
+ git worktree remove --force "$tmp" 2>/dev/null
146
+ rm -rf "$tmp"
147
+
148
+ [ "$conformity" -ne 0 ] && break
149
+ [ "$unmeasured" -ne 0 ] && break
150
+ done
151
+
152
+ if [ "$unmeasured" -ne 0 ]; then
153
+ echo "ERROR: pre-push did NOT run the conformity suite — $why." >&2
154
+ echo " This is UNMEASURED, not a test failure: your conformity tests may be green." >&2
155
+ echo " Fix the cause, or push with --no-verify once you have run" >&2
156
+ echo " \\\`bun test ${PRE_PUSH_SUITE}\\\` in the real tree yourself." >&2
157
+ exit $REFUSE
158
+ fi
159
+ if [ "$conformity" -ne 0 ]; then
160
+ echo "ERROR: Conformity tests failed against the commits being pushed — fix before pushing" >&2
161
+ exit $REFUSE
162
+ fi
163
+ exit 0
164
+ `;
165
+ }