@getcodesentinel/codesentinel 1.43.3 → 1.43.4

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
@@ -339,7 +339,7 @@ Notes:
339
339
 
340
340
  - `likely_merge` (default) may merge multiple emails that likely belong to the same person based on repository history.
341
341
  - `strict_email` treats each canonical email as a distinct author, which avoids false merges but can split the same person across multiple emails.
342
- - Git mailmap is enabled (`git log --use-mailmap`). Put `.mailmap` in the repository being analyzed (the `codesentinel analyze [path]` target). Git will then deterministically unify known aliases before CodeSentinel computes ownership distributions.
342
+ - Git mailmap is enabled for both analysis history and the ownership verdict (`git log --use-mailmap` with mailmap-aware author fields). Put `.mailmap` in the repository being analyzed (the `codesentinel analyze [path]` target) and Git will deterministically unify known aliases in evolution distributions and in `owners` identity matching.
343
343
  - Evolution output includes both `authorDistributionByCommits` and `authorDistributionByChurn`, plus their derived `topAuthorShare...` and `busFactor...` fields.
344
344
  - Current scoring continues to use the commit-weighted ownership view (`...ByCommits`).
345
345
  - Logs are emitted to `stderr` and JSON output is written to `stdout`, so CI redirection still works.
@@ -951,7 +951,13 @@ The audit measures system risk, not individual performance. It emits no owner or
951
951
 
952
952
  ### Identity matching is heuristic
953
953
 
954
- Declared handles are matched to commit authors by noreply address, email local part, display name and the alias map in `.codesentinel/owners.json`. When that fails, the same person appears twice. This repository has one such case: `pnpm-workspace.yaml` is reported as drifted because the audit cannot prove that the declared `@aleixalonso` and the author `aleixalonso@hotmail.com` are the same account. A `.mailmap`, or an `aliases` entry in `.codesentinel/owners.json`, removes the ambiguity.
954
+ A declared handle covers every commit author the cascade attributes to it: the GitHub noreply address `<handle>@users.noreply.github.com`, any address whose local part is the handle, an exact normalized author name, and every identity listed in the alias map in `.codesentinel/owners.json`. When several steps match, the owner keeps all of those author ids in evidence order; the reported match kind is the highest-priority step (noreply, then email local part, then author name, then alias). This repository commits an alias entry for the two-address case, so `@aleixalonso` covers both `aleixalonso@users.noreply.github.com` and `aleixalonso@hotmail.com`.
955
+
956
+ Matching stays deliberately conservative. An address with no link to the handle — a different local part, no alias entry, and no `.mailmap` — is not guessed, so that file still drifts. Add the address to the alias map or add a `.mailmap` entry when you want the audit to treat it as the same person. Neither remedy broadens drift: an alias that never appears in a file's evidence does not make that file aligned.
957
+
958
+ `.codesentinel/owners.json` accepts two shapes: the wrapped object `{ "aliases": { "marta": ["m.gil@company.com"] }, "ignoreAuthors": ["*-bot@*"] }` and a bare alias map `{ "marta": ["m.gil@company.com"] }`. The wrapped shape is selected when either wrapped key is present; otherwise every value must be an array for the object to be read as the alias map.
959
+
960
+ `--aliases <file>` accepts a path relative to the audited repository root or an absolute path. A relative path and an absolute path inside the repository are read from the audited ref when tracked there and from the working tree otherwise. An absolute path outside the repository is read directly from disk and reported as unversioned. An explicitly requested alias file that cannot be read produces a warning and the audit runs without identity aliases; it is never a silent no-op.
955
961
 
956
962
  ### Ownership parsing and scope
957
963
 
package/dist/index.js CHANGED
@@ -6466,7 +6466,7 @@ var ExecGitCommandClient = class {
6466
6466
  };
6467
6467
  var COMMIT_RECORD_SEPARATOR = "";
6468
6468
  var COMMIT_FIELD_SEPARATOR = "";
