repometry 0.4.1 → 0.5.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 (190) hide show
  1. package/README.md +4 -0
  2. package/package.json +1 -1
  3. package/target/main/resources/report/json/report-v2.schema.json +13 -1
  4. package/target/main/resources/viewer/files.css +7 -3
  5. package/target/main/resources/viewer/styles.css +2 -2
  6. package/target/main/ts/api/git/git.d.ts +1 -0
  7. package/target/main/ts/api/git/git.js +12 -0
  8. package/target/main/ts/api/git/inspection-source.js +2 -8
  9. package/target/main/ts/api/git/local.d.ts +1 -1
  10. package/target/main/ts/api/git/local.js +39 -5
  11. package/target/main/ts/api/process/docker-tool-runner.d.ts +13 -0
  12. package/target/main/ts/api/process/docker-tool-runner.js +108 -0
  13. package/target/main/ts/api/process/failure.d.ts +1 -0
  14. package/target/main/ts/api/process/failure.js +12 -0
  15. package/target/main/ts/api/process/plugin.d.ts +10 -0
  16. package/target/main/ts/api/process/plugin.js +96 -0
  17. package/target/main/ts/compose/analyze-snapshot.d.ts +3 -2
  18. package/target/main/ts/compose/analyze-snapshot.js +82 -29
  19. package/target/main/ts/compose/inspect.d.ts +5 -0
  20. package/target/main/ts/compose/inspect.js +10 -6
  21. package/target/main/ts/core/engine/execute.d.ts +3 -1
  22. package/target/main/ts/core/engine/execute.js +14 -2
  23. package/target/main/ts/core/engine/operation-cache.d.ts +14 -0
  24. package/target/main/ts/core/engine/operation-cache.js +66 -0
  25. package/target/main/ts/core/engine/plan.d.ts +1 -0
  26. package/target/main/ts/core/engine/plan.js +22 -3
  27. package/target/main/ts/core/engine/plugin.d.ts +8 -1
  28. package/target/main/ts/core/engine/plugin.js +1 -3
  29. package/target/main/ts/core/engine/report-products.js +2 -13
  30. package/target/main/ts/core/model/clone-source.js +1 -1
  31. package/target/main/ts/core/model/code-structure.d.ts +3 -0
  32. package/target/main/ts/core/model/code-structure.js +4 -1
  33. package/target/main/ts/core/model/finding-ignore.js +1 -1
  34. package/target/main/ts/core/model/finding.js +1 -1
  35. package/target/main/ts/core/model/line-coverage.d.ts +5 -1
  36. package/target/main/ts/core/model/line-coverage.js +14 -11
  37. package/target/main/ts/core/model/measurement.js +1 -1
  38. package/target/main/ts/core/model/plugin-data.d.ts +2 -0
  39. package/target/main/ts/core/model/plugin-data.js +15 -1
  40. package/target/main/ts/core/model/quality-summary.js +1 -1
  41. package/target/main/ts/core/model/scanner-import.js +1 -1
  42. package/target/main/ts/core/model/snapshot.d.ts +1 -0
  43. package/target/main/ts/core/model/snapshot.js +5 -1
  44. package/target/main/ts/core/model/source.d.ts +3 -0
  45. package/target/main/ts/core/model/source.js +15 -0
  46. package/target/main/ts/core/ports/tool-runner.d.ts +18 -0
  47. package/target/main/ts/core/ports/tool-runner.js +2 -0
  48. package/target/main/ts/plugin.d.ts +7 -1
  49. package/target/main/ts/plugin.js +3 -1
  50. package/target/main/ts/plugins/coverage/coverage.d.ts +5 -2
  51. package/target/main/ts/plugins/coverage/coverage.js +35 -10
  52. package/target/main/ts/plugins/language-js/function-facts.d.ts +1 -0
  53. package/target/main/ts/plugins/language-js/function-facts.js +30 -4
  54. package/target/main/ts/report/html/app/viewer-chart-bars.d.ts +11 -0
  55. package/target/main/ts/report/html/app/viewer-chart-bars.js +54 -0
  56. package/target/main/ts/report/html/app/viewer-chart-label.d.ts +15 -0
  57. package/target/main/ts/report/html/app/viewer-chart-label.js +43 -0
  58. package/target/main/ts/report/html/app/viewer-chart-line.d.ts +24 -0
  59. package/target/main/ts/report/html/app/viewer-chart-line.js +89 -0
  60. package/target/main/ts/report/html/app/viewer-chart-points.d.ts +49 -0
  61. package/target/main/ts/report/html/app/viewer-chart-points.js +74 -0
  62. package/target/main/ts/report/html/app/viewer-chart-scale.d.ts +21 -0
  63. package/target/main/ts/report/html/app/viewer-chart-scale.js +93 -0
  64. package/target/main/ts/report/html/app/viewer-chart-svg.d.ts +28 -0
  65. package/target/main/ts/report/html/app/viewer-chart-svg.js +41 -0
  66. package/target/main/ts/report/html/app/viewer-chart-time.d.ts +26 -0
  67. package/target/main/ts/report/html/app/viewer-chart-time.js +150 -0
  68. package/target/main/ts/report/html/app/viewer-chart-tip.d.ts +4 -0
  69. package/target/main/ts/report/html/app/viewer-chart-tip.js +210 -0
  70. package/target/main/ts/report/html/app/viewer-chart-x.d.ts +12 -0
  71. package/target/main/ts/report/html/app/viewer-chart-x.js +50 -0
  72. package/target/main/ts/report/html/app/viewer-chart.d.ts +4 -98
  73. package/target/main/ts/report/html/app/viewer-chart.js +16 -677
  74. package/target/main/ts/report/html/app/viewer-code-map.d.ts +27 -0
  75. package/target/main/ts/report/html/app/viewer-code-map.js +175 -0
  76. package/target/main/ts/report/html/app/viewer-columns.d.ts +38 -0
  77. package/target/main/ts/report/html/app/viewer-columns.js +92 -0
  78. package/target/main/ts/report/html/app/viewer-commit-picker.d.ts +12 -0
  79. package/target/main/ts/report/html/app/viewer-commit-picker.js +229 -0
  80. package/target/main/ts/report/html/app/viewer-commits.d.ts +5 -9
  81. package/target/main/ts/report/html/app/viewer-commits.js +17 -216
  82. package/target/main/ts/report/html/app/viewer-controls.d.ts +43 -0
  83. package/target/main/ts/report/html/app/viewer-controls.js +141 -0
  84. package/target/main/ts/report/html/app/viewer-copy.d.ts +17 -0
  85. package/target/main/ts/report/html/app/viewer-copy.js +64 -0
  86. package/target/main/ts/report/html/app/viewer-diagnostics.d.ts +4 -0
  87. package/target/main/ts/report/html/app/viewer-diagnostics.js +60 -0
  88. package/target/main/ts/report/html/app/viewer-dom.d.ts +27 -0
  89. package/target/main/ts/report/html/app/viewer-dom.js +99 -0
  90. package/target/main/ts/report/html/app/viewer-file-aside.d.ts +19 -0
  91. package/target/main/ts/report/html/app/viewer-file-aside.js +124 -0
  92. package/target/main/ts/report/html/app/viewer-file-figures.d.ts +15 -0
  93. package/target/main/ts/report/html/app/viewer-file-figures.js +60 -0
  94. package/target/main/ts/report/html/app/viewer-file-source.d.ts +7 -0
  95. package/target/main/ts/report/html/app/viewer-file-source.js +119 -0
  96. package/target/main/ts/report/html/app/viewer-files.d.ts +2 -118
  97. package/target/main/ts/report/html/app/viewer-files.js +24 -2184
  98. package/target/main/ts/report/html/app/viewer-filter.d.ts +3 -51
  99. package/target/main/ts/report/html/app/viewer-filter.js +111 -450
  100. package/target/main/ts/report/html/app/viewer-hotspots.d.ts +4 -0
  101. package/target/main/ts/report/html/app/viewer-hotspots.js +131 -0
  102. package/target/main/ts/report/html/app/viewer-inspection.d.ts +69 -0
  103. package/target/main/ts/report/html/app/viewer-inspection.js +36 -0
  104. package/target/main/ts/report/html/app/viewer-issue-group.d.ts +27 -0
  105. package/target/main/ts/report/html/app/viewer-issue-group.js +174 -0
  106. package/target/main/ts/report/html/app/viewer-issues.d.ts +4 -0
  107. package/target/main/ts/report/html/app/viewer-issues.js +173 -0
  108. package/target/main/ts/report/html/app/viewer-language-bar.d.ts +9 -0
  109. package/target/main/ts/report/html/app/viewer-language-bar.js +72 -0
  110. package/target/main/ts/report/html/app/viewer-languages.d.ts +27 -0
  111. package/target/main/ts/report/html/app/viewer-languages.js +93 -0
  112. package/target/main/ts/report/html/app/viewer-layout.d.ts +14 -0
  113. package/target/main/ts/report/html/app/viewer-layout.js +134 -0
  114. package/target/main/ts/report/html/app/viewer-line-coverage.d.ts +47 -0
  115. package/target/main/ts/report/html/app/viewer-line-coverage.js +121 -0
  116. package/target/main/ts/report/html/app/viewer-locations.d.ts +16 -0
  117. package/target/main/ts/report/html/app/viewer-locations.js +31 -0
  118. package/target/main/ts/report/html/app/viewer-map-scale.d.ts +26 -0
  119. package/target/main/ts/report/html/app/viewer-map-scale.js +147 -0
  120. package/target/main/ts/report/html/app/viewer-map-shape.d.ts +42 -0
  121. package/target/main/ts/report/html/app/viewer-map-shape.js +102 -0
  122. package/target/main/ts/report/html/app/viewer-metric-format.d.ts +23 -0
  123. package/target/main/ts/report/html/app/viewer-metric-format.js +93 -0
  124. package/target/main/ts/report/html/app/viewer-metric-registry.d.ts +0 -20
  125. package/target/main/ts/report/html/app/viewer-metric-registry.js +0 -77
  126. package/target/main/ts/report/html/app/viewer-metrics-view.d.ts +4 -0
  127. package/target/main/ts/report/html/app/viewer-metrics-view.js +162 -0
  128. package/target/main/ts/report/html/app/viewer-metrics.d.ts +6 -1
  129. package/target/main/ts/report/html/app/viewer-metrics.js +53 -35
  130. package/target/main/ts/report/html/app/viewer-overview-cards.d.ts +12 -0
  131. package/target/main/ts/report/html/app/viewer-overview-cards.js +112 -0
  132. package/target/main/ts/report/html/app/viewer-overview-hotspots.d.ts +9 -0
  133. package/target/main/ts/report/html/app/viewer-overview-hotspots.js +173 -0
  134. package/target/main/ts/report/html/app/viewer-overview-lead.d.ts +12 -0
  135. package/target/main/ts/report/html/app/viewer-overview-lead.js +116 -0
  136. package/target/main/ts/report/html/app/viewer-profile-badges.d.ts +11 -0
  137. package/target/main/ts/report/html/app/viewer-profile-badges.js +119 -0
  138. package/target/main/ts/report/html/app/viewer-profile-table.d.ts +29 -0
  139. package/target/main/ts/report/html/app/viewer-profile-table.js +124 -0
  140. package/target/main/ts/report/html/app/viewer-profile.d.ts +2 -6
  141. package/target/main/ts/report/html/app/viewer-profile.js +6 -248
  142. package/target/main/ts/report/html/app/viewer-pull-sections.d.ts +4 -0
  143. package/target/main/ts/report/html/app/viewer-pull-sections.js +118 -0
  144. package/target/main/ts/report/html/app/viewer-pull-trend.d.ts +5 -0
  145. package/target/main/ts/report/html/app/viewer-pull-trend.js +63 -0
  146. package/target/main/ts/report/html/app/viewer-pulls.d.ts +0 -1
  147. package/target/main/ts/report/html/app/viewer-pulls.js +28 -178
  148. package/target/main/ts/report/html/app/viewer-query-field.d.ts +19 -0
  149. package/target/main/ts/report/html/app/viewer-query-field.js +203 -0
  150. package/target/main/ts/report/html/app/viewer-route.d.ts +34 -0
  151. package/target/main/ts/report/html/app/viewer-route.js +55 -0
  152. package/target/main/ts/report/html/app/viewer-shell.d.ts +20 -0
  153. package/target/main/ts/report/html/app/viewer-shell.js +116 -0
  154. package/target/main/ts/report/html/app/viewer-source-view.d.ts +49 -0
  155. package/target/main/ts/report/html/app/viewer-source-view.js +150 -0
  156. package/target/main/ts/report/html/app/viewer-source.d.ts +0 -84
  157. package/target/main/ts/report/html/app/viewer-source.js +7 -363
  158. package/target/main/ts/report/html/app/viewer-suggest.d.ts +13 -0
  159. package/target/main/ts/report/html/app/viewer-suggest.js +91 -0
  160. package/target/main/ts/report/html/app/viewer-sunburst.d.ts +5 -0
  161. package/target/main/ts/report/html/app/viewer-sunburst.js +40 -0
  162. package/target/main/ts/report/html/app/viewer-table-cells.d.ts +25 -0
  163. package/target/main/ts/report/html/app/viewer-table-cells.js +129 -0
  164. package/target/main/ts/report/html/app/viewer-table-rows.d.ts +54 -0
  165. package/target/main/ts/report/html/app/viewer-table-rows.js +95 -0
  166. package/target/main/ts/report/html/app/viewer-tokenizer.d.ts +16 -0
  167. package/target/main/ts/report/html/app/viewer-tokenizer.js +192 -0
  168. package/target/main/ts/report/html/app/viewer-totals.d.ts +14 -0
  169. package/target/main/ts/report/html/app/viewer-totals.js +89 -0
  170. package/target/main/ts/report/html/app/viewer-treemap.d.ts +24 -0
  171. package/target/main/ts/report/html/app/viewer-treemap.js +112 -0
  172. package/target/main/ts/report/html/app/viewer-trend-data.d.ts +49 -0
  173. package/target/main/ts/report/html/app/viewer-trend-data.js +105 -0
  174. package/target/main/ts/report/html/app/viewer-trend-nav.d.ts +5 -0
  175. package/target/main/ts/report/html/app/viewer-trend-nav.js +85 -0
  176. package/target/main/ts/report/html/app/viewer-trend-points.d.ts +30 -0
  177. package/target/main/ts/report/html/app/viewer-trend-points.js +128 -0
  178. package/target/main/ts/report/html/app/viewer-trend-series.d.ts +26 -0
  179. package/target/main/ts/report/html/app/viewer-trend-series.js +98 -0
  180. package/target/main/ts/report/html/app/viewer-trends.d.ts +2 -70
  181. package/target/main/ts/report/html/app/viewer-trends.js +41 -392
  182. package/target/main/ts/report/html/app/viewer.js +152 -663
  183. package/target/main/ts/report/html/site/badges.js +41 -18
  184. package/target/main/ts/report/json/store/local-store.js +2 -12
  185. package/target/main/ts/report/json/store/operation-cache.d.ts +8 -0
  186. package/target/main/ts/report/json/store/operation-cache.js +32 -0
  187. package/target/main/ts/report/json/store/replace-file.d.ts +1 -0
  188. package/target/main/ts/report/json/store/replace-file.js +14 -0
  189. package/target/main/ts/report.d.ts +1 -0
  190. package/target/main/ts/report.js +1 -0
