critical-gate 2.0.1 → 2.1.1

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 (173) hide show
  1. package/README.md +163 -0
  2. package/dist/cli.d.ts +8 -2
  3. package/dist/cli.d.ts.map +1 -1
  4. package/dist/cli.js +484 -22
  5. package/dist/cli.js.map +1 -1
  6. package/dist/config/critical-gate-config.d.ts +41 -0
  7. package/dist/config/critical-gate-config.d.ts.map +1 -1
  8. package/dist/config/critical-gate-config.js +193 -4
  9. package/dist/config/critical-gate-config.js.map +1 -1
  10. package/dist/config/index.d.ts +2 -1
  11. package/dist/config/index.d.ts.map +1 -1
  12. package/dist/config/index.js +2 -1
  13. package/dist/config/index.js.map +1 -1
  14. package/dist/config/learning-policy.d.ts +9 -0
  15. package/dist/config/learning-policy.d.ts.map +1 -0
  16. package/dist/config/learning-policy.js +34 -0
  17. package/dist/config/learning-policy.js.map +1 -0
  18. package/dist/detectors/api-surface-detector.d.ts.map +1 -1
  19. package/dist/detectors/api-surface-detector.js +123 -5
  20. package/dist/detectors/api-surface-detector.js.map +1 -1
  21. package/dist/detectors/confidence-calibration.d.ts +11 -0
  22. package/dist/detectors/confidence-calibration.d.ts.map +1 -0
  23. package/dist/detectors/confidence-calibration.js +53 -0
  24. package/dist/detectors/confidence-calibration.js.map +1 -0
  25. package/dist/detectors/existing-solution-detector.js +6 -0
  26. package/dist/detectors/existing-solution-detector.js.map +1 -1
  27. package/dist/detectors/expected-companions-detector.d.ts.map +1 -1
  28. package/dist/detectors/expected-companions-detector.js +208 -10
  29. package/dist/detectors/expected-companions-detector.js.map +1 -1
  30. package/dist/detectors/index.d.ts +1 -0
  31. package/dist/detectors/index.d.ts.map +1 -1
  32. package/dist/detectors/index.js +1 -0
  33. package/dist/detectors/index.js.map +1 -1
  34. package/dist/detectors/intent-verification-detector.d.ts.map +1 -1
  35. package/dist/detectors/intent-verification-detector.js +64 -1
  36. package/dist/detectors/intent-verification-detector.js.map +1 -1
  37. package/dist/detectors/reason-chain.d.ts +4 -0
  38. package/dist/detectors/reason-chain.d.ts.map +1 -0
  39. package/dist/detectors/reason-chain.js +102 -0
  40. package/dist/detectors/reason-chain.js.map +1 -0
  41. package/dist/detectors/repair-contract.d.ts +4 -0
  42. package/dist/detectors/repair-contract.d.ts.map +1 -0
  43. package/dist/detectors/repair-contract.js +45 -0
  44. package/dist/detectors/repair-contract.js.map +1 -0
  45. package/dist/detectors/repository-intelligence-detector.d.ts.map +1 -1
  46. package/dist/detectors/repository-intelligence-detector.js +17 -4
  47. package/dist/detectors/repository-intelligence-detector.js.map +1 -1
  48. package/dist/detectors/rewrite-detector.d.ts.map +1 -1
  49. package/dist/detectors/rewrite-detector.js +5 -2
  50. package/dist/detectors/rewrite-detector.js.map +1 -1
  51. package/dist/detectors/runner.d.ts +1 -0
  52. package/dist/detectors/runner.d.ts.map +1 -1
  53. package/dist/detectors/runner.js +50 -3
  54. package/dist/detectors/runner.js.map +1 -1
  55. package/dist/detectors/scope-detector.d.ts.map +1 -1
  56. package/dist/detectors/scope-detector.js +1 -8
  57. package/dist/detectors/scope-detector.js.map +1 -1
  58. package/dist/detectors/secret-path-detector.js +1 -1
  59. package/dist/detectors/secret-path-detector.js.map +1 -1
  60. package/dist/detectors/test-weakening-detector.d.ts.map +1 -1
  61. package/dist/detectors/test-weakening-detector.js +188 -39
  62. package/dist/detectors/test-weakening-detector.js.map +1 -1
  63. package/dist/detectors/types.d.ts +2 -0
  64. package/dist/detectors/types.d.ts.map +1 -1
  65. package/dist/diff/git-diff-reader.d.ts +1 -0
  66. package/dist/diff/git-diff-reader.d.ts.map +1 -1
  67. package/dist/diff/git-diff-reader.js +6 -3
  68. package/dist/diff/git-diff-reader.js.map +1 -1
  69. package/dist/diff/path-classifier.d.ts.map +1 -1
  70. package/dist/diff/path-classifier.js +9 -1
  71. package/dist/diff/path-classifier.js.map +1 -1
  72. package/dist/frameworks/detect.d.ts +11 -0
  73. package/dist/frameworks/detect.d.ts.map +1 -0
  74. package/dist/frameworks/detect.js +29 -0
  75. package/dist/frameworks/detect.js.map +1 -0
  76. package/dist/frameworks/index.d.ts +5 -0
  77. package/dist/frameworks/index.d.ts.map +1 -0
  78. package/dist/frameworks/index.js +4 -0
  79. package/dist/frameworks/index.js.map +1 -0
  80. package/dist/frameworks/packs.d.ts +3 -0
  81. package/dist/frameworks/packs.d.ts.map +1 -0
  82. package/dist/frameworks/packs.js +146 -0
  83. package/dist/frameworks/packs.js.map +1 -0
  84. package/dist/frameworks/path-patterns.d.ts +3 -0
  85. package/dist/frameworks/path-patterns.d.ts.map +1 -0
  86. package/dist/frameworks/path-patterns.js +16 -0
  87. package/dist/frameworks/path-patterns.js.map +1 -0
  88. package/dist/frameworks/types.d.ts +15 -0
  89. package/dist/frameworks/types.d.ts.map +1 -0
  90. package/dist/frameworks/types.js +2 -0
  91. package/dist/frameworks/types.js.map +1 -0
  92. package/dist/index.d.ts +2 -0
  93. package/dist/index.d.ts.map +1 -1
  94. package/dist/index.js +2 -0
  95. package/dist/index.js.map +1 -1
  96. package/dist/intent/diff-coherence-score.d.ts +13 -0
  97. package/dist/intent/diff-coherence-score.d.ts.map +1 -0
  98. package/dist/intent/diff-coherence-score.js +125 -0
  99. package/dist/intent/diff-coherence-score.js.map +1 -0
  100. package/dist/intent/index.d.ts +2 -0
  101. package/dist/intent/index.d.ts.map +1 -1
  102. package/dist/intent/index.js +2 -0
  103. package/dist/intent/index.js.map +1 -1
  104. package/dist/intent/intent-core.d.ts.map +1 -1
  105. package/dist/intent/intent-core.js +17 -1
  106. package/dist/intent/intent-core.js.map +1 -1
  107. package/dist/intent/intent-model.d.ts.map +1 -1
  108. package/dist/intent/intent-model.js +39 -2
  109. package/dist/intent/intent-model.js.map +1 -1
  110. package/dist/intent/task-intent-quality.d.ts +4 -0
  111. package/dist/intent/task-intent-quality.d.ts.map +1 -0
  112. package/dist/intent/task-intent-quality.js +98 -0
  113. package/dist/intent/task-intent-quality.js.map +1 -0
  114. package/dist/knowledge/history-index.d.ts.map +1 -1
  115. package/dist/knowledge/history-index.js +10 -3
  116. package/dist/knowledge/history-index.js.map +1 -1
  117. package/dist/knowledge/index.d.ts +2 -1
  118. package/dist/knowledge/index.d.ts.map +1 -1
  119. package/dist/knowledge/index.js +1 -0
  120. package/dist/knowledge/index.js.map +1 -1
  121. package/dist/knowledge/normal-change-model.d.ts +8 -0
  122. package/dist/knowledge/normal-change-model.d.ts.map +1 -0
  123. package/dist/knowledge/normal-change-model.js +121 -0
  124. package/dist/knowledge/normal-change-model.js.map +1 -0
  125. package/dist/knowledge/solution-index.d.ts.map +1 -1
  126. package/dist/knowledge/solution-index.js +43 -3
  127. package/dist/knowledge/solution-index.js.map +1 -1
  128. package/dist/knowledge/types.d.ts +11 -0
  129. package/dist/knowledge/types.d.ts.map +1 -1
  130. package/dist/reporters/index.d.ts +4 -1
  131. package/dist/reporters/index.d.ts.map +1 -1
  132. package/dist/reporters/index.js +6 -0
  133. package/dist/reporters/index.js.map +1 -1
  134. package/dist/reporters/markdown-reporter.d.ts.map +1 -1
  135. package/dist/reporters/markdown-reporter.js +67 -0
  136. package/dist/reporters/markdown-reporter.js.map +1 -1
  137. package/dist/reporters/pr-comment-reporter.d.ts +3 -0
  138. package/dist/reporters/pr-comment-reporter.d.ts.map +1 -0
  139. package/dist/reporters/pr-comment-reporter.js +105 -0
  140. package/dist/reporters/pr-comment-reporter.js.map +1 -0
  141. package/dist/reporters/repair-contract.d.ts +3 -0
  142. package/dist/reporters/repair-contract.d.ts.map +1 -0
  143. package/dist/reporters/repair-contract.js +25 -0
  144. package/dist/reporters/repair-contract.js.map +1 -0
  145. package/dist/reporters/repair-reporter.d.ts.map +1 -1
  146. package/dist/reporters/repair-reporter.js +19 -1
  147. package/dist/reporters/repair-reporter.js.map +1 -1
  148. package/dist/reporters/reviewer-checklist.d.ts +10 -0
  149. package/dist/reporters/reviewer-checklist.d.ts.map +1 -0
  150. package/dist/reporters/reviewer-checklist.js +112 -0
  151. package/dist/reporters/reviewer-checklist.js.map +1 -0
  152. package/dist/repository/api-snapshot.d.ts +41 -0
  153. package/dist/repository/api-snapshot.d.ts.map +1 -0
  154. package/dist/repository/api-snapshot.js +219 -0
  155. package/dist/repository/api-snapshot.js.map +1 -0
  156. package/dist/repository/index.d.ts +2 -0
  157. package/dist/repository/index.d.ts.map +1 -1
  158. package/dist/repository/index.js +2 -0
  159. package/dist/repository/index.js.map +1 -1
  160. package/dist/repository/monorepo.d.ts +7 -0
  161. package/dist/repository/monorepo.d.ts.map +1 -0
  162. package/dist/repository/monorepo.js +189 -0
  163. package/dist/repository/monorepo.js.map +1 -0
  164. package/dist/schema/gate-result.schema.d.ts +272 -0
  165. package/dist/schema/gate-result.schema.d.ts.map +1 -1
  166. package/dist/schema/gate-result.schema.js +148 -1
  167. package/dist/schema/gate-result.schema.js.map +1 -1
  168. package/dist/schema/index.d.ts +1 -1
  169. package/dist/schema/index.d.ts.map +1 -1
  170. package/dist/schema/index.js.map +1 -1
  171. package/dist/schema/types.d.ts +63 -0
  172. package/dist/schema/types.d.ts.map +1 -1
  173. package/package.json +1 -1
