repometry 0.6.2 → 0.8.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 (153) hide show
  1. package/README.md +3 -0
  2. package/package.json +1 -1
  3. package/target/main/resources/config/process-plugins-v1.schema.json +79 -0
  4. package/target/main/resources/languages/go/parser.go +602 -0
  5. package/target/main/resources/languages/python/parser.py +312 -0
  6. package/target/main/resources/report/json/report-v2.schema.json +21 -1
  7. package/target/main/resources/report/json/repository-summary-v1.schema.json +9 -0
  8. package/target/main/resources/report/json/viewer-inspection-v1.schema.json +12 -3
  9. package/target/main/resources/viewer/files.css +7 -0
  10. package/target/main/resources/viewer/index.html +1 -1
  11. package/target/main/resources/viewer/styles.css +1 -0
  12. package/target/main/ts/api/git/git-reader.d.ts +10 -2
  13. package/target/main/ts/api/git/git-reader.js +74 -35
  14. package/target/main/ts/api/git/git.d.ts +19 -1
  15. package/target/main/ts/api/git/git.js +97 -7
  16. package/target/main/ts/api/import/go-cover.d.ts +13 -0
  17. package/target/main/ts/api/import/go-cover.js +150 -0
  18. package/target/main/ts/api/import/lcov-files.d.ts +6 -1
  19. package/target/main/ts/api/import/lcov-files.js +27 -7
  20. package/target/main/ts/api/process/docker-tool-runner.js +5 -21
  21. package/target/main/ts/api/process/host-language-runner.d.ts +13 -0
  22. package/target/main/ts/api/process/host-language-runner.js +176 -0
  23. package/target/main/ts/api/process/plugin.d.ts +4 -1
  24. package/target/main/ts/api/process/plugin.js +7 -3
  25. package/target/main/ts/api/process/tool-snapshot.d.ts +3 -0
  26. package/target/main/ts/api/process/tool-snapshot.js +26 -0
  27. package/target/main/ts/cli/config.d.ts +1 -0
  28. package/target/main/ts/cli/config.js +3 -2
  29. package/target/main/ts/cli/imports.d.ts +1 -0
  30. package/target/main/ts/cli/imports.js +5 -2
  31. package/target/main/ts/cli/main.js +76 -27
  32. package/target/main/ts/cli/reporting.js +3 -3
  33. package/target/main/ts/compose/analysis-files.d.ts +3 -1
  34. package/target/main/ts/compose/analysis-files.js +46 -12
  35. package/target/main/ts/compose/analysis-imports.js +4 -2
  36. package/target/main/ts/compose/analysis-report.d.ts +1 -0
  37. package/target/main/ts/compose/analysis-report.js +20 -15
  38. package/target/main/ts/compose/analysis-repository.d.ts +2 -1
  39. package/target/main/ts/compose/analysis-repository.js +42 -4
  40. package/target/main/ts/compose/analysis-results.d.ts +4 -1
  41. package/target/main/ts/compose/analysis-results.js +3 -0
  42. package/target/main/ts/compose/analysis-sources.d.ts +5 -0
  43. package/target/main/ts/compose/analysis-sources.js +11 -3
  44. package/target/main/ts/compose/analyze-snapshot.d.ts +2 -1
  45. package/target/main/ts/compose/analyze-snapshot.js +5 -3
  46. package/target/main/ts/compose/diff-coverage.d.ts +2 -1
  47. package/target/main/ts/compose/diff-coverage.js +8 -6
  48. package/target/main/ts/compose/history-cache.d.ts +29 -0
  49. package/target/main/ts/compose/history-cache.js +57 -0
  50. package/target/main/ts/compose/inspect.d.ts +6 -1
  51. package/target/main/ts/compose/inspect.js +10 -10
  52. package/target/main/ts/compose/inspection-coverage.d.ts +9 -0
  53. package/target/main/ts/compose/inspection-coverage.js +9 -0
  54. package/target/main/ts/compose/languages.d.ts +6 -1
  55. package/target/main/ts/compose/languages.js +23 -7
  56. package/target/main/ts/compose/native-language-plugins.d.ts +6 -0
  57. package/target/main/ts/compose/native-language-plugins.js +40 -0
  58. package/target/main/ts/compose/plugin-list.d.ts +7 -3
  59. package/target/main/ts/compose/plugin-list.js +13 -3
  60. package/target/main/ts/compose/prepare-metabranch.js +1 -1
  61. package/target/main/ts/compose/process-plugins.d.ts +2 -0
  62. package/target/main/ts/compose/process-plugins.js +64 -0
  63. package/target/main/ts/compose/review.d.ts +1 -2
  64. package/target/main/ts/compose/review.js +2 -2
  65. package/target/main/ts/compose/structure-measures.d.ts +5 -0
  66. package/target/main/ts/compose/structure-measures.js +57 -0
  67. package/target/main/ts/core/engine/manifest.js +5 -1
  68. package/target/main/ts/core/engine/plan.js +5 -6
  69. package/target/main/ts/core/engine/plugin.d.ts +2 -0
  70. package/target/main/ts/core/model/clone-source.js +0 -1
  71. package/target/main/ts/core/model/code-structure.d.ts +14 -9
  72. package/target/main/ts/core/model/code-structure.js +23 -10
  73. package/target/main/ts/core/model/file-types.d.ts +1 -0
  74. package/target/main/ts/core/model/file-types.js +14 -3
  75. package/target/main/ts/core/model/language.d.ts +2 -0
  76. package/target/main/ts/core/model/plugin-data.d.ts +2 -0
  77. package/target/main/ts/core/model/quality-summary.d.ts +4 -0
  78. package/target/main/ts/core/model/quality-summary.js +55 -29
  79. package/target/main/ts/core/model/report.d.ts +6 -0
  80. package/target/main/ts/core/model/source.d.ts +2 -0
  81. package/target/main/ts/core/usecases/inspect.d.ts +1 -1
  82. package/target/main/ts/core/usecases/inspect.js +1 -1
  83. package/target/main/ts/plugin.d.ts +1 -1
  84. package/target/main/ts/plugins/coverage/coverage.d.ts +2 -1
  85. package/target/main/ts/plugins/coverage/coverage.js +40 -30
  86. package/target/main/ts/plugins/language-js/function-facts.d.ts +1 -1
  87. package/target/main/ts/plugins/language-js/function-facts.js +0 -1
  88. package/target/main/ts/plugins/language-js/js-security.js +25 -37
  89. package/target/main/ts/plugins/language-js/structural-observations.js +5 -4
  90. package/target/main/ts/plugins/maintainability/maintainability.d.ts +1 -1
  91. package/target/main/ts/plugins/maintainability/maintainability.js +9 -8
  92. package/target/main/ts/plugins/security/dockerfile.js +51 -52
  93. package/target/main/ts/plugins/structure/structure.js +2 -2
  94. package/target/main/ts/report/html/app/viewer-code-map.js +6 -5
  95. package/target/main/ts/report/html/app/viewer-columns.d.ts +2 -0
  96. package/target/main/ts/report/html/app/viewer-columns.js +9 -4
  97. package/target/main/ts/report/html/app/viewer-data.d.ts +2 -1
  98. package/target/main/ts/report/html/app/viewer-data.js +1 -1
  99. package/target/main/ts/report/html/app/viewer-file-aside.d.ts +5 -9
  100. package/target/main/ts/report/html/app/viewer-file-aside.js +18 -8
  101. package/target/main/ts/report/html/app/viewer-file-figures.d.ts +2 -0
  102. package/target/main/ts/report/html/app/viewer-file-figures.js +6 -1
  103. package/target/main/ts/report/html/app/viewer-hotspots.js +7 -5
  104. package/target/main/ts/report/html/app/viewer-inspection.js +1 -1
  105. package/target/main/ts/report/html/app/viewer-issue-group.js +2 -2
  106. package/target/main/ts/report/html/app/viewer-language-bar.d.ts +2 -0
  107. package/target/main/ts/report/html/app/viewer-language-bar.js +5 -1
  108. package/target/main/ts/report/html/app/viewer-languages.d.ts +3 -2
  109. package/target/main/ts/report/html/app/viewer-languages.js +14 -7
  110. package/target/main/ts/report/html/app/viewer-line-coverage.d.ts +4 -4
  111. package/target/main/ts/report/html/app/viewer-line-coverage.js +11 -24
  112. package/target/main/ts/report/html/app/viewer-map-scale.d.ts +1 -1
  113. package/target/main/ts/report/html/app/viewer-map-scale.js +1 -1
  114. package/target/main/ts/report/html/app/viewer-map-shape.d.ts +2 -2
  115. package/target/main/ts/report/html/app/viewer-metric-registry.d.ts +0 -3
  116. package/target/main/ts/report/html/app/viewer-metric-registry.js +0 -9
  117. package/target/main/ts/report/html/app/viewer-metrics-view.js +1 -4
  118. package/target/main/ts/report/html/app/viewer-metrics.d.ts +2 -0
  119. package/target/main/ts/report/html/app/viewer-metrics.js +5 -0
  120. package/target/main/ts/report/html/app/viewer-overview-cards.js +4 -1
  121. package/target/main/ts/report/html/app/viewer-overview-hotspots.js +2 -2
  122. package/target/main/ts/report/html/app/viewer-profile.js +22 -1
  123. package/target/main/ts/report/html/app/viewer-source-view.js +7 -6
  124. package/target/main/ts/report/html/app/viewer-table-cells.js +8 -2
  125. package/target/main/ts/report/html/app/viewer-table-rows.d.ts +2 -0
  126. package/target/main/ts/report/html/app/viewer-table-rows.js +7 -5
  127. package/target/main/ts/report/html/app/viewer-tokenizer.d.ts +2 -5
  128. package/target/main/ts/report/html/app/viewer-tokenizer.js +9 -12
  129. package/target/main/ts/report/html/app/viewer-totals.d.ts +6 -0
  130. package/target/main/ts/report/html/app/viewer-totals.js +11 -0
  131. package/target/main/ts/report/html/app/viewer-trend-data.d.ts +1 -1
  132. package/target/main/ts/report/html/app/viewer-trend-data.js +1 -1
  133. package/target/main/ts/report/html/app/viewer-trend-nav.js +3 -2
  134. package/target/main/ts/report/html/app/viewer.js +1 -7
  135. package/target/main/ts/report/json/projections/commit-summary.d.ts +1 -0
  136. package/target/main/ts/report/json/projections/commit-summary.js +10 -0
  137. package/target/main/ts/report/json/projections/file-metrics.js +56 -45
  138. package/target/main/ts/report/json/projections/inspection-details.js +33 -14
  139. package/target/main/ts/report/json/projections/metric-values.d.ts +1 -0
  140. package/target/main/ts/report/json/projections/metric-values.js +36 -3
  141. package/target/main/ts/report/json/store/directory.d.ts +3 -0
  142. package/target/main/ts/report/json/store/directory.js +19 -0
  143. package/target/main/ts/report/json/store/local-store.d.ts +14 -2
  144. package/target/main/ts/report/json/store/local-store.js +74 -60
  145. package/target/main/ts/report/json/store/object-store.d.ts +14 -0
  146. package/target/main/ts/report/json/store/object-store.js +73 -0
  147. package/target/main/ts/report/json/store/report-tree.d.ts +46 -0
  148. package/target/main/ts/report/json/store/report-tree.js +290 -0
  149. package/target/main/ts/report/json/store/store-check.d.ts +32 -0
  150. package/target/main/ts/report/json/store/store-check.js +144 -0
  151. package/target/main/ts/report/json/validation/report.d.ts +6 -1
  152. package/target/main/ts/report/json/validation/report.js +10 -4
  153. package/target/main/ts/report/json/wire/inspection-details-model.d.ts +9 -1
