repometry 0.0.0-dev.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.
package/README.md ADDED
@@ -0,0 +1,5 @@
1
+ # Repometry
2
+
3
+ **Track repository metrics without SaaS**
4
+
5
+ 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/index.js ADDED
@@ -0,0 +1 @@
1
+ const repometry = 'repometry'
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "repometry",
3
+ "version": "0.0.0-dev.0",
4
+ "description": "Track repository metrics without SaaS",
5
+ "type": "module",
6
+ "engines": { "node": ">=24" },
7
+ "bin": { "repometry": "./target/main/ts/cli/main.js" },
8
+ "exports": { ".": { "types": "./target/main/ts/index.d.ts", "default": "./target/main/ts/index.js" } },
9
+ "files": ["index.js"],
10
+ "scripts": {
11
+ "build": "tsc -p tsconfig.json && node -e \"const fs = require('node:fs'); fs.chmodSync('target/main/ts/cli/main.js', 0o755); fs.cpSync('src/main/resources', 'target/main/resources', { recursive: true })\"",
12
+ "test": "npm run build && tsc -p tsconfig.test.json && node --test 'target/verification/test/ts/*.test.js'",
13
+ "prepack": "npm run build"
14
+ },
15
+ "dependencies": {
16
+ "@babel/parser": "7.29.15",
17
+ "@babel/types": "7.29.15",
18
+ "ajv": "8.20.0"
19
+ },
20
+ "devDependencies": {
21
+ "@types/node": "24.19.2",
22
+ "typescript": "7.0.2"
23
+ }
24
+ }
@@ -0,0 +1,319 @@
1
+ #!/usr/bin/env node
2
+ import { readFile } from 'node:fs/promises';
3
+ import { basename, resolve } from 'node:path';
4
+ import { parseArgs } from 'node:util';
5
+ import { isRecord } from '../analysis/plugin.js';
6
+ import { measureDiffCoverage } from '../application/diff-coverage.js';
7
+ import { inspect } from '../application/inspect.js';
8
+ import { prepareMetabranch } from '../application/prepare-metabranch.js';
9
+ import { reviewExitCode, reviewPull } from '../application/review.js';
10
+ import { compareInspections } from '../comparison/compare.js';
11
+ import { remoteExecutor } from '../execution/remote-executor.js';
12
+ import { serveWorker } from '../execution/worker.js';
13
+ import { workerToken } from '../execution/worker-protocol.js';
14
+ import { normalizeFindingIgnore } from '../inspections/finding-ignore.js';
15
+ import { exportSite } from '../presentation/export-site.js';
16
+ import { readComponents } from '../presentation/components.js';
17
+ import { fileMetrics } from '../presentation/file-metrics.js';
18
+ import { serveSite } from '../presentation/local-server.js';
19
+ import { exportProjects } from '../presentation/projects.js';
20
+ import { GitReportReader } from '../reporting/git-reader.js';
21
+ import { LocalReportStore } from '../reporting/local-store.js';
22
+ import { listPullReviews } from '../reporting/pull-review-store.js';
23
+ import { savePullReview } from '../reporting/pull-review-store.js';
24
+ import { validSubjectId } from '../reporting/report.js';
25
+ import { normalizeExclusions } from '../source/exclusions.js';
26
+ import { gitRoot, resolveGitCommit } from '../source/git.js';
27
+ import { writeGitHubDiffCoverage, writeGitHubResult, writeGitHubReview } from './github.js';
28
+ const usage = `Repometry
29
+
30
+ repometry inspect [--repo DIR] [--revision REF | --working-tree] [--output DIR] [--profile FILE | --no-profile] [--exclude PATTERN]... [--lcov FILE]... [--worker-url URL]
31
+ [--sarif FILE]... [--security-sarif FILE]... [--secret-sarif FILE]... [--eslint-report FILE]... [--osv-report FILE]... [--finding-root DIR]
32
+ repometry show <ID> [--working-tree] [--repo DIR] [--output DIR | --meta-ref REF]
33
+ repometry files <ID> [--working-tree] [--repo DIR] [--output DIR | --meta-ref REF]
34
+ repometry history [--repo DIR] [--output DIR | --meta-ref REF]
35
+ repometry compare <BASE> <HEAD> [--repo DIR] [--output DIR | --meta-ref REF] [--baseline-output DIR]
36
+ repometry diff-coverage --base REF --lcov FILE [--lcov FILE]... [--repo DIR] [--revision REF] [--profile FILE] [--exclude PATTERN]... [--min-diff-coverage PERCENT]
37
+ repometry review --base REF [--lcov FILE]... [--repo DIR] [--revision REF] [--number NUMBER] [--output DIR] [--baseline-output DIR]
38
+ [--profile FILE] [--exclude PATTERN]... [--min-diff-coverage PERCENT] [--min-diff-lines COUNT]
39
+ [--max-coverage-drop POINTS] [--max-new-issues COUNT] [--github-summary] [--github-annotations]
40
+ repometry prepare <SHA> --meta-worktree DIR [--meta-branch NAME] [--repo DIR] [--output DIR]
41
+ repometry export --destination DIR [--local-details] [--title NAME] [--components FILE] [--repo DIR] [--output DIR | --meta-ref REF]
42
+ repometry view [--port NUMBER] [--title NAME] [--components FILE] [--repo DIR] [--output DIR | --meta-ref REF]
43
+ repometry projects --destination DIR
44
+ repometry worker [--port NUMBER] [--listen ADDRESS]
45
+
46
+ Inspect reads HEAD by default. Use --working-tree to inspect a directory as it is.
47
+ The output defaults to .repometry inside --repo (the current directory by default).
48
+ Use --working-tree with show to select a working snapshot digest.
49
+ Exit codes: 0 success, 1 command or input error, 2 incomplete result, 3 quality gate failed.
50
+ `;
51
+ const commandOptions = {
52
+ inspect: ['revision', 'profile', 'no-profile', 'exclude', 'lcov', 'working-tree', 'github-summary', 'worker-url',
53
+ 'sarif', 'security-sarif', 'secret-sarif', 'eslint-report', 'osv-report', 'finding-root'],
54
+ show: ['working-tree', 'meta-ref'],
55
+ files: ['working-tree', 'meta-ref'],
56
+ history: ['meta-ref'],
57
+ compare: ['meta-ref', 'baseline-output'],
58
+ 'diff-coverage': ['revision', 'base', 'lcov', 'profile', 'exclude', 'min-diff-coverage', 'github-summary'],
59
+ review: ['revision', 'base', 'lcov', 'profile', 'exclude', 'number', 'min-diff-coverage', 'min-diff-lines',
60
+ 'max-coverage-drop', 'max-new-issues', 'baseline-output', 'github-summary', 'github-annotations'],
61
+ prepare: ['meta-worktree', 'meta-branch'],
62
+ export: ['meta-ref', 'destination', 'local-details', 'title', 'components'],
63
+ view: ['meta-ref', 'port', 'title', 'components'],
64
+ projects: ['destination'],
65
+ worker: ['port', 'listen'],
66
+ };
67
+ function isCommand(command) {
68
+ return Object.hasOwn(commandOptions, command);
69
+ }
70
+ async function run(args) {
71
+ const [command, ...argv] = args;
72
+ if (command === undefined || command === 'help' || command === '--help' || command === '-h') {
73
+ process.stdout.write(usage);
74
+ return 0;
75
+ }
76
+ if (!isCommand(command))
77
+ throw new Error(`Unknown command: ${command}`);
78
+ const { values, positionals, tokens } = parseArgs({
79
+ args: argv,
80
+ options: {
81
+ repo: { type: 'string' }, output: { type: 'string' }, help: { type: 'boolean', short: 'h' },
82
+ revision: { type: 'string' }, lcov: { type: 'string', multiple: true }, 'working-tree': { type: 'boolean' },
83
+ profile: { type: 'string' }, 'no-profile': { type: 'boolean' }, exclude: { type: 'string', multiple: true },
84
+ 'meta-ref': { type: 'string' }, 'meta-worktree': { type: 'string' }, 'meta-branch': { type: 'string' }, 'github-summary': { type: 'boolean' },
85
+ 'baseline-output': { type: 'string' },
86
+ base: { type: 'string' }, 'min-diff-coverage': { type: 'string' },
87
+ number: { type: 'string' }, 'min-diff-lines': { type: 'string' }, 'max-coverage-drop': { type: 'string' },
88
+ 'max-new-issues': { type: 'string' }, 'github-annotations': { type: 'boolean' },
89
+ destination: { type: 'string' }, port: { type: 'string' }, title: { type: 'string' },
90
+ 'local-details': { type: 'boolean' }, components: { type: 'string' },
91
+ 'worker-url': { type: 'string' }, listen: { type: 'string' },
92
+ sarif: { type: 'string', multiple: true }, 'security-sarif': { type: 'string', multiple: true },
93
+ 'secret-sarif': { type: 'string', multiple: true }, 'eslint-report': { type: 'string', multiple: true },
94
+ 'osv-report': { type: 'string', multiple: true }, 'finding-root': { type: 'string' },
95
+ },
96
+ allowPositionals: command === 'show' || command === 'files' || command === 'prepare' || command === 'compare',
97
+ tokens: true,
98
+ });
99
+ if (values.help) {
100
+ process.stdout.write(usage);
101
+ return 0;
102
+ }
103
+ const repositoryOptions = command === 'worker' || command === 'projects' ? [] : command === 'diff-coverage' ? ['repo'] : ['repo', 'output'];
104
+ const allowed = new Set([...repositoryOptions, ...commandOptions[command]]);
105
+ for (const token of tokens) {
106
+ if (token.kind === 'option' && !allowed.has(token.name))
107
+ throw new Error(`${token.rawName} is unavailable for ${command}`);
108
+ }
109
+ if (values['meta-ref'] !== undefined && (values.output !== undefined || values['working-tree'])) {
110
+ throw new Error('Use --meta-ref to read Git reports separately from --output and --working-tree');
111
+ }
112
+ if (command === 'worker') {
113
+ const host = values.listen ?? '127.0.0.1';
114
+ if (host !== '127.0.0.1' && host !== '0.0.0.0')
115
+ throw new Error('--listen must be 127.0.0.1 or 0.0.0.0');
116
+ const server = await serveWorker(host, parsePort(values.port ?? '7331'), workerToken());
117
+ announce(server);
118
+ return 0;
119
+ }
120
+ if (command === 'projects') {
121
+ if (!values.destination)
122
+ throw new Error('projects requires --destination');
123
+ const destination = resolve(values.destination);
124
+ print({ destination, projects: await exportProjects(destination) });
125
+ return 0;
126
+ }
127
+ const directory = resolve(values.repo ?? '.');
128
+ const lcov = values.lcov?.length ? values.lcov.map(file => resolve(file)) : undefined;
129
+ if (command === 'diff-coverage') {
130
+ if (!values.base || lcov === undefined)
131
+ throw new Error('diff-coverage requires --base and --lcov');
132
+ const report = await measureDiffCoverage({
133
+ directory, revision: values.revision ?? 'HEAD', base: values.base, lcov,
134
+ exclude: await profileExclusions(values.profile, values.exclude),
135
+ minimumPercent: parsePercentage(values['min-diff-coverage']),
136
+ });
137
+ if (values['github-summary'])
138
+ await writeGitHubDiffCoverage(report);
139
+ print(report);
140
+ if (report.status === 'partial')
141
+ return 2;
142
+ return report.decision?.status === 'failed' ? 3 : 0;
143
+ }
144
+ const output = resolve(values.output ?? resolve(directory, '.repometry'));
145
+ if (command === 'inspect') {
146
+ if (values['working-tree'] && values.revision !== undefined)
147
+ throw new Error('Choose either --working-tree or --revision');
148
+ const executor = values['worker-url'] === undefined ? undefined : remoteExecutor(values['worker-url'], workerToken());
149
+ if (values['no-profile'] && values.profile !== undefined)
150
+ throw new Error('Choose either --profile or --no-profile');
151
+ const defaultProfile = values.profile === undefined && !values['no-profile']
152
+ ? resolve(values['working-tree'] ? directory : await gitRoot(directory), '.repometry', 'profile.json') : undefined;
153
+ const profile = await readProfile(values.profile ?? defaultProfile, defaultProfile !== undefined);
154
+ const findingInputs = [
155
+ ...(values.sarif ?? []).map(file => ({ file: resolve(file), format: 'sarif', category: 'lint' })),
156
+ ...(values['security-sarif'] ?? []).map(file => ({ file: resolve(file), format: 'sarif', category: 'security' })),
157
+ ...(values['secret-sarif'] ?? []).map(file => ({ file: resolve(file), format: 'sarif', category: 'secret' })),
158
+ ...(values['eslint-report'] ?? []).map(file => ({ file: resolve(file), format: 'eslint', category: 'lint' })),
159
+ ...(values['osv-report'] ?? []).map(file => ({ file: resolve(file), format: 'osv', category: 'dependency' })),
160
+ ];
161
+ if (values['finding-root'] !== undefined && findingInputs.length === 0)
162
+ throw new Error('--finding-root requires a scanner report');
163
+ const report = await inspect({ directory, output, source: values['working-tree'] ? { workingTree: true } : { revision: values.revision ?? 'HEAD' },
164
+ lcov,
165
+ exclude: [...profile.exclude, ...values.exclude ?? []], ignore: profile.ignore,
166
+ findingInputs, findingRoot: values['finding-root'] }, executor);
167
+ if (values['github-summary'])
168
+ await writeGitHubResult(report);
169
+ print({ ...summary(report), output });
170
+ return report.status === 'partial' ? 2 : 0;
171
+ }
172
+ const local = new LocalReportStore(output);
173
+ if (command === 'review') {
174
+ if (!values.base)
175
+ throw new Error('review requires --base');
176
+ if (values['github-annotations'] && !values['github-summary'])
177
+ throw new Error('--github-annotations requires --github-summary');
178
+ const number = parseCount(values.number, '--number', 1);
179
+ const minimumPercent = parsePercentage(values['min-diff-coverage']);
180
+ const minimumLines = parseCount(values['min-diff-lines'], '--min-diff-lines');
181
+ const maxCoverageDrop = parsePercentage(values['max-coverage-drop'], '--max-coverage-drop');
182
+ const maxNewIssues = parseCount(values['max-new-issues'], '--max-new-issues');
183
+ const baseline = values['baseline-output'] === undefined ? local : new LocalReportStore(resolve(values['baseline-output']));
184
+ const report = await reviewPull({ directory, revision: values.revision ?? 'HEAD', base: values.base,
185
+ lcov,
186
+ exclude: await profileExclusions(values.profile, values.exclude), number, minimumPercent, minimumLines, maxCoverageDrop, maxNewIssues }, local, baseline);
187
+ if (number !== undefined)
188
+ await savePullReview(output, report);
189
+ if (values['github-summary'])
190
+ await writeGitHubReview(report, values['github-annotations'] ? await gitRoot(directory) : undefined);
191
+ print(report);
192
+ return reviewExitCode(report);
193
+ }
194
+ if (command === 'prepare') {
195
+ const id = positionals[0];
196
+ const worktree = values['meta-worktree'];
197
+ if (positionals.length !== 1 || id === undefined || worktree === undefined)
198
+ throw new Error('prepare requires a source commit ID and --meta-worktree');
199
+ const report = await local.read({ kind: 'commit', id });
200
+ const files = await prepareMetabranch({ repository: directory, worktree: resolve(worktree), branch: values['meta-branch'] ?? 'repometry', report });
201
+ print({ subject: report.subject, worktree: resolve(worktree), files });
202
+ return 0;
203
+ }
204
+ if (command === 'compare') {
205
+ const [base, head] = positionals;
206
+ if (positionals.length !== 2 || !base || !head)
207
+ throw new Error('compare requires an explicit baseline and current Git commit');
208
+ const id = (revision) => validSubjectId('commit', revision) ? revision : resolveGitCommit(directory, revision);
209
+ const [baseId, headId, metaId] = await Promise.all([id(base), id(head),
210
+ values['meta-ref'] === undefined ? undefined : resolveGitCommit(directory, values['meta-ref'])]);
211
+ const currentReader = metaId === undefined ? local : new GitReportReader(directory, metaId);
212
+ const baselineReader = values['baseline-output'] === undefined ? currentReader : new LocalReportStore(resolve(values['baseline-output']));
213
+ const current = currentReader.read({ kind: 'commit', id: headId });
214
+ const baseline = baseId === headId && baselineReader === currentReader ? current : baselineReader.read({ kind: 'commit', id: baseId });
215
+ const [before, after] = await Promise.all([baseline, current]);
216
+ print(compareInspections(before, after));
217
+ return 0;
218
+ }
219
+ const store = values['meta-ref'] === undefined ? local : new GitReportReader(directory, values['meta-ref']);
220
+ if (command === 'export') {
221
+ if (!values.destination)
222
+ throw new Error('export requires --destination');
223
+ const destination = resolve(values.destination);
224
+ const title = values.title ?? (values.repo === undefined ? undefined : basename(directory));
225
+ const detailed = values['local-details'] === true;
226
+ if (values.components && !detailed)
227
+ throw new Error('--components requires --local-details when exporting');
228
+ const [components, pulls] = detailed ? await Promise.all([
229
+ readComponents(values.components ?? resolve(directory, '.repometry', 'components.json'), values.components === undefined),
230
+ listPullReviews(output),
231
+ ]) : [undefined, undefined];
232
+ await exportSite(store, destination, { title, mode: detailed ? 'private' : 'public', components, pulls });
233
+ print({ destination });
234
+ return 0;
235
+ }
236
+ if (command === 'view') {
237
+ const [components, pulls] = await Promise.all([
238
+ readComponents(values.components ?? resolve(directory, '.repometry', 'components.json'), values.components === undefined),
239
+ listPullReviews(output),
240
+ ]);
241
+ announce(await serveSite(store, parsePort(values.port ?? '0'), { title: values.title ?? basename(directory), components, pulls }));
242
+ return 0;
243
+ }
244
+ if (command === 'history') {
245
+ print((await store.list()).map(summary));
246
+ return 0;
247
+ }
248
+ if (positionals.length !== 1 || positionals[0] === undefined)
249
+ throw new Error(`${command} requires one full commit ID or snapshot digest`);
250
+ const report = await store.read({ kind: values['working-tree'] ? 'working-tree' : 'commit', id: positionals[0] });
251
+ print(command === 'files' ? fileMetrics(report) : report);
252
+ return 0;
253
+ }
254
+ async function profileExclusions(file, additional = []) {
255
+ const preset = await readProfile(file);
256
+ return [...preset.exclude, ...additional];
257
+ }
258
+ async function readProfile(file, optional = false) {
259
+ if (file === undefined)
260
+ return { exclude: [], ignore: [] };
261
+ let text;
262
+ try {
263
+ text = await readFile(file, 'utf8');
264
+ }
265
+ catch (error) {
266
+ if (optional && error instanceof Error && 'code' in error && error.code === 'ENOENT')
267
+ return { exclude: [], ignore: [] };
268
+ throw error;
269
+ }
270
+ const profile = JSON.parse(text);
271
+ if (!isRecord(profile) || Object.keys(profile).some(key => key !== 'exclude' && key !== 'ignore')) {
272
+ throw new Error('Expected a JSON profile with optional exclude and ignore arrays');
273
+ }
274
+ return { exclude: normalizeExclusions(profile.exclude === undefined ? [] : profile.exclude),
275
+ ignore: normalizeFindingIgnore(profile.ignore === undefined ? [] : profile.ignore) };
276
+ }
277
+ function parsePercentage(value, option = '--min-diff-coverage') {
278
+ if (value === undefined)
279
+ return undefined;
280
+ const percent = Number(value);
281
+ if (!/^(?:\d+(?:\.\d+)?|\.\d+)$/.test(value) || percent < 0 || percent > 100) {
282
+ throw new Error(`${option} must be a percentage from 0 to 100`);
283
+ }
284
+ return percent;
285
+ }
286
+ function parseCount(value, option, minimum = 0) {
287
+ if (value === undefined)
288
+ return undefined;
289
+ const count = Number(value);
290
+ if (!/^\d+$/.test(value) || !Number.isSafeInteger(count) || count < minimum) {
291
+ throw new Error(`${option} must be an integer of at least ${minimum}`);
292
+ }
293
+ return count;
294
+ }
295
+ function parsePort(raw) {
296
+ const port = Number(raw);
297
+ if (!/^\d+$/.test(raw) || port > 65_535)
298
+ throw new Error('--port must be an integer from 0 to 65535');
299
+ return port;
300
+ }
301
+ function announce(server) {
302
+ process.once('SIGINT', server.close);
303
+ process.once('SIGTERM', server.close);
304
+ process.stdout.write(`${server.url}\n`);
305
+ }
306
+ function summary(report) {
307
+ return { subject: report.subject, generatedAt: report.generatedAt, status: report.status, scope: report.scope,
308
+ measurements: report.measurements.length, diagnostics: report.diagnostics.length };
309
+ }
310
+ function print(value) {
311
+ process.stdout.write(`${JSON.stringify(value, null, 2)}\n`);
312
+ }
313
+ try {
314
+ process.exitCode = await run(process.argv.slice(2));
315
+ }
316
+ catch (error) {
317
+ process.stderr.write(`repometry: ${error instanceof Error ? error.message : String(error)}\n`);
318
+ process.exitCode = 1;
319
+ }
@@ -0,0 +1,13 @@
1
+ export { pluginApi } from './analysis/plugin.js';
2
+ export { plan } from './analysis/plan.js';
3
+ export { execute } from './analysis/execute.js';
4
+ export { analyzeSnapshot, inspect } from './application/inspect.js';
5
+ export { diffCoverageSchema, measureDiffCoverage } from './application/diff-coverage.js';
6
+ export { reviewPull, reviewExitCode } from './application/review.js';
7
+ export { compareInspections, comparisonSchema } from './comparison/compare.js';
8
+ export { fileMetrics, fileMetricsSchema } from './presentation/file-metrics.js';
9
+ export { LocalReportStore } from './reporting/local-store.js';
10
+ export { GitReportReader } from './reporting/git-reader.js';
11
+ export { readReport, reportSchema } from './reporting/report.js';
12
+ export { coverageGrade, qualitySummary } from './inspections/quality-summary.js';
13
+ export { pullReviewSchema, pullReviewsSchema } from './reporting/pull-review-model.js';