package/README.md CHANGED
@@ -36,6 +36,157 @@ Current detectors focus on TypeScript and JavaScript repositories:
36
36
  Every finding includes severity, confidence, evidence, tags, and a repair hint that another agent or
37
37
  developer can act on.
38
38
 
39
+ ## Concrete Examples
40
+
41
+ Critical Gate is most useful when an AI-generated diff looks plausible at a glance but breaks the
42
+ shape of the task.
43
+
44
+ ### Dependency Drift
45
+
46
+ Task:
47
+
48
+ ```text
49
+ Add CSV export using the existing file writer utilities.
50
+ ```
51
+
52
+ Risky diff:
53
+
54
+ - Adds `papaparse` or another production dependency.
55
+ - Changes `package.json` and the lockfile.
56
+ - Does not document why the existing repository utilities are insufficient.
57
+
58
+ What Critical Gate reports:
59
+
60
+ - The manifest changed.
61
+ - A dependency was added.
62
+ - The task did not ask for a dependency.
63
+ - Repair guidance asks the agent to remove the package, use existing utilities, or add explicit
64
+ justification.
65
+
66
+ ### Test Weakening
67
+
68
+ Task:
69
+
70
+ ```text
71
+ Refactor signup validation internals without changing behavior.
72
+ ```
73
+
74
+ Risky diff:
75
+
76
+ ```diff
77
+ - expect(result.error.message).toContain("email is required");
78
+ + expect(result.error).toBeDefined();
79
+ ```
80
+
81
+ What Critical Gate reports:
82
+
83
+ - A behavioral assertion became a generic existence assertion.
84
+ - The replacement is less specific even though the test still passes.
85
+ - Repair guidance asks for an equally specific behavioral assertion.
86
+
87
+ ### Unrelated Edits
88
+
89
+ Task:
90
+
91
+ ```text
92
+ Fix font weight in the profile heading.
93
+ ```
94
+
95
+ Risky diff:
96
+
97
+ - Changes the intended stylesheet.
98
+ - Also rewrites unrelated layout files.
99
+ - Touches CI config or package metadata.
100
+
101
+ What Critical Gate reports:
102
+
103
+ - The changed files do not fit the small task boundary.
104
+ - Diff Cost Score and Scope Expansion Score increase.
105
+ - Repair guidance asks to split unrelated edits or expand the task explicitly.
106
+
107
+ ### Utility Reinvention
108
+
109
+ Task:
110
+
111
+ ```text
112
+ Add signup date formatting.
113
+ ```
114
+
115
+ Risky diff:
116
+
117
+ ```ts
118
+ export function formatDateForSignup(value: Date): string {
119
+ return value.toISOString();
120
+ }
121
+ ```
122
+
123
+ when the repository already has:
124
+
125
+ ```ts
126
+ export function formatDate(value: Date): string;
127
+ ```
128
+
129
+ What Critical Gate reports:
130
+
131
+ - A similar exported helper already exists.
132
+ - Evidence includes existing export name, signature shape, folder role, path, and import count.
133
+ - Repair guidance points the agent toward reuse instead of another local abstraction.
134
+
135
+ ### Public API Changes
136
+
137
+ Task:
138
+
139
+ ```text
140
+ Improve internal validation.
141
+ ```
142
+
143
+ Risky diff:
144
+
145
+ ```diff
146
+ - export interface SignupOptions {}
147
+ + interface SignupOptions {}
148
+ ```
149
+
150
+ What Critical Gate reports:
151
+
152
+ - A public export was removed without task or release evidence.
153
+ - If `.critical-gate/api-surface.json` exists, the finding cites the snapshotted public contract.
154
+ - Repair guidance asks for restore, migration notes, changelog/changeset evidence, or an updated API
155
+ snapshot.
156
+
157
+ ### Clean Diff Certification
158
+
159
+ When the gate passes, the Markdown report still explains what was checked:
160
+
161
+ - Changed file count and churn.
162
+ - Diff Coherence Score.
163
+ - Dependency discipline.
164
+ - Test integrity.
165
+ - Public API surface.
166
+ - Secret/path checks.
167
+
168
+ This makes clean runs useful in PRs and agent handoffs instead of just saying “no findings.”
169
+
170
+ ## Positioning
171
+
172
+ Critical Gate is adjacent to linters, test suites, security scanners, and AI code review tools, but
173
+ it is not trying to replace them.
174
+
175
+ - **Linters and formatters** enforce code style and static rules. Critical Gate checks whether the
176
+ diff stayed inside the task and repository contract.
177
+ - **Test suites** prove selected behavior still passes. Critical Gate looks for tests that were
178
+ weakened, skipped, or changed to assert less meaningful behavior.
179
+ - **Security scanners** look for known vulnerabilities or secrets. Critical Gate includes lightweight
180
+ diff-only secret/path checks but focuses on agent failure patterns beyond security.
181
+ - **AI code reviewers** often produce broad suggestions. Critical Gate is deterministic-first and
182
+ evidence-first; optional model help is for explanation, not primary detection.
183
+ - **CI checks** usually answer whether the project builds. Critical Gate answers whether the diff is
184
+ acceptable for the task before it is merged.
185
+
186
+ The category is a **diff integrity gate for AI-assisted development**: a cheap, local, repository-
187
+ aware enforcement layer that catches high-risk agent behavior before humans have to infer it from a
188
+ large patch.
189
+
39
190
  ## Surfaces