@@ -2,15 +2,16 @@ import { readFile } from 'node:fs/promises';
2
2
  import { resolve } from 'node:path';
3
3
  import { isRecord } from '../core/engine/plugin.js';
4
4
  import { normalizeProfile } from '../core/profile/profile.js';
5
+ import { readProcessPlugins } from '../compose/process-plugins.js';
5
6
  import { invocationDirectory } from './store.js';
6
7
  const keys = new Set(['$schema', 'exclude', 'ignore', 'imports', 'reports', 'sources', 'branch',
7
- 'minCoverage', 'minLines', 'maxCoverageDrop', 'maxNewIssues']);
8
+ 'minCoverage', 'minLines', 'maxCoverageDrop', 'maxNewIssues', 'plugins']);
8
9
  function parseConfig(value) {
9
10
  if (!isRecord(value) || Object.keys(value).some(key => !keys.has(key)))
10
11
  throw new Error('Invalid Repometry JSON configuration');
11
12
  string(value.$schema, '$schema');
12
13
  const profile = normalizeProfile({ exclude: value.exclude, ignore: value.ignore });
13
- return { ...profile, imports: list(value.imports, 'imports'), reports: list(value.reports, 'reports'),
14
+ return { ...profile, plugins: readProcessPlugins(value.plugins), imports: list(value.imports, 'imports'), reports: list(value.reports, 'reports'),
14
15
  sources: string(value.sources, 'sources'), branch: string(value.branch, 'branch'),
15
16
  minCoverage: number(value.minCoverage, 'minCoverage'), minLines: number(value.minLines, 'minLines'),
16
17
  maxCoverageDrop: number(value.maxCoverageDrop, 'maxCoverageDrop'), maxNewIssues: number(value.maxNewIssues, 'maxNewIssues') };
@@ -3,5 +3,6 @@ export declare const importerIds: string[];
3
3
  /** Typed imports resolve against the invocation directory, imports from the config against the repository root. */
4
4
  export declare function readInputs(base: string, inputs: readonly string[]): {
5
5
  lcov: string[] | undefined;
6
+ goCover: string[] | undefined;
6
7
  findings: FindingInput[];
7
8
  };
@@ -6,10 +6,11 @@ const scanners = {
6
6
  eslint: { format: 'eslint', category: 'lint' },
7
7
  osv: { format: 'osv', category: 'dependency' },
8
8
  };
9
- export const importerIds = ['lcov', ...Object.keys(scanners)];
9
+ export const importerIds = ['lcov', 'go-cover', ...Object.keys(scanners)];
10
10
  /** Typed imports resolve against the invocation directory, imports from the config against the repository root. */
11
11
  export function readInputs(base, inputs) {
12
12
  const lcov = [];
13
+ const goCover = [];
13
14
  const findings = [];
14
15
  for (const value of inputs) {
15
16
  const equal = value.indexOf('=');
@@ -19,12 +20,14 @@ export function readInputs(base, inputs) {
19
20
  throw new Error('Use --import FORMAT=PATH');
20
21
  if (format === 'lcov')
21
22
  lcov.push(resolve(base, file));
23
+ else if (format === 'go-cover')
24
+ goCover.push(resolve(base, file));
22
25
  else {
23
26
  if (!Object.hasOwn(scanners, format))
24
27
  throw new Error(`Unknown import format: ${format}. Choose ${importerIds.join(', ')}.`);
25
28
  findings.push({ ...scanners[format], file: resolve(base, file) });
26
29
  }
27
30
  }
28
- return { lcov: lcov.length ? lcov : undefined, findings };
31
+ return { lcov: lcov.length ? lcov : undefined, goCover: goCover.length ? goCover : undefined, findings };
29
32
  }
30
33
  //# sourceMappingURL=imports.js.map
@@ -1,26 +1,31 @@
1
1
  #!/usr/bin/env node
2
- import { lstat, readFile } from 'node:fs/promises';
2
+ import { lstat, readFile, realpath } from 'node:fs/promises';
3
3
  import { join, resolve } from 'node:path';
4
4
  import { firstParentRange, gitRoot, resolveGitCommit } from '../api/git/git.js';
5
+ import { gitReportObjects } from '../api/git/git-reader.js';
5
6
  import { resolveGitBranch } from '../api/git/commit-metadata.js';
6
7
  import { clearSourceCache, sourceCacheRoot } from '../api/git/source-cache.js';
7
8
  import { writeGitHubDiffCoverage, writeGitHubResult, writeGitHubReview } from '../api/gh/github.js';
8
9
  import { remoteExecutor } from '../api/worker/remote-executor.js';
9
10
  import { serveWorker } from '../api/worker/worker.js';
10
11
  import { workerToken } from '../api/worker/worker-protocol.js';
11
- import { defaultLanguages } from '../compose/languages.js';
12
+ import { HistoryCache } from '../compose/history-cache.js';
13
+ import { defaultLanguages, languageRegistry } from '../compose/languages.js';
12
14
  import { analyzeSnapshot, attachFindings, inspect } from '../compose/inspect.js';
13
15
  import { measureDiffCoverage } from '../compose/diff-coverage.js';
14
16
  import { prepareMetabranch } from '../compose/prepare-metabranch.js';
15
17
  import { reviewExitCode, reviewPull } from '../compose/review.js';
16
- import { builtInPlugins } from '../compose/plugin-list.js';
18
+ import { effectivePlugins } from '../compose/plugin-list.js';
17
19
  import { isRecord } from '../core/engine/plugin.js';
18
20
  import { validSubjectId } from '../core/model/report.js';
19
21
  import { sourceExclusionMatcher } from '../core/profile/exclusions.js';
20
22
  import { compareInspections } from '../core/usecases/compare.js';
21
23
  import { exportProjects } from '../report/html/site/projects.js';
22
24
  import { fileMetrics } from '../report/json/projections/file-metrics.js';
25
+ import { LocalReportStore } from '../report/json/store/local-store.js';
23
26
  import { savePullReview } from '../report/json/store/pull-review-store.js';
27
+ import { LocalObjectStore } from '../report/json/store/object-store.js';
28
+ import { checkStore } from '../report/json/store/store-check.js';
24
29
  import { dispatch, flag, option } from './arguments.js';
25
30
  import { readConfig } from './config.js';
26
31
  import { importerIds, readInputs } from './imports.js';
@@ -115,10 +120,14 @@ const commands = {
115
120
  print({ schema: 'urn:repometry:schema:prepare-result:1', subject: report.subject, worktree, files });
116
121
  },
117
122
  },
118
- plugins: { description: 'List plugins and supported formats.', run() {
119
- print({ schema: 'urn:repometry:schema:plugin-list:1', plugins: builtInPlugins, importers: importerIds,
120
- reporters: reporterIds, ci: ['github'], stores: ['local', 'git'] });
121
- } },
123
+ plugins: { description: 'List effective plugins and supported formats.', options: configOptions,
124
+ async run(input) {
125
+ const { root } = await context(input);
126
+ const config = await readConfig(root, input);
127
+ print({ schema: 'urn:repometry:schema:plugin-list:1', plugins: effectivePlugins(config.plugins),
128
+ importers: importerIds, reporters: reporterIds, ci: ['github'], stores: ['local', 'git'] });
129
+ },
130
+ },
122
131
  cache: {
123
132
  description: 'Find or clear the system cache.', parameters: 'path|clear', min: 1, max: 1,
124
133
  options: { sources: flag('Clear only source blobs.') },
@@ -134,13 +143,34 @@ const commands = {
134
143
  print({ schema: 'urn:repometry:schema:cache-result:1', path, ...(action === 'clear' ? { cleared: ['sources'] } : {}) });
135
144
  },
136
145
  },
146
+ store: {
147
+ description: 'Check saved inspections and repair what can be restored.', parameters: 'check', min: 1, max: 1,
148
+ options: {
149
+ repair: flag('Restore missing data from a copy.'),
150
+ from: option('PATH|git:REF', 'The copy: another store or a storage branch.'),
151
+ },
152
+ async run(input) {
153
+ if (input.args[0] !== 'check')
154
+ throw new Error('Use store check');
155
+ const from = input.text('from');
156
+ if (from !== undefined && !input.flag('repair'))
157
+ throw new Error('--from requires --repair');
158
+ const { directory, root, store } = await context(input);
159
+ const path = writableStore(store);
160
+ const source = from === undefined ? undefined
161
+ : from.startsWith('git:') ? await gitReportObjects(root, from.slice(4)) : new LocalObjectStore(resolve(directory, from)).source();
162
+ const result = await checkStore(path, input.flag('repair') ? { from: source } : undefined);
163
+ print({ ...result, store: path });
164
+ return result.problems.length ? 1 : 0;
165
+ },
166
+ },
137
167
  worker: { description: 'Run the remote analysis worker.',
138
168
  options: { port: option('PORT', 'Listen on this port.'), listen: option('ADDRESS', 'Listen on 127.0.0.1 or 0.0.0.0.') },
139
169
  async run(input) {
140
170
  const host = input.text('listen') ?? '127.0.0.1';
141
171
  if (host !== '127.0.0.1' && host !== '0.0.0.0')
142
172
  throw new Error('--listen must be 127.0.0.1 or 0.0.0.0');
143
- announce(await serveWorker(host, port(input.text('port') ?? '7331'), workerToken(), analyzeSnapshot, defaultLanguages.isSource));
173
+ announce(await serveWorker(host, port(input.text('port') ?? '7331'), workerToken(), analyzeSnapshot, languageRegistry([]).isSource));
144
174
  } },
145
175
  };
146
176
  async function context(input) {
@@ -163,17 +193,17 @@ async function analyze(input) {
163
193
  const branch = input.text('branch') ?? config.branch;
164
194
  const revision = input.args[0] ?? (!input.flag('working-tree') && branch !== undefined ? await resolveGitBranch(root, branch) : 'HEAD');
165
195
  const imports = input.many('import');
166
- const { lcov, findings } = imports.length ? readInputs(directory, imports) : readInputs(root, config.imports);
196
+ const { lcov, goCover, findings } = imports.length ? readInputs(directory, imports) : readInputs(root, config.imports);
167
197
  const importRoot = input.text('import-root');
168
198
  if (importRoot && findings.length === 0)
169
199
  throw new Error('--import-root requires a scanner report');
170
- const worker = input.text('worker');
200
+ const executor = analysisExecutor(input, config.plugins);
171
201
  const savedId = input.flag('skip-saved') ? await resolveGitCommit(root, revision) : undefined;
172
202
  const skipped = savedId !== undefined && await isSaved(output, savedId);
173
203
  const report = skipped ? await store.reader.read({ kind: 'commit', id: savedId })
174
204
  : await inspect({ directory, output, source: input.flag('working-tree') ? { workingTree: true } : { revision },
175
- lcov, exclude: [...config.exclude, ...input.many('exclude')], ignore: config.ignore,
176
- findingInputs: findings, findingRoot: importRoot ? resolve(directory, importRoot) : undefined }, worker === undefined ? undefined : remoteExecutor(worker, workerToken(), defaultLanguages.isSource));
205
+ lcov, goCover, exclude: [...config.exclude, ...input.many('exclude')], ignore: config.ignore, plugins: config.plugins,
206
+ findingInputs: findings, findingRoot: importRoot ? resolve(directory, importRoot) : undefined }, executor);
177
207
  if (github)
178
208
  await writeGitHubResult(report);
179
209
  const requested = input.many('report');
@@ -199,9 +229,24 @@ async function analyzeRange(input, range) {
199
229
  const { base, head, commits } = await firstParentRange(root, range.base, range.head);
200
230
  if (!commits.length)
201
231
  process.stderr.write(`No commits in ${range.base}..${range.head}.\n`);
202
- const worker = input.text('worker');
203
- const executor = worker === undefined ? undefined : remoteExecutor(worker, workerToken(), defaultLanguages.isSource);
232
+ const executor = analysisExecutor(input, config.plugins);
204
233
  const exclude = [...config.exclude, ...input.many('exclude')];
234
+ const { plugins, ...profile } = config;
235
+ const history = executor === undefined ? new HistoryCache(profile) : undefined;
236
+ const inspectCommit = (id) => inspect({ directory, output, source: { revision: id }, exclude,
237
+ ignore: config.ignore, plugins }, executor, { history, deferSummary: true });
238
+ const skip = input.flag('skip-saved') ? (id) => isSaved(output, id) : undefined;
239
+ const { interrupted, ...results } = await analyzeCommits(commits, inspectCommit, skip);
240
+ if (results.analyzed.length || results.skipped.length) {
241
+ await new LocalReportStore(await realpath(output)).refreshSummary();
242
+ }
243
+ const requested = input.many('report');
244
+ const reports = interrupted ? [] : await outputReports(root, store, requested.length ? requested : config.reports, input, config);
245
+ print({ schema: 'urn:repometry:schema:analyze-range:1', range: `${base}..${head}`,
246
+ ...results, store: output, reports });
247
+ return interrupted ? 130 : results.failed.length || results.partial.length ? 2 : 0;
248
+ }
249
+ async function analyzeCommits(commits, inspectCommit, skip) {
205
250
  const analyzed = [], partial = [], skipped = [];
206
251
  const failed = [];
207
252
  let interrupted = false;
@@ -213,13 +258,13 @@ async function analyzeRange(input, range) {
213
258
  for (const [index, id] of commits.entries()) {
214
259
  if (interrupted)
215
260
  break;
216
- if (input.flag('skip-saved') && await isSaved(output, id)) {
261
+ if (skip !== undefined && await skip(id)) {
217
262
  skipped.push(id);
218
263
  progress(index, id, 'skipped');
219
264
  continue;
220
265
  }
221
266
  try {
222
- const report = await inspect({ directory, output, source: { revision: id }, exclude, ignore: config.ignore }, executor);
267
+ const report = await inspectCommit(id);
223
268
  analyzed.push(id);
224
269
  if (report.status === 'partial')
225
270
  partial.push(id);
@@ -237,11 +282,15 @@ async function analyzeRange(input, range) {
237
282
  finally {
238
283
  process.removeListener('SIGINT', stop);
239
284
  }
240
- const requested = input.many('report');
241
- const reports = interrupted ? [] : await outputReports(root, store, requested.length ? requested : config.reports, input, config);
242
- print({ schema: 'urn:repometry:schema:analyze-range:1', range: `${base}..${head}`,
243
- analyzed, partial, skipped, failed, store: output, reports });
244
- return interrupted ? 130 : failed.length || partial.length ? 2 : 0;
285
+ return { analyzed, partial, skipped, failed, interrupted };
286
+ }
287
+ function analysisExecutor(input, plugins) {
288
+ const worker = input.text('worker');
289
+ if (worker === undefined)
290
+ return undefined;
291
+ if (plugins.length)
292
+ throw new Error('Configured process plugins require local analysis. Use --no-config with --worker.');
293
+ return remoteExecutor(worker, workerToken(), languageRegistry([]).isSource);
245
294
  }
246
295
  async function isSaved(store, id) {
247
296
  try {
@@ -282,10 +331,10 @@ async function diffCoverage(input) {
282
331
  const { directory, root } = await context(input);
283
332
  const config = await readConfig(root, input);
284
333
  const imports = input.many('import');
285
- const { lcov, findings } = imports.length ? readInputs(directory, imports) : readInputs(root, config.imports);
286
- if (!lcov || (imports.length && findings.length))
287
- throw new Error('diff-coverage requires --import lcov=PATH');
288
- const report = await measureDiffCoverage({ directory: root, base: input.args[0], revision: input.args[1] ?? 'HEAD', lcov,
334
+ const { lcov, goCover, findings } = imports.length ? readInputs(directory, imports) : readInputs(root, config.imports);
335
+ if ((!lcov && !goCover) || (imports.length && findings.length))
336
+ throw new Error('diff-coverage requires --import lcov=PATH or go-cover=PATH');
337
+ const report = await measureDiffCoverage({ directory: root, base: input.args[0], revision: input.args[1] ?? 'HEAD', lcov, goCover, plugins: config.plugins,
289
338
  exclude: [...config.exclude, ...input.many('exclude')], minimumPercent: percent(input.text('min-coverage') ?? config.minCoverage, '--min-coverage') });
290
339
  if (useGitHub(input))
291
340
  await writeGitHubDiffCoverage(report);
@@ -299,7 +348,7 @@ async function review(input) {
299
348
  throw new Error('--annotations requires --ci github');
300
349
  const config = await readConfig(root, input);
301
350
  const imports = input.many('import');
302
- const { lcov, findings } = imports.length ? readInputs(directory, imports) : readInputs(root, config.imports);
351
+ const { lcov, goCover, findings } = imports.length ? readInputs(directory, imports) : readInputs(root, config.imports);
303
352
  const baselinePath = input.text('baseline-store');
304
353
  const baseline = baselinePath === undefined ? store : selectStore(root, baselinePath, directory);
305
354
  const exclude = [...config.exclude, ...input.many('exclude')];
@@ -314,7 +363,7 @@ async function review(input) {
314
363
  },
315
364
  } : store.reader;
316
365
  const number = count(input.text('pull'), '--pull', 1);
317
- const report = await reviewPull({ directory: root, base: input.args[0], revision: input.args[1] ?? 'HEAD', lcov, exclude, number,
366
+ const report = await reviewPull({ directory: root, base: input.args[0], revision: input.args[1] ?? 'HEAD', lcov, goCover, exclude, number, plugins: config.plugins,
318
367
  minimumPercent: percent(input.text('min-coverage') ?? config.minCoverage, '--min-coverage'),
319
368
  minimumLines: count(input.text('min-lines') ?? config.minLines, '--min-lines'),
320
369
  maxCoverageDrop: percent(input.text('max-coverage-drop') ?? config.maxCoverageDrop, '--max-coverage-drop'),
@@ -3,7 +3,7 @@ import { mkdir, rename, rm, writeFile } from 'node:fs/promises';
3
3
  import { basename, dirname, resolve } from 'node:path';
4
4
  import { commitMetadataReader } from '../api/git/commit-metadata.js';
5
5
  import { readLocalSources, sourceRemotes } from '../api/git/local-sources.js';
6
- import { defaultLanguages } from '../compose/languages.js';
6
+ import { defaultLanguages, languageRegistry } from '../compose/languages.js';
7
7
  import { resolveSourceLocator } from '../compose/sources.js';
8
8
  import { commitSummary, withCommitMetadata } from '../report/json/projections/commit-summary.js';
9
9
  import { exportSite, siteSummary } from '../report/html/site/export-site.js';
@@ -42,7 +42,7 @@ export async function outputReports(root, store, requested, input, config) {
42
42
  readComponents(componentsPath(root, input), input.text('components') === undefined),
43
43
  store.path ? listPullReviews(store.path) : [],
44
44
  ]);
45
- const options = { languages: defaultLanguages, sources, components, pulls, readCommitMetadata, branch: input.text('branch') ?? config.branch,
45
+ const options = { languages: config.plugins.length ? languageRegistry(config.plugins) : defaultLanguages, sources, components, pulls, readCommitMetadata, branch: input.text('branch') ?? config.branch,
46
46
  title: input.text('title') ?? (input.text('repo') ? basename(root) : undefined),
47
47
  footer: !input.flag('no-footer') };
48
48
  for (const request of requests) {
@@ -93,7 +93,7 @@ export async function viewTarget(input, port) {
93
93
  readConfig(root, input),
94
94
  ]);
95
95
  const local = repository ? readLocalSources(repository) : undefined;
96
- const server = await serveSite(store.reader, port, { languages: defaultLanguages, title: input.text('title') ?? basename(root), components, pulls,
96
+ const server = await serveSite(store.reader, port, { languages: config.plugins.length ? languageRegistry(config.plugins) : defaultLanguages, title: input.text('title') ?? basename(root), components, pulls,
97
97
  branch: input.text('branch') ?? config.branch, readCommitMetadata: repository ? commitMetadataReader(repository) : undefined,
98
98
  sources: local ? resolveSourceLocator('local', { remotes: [], env: {} }) : undefined, footer: !input.flag('no-footer') }, local);
99
99
  return { ...server, label: `${basename(root)} (live from ${store.path ?? input.text('store')})` };
@@ -5,9 +5,11 @@ import type { CodeStructure } from '../core/model/code-structure.js';
5
5
  import type { SourceLineRange } from '../core/model/source.js';
6
6
  import type { AnalysisResults } from './analysis-results.js';
7
7
  import type { AnalysisSources } from './analysis-sources.js';
8
+ import type { HistoryFiles } from './history-cache.js';
8
9
  export declare const defaultFilePlan: readonly PlannedOperation[];
9
10
  export interface FileAnalysis {
10
11
  readonly cloneSources: readonly CloneSource[];
12
+ readonly codeLines: ReadonlyMap<string, ReadonlySet<number>>;
11
13
  readonly functionBodies: ReadonlyMap<string, readonly SourceLineRange[]>;
12
14
  }
13
- export declare function inspectFiles(sources: AnalysisSources, batchFacts: ReadonlyMap<string, CodeStructure>, results: AnalysisResults, withCoverage: boolean, cache?: OperationCacheOptions): Promise<FileAnalysis>;
15
+ export declare function inspectFiles(sources: AnalysisSources, batchFacts: ReadonlyMap<string, CodeStructure>, results: AnalysisResults, withCoverage: boolean, cache?: OperationCacheOptions, history?: HistoryFiles): Promise<FileAnalysis>;
@@ -1,18 +1,21 @@
1
1
  import { execute } from '../core/engine/execute.js';
2
2
  import { plan } from '../core/engine/plan.js';
3
- import { codeStructure } from '../core/model/code-structure.js';
3
+ import { codeStructure, structuralCheckIds, structureCodeLines } from '../core/model/code-structure.js';
4
4
  import { sourceFile } from '../core/model/snapshot.js';
5
5
  import { isClaimedText, maxClaimedFileBytes } from '../core/model/source.js';
6
6
  import { fileQuality } from '../plugins/maintainability/maintainability.js';
7
7
  import { oversizedClaim } from './analysis-results.js';
8
8
  import { defaultProvider, inspectionKeys, pluginForScope, structuralInspections } from './analysis-sources.js';
9
+ import { canReuseBatch } from './history-cache.js';
10
+ import { unmeasuredStructure } from './structure-measures.js';
9
11
  const standardInspections = ['structure/size', 'structure/complexity', 'maintainability/file'];
10
12
  const fileInput = new Map([['file', sourceFile.id]]);
11
13
  const batchFileInput = new Map([...fileInput, ['syntax', codeStructure.id]]);
12
14
  export const defaultFilePlan = filePlan(defaultProvider, []);
13
- export async function inspectFiles(sources, batchFacts, results, withCoverage, cache) {
15
+ export async function inspectFiles(sources, batchFacts, results, withCoverage, cache, history) {
14
16
  const plans = new Map([[filePlanKey(defaultProvider, []), defaultFilePlan]]);
15
17
  const cloneSources = [];
18
+ const codeLines = new Map();
16
19
  const functionBodies = new Map();
17
20
  for (const source of sources.sources) {
18
21
  const plugins = matchedInspections(source, sources, results);
@@ -21,17 +24,35 @@ export async function inspectFiles(sources, batchFacts, results, withCoverage, c
21
24
  continue;
22
25
  const tasks = findFilePlan(provider, plugins, plans, results);
23
26
  const facts = batchFacts.get(file.path);
24
- const products = new Map([['file', { contract: sourceFile.id, value: file }]]);
25
- if (facts)
26
- products.set('syntax', { contract: codeStructure.id, value: facts });
27
- const outcomes = await execute(tasks, products, cache);
27
+ const reusable = provider?.batch && (!facts || !canReuseBatch(provider)) ? undefined : history;
28
+ const outcomes = await fileOutcomes(source, tasks, facts, cache, reusable);
28
29
  const syntax = provider && outcomes.get(provider.key);
29
- const bodies = recordFileSyntax(source, syntax, facts, results, withCoverage);
30
- if (bodies !== undefined)
31
- functionBodies.set(file.path, bodies);
30
+ const parsed = recordFileSyntax(source, syntax, facts, results, withCoverage);
31
+ if (withCoverage && parsed) {
32
+ const lines = structureCodeLines(parsed);
33
+ if (lines !== undefined)
34
+ codeLines.set(file.path, new Set(lines));
35
+ if (parsed.functionBodies !== undefined)
36
+ functionBodies.set(file.path, parsed.functionBodies);
37
+ }
32
38
  collectFileProducts(tasks, outcomes, source, cloneSources, results);
33
39
  }
34
- return { cloneSources, functionBodies };
40
+ return { cloneSources, codeLines, functionBodies };
41
+ }
42
+ async function fileOutcomes({ file }, tasks, facts, cache, history) {
43
+ const saved = history?.read(file.path)?.outcomes;
44
+ if (saved) {
45
+ history?.retain(file.path, { outcomes: saved });
46
+ return saved;
47
+ }
48
+ const products = new Map([['file', { contract: sourceFile.id, value: file }]]);
49
+ if (facts)
50
+ products.set('syntax', { contract: codeStructure.id, value: facts });
51
+ const outcomes = await execute(tasks, products, cache);
52
+ if (history && [...outcomes.values()].every(outcome => outcome.state === 'completed' && !outcome.diagnostics?.length)) {
53
+ history.retain(file.path, { outcomes });
54
+ }
55
+ return outcomes;
35
56
  }
36
57
  function matchedInspections({ file }, sources, results) {
37
58
  const claimed = sources.perFile.filter(({ matches }) => matches(file.path));
@@ -75,7 +96,20 @@ function recordFileSyntax({ file, provider }, outcome, batch, results, withCover
75
96
  const facts = batch ?? ((!builtinParsed || withCoverage) && codeStructure.accepts(value) ? value : undefined);
76
97
  if (facts || builtinParsed)
77
98
  results.parsed.add(file.path);
78
- return withCoverage ? facts?.functionBodies : undefined;
99
+ if (facts && !builtinParsed)
100
+ recordUnmeasured(file.path, facts, results);
101
+ return facts;
102
+ }
103
+ function recordUnmeasured(path, facts, results) {
104
+ const unmeasured = unmeasuredStructure(facts);
105
+ if (unmeasured.length)
106
+ results.unmeasured.set(path, unmeasured);
107
+ if (facts.observations === undefined) {
108
+ results.ruleSkips.push({ path, plugin: 'maintainability', rules: structuralCheckIds, reason: 'unmeasured' });
109
+ }
110
+ if (facts.clones === undefined) {
111
+ results.ruleSkips.push({ path, plugin: 'duplication', rules: ['identical-code', 'similar-code'], reason: 'unmeasured' });
112
+ }
79
113
  }
80
114
  function collectFileProducts(tasks, outcomes, { file, provider }, clones, results) {
81
115
  for (const task of tasks) {
@@ -90,6 +124,6 @@ function cloneSource(outcome, provider) {
90
124
  if (outcome.state !== 'completed' || outcome.product.contract !== fileQuality.id || !fileQuality.accepts(outcome.product.value))
91
125
  return;
92
126
  const source = outcome.product.value.cloneSource;
93
- return provider && source.scheme === undefined ? { ...source, scheme: provider.plugin.id } : source;
127
+ return source && provider && source.scheme === undefined ? { ...source, scheme: provider.plugin.id } : source;
94
128
  }
95
129
  //# sourceMappingURL=analysis-files.js.map
@@ -16,9 +16,11 @@ export async function inspectDuplication(files, results, cache) {
16
16
  export async function importAnalysisCoverage({ coverage: input, excludedPaths = [], snapshot }, sources, files, results, cache) {
17
17
  if (input === undefined)
18
18
  return;
19
+ const unclassified = new Set([...results.unmeasured].filter(([, missing]) => missing.includes('codeLines')).map(([path]) => path));
20
+ const excludes = sourceExclusionMatcher(excludedPaths, snapshot.generatedExcluded);
19
21
  const value = { text: input.text, root: input.sourceRoot, sourceLines: sourceLineCounts(sources.sourceFiles),
20
- codeLines: new Map(files.cloneSources.map(({ path, codeLines }) => [path, new Set(codeLines)])), functionBodies: files.functionBodies,
21
- excludes: sourceExclusionMatcher(excludedPaths, snapshot.generatedExcluded) };
22
+ codeLines: files.codeLines, unclassified, functionBodies: files.functionBodies,
23
+ excludes: (path) => excludes(path) || sources.unavailableFiles.has(path) };
22
24
  const outcomes = await execute(coveragePlan, new Map([['lcov', { contract: lcovInput.id, value }]]), cache);
23
25
  for (const task of coveragePlan) {
24
26
  results.remember(task);
@@ -2,4 +2,5 @@ import type { Report } from '../core/model/report.js';
2
2
  import type { AnalysisInput } from '../core/usecases/inspect.js';
3
3
  import type { AnalysisResults } from './analysis-results.js';
4
4
  import type { AnalysisSources } from './analysis-sources.js';
5
+ export declare const analysisProfile = "repository/v3";
5
6
  export declare function assembleAnalysisReport(input: AnalysisInput, sources: AnalysisSources, results: AnalysisResults): Report;
@@ -6,14 +6,15 @@ import { defaultSourceExclusions, generatedSourcePolicy } from '../core/profile/
6
6
  import { duplicationSettings, structuralRules } from '../core/profile/maintainability.js';
7
7
  import { defaultProvider } from './analysis-sources.js';
8
8
  import { fileTypeId } from '../core/model/file-types.js';
9
+ export const analysisProfile = 'repository/v3';
9
10
  const measurementDefinitions = {
10
11
  [definitions.lines]: 'Physical lines including blank lines and comments. A final line terminator does not add a line.',
11
- [definitions.functions]: 'Babel function nodes with bodies, including nested functions and methods.',
12
- [definitions.complexity]: 'One plus branches in the function body: if, ternary, loops, catch, non-default switch cases and logical operators. Nested functions are measured separately. Line and column are 1-based and columns count UTF-16 units.',
13
- [definitions.coverage]: 'Distinct covered code lines divided by the distinct code lines listed in LCOV DA records. Hit counts are summed across records. A zero denominator has no ratio.',
14
- [definitions.codeLines]: 'Nonblank physical lines after removing Babel comment spans and the interpreter directive. A line containing both code and a comment counts as code.',
15
- [definitions.comments]: 'Physical lines containing only a Babel comment or interpreter directive.',
16
- [definitions.classes]: 'Babel class declaration and expression nodes.',
12
+ [definitions.functions]: 'Functions, methods and function literals recognized by the language provider, including nested functions.',
13
+ [definitions.complexity]: 'One plus decision points in the function body. The language provider defines its decision rules and column units. Nested functions are measured separately.',
14
+ [definitions.coverage]: 'Distinct covered lines divided by the distinct lines listed in LCOV DA records, filtered to code where classifications are available. Hit counts are summed across records. A zero denominator has no ratio.',
15
+ [definitions.codeLines]: 'Nonblank physical lines after removing comment spans and the interpreter directive. A line containing both code and a comment counts as code.',
16
+ [definitions.comments]: 'Physical lines containing only a comment or interpreter directive.',
17
+ [definitions.classes]: 'Class declarations and expressions recognized by the language provider.',
17
18
  [definitions.cognitiveComplexity]: 'Flow breaks plus nesting weight and logical operator sequences. Nested functions are measured separately. File complexity sums functions and module-level flow breaks.',
18
19
  [definitions.duplicatedLines]: 'Distinct code lines inside repeated Babel syntax subtrees, including original and repeated occurrences. Identifier and literal spellings are ignored for similar-code matches.',
19
20
  };
@@ -29,10 +30,11 @@ export function assembleAnalysisReport(input, sources, results) {
29
30
  definitions: { ...Object.fromEntries((pluginData?.metrics ?? []).map(metric => [metric.id, metric.description ?? metric.label])),
30
31
  ...measurementDefinitions },
31
32
  scope: { files: fileCount, parsed: results.parsed.size },
32
- status: inspectionStatus(fileCount, results),
33
+ status: inspectionStatus(fileCount > 0 || sources.unavailableFiles.size > 0, results),
33
34
  measurements: results.measurements,
34
35
  diagnostics: results.diagnostics,
35
36
  findings: results.findings,
37
+ ...(results.ruleSkips.length === 0 ? {} : { ruleSkips: results.ruleSkips }),
36
38
  ...(pluginData === undefined ? {} : { pluginData: { ...pluginData, languages: sources.languages.catalog,
37
39
  inventory: reportInventory(snapshot, sources, results) } }),
38
40
  };
@@ -40,28 +42,29 @@ export function assembleAnalysisReport(input, sources, results) {
40
42
  function appliedConfiguration({ snapshot, excludedOutput, excludedPaths = [], coverage }, { languages, claimedPlugins, plugins }, results) {
41
43
  const securityScanners = results.securityScanners(claimedPlugins);
42
44
  return {
43
- profile: 'js-ts/v2', mode: snapshot.subject.kind,
45
+ profile: analysisProfile, mode: snapshot.subject.kind,
44
46
  source: { extensions: languages.extensions, ...(languages.globs.length ? { globs: languages.globs } : {}),
45
47
  excludedDirectories: sourceDirectoriesExcluded, excludedOutput, excludedPaths,
46
48
  defaultExclusions: defaultSourceExclusions, generatedSourcePolicy, generatedExcluded: snapshot.generatedExcluded ?? [] },
47
49
  parser: defaultProvider.plugin.settings,
48
50
  maintainability: { structuralRules, duplication: duplicationSettings, debtModel, remediation: 'nonoverlapping-complexity/v1' },
49
51
  coverage: coverage === undefined ? null : { inputDigest: digest(coverage.text), pathBase: coverage.sourceRoot,
50
- merge: 'any-hit', hitCounts: 'sum', lines: 'code-only' },
52
+ merge: 'any-hit', hitCounts: 'sum',
53
+ lines: [...results.unmeasured.values()].some(measures => measures.includes('codeLines')) ? 'code-when-classified' : 'code-only' },
51
54
  ...(securityScanners.length ? { securityScanners } : {}),
52
- plugins: plugins.map(pluginProvenance),
55
+ plugins: [...plugins, ...languages.native.filter(plugin => plugin.unavailableReason !== undefined)].map(pluginProvenance),
53
56
  operations: results.operationRecords(),
54
57
  };
55
58
  }
56
- function pluginProvenance({ id, version, api, tools, kinds, claims, settings, providesLanguages }) {
59
+ function pluginProvenance({ id, version, api, tools, kinds, claims, settings, providesLanguages, unavailableReason }) {
57
60
  return { id, version, api, tools: tools ?? {}, kinds,
58
61
  ...(claims === undefined ? {} : { claims }), ...(settings === undefined ? {} : { settings }),
59
- ...(providesLanguages === undefined ? {} : { providesLanguages }) };
62
+ ...(providesLanguages === undefined ? {} : { providesLanguages }), ...(unavailableReason === undefined ? {} : { unavailableReason }) };
60
63
  }
61
- function inspectionStatus(fileCount, results) {
64
+ function inspectionStatus(hasSources, results) {
62
65
  if (results.diagnostics.length > 0)
63
66
  return 'partial';
64
- return fileCount === 0 && !results.completedInspection ? 'not-applicable' : 'complete';
67
+ return !hasSources && !results.completedInspection ? 'not-applicable' : 'complete';
65
68
  }
66
69
  function reportInventory(snapshot, sources, results) {
67
70
  const inventory = new Map((snapshot.inventory ?? []).map(({ path, lines, bytes }) => [path, { lines, bytes }]));
@@ -71,8 +74,10 @@ function reportInventory(snapshot, sources, results) {
71
74
  }
72
75
  return [...inventory].sort(([left], [right]) => comparePaths(left, right)).map(([path, { lines, bytes }]) => {
73
76
  const provider = sources.providersByPath.get(path);
77
+ const unmeasured = results.unmeasured.get(path);
74
78
  return { path, lines, ...(bytes === undefined ? {} : { bytes }), language: provider?.language(path) ?? fileTypeId(path),
75
- analysed: results.parsed.has(path) || results.inspected.has(path), ...(provider === undefined ? {} : { provider: provider.key }) };
79
+ analysed: results.parsed.has(path) || results.inspected.has(path), ...(provider === undefined ? {} : { provider: provider.key }),
80
+ ...(unmeasured === undefined ? {} : { unmeasured }) };
76
81
  });
77
82
  }
78
83
  //# sourceMappingURL=analysis-report.js.map
@@ -2,5 +2,6 @@ import type { OperationCacheOptions } from '../core/engine/operation-cache.js';
2
2
  import type { CodeStructure } from '../core/model/code-structure.js';
3
3
  import type { AnalysisResults } from './analysis-results.js';
4
4
  import type { AnalysisSources } from './analysis-sources.js';
5
- export declare function collectRepositorySyntax(sources: AnalysisSources, results: AnalysisResults, cache?: OperationCacheOptions): Promise<Map<string, CodeStructure>>;
5
+ import type { HistoryFiles } from './history-cache.js';
6
+ export declare function collectRepositorySyntax(sources: AnalysisSources, results: AnalysisResults, cache?: OperationCacheOptions, history?: HistoryFiles): Promise<Map<string, CodeStructure>>;
6
7
  export declare function inspectRepositories(sources: AnalysisSources, results: AnalysisResults, cache?: OperationCacheOptions): Promise<void>;
@@ -4,8 +4,9 @@ import { codeStructures } from '../core/model/code-structure.js';
4
4
  import { sourceFiles } from '../core/model/snapshot.js';
5
5
  import { isClaimedText } from '../core/model/source.js';
6
6
  import { inspectionKeys } from './analysis-sources.js';
7
+ import { canReuseBatch } from './history-cache.js';
7
8
  const repositoryInput = new Map([['files', sourceFiles.id]]);
8
- export async function collectRepositorySyntax(sources, results, cache) {
9
+ export async function collectRepositorySyntax(sources, results, cache, history) {
9
10
  const providers = new Map(sources.languages.providers.filter(provider => provider.batch).map(provider => [provider.plugin.id, provider]));
10
11
  const facts = new Map();
11
12
  for (const { plugin } of sources.repository) {
@@ -15,7 +16,8 @@ export async function collectRepositorySyntax(sources, results, cache) {
15
16
  const files = sources.sources.filter(source => source.provider === provider).map(({ file }) => file);
16
17
  if (!files.length)
17
18
  continue;
18
- const outcomes = await runRepository(plugin, files, [provider.key, ...inspectionKeys(plugin)], results, cache);
19
+ const reusable = canReuseBatch(provider) ? history : undefined;
20
+ const outcomes = await runRepository(plugin, files, [provider.key, ...inspectionKeys(plugin)], results, cache, reusable);
19
21
  const syntax = outcomes.get(provider.key);
20
22
  if (syntax?.state === 'completed' && codeStructures.accepts(syntax.product.value)) {
21
23
  collectFacts(facts, syntax.product.value, files, provider.key, results);
@@ -35,9 +37,10 @@ export async function inspectRepositories(sources, results, cache) {
35
37
  await runRepository(plugin, files, select, results, cache);
36
38
  }
37
39
  }
38
- async function runRepository(plugin, files, select, results, cache) {
40
+ async function runRepository(plugin, files, select, results, cache, history) {
39
41
  const tasks = plan({ plugins: [plugin], select, inputs: repositoryInput });
40
- const outcomes = await execute(tasks, new Map([['files', { contract: sourceFiles.id, value: files }]]), cache);
42
+ const outcomes = history && tasks.length === 1
43
+ ? await runIndependentProvider(tasks[0], files, history, cache) : await executeRepository(tasks, files, cache);
41
44
  const paths = files.map(({ path }) => path);
42
45
  for (const task of tasks) {
43
46
  results.remember(task);
@@ -45,6 +48,41 @@ async function runRepository(plugin, files, select, results, cache) {
45
48
  }
46
49
  return outcomes;
47
50
  }
51
+ function executeRepository(tasks, files, cache) {
52
+ return execute(tasks, new Map([['files', { contract: sourceFiles.id, value: files }]]), cache);
53
+ }
54
+ async function runIndependentProvider(task, files, history, cache) {
55
+ const saved = new Map(files.flatMap(({ path }) => {
56
+ const syntax = history.read(path)?.syntax;
57
+ return syntax === undefined ? [] : [[path, syntax]];
58
+ }));
59
+ const missing = files.filter(({ path }) => !saved.has(path));
60
+ const outcomes = missing.length === 0 ? undefined : await executeRepository([task], missing, cache);
61
+ const fresh = outcomes === undefined ? [] : successfulBatch(outcomes.get(task.key), missing);
62
+ // Preserve complete-batch diagnostics if an incremental run produces incomplete facts or a warning.
63
+ if (!fresh)
64
+ return saved.size ? executeRepository([task], files, cache) : outcomes;
65
+ for (const syntax of fresh)
66
+ saved.set(syntax.path, syntax);
67
+ const values = files.map(({ path }) => saved.get(path));
68
+ const { output } = task.operation;
69
+ if (missing.length !== files.length && (!output.accepts(values) || (task.validateOutput && !task.validateOutput(values)))) {
70
+ return executeRepository([task], files, cache);
71
+ }
72
+ for (const syntax of values)
73
+ history.retain(syntax.path, { syntax });
74
+ return missing.length === files.length ? outcomes : new Map([[task.key, {
75
+ state: 'completed', product: { contract: output.id, value: values },
76
+ }]]);
77
+ }
78
+ function successfulBatch(outcome, files) {
79
+ if (outcome?.state !== 'completed' || outcome.diagnostics?.length || !codeStructures.accepts(outcome.product.value))
80
+ return;
81
+ const values = outcome.product.value;
82
+ const paths = new Set(files.map(({ path }) => path));
83
+ if (values.length === paths.size && values.every(({ path }) => paths.has(path)))
84
+ return values;
85
+ }
48
86
  function collectFacts(target, values, files, operation, results) {
49
87
  const planned = new Set(files.map(({ path }) => path));
50
88
  if (values.some(({ path }) => !planned.has(path))) {
@@ -3,12 +3,14 @@ import type { PlannedOperation } from '../core/engine/plan.js';
3
3
  import type { Plugin } from '../core/engine/plugin.js';
4
4
  import type { Finding } from '../core/model/finding.js';
5
5
  import type { Measurement } from '../core/model/measurement.js';
6
- import type { Diagnostic } from '../core/model/report.js';
6
+ import type { Diagnostic, Report } from '../core/model/report.js';
7
7
  export declare class AnalysisResults {
8
8
  readonly measurements: Measurement[];
9
9
  readonly findings: Finding[];
10
10
  readonly diagnostics: Diagnostic[];
11
11
  readonly parsed: Set<string>;
12
+ readonly ruleSkips: NonNullable<Report['ruleSkips']>[number][];
13
+ readonly unmeasured: Map<string, readonly ("classes" | "codeLines" | "cognitiveComplexity" | "commentLines" | "cyclomaticComplexity" | "duplication" | "functions" | "structuralRules")[]>;
12
14
  readonly inspected: Set<string>;
13
15
  completedInspection: boolean;
14
16
  private readonly products;
@@ -32,6 +34,7 @@ export declare function operationProvenance(task: PlannedOperation, syntaxProvid
32
34
  inputs: {
33
35
  [k: string]: import("../core/engine/plan.js").InputBinding;
34
36
  };
37
+ implementation?: string | undefined;
35
38
  scope?: "repository" | undefined;
36
39
  syntaxProvider?: string | undefined;
37
40
  };