repometry 0.0.0-stage → 0.1.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 (280) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +27 -2
  3. package/package.json +63 -4
  4. package/target/main/resources/report/json/compact-json-v1.schema.json +24 -0
  5. package/target/main/resources/report/json/comparison-v1.schema.json +65 -0
  6. package/target/main/resources/report/json/config-v1.schema.json +34 -0
  7. package/target/main/resources/report/json/diff-coverage-v1.schema.json +55 -0
  8. package/target/main/resources/report/json/file-metrics-v1.schema.json +134 -0
  9. package/target/main/resources/report/json/inspection-context-v1.schema.json +172 -0
  10. package/target/main/resources/report/json/metabranch-v1.schema.json +9 -0
  11. package/target/main/resources/report/json/metric-catalog-v1.schema.json +31 -0
  12. package/target/main/resources/report/json/public-history-v1.schema.json +50 -0
  13. package/target/main/resources/report/json/pull-review-v1.schema.json +97 -0
  14. package/target/main/resources/report/json/quality-history-v1.schema.json +51 -0
  15. package/target/main/resources/report/json/report-v1.schema.json +65 -0
  16. package/target/main/resources/report/json/report-v2.schema.json +238 -0
  17. package/target/main/resources/report/json/repository-summary-v1.schema.json +181 -0
  18. package/target/main/resources/report/json/viewer-details-v1.schema.json +343 -0
  19. package/target/main/resources/report/json/viewer-inspection-v1.schema.json +13 -0
  20. package/target/main/resources/viewer/files.css +578 -0
  21. package/target/main/resources/viewer/index.html +130 -0
  22. package/target/main/resources/viewer/projects.html +52 -0
  23. package/target/main/resources/viewer/styles.css +586 -0
  24. package/target/main/resources/viewer/viewer-pulls.css +64 -0
  25. package/target/main/ts/api/gh/github-pr-comment.d.ts +4 -0
  26. package/target/main/ts/api/gh/github-pr-comment.js +107 -0
  27. package/target/main/ts/api/gh/github.d.ts +6 -0
  28. package/target/main/ts/api/gh/github.js +91 -0
  29. package/target/main/ts/api/git/blob-batch.d.ts +10 -0
  30. package/target/main/ts/api/git/blob-batch.js +105 -0
  31. package/target/main/ts/api/git/changes.d.ts +22 -0
  32. package/target/main/ts/api/git/changes.js +107 -0
  33. package/target/main/ts/api/git/commit-metadata.d.ts +3 -0
  34. package/target/main/ts/api/git/commit-metadata.js +54 -0
  35. package/target/main/ts/api/git/git-churn.d.ts +9 -0
  36. package/target/main/ts/api/git/git-churn.js +70 -0
  37. package/target/main/ts/api/git/git-reader.d.ts +16 -0
  38. package/target/main/ts/api/git/git-reader.js +73 -0
  39. package/target/main/ts/api/git/git.d.ts +21 -0
  40. package/target/main/ts/api/git/git.js +152 -0
  41. package/target/main/ts/api/git/inspection-source.d.ts +15 -0
  42. package/target/main/ts/api/git/inspection-source.js +30 -0
  43. package/target/main/ts/api/git/local-sources.d.ts +5 -0
  44. package/target/main/ts/api/git/local-sources.js +46 -0
  45. package/target/main/ts/api/git/local.d.ts +3 -0
  46. package/target/main/ts/api/git/local.js +35 -0
  47. package/target/main/ts/api/git/metabranch-worktree.d.ts +1 -0
  48. package/target/main/ts/api/git/metabranch-worktree.js +34 -0
  49. package/target/main/ts/api/git/source-cache.d.ts +3 -0
  50. package/target/main/ts/api/git/source-cache.js +56 -0
  51. package/target/main/ts/api/import/finding-import.d.ts +9 -0
  52. package/target/main/ts/api/import/finding-import.js +226 -0
  53. package/target/main/ts/api/import/lcov-files.d.ts +5 -0
  54. package/target/main/ts/api/import/lcov-files.js +13 -0
  55. package/target/main/ts/api/import/profile-file.d.ts +4 -0
  56. package/target/main/ts/api/import/profile-file.js +16 -0
  57. package/target/main/ts/api/worker/remote-executor.d.ts +2 -0
  58. package/target/main/ts/api/worker/remote-executor.js +45 -0
  59. package/target/main/ts/api/worker/worker-protocol.d.ts +7 -0
  60. package/target/main/ts/api/worker/worker-protocol.js +101 -0
  61. package/target/main/ts/api/worker/worker.d.ts +5 -0
  62. package/target/main/ts/api/worker/worker.js +85 -0
  63. package/target/main/ts/cli/arguments.d.ts +28 -0
  64. package/target/main/ts/cli/arguments.js +110 -0
  65. package/target/main/ts/cli/config.d.ts +14 -0
  66. package/target/main/ts/cli/config.js +60 -0
  67. package/target/main/ts/cli/github-pr-comment.d.ts +1 -0
  68. package/target/main/ts/cli/github-pr-comment.js +12 -0
  69. package/target/main/ts/cli/imports.d.ts +7 -0
  70. package/target/main/ts/cli/imports.js +29 -0
  71. package/target/main/ts/cli/main.d.ts +2 -0
  72. package/target/main/ts/cli/main.js +378 -0
  73. package/target/main/ts/cli/reporting.d.ts +18 -0
  74. package/target/main/ts/cli/reporting.js +108 -0
  75. package/target/main/ts/cli/revisions.d.ts +6 -0
  76. package/target/main/ts/cli/revisions.js +15 -0
  77. package/target/main/ts/cli/store.d.ts +13 -0
  78. package/target/main/ts/cli/store.js +38 -0
  79. package/target/main/ts/compose/analyze-snapshot.d.ts +4 -0
  80. package/target/main/ts/compose/analyze-snapshot.js +163 -0
  81. package/target/main/ts/compose/attach-churn.d.ts +2 -0
  82. package/target/main/ts/compose/attach-churn.js +37 -0
  83. package/target/main/ts/compose/diff-coverage.d.ts +20 -0
  84. package/target/main/ts/compose/diff-coverage.js +56 -0
  85. package/target/main/ts/compose/inspect.d.ts +23 -0
  86. package/target/main/ts/compose/inspect.js +44 -0
  87. package/target/main/ts/compose/plugin-list.d.ts +6 -0
  88. package/target/main/ts/compose/plugin-list.js +9 -0
  89. package/target/main/ts/compose/prepare-metabranch.d.ts +9 -0
  90. package/target/main/ts/compose/prepare-metabranch.js +16 -0
  91. package/target/main/ts/compose/review.d.ts +16 -0
  92. package/target/main/ts/compose/review.js +38 -0
  93. package/target/main/ts/compose/sources.d.ts +3 -0
  94. package/target/main/ts/compose/sources.js +29 -0
  95. package/target/main/ts/core/engine/execute.d.ts +10 -0
  96. package/target/main/ts/core/engine/execute.js +49 -0
  97. package/target/main/ts/core/engine/manifest.d.ts +4 -0
  98. package/target/main/ts/core/engine/manifest.js +104 -0
  99. package/target/main/ts/core/engine/plan.d.ts +22 -0
  100. package/target/main/ts/core/engine/plan.js +106 -0
  101. package/target/main/ts/core/engine/plugin.d.ts +59 -0
  102. package/target/main/ts/core/engine/plugin.js +4 -0
  103. package/target/main/ts/core/engine/report-products.d.ts +16 -0
  104. package/target/main/ts/core/engine/report-products.js +85 -0
  105. package/target/main/ts/core/model/changes.d.ts +8 -0
  106. package/target/main/ts/core/model/changes.js +1 -0
  107. package/target/main/ts/core/model/churn.d.ts +11 -0
  108. package/target/main/ts/core/model/churn.js +5 -0
  109. package/target/main/ts/core/model/clone-source.d.ts +16 -0
  110. package/target/main/ts/core/model/clone-source.js +14 -0
  111. package/target/main/ts/core/model/code-structure.d.ts +30 -0
  112. package/target/main/ts/core/model/code-structure.js +31 -0
  113. package/target/main/ts/core/model/comparison.d.ts +24 -0
  114. package/target/main/ts/core/model/comparison.js +1 -0
  115. package/target/main/ts/core/model/diff-coverage.d.ts +23 -0
  116. package/target/main/ts/core/model/diff-coverage.js +1 -0
  117. package/target/main/ts/core/model/finding-ignore.d.ts +8 -0
  118. package/target/main/ts/core/model/finding-ignore.js +35 -0
  119. package/target/main/ts/core/model/finding.d.ts +28 -0
  120. package/target/main/ts/core/model/finding.js +29 -0
  121. package/target/main/ts/core/model/ignore-rule.d.ts +11 -0
  122. package/target/main/ts/core/model/ignore-rule.js +1 -0
  123. package/target/main/ts/core/model/measurement.d.ts +27 -0
  124. package/target/main/ts/core/model/measurement.js +24 -0
  125. package/target/main/ts/core/model/metric-descriptor.d.ts +17 -0
  126. package/target/main/ts/core/model/metric-descriptor.js +1 -0
  127. package/target/main/ts/core/model/plugin-data.d.ts +25 -0
  128. package/target/main/ts/core/model/plugin-data.js +1 -0
  129. package/target/main/ts/core/model/pull-review.d.ts +48 -0
  130. package/target/main/ts/core/model/pull-review.js +1 -0
  131. package/target/main/ts/core/model/quality-summary.d.ts +42 -0
  132. package/target/main/ts/core/model/quality-summary.js +64 -0
  133. package/target/main/ts/core/model/report.d.ts +32 -0
  134. package/target/main/ts/core/model/report.js +5 -0
  135. package/target/main/ts/core/model/scanner-import.d.ts +39 -0
  136. package/target/main/ts/core/model/scanner-import.js +28 -0
  137. package/target/main/ts/core/model/snapshot.d.ts +15 -0
  138. package/target/main/ts/core/model/snapshot.js +50 -0
  139. package/target/main/ts/core/model/source-locator.d.ts +7 -0
  140. package/target/main/ts/core/model/source-locator.js +1 -0
  141. package/target/main/ts/core/model/source.d.ts +23 -0
  142. package/target/main/ts/core/model/source.js +1 -0
  143. package/target/main/ts/core/ports/report.d.ts +9 -0
  144. package/target/main/ts/core/ports/report.js +1 -0
  145. package/target/main/ts/core/ports/source-provider.d.ts +14 -0
  146. package/target/main/ts/core/ports/source-provider.js +4 -0
  147. package/target/main/ts/core/profile/exclusions.d.ts +11 -0
  148. package/target/main/ts/core/profile/exclusions.js +57 -0
  149. package/target/main/ts/core/profile/maintainability.d.ts +31 -0
  150. package/target/main/ts/core/profile/maintainability.js +9 -0
  151. package/target/main/ts/core/profile/profile.d.ts +4 -0
  152. package/target/main/ts/core/profile/profile.js +10 -0
  153. package/target/main/ts/core/usecases/compare.d.ts +6 -0
  154. package/target/main/ts/core/usecases/compare.js +145 -0
  155. package/target/main/ts/core/usecases/diff-coverage-policy.d.ts +6 -0
  156. package/target/main/ts/core/usecases/diff-coverage-policy.js +10 -0
  157. package/target/main/ts/core/usecases/diff-coverage.d.ts +40 -0
  158. package/target/main/ts/core/usecases/diff-coverage.js +15 -0
  159. package/target/main/ts/core/usecases/inspect.d.ts +38 -0
  160. package/target/main/ts/core/usecases/inspect.js +41 -0
  161. package/target/main/ts/core/usecases/review.d.ts +31 -0
  162. package/target/main/ts/core/usecases/review.js +128 -0
  163. package/target/main/ts/index.d.ts +35 -0
  164. package/target/main/ts/index.js +17 -0
  165. package/target/main/ts/plugin.d.ts +14 -0
  166. package/target/main/ts/plugin.js +5 -0
  167. package/target/main/ts/plugins/coverage/coverage.d.ts +23 -0
  168. package/target/main/ts/plugins/coverage/coverage.js +120 -0
  169. package/target/main/ts/plugins/coverage/diff-coverage.d.ts +7 -0
  170. package/target/main/ts/plugins/coverage/diff-coverage.js +89 -0
  171. package/target/main/ts/plugins/duplication/duplication.d.ts +4 -0
  172. package/target/main/ts/plugins/duplication/duplication.js +93 -0
  173. package/target/main/ts/plugins/language-js/babel-provider.d.ts +10 -0
  174. package/target/main/ts/plugins/language-js/babel-provider.js +46 -0
  175. package/target/main/ts/plugins/language-js/clone-candidates.d.ts +3 -0
  176. package/target/main/ts/plugins/language-js/clone-candidates.js +64 -0
  177. package/target/main/ts/plugins/language-js/code-lines.d.ts +6 -0
  178. package/target/main/ts/plugins/language-js/code-lines.js +35 -0
  179. package/target/main/ts/plugins/language-js/function-facts.d.ts +8 -0
  180. package/target/main/ts/plugins/language-js/function-facts.js +60 -0
  181. package/target/main/ts/plugins/language-js/structural-observations.d.ts +8 -0
  182. package/target/main/ts/plugins/language-js/structural-observations.js +79 -0
  183. package/target/main/ts/plugins/maintainability/maintainability.d.ts +9 -0
  184. package/target/main/ts/plugins/maintainability/maintainability.js +42 -0
  185. package/target/main/ts/plugins/maintainability/structural-smells.d.ts +3 -0
  186. package/target/main/ts/plugins/maintainability/structural-smells.js +15 -0
  187. package/target/main/ts/plugins/source/forges.d.ts +4 -0
  188. package/target/main/ts/plugins/source/forges.js +79 -0
  189. package/target/main/ts/plugins/structure/structure.d.ts +2 -0
  190. package/target/main/ts/plugins/structure/structure.js +37 -0
  191. package/target/main/ts/report/html/app/viewer-access.d.ts +19 -0
  192. package/target/main/ts/report/html/app/viewer-access.js +25 -0
  193. package/target/main/ts/report/html/app/viewer-chart.d.ts +101 -0
  194. package/target/main/ts/report/html/app/viewer-chart.js +711 -0
  195. package/target/main/ts/report/html/app/viewer-commits.d.ts +36 -0
  196. package/target/main/ts/report/html/app/viewer-commits.js +280 -0
  197. package/target/main/ts/report/html/app/viewer-data.d.ts +23 -0
  198. package/target/main/ts/report/html/app/viewer-data.js +105 -0
  199. package/target/main/ts/report/html/app/viewer-files.d.ts +117 -0
  200. package/target/main/ts/report/html/app/viewer-files.js +2087 -0
  201. package/target/main/ts/report/html/app/viewer-filter.d.ts +113 -0
  202. package/target/main/ts/report/html/app/viewer-filter.js +492 -0
  203. package/target/main/ts/report/html/app/viewer-metric-registry.d.ts +68 -0
  204. package/target/main/ts/report/html/app/viewer-metric-registry.js +206 -0
  205. package/target/main/ts/report/html/app/viewer-metrics.d.ts +44 -0
  206. package/target/main/ts/report/html/app/viewer-metrics.js +172 -0
  207. package/target/main/ts/report/html/app/viewer-profile.d.ts +17 -0
  208. package/target/main/ts/report/html/app/viewer-profile.js +401 -0
  209. package/target/main/ts/report/html/app/viewer-projects.d.ts +1 -0
  210. package/target/main/ts/report/html/app/viewer-projects.js +90 -0
  211. package/target/main/ts/report/html/app/viewer-pulls.d.ts +3 -0
  212. package/target/main/ts/report/html/app/viewer-pulls.js +242 -0
  213. package/target/main/ts/report/html/app/viewer-source.d.ts +75 -0
  214. package/target/main/ts/report/html/app/viewer-source.js +313 -0
  215. package/target/main/ts/report/html/app/viewer-trends.d.ts +74 -0
  216. package/target/main/ts/report/html/app/viewer-trends.js +413 -0
  217. package/target/main/ts/report/html/app/viewer.d.ts +1 -0
  218. package/target/main/ts/report/html/app/viewer.js +794 -0
  219. package/target/main/ts/report/html/site/badges.d.ts +14 -0
  220. package/target/main/ts/report/html/site/badges.js +39 -0
  221. package/target/main/ts/report/html/site/export-site.d.ts +21 -0
  222. package/target/main/ts/report/html/site/export-site.js +157 -0
  223. package/target/main/ts/report/html/site/exported-server.d.ts +6 -0
  224. package/target/main/ts/report/html/site/exported-server.js +70 -0
  225. package/target/main/ts/report/html/site/local-server.d.ts +7 -0
  226. package/target/main/ts/report/html/site/local-server.js +64 -0
  227. package/target/main/ts/report/html/site/projects.d.ts +3 -0
  228. package/target/main/ts/report/html/site/projects.js +79 -0
  229. package/target/main/ts/report/html/site/server.d.ts +4 -0
  230. package/target/main/ts/report/html/site/server.js +64 -0
  231. package/target/main/ts/report/html/site/source-route.d.ts +6 -0
  232. package/target/main/ts/report/html/site/source-route.js +22 -0
  233. package/target/main/ts/report/json/projections/commit-summary.d.ts +11 -0
  234. package/target/main/ts/report/json/projections/commit-summary.js +118 -0
  235. package/target/main/ts/report/json/projections/components.d.ts +4 -0
  236. package/target/main/ts/report/json/projections/components.js +29 -0
  237. package/target/main/ts/report/json/projections/file-metrics.d.ts +5 -0
  238. package/target/main/ts/report/json/projections/file-metrics.js +243 -0
  239. package/target/main/ts/report/json/projections/inspection-context.d.ts +6 -0
  240. package/target/main/ts/report/json/projections/inspection-context.js +92 -0
  241. package/target/main/ts/report/json/projections/inspection-details.d.ts +11 -0
  242. package/target/main/ts/report/json/projections/inspection-details.js +69 -0
  243. package/target/main/ts/report/json/projections/metric-values.d.ts +7 -0
  244. package/target/main/ts/report/json/projections/metric-values.js +57 -0
  245. package/target/main/ts/report/json/projections/public-history.d.ts +4 -0
  246. package/target/main/ts/report/json/projections/public-history.js +16 -0
  247. package/target/main/ts/report/json/store/components.d.ts +2 -0
  248. package/target/main/ts/report/json/store/components.js +31 -0
  249. package/target/main/ts/report/json/store/local-store.d.ts +13 -0
  250. package/target/main/ts/report/json/store/local-store.js +179 -0
  251. package/target/main/ts/report/json/store/pull-review-store.d.ts +3 -0
  252. package/target/main/ts/report/json/store/pull-review-store.js +51 -0
  253. package/target/main/ts/report/json/validation/metabranch.d.ts +4 -0
  254. package/target/main/ts/report/json/validation/metabranch.js +7 -0
  255. package/target/main/ts/report/json/validation/report.d.ts +15 -0
  256. package/target/main/ts/report/json/validation/report.js +64 -0
  257. package/target/main/ts/report/json/validation/summary-validation.d.ts +4 -0
  258. package/target/main/ts/report/json/validation/summary-validation.js +27 -0
  259. package/target/main/ts/report/json/wire/compact-json.d.ts +11 -0
  260. package/target/main/ts/report/json/wire/compact-json.js +76 -0
  261. package/target/main/ts/report/json/wire/component-model.d.ts +9 -0
  262. package/target/main/ts/report/json/wire/component-model.js +1 -0
  263. package/target/main/ts/report/json/wire/domain-types.d.ts +2 -0
  264. package/target/main/ts/report/json/wire/domain-types.js +1 -0
  265. package/target/main/ts/report/json/wire/file-metrics-model.d.ts +77 -0
  266. package/target/main/ts/report/json/wire/file-metrics-model.js +1 -0
  267. package/target/main/ts/report/json/wire/inspection-context-model.d.ts +26 -0
  268. package/target/main/ts/report/json/wire/inspection-context-model.js +1 -0
  269. package/target/main/ts/report/json/wire/inspection-details-model.d.ts +82 -0
  270. package/target/main/ts/report/json/wire/inspection-details-model.js +1 -0
  271. package/target/main/ts/report/json/wire/project-model.d.ts +7 -0
  272. package/target/main/ts/report/json/wire/project-model.js +1 -0
  273. package/target/main/ts/report/json/wire/public-history-model.d.ts +42 -0
  274. package/target/main/ts/report/json/wire/public-history-model.js +6 -0
  275. package/target/main/ts/report/json/wire/pull-review-model.d.ts +7 -0
  276. package/target/main/ts/report/json/wire/pull-review-model.js +1 -0
  277. package/target/main/ts/report/json/wire/summary-model.d.ts +45 -0
  278. package/target/main/ts/report/json/wire/summary-model.js +1 -0
  279. package/target/main/ts/report.d.ts +11 -0
  280. package/target/main/ts/report.js +5 -0
