@getcodesentinel/codesentinel 1.36.0 → 1.37.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 CHANGED
@@ -193,7 +193,7 @@ Use `codesentinel update` to manually check for a newer CLI release and install
193
193
 
194
194
  `codesentinel owners` cross-checks the owners declared in `CODEOWNERS` with the authors that history proves. It is offline, reads the `CODEOWNERS` file and the tracked tree from `--ref` so CI and a local run measure the same revision, and exits with `0` when the audit ran, `1` when a configured threshold is exceeded under `--fail-on error`, and `2` on a configuration or parse error (an untracked `CODEOWNERS`, an invalid flag value, or a file above GitHub's 3 MB limit). A repository without a `CODEOWNERS` file reports `available: false` and still exits `0`.
195
195
 
196
- `codesentinel init [path]` scaffolds a working CI setup in the target repository. It writes `.github/workflows/codesentinel.yml` and, when a `CODEOWNERS` file exists, `.codesentinel/owners.json`. The workflow runs `codesentinel ci --baseline-ref auto --fail-on error --snapshot codesentinel-snapshot.json`, builds an ownership report when a `CODEOWNERS` file is present, and uploads both artifacts with 90-day retention. Use `--force` to overwrite existing generated files, `--ci none` to skip the workflow (for example when CI lives elsewhere), or `--dry-run` to print what would be written without changing anything. Existing files are never overwritten without `--force`, and the command never edits `package.json`.
196
+ `codesentinel init [path]` scaffolds a working CI setup in the target repository. It writes `.github/workflows/codesentinel.yml` and, when a `CODEOWNERS` file exists, `.codesentinel/owners.json`. The workflow runs `codesentinel ci --baseline-ref auto --fail-on error --snapshot codesentinel-snapshot.json`, builds an ownership report when a `CODEOWNERS` file is present, and uploads both artifacts with 90-day retention. The uploaded snapshot includes ownership data when a `CODEOWNERS` file exists, so `codesentinel trend` can chart ownership history from those artifacts. Use `--force` to overwrite existing generated files, `--ci none` to skip the workflow (for example when CI lives elsewhere), or `--dry-run` to print what would be written without changing anything. Existing files are never overwritten without `--force`, and the command never edits `package.json`.
197
197
 
198
198
  Author identity mode:
199
199
 
@@ -333,6 +333,8 @@ Ownership violations are error-level, so `--fail-on` never softens them; `--fail
333
333
 
334
334
  `codesentinel ci` orchestrates snapshot + diff + gate evaluation + markdown summary generation.
335
335
 
336
+ `--snapshot <path>` writes a `codesentinel.snapshot.v2` artifact. Whenever a `CODEOWNERS` file exists, the snapshot embeds the ownership audit block (`ownership`) independently of the ownership thresholds, which only control enforcement. It also records `source.commit` (the full SHA) and `source.ref`, so `trend` can show the revision each run measured.
337
+
336
338
  Baseline input modes:
337
339
 
338
340
  - `--baseline <path>`: use an existing snapshot JSON artifact.
@@ -442,6 +444,8 @@ This measures system risk, not individual performance. No owner or author rankin
442
444
 
443
445
  `codesentinel trend` reads snapshot JSON artifacts written by `codesentinel ci --snapshot` and prints the series over time. Snapshots are CI artifacts, not repository files: `trend` never writes history into the repository and never changes the snapshot schema.
444
446
 
447
+ The workflow generated by `codesentinel init` runs `codesentinel ci --snapshot` and uploads the result as the `codesentinel` artifact, retrievable with `gh run download <run-id> -n codesentinel`. The ownership columns (Unowned, Ghosts, Drift) are populated from the snapshot's embedded ownership block, and the Commit column shows the short SHA. Both `codesentinel.snapshot.v2` and legacy `codesentinel.snapshot.v1` artifacts are read; v1 snapshots have no commit, so Commit shows `—`.
448
+
445
449
  ```bash
446
450
  codesentinel trend --from ./snapshots
447
451
  codesentinel trend --from './snapshots/*.json' --since 90d --last 12 --format md --output trend.md
package/dist/index.js CHANGED
@@ -1944,7 +1944,12 @@ var analyzeDependencyCandidateFromRegistry = async (input) => {
1944
1944
 
1945
1945
  // ../reporter/dist/index.js
1946
1946
  import { basename as basename2, posix } from "path";
1947
- var SNAPSHOT_SCHEMA_VERSION = "codesentinel.snapshot.v1";
1947
+ var SNAPSHOT_SCHEMA_VERSION = "codesentinel.snapshot.v2";
1948
+ var LEGACY_SNAPSHOT_SCHEMA_VERSIONS = ["codesentinel.snapshot.v1"];
1949
+ var SUPPORTED_SNAPSHOT_SCHEMA_VERSIONS = [
1950
+ SNAPSHOT_SCHEMA_VERSION,
1951
+ ...LEGACY_SNAPSHOT_SCHEMA_VERSIONS
1952
+ ];
1948
1953
  var REPORT_SCHEMA_VERSION = "codesentinel.report.v1";
1949
1954
  var RISK_MODEL_VERSION = "deterministic-v1";
1950
1955
  var round43 = (value) => Number(value.toFixed(4));
@@ -3071,15 +3076,19 @@ var createSnapshot = (input) => ({
3071
3076
  generatedAt: input.generatedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
3072
3077
  riskModelVersion: RISK_MODEL_VERSION,
3073
3078
  source: {
3074
- targetPath: input.analysis.structural.targetPath
3079
+ targetPath: input.analysis.structural.targetPath,
3080
+ ...input.source?.commit === void 0 ? {} : { commit: input.source.commit },
3081
+ ...input.source?.ref === void 0 ? {} : { ref: input.source.ref }
3075
3082
  },
3076
3083
  analysis: input.analysis,
3077
3084
  ...input.trace === void 0 ? {} : { trace: input.trace },
3078
- ...input.analysisConfig === void 0 ? {} : { analysisConfig: input.analysisConfig }
3085
+ ...input.analysisConfig === void 0 ? {} : { analysisConfig: input.analysisConfig },
3086
+ ...input.ownership === void 0 ? {} : { ownership: input.ownership }
3079
3087
  });
3088
+ var isSupportedSchemaVersion = (value) => typeof value === "string" && SUPPORTED_SNAPSHOT_SCHEMA_VERSIONS.includes(value);
3080
3089
  var parseSnapshot = (raw) => {
3081
3090
  const parsed = JSON.parse(raw);
3082
- if (parsed.schemaVersion !== SNAPSHOT_SCHEMA_VERSION) {
3091
+ if (!isSupportedSchemaVersion(parsed.schemaVersion)) {
3083
3092
  throw new Error("unsupported_snapshot_schema");
3084
3093
  }
3085
3094
  if (typeof parsed.generatedAt !== "string") {
@@ -3091,6 +3100,15 @@ var parseSnapshot = (raw) => {
3091
3100
  if (parsed.source === void 0 || typeof parsed.source.targetPath !== "string") {
3092
3101
  throw new Error("invalid_snapshot_source");
3093
3102
  }
3103
+ if (parsed.source.commit !== void 0 && (typeof parsed.source.commit !== "string" || parsed.source.commit.length === 0)) {
3104
+ throw new Error("invalid_snapshot_source_commit");
3105
+ }
3106
+ if (parsed.source.ref !== void 0 && (typeof parsed.source.ref !== "string" || parsed.source.ref.length === 0)) {
3107
+ throw new Error("invalid_snapshot_source_ref");
3108
+ }
3109
+ if (parsed.ownership !== void 0 && (typeof parsed.ownership !== "object" || parsed.ownership === null || Array.isArray(parsed.ownership))) {
3110
+ throw new Error("invalid_snapshot_ownership");
3111
+ }
3094
3112
  return parsed;
3095
3113
  };
3096
3114
  var formatReport = (report, format) => {
@@ -8967,6 +8985,8 @@ var buildAnalysisSnapshot = async (inputPath, authorIdentityMode, options, logge
8967
8985
  return createSnapshot({
8968
8986
  analysis: summary,
8969
8987
  ...evaluation.trace === void 0 ? {} : { trace: evaluation.trace },
8988
+ ...options.source === void 0 ? {} : { source: options.source },
8989
+ ...options.ownership === void 0 ? {} : { ownership: options.ownership },
8970
8990
  analysisConfig: {
8971
8991
  authorIdentityMode,
8972
8992
  includeTrace: options.includeTrace,
@@ -9053,13 +9073,9 @@ var runCheckCommand = async (inputPath, authorIdentityMode, options, logger = cr
9053
9073
  };
9054
9074
 
9055
9075
  // src/application/run-ci-command.ts
9076
+ import { existsSync as existsSync5 } from "fs";
9056
9077
  import { readFile as readFile5, writeFile as writeFile4 } from "fs/promises";
9057
- import { relative as relative3, resolve as resolve6 } from "path";
9058
-
9059
- // src/application/build-ownership-audit.ts
9060
- import { existsSync as existsSync4 } from "fs";
9061
- import { readFile as readFile4 } from "fs/promises";
9062
- import { resolve as resolve5 } from "path";
9078
+ import { join as join9, relative as relative3, resolve as resolve6 } from "path";
9063
9079
 
9064
9080
  // ../ownership/dist/index.js
9065
9081
  var CODEOWNERS_MAX_BYTES = 3 * 1024 * 1024;
@@ -9702,6 +9718,11 @@ var auditOwnership = (input) => {
9702
9718
  };
9703
9719
  };
9704
9720
 
9721
+ // src/application/build-ownership-audit.ts
9722
+ import { existsSync as existsSync4 } from "fs";
9723
+ import { readFile as readFile4 } from "fs/promises";
9724
+ import { resolve as resolve5 } from "path";
9725
+
9705
9726
  // src/application/owners-git.ts
9706
9727
  import { execFileSync as execFileSync2 } from "child_process";
9707
9728
  var RECORD_SEPARATOR = "";
@@ -9808,6 +9829,18 @@ var readRepositorySnapshot = (targetPath, ref) => {
9808
9829
  }
9809
9830
  return { repositoryPath, ref, commitUnix, trackedFiles };
9810
9831
  };
9832
+ var COMMIT_SHA_PATTERN = /^[0-9a-f]{40}(?:[0-9a-f]{24})?$/i;
9833
+ var readRepositoryContext = (targetPath, ref = "HEAD") => {
9834
+ try {
9835
+ const repositoryPath = runGit2(targetPath, ["rev-parse", "--show-toplevel"]).trim();
9836
+ if (repositoryPath.length === 0) return null;
9837
+ const commit = runGit2(repositoryPath, ["rev-parse", "--verify", `${ref}^{commit}`]).trim();
9838
+ if (!COMMIT_SHA_PATTERN.test(commit)) return null;
9839
+ return { repositoryPath, commit, ref };
9840
+ } catch {
9841
+ return null;
9842
+ }
9843
+ };
9811
9844
  var readTextAtRef = (repositoryPath, ref, filePath) => runGit2(repositoryPath, ["show", `${ref}:${filePath}`]);
9812
9845
  var accumulateAuthor = (authors, authorId, authorName) => {
9813
9846
  const author = authors.get(authorId) ?? { authorName, commits: 0 };
@@ -10021,6 +10054,96 @@ var buildOwnershipAudit = async (targetPath, options, logger) => {
10021
10054
  };
10022
10055
  };
10023
10056
 
10057
+ // src/application/report-ownership.ts
10058
+ import { execFileSync as execFileSync3 } from "child_process";
10059
+ var stripGitSuffix = (path) => path.replace(/\.git\/?$/i, "").replace(/\/+$/, "");
10060
+ var normalizeRepositoryWebUrl = (raw) => {
10061
+ const value = raw.trim();
10062
+ if (value.length === 0) {
10063
+ return null;
10064
+ }
10065
+ if (!value.includes("://")) {
10066
+ const scpMatch = value.match(/^(?:[^@\s]+@)?([^:/\s]+):(.+)$/);
10067
+ if (scpMatch === null) {
10068
+ return null;
10069
+ }
10070
+ const host = scpMatch[1];
10071
+ const path2 = stripGitSuffix(scpMatch[2] ?? "").replace(/^\/+/, "");
10072
+ if (host === void 0 || path2.length === 0) {
10073
+ return null;
10074
+ }
10075
+ return `https://${host}/${path2}`;
10076
+ }
10077
+ let url;
10078
+ try {
10079
+ url = new URL(value);
10080
+ } catch {
10081
+ return null;
10082
+ }
10083
+ if (url.protocol !== "https:" && url.protocol !== "http:" && url.protocol !== "ssh:") {
10084
+ return null;
10085
+ }
10086
+ const path = stripGitSuffix(url.pathname).replace(/^\/+/, "");
10087
+ if (url.hostname.length === 0 || path.length === 0) {
10088
+ return null;
10089
+ }
10090
+ return `https://${url.hostname}/${path}`;
10091
+ };
10092
+ var readRepositoryWebUrl = (repositoryPath) => {
10093
+ try {
10094
+ const raw = execFileSync3(
10095
+ "git",
10096
+ ["-C", repositoryPath, "config", "--get", "remote.origin.url"],
10097
+ {
10098
+ encoding: "utf8",
10099
+ stdio: ["ignore", "pipe", "ignore"]
10100
+ }
10101
+ );
10102
+ return normalizeRepositoryWebUrl(raw);
10103
+ } catch {
10104
+ return null;
10105
+ }
10106
+ };
10107
+ var toOwnershipAuditReport = (audit) => {
10108
+ if (!audit.available) {
10109
+ return {
10110
+ available: false,
10111
+ reason: audit.reason,
10112
+ warnings: audit.warnings
10113
+ };
10114
+ }
10115
+ return {
10116
+ available: true,
10117
+ codeowners: {
10118
+ source: audit.codeowners.source,
10119
+ ignoredSources: audit.codeowners.ignoredSources,
10120
+ errors: audit.codeowners.errors
10121
+ },
10122
+ metrics: audit.metrics,
10123
+ ghostOwners: audit.ghostOwners,
10124
+ files: audit.files,
10125
+ warnings: audit.warnings
10126
+ };
10127
+ };
10128
+ var buildReportOwnership = async (repositoryPath, logger) => {
10129
+ const webUrl = readRepositoryWebUrl(repositoryPath);
10130
+ try {
10131
+ const { audit } = await buildOwnershipAudit(repositoryPath, {}, logger);
10132
+ return { ownership: toOwnershipAuditReport(audit), webUrl };
10133
+ } catch (error) {
10134
+ const message = error instanceof Error ? error.message : "Unknown ownership audit error.";
10135
+ logger.warn(`ownership audit unavailable: ${message}`);
10136
+ return {
10137
+ ownership: {
10138
+ available: false,
10139
+ reason: "audit_unavailable",
10140
+ warnings: [message]
10141
+ },
10142
+ webUrl
10143
+ };
10144
+ }
10145
+ };
10146
+
10024
10147
  // src/application/run-ci-command.ts
10025
10148
  var isPathOutsideBase = (value) => {
10026
10149
  return value === ".." || value.startsWith("../") || value.startsWith("..\\");
@@ -10035,6 +10158,38 @@ var runCiCommand = async (inputPath, authorIdentityMode, options, logger = creat
10035
10158
  throw new GovernanceConfigurationError("baseline-sha requires --baseline-ref auto");
10036
10159
  }
10037
10160
  const resolvedTargetPath = resolve6(inputPath ?? process.cwd());
10161
+ const repositoryContext = readRepositoryContext(resolvedTargetPath);
10162
+ const repositoryPath = repositoryContext?.repositoryPath ?? resolvedTargetPath;
10163
+ const ownershipConfigured = options.gateConfig.maxUnownedCritical !== void 0 || options.gateConfig.maxGhostOwners !== void 0 || options.gateConfig.maxDrift !== void 0;
10164
+ const needsOwnershipData = ownershipConfigured || CODEOWNERS_CANDIDATE_PATHS.some((candidate) => existsSync5(join9(repositoryPath, candidate)));
10165
+ let audit;
10166
+ if (needsOwnershipData) {
10167
+ logger.info(
10168
+ ownershipConfigured ? "auditing declared ownership for ownership gates" : "auditing declared ownership for the snapshot"
10169
+ );
10170
+ try {
10171
+ ({ audit } = await buildOwnershipAudit(
10172
+ resolvedTargetPath,
10173
+ {
10174
+ ...options.ownership?.ref === void 0 ? {} : { ref: options.ownership.ref },
10175
+ ...options.ownership?.windowDays === void 0 ? {} : { windowDays: options.ownership.windowDays },
10176
+ ...options.ownership?.minCommits === void 0 ? {} : { minCommits: options.ownership.minCommits }
10177
+ },
10178
+ logger
10179
+ ));
10180
+ } catch (error) {
10181
+ if (error instanceof OwnersConfigurationError) {
10182
+ if (ownershipConfigured) {
10183
+ throw new GovernanceConfigurationError(error.message);
10184
+ }
10185
+ logger.warn(`ownership data unavailable: ${error.message}`);
10186
+ } else {
10187
+ throw error;
10188
+ }
10189
+ }
10190
+ }
10191
+ const ownershipReport = audit !== void 0 && audit.available ? toOwnershipAuditReport(audit) : void 0;
10192
+ const source = repositoryContext === null ? void 0 : { commit: repositoryContext.commit, ref: repositoryContext.ref };
10038
10193
  logger.info("building current snapshot");
10039
10194
  const current = await buildAnalysisSnapshot(
10040
10195
  inputPath,
@@ -10042,7 +10197,9 @@ var runCiCommand = async (inputPath, authorIdentityMode, options, logger = creat
10042
10197
  {
10043
10198
  includeTrace: options.includeTrace,
10044
10199
  ...options.scoringProfile === void 0 ? {} : { scoringProfile: options.scoringProfile },
10045
- ...options.recentWindowDays === void 0 ? {} : { recentWindowDays: options.recentWindowDays }
10200
+ ...options.recentWindowDays === void 0 ? {} : { recentWindowDays: options.recentWindowDays },
10201
+ ...source === void 0 ? {} : { source },
10202
+ ...ownershipReport === void 0 ? {} : { ownership: ownershipReport }
10046
10203
  },
10047
10204
  logger
10048
10205
  );
@@ -10129,28 +10286,9 @@ var runCiCommand = async (inputPath, authorIdentityMode, options, logger = creat
10129
10286
  }
10130
10287
  diff = compareSnapshots(current, baseline);
10131
10288
  }
10132
- const ownershipConfigured = options.gateConfig.maxUnownedCritical !== void 0 || options.gateConfig.maxGhostOwners !== void 0 || options.gateConfig.maxDrift !== void 0;
10133
10289
  let ownershipInput;
10134
10290
  let ownershipSummary;
10135
- if (ownershipConfigured) {
10136
- logger.info("auditing declared ownership for ownership gates");
10137
- let audit;
10138
- try {
10139
- ({ audit } = await buildOwnershipAudit(
10140
- resolvedTargetPath,
10141
- {
10142
- ...options.ownership?.ref === void 0 ? {} : { ref: options.ownership.ref },
10143
- ...options.ownership?.windowDays === void 0 ? {} : { windowDays: options.ownership.windowDays },
10144
- ...options.ownership?.minCommits === void 0 ? {} : { minCommits: options.ownership.minCommits }
10145
- },
10146
- logger
10147
- ));
10148
- } catch (error) {
10149
- if (error instanceof OwnersConfigurationError) {
10150
- throw new GovernanceConfigurationError(error.message);
10151
- }
10152
- throw error;
10153
- }
10291
+ if (ownershipConfigured && audit !== void 0) {
10154
10292
  if (audit.available) {
10155
10293
  const metrics = {
10156
10294
  declaredCoveragePercent: audit.metrics.declaredCoveragePercent,
@@ -10222,12 +10360,12 @@ ${ciMarkdown}`;
10222
10360
  };
10223
10361
 
10224
10362
  // src/application/run-report-command.ts
10225
- import { join as join10 } from "path";
10363
+ import { join as join11 } from "path";
10226
10364
  import { readFile as readFile7, writeFile as writeFile6 } from "fs/promises";
10227
10365
 
10228
10366
  // src/application/html-report.ts
10229
10367
  import { mkdir as mkdir3, readFile as readFile6, rm, stat as stat2, writeFile as writeFile5 } from "fs/promises";
10230
- import { dirname as dirname2, join as join9, resolve as resolve7 } from "path";
10368
+ import { dirname as dirname2, join as join10, resolve as resolve7 } from "path";
10231
10369
  import { fileURLToPath } from "url";
10232
10370
  var HTML_REPORT_DIR = ".codesentinel/report";
10233
10371
  var getBundledHtmlAppPath = () => resolve7(dirname2(fileURLToPath(import.meta.url)), "html-report-app");
@@ -10290,7 +10428,7 @@ var assertHtmlAppAssets = async (assetPath) => {
10290
10428
  };
10291
10429
  var resolveHtmlReportOutputPath = (repositoryPath, outputPath) => {
10292
10430
  const invocationCwd = process.env["INIT_CWD"] ?? process.cwd();
10293
- return resolve7(invocationCwd, outputPath ?? join9(repositoryPath, HTML_REPORT_DIR));
10431
+ return resolve7(invocationCwd, outputPath ?? join10(repositoryPath, HTML_REPORT_DIR));
10294
10432
  };
10295
10433
  var writeHtmlReportBundle = async (report, options) => {
10296
10434
  const bundledAppPath = options.bundledAppPath ?? getBundledHtmlAppPath();
@@ -10339,96 +10477,6 @@ var openPath = async (targetPath) => {
10339
10477
  });
10340
10478
  };
10341
10479
 
10342
- // src/application/report-ownership.ts
10343
- import { execFileSync as execFileSync3 } from "child_process";
10344
- var stripGitSuffix = (path) => path.replace(/\.git\/?$/i, "").replace(/\/+$/, "");
10345
- var normalizeRepositoryWebUrl = (raw) => {
10346
- const value = raw.trim();
10347
- if (value.length === 0) {
10348
- return null;
10349
- }
10350
- if (!value.includes("://")) {
10351
- const scpMatch = value.match(/^(?:[^@\s]+@)?([^:/\s]+):(.+)$/);
10352
- if (scpMatch === null) {
10353
- return null;
10354
- }
10355
- const host = scpMatch[1];
10356
- const path2 = stripGitSuffix(scpMatch[2] ?? "").replace(/^\/+/, "");
10357
- if (host === void 0 || path2.length === 0) {
10358
- return null;
10359
- }
10360
- return `https://${host}/${path2}`;
10361
- }
10362
- let url;
10363
- try {
10364
- url = new URL(value);
10365
- } catch {
10366
- return null;
10367
- }
10368
- if (url.protocol !== "https:" && url.protocol !== "http:" && url.protocol !== "ssh:") {
10369
- return null;
10370
- }
10371
- const path = stripGitSuffix(url.pathname).replace(/^\/+/, "");
10372
- if (url.hostname.length === 0 || path.length === 0) {
10373
- return null;
10374
- }
10375
- return `https://${url.hostname}/${path}`;
10376
- };
10377
- var readRepositoryWebUrl = (repositoryPath) => {
10378
- try {
10379
- const raw = execFileSync3(
10380
- "git",
10381
- ["-C", repositoryPath, "config", "--get", "remote.origin.url"],
10382
- {
10383
- encoding: "utf8",
10384
- stdio: ["ignore", "pipe", "ignore"]
10385
- }
10386
- );
10387
- return normalizeRepositoryWebUrl(raw);
10388
- } catch {
10389
- return null;
10390
- }
10391
- };
10392
- var toOwnershipAuditReport = (audit) => {
10393
- if (!audit.available) {
10394
- return {
10395
- available: false,
10396
- reason: audit.reason,
10397
- warnings: audit.warnings
10398
- };
10399
- }
10400
- return {
10401
- available: true,
10402
- codeowners: {
10403
- source: audit.codeowners.source,
10404
- ignoredSources: audit.codeowners.ignoredSources,
10405
- errors: audit.codeowners.errors
10406
- },
10407
- metrics: audit.metrics,
10408
- ghostOwners: audit.ghostOwners,
10409
- files: audit.files,
10410
- warnings: audit.warnings
10411
- };
10412
- };
10413
- var buildReportOwnership = async (repositoryPath, logger) => {
10414
- const webUrl = readRepositoryWebUrl(repositoryPath);
10415
- try {
10416
- const { audit } = await buildOwnershipAudit(repositoryPath, {}, logger);
10417
- return { ownership: toOwnershipAuditReport(audit), webUrl };
10418
- } catch (error) {
10419
- const message = error instanceof Error ? error.message : "Unknown ownership audit error.";
10420
- logger.warn(`ownership audit unavailable: ${message}`);
10421
- return {
10422
- ownership: {
10423
- available: false,
10424
- reason: "audit_unavailable",
10425
- warnings: [message]
10426
- },
10427
- webUrl
10428
- };
10429
- }
10430
- };
10431
-
10432
10480
  // src/application/run-report-command.ts
10433
10481
  var runReportCommand = async (inputPath, authorIdentityMode, options, logger = createSilentLogger()) => {
10434
10482
  logger.info("building analysis snapshot");
@@ -10467,7 +10515,7 @@ var runReportCommand = async (inputPath, authorIdentityMode, options, logger = c
10467
10515
  ...options.outputPath === void 0 ? {} : { outputPath: options.outputPath }
10468
10516
  });
10469
10517
  if (options.open === true) {
10470
- const opened = await openPath(join10(bundlePath, "index.html"));
10518
+ const opened = await openPath(join11(bundlePath, "index.html"));
10471
10519
  if (!opened) {
10472
10520
  logger.warn("unable to open html report automatically on this platform");
10473
10521
  }
@@ -11114,7 +11162,7 @@ var formatTrendOutput = (report, format) => {
11114
11162
 
11115
11163
  // src/application/read-trend-snapshots.ts
11116
11164
  import { glob, readFile as readFile8, readdir as readdir2, stat as stat3 } from "fs/promises";
11117
- import { basename as basename5, join as join11, resolve as resolve9 } from "path";
11165
+ import { basename as basename5, join as join12, resolve as resolve9 } from "path";
11118
11166
  var TrendConfigurationError = class extends Error {
11119
11167
  constructor(message) {
11120
11168
  super(message);
@@ -11160,6 +11208,7 @@ var formatSchemaVersion = (value) => {
11160
11208
  }
11161
11209
  return JSON.stringify(value) ?? "invalid";
11162
11210
  };
11211
+ var isSupportedSchemaVersion2 = (value) => typeof value === "string" && SUPPORTED_SNAPSHOT_SCHEMA_VERSIONS.includes(value);
11163
11212
  var parseSnapshot2 = (fileName, content) => {
11164
11213
  let parsed;
11165
11214
  try {
@@ -11172,7 +11221,7 @@ var parseSnapshot2 = (fileName, content) => {
11172
11221
  return { point: null, warning: `skipped ${fileName}: unsupported schema version "missing"` };
11173
11222
  }
11174
11223
  const schemaVersion = snapshot["schemaVersion"];
11175
- if (schemaVersion !== SNAPSHOT_SCHEMA_VERSION) {
11224
+ if (!isSupportedSchemaVersion2(schemaVersion)) {
11176
11225
  const label = formatSchemaVersion(schemaVersion);
11177
11226
  return {
11178
11227
  point: null,
@@ -11219,7 +11268,7 @@ var discoverSnapshotFiles = async (from) => {
11219
11268
  const entries = await readdir2(resolved, { withFileTypes: true }).catch(() => {
11220
11269
  throw new TrendConfigurationError(`--from directory is not readable: ${from}`);
11221
11270
  });
11222
- const files2 = entries.filter((entry) => entry.isFile() && entry.name.endsWith(".json")).map((entry) => ({ path: join11(resolved, entry.name), name: entry.name })).sort((a, b) => compareText4(a.name, b.name));
11271
+ const files2 = entries.filter((entry) => entry.isFile() && entry.name.endsWith(".json")).map((entry) => ({ path: join12(resolved, entry.name), name: entry.name })).sort((a, b) => compareText4(a.name, b.name));
11223
11272
  if (files2.length === 0) {
11224
11273
  throw new TrendConfigurationError(`no snapshot JSON files found in ${from}`);
11225
11274
  }
@@ -11370,7 +11419,7 @@ var runTrendCommand = async (options, logger = createSilentLogger()) => {
11370
11419
 
11371
11420
  // src/application/run-init-command.ts
11372
11421
  import { access, mkdir as mkdir4, writeFile as writeFile9 } from "fs/promises";
11373
- import { dirname as dirname3, join as join12, resolve as resolve10 } from "path";
11422
+ import { dirname as dirname3, join as join13, resolve as resolve10 } from "path";
11374
11423
  var CODESENTINEL_WORKFLOW_PATH = ".github/workflows/codesentinel.yml";
11375
11424
  var CODESENTINEL_OWNERS_PATH = ".codesentinel/owners.json";
11376
11425
  var CODESENTINEL_WORKFLOW_TEMPLATE = `name: CodeSentinel
@@ -11512,7 +11561,7 @@ var fileExists = async (absolutePath) => {
11512
11561
  };
11513
11562
  var anyFileExists = async (targetPath, candidates) => {
11514
11563
  for (const candidate of candidates) {
11515
- if (await fileExists(join12(targetPath, candidate))) {
11564
+ if (await fileExists(join13(targetPath, candidate))) {
11516
11565
  return true;
11517
11566
  }
11518
11567
  }
@@ -11528,8 +11577,8 @@ var runInitCommand = async (inputPath, options = {}) => {
11528
11577
  const hasCodeownersFile = await anyFileExists(targetPath, CODEOWNERS_CANDIDATES);
11529
11578
  const plan = buildInitPlan({
11530
11579
  hasCodeownersFile,
11531
- workflowExists: ci === "github" && await fileExists(join12(targetPath, CODESENTINEL_WORKFLOW_PATH)),
11532
- ownersFileExists: hasCodeownersFile && await fileExists(join12(targetPath, CODESENTINEL_OWNERS_PATH)),
11580
+ workflowExists: ci === "github" && await fileExists(join13(targetPath, CODESENTINEL_WORKFLOW_PATH)),
11581
+ ownersFileExists: hasCodeownersFile && await fileExists(join13(targetPath, CODESENTINEL_OWNERS_PATH)),
11533
11582
  options: { ...options, ci }
11534
11583
  });
11535
11584
  if (options.dryRun !== true) {
@@ -11537,7 +11586,7 @@ var runInitCommand = async (inputPath, options = {}) => {
11537
11586
  if (entry.status !== "created" && entry.status !== "updated") {
11538
11587
  continue;
11539
11588
  }
11540
- const absolutePath = join12(targetPath, entry.path);
11589
+ const absolutePath = join13(targetPath, entry.path);
11541
11590
  await mkdir4(dirname3(absolutePath), { recursive: true });
11542
11591
  await writeFile9(absolutePath, entry.content ?? "", "utf8");
11543
11592
  }