40
191
 
41
192
  Critical Gate has one analysis core and multiple surfaces:
@@ -78,6 +229,17 @@ node dist/cli.js check --task "Add signup validation" --format sarif --output cr
78
229
  node dist/cli.js check --task "Add signup validation" --format repair
79
230
  ```
80
231
 
232
+ Create a public API contract snapshot for repositories that expose TS/JS entrypoints:
233
+
234
+ ```bash
235
+ node dist/cli.js snapshot-api
236
+ git add .critical-gate/api-surface.json
237
+ ```
238
+
239
+ After the snapshot is committed, normal `check` runs compare export removals, additions, and
240
+ signature changes against it. Public contract changes should include snapshot, changelog, changeset,
241
+ or migration evidence.
242
+
81
243
  Exit codes:
82
244
 
83
245
  - `0`: gate passed.
@@ -226,6 +388,7 @@ Branch and commit conventions for this repository:
226
388
  - [docs/github-integration.md](docs/github-integration.md): GitHub Action, SARIF, and threshold guidance.
227
389
  - [docs/codex-integration.md](docs/codex-integration.md): Codex hook and repair-loop guidance.
228
390
  - [docs/versioning-policy.md](docs/versioning-policy.md): release and versioning policy.
391
+ - [docs/improvements-task-plan.md](docs/improvements-task-plan.md): trust and calibration roadmap.
229
392
  - [CHANGELOG.md](CHANGELOG.md): project-level release notes.
230
393
 
231
394
  ## Project Status
package/dist/cli.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import { type GitDiffResult } from "./index.js";
3
- export declare const CLI_VERSION = "2.0.1";
3
+ export declare const CLI_VERSION = "2.1.1";
4
4
  export declare const ExitCode: {
5
5
  readonly Pass: 0;
6
6
  readonly FindingsFailed: 1;
@@ -12,9 +12,15 @@ interface CliIo {
12
12
  stdout: (message: string) => void;
13
13
  stderr: (message: string) => void;
14
14
  writeFile: (path: string, content: string) => void;
15
+ chmodFile?: (path: string, mode: number) => void;
15
16
  now: () => Date;
16
- readDiff: (baseRef?: string) => GitDiffResult;
17
+ readDiff: (baseRef?: string, options?: {
18
+ staged?: boolean;
19
+ }) => GitDiffResult;
20
+ exists?: (path: string) => boolean;
21
+ readFile?: (path: string) => string;
17
22
  }
18
23
  export declare function main(argv?: string[], io?: CliIo): ExitCode;
24
+ export declare function isCliEntrypoint(importMetaUrl: string, argvPath?: string): boolean;
19
25
  export {};
20
26
  //# sourceMappingURL=cli.d.ts.map
package/dist/cli.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAMA,OAAO,EASL,KAAK,aAAa,EAEnB,MAAM,YAAY,CAAC;AAEpB,eAAO,MAAM,WAAW,UAAU,CAAC;AAEnC,eAAO,MAAM,QAAQ;;;;;CAKX,CAAC;AAEX,MAAM,MAAM,QAAQ,GAAG,CAA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