6469
- var GIT_LOG_FORMAT = `%x1e%H%x1f%at%x1f%an%x1f%ae`;
6469
+ var GIT_LOG_FORMAT = `%x1e%H%x1f%at%x1f%aN%x1f%aE`;
6470
6470
  var mapParseProgressToHistoryProgress = (event) => ({
6471
6471
  stage: "git_log_parse_progress",
6472
6472
  parsedRecords: event.parsedRecords,
@@ -9085,7 +9085,7 @@ var runCheckCommand = async (inputPath, authorIdentityMode, options, logger = cr
9085
9085
  // src/application/run-ci-command.ts
9086
9086
  import { existsSync as existsSync5 } from "fs";
9087
9087
  import { readFile as readFile5, writeFile as writeFile4 } from "fs/promises";
9088
- import { join as join9, relative as relative3, resolve as resolve6 } from "path";
9088
+ import { join as join9, relative as relative4, resolve as resolve6 } from "path";
9089
9089
 
9090
9090
  // ../ownership/dist/index.js
9091
9091
  var CODEOWNERS_MAX_BYTES = 3 * 1024 * 1024;
@@ -9538,6 +9538,18 @@ var parseOwnersConfig = (raw) => {
9538
9538
  warnings: ["owners.json must contain a JSON object: identity aliases were ignored."]
9539
9539
  };
9540
9540
  }
9541
+ if (!("aliases" in parsed) && !("ignoreAuthors" in parsed)) {
9542
+ if (Object.keys(parsed).length === 0) {
9543
+ return { aliases: {}, ignoreAuthors: [], warnings };
9544
+ }
9545
+ if (Object.values(parsed).every((value) => Array.isArray(value))) {
9546
+ return { aliases: parseAliases(parsed, warnings), ignoreAuthors: [], warnings };
9547
+ }
9548
+ warnings.push(
9549
+ 'owners.json must contain either an "aliases" object or a bare { "handle": ["author-id"] } map: identity aliases were ignored.'
9550
+ );
9551
+ return { aliases: {}, ignoreAuthors: [], warnings };
9552
+ }
9541
9553
  const aliases = parseAliases(parsed["aliases"], warnings);
9542
9554
  const ignoreAuthors = parseIgnoreAuthors(parsed["ignoreAuthors"], warnings);
9543
9555
  return { aliases, ignoreAuthors, warnings };
@@ -9558,41 +9570,42 @@ var resolveOwner = (owner, authors, aliases) => {
9558
9570
  }
9559
9571
  const noreplyId = `${handle}@users.noreply.github.com`;
9560
9572
  const aliasTargets = aliases.get(handle) ?? [];
9561
- const byNoreply = [];
9562
- const byLocalPart = [];
9563
- const byName = [];
9564
- const byAlias = [];
9573
+ const matchedKinds = {
9574
+ github_noreply: false,
9575
+ email_local_part: false,
9576
+ author_name: false,
9577
+ alias: false
9578
+ };
9579
+ const activeAuthorIds = [];
9580
+ const seenAuthorIds = /* @__PURE__ */ new Set();
9565
9581
  for (const author of candidates) {
9566
9582
  const authorId = author.authorId.trim().toLowerCase();
9567
- if (authorId === noreplyId) {
9568
- byNoreply.push(author.authorId);
9569
- continue;
9570
- }
9583
+ const matchesNoreply = authorId === noreplyId;
9571
9584
  const localPart = localPartOf(authorId);
9572
- if (localPart !== null && localPart === handle) {
9573
- byLocalPart.push(author.authorId);
9574
- continue;
9575
- }
9585
+ const matchesLocalPart = localPart !== null && localPart === handle;
9576
9586
  const authorName = typeof author.authorName === "string" ? normalizeAuthorName(author.authorName) : "";
9577
- if (authorName.length > 0 && authorName === handle) {
9578
- byName.push(author.authorId);
9579
- continue;
9580
- }
9581
- if (aliasTargets.includes(authorId)) {
9582
- byAlias.push(author.authorId);
9583
- }
9587
+ const matchesName = authorName.length > 0 && authorName === handle;
9588
+ const matchesAlias = aliasTargets.includes(authorId);
9589
+ if (!matchesNoreply && !matchesLocalPart && !matchesName && !matchesAlias) continue;
9590
+ matchedKinds.github_noreply ||= matchesNoreply;
9591
+ matchedKinds.email_local_part ||= matchesLocalPart;
9592
+ matchedKinds.author_name ||= matchesName;
9593
+ matchedKinds.alias ||= matchesAlias;
9594
+ if (seenAuthorIds.has(author.authorId)) continue;
9595
+ seenAuthorIds.add(author.authorId);
9596
+ activeAuthorIds.push(author.authorId);
9584
9597
  }
9585
- if (byNoreply.length > 0) {
9586
- return { owner, kind: "github_noreply", activeAuthorIds: uniquify(byNoreply) };
9598
+ if (matchedKinds.github_noreply) {
9599
+ return { owner, kind: "github_noreply", activeAuthorIds };
9587
9600
  }
9588
- if (byLocalPart.length > 0) {
9589
- return { owner, kind: "email_local_part", activeAuthorIds: uniquify(byLocalPart) };
9601
+ if (matchedKinds.email_local_part) {
9602
+ return { owner, kind: "email_local_part", activeAuthorIds };
9590
9603
  }
9591
- if (byName.length > 0) {
9592
- return { owner, kind: "author_name", activeAuthorIds: uniquify(byName) };
9604
+ if (matchedKinds.author_name) {
9605
+ return { owner, kind: "author_name", activeAuthorIds };
9593
9606
  }
9594
- if (byAlias.length > 0) {
9595
- return { owner, kind: "alias", activeAuthorIds: uniquify(byAlias) };
9607
+ if (matchedKinds.alias) {
9608
+ return { owner, kind: "alias", activeAuthorIds };
9596
9609
  }
9597
9610
  if (aliasTargets.length > 0) {
9598
9611
  return { owner, kind: "alias_unresolved", activeAuthorIds: [] };
@@ -9826,13 +9839,13 @@ var auditOwnership = (input) => {
9826
9839
  // src/application/build-ownership-audit.ts
9827
9840
  import { existsSync as existsSync4 } from "fs";
9828
9841
  import { readFile as readFile4 } from "fs/promises";
9829
- import { resolve as resolve5 } from "path";
9842
+ import { isAbsolute as isAbsolute2, relative as relative3, resolve as resolve5 } from "path";
9830
9843
 
9831
9844
  // src/application/owners-git.ts
9832
9845
  import { execFileSync as execFileSync2 } from "child_process";
9833
9846
  var RECORD_SEPARATOR = "";
9834
9847
  var FIELD_SEPARATOR = "";
9835
- var LOG_FORMAT = `%x1e%at${FIELD_SEPARATOR}%an${FIELD_SEPARATOR}%ae`;
9848
+ var LOG_FORMAT = `%x1e%at${FIELD_SEPARATOR}%aN${FIELD_SEPARATOR}%aE`;
9836
9849
  var MAX_BUFFER_BYTES = 1024 * 1024 * 256;
9837
9850
  var OwnersGitError = class extends Error {
9838
9851
  code;
@@ -9963,6 +9976,7 @@ var collectOwnershipEvidence = (snapshot, windowDays) => {
9963
9976
  "core.quotepath=false",
9964
9977
  "log",
9965
9978
  snapshot.ref,
9979
+ "--use-mailmap",
9966
9980
  "--no-merges",
9967
9981
  "--no-renames",
9968
9982
  "--numstat",
@@ -10068,32 +10082,80 @@ var readCodeowners = (input) => {
10068
10082
  ignoredSources: selection.ignoredSources
10069
10083
  });
10070
10084
  };
10071
- var readOwnersConfig = async (snapshot, aliasesPath) => {
10072
- const normalized = normalizeRepositoryPath(aliasesPath);
10073
- const tracked = snapshot.trackedFiles.includes(normalized);
10074
- if (tracked) {
10075
- const text = readTextAtRef(snapshot.repositoryPath, snapshot.ref, normalized);
10076
- const parsed = parseOwnersConfig(text);
10085
+ var resolveAliasesPath = (repositoryPath, aliasesPath) => {
10086
+ if (!isAbsolute2(aliasesPath)) {
10087
+ const normalized = normalizeRepositoryPath(aliasesPath);
10088
+ return {
10089
+ repositoryRelativePath: normalized,
10090
+ displayPath: normalized,
10091
+ diskPath: resolve5(repositoryPath, normalized)
10092
+ };
10093
+ }
10094
+ const absolutePath = resolve5(aliasesPath);
10095
+ const relativePath = relative3(repositoryPath, absolutePath);
10096
+ const insideRepository = !relativePath.startsWith("..") && !isAbsolute2(relativePath);
10097
+ if (insideRepository) {
10098
+ const normalized = normalizeRepositoryPath(relativePath);
10077
10099
  return {
10078
- aliases: parsed.aliases,
10079
- ignoreAuthors: parsed.ignoreAuthors,
10080
- warnings: parsed.warnings
10100
+ repositoryRelativePath: normalized,
10101
+ displayPath: normalized,
10102
+ diskPath: absolutePath
10081
10103
  };
10082
10104
  }
10083
- const workingTreePath = resolve5(snapshot.repositoryPath, normalized);
10084
- if (existsSync4(workingTreePath)) {
10085
- const text = await readFile4(workingTreePath, "utf8");
10086
- const parsed = parseOwnersConfig(text);
10105
+ return {
10106
+ repositoryRelativePath: null,
10107
+ displayPath: absolutePath,
10108
+ diskPath: absolutePath
10109
+ };
10110
+ };
10111
+ var unreadableAliasesWarning = (displayPath, detail) => detail === void 0 ? `Identity aliases file "${displayPath}" could not be read: the audit ran without identity aliases.` : `Identity aliases file "${displayPath}" could not be read (${detail}): the audit ran without identity aliases.`;
10112
+ var readOwnersConfig = async (snapshot, aliasesPath, explicit) => {
10113
+ const resolved = resolveAliasesPath(snapshot.repositoryPath, aliasesPath);
10114
+ const normalized = resolved.repositoryRelativePath;
10115
+ if (normalized !== null && snapshot.trackedFiles.includes(normalized)) {
10116
+ const text2 = readTextAtRef(snapshot.repositoryPath, snapshot.ref, normalized);
10117
+ const parsed2 = parseOwnersConfig(text2);
10087
10118
  return {
10088
- aliases: parsed.aliases,
10089
- ignoreAuthors: parsed.ignoreAuthors,
10119
+ aliases: parsed2.aliases,
10120
+ ignoreAuthors: parsed2.ignoreAuthors,
10121
+ warnings: parsed2.warnings
10122
+ };
10123
+ }
10124
+ if (!existsSync4(resolved.diskPath)) {
10125
+ if (!explicit) {
10126
+ return { aliases: {}, ignoreAuthors: [], warnings: [] };
10127
+ }
10128
+ return {
10129
+ aliases: {},
10130
+ ignoreAuthors: [],
10131
+ warnings: [unreadableAliasesWarning(resolved.displayPath)]
10132
+ };
10133
+ }
10134
+ let text;
10135
+ try {
10136
+ text = await readFile4(resolved.diskPath, "utf8");
10137
+ } catch (error) {
10138
+ if (!explicit) {
10139
+ throw error;
10140
+ }
10141
+ return {
10142
+ aliases: {},
10143
+ ignoreAuthors: [],
10090
10144
  warnings: [
10091
- ...parsed.warnings,
10092
- `Identity aliases were read from the working tree because "${normalized}" is not tracked at "${snapshot.ref}".`
10145
+ unreadableAliasesWarning(
10146
+ resolved.displayPath,
10147
+ error instanceof Error ? error.message : "unknown error"
10148
+ )
10093
10149
  ]
10094
10150
  };
10095
10151
  }
10096
- return { aliases: {}, ignoreAuthors: [], warnings: [] };
10152
+ const parsed = parseOwnersConfig(text);
10153
+ const sourceWarning = normalized === null ? `Identity aliases were read from "${resolved.diskPath}", which is outside the audited repository and is not versioned with it.` : `Identity aliases were read from the working tree because "${normalized}" is not tracked at "${snapshot.ref}".`;
10154
+ return {
10155
+ aliases: parsed.aliases,
10156
+ ignoreAuthors: parsed.ignoreAuthors,
10157
+ warnings: [...parsed.warnings, sourceWarning]
10158
+ };
10097
10159
  };
10098
10160
  var collectFanInByPath = (projectPath, logger) => {
10099
10161
  try {
@@ -10141,7 +10203,8 @@ var buildOwnershipAudit = async (targetPath, options, logger) => {
10141
10203
  }
10142
10204
  const configSource = await readOwnersConfig(
10143
10205
  snapshot,
10144
- options.aliasesPath ?? DEFAULT_OWNERS_ALIASES_PATH
10206
+ options.aliasesPath ?? DEFAULT_OWNERS_ALIASES_PATH,
10207
+ options.aliasesPath !== void 0
10145
10208
  );
10146
10209
  const collected = collectOwnershipEvidence(snapshot, windowDays);
10147
10210
  logger.debug(
@@ -10357,7 +10420,7 @@ var runCiCommand = async (inputPath, authorIdentityMode, options, logger = creat
10357
10420
  repositoryPath: resolvedTargetPath,
10358
10421
  baselineRef,
10359
10422
  analyzeWorktree: async (worktreePath, repositoryRoot) => {
10360
- const relativeTargetPath = relative3(repositoryRoot, resolvedTargetPath);
10423
+ const relativeTargetPath = relative4(repositoryRoot, resolvedTargetPath);
10361
10424
  if (isPathOutsideBase(relativeTargetPath)) {
10362
10425
  throw new GovernanceConfigurationError(
10363
10426
  `target path is outside git repository root: ${resolvedTargetPath}`
@@ -11288,7 +11351,7 @@ var hasConfiguredThreshold = (thresholds) => thresholds.maxUnownedCritical !== n
11288
11351
  // src/application/run-path-command.ts
11289
11352
  import { existsSync as existsSync6, statSync as statSync3 } from "fs";
11290
11353
  import { readFile as readFile8, writeFile as writeFile8 } from "fs/promises";
11291
- import { isAbsolute as isAbsolute2, join as join12, relative as relative4, resolve as resolve9 } from "path";
11354
+ import { isAbsolute as isAbsolute3, join as join12, relative as relative5, resolve as resolve9 } from "path";
11292
11355
 
11293
11356
  // ../reading-path/dist/index.js
11294
11357
  var comparePaths = (a, b) => a < b ? -1 : a > b ? 1 : 0;
@@ -12203,13 +12266,13 @@ var PathConfigurationError = class extends Error {
12203
12266
  var DEFAULT_PATH_WINDOW_DAYS = DEFAULT_OWNERS_WINDOW_DAYS;
12204
12267
  var resolveRelativeTarget = (repositoryPath, target, invocationCwd) => {
12205
12268
  const absoluteTarget = resolve9(invocationCwd, target);
12206
- const relativeTarget = relative4(repositoryPath, absoluteTarget);
12269
+ const relativeTarget = relative5(repositoryPath, absoluteTarget);
12207
12270
  if (relativeTarget === "" || relativeTarget === ".") {
12208
12271
  throw new PathConfigurationError(
12209
12272
  `target "${target}" is the repository root; pass a module directory or a file.`
12210
12273
  );
12211
12274
  }
12212
- if (relativeTarget.startsWith("..") || isAbsolute2(relativeTarget)) {
12275
+ if (relativeTarget.startsWith("..") || isAbsolute3(relativeTarget)) {
12213
12276
  throw new PathConfigurationError(
12214
12277
  `target "${target}" is outside the repository at "${repositoryPath}".`
12215
12278
  );
@@ -13434,7 +13497,7 @@ var createAnalysisCache = (root, logger) => {
13434
13497
 
13435
13498
  // src/mcp/context.ts
13436
13499
  import { existsSync as existsSync7 } from "fs";
13437
- import { isAbsolute as isAbsolute3, relative as relative5, resolve as resolve12 } from "path";
13500
+ import { isAbsolute as isAbsolute4, relative as relative6, resolve as resolve12 } from "path";
13438
13501
 
13439
13502
  // src/mcp/errors.ts
13440
13503
  var McpToolError = class extends Error {
@@ -13487,10 +13550,10 @@ var toToolErrorResult = (error) => {
13487
13550
 
13488
13551
  // src/mcp/context.ts
13489
13552
  var resolveMcpRoot = (environment) => resolve12(environment["CODESENTINEL_ROOT"] ?? process.cwd());
13490
- var isOutsideRoot = (relativePath) => relativePath.startsWith("..") || isAbsolute3(relativePath);
13553
+ var isOutsideRoot = (relativePath) => relativePath.startsWith("..") || isAbsolute4(relativePath);
13491
13554
  var resolveRepositoryPath = (root, input) => {
13492
13555
  const absolutePath = resolve12(root, input);
13493
- const relativePath = relative5(root, absolutePath);
13556
+ const relativePath = relative6(root, absolutePath);
13494
13557
  if (relativePath === "" || isOutsideRoot(relativePath)) {
13495
13558
  throw new McpToolError(
13496
13559
  "path_outside_root",
@@ -13503,20 +13566,20 @@ var resolveRepositoryPath = (root, input) => {
13503
13566
  return normalizeRepositoryPath(relativePath);
13504
13567
  };
13505
13568
  var assertPathInsideRoot = (root, absolutePath) => {
13506
- const relativePath = relative5(root, absolutePath);
13569
+ const relativePath = relative6(root, absolutePath);
13507
13570
  if (isOutsideRoot(relativePath)) {
13508
13571
  throw new McpToolError(
13509
13572
  "path_outside_root",
13510
13573
  `path "${absolutePath}" is outside the repository root`
13511
13574
  );
13512
13575
  }
13513
- return normalizeRepositoryPath(relative5(root, absolutePath));
13576
+ return normalizeRepositoryPath(relative6(root, absolutePath));
13514
13577
  };
13515
13578
 
13516
13579
  // src/mcp/tools.ts
13517
13580
  import { spawn as spawn4 } from "child_process";
13518
13581
  import { mkdir as mkdir5, writeFile as writeFile12 } from "fs/promises";
13519
- import { isAbsolute as isAbsolute4, join as join15, resolve as resolve13 } from "path";
13582
+ import { isAbsolute as isAbsolute5, join as join15, resolve as resolve13 } from "path";
13520
13583
  import { z } from "zod";
13521
13584
 
13522
13585
  // src/mcp/shapes.ts
@@ -14106,7 +14169,7 @@ var runScan = async (context, input) => {
14106
14169
  });
14107
14170
  };
14108
14171
  var searchFindings = async (context, input) => {
14109
- if (input.path !== void 0 && isAbsolute4(input.path)) {
14172
+ if (input.path !== void 0 && isAbsolute5(input.path)) {
14110
14173
  throw new McpToolError("path_outside_root", `path "${input.path}" must be repository-relative`);
14111
14174
  }
14112
14175
  const pathPrefix = input.path === void 0 ? "" : normalizePathPrefix(input.path);
@@ -15140,7 +15203,10 @@ program.command("owners").alias("ownership").exitOverride().argument("[path]", "
15140
15203
  "--format <mode>",
15141
15204
  "output format: console (default), json (stable, sorted payload), md (pastes into a PR) or sarif (code scanning)"
15142
15205
  ).choices(["console", "json", "md", "sarif"]).default("console")
15143
- ).option("--output <file>", "write the rendered output to a file instead of stdout").option("--aliases <file>", "identity alias map", ".codesentinel/owners.json").addOption(
15206
+ ).option("--output <file>", "write the rendered output to a file instead of stdout").option(
15207
+ "--aliases <file>",
15208
+ "identity alias map, relative to the repository root or absolute (default: .codesentinel/owners.json)"
15209
+ ).addOption(
15144
15210
  new Option(
15145
15211
  "--ignore-author <glob>",
15146
15212
  "additional author glob to exclude from ownership evidence (repeatable; the defaults stay active)"
@@ -15171,7 +15237,7 @@ program.command("owners").alias("ownership").exitOverride().argument("[path]", "
15171
15237
  top,
15172
15238
  format: options.format,
15173
15239
  ...options.output === void 0 ? {} : { outputPath: options.output },
15174
- aliasesPath: options.aliases,
15240
+ ...options.aliases === void 0 ? {} : { aliasesPath: options.aliases },
15175
15241
  ...ignoreAuthors === void 0 ? {} : { ignoreAuthors },
15176
15242
  toolVersion: version,
15177
15243
  ...options.resolveGithub === true ? { resolveGithub: true } : {},