package/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Repometry
2
2
 
3
+ [![Maintainability](https://idleware.github.io/repometry/maintainability.svg)](https://idleware.github.io/repometry/)
4
+ [![Coverage](https://idleware.github.io/repometry/coverage.svg)](https://idleware.github.io/repometry/)
5
+ [![Security](https://idleware.github.io/repometry/security.svg)](https://idleware.github.io/repometry/)
6
+
3
7
  > Track repository metrics without SaaS
4
8
 
5
9
  Git can serve as a project’s single source of truth for code, tests, docs, and CI configuration. Repometry lets you keep coverage and maintainability metrics alongside your code, commit by commit.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "repometry",
3
- "version": "0.4.1",
3
+ "version": "0.5.0",
4
4
  "description": "Track repository metrics without SaaS",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -155,7 +155,9 @@
155
155
  "covered": { "$ref": "#/$defs/lcovLineRanges" },
156
156
  "uncovered": { "$ref": "#/$defs/lcovLineRanges" },
157
157
  "partial": { "$ref": "#/$defs/lcovLineRanges" },
158
- "hits": { "$ref": "#/$defs/lcovHitRuns" }
158
+ "hits": { "$ref": "#/$defs/lcovHitRuns" },
159
+ "functionCalls": { "$ref": "#/$defs/lcovFunctionCalls" },
160
+ "functionBodies": { "$ref": "#/$defs/lcovLineRanges" }
159
161
  }
160
162
  }
161
163
  },
@@ -179,6 +181,16 @@
179
181
  "items": false
180
182
  }
181
183
  },
184
+ "lcovFunctionCalls": {
185
+ "type": "array",
186
+ "description": "Pairs of 1-based function declaration line and summed LCOV call count, ordered by line. Multiple functions can share a line.",
187
+ "items": {
188
+ "type": "array",
189
+ "minItems": 2,
190
+ "prefixItems": [{ "type": "integer", "minimum": 1 }, { "type": "integer", "minimum": 0 }],
191
+ "items": false
192
+ }
193
+ },
182
194
  "pluginRule": {
183
195
  "type": "object",
184
196
  "required": ["id", "category"],
@@ -460,9 +460,13 @@
460
460
  .src[data-layer="coverage"] .src-line { grid-template-columns: 3.25rem 3rem max-content; }
461
461
  .src[data-layer="coverage"] .src-cov { display: flex; flex: 1; align-self: stretch; align-items: center; justify-content: flex-end;
462
462
  padding-right: .5rem; font-family: var(--sans); font-size: .6875rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
463
- .src-cov-mark-covered { color: var(--cov-hit-ink); background: var(--cov-hit-bg); }
464
- .src-cov-mark-partial { color: var(--cov-part-ink); background: var(--cov-part-bg); }
465
- .src-cov-mark-uncovered { color: var(--cov-miss-ink); background: var(--cov-miss-bg); }
463
+ .src-cov-mark-covered { --cov-bg: var(--cov-hit-bg); color: var(--cov-hit-ink); background: var(--cov-bg); }
464
+ .src-cov-mark-partial { --cov-bg: var(--cov-part-bg); color: var(--cov-part-ink); background: var(--cov-bg); }
465
+ .src-cov-mark-uncovered { --cov-bg: var(--cov-miss-bg); color: var(--cov-miss-ink); background: var(--cov-bg); }
466
+ /* The strip runs from the panel's head to its foot: the first and last cells reach over the code's own padding. */
467
+ .src[data-layer="coverage"] .src-first .src-cov { box-shadow: 0 -.375rem 0 var(--cov-bg); }
468
+ .src[data-layer="coverage"] .src-last .src-cov { box-shadow: 0 .75rem 0 var(--cov-bg); }
469
+ .src[data-layer="coverage"] .src-first.src-last .src-cov { box-shadow: 0 -.375rem 0 var(--cov-bg), 0 .75rem 0 var(--cov-bg); }
466
470
  .src-target, .src-target:hover { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
467
471
  .src-complexity { min-width: 1.375rem; padding: 0 .25rem; font-family: var(--sans); font-size: .6875rem; font-weight: 650; line-height: 1.125rem; text-align: center; border-radius: 4px; color: var(--secondary); background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--rule); }
468
472
  .src-band-1 { color: var(--heat-ink); background: var(--heat-1); box-shadow: none; }
@@ -417,9 +417,9 @@ a.tc-tip-entry:hover { background: var(--surface-2); }
417
417
  /* Trends page */
418
418
  .trend-nav { display: grid; gap: 1.125rem; }
419
419
  .trend-group h3 { display: flex; align-items: center; justify-content: space-between; gap: .75rem; min-height: 1.5rem; margin: 0 0 .3rem; padding: 0 .5rem 0 .75rem; color: var(--muted); font-size: .75rem; font-weight: 600; letter-spacing: .07em; text-transform: uppercase; }
420
- /* A group's reading: the grade or the coverage in its colour when it earns one, the size plain. */
420
+ /* A group's reading: the maintainability grade, or the coverage in its grade's colour, as the badges show them. */
421
421
  .trend-reading { flex: none; min-width: 1.25rem; padding: 0 .4rem; border-radius: 999px; background: var(--rule); color: var(--secondary); font-size: .75rem; font-weight: 600; letter-spacing: 0; line-height: 1.25rem; text-align: center; text-transform: none; font-variant-numeric: tabular-nums; }
422
- .trend-reading-grade, .trend-reading-good { color: #fff; background: var(--grade-a); }
422
+ .trend-reading-grade { color: #fff; background: var(--grade-a); }
423
423
  .trend-reading-grade[data-grade="B"] { background: var(--grade-b); }
424
424
  .trend-reading-grade[data-grade="C"] { background: var(--grade-c); }
425
425
  .trend-reading-grade[data-grade="D"] { background: var(--grade-d); }
@@ -3,6 +3,7 @@ export declare function gitRoot(directory: string): Promise<string>;
3
3
  export declare function physicalGitRoot(directory: string): Promise<string>;
4
4
  export declare function gitText(directory: string, args: readonly string[], timeout?: number): Promise<string>;
5
5
  export declare function gitUtf8(directory: string, args: readonly string[], timeout?: number): Promise<string>;
6
+ export declare function gitWorkingTreePaths(directory: string): Promise<readonly string[] | undefined>;
6
7
  export declare function resolveGitCommit(directory: string, revision: string): Promise<string>;
7
8
  /** Commits on the first-parent line of `head` after `base`, oldest first. */
8
9
  export declare function firstParentRange(directory: string, base: string, head: string): Promise<{
@@ -29,6 +29,18 @@ export async function gitUtf8(directory, args, timeout) {
29
29
  const result = await git('git', ['--no-replace-objects', ...args], { cwd: directory, env, encoding: 'buffer', maxBuffer, timeout });
30
30
  return utf8(result.stdout);
31
31
  }
32
+ export async function gitWorkingTreePaths(directory) {
33
+ try {
34
+ const { stdout } = await git('git', ['--no-replace-objects', 'ls-files', '--cached', '--others', '--exclude-standard', '-z', '--', '.'], { cwd: directory, env: { ...env, LC_ALL: 'C' }, encoding: 'buffer', maxBuffer });
35
+ return [...new Set(utf8(stdout).split('\0').filter(Boolean))];
36
+ }
37
+ catch (error) {
38
+ if (error instanceof Error && ('code' in error && error.code === 'ENOENT'
39
+ || 'stderr' in error && /fatal: not a git repository\b/.test(String(error.stderr))))
40
+ return undefined;
41
+ throw error;
42
+ }
43
+ }
32
44
  export async function resolveGitCommit(directory, revision) {
33
45
  let output;
34
46
  try {
@@ -1,6 +1,6 @@
1
1
  import { realpath } from 'node:fs/promises';
2
2
  import { basename, dirname, join, relative, resolve, sep } from 'node:path';
3
- import { gitRoot, gitUtf8, readGitCommit } from './git.js';
3
+ import { gitRoot, gitWorkingTreePaths, readGitCommit } from './git.js';
4
4
  import { containsPath, readWorkingTree } from './local.js';
5
5
  export async function readInspectionSource(request, excludes, claims) {
6
6
  const root = await realpath('workingTree' in request.source ? request.directory : await gitRoot(request.directory));
@@ -9,18 +9,12 @@ export async function readInspectionSource(request, excludes, claims) {
9
9
  throw new Error('Choose a dedicated report directory outside Git metadata');
10
10
  }
11
11
  const snapshot = 'workingTree' in request.source
12
- ? await readWorkingTree(root, output, excludes, await trackedClaims(root, claims))
12
+ ? await readWorkingTree(root, output, excludes, claims, await gitWorkingTreePaths(root))
13
13
  : await readGitCommit(root, request.source.revision, excludes, claims);
14
14
  const excludedOutput = snapshot.subject.kind === 'working-tree' && containsPath(root, output)
15
15
  ? relative(root, output).split(sep).join('/') : null;
16
16
  return { root, snapshot, excludedOutput, output };
17
17
  }
18
- async function trackedClaims(directory, claims) {
19
- if (!claims || !await gitRoot(directory).catch(() => undefined))
20
- return claims;
21
- const tracked = new Set((await gitUtf8(directory, ['ls-files', '--cached', '-z', '--', '.'])).split('\0'));
22
- return (path) => tracked.has(path) && claims(path);
23
- }
24
18
  async function physicalPath(path) {
25
19
  try {
26
20
  return await realpath(path);
@@ -1,3 +1,3 @@
1
1
  import type { SourceSnapshot } from '../../core/model/snapshot.js';
2
2
  export declare function containsPath(parent: string, path: string): boolean;
3
- export declare function readWorkingTree(directory: string, output: string, excludes: (path: string) => boolean, claims?: (path: string) => boolean): Promise<SourceSnapshot>;
3
+ export declare function readWorkingTree(directory: string, output: string, excludes: (path: string) => boolean, claims?: (path: string) => boolean, gitPaths?: readonly string[]): Promise<SourceSnapshot>;
@@ -1,5 +1,5 @@
1
1
  import { lstat, readdir, realpath, readFile } from 'node:fs/promises';
2
- import { isAbsolute, join, relative, sep } from 'node:path';
2
+ import { isAbsolute, join, posix, relative, sep } from 'node:path';
3
3
  import { comparePaths, isExcludedDirectory, isSourcePath, workingSnapshot } from '../../core/model/snapshot.js';
4
4
  import { isClaimedText, maxClaimedFileBytes } from '../../core/model/source.js';
5
5
  import { isGeneratedSource } from '../../core/profile/exclusions.js';
@@ -7,7 +7,7 @@ export function containsPath(parent, path) {
7
7
  const rest = relative(parent, path);
8
8
  return rest === '' || (!isAbsolute(rest) && rest !== '..' && !rest.startsWith(`..${sep}`));
9
9
  }
10
- export async function readWorkingTree(directory, output, excludes, claims) {
10
+ export async function readWorkingTree(directory, output, excludes, claims, gitPaths) {
11
11
  const root = await realpath(directory);
12
12
  const files = [];
13
13
  const generatedExcluded = [];
@@ -27,7 +27,7 @@ export async function readWorkingTree(directory, output, excludes, claims) {
27
27
  await read(path, absolute);
28
28
  }
29
29
  }
30
- async function read(path, absolute) {
30
+ async function read(path, absolute, size) {
31
31
  if (isSourcePath(path)) {
32
32
  const bytes = await readFile(absolute);
33
33
  if (isGeneratedSource(bytes))
@@ -38,7 +38,7 @@ export async function readWorkingTree(directory, output, excludes, claims) {
38
38
  }
39
39
  if (!claims?.(path))
40
40
  return;
41
- if ((await lstat(absolute)).size > maxClaimedFileBytes) {
41
+ if ((size ?? (await lstat(absolute)).size) > maxClaimedFileBytes) {
42
42
  oversizedClaims.push(path);
43
43
  return;
44
44
  }
@@ -48,8 +48,42 @@ export async function readWorkingTree(directory, output, excludes, claims) {
48
48
  else if (isClaimedText(bytes))
49
49
  files.push({ path, bytes });
50
50
  }
51
- await visit(root, '');
51
+ if (gitPaths === undefined) {
52
+ await visit(root, '');
53
+ }
54
+ else {
55
+ const directories = new Map([['.', true]]);
56
+ async function regularDirectory(path) {
57
+ const cached = directories.get(path);
58
+ if (cached !== undefined)
59
+ return cached;
60
+ const allowed = !isExcludedDirectory(posix.basename(path)) && await regularDirectory(posix.dirname(path))
61
+ && (await statIfPresent(join(root, path)))?.isDirectory() === true;
62
+ directories.set(path, allowed);
63
+ return allowed;
64
+ }
65
+ for (const path of gitPaths) {
66
+ const absolute = join(root, path);
67
+ if (excludes(path) || !containsPath(root, absolute) || containsPath(output, absolute))
68
+ continue;
69
+ if (!(isSourcePath(path) || claims?.(path)) || !await regularDirectory(posix.dirname(path)))
70
+ continue;
71
+ const stat = await statIfPresent(absolute);
72
+ if (stat?.isFile())
73
+ await read(path, absolute, stat.size);
74
+ }
75
+ }
52
76
  return { ...workingSnapshot(files), generatedExcluded: generatedExcluded.sort(comparePaths),
53
77
  ...(oversizedClaims.length ? { oversizedClaims: oversizedClaims.sort(comparePaths) } : {}) };
54
78
  }
79
+ async function statIfPresent(path) {
80
+ try {
81
+ return await lstat(path);
82
+ }
83
+ catch (error) {
84
+ if (error instanceof Error && 'code' in error && (error.code === 'ENOENT' || error.code === 'ENOTDIR'))
85
+ return undefined;
86
+ throw error;
87
+ }
88
+ }
55
89
  //# sourceMappingURL=local.js.map
@@ -0,0 +1,13 @@
1
+ import type { ToolInvocation, ToolResult, ToolRunner } from '../../core/ports/tool-runner.js';
2
+ export interface DockerToolLimits {
3
+ readonly memoryBytes?: number;
4
+ readonly pidsLimit?: number;
5
+ }
6
+ export declare class DockerToolRunner implements ToolRunner {
7
+ private readonly image;
8
+ readonly network = "none";
9
+ readonly implementation: string;
10
+ private readonly limits;
11
+ constructor(image: string, { memoryBytes, pidsLimit }?: DockerToolLimits);
12
+ run(invocation: ToolInvocation): Promise<ToolResult>;
13
+ }
@@ -0,0 +1,108 @@
1
+ import { execFile } from 'node:child_process';
2
+ import { randomUUID } from 'node:crypto';
3
+ import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises';
4
+ import { tmpdir } from 'node:os';
5
+ import { dirname, join } from 'node:path';
6
+ import { promisify } from 'node:util';
7
+ import { isSourcePathname } from '../../core/ports/source-provider.js';
8
+ import { toolFailure } from './failure.js';
9
+ const docker = promisify(execFile);
10
+ const proxyOverrides = ['HTTP_PROXY', 'HTTPS_PROXY', 'FTP_PROXY', 'ALL_PROXY', 'NO_PROXY']
11
+ .flatMap(name => ['--env', `${name}=`, '--env', `${name.toLowerCase()}=`]);
12
+ export class DockerToolRunner {
13
+ image;
14
+ network = 'none';
15
+ implementation;
16
+ limits;
17
+ constructor(image, { memoryBytes, pidsLimit } = {}) {
18
+ this.image = image;
19
+ if (!image || /[\s\0]/.test(image))
20
+ throw new Error('A locally available Docker image is required');
21
+ if ([memoryBytes, pidsLimit].some(value => value !== undefined && (!Number.isSafeInteger(value) || value < 1))) {
22
+ throw new Error('Docker memory and process limits must be positive integers');
23
+ }
24
+ this.limits = [...(memoryBytes === undefined ? [] : ['--memory', String(memoryBytes)]),
25
+ ...(pidsLimit === undefined ? [] : ['--pids-limit', String(pidsLimit)])];
26
+ this.implementation = JSON.stringify(['docker-tool-runner/v2', image, this.limits]);
27
+ }
28
+ async run(invocation) {
29
+ const [command, ...args] = invocation.argv;
30
+ if (!command || invocation.argv.some(arg => arg.includes('\0')))
31
+ throw new Error('A tool command and valid arguments are required');
32
+ if (!Number.isSafeInteger(invocation.timeoutMs) || invocation.timeoutMs < 1 || invocation.timeoutMs > 2_147_483_647) {
33
+ throw new Error('Invalid tool timeout');
34
+ }
35
+ if (!Number.isSafeInteger(invocation.maxOutputBytes) || invocation.maxOutputBytes < 1)
36
+ throw new Error('Invalid tool output limit');
37
+ const paths = new Set();
38
+ for (const { path } of invocation.files) {
39
+ if (!isSourcePathname(path) || paths.has(path))
40
+ throw new Error(`Invalid or duplicate snapshot path: ${path}`);
41
+ paths.add(path);
42
+ }
43
+ const directory = await mkdtemp(join(tmpdir(), 'repometry-tool-'));
44
+ const container = `repometry-tool-${randomUUID()}`;
45
+ try {
46
+ for (const file of invocation.files) {
47
+ const path = join(directory, file.path);
48
+ await mkdir(dirname(path), { recursive: true, mode: 0o700 });
49
+ await writeFile(path, file.bytes, { mode: 0o600, flag: 'wx' });
50
+ }
51
+ const mount = `type=bind,"source=${directory.replaceAll('"', '""')}",target=/snapshot,readonly`;
52
+ const uid = process.getuid?.();
53
+ const gid = process.getgid?.();
54
+ const user = uid === undefined || gid === undefined ? [] : ['--user', `${uid}:${gid}`];
55
+ let result;
56
+ try {
57
+ result = await runTool([
58
+ 'run', '--rm', '--name', container, '--interactive', '--pull', 'never', '--network', 'none', '--read-only',
59
+ '--cap-drop', 'ALL', '--security-opt', 'no-new-privileges', '--tmpfs', '/tmp:rw,nosuid,nodev', '--env', 'HOME=/tmp',
60
+ ...this.limits, ...user, ...proxyOverrides,
61
+ '--mount', mount, '--workdir', '/snapshot', '--entrypoint', command, '--', this.image, ...args,
62
+ ], invocation);
63
+ }
64
+ catch (error) {
65
+ await removeContainer(container);
66
+ throw error;
67
+ }
68
+ if ([125, 126, 127].includes(result.exitCode)) {
69
+ throw new Error(toolFailure(`Docker could not start the tool (exit code ${result.exitCode})`, result.stderr));
70
+ }
71
+ return result;
72
+ }
73
+ finally {
74
+ await rm(directory, { recursive: true, force: true });
75
+ }
76
+ }
77
+ }
78
+ function runTool(args, { stdin, timeoutMs, maxOutputBytes }) {
79
+ return new Promise((resolve, reject) => {
80
+ const child = execFile('docker', args, { encoding: 'buffer', timeout: timeoutMs, maxBuffer: maxOutputBytes, killSignal: 'SIGKILL' }, (error, stdout, stderr) => {
81
+ if (error?.code === 'ERR_CHILD_PROCESS_STDIO_MAXBUFFER' || stdout.length + stderr.length > maxOutputBytes) {
82
+ reject(new Error('Tool exceeded the output limit'));
83
+ }
84
+ else if (error?.killed) {
85
+ reject(new Error('Tool timed out'));
86
+ }
87
+ else if (error && typeof error.code !== 'number') {
88
+ reject(new Error('Could not run the Docker tool', { cause: error }));
89
+ }
90
+ else {
91
+ resolve({ exitCode: typeof error?.code === 'number' ? error.code : 0, stdout, stderr });
92
+ }
93
+ });
94
+ child.stdin?.on('error', () => { });
95
+ child.stdin?.end(stdin);
96
+ });
97
+ }
98
+ async function removeContainer(container) {
99
+ try {
100
+ await docker('docker', ['rm', '-f', '-v', container], { timeout: 5_000, maxBuffer: 16_384 });
101
+ }
102
+ catch (error) {
103
+ if (error instanceof Error && 'stderr' in error && String(error.stderr).includes('No such container'))
104
+ return;
105
+ throw new Error('Could not confirm Docker tool cleanup', { cause: error });
106
+ }
107
+ }
108
+ //# sourceMappingURL=docker-tool-runner.js.map
@@ -0,0 +1 @@
1
+ export declare function toolFailure(message: string, stderr: Uint8Array): string;
@@ -0,0 +1,12 @@
1
+ const credentialAssignment = /\b[\w.-]*(?:password|passwd|secret|token|credential|authorization|api[_-]?key|private[_-]?key)[\w.-]*["']?\s*[:=]/i;
2
+ export function toolFailure(message, stderr) {
3
+ const lines = new TextDecoder().decode(stderr).split(/\r?\n/).map(line => line.trim()).filter(Boolean).slice(-3);
4
+ const tail = lines.map(line => {
5
+ if (credentialAssignment.test(line))
6
+ return '[redacted tool output]';
7
+ return line.replace(/[\p{Cc}\p{Cf}]/gu, '').replace(/:\/\/[^/\s]+@/g, '://[redacted]@')
8
+ .replace(/[A-Za-z0-9_+=-]{32,}/g, '[redacted]').slice(0, 240);
9
+ });
10
+ return tail.length ? `${message}\n${tail.join('\n')}` : message;
11
+ }
12
+ //# sourceMappingURL=failure.js.map
@@ -0,0 +1,10 @@
1
+ import type { Operation, Plugin } from '../../core/engine/plugin.js';
2
+ import type { ToolInvocation, ToolRunner } from '../../core/ports/tool-runner.js';
3
+ export declare const processPluginProtocol = "repometry.plugin-process/v1";
4
+ export interface ProcessOperation extends Omit<Operation, 'execute'>, Pick<ToolInvocation, 'argv' | 'timeoutMs' | 'maxOutputBytes'> {
5
+ }
6
+ export interface ProcessPluginManifest extends Omit<Plugin, 'operations' | 'tools'> {
7
+ readonly operations: readonly ProcessOperation[];
8
+ readonly tools: Readonly<Record<string, string>>;
9
+ }
10
+ export declare function processPlugin({ operations, ...manifest }: ProcessPluginManifest, runner: ToolRunner): Plugin;
@@ -0,0 +1,96 @@
1
+ import { isRecord } from '../../core/engine/plugin.js';
2
+ import { isJsonValue } from '../../core/model/plugin-data.js';
3
+ import { digest, sourceFile, sourceFiles, utf8 } from '../../core/model/snapshot.js';
4
+ import { toolFailure } from './failure.js';
5
+ export const processPluginProtocol = 'repometry.plugin-process/v1';
6
+ export function processPlugin({ operations, ...manifest }, runner) {
7
+ if (runner.network !== 'none')
8
+ throw new Error('Process plugins require a runner with networking disabled');
9
+ const versions = Object.values(manifest.tools);
10
+ if (versions.length === 0 || versions.some(version => typeof version !== 'string' || !version.trim())) {
11
+ throw new Error('Process plugins must declare their tool versions');
12
+ }
13
+ return { ...manifest, operations: operations.map(operation => bindOperation(manifest.id, manifest.settings ?? null, operation, runner)) };
14
+ }
15
+ function bindOperation(plugin, settings, operation, runner) {
16
+ const { id, role, scope, inputs, output, argv, timeoutMs, maxOutputBytes } = operation;
17
+ const implementation = digest(JSON.stringify([processPluginProtocol, operation.implementation, runner.implementation, argv, timeoutMs, maxOutputBytes]));
18
+ return { id, role, scope, inputs, output, implementation, async execute(context) {
19
+ const { files, stdin } = encodeRequest(`${plugin}/${id}`, settings, operation, context);
20
+ const result = await runner.run({ argv, timeoutMs, maxOutputBytes, files, stdin });
21
+ if (result.exitCode !== 0)
22
+ throw new Error(toolFailure(`Process plugin exited with code ${result.exitCode}`, result.stderr));
23
+ return decodeResponse(result.stdout, output.id, context);
24
+ } };
25
+ }
26
+ function encodeRequest(key, settings, operation, context) {
27
+ const files = new Map();
28
+ function referenceFile(file) {
29
+ const reference = { path: file.path, sha256: digest(file.bytes) };
30
+ const existing = files.get(file.path);
31
+ if (existing && existing.reference.sha256 !== reference.sha256)
32
+ throw new Error(`Conflicting process input file: ${file.path}`);
33
+ files.set(file.path, { file, reference });
34
+ return reference;
35
+ }
36
+ const inputs = Object.fromEntries(Object.entries(operation.inputs).map(([port, contract]) => {
37
+ const value = context.read(port, contract);
38
+ if (contract.id === sourceFile.id) {
39
+ if (!sourceFile.accepts(value))
40
+ throw new Error(`Invalid process input file: ${key}.${port}`);
41
+ return [port, { contract: contract.id, file: referenceFile(value) }];
42
+ }
43
+ if (contract.id === sourceFiles.id) {
44
+ if (!sourceFiles.accepts(value))
45
+ throw new Error(`Invalid process input file set: ${key}.${port}`);
46
+ return [port, { contract: contract.id, files: value.map(referenceFile) }];
47
+ }
48
+ if (!isJsonValue(value))
49
+ throw new Error(`Process input must be JSON data: ${key}.${port}`);
50
+ return [port, { contract: contract.id, value }];
51
+ }));
52
+ const entries = [...files.values()];
53
+ const request = { protocol: processPluginProtocol, operation: key, settings, files: entries.map(({ reference }) => reference), inputs };
54
+ return { files: entries.map(({ file }) => file), stdin: Buffer.from(`${JSON.stringify(request)}\n`) };
55
+ }
56
+ function decodeResponse(bytes, contract, context) {
57
+ let product;
58
+ for (const line of utf8(bytes).split(/\r?\n/)) {
59
+ if (!line.trim())
60
+ continue;
61
+ let entry;
62
+ try {
63
+ entry = JSON.parse(line);
64
+ }
65
+ catch {
66
+ throw new Error('Invalid JSON Lines output from the process plugin');
67
+ }
68
+ if (!isRecord(entry))
69
+ throw new Error('Invalid process plugin output record');
70
+ if (entry.kind === 'diagnostic') {
71
+ readDiagnostic(entry, context);
72
+ continue;
73
+ }
74
+ if (entry.kind !== 'product' || entry.contract !== contract || product !== undefined || !isJsonValue(entry.value)) {
75
+ throw new Error('Expected one declared product from the process plugin');
76
+ }
77
+ product = entry.value;
78
+ }
79
+ if (product === undefined)
80
+ throw new Error('Missing declared product from the process plugin');
81
+ return product;
82
+ }
83
+ function readDiagnostic(entry, context) {
84
+ if (typeof entry.message !== 'string' || !entry.message.trim())
85
+ throw new Error('Invalid process plugin diagnostic message');
86
+ switch (entry.severity) {
87
+ case undefined:
88
+ case 'info': return;
89
+ case 'warning':
90
+ context.emitDiagnostic?.(entry.message);
91
+ return;
92
+ case 'error': throw new Error(entry.message);
93
+ default: throw new Error('Invalid process plugin diagnostic severity');
94
+ }
95
+ }
96
+ //# sourceMappingURL=plugin.js.map
@@ -1,5 +1,6 @@
1
+ import type { OperationCacheOptions } from '../core/engine/operation-cache.js';
1
2
  import type { Plugin } from '../core/engine/plugin.js';
2
3
  import type { Report } from '../core/model/report.js';
3
4
  import type { AnalysisInput } from '../core/usecases/inspect.js';
4
- export declare function claimsNativeFile(path: string): boolean;
5
- export declare function analyzeSnapshot({ snapshot, excludedOutput, excludedPaths, coverage: inputCoverage }: AnalysisInput, additional?: readonly Plugin[]): Promise<Report>;
5
+ export declare function inspectionFileMatcher(additional: readonly Plugin[]): (path: string) => boolean;
6
+ export declare function analyzeSnapshot({ snapshot, excludedOutput, excludedPaths, coverage: inputCoverage }: AnalysisInput, additional?: readonly Plugin[], cache?: OperationCacheOptions): Promise<Report>;