repometry 0.0.0-dev.0 → 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 (281) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +24 -1
  3. package/package.json +48 -7
  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 +343 -284
  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 -13
  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
  281. package/index.js +0 -1
@@ -0,0 +1,38 @@
1
+ import { resolve } from 'node:path';
2
+ import { findMergeBase } from '../api/git/changes.js';
3
+ import { gitRoot, resolveGitCommit } from '../api/git/git.js';
4
+ import { executeReview } from '../core/usecases/review.js';
5
+ import { LocalReportStore } from '../report/json/store/local-store.js';
6
+ import { measureChangedLines } from './diff-coverage.js';
7
+ export { projectReview, reviewExitCode } from '../core/usecases/review.js';
8
+ export async function reviewPull(request, current, baseline = current) {
9
+ return review(request, {
10
+ readHead: id => readIfAvailable(current, id),
11
+ readBase: id => readIfAvailable(baseline, id),
12
+ });
13
+ }
14
+ export async function review(request, overrides) {
15
+ const store = new LocalReportStore(resolve(request.output ?? resolve(request.directory, '.repometry')));
16
+ const { lcov } = request;
17
+ return executeReview(request, {
18
+ readHead: id => readIfAvailable(store, id),
19
+ readBase: id => readIfAvailable(store, id),
20
+ async readRevisions() {
21
+ const directory = await gitRoot(request.directory);
22
+ const [head, base] = await Promise.all([resolveGitCommit(directory, request.revision), resolveGitCommit(directory, request.base)]);
23
+ return { head, base, mergeBase: () => findMergeBase(directory, base, head) };
24
+ },
25
+ ...(lcov === undefined ? {} : { measureChanged: () => measureChangedLines({ ...request, lcov }) }),
26
+ ...overrides,
27
+ });
28
+ }
29
+ async function readIfAvailable(reader, id) {
30
+ try {
31
+ return await reader.read({ kind: 'commit', id });
32
+ }
33
+ catch (error) {
34
+ if (error instanceof Error && 'code' in error && error.code === 'ENOENT')
35
+ return null;
36
+ throw error;
37
+ }
38
+ }
@@ -0,0 +1,3 @@
1
+ import type { SourceContext, SourcePlugin } from '../core/ports/source-provider.js';
2
+ export declare const sourceProviders: readonly SourcePlugin[];
3
+ export declare function resolveSourceLocator(option: string | undefined, context: Omit<SourceContext, 'option'>, providers?: readonly SourcePlugin[]): import("../plugin.js").SourceLocator | undefined;
@@ -0,0 +1,29 @@
1
+ import { plan } from '../core/engine/plan.js';
2
+ import { githubSource, gitlabSource, localSource } from '../plugins/source/forges.js';
3
+ export const sourceProviders = [githubSource, gitlabSource, localSource];
4
+ export function resolveSourceLocator(option, context, providers = sourceProviders) {
5
+ plan({ plugins: providers, select: [], inputs: new Map() });
6
+ if (option === 'none')
7
+ return undefined;
8
+ if (option && option !== 'auto') {
9
+ const colon = option.indexOf(':');
10
+ const id = colon < 0 ? option : option.slice(0, colon);
11
+ const spec = colon < 0 ? undefined : option.slice(colon + 1);
12
+ const provider = providers.find(item => item.id === id);
13
+ if (!provider)
14
+ throw new Error(`Unknown source provider: ${id}. Choose ${providers.map(item => item.id).join(', ')}.`);
15
+ const locator = provider.locate({ ...context, option: spec });
16
+ if (!locator)
17
+ throw new Error(`Cannot locate sources for ${id}. Name the repository as ${id}:OWNER/REPO.`);
18
+ return locator;
19
+ }
20
+ const remoteProviders = providers.filter(provider => provider.id !== 'local');
21
+ for (const candidate of [{ env: context.env, remotes: [] }, { env: {}, remotes: context.remotes }]) {
22
+ for (const provider of remoteProviders) {
23
+ const locator = provider.locate(candidate);
24
+ if (locator)
25
+ return locator;
26
+ }
27
+ }
28
+ return providers.find(provider => provider.id === 'local')?.locate(context);
29
+ }
@@ -0,0 +1,10 @@
1
+ import type { Product } from './plugin.js';
2
+ import type { PlannedOperation } from './plan.js';
3
+ export type Outcome = {
4
+ readonly state: 'completed';
5
+ readonly product: Product;
6
+ } | {
7
+ readonly state: 'failed' | 'blocked';
8
+ readonly reason: string;
9
+ };
10
+ export declare function execute(plan: readonly PlannedOperation[], external: ReadonlyMap<string, Product>): Promise<ReadonlyMap<string, Outcome>>;
@@ -0,0 +1,49 @@
1
+ export async function execute(plan, external) {
2
+ const results = new Map();
3
+ for (const task of plan) {
4
+ const inputs = new Map();
5
+ for (const [name, binding] of task.inputs) {
6
+ const producer = 'operation' in binding ? results.get(binding.operation) : undefined;
7
+ const product = 'external' in binding ? external.get(binding.external)
8
+ : producer?.state === 'completed' ? producer.product : undefined;
9
+ if (product)
10
+ inputs.set(name, product);
11
+ }
12
+ const missing = [...task.inputs.keys()].filter(name => !inputs.has(name));
13
+ if (missing.length > 0) {
14
+ results.set(task.key, { state: 'blocked', reason: `Unavailable inputs: ${missing.join(', ')}` });
15
+ continue;
16
+ }
17
+ try {
18
+ for (const [name, contract] of Object.entries(task.operation.inputs)) {
19
+ readInput(inputs, name, contract);
20
+ }
21
+ const context = {
22
+ read: (port, contract) => {
23
+ if (!Object.hasOwn(task.operation.inputs, port) || task.operation.inputs[port]?.id !== contract.id) {
24
+ throw new Error(`Undeclared input contract: ${port} (${contract.id})`);
25
+ }
26
+ return readInput(inputs, port, contract);
27
+ },
28
+ };
29
+ const value = await task.operation.execute(context);
30
+ const { output } = task.operation;
31
+ if (!output.accepts(value))
32
+ throw new Error(`Invalid output for ${output.id}`);
33
+ if (task.validateOutput && !task.validateOutput(value))
34
+ throw new Error(`Output violates the schema for ${output.id}`);
35
+ results.set(task.key, { state: 'completed', product: { contract: output.id, value } });
36
+ }
37
+ catch (error) {
38
+ results.set(task.key, { state: 'failed', reason: error instanceof Error ? error.message : String(error) });
39
+ }
40
+ }
41
+ return results;
42
+ }
43
+ function readInput(inputs, port, contract) {
44
+ const product = inputs.get(port);
45
+ if (!product || product.contract !== contract.id || !contract.accepts(product.value)) {
46
+ throw new Error(`Invalid input: ${port} (${contract.id})`);
47
+ }
48
+ return product.value;
49
+ }
@@ -0,0 +1,4 @@
1
+ import type { LegacyPlugin, MetricDescriptor, Plugin, ProductDeclaration } from './plugin.js';
2
+ export declare function isCoreReportProduct(contract: string): boolean;
3
+ export declare function manifestProducts(plugin: Plugin | LegacyPlugin, allowLegacy: boolean): ReadonlyMap<string, ProductDeclaration> | undefined;
4
+ export declare function isMetricDescriptor(value: unknown): value is MetricDescriptor;
@@ -0,0 +1,104 @@
1
+ import { isRecord } from './plugin.js';
2
+ import { definitions } from '../model/measurement.js';
3
+ const kinds = new Set(['language', 'analysis', 'coverage', 'security', 'import', 'source']);
4
+ const persistence = new Set(['report', 'cache', 'transient']);
5
+ const units = new Set(['count', 'ratio', 'minutes']);
6
+ const scopes = new Set(['repository', 'file', 'function']);
7
+ const aggregates = new Set(['sum', 'max', 'none']);
8
+ const directions = new Set(['lower', 'higher', 'none']);
9
+ const coreMetrics = new Set(Object.values(definitions));
10
+ const coreProducts = new Set([
11
+ 'repometry.measurements/v1', 'repometry.findings-and-measurements/v1',
12
+ 'repometry.maintainability-file/v1', 'repometry.coverage-result/v1',
13
+ 'repometry.source-locator/v1',
14
+ ]);
15
+ export function isCoreReportProduct(contract) {
16
+ return coreProducts.has(contract);
17
+ }
18
+ export function manifestProducts(plugin, allowLegacy) {
19
+ const { id, kinds: declaredKinds, claims, produces, rules, config } = plugin;
20
+ if (declaredKinds === undefined && claims === undefined && produces === undefined) {
21
+ if (allowLegacy)
22
+ return undefined;
23
+ throw new Error(`Missing plugin manifest for ${id}. Declare kinds and produces.`);
24
+ }
25
+ if (Object.hasOwn(plugin, 'languages'))
26
+ throw new Error(`Plugin ${id} must declare languages in claims.languages`);
27
+ if (!strings(declaredKinds) || declaredKinds.length === 0 || declaredKinds.some(kind => !kinds.has(kind))) {
28
+ throw new Error(`Invalid kinds for plugin ${id}`);
29
+ }
30
+ if (claims !== undefined && (!isRecord(claims) || Object.entries(claims).some(([key, values]) => !['extensions', 'globs', 'languages'].includes(key) || !strings(values)
31
+ || (key === 'extensions' && values.some(extension => !/^\.[\w-]+$/.test(extension)))))) {
32
+ throw new Error(`Invalid file claims for plugin ${id}`);
33
+ }
34
+ if (!Array.isArray(produces))
35
+ throw new Error(`Plugin ${id} must declare its products`);
36
+ if (rules !== undefined && (!Array.isArray(rules) || !rules.every(isRuleDescriptor)
37
+ || new Set(rules.map(rule => rule.id)).size !== rules.length))
38
+ throw new Error(`Invalid or duplicate rules for plugin ${id}`);
39
+ if (config !== undefined && typeof config !== 'boolean' && !isRecord(config))
40
+ throw new Error(`Invalid configuration schema for plugin ${id}`);
41
+ const products = new Map();
42
+ const catalog = new Map();
43
+ for (const product of produces) {
44
+ if (!isRecord(product) || !text(product.contract) || !text(product.persistence) || !persistence.has(product.persistence)
45
+ || products.has(product.contract))
46
+ throw new Error(`Invalid or duplicate product for plugin ${id}`);
47
+ const { contract, schema, metrics } = product;
48
+ if ((schema === undefined && product.persistence !== 'transient' && !isCoreReportProduct(contract))
49
+ || (schema !== undefined && typeof schema !== 'boolean' && !isRecord(schema))) {
50
+ throw new Error(`Missing or invalid product schema for ${contract} in plugin ${id}`);
51
+ }
52
+ if (metrics !== undefined && (!Array.isArray(metrics) || !metrics.every(isMetricDescriptor))) {
53
+ throw new Error(`Invalid metric descriptors for ${contract} in plugin ${id}`);
54
+ }
55
+ const declaration = product;
56
+ for (const metric of declaration.metrics ?? []) {
57
+ if (catalog.has(metric.id))
58
+ throw new Error(`Duplicate metric ${metric.id} in plugin ${id}`);
59
+ catalog.set(metric.id, metric);
60
+ }
61
+ products.set(contract, declaration);
62
+ }
63
+ for (const rule of rules ?? []) {
64
+ if (rule.measure !== undefined && !catalog.has(rule.measure)) {
65
+ throw new Error(`Rule ${rule.id} in plugin ${id} references undeclared metric ${rule.measure}`);
66
+ }
67
+ }
68
+ for (const metric of catalog.values()) {
69
+ if (!metric.ratio)
70
+ continue;
71
+ for (const component of [metric.ratio.of, metric.ratio.over]) {
72
+ if (component === metric.id || (!catalog.has(component) && !coreMetrics.has(component))) {
73
+ throw new Error(`Ratio ${metric.id} in plugin ${id} references invalid component ${component}`);
74
+ }
75
+ }
76
+ }
77
+ return products;
78
+ }
79
+ function isRuleDescriptor(value) {
80
+ return isRecord(value) && text(value.id) && text(value.category) && optionalText(value.description)
81
+ && optionalText(value.measure) && (value.per === undefined || (Array.isArray(value.per) && value.per.length === 2 && value.per.every(text)))
82
+ && (value.defaults === undefined || (isRecord(value.defaults)
83
+ && Object.entries(value.defaults).every(([key, amount]) => (key === 'limit' || key === 'cost')
84
+ && (amount === undefined || (typeof amount === 'number' && Number.isFinite(amount) && amount >= 0)))));
85
+ }
86
+ export function isMetricDescriptor(value) {
87
+ return isRecord(value) && text(value.id) && text(value.label)
88
+ && text(value.unit) && units.has(value.unit) && text(value.scope) && scopes.has(value.scope)
89
+ && text(value.aggregate) && aggregates.has(value.aggregate) && text(value.better) && directions.has(value.better)
90
+ && optionalText(value.short) && optionalText(value.description) && optionalText(value.group)
91
+ && (value.ratio === undefined || (value.unit === 'ratio' && isRecord(value.ratio) && text(value.ratio.of) && text(value.ratio.over)))
92
+ && (value.bands === undefined || (Array.isArray(value.bands) && value.bands.length === 4
93
+ && value.bands.every((limit, index, array) => typeof limit === 'number' && Number.isFinite(limit)
94
+ && (index === 0 || limit > array[index - 1]))));
95
+ }
96
+ function strings(value) {
97
+ return Array.isArray(value) && value.every(text) && new Set(value).size === value.length;
98
+ }
99
+ function text(value) {
100
+ return typeof value === 'string' && value.trim().length > 0;
101
+ }
102
+ function optionalText(value) {
103
+ return value === undefined || text(value);
104
+ }
@@ -0,0 +1,22 @@
1
+ import type { LegacyPlugin, Operation, Plugin, ProductDeclaration } from './plugin.js';
2
+ export type InputBinding = {
3
+ readonly external: string;
4
+ } | {
5
+ readonly operation: string;
6
+ };
7
+ export interface PlanRequest {
8
+ readonly plugins: readonly (Plugin | LegacyPlugin)[];
9
+ readonly select: readonly string[];
10
+ readonly inputs: ReadonlyMap<string, string>;
11
+ readonly bindings?: ReadonlyMap<string, Readonly<Record<string, InputBinding>>>;
12
+ /** Explicit migration exception for named v1 plugins that predate the manifest. */
13
+ readonly legacyPluginIds?: readonly string[];
14
+ }
15
+ export interface PlannedOperation {
16
+ readonly key: string;
17
+ readonly operation: Operation;
18
+ readonly inputs: ReadonlyMap<string, InputBinding>;
19
+ readonly declaration?: ProductDeclaration;
20
+ readonly validateOutput?: (value: unknown) => boolean;
21
+ }
22
+ export declare function plan(request: PlanRequest): readonly PlannedOperation[];
@@ -0,0 +1,106 @@
1
+ import { Ajv2020 } from 'ajv/dist/2020.js';
2
+ import { pluginApi } from './plugin.js';
3
+ import { manifestProducts } from './manifest.js';
4
+ export function plan(request) {
5
+ const { operations, declarations } = indexOperations(request.plugins, new Set(request.legacyPluginIds));
6
+ const resolved = new Map();
7
+ const path = [];
8
+ function visit(key) {
9
+ const cycle = path.indexOf(key);
10
+ if (cycle >= 0)
11
+ throw new Error(`Plugin dependency cycle: ${[...path.slice(cycle), key].join(' -> ')}`);
12
+ if (resolved.has(key))
13
+ return;
14
+ const operation = operations.get(key);
15
+ if (!operation)
16
+ throw new Error(`Unknown operation: ${key}`);
17
+ path.push(key);
18
+ const inputs = new Map();
19
+ const declared = request.bindings?.get(key);
20
+ for (const name of Object.keys(declared ?? {})) {
21
+ if (!Object.hasOwn(operation.inputs, name))
22
+ throw new Error(`Unknown input port: ${key}.${name}`);
23
+ }
24
+ for (const [name, contract] of Object.entries(operation.inputs)) {
25
+ const explicit = declared && Object.hasOwn(declared, name) ? declared[name] : undefined;
26
+ const candidates = explicit ? [explicit] : candidatesFor(contract.id, request.inputs, operations);
27
+ const binding = candidates[0];
28
+ if (!binding)
29
+ throw new Error(`Missing input ${key}.${name} (${contract.id})`);
30
+ if (candidates.length > 1)
31
+ throw new Error(`Ambiguous input ${key}.${name} (${contract.id})`);
32
+ if (('external' in binding) === ('operation' in binding)) {
33
+ throw new Error(`Expected one binding for ${key}.${name}`);
34
+ }
35
+ const actual = 'external' in binding
36
+ ? request.inputs.get(binding.external)
37
+ : operations.get(binding.operation)?.output.id;
38
+ if (actual !== contract.id)
39
+ throw new Error(`Incompatible input ${key}.${name}: expected ${contract.id}, got ${actual ?? 'missing'}`);
40
+ if ('operation' in binding)
41
+ visit(binding.operation);
42
+ inputs.set(name, binding);
43
+ }
44
+ path.pop();
45
+ const declaration = declarations.get(key);
46
+ const validateOutput = declaration?.schema === undefined ? undefined : validateSchema(declaration.schema, key);
47
+ resolved.set(key, { key, operation, inputs, ...(declaration === undefined ? {} : { declaration }),
48
+ ...(validateOutput === undefined ? {} : { validateOutput }) });
49
+ }
50
+ for (const key of request.select)
51
+ visit(key);
52
+ return [...resolved.values()];
53
+ }
54
+ function validateSchema(schema, key) {
55
+ try {
56
+ return new Ajv2020().compile(schema);
57
+ }
58
+ catch (error) {
59
+ throw new Error(`Invalid product schema for ${key}`, { cause: error });
60
+ }
61
+ }
62
+ function indexOperations(plugins, legacyPlugins) {
63
+ const ids = new Set();
64
+ const operations = new Map();
65
+ const declarations = new Map();
66
+ const metricOwners = new Map();
67
+ for (const plugin of plugins) {
68
+ if (plugin.api !== pluginApi)
69
+ throw new Error(`Unsupported plugin API for ${plugin.id}: ${plugin.api}`);
70
+ if (ids.has(plugin.id) || !plugin.id || plugin.id.includes('/'))
71
+ throw new Error(`Invalid or duplicate plugin ID: ${plugin.id}`);
72
+ ids.add(plugin.id);
73
+ const products = manifestProducts(plugin, legacyPlugins.has(plugin.id));
74
+ for (const declaration of products?.values() ?? []) {
75
+ for (const metric of declaration.metrics ?? []) {
76
+ const owner = metricOwners.get(metric.id);
77
+ if (owner !== undefined)
78
+ throw new Error(`Duplicate metric ${metric.id} in plugins ${owner} and ${plugin.id}`);
79
+ metricOwners.set(metric.id, plugin.id);
80
+ }
81
+ }
82
+ for (const operation of plugin.operations) {
83
+ const key = `${plugin.id}/${operation.id}`;
84
+ if (operations.has(key) || !operation.id || operation.id.includes('/'))
85
+ throw new Error(`Invalid or duplicate operation: ${key}`);
86
+ if (products !== undefined) {
87
+ const declaration = products.get(operation.output.id);
88
+ if (!declaration)
89
+ throw new Error(`Undeclared output for ${key}: ${operation.output.id}`);
90
+ declarations.set(key, declaration);
91
+ }
92
+ operations.set(key, operation);
93
+ }
94
+ }
95
+ return { operations, declarations };
96
+ }
97
+ function candidatesFor(contract, inputs, operations) {
98
+ const candidates = [];
99
+ for (const [external, id] of inputs)
100
+ if (id === contract)
101
+ candidates.push({ external });
102
+ for (const [operation, candidate] of operations)
103
+ if (candidate.output.id === contract)
104
+ candidates.push({ operation });
105
+ return candidates;
106
+ }
@@ -0,0 +1,59 @@
1
+ import type { MetricDescriptor } from '../model/metric-descriptor.js';
2
+ export type { MetricDescriptor, MetricScope } from '../model/metric-descriptor.js';
3
+ export declare const pluginApi = "repometry.plugin/v1";
4
+ export interface DataContract<T = unknown> {
5
+ readonly id: string;
6
+ readonly accepts: (value: unknown) => value is T;
7
+ }
8
+ export interface Product {
9
+ readonly contract: string;
10
+ readonly value: unknown;
11
+ }
12
+ export interface InspectionInputs {
13
+ read<T>(port: string, contract: DataContract<T>): T;
14
+ }
15
+ export interface Operation {
16
+ readonly id: string;
17
+ readonly role: 'provider' | 'inspection';
18
+ readonly inputs: Readonly<Record<string, DataContract>>;
19
+ readonly output: DataContract;
20
+ execute(inputs: InspectionInputs): unknown | Promise<unknown>;
21
+ }
22
+ export interface RuleDescriptor {
23
+ readonly id: string;
24
+ readonly category: string;
25
+ readonly description?: string;
26
+ readonly defaults?: {
27
+ readonly limit?: number;
28
+ readonly cost?: number;
29
+ };
30
+ readonly measure?: string;
31
+ readonly per?: readonly [singular: string, plural: string];
32
+ }
33
+ export type PluginConfigSchema = boolean | Readonly<Record<string, unknown>>;
34
+ export type PluginKind = 'language' | 'analysis' | 'coverage' | 'security' | 'import' | 'source';
35
+ export interface FileClaims {
36
+ readonly extensions?: readonly string[];
37
+ readonly globs?: readonly string[];
38
+ readonly languages?: readonly string[];
39
+ }
40
+ export interface ProductDeclaration {
41
+ readonly contract: string;
42
+ readonly persistence: 'report' | 'cache' | 'transient';
43
+ readonly schema?: PluginConfigSchema;
44
+ readonly metrics?: readonly MetricDescriptor[];
45
+ }
46
+ export interface Plugin {
47
+ readonly id: string;
48
+ readonly version: string;
49
+ readonly api: string;
50
+ readonly tools?: Readonly<Record<string, string>>;
51
+ readonly operations: readonly Operation[];
52
+ readonly rules?: readonly RuleDescriptor[];
53
+ readonly config?: PluginConfigSchema;
54
+ readonly kinds: readonly PluginKind[];
55
+ readonly claims?: FileClaims;
56
+ readonly produces: readonly ProductDeclaration[];
57
+ }
58
+ export type LegacyPlugin = Omit<Plugin, 'kinds' | 'claims' | 'produces'>;
59
+ export declare function isRecord(value: unknown): value is Record<string, unknown>;
@@ -0,0 +1,4 @@
1
+ export const pluginApi = 'repometry.plugin/v1';
2
+ export function isRecord(value) {
3
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
4
+ }
@@ -0,0 +1,16 @@
1
+ import type { FindingResult } from '../model/finding.js';
2
+ import type { PluginData } from '../model/plugin-data.js';
3
+ import type { Plugin, Product } from './plugin.js';
4
+ import type { PlannedOperation } from './plan.js';
5
+ export declare class ReportProducts {
6
+ private readonly metrics;
7
+ private readonly measured;
8
+ private readonly privateMetrics;
9
+ private readonly products;
10
+ private readonly contracts;
11
+ private readonly rules;
12
+ private readonly declared;
13
+ constructor(plugins: readonly Plugin[]);
14
+ record(task: PlannedOperation, { contract, value }: Product, path?: string): FindingResult | undefined;
15
+ result(): PluginData | undefined;
16
+ }
@@ -0,0 +1,85 @@
1
+ import { isDeepStrictEqual } from 'node:util';
2
+ import { findingResult } from '../model/finding.js';
3
+ import { measurements } from '../model/measurement.js';
4
+ import { isRecord } from './plugin.js';
5
+ import { isCoreReportProduct } from './manifest.js';
6
+ export class ReportProducts {
7
+ metrics = new Map();
8
+ measured = new Set();
9
+ privateMetrics = new Set();
10
+ products = new Map();
11
+ contracts = new Map();
12
+ rules;
13
+ declared;
14
+ constructor(plugins) {
15
+ this.declared = plugins.some(plugin => plugin.produces !== undefined);
16
+ this.rules = plugins.flatMap(({ id, rules }) => rules?.length ? [{ plugin: id, rules }] : []);
17
+ for (const plugin of plugins) {
18
+ for (const product of plugin.produces ?? []) {
19
+ if (product.persistence !== 'report')
20
+ continue;
21
+ if (product.schema !== undefined) {
22
+ const previous = this.contracts.get(product.contract);
23
+ if (previous !== undefined && !isDeepStrictEqual(previous, product.schema)) {
24
+ throw new Error(`Conflicting product schemas: ${product.contract}`);
25
+ }
26
+ this.contracts.set(product.contract, product.schema);
27
+ }
28
+ for (const metric of product.metrics ?? []) {
29
+ const existing = this.metrics.get(metric.id);
30
+ if (existing && !isDeepStrictEqual(existing, metric))
31
+ throw new Error(`Conflicting metric declaration: ${metric.id}`);
32
+ this.metrics.set(metric.id, metric);
33
+ if (plugin.kinds?.includes('security'))
34
+ this.privateMetrics.add(metric.id);
35
+ }
36
+ }
37
+ }
38
+ }
39
+ record(task, { contract, value }, path) {
40
+ if (task.declaration?.persistence !== 'report')
41
+ return undefined;
42
+ const rows = measurements.accepts(value) ? { measurements: value, findings: [] }
43
+ : findingResult.accepts(value) ? value
44
+ : isRecord(value) && measurements.accepts(value.measurements) ? { measurements: value.measurements, findings: [] } : undefined;
45
+ if (rows) {
46
+ const declared = new Set(task.declaration.metrics?.map(metric => metric.id));
47
+ const unknown = rows.measurements.find(row => !declared.has(row.definition));
48
+ if (unknown)
49
+ throw new Error(`Undeclared metric from ${task.key}: ${unknown.definition}`);
50
+ }
51
+ if (!isCoreReportProduct(contract)) {
52
+ if (!isJson(value))
53
+ throw new Error(`Report product ${contract} is not JSON data`);
54
+ const record = { operation: task.key, ...(path === undefined ? {} : { path }), value };
55
+ const existing = this.products.get(contract);
56
+ if (existing)
57
+ existing.push(record);
58
+ else
59
+ this.products.set(contract, [record]);
60
+ }
61
+ for (const metric of task.declaration.metrics ?? [])
62
+ this.measured.add(metric.id);
63
+ return rows;
64
+ }
65
+ result() {
66
+ if (!this.declared)
67
+ return undefined;
68
+ return { metrics: [...this.metrics.values()], measured: [...this.measured],
69
+ ...(this.privateMetrics.size ? { privateMetrics: [...this.privateMetrics] } : {}),
70
+ ...(this.contracts.size ? { contracts: Object.fromEntries(this.contracts) } : {}),
71
+ rules: this.rules, products: Object.fromEntries(this.products) };
72
+ }
73
+ }
74
+ function isJson(value, depth = 0) {
75
+ if (depth > 512)
76
+ return false;
77
+ if (value === null || typeof value === 'boolean' || typeof value === 'string')
78
+ return true;
79
+ if (typeof value === 'number')
80
+ return Number.isFinite(value);
81
+ if (Array.isArray(value))
82
+ return value.every(item => isJson(item, depth + 1));
83
+ return isRecord(value) && (Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null)
84
+ && Object.values(value).every(item => isJson(item, depth + 1));
85
+ }
@@ -0,0 +1,8 @@
1
+ export interface LineRange {
2
+ readonly first: number;
3
+ readonly last: number;
4
+ }
5
+ export interface GitChanges {
6
+ readonly files: ReadonlyMap<string, readonly LineRange[]>;
7
+ readonly gaps: ReadonlyMap<string, string>;
8
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,11 @@
1
+ export declare const churnSettings: {
2
+ readonly method: 'first-parent-path-touches/v1';
3
+ readonly lookbackDays: 90;
4
+ readonly maxCommits: 512;
5
+ };
6
+ export interface ChurnWindow {
7
+ readonly endingAt: string;
8
+ readonly commits: number;
9
+ readonly shallow: boolean;
10
+ readonly capReached: boolean;
11
+ }
@@ -0,0 +1,5 @@
1
+ export const churnSettings = {
2
+ method: 'first-parent-path-touches/v1',
3
+ lookbackDays: 90,
4
+ maxCommits: 512,
5
+ };
@@ -0,0 +1,16 @@
1
+ export interface Candidate {
2
+ readonly start: number;
3
+ readonly end: number;
4
+ readonly line: number;
5
+ readonly endLine: number;
6
+ readonly codeLines: number;
7
+ readonly nodes: number;
8
+ readonly exact: string;
9
+ readonly similar: string;
10
+ }
11
+ export interface CloneSource {
12
+ readonly path: string;
13
+ readonly codeLines: readonly number[];
14
+ readonly candidates: readonly Candidate[];
15
+ }
16
+ export declare function isCloneSource(value: unknown): value is CloneSource;
@@ -0,0 +1,14 @@
1
+ import { isRecord } from '../engine/plugin.js';
2
+ function isCandidate(value) {
3
+ return isRecord(value) && isCount(value.start) && isCount(value.end) && value.start < value.end
4
+ && isCount(value.line) && value.line > 0 && isCount(value.endLine) && value.endLine >= value.line
5
+ && isCount(value.codeLines) && isCount(value.nodes) && typeof value.exact === 'string' && typeof value.similar === 'string';
6
+ }
7
+ function isCount(value) {
8
+ return typeof value === 'number' && Number.isSafeInteger(value) && value >= 0;
9
+ }
10
+ export function isCloneSource(value) {
11
+ return isRecord(value) && typeof value.path === 'string' && Array.isArray(value.codeLines)
12
+ && value.codeLines.every((line, index, lines) => isCount(line) && line > (lines[index - 1] ?? 0))
13
+ && Array.isArray(value.candidates) && value.candidates.every(isCandidate);
14
+ }
@@ -0,0 +1,30 @@
1
+ import type { DataContract } from '../engine/plugin.js';
2
+ import type { CloneSource } from './clone-source.js';
3
+ export declare const structuralCheckIds: readonly ['function-parameters', 'return-statements', 'boolean-logic', 'nested-control-flow', 'function-complexity', 'file-complexity'];
4
+ export type StructuralCheck = typeof structuralCheckIds[number];
5
+ export interface FunctionComplexity {
6
+ readonly name: string;
7
+ readonly line?: number;
8
+ readonly column?: number;
9
+ readonly value: number;
10
+ }
11
+ export interface StructuralObservation {
12
+ readonly rule: StructuralCheck;
13
+ readonly value: number;
14
+ readonly label: string;
15
+ readonly line?: number;
16
+ readonly endLine?: number;
17
+ }
18
+ export interface CodeStructure {
19
+ readonly path: string;
20
+ readonly lines: number;
21
+ readonly functions: number;
22
+ readonly classes: number;
23
+ readonly cognitiveComplexity: number;
24
+ readonly commentLines: number;
25
+ readonly cyclomaticFunctions: readonly FunctionComplexity[];
26
+ readonly cognitiveFunctions: readonly FunctionComplexity[];
27
+ readonly observations: readonly StructuralObservation[];
28
+ readonly clones: CloneSource;
29
+ }
30
+ export declare const codeStructure: DataContract<CodeStructure>;