@@ -0,0 +1,57 @@
1
+ import { posix } from 'node:path';
2
+ export const defaultSourceExclusions = [
3
+ '**/.yarn', '**/.pnp.{js,cjs,loader.mjs}', '**/vendor', '**/third_party',
4
+ '**/*.min.{js,cjs,mjs}', '**/*{.,-}bundle.{js,cjs,mjs}',
5
+ ];
6
+ export function sourceExclusionMatcher(patterns, generated = []) {
7
+ const matches = exclusionMatcher([...defaultSourceExclusions, ...patterns]);
8
+ const generatedPaths = new Set(generated);
9
+ return path => generatedPaths.has(path) || matches(path);
10
+ }
11
+ export const generatedSourcePolicy = { version: 1, minBytes: 1024, minMeanLineLength: 300 };
12
+ /** Detect generated text by its source-map trailer or the density of its nonblank lines. */
13
+ export function isGeneratedSource(bytes) {
14
+ const source = new TextDecoder().decode(bytes);
15
+ if (/(?:^|\n)[ \t]*(?:\/\/[#@][ \t]*sourceMappingURL=\S+|\/\*[#@][ \t]*sourceMappingURL=[^\r\n]+\*\/)[ \t\r\n]*$/.test(source))
16
+ return true;
17
+ if (bytes.length < generatedSourcePolicy.minBytes)
18
+ return false;
19
+ const lines = source.split(/\r\n|[\n\r\u2028\u2029]/).map(line => line.trim()).filter(Boolean);
20
+ return lines.reduce((sum, line) => sum + line.length, 0) > lines.length * generatedSourcePolicy.minMeanLineLength;
21
+ }
22
+ export function normalizeExclusions(value) {
23
+ if (!Array.isArray(value))
24
+ throw new Error('Profile exclude must be an array of repository-relative paths or globs');
25
+ const patterns = new Set();
26
+ for (const item of value) {
27
+ if (typeof item !== 'string')
28
+ throw new Error('Each exclusion must be a string');
29
+ const pattern = item.replace(/^(?:\.\/)+/, '').replace(/\/+$/, '');
30
+ if (!isRelativePath(pattern) || /[\\\0]/.test(pattern) || /^[#!]/.test(pattern)) {
31
+ throw new Error(`Invalid source exclusion: ${JSON.stringify(item)}. Use a repository-relative path or glob.`);
32
+ }
33
+ patterns.add(pattern);
34
+ }
35
+ return [...patterns];
36
+ }
37
+ export function exclusionMatcher(patterns) {
38
+ if (patterns.length === 0)
39
+ return () => false;
40
+ return path => {
41
+ if (!isRelativePath(path))
42
+ return false;
43
+ // A rule that matches a directory excludes its entire subtree.
44
+ let candidate = path;
45
+ for (;;) {
46
+ if (patterns.some(pattern => candidate === pattern || posix.matchesGlob(candidate, pattern)))
47
+ return true;
48
+ const slash = candidate.lastIndexOf('/');
49
+ if (slash === -1)
50
+ return false;
51
+ candidate = candidate.slice(0, slash);
52
+ }
53
+ };
54
+ }
55
+ function isRelativePath(path) {
56
+ return !/^[A-Za-z]:/.test(path) && path.split('/').every(part => part !== '' && part !== '.' && part !== '..');
57
+ }
@@ -0,0 +1,31 @@
1
+ export declare const structuralRules: {
2
+ readonly 'function-parameters': {
3
+ readonly limit: 5;
4
+ readonly minutesPerExcess: 10;
5
+ };
6
+ readonly 'return-statements': {
7
+ readonly limit: 6;
8
+ readonly minutesPerExcess: 10;
9
+ };
10
+ readonly 'boolean-logic': {
11
+ readonly limit: 4;
12
+ readonly minutesPerExcess: 10;
13
+ };
14
+ readonly 'nested-control-flow': {
15
+ readonly limit: 4;
16
+ readonly minutesPerExcess: 20;
17
+ };
18
+ readonly 'function-complexity': {
19
+ readonly limit: 15;
20
+ readonly minutesPerExcess: 10;
21
+ };
22
+ readonly 'file-complexity': {
23
+ readonly limit: 50;
24
+ readonly minutesPerExcess: 5;
25
+ };
26
+ };
27
+ export declare const duplicationSettings: {
28
+ readonly minCodeLines: 12;
29
+ readonly minNodes: 50;
30
+ readonly minutesPerRepeatedLine: 2;
31
+ };
@@ -0,0 +1,9 @@
1
+ export const structuralRules = {
2
+ 'function-parameters': { limit: 5, minutesPerExcess: 10 },
3
+ 'return-statements': { limit: 6, minutesPerExcess: 10 },
4
+ 'boolean-logic': { limit: 4, minutesPerExcess: 10 },
5
+ 'nested-control-flow': { limit: 4, minutesPerExcess: 20 },
6
+ 'function-complexity': { limit: 15, minutesPerExcess: 10 },
7
+ 'file-complexity': { limit: 50, minutesPerExcess: 5 },
8
+ };
9
+ export const duplicationSettings = { minCodeLines: 12, minNodes: 50, minutesPerRepeatedLine: 2 };
@@ -0,0 +1,4 @@
1
+ export declare function normalizeProfile(profile: unknown): {
2
+ exclude: readonly string[];
3
+ ignore: readonly import("../model/ignore-rule.js").FindingIgnoreRule[];
4
+ };
@@ -0,0 +1,10 @@
1
+ import { isRecord } from '../engine/plugin.js';
2
+ import { normalizeFindingIgnore } from '../model/finding-ignore.js';
3
+ import { normalizeExclusions } from './exclusions.js';
4
+ export function normalizeProfile(profile) {
5
+ if (!isRecord(profile) || Object.keys(profile).some(key => key !== 'exclude' && key !== 'ignore')) {
6
+ throw new Error('Expected a JSON profile with optional exclude and ignore arrays');
7
+ }
8
+ return { exclude: normalizeExclusions(profile.exclude === undefined ? [] : profile.exclude),
9
+ ignore: normalizeFindingIgnore(profile.ignore === undefined ? [] : profile.ignore) };
10
+ }
@@ -0,0 +1,6 @@
1
+ import type { Report } from '../model/report.js';
2
+ import type { InspectionComparison, Observation } from '../model/comparison.js';
3
+ export { comparisonSchema } from '../model/comparison.js';
4
+ export type { InspectionComparison } from '../model/comparison.js';
5
+ export declare function compareInspections(baseline: Report, current: Report): InspectionComparison;
6
+ export declare function observeCoverage(report: Report): Observation;
@@ -0,0 +1,145 @@
1
+ import { isDeepStrictEqual } from 'node:util';
2
+ import { isRecord } from '../engine/plugin.js';
3
+ import { definitions } from '../model/measurement.js';
4
+ import { comparePaths } from '../model/snapshot.js';
5
+ import { comparisonSchema } from '../model/comparison.js';
6
+ export { comparisonSchema } from '../model/comparison.js';
7
+ const metrics = {
8
+ physicalLines: { definition: definitions.lines, operation: 'structure/size' },
9
+ functions: { definition: definitions.functions, operation: 'structure/size' },
10
+ maxCyclomaticComplexity: { definition: definitions.complexity, operation: 'structure/complexity' },
11
+ lineCoverage: { definition: definitions.coverage, operation: 'lcov/import' },
12
+ };
13
+ export function compareInspections(baseline, current) {
14
+ const scopes = [sourceScope(baseline), sourceScope(current)];
15
+ const scopeReason = scopes.some(scope => scope === null) ? 'source-scope-unknown'
16
+ : isDeepStrictEqual(scopes[0], scopes[1]) ? null : 'source-scope-changed';
17
+ const compare = (metric) => compareMetric(metric, baseline, current, scopeReason);
18
+ return { schema: comparisonSchema, baseline: subject(baseline), current: subject(current), metrics: {
19
+ physicalLines: compare(metrics.physicalLines), functions: compare(metrics.functions),
20
+ maxCyclomaticComplexity: compare(metrics.maxCyclomaticComplexity), lineCoverage: compare(metrics.lineCoverage),
21
+ } };
22
+ }
23
+ function compareMetric(metric, baseline, current, scopeReason) {
24
+ const before = observe(baseline, metric);
25
+ const after = observe(current, metric);
26
+ const unit = metric.definition === definitions.coverage ? 'percent' : 'count';
27
+ const base = { definition: metric.definition, unit, baseline: before, current: after, delta: null };
28
+ if (before.status !== 'complete' || after.status !== 'complete' || before.value === null || after.value === null) {
29
+ return { ...base, status: 'unavailable', reason: 'observations-unavailable' };
30
+ }
31
+ if (scopeReason) {
32
+ return { ...base, status: scopeReason === 'source-scope-unknown' ? 'unavailable' : 'incompatible', reason: scopeReason };
33
+ }
34
+ const beforeMethod = method(baseline, metric);
35
+ const afterMethod = method(current, metric);
36
+ if (!beforeMethod || !afterMethod)
37
+ return { ...base, status: 'unavailable', reason: 'method-unknown' };
38
+ if (!isDeepStrictEqual(beforeMethod, afterMethod))
39
+ return { ...base, status: 'incompatible', reason: 'method-changed' };
40
+ return { ...base, status: 'comparable', reason: null, delta: after.value - before.value };
41
+ }
42
+ function observe(report, metric) {
43
+ if (metric.definition === definitions.coverage)
44
+ return observeCoverage(report);
45
+ const maximum = metric.definition === definitions.complexity;
46
+ const target = maximum ? 'function' : 'file';
47
+ const rows = report.measurements.filter(row => row.definition === metric.definition && row.target === target);
48
+ const partial = report.scope.parsed < report.scope.files || hasDiagnostic(report, metric.operation, 'babel-syntax/parse');
49
+ const expected = maximum ? fileCount(report.measurements, definitions.functions, report.scope.files) : report.scope.files;
50
+ const value = integerAggregate(rows, maximum);
51
+ if (partial)
52
+ return { status: 'partial', value };
53
+ if (expected === null || rows.length !== expected || (!maximum && !distinctPaths(rows))) {
54
+ return { status: 'unavailable', value: null };
55
+ }
56
+ if (expected === 0)
57
+ return { status: 'not-applicable', value: null };
58
+ return { status: value === null ? 'unavailable' : 'complete', value };
59
+ }
60
+ export function observeCoverage(report) {
61
+ const rows = report.measurements.filter(row => row.definition === definitions.coverage && row.target === 'repository');
62
+ const row = rows.length === 1 ? rows[0] : undefined;
63
+ const partial = hasDiagnostic(report, 'lcov/import');
64
+ if (row?.covered === undefined || row.total === undefined)
65
+ return { status: partial ? 'partial' : 'unavailable', value: null };
66
+ const value = row.total > 0 ? 100 * row.covered / row.total : null;
67
+ return { status: partial ? 'partial' : value === null ? 'not-applicable' : 'complete', value, covered: row.covered, total: row.total };
68
+ }
69
+ function fileCount(measurements, definition, expected) {
70
+ const rows = measurements.filter(row => row.definition === definition && row.target === 'file');
71
+ if (rows.length !== expected || !distinctPaths(rows))
72
+ return null;
73
+ return rows.length === 0 ? 0 : integerAggregate(rows, false);
74
+ }
75
+ function distinctPaths(rows) {
76
+ const paths = new Set(rows.map(row => row.path));
77
+ return !paths.has(undefined) && paths.size === rows.length;
78
+ }
79
+ function integerAggregate(rows, maximum) {
80
+ if (rows.length === 0)
81
+ return null;
82
+ let result = 0;
83
+ for (const { value } of rows) {
84
+ if (value === null || !Number.isSafeInteger(value) || value < 0)
85
+ return null;
86
+ result = maximum ? Math.max(result, value) : result + value;
87
+ }
88
+ return Number.isSafeInteger(result) ? result : null;
89
+ }
90
+ function hasDiagnostic(report, ...operations) {
91
+ return report.diagnostics.some(item => operations.includes(item.operation));
92
+ }
93
+ function sourceScope(report) {
94
+ const { source, profile } = report.appliedConfig;
95
+ if (!isRecord(source))
96
+ return null;
97
+ const paths = orderedStrings(source.excludedPaths === undefined && profile === 'js-ts/v1' ? [] : source.excludedPaths);
98
+ const defaults = orderedStrings(source.defaultExclusions ?? []);
99
+ const directories = orderedStrings(source.excludedDirectories);
100
+ const extensions = orderedStrings(source.extensions);
101
+ const excludedOutput = source.excludedOutput;
102
+ if (!paths || !defaults || !directories || !extensions || (excludedOutput !== null && typeof excludedOutput !== 'string'))
103
+ return null;
104
+ return { kind: report.subject.kind, paths: orderedStrings([...paths, ...defaults]), directories, extensions, excludedOutput,
105
+ generatedSourcePolicy: source.generatedSourcePolicy ?? null };
106
+ }
107
+ function orderedStrings(value) {
108
+ if (!Array.isArray(value) || !value.every((item) => typeof item === 'string'))
109
+ return null;
110
+ return [...new Set(value)].sort(comparePaths);
111
+ }
112
+ function method(report, metric) {
113
+ const definition = report.definitions[metric.definition];
114
+ const { plugins, operations, parser, coverage } = report.appliedConfig;
115
+ const importsCoverage = metric.definition === definitions.coverage;
116
+ const pluginIds = importsCoverage ? ['lcov'] : ['babel-syntax', 'structure'];
117
+ const operationKeys = importsCoverage ? [metric.operation] : ['babel-syntax/parse', metric.operation];
118
+ const toolchain = recordedEntries(plugins, 'id', pluginIds);
119
+ const bindings = recordedEntries(operations, 'key', operationKeys);
120
+ const settings = importsCoverage ? coverage : parser;
121
+ if (typeof definition !== 'string' || !toolchain || !bindings || !isRecord(settings))
122
+ return null;
123
+ if (importsCoverage && typeof settings.merge !== 'string')
124
+ return null;
125
+ if (!importsCoverage)
126
+ return { definition, toolchain, bindings, settings };
127
+ const { inputDigest, inputDigests, pathBase, ...importSettings } = settings;
128
+ return { definition, toolchain, bindings, settings: importSettings };
129
+ }
130
+ function recordedEntries(value, key, names) {
131
+ if (!Array.isArray(value))
132
+ return null;
133
+ const entries = value.filter(isRecord);
134
+ const matches = names.map(name => entries.filter(entry => entry[key] === name));
135
+ if (matches.some(group => group.length !== 1))
136
+ return null;
137
+ const recorded = matches.map(group => group[0]);
138
+ const valid = key === 'id'
139
+ ? recorded.every(entry => typeof entry.version === 'string' && typeof entry.api === 'string' && isRecord(entry.tools))
140
+ : recorded.every(entry => isRecord(entry.inputs));
141
+ return valid ? recorded : null;
142
+ }
143
+ function subject({ subject, generatedAt, status, scope }) {
144
+ return { subject, generatedAt, status, scope };
145
+ }
@@ -0,0 +1,6 @@
1
+ import type { DiffCoverage } from '../model/diff-coverage.js';
2
+ export interface CoverageDecision {
3
+ readonly status: 'passed' | 'failed' | 'not-applicable' | 'indeterminate';
4
+ readonly minimumPercent: number;
5
+ }
6
+ export declare function assessDiffCoverage(result: DiffCoverage, minimumPercent: number): CoverageDecision;
@@ -0,0 +1,10 @@
1
+ export function assessDiffCoverage(result, minimumPercent) {
2
+ if (!Number.isFinite(minimumPercent) || minimumPercent < 0 || minimumPercent > 100) {
3
+ throw new Error('Minimum diff coverage must be a percentage from 0 to 100');
4
+ }
5
+ if (result.status === 'partial')
6
+ return { status: 'indeterminate', minimumPercent };
7
+ if (result.percent === null)
8
+ return { status: 'not-applicable', minimumPercent };
9
+ return { status: result.percent >= minimumPercent ? 'passed' : 'failed', minimumPercent };
10
+ }
@@ -0,0 +1,40 @@
1
+ import type { GitChanges } from '../model/changes.js';
2
+ import type { DiffCoverage, DiffCoverageResult } from '../model/diff-coverage.js';
3
+ import type { SourceSnapshot } from '../model/source.js';
4
+ import type { CoverageDecision } from './diff-coverage-policy.js';
5
+ export declare const diffCoverageSchema = "urn:repometry:schema:diff-coverage:1";
6
+ export interface DiffCoverageReport extends DiffCoverage {
7
+ readonly schema: typeof diffCoverageSchema;
8
+ readonly requestedBase: string;
9
+ readonly base: string;
10
+ readonly head: string;
11
+ readonly generatedAt: string;
12
+ readonly appliedConfig: Readonly<Record<string, unknown>>;
13
+ readonly decision: CoverageDecision | null;
14
+ }
15
+ export interface DiffCoverageSource {
16
+ readonly requestedBase: string;
17
+ readonly base: string;
18
+ readonly head: string;
19
+ readonly snapshot: SourceSnapshot;
20
+ readonly changes: GitChanges;
21
+ readonly root: string;
22
+ readonly lcovText: string;
23
+ readonly appliedConfig: Readonly<Record<string, unknown>>;
24
+ }
25
+ export interface DiffCoveragePorts {
26
+ readInputs(excludedPaths: readonly string[], excludes: (path: string) => boolean): Promise<DiffCoverageSource>;
27
+ measure(source: DiffCoverageSource, excludes: (path: string) => boolean): Promise<DiffCoverageResult>;
28
+ }
29
+ interface DiffCoverageOptions {
30
+ readonly exclude?: readonly string[];
31
+ readonly minimumPercent?: number;
32
+ }
33
+ export declare function executeDiffCoverage(options: DiffCoverageOptions, ports: DiffCoveragePorts): Promise<{
34
+ report: DiffCoverageReport;
35
+ uncovered: readonly {
36
+ readonly path: string;
37
+ readonly lines: readonly number[];
38
+ }[];
39
+ }>;
40
+ export {};
@@ -0,0 +1,15 @@
1
+ import { normalizeExclusions, sourceExclusionMatcher } from '../profile/exclusions.js';
2
+ import { assessDiffCoverage } from './diff-coverage-policy.js';
3
+ export const diffCoverageSchema = 'urn:repometry:schema:diff-coverage:1';
4
+ export async function executeDiffCoverage(options, ports) {
5
+ const excludedPaths = normalizeExclusions(options.exclude ?? []);
6
+ const source = await ports.readInputs(excludedPaths, sourceExclusionMatcher(excludedPaths));
7
+ const value = await ports.measure(source, sourceExclusionMatcher(excludedPaths, source.snapshot.generatedExcluded));
8
+ const { uncovered, ...observation } = value;
9
+ const { requestedBase, base, head, appliedConfig } = source;
10
+ const report = {
11
+ schema: diffCoverageSchema, requestedBase, base, head, generatedAt: new Date().toISOString(), appliedConfig,
12
+ ...observation, decision: options.minimumPercent === undefined ? null : assessDiffCoverage(value, options.minimumPercent),
13
+ };
14
+ return { report, uncovered };
15
+ }
@@ -0,0 +1,38 @@
1
+ import type { FindingIgnoreRule } from '../model/finding-ignore.js';
2
+ import type { Report } from '../model/report.js';
3
+ import type { SourceSnapshot } from '../model/source.js';
4
+ export interface AnalysisInput {
5
+ /** The source adapter has already applied the exclusions to this snapshot. */
6
+ readonly snapshot: SourceSnapshot;
7
+ readonly excludedOutput: string | null;
8
+ readonly excludedPaths?: readonly string[];
9
+ readonly coverage?: {
10
+ readonly text: string;
11
+ readonly sourceRoot: string;
12
+ };
13
+ }
14
+ export type AnalysisExecutor = (input: AnalysisInput) => Promise<Report>;
15
+ type Excludes = (path: string) => boolean;
16
+ interface InspectionSource {
17
+ readonly snapshot: SourceSnapshot;
18
+ readonly root: string;
19
+ readonly excludedOutput: string | null;
20
+ save(report: Report): Promise<void>;
21
+ }
22
+ interface InspectionCoverage {
23
+ readonly text: string;
24
+ readonly inputDigests: readonly string[];
25
+ }
26
+ export interface InspectionPorts {
27
+ readSource(excludes: Excludes): Promise<InspectionSource>;
28
+ readonly analyze: AnalysisExecutor;
29
+ readCoverage?(): Promise<InspectionCoverage>;
30
+ importFindings?(report: Report, root: string, excludes: Excludes): Promise<Report>;
31
+ recordChurn?(report: Report, root: string, paths: readonly string[]): Promise<Report>;
32
+ }
33
+ export interface InspectionOptions {
34
+ readonly exclude?: readonly string[];
35
+ readonly ignore?: readonly FindingIgnoreRule[];
36
+ }
37
+ export declare function executeInspection(options: InspectionOptions, ports: InspectionPorts): Promise<Report>;
38
+ export {};
@@ -0,0 +1,41 @@
1
+ import { isDeepStrictEqual } from 'node:util';
2
+ import { isRecord } from '../engine/plugin.js';
3
+ import { normalizeFindingIgnore, partitionFindings } from '../model/finding-ignore.js';
4
+ import { reportSchema } from '../model/report.js';
5
+ import { digest } from '../model/snapshot.js';
6
+ import { normalizeExclusions, sourceExclusionMatcher } from '../profile/exclusions.js';
7
+ export async function executeInspection(options, ports) {
8
+ const excludedPaths = normalizeExclusions(options.exclude ?? []);
9
+ const ignore = normalizeFindingIgnore(options.ignore ?? []);
10
+ const source = await ports.readSource(sourceExclusionMatcher(excludedPaths));
11
+ const { snapshot, root, excludedOutput } = source;
12
+ const lcov = await ports.readCoverage?.();
13
+ const report = await ports.analyze({
14
+ snapshot, excludedOutput, excludedPaths,
15
+ coverage: lcov === undefined ? undefined : { text: lcov.text, sourceRoot: root },
16
+ });
17
+ if (report.subject.kind !== snapshot.subject.kind || report.subject.id !== snapshot.subject.id) {
18
+ throw new Error('Analysis result belongs to a different source snapshot');
19
+ }
20
+ const appliedSource = report.appliedConfig.source;
21
+ if (excludedPaths.length > 0 && (!isRecord(appliedSource) || !isDeepStrictEqual(appliedSource.excludedPaths, excludedPaths))) {
22
+ throw new Error('Analysis result does not record the requested source exclusions');
23
+ }
24
+ const covered = lcov && lcov.inputDigests.length > 1 ? withLcovDigests(report, lcov) : report;
25
+ const findings = ports.importFindings
26
+ ? await ports.importFindings(covered, root, sourceExclusionMatcher(excludedPaths, snapshot.generatedExcluded)) : covered;
27
+ const filtered = ignore.length === 0 ? findings : { ...findings, schema: reportSchema,
28
+ appliedConfig: { ...findings.appliedConfig, findingIgnore: ignore },
29
+ ...(findings.findings === undefined ? {} : partitionFindings(findings.findings, ignore)) };
30
+ const result = snapshot.subject.kind === 'commit' && ports.recordChurn
31
+ ? await ports.recordChurn(filtered, root, snapshot.files.map(file => file.path)) : filtered;
32
+ await source.save(result);
33
+ return result;
34
+ }
35
+ function withLcovDigests(report, { text, inputDigests }) {
36
+ const coverage = report.appliedConfig.coverage;
37
+ if (!isRecord(coverage) || coverage.inputDigest !== digest(text)) {
38
+ throw new Error('Analysis result does not record the requested LCOV inputs');
39
+ }
40
+ return { ...report, appliedConfig: { ...report.appliedConfig, coverage: { ...coverage, inputDigests } } };
41
+ }
@@ -0,0 +1,31 @@
1
+ import type { PullReview } from '../model/pull-review.js';
2
+ import type { Report } from '../model/report.js';
3
+ import type { DiffCoverageReport } from './diff-coverage.js';
4
+ export interface ReviewOptions {
5
+ readonly number?: number;
6
+ readonly minimumLines?: number;
7
+ readonly minimumPercent?: number;
8
+ readonly maxCoverageDrop?: number;
9
+ readonly maxNewIssues?: number;
10
+ }
11
+ export interface ReviewPorts {
12
+ readHead(id: string): Promise<Report | null>;
13
+ readBase(id: string): Promise<Report | null>;
14
+ readRevisions(): Promise<{
15
+ head: string;
16
+ base: string;
17
+ mergeBase(): Promise<string>;
18
+ }>;
19
+ measureChanged?(): Promise<{
20
+ report: DiffCoverageReport;
21
+ uncovered: PullReview['diff']['uncovered'];
22
+ }>;
23
+ }
24
+ export declare function executeReview(options: ReviewOptions, ports: ReviewPorts): Promise<PullReview>;
25
+ type ChangedLines = Pick<DiffCoverageReport, 'generatedAt' | 'requestedBase' | 'base' | 'head' | 'covered' | 'total' | 'percent' | 'files' | 'gaps' | 'decision'> & {
26
+ readonly status: PullReview['diff']['status'];
27
+ readonly appliedConfig?: DiffCoverageReport['appliedConfig'];
28
+ };
29
+ export declare function projectReview(request: ReviewOptions, diff: ChangedLines, uncovered: PullReview['diff']['uncovered'], head: Report | null, base: Report | null): PullReview;
30
+ export declare function reviewExitCode(review: PullReview): number;
31
+ export {};
@@ -0,0 +1,128 @@
1
+ import { isDeepStrictEqual } from 'node:util';
2
+ import { isRecord } from '../engine/plugin.js';
3
+ import { isSensitiveFinding } from '../model/finding.js';
4
+ import { pullReviewSchema } from '../model/pull-review.js';
5
+ import { findingImportMethods } from '../model/scanner-import.js';
6
+ import { compareInspections, observeCoverage } from './compare.js';
7
+ export async function executeReview(options, ports) {
8
+ if (!ports.measureChanged && options.minimumPercent !== undefined)
9
+ throw new Error('Minimum diff coverage requires --lcov');
10
+ if (ports.measureChanged) {
11
+ const { report, uncovered } = await ports.measureChanged();
12
+ const [head, base] = await Promise.all([ports.readHead(report.head), ports.readBase(report.requestedBase)]);
13
+ return projectReview(options, report, uncovered, head, base);
14
+ }
15
+ const revisions = await ports.readRevisions();
16
+ const [head, base, mergeBase] = await Promise.all([
17
+ ports.readHead(revisions.head), ports.readBase(revisions.base), revisions.mergeBase(),
18
+ ]);
19
+ return projectReview(options, {
20
+ generatedAt: new Date().toISOString(), requestedBase: revisions.base, base: mergeBase, head: revisions.head,
21
+ status: 'unavailable', covered: 0, total: 0, percent: null, files: [], gaps: [], decision: null,
22
+ }, [], head, base);
23
+ }
24
+ export function projectReview(request, diff, uncovered, head, base) {
25
+ const minimumLines = request.minimumLines ?? 0;
26
+ if (request.number !== undefined && (!Number.isSafeInteger(request.number) || request.number < 1)) {
27
+ throw new Error('Pull request number must be a positive integer');
28
+ }
29
+ if (!Number.isSafeInteger(minimumLines) || minimumLines < 0)
30
+ throw new Error('Minimum diff lines must be a non-negative integer');
31
+ if (request.maxNewIssues !== undefined && (!Number.isSafeInteger(request.maxNewIssues) || request.maxNewIssues < 0)) {
32
+ throw new Error('Maximum new issues must be a non-negative integer');
33
+ }
34
+ if (request.maxCoverageDrop !== undefined && (!Number.isFinite(request.maxCoverageDrop) || request.maxCoverageDrop < 0 || request.maxCoverageDrop > 100)) {
35
+ throw new Error('Maximum coverage drop must be a number from 0 to 100');
36
+ }
37
+ if (request.minimumLines !== undefined && diff.decision === null) {
38
+ throw new Error('Minimum diff lines requires a minimum diff coverage percentage');
39
+ }
40
+ const { status, covered, total, percent, files, gaps, decision } = diff;
41
+ const config = diff.appliedConfig;
42
+ const source = config?.source;
43
+ const lcov = config?.lcov;
44
+ const excludedPaths = isRecord(source) && Array.isArray(source.excludedPaths)
45
+ && source.excludedPaths.every((path) => typeof path === 'string') ? source.excludedPaths : null;
46
+ const coverageInputDigest = isRecord(lcov) && typeof lcov.inputDigest === 'string' ? lcov.inputDigest : null;
47
+ const gate = decision && {
48
+ minimumPercent: decision.minimumPercent,
49
+ minimumLines,
50
+ status: total < minimumLines && status !== 'partial' ? 'not-applicable' : decision.status,
51
+ };
52
+ return { schema: pullReviewSchema, number: request.number ?? null, generatedAt: diff.generatedAt,
53
+ base: diff.requestedBase, mergeBase: diff.base, head: diff.head,
54
+ coverage: coverageImpact(head, base, diff, request.maxCoverageDrop),
55
+ diff: { status, covered, total, percent, files, gaps, excludedPaths, coverageInputDigest, uncovered, gate },
56
+ findings: findingImpact(head, base, request.maxNewIssues),
57
+ };
58
+ }
59
+ export function reviewExitCode(review) {
60
+ const decisions = [review.diff.gate, review.coverage.gate, review.findings.gate].map(gate => gate?.status);
61
+ if (review.diff.status === 'partial' || decisions.includes('indeterminate')
62
+ || (review.diff.status === 'unavailable' && review.findings.added === null && review.coverage.delta === null))
63
+ return 2;
64
+ return decisions.includes('failed') ? 3 : 0;
65
+ }
66
+ function coverageImpact(head, base, diff, maxDrop) {
67
+ const method = head?.appliedConfig.coverage;
68
+ const input = diff.appliedConfig?.lcov;
69
+ const usesHeadCoverage = isRecord(method) && isRecord(input) && method.inputDigest === input.inputDigest;
70
+ const mismatch = head !== null && diff.appliedConfig !== undefined && !usesHeadCoverage;
71
+ const comparison = base && head && !mismatch ? compareInspections(base, head).metrics.lineCoverage : null;
72
+ const delta = comparison?.delta ?? null;
73
+ const gate = maxDrop === undefined ? null : { maxDrop,
74
+ status: delta === null ? 'indeterminate' : delta + maxDrop < -Number.EPSILON * 100 ? 'failed' : 'passed' };
75
+ return {
76
+ base: base ? observeCoverage(base) : null,
77
+ head: head && !mismatch ? observeCoverage(head) : null,
78
+ delta, reason: comparison ? comparison.reason : mismatch ? 'head-coverage-changed' : 'reports-unavailable', gate,
79
+ };
80
+ }
81
+ function findingImpact(head, base, maximum) {
82
+ const { added, reason } = comparableFindings(head, base, false);
83
+ const quality = added ?? comparableFindings(head, base, true).added;
84
+ const qualityCount = quality ? quality.filter(finding => !isSensitiveFinding(finding.category)).length : null;
85
+ return { added, qualityCount, reason, gate: maximum === undefined ? null : { maximum,
86
+ status: qualityCount === null ? 'indeterminate' : qualityCount > maximum ? 'failed' : 'passed' } };
87
+ }
88
+ function comparableFindings(head, base, qualityOnly) {
89
+ let reason = null;
90
+ let added = null;
91
+ if (!head || !base)
92
+ reason = 'reports-unavailable';
93
+ else if (!head.findings || !base.findings)
94
+ reason = 'findings-unavailable';
95
+ else if (incompleteAnalysis(head, qualityOnly) || incompleteAnalysis(base, qualityOnly))
96
+ reason = 'partial-inspection';
97
+ else if (!isDeepStrictEqual(findingMethod(head, qualityOnly), findingMethod(base, qualityOnly)))
98
+ reason = 'analysis-changed';
99
+ else
100
+ added = newFindings(base.findings, head.findings);
101
+ return { added, reason };
102
+ }
103
+ function incompleteAnalysis(report, qualityOnly) {
104
+ return report.scope.parsed < report.scope.files || report.diagnostics.some(({ operation }) => operation !== 'lcov/import' && operation !== 'git/churn'
105
+ && !(qualityOnly && /^findings\/(security|dependency|secret|infrastructure)\//.test(operation)));
106
+ }
107
+ function newFindings(base, head) {
108
+ const remaining = new Map();
109
+ const key = ({ category, path, tool, rule, message }) => JSON.stringify([category, path, tool, rule, message]);
110
+ for (const finding of base) {
111
+ const id = key(finding);
112
+ remaining.set(id, (remaining.get(id) ?? 0) + 1);
113
+ }
114
+ return head.filter(finding => {
115
+ const id = key(finding);
116
+ const count = remaining.get(id) ?? 0;
117
+ if (count === 0)
118
+ return true;
119
+ remaining.set(id, count - 1);
120
+ return false;
121
+ });
122
+ }
123
+ function findingMethod(report, qualityOnly) {
124
+ const { coverage, findingImports, churn, churnWindow, plugins, operations, ...settings } = report.appliedConfig;
125
+ const exclude = (entries, key, value) => Array.isArray(entries) ? entries.filter(entry => !isRecord(entry) || entry[key] !== value) : entries;
126
+ const imported = findingImportMethods(findingImports).filter(({ category }) => !qualityOnly || !isSensitiveFinding(category));
127
+ return { ...settings, imported, plugins: exclude(plugins, 'id', 'lcov'), operations: exclude(operations, 'key', 'lcov/import') };
128
+ }
@@ -0,0 +1,35 @@
1
+ export { pluginApi } from './core/engine/plugin.js';
2
+ export type { DataContract, InspectionInputs, Operation, Plugin, Product } from './core/engine/plugin.js';
3
+ export { plan } from './core/engine/plan.js';
4
+ export type { InputBinding, PlanRequest, PlannedOperation } from './core/engine/plan.js';
5
+ export { execute } from './core/engine/execute.js';
6
+ export type { Outcome } from './core/engine/execute.js';
7
+ export { analyzeSnapshot, inspect } from './compose/inspect.js';
8
+ export type { AnalysisExecutor, AnalysisInput, InspectionPorts, InspectRequest } from './compose/inspect.js';
9
+ export { diffCoverageSchema, measureDiffCoverage } from './compose/diff-coverage.js';
10
+ export type { DiffCoverageReport, DiffCoverageRequest } from './compose/diff-coverage.js';
11
+ export type { DiffCoveragePorts, DiffCoverageSource } from './core/usecases/diff-coverage.js';
12
+ export { reviewPull, reviewExitCode } from './compose/review.js';
13
+ export type { ReviewRequest } from './compose/review.js';
14
+ export type { ReviewPorts } from './core/usecases/review.js';
15
+ export { compareInspections, comparisonSchema } from './core/usecases/compare.js';
16
+ export { compareInspections as compare } from './core/usecases/compare.js';
17
+ export { measureDiffCoverage as diffCoverage } from './compose/diff-coverage.js';
18
+ export { review } from './compose/review.js';
19
+ export type { InspectionComparison } from './core/usecases/compare.js';
20
+ export { fileMetrics, fileMetricsSchema } from './report/json/projections/file-metrics.js';
21
+ export type { FileMetricsReport } from './report/json/projections/file-metrics.js';
22
+ export { LocalReportStore } from './report/json/store/local-store.js';
23
+ export { GitReportReader } from './api/git/git-reader.js';
24
+ export { readReport, reportSchema } from './report/json/validation/report.js';
25
+ export type { Diagnostic, Report, ReportReader, ReportStore } from './report/json/validation/report.js';
26
+ export type { Measurement } from './core/model/measurement.js';
27
+ export type { Finding, FindingLocation } from './core/model/finding.js';
28
+ export type { FindingInput } from './api/import/finding-import.js';
29
+ export type { FindingIgnoreRule, IgnoredFinding } from './core/model/finding-ignore.js';
30
+ export { coverageGrade, qualitySummary } from './core/model/quality-summary.js';
31
+ export type { Grade, QualitySummary } from './core/model/quality-summary.js';
32
+ export { pullReviewSchema } from './core/model/pull-review.js';
33
+ export { pullReviewsSchema } from './report/json/wire/pull-review-model.js';
34
+ export type { PullReview, PullReviews } from './report/json/wire/pull-review-model.js';
35
+ export type { Subject } from './core/model/snapshot.js';
@@ -0,0 +1,17 @@
1
+ export { pluginApi } from './core/engine/plugin.js';
2
+ export { plan } from './core/engine/plan.js';
3
+ export { execute } from './core/engine/execute.js';
4
+ export { analyzeSnapshot, inspect } from './compose/inspect.js';
5
+ export { diffCoverageSchema, measureDiffCoverage } from './compose/diff-coverage.js';
6
+ export { reviewPull, reviewExitCode } from './compose/review.js';
7
+ export { compareInspections, comparisonSchema } from './core/usecases/compare.js';
8
+ export { compareInspections as compare } from './core/usecases/compare.js';
9
+ export { measureDiffCoverage as diffCoverage } from './compose/diff-coverage.js';
10
+ export { review } from './compose/review.js';
11
+ export { fileMetrics, fileMetricsSchema } from './report/json/projections/file-metrics.js';
12
+ export { LocalReportStore } from './report/json/store/local-store.js';
13
+ export { GitReportReader } from './api/git/git-reader.js';
14
+ export { readReport, reportSchema } from './report/json/validation/report.js';
15
+ export { coverageGrade, qualitySummary } from './core/model/quality-summary.js';
16
+ export { pullReviewSchema } from './core/model/pull-review.js';
17
+ export { pullReviewsSchema } from './report/json/wire/pull-review-model.js';