@getcodesentinel/codesentinel 1.29.0 → 1.31.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/dist/html-report-app/assets/index-BVFLpD3q.css +2 -0
- package/dist/html-report-app/assets/index-CzioVJuu.js +9 -0
- package/dist/html-report-app/index.html +2 -2
- package/dist/index.js +439 -35
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/html-report-app/assets/index-B_eG9xOn.css +0 -1
- package/dist/html-report-app/assets/index-CfyvK2On.js +0 -9
package/dist/index.js
CHANGED
|
@@ -2086,7 +2086,7 @@ var structuralModuleAnatomy = (snapshot) => {
|
|
|
2086
2086
|
};
|
|
2087
2087
|
var average = (values) => values.length === 0 ? null : round43(values.reduce((sum, value) => sum + value, 0) / values.length);
|
|
2088
2088
|
var toPercent = (value) => round43(value * 100);
|
|
2089
|
-
var
|
|
2089
|
+
var STALE_OWNED_FILE_DAYS = 180;
|
|
2090
2090
|
var MODULE_KNOWLEDGE_LABEL_PRIORITY = {
|
|
2091
2091
|
siloed: 0,
|
|
2092
2092
|
sparse: 1,
|
|
@@ -2174,11 +2174,11 @@ var ownershipPosture = (fileOwnership, moduleKnowledge, metrics) => {
|
|
|
2174
2174
|
).length;
|
|
2175
2175
|
const singleOwnerModulesPercent = moduleKnowledge.length === 0 ? null : round43(dominatedModules / moduleKnowledge.length * 100);
|
|
2176
2176
|
const concentratedOrSingle = (metrics.concentratedOwnershipPercent ?? 0) + (metrics.singleMaintainerPercent ?? 0);
|
|
2177
|
-
const
|
|
2177
|
+
const staleOwnedFilesPercent = metrics.staleOwnedFilesPercent ?? 0;
|
|
2178
2178
|
const singleMaintainerPercent = metrics.singleMaintainerPercent ?? 0;
|
|
2179
2179
|
let status = "balanced";
|
|
2180
|
-
if (
|
|
2181
|
-
status = "
|
|
2180
|
+
if (staleOwnedFilesPercent >= 25) {
|
|
2181
|
+
status = "stale";
|
|
2182
2182
|
} else if (singleMaintainerPercent >= 35 || (singleOwnerModulesPercent ?? 0) >= 35 || (largestContributorSharePercent ?? 0) >= 55) {
|
|
2183
2183
|
status = "siloed";
|
|
2184
2184
|
} else if (concentratedOrSingle >= 45 || (largestContributorSharePercent ?? 0) >= 30) {
|
|
@@ -2188,13 +2188,13 @@ var ownershipPosture = (fileOwnership, moduleKnowledge, metrics) => {
|
|
|
2188
2188
|
balanced: "Balanced Ownership",
|
|
2189
2189
|
concentrated: "Concentrated Ownership",
|
|
2190
2190
|
siloed: "Siloed Ownership",
|
|
2191
|
-
|
|
2191
|
+
stale: "Stale Ownership"
|
|
2192
2192
|
};
|
|
2193
2193
|
const summaryByStatus = {
|
|
2194
2194
|
balanced: `Knowledge is broadly distributed across the repository. ${metrics.sharedOwnershipPercent ?? 0}% of ownership-ready files are shared, with limited module concentration.`,
|
|
2195
2195
|
concentrated: `The repository still depends on a narrow set of contributors in key paths. ${round43(concentratedOrSingle)}% of ownership-ready files are concentrated or single-maintainer.`,
|
|
2196
2196
|
siloed: `Knowledge silos are material. Single-maintainer files or module dominance are high enough that handoff risk is no longer isolated.`,
|
|
2197
|
-
|
|
2197
|
+
stale: `A meaningful slice of owned files has gone cold. Stale ownership areas are large enough to distort the repo's operating posture.`
|
|
2198
2198
|
};
|
|
2199
2199
|
return {
|
|
2200
2200
|
status,
|
|
@@ -2286,8 +2286,8 @@ var changeOwnershipSummary = (snapshot) => {
|
|
|
2286
2286
|
(file) => file.authorDistributionByCommits.length <= 1
|
|
2287
2287
|
).length;
|
|
2288
2288
|
const headCommitTimestamp = evolution.metrics.headCommitTimestamp;
|
|
2289
|
-
const
|
|
2290
|
-
(file) => file.commitCount > 0 && file.lastCommitTimestamp !== null && headCommitTimestamp !== null && headCommitTimestamp - file.lastCommitTimestamp >=
|
|
2289
|
+
const staleOwnedFilesCount = ownershipReadyFiles.filter(
|
|
2290
|
+
(file) => file.commitCount > 0 && file.lastCommitTimestamp !== null && headCommitTimestamp !== null && headCommitTimestamp - file.lastCommitTimestamp >= STALE_OWNED_FILE_DAYS * 86400
|
|
2291
2291
|
).length;
|
|
2292
2292
|
const ownershipDivisor = ownershipReadyFiles.length || 0;
|
|
2293
2293
|
const metrics = {
|
|
@@ -2301,7 +2301,7 @@ var changeOwnershipSummary = (snapshot) => {
|
|
|
2301
2301
|
sharedOwnershipPercent: ownershipDivisor === 0 ? null : round43(sharedOwnershipCount / ownershipDivisor * 100),
|
|
2302
2302
|
concentratedOwnershipPercent: ownershipDivisor === 0 ? null : round43(concentratedOwnershipCount / ownershipDivisor * 100),
|
|
2303
2303
|
singleMaintainerPercent: ownershipDivisor === 0 ? null : round43(singleMaintainerCount / ownershipDivisor * 100),
|
|
2304
|
-
|
|
2304
|
+
staleOwnedFilesPercent: ownershipDivisor === 0 ? null : round43(staleOwnedFilesCount / ownershipDivisor * 100)
|
|
2305
2305
|
};
|
|
2306
2306
|
const fileOwnership = fileOwnershipItems(files);
|
|
2307
2307
|
const allModuleKnowledge = moduleKnowledgeItems(files);
|
|
@@ -3336,7 +3336,7 @@ var resolveAutoBaselineRef = async (input) => {
|
|
|
3336
3336
|
};
|
|
3337
3337
|
|
|
3338
3338
|
// src/index.ts
|
|
3339
|
-
import { readFileSync as
|
|
3339
|
+
import { readFileSync as readFileSync3 } from "fs";
|
|
3340
3340
|
import { readFile as readFile7, writeFile as writeFile7 } from "fs/promises";
|
|
3341
3341
|
import { dirname as dirname3, resolve as resolve6 } from "path";
|
|
3342
3342
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
@@ -4426,8 +4426,11 @@ ${PROMPT_PADDING}Command exited with code ${exitCode}.
|
|
|
4426
4426
|
import { resolve as resolve3 } from "path";
|
|
4427
4427
|
|
|
4428
4428
|
// ../code-graph/dist/index.js
|
|
4429
|
-
import {
|
|
4429
|
+
import { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
|
|
4430
|
+
import { extname, isAbsolute, join as join7, relative, resolve as resolve2 } from "path";
|
|
4430
4431
|
import * as ts from "typescript";
|
|
4432
|
+
import { existsSync as existsSync22, readdirSync, readFileSync as readFileSync22, statSync } from "fs";
|
|
4433
|
+
import { basename as basename3, join as join22, relative as relative2, resolve as resolve22 } from "path";
|
|
4431
4434
|
var edgeKey = (from, to) => `${from}\0${to}`;
|
|
4432
4435
|
var createGraphData = (nodes, rawEdges) => {
|
|
4433
4436
|
const sortedNodes = [...nodes].sort((a, b) => a.id.localeCompare(b.id));
|
|
@@ -4622,7 +4625,103 @@ var computeCyclesAndDepth = (graph) => {
|
|
|
4622
4625
|
cycles
|
|
4623
4626
|
};
|
|
4624
4627
|
};
|
|
4625
|
-
var
|
|
4628
|
+
var findWorkspaceForFile = (filePath, workspaces) => {
|
|
4629
|
+
let match = null;
|
|
4630
|
+
for (const workspace of workspaces) {
|
|
4631
|
+
if (filePath === workspace.path || filePath.startsWith(`${workspace.path}/`)) {
|
|
4632
|
+
if (match === null || workspace.path.length > match.path.length) {
|
|
4633
|
+
match = workspace;
|
|
4634
|
+
}
|
|
4635
|
+
}
|
|
4636
|
+
}
|
|
4637
|
+
return match;
|
|
4638
|
+
};
|
|
4639
|
+
var createWorkspaceByFile = (graph, workspaces) => {
|
|
4640
|
+
const workspaceByFile = /* @__PURE__ */ new Map();
|
|
4641
|
+
for (const node of graph.nodes) {
|
|
4642
|
+
const workspace = findWorkspaceForFile(node.id, workspaces);
|
|
4643
|
+
if (workspace !== null) {
|
|
4644
|
+
workspaceByFile.set(node.id, workspace);
|
|
4645
|
+
}
|
|
4646
|
+
}
|
|
4647
|
+
return workspaceByFile;
|
|
4648
|
+
};
|
|
4649
|
+
var createCrossWorkspaceEdges = (graph, workspaceByFile) => {
|
|
4650
|
+
const edges = [];
|
|
4651
|
+
for (const edge of graph.edges) {
|
|
4652
|
+
const fromWorkspace = workspaceByFile.get(edge.from);
|
|
4653
|
+
const toWorkspace = workspaceByFile.get(edge.to);
|
|
4654
|
+
if (fromWorkspace === void 0 || toWorkspace === void 0 || fromWorkspace.path === toWorkspace.path) {
|
|
4655
|
+
continue;
|
|
4656
|
+
}
|
|
4657
|
+
edges.push({
|
|
4658
|
+
fromWorkspace: fromWorkspace.path,
|
|
4659
|
+
toWorkspace: toWorkspace.path,
|
|
4660
|
+
from: edge.from,
|
|
4661
|
+
to: edge.to
|
|
4662
|
+
});
|
|
4663
|
+
}
|
|
4664
|
+
return edges;
|
|
4665
|
+
};
|
|
4666
|
+
var createWorkspaceSummaries = (graph, workspaces, workspaceByFile) => {
|
|
4667
|
+
if (workspaces.length === 0) {
|
|
4668
|
+
return [];
|
|
4669
|
+
}
|
|
4670
|
+
const fileCountByWorkspacePath = /* @__PURE__ */ new Map();
|
|
4671
|
+
const internalEdgesByWorkspacePath = /* @__PURE__ */ new Map();
|
|
4672
|
+
const incomingEdgesByWorkspacePath = /* @__PURE__ */ new Map();
|
|
4673
|
+
const outgoingEdgesByWorkspacePath = /* @__PURE__ */ new Map();
|
|
4674
|
+
for (const workspace of workspaces) {
|
|
4675
|
+
fileCountByWorkspacePath.set(workspace.path, 0);
|
|
4676
|
+
internalEdgesByWorkspacePath.set(workspace.path, 0);
|
|
4677
|
+
incomingEdgesByWorkspacePath.set(workspace.path, 0);
|
|
4678
|
+
outgoingEdgesByWorkspacePath.set(workspace.path, 0);
|
|
4679
|
+
}
|
|
4680
|
+
for (const node of graph.nodes) {
|
|
4681
|
+
const workspace = workspaceByFile.get(node.id);
|
|
4682
|
+
if (workspace === void 0) {
|
|
4683
|
+
continue;
|
|
4684
|
+
}
|
|
4685
|
+
fileCountByWorkspacePath.set(
|
|
4686
|
+
workspace.path,
|
|
4687
|
+
(fileCountByWorkspacePath.get(workspace.path) ?? 0) + 1
|
|
4688
|
+
);
|
|
4689
|
+
}
|
|
4690
|
+
for (const edge of graph.edges) {
|
|
4691
|
+
const fromWorkspace = workspaceByFile.get(edge.from) ?? null;
|
|
4692
|
+
const toWorkspace = workspaceByFile.get(edge.to) ?? null;
|
|
4693
|
+
if (fromWorkspace === null && toWorkspace === null) {
|
|
4694
|
+
continue;
|
|
4695
|
+
}
|
|
4696
|
+
if (fromWorkspace?.path === toWorkspace?.path && fromWorkspace !== null) {
|
|
4697
|
+
internalEdgesByWorkspacePath.set(
|
|
4698
|
+
fromWorkspace.path,
|
|
4699
|
+
(internalEdgesByWorkspacePath.get(fromWorkspace.path) ?? 0) + 1
|
|
4700
|
+
);
|
|
4701
|
+
continue;
|
|
4702
|
+
}
|
|
4703
|
+
if (fromWorkspace !== null) {
|
|
4704
|
+
outgoingEdgesByWorkspacePath.set(
|
|
4705
|
+
fromWorkspace.path,
|
|
4706
|
+
(outgoingEdgesByWorkspacePath.get(fromWorkspace.path) ?? 0) + 1
|
|
4707
|
+
);
|
|
4708
|
+
}
|
|
4709
|
+
if (toWorkspace !== null) {
|
|
4710
|
+
incomingEdgesByWorkspacePath.set(
|
|
4711
|
+
toWorkspace.path,
|
|
4712
|
+
(incomingEdgesByWorkspacePath.get(toWorkspace.path) ?? 0) + 1
|
|
4713
|
+
);
|
|
4714
|
+
}
|
|
4715
|
+
}
|
|
4716
|
+
return workspaces.map((workspace) => ({
|
|
4717
|
+
...workspace,
|
|
4718
|
+
fileCount: fileCountByWorkspacePath.get(workspace.path) ?? 0,
|
|
4719
|
+
internalEdgeCount: internalEdgesByWorkspacePath.get(workspace.path) ?? 0,
|
|
4720
|
+
incomingEdgeCount: incomingEdgesByWorkspacePath.get(workspace.path) ?? 0,
|
|
4721
|
+
outgoingEdgeCount: outgoingEdgesByWorkspacePath.get(workspace.path) ?? 0
|
|
4722
|
+
}));
|
|
4723
|
+
};
|
|
4724
|
+
var createGraphAnalysisSummary = (targetPath, graph, workspaces = []) => {
|
|
4626
4725
|
const fanInById = /* @__PURE__ */ new Map();
|
|
4627
4726
|
const fanOutById = /* @__PURE__ */ new Map();
|
|
4628
4727
|
for (const node of graph.nodes) {
|
|
@@ -4661,13 +4760,18 @@ var createGraphAnalysisSummary = (targetPath, graph) => {
|
|
|
4661
4760
|
maxFanIn,
|
|
4662
4761
|
maxFanOut
|
|
4663
4762
|
};
|
|
4763
|
+
const workspaceByFile = createWorkspaceByFile(graph, workspaces);
|
|
4664
4764
|
return {
|
|
4665
4765
|
targetPath,
|
|
4666
4766
|
nodes: graph.nodes,
|
|
4667
4767
|
edges: graph.edges,
|
|
4668
4768
|
cycles,
|
|
4669
4769
|
files,
|
|
4670
|
-
metrics
|
|
4770
|
+
metrics,
|
|
4771
|
+
...workspaces.length === 0 ? {} : {
|
|
4772
|
+
workspaces: createWorkspaceSummaries(graph, workspaces, workspaceByFile),
|
|
4773
|
+
crossWorkspaceEdges: createCrossWorkspaceEdges(graph, workspaceByFile)
|
|
4774
|
+
}
|
|
4671
4775
|
};
|
|
4672
4776
|
};
|
|
4673
4777
|
var SOURCE_EXTENSIONS = /* @__PURE__ */ new Set([".ts", ".tsx", ".mts", ".cts", ".js", ".jsx", ".mjs", ".cjs"]);
|
|
@@ -4695,6 +4799,13 @@ var IGNORED_SEGMENTS = /* @__PURE__ */ new Set([
|
|
|
4695
4799
|
"out"
|
|
4696
4800
|
]);
|
|
4697
4801
|
var normalizePath = (pathValue) => pathValue.replaceAll("\\", "/");
|
|
4802
|
+
var readPackageJson = (packageJsonPath2) => {
|
|
4803
|
+
try {
|
|
4804
|
+
return JSON.parse(readFileSync2(packageJsonPath2, "utf8"));
|
|
4805
|
+
} catch {
|
|
4806
|
+
return null;
|
|
4807
|
+
}
|
|
4808
|
+
};
|
|
4698
4809
|
var isProjectSourceFile = (filePath, projectRoot) => {
|
|
4699
4810
|
const extension = extname(filePath);
|
|
4700
4811
|
if (!SOURCE_EXTENSIONS.has(extension)) {
|
|
@@ -4887,7 +4998,159 @@ var extractModuleSpecifiers = (sourceFile) => {
|
|
|
4887
4998
|
visit(sourceFile);
|
|
4888
4999
|
return [...specifiers];
|
|
4889
5000
|
};
|
|
4890
|
-
var
|
|
5001
|
+
var parseWorkspaceSpecifier = (specifier, workspaceNames) => {
|
|
5002
|
+
const parts = specifier.split("/");
|
|
5003
|
+
const packageName = specifier.startsWith("@") ? parts.slice(0, 2).join("/") : parts[0] ?? "";
|
|
5004
|
+
if (!workspaceNames.has(packageName)) {
|
|
5005
|
+
return null;
|
|
5006
|
+
}
|
|
5007
|
+
const subpath = specifier.slice(packageName.length).replace(/^\//, "");
|
|
5008
|
+
return {
|
|
5009
|
+
packageName,
|
|
5010
|
+
subpath: subpath.length === 0 ? null : subpath
|
|
5011
|
+
};
|
|
5012
|
+
};
|
|
5013
|
+
var expandFileCandidates = (pathWithoutExtension) => [
|
|
5014
|
+
pathWithoutExtension,
|
|
5015
|
+
...[...SOURCE_EXTENSIONS].map((extension) => `${pathWithoutExtension}${extension}`),
|
|
5016
|
+
...[...SOURCE_EXTENSIONS].map((extension) => join7(pathWithoutExtension, `index${extension}`))
|
|
5017
|
+
];
|
|
5018
|
+
var isExportArray = (value) => Array.isArray(value);
|
|
5019
|
+
var isExportMap = (value) => typeof value !== "string" && !isExportArray(value);
|
|
5020
|
+
var collectExportTargetCandidates = (value) => {
|
|
5021
|
+
if (value === void 0) {
|
|
5022
|
+
return [];
|
|
5023
|
+
}
|
|
5024
|
+
if (typeof value === "string") {
|
|
5025
|
+
return [value];
|
|
5026
|
+
}
|
|
5027
|
+
if (isExportArray(value)) {
|
|
5028
|
+
return value.flatMap((entry) => collectExportTargetCandidates(entry));
|
|
5029
|
+
}
|
|
5030
|
+
if (!isExportMap(value)) {
|
|
5031
|
+
return [];
|
|
5032
|
+
}
|
|
5033
|
+
const candidates = [];
|
|
5034
|
+
for (const key of ["source", "types", "typings", "import", "module", "require", "default"]) {
|
|
5035
|
+
candidates.push(...collectExportTargetCandidates(value[key]));
|
|
5036
|
+
}
|
|
5037
|
+
return candidates;
|
|
5038
|
+
};
|
|
5039
|
+
var collectPackageExportCandidates = (packageJson, subpath) => {
|
|
5040
|
+
const exportsValue = packageJson?.exports;
|
|
5041
|
+
if (exportsValue === void 0) {
|
|
5042
|
+
return [];
|
|
5043
|
+
}
|
|
5044
|
+
if (subpath === null) {
|
|
5045
|
+
if (typeof exportsValue === "string" || isExportArray(exportsValue)) {
|
|
5046
|
+
return collectExportTargetCandidates(exportsValue);
|
|
5047
|
+
}
|
|
5048
|
+
return collectExportTargetCandidates(exportsValue["."]);
|
|
5049
|
+
}
|
|
5050
|
+
if (typeof exportsValue === "string" || isExportArray(exportsValue)) {
|
|
5051
|
+
return [];
|
|
5052
|
+
}
|
|
5053
|
+
const exportKey = `./${subpath}`;
|
|
5054
|
+
const exactCandidates = collectExportTargetCandidates(exportsValue[exportKey]);
|
|
5055
|
+
if (exactCandidates.length > 0) {
|
|
5056
|
+
return exactCandidates;
|
|
5057
|
+
}
|
|
5058
|
+
const wildcardCandidates = [];
|
|
5059
|
+
for (const [key, value] of Object.entries(exportsValue)) {
|
|
5060
|
+
if (!key.includes("*")) {
|
|
5061
|
+
continue;
|
|
5062
|
+
}
|
|
5063
|
+
const [prefix = "", suffix = ""] = key.split("*");
|
|
5064
|
+
if (!exportKey.startsWith(prefix) || !exportKey.endsWith(suffix)) {
|
|
5065
|
+
continue;
|
|
5066
|
+
}
|
|
5067
|
+
const replacement = exportKey.slice(prefix.length, exportKey.length - suffix.length);
|
|
5068
|
+
for (const candidate of collectExportTargetCandidates(value)) {
|
|
5069
|
+
wildcardCandidates.push(candidate.replaceAll("*", replacement));
|
|
5070
|
+
}
|
|
5071
|
+
}
|
|
5072
|
+
return wildcardCandidates;
|
|
5073
|
+
};
|
|
5074
|
+
var resolveFirstAnalyzedCandidate = (candidates, sourceFilePathSet) => {
|
|
5075
|
+
for (const candidate of candidates) {
|
|
5076
|
+
for (const expanded of expandFileCandidates(candidate)) {
|
|
5077
|
+
const normalized = normalizePath(expanded);
|
|
5078
|
+
if (sourceFilePathSet.has(normalized) && existsSync2(normalized)) {
|
|
5079
|
+
return normalized;
|
|
5080
|
+
}
|
|
5081
|
+
}
|
|
5082
|
+
}
|
|
5083
|
+
return void 0;
|
|
5084
|
+
};
|
|
5085
|
+
var createWorkspaceResolver = (projectRoot, workspaces, sourceFilePathSet) => {
|
|
5086
|
+
const workspaceByName = new Map(workspaces.map((workspace) => [workspace.name, workspace]));
|
|
5087
|
+
const workspaceNames = new Set(workspaceByName.keys());
|
|
5088
|
+
return (specifier) => {
|
|
5089
|
+
const parsed = parseWorkspaceSpecifier(specifier, workspaceNames);
|
|
5090
|
+
if (parsed === null) {
|
|
5091
|
+
return void 0;
|
|
5092
|
+
}
|
|
5093
|
+
const workspace = workspaceByName.get(parsed.packageName);
|
|
5094
|
+
if (workspace === void 0) {
|
|
5095
|
+
return void 0;
|
|
5096
|
+
}
|
|
5097
|
+
const workspaceRoot = resolve2(projectRoot, workspace.path);
|
|
5098
|
+
const packageJson = readPackageJson(join7(workspaceRoot, "package.json"));
|
|
5099
|
+
const candidates = parsed.subpath === null ? [
|
|
5100
|
+
...collectPackageExportCandidates(packageJson, null),
|
|
5101
|
+
packageJson?.source,
|
|
5102
|
+
packageJson?.types,
|
|
5103
|
+
packageJson?.typings,
|
|
5104
|
+
packageJson?.module,
|
|
5105
|
+
packageJson?.main,
|
|
5106
|
+
"src/index",
|
|
5107
|
+
"index"
|
|
5108
|
+
].filter((candidate) => candidate !== void 0) : [
|
|
5109
|
+
...collectPackageExportCandidates(packageJson, parsed.subpath),
|
|
5110
|
+
parsed.subpath,
|
|
5111
|
+
join7("src", parsed.subpath)
|
|
5112
|
+
];
|
|
5113
|
+
return resolveFirstAnalyzedCandidate(
|
|
5114
|
+
candidates.map((candidate) => resolve2(workspaceRoot, candidate)),
|
|
5115
|
+
sourceFilePathSet
|
|
5116
|
+
);
|
|
5117
|
+
};
|
|
5118
|
+
};
|
|
5119
|
+
var createTsPathAliasResolver = (projectRoot, options, sourceFilePathSet) => {
|
|
5120
|
+
const paths = options.paths;
|
|
5121
|
+
if (paths === void 0) {
|
|
5122
|
+
return () => void 0;
|
|
5123
|
+
}
|
|
5124
|
+
const baseUrl = options.baseUrl === void 0 ? projectRoot : options.baseUrl;
|
|
5125
|
+
const pathEntries = Object.entries(paths).sort(([left], [right]) => {
|
|
5126
|
+
const leftPrefix = left.split("*")[0]?.length ?? left.length;
|
|
5127
|
+
const rightPrefix = right.split("*")[0]?.length ?? right.length;
|
|
5128
|
+
return rightPrefix - leftPrefix || left.localeCompare(right);
|
|
5129
|
+
});
|
|
5130
|
+
return (specifier) => {
|
|
5131
|
+
for (const [pattern, substitutions] of pathEntries) {
|
|
5132
|
+
const [prefix = "", suffix = ""] = pattern.split("*");
|
|
5133
|
+
const hasWildcard = pattern.includes("*");
|
|
5134
|
+
if (hasWildcard) {
|
|
5135
|
+
if (!specifier.startsWith(prefix) || !specifier.endsWith(suffix)) {
|
|
5136
|
+
continue;
|
|
5137
|
+
}
|
|
5138
|
+
} else if (specifier !== pattern) {
|
|
5139
|
+
continue;
|
|
5140
|
+
}
|
|
5141
|
+
const replacement = hasWildcard ? specifier.slice(prefix.length, specifier.length - suffix.length) : "";
|
|
5142
|
+
const candidates = substitutions.map(
|
|
5143
|
+
(substitution) => resolve2(baseUrl, hasWildcard ? substitution.replaceAll("*", replacement) : substitution)
|
|
5144
|
+
);
|
|
5145
|
+
const resolved = resolveFirstAnalyzedCandidate(candidates, sourceFilePathSet);
|
|
5146
|
+
if (resolved !== void 0) {
|
|
5147
|
+
return resolved;
|
|
5148
|
+
}
|
|
5149
|
+
}
|
|
5150
|
+
return void 0;
|
|
5151
|
+
};
|
|
5152
|
+
};
|
|
5153
|
+
var parseTypescriptProject = (projectPath, onProgress, workspaces = []) => {
|
|
4891
5154
|
const projectRoot = isAbsolute(projectPath) ? projectPath : resolve2(projectPath);
|
|
4892
5155
|
const { fileNames, options, tsconfigCount, usedFallbackScan } = parseTsConfig(projectRoot);
|
|
4893
5156
|
onProgress?.({ stage: "config_resolved", tsconfigCount, usedFallbackScan });
|
|
@@ -4911,6 +5174,12 @@ var parseTypescriptProject = (projectPath, onProgress) => {
|
|
|
4911
5174
|
});
|
|
4912
5175
|
}
|
|
4913
5176
|
const resolverCache = /* @__PURE__ */ new Map();
|
|
5177
|
+
const resolveWorkspaceSpecifier = createWorkspaceResolver(
|
|
5178
|
+
projectRoot,
|
|
5179
|
+
workspaces,
|
|
5180
|
+
sourceFilePathSet
|
|
5181
|
+
);
|
|
5182
|
+
const resolveTsPathAlias = createTsPathAliasResolver(projectRoot, options, sourceFilePathSet);
|
|
4914
5183
|
const edges = [];
|
|
4915
5184
|
for (const [index, sourcePath] of uniqueSourceFilePaths.entries()) {
|
|
4916
5185
|
const sourceFile = program2.getSourceFile(sourcePath);
|
|
@@ -4935,6 +5204,12 @@ var parseTypescriptProject = (projectPath, onProgress) => {
|
|
|
4935
5204
|
if (resolved !== void 0) {
|
|
4936
5205
|
resolvedPath = normalizePath(resolve2(resolved.resolvedFileName));
|
|
4937
5206
|
}
|
|
5207
|
+
if (resolvedPath === void 0 || !sourceFilePathSet.has(resolvedPath)) {
|
|
5208
|
+
resolvedPath = resolveTsPathAlias(specifier);
|
|
5209
|
+
}
|
|
5210
|
+
if (resolvedPath === void 0 || !sourceFilePathSet.has(resolvedPath)) {
|
|
5211
|
+
resolvedPath = resolveWorkspaceSpecifier(specifier);
|
|
5212
|
+
}
|
|
4938
5213
|
resolverCache.set(cacheKey, resolvedPath);
|
|
4939
5214
|
}
|
|
4940
5215
|
if (resolvedPath === void 0 || !sourceFilePathSet.has(resolvedPath)) {
|
|
@@ -4962,10 +5237,139 @@ var parseTypescriptProject = (projectPath, onProgress) => {
|
|
|
4962
5237
|
edges
|
|
4963
5238
|
};
|
|
4964
5239
|
};
|
|
5240
|
+
var normalizePath2 = (pathValue) => pathValue.replaceAll("\\", "/");
|
|
5241
|
+
var stripQuotes2 = (value) => value.replace(/^['"]|['"]$/g, "");
|
|
5242
|
+
var readPackageJson2 = (path) => {
|
|
5243
|
+
try {
|
|
5244
|
+
return JSON.parse(readFileSync22(path, "utf8"));
|
|
5245
|
+
} catch {
|
|
5246
|
+
return null;
|
|
5247
|
+
}
|
|
5248
|
+
};
|
|
5249
|
+
var inferWorkspaceKind = (workspacePath) => {
|
|
5250
|
+
const segments = workspacePath.split("/");
|
|
5251
|
+
const first = segments[0] ?? "";
|
|
5252
|
+
if (first === "apps" || first === "app") {
|
|
5253
|
+
return "app";
|
|
5254
|
+
}
|
|
5255
|
+
if (first === "packages" || first === "package") {
|
|
5256
|
+
return "package";
|
|
5257
|
+
}
|
|
5258
|
+
if (first === "docs" || first === "documentation") {
|
|
5259
|
+
return "docs";
|
|
5260
|
+
}
|
|
5261
|
+
if (first === "examples" || first === "example-apps" || first === "playground") {
|
|
5262
|
+
return "example";
|
|
5263
|
+
}
|
|
5264
|
+
if (first === "tooling" || first === "tools") {
|
|
5265
|
+
return "tooling";
|
|
5266
|
+
}
|
|
5267
|
+
return "unknown";
|
|
5268
|
+
};
|
|
5269
|
+
var readWorkspacePatternsFromPackageJson = (projectRoot) => {
|
|
5270
|
+
const packageJson = readPackageJson2(join22(projectRoot, "package.json"));
|
|
5271
|
+
if (packageJson?.workspaces === void 0) {
|
|
5272
|
+
return [];
|
|
5273
|
+
}
|
|
5274
|
+
const workspaces = packageJson.workspaces;
|
|
5275
|
+
if (Array.isArray(workspaces)) {
|
|
5276
|
+
const workspaceArray = workspaces;
|
|
5277
|
+
return workspaceArray.filter((workspace) => typeof workspace === "string");
|
|
5278
|
+
}
|
|
5279
|
+
const workspaceObject = workspaces;
|
|
5280
|
+
return workspaceObject.packages ?? [];
|
|
5281
|
+
};
|
|
5282
|
+
var readWorkspacePatternsFromPnpmWorkspace = (projectRoot) => {
|
|
5283
|
+
const workspacePath = join22(projectRoot, "pnpm-workspace.yaml");
|
|
5284
|
+
if (!existsSync22(workspacePath)) {
|
|
5285
|
+
return [];
|
|
5286
|
+
}
|
|
5287
|
+
const patterns = [];
|
|
5288
|
+
const lines = readFileSync22(workspacePath, "utf8").split("\n");
|
|
5289
|
+
let readingPackages = false;
|
|
5290
|
+
for (const line of lines) {
|
|
5291
|
+
const trimmed = line.trim();
|
|
5292
|
+
if (trimmed.length === 0 || trimmed.startsWith("#")) {
|
|
5293
|
+
continue;
|
|
5294
|
+
}
|
|
5295
|
+
if (!line.startsWith(" ") && !line.startsWith("-")) {
|
|
5296
|
+
readingPackages = trimmed === "packages:";
|
|
5297
|
+
continue;
|
|
5298
|
+
}
|
|
5299
|
+
if (!readingPackages) {
|
|
5300
|
+
continue;
|
|
5301
|
+
}
|
|
5302
|
+
const match = trimmed.match(/^-\s+(.+)$/);
|
|
5303
|
+
if (match?.[1] !== void 0) {
|
|
5304
|
+
patterns.push(stripQuotes2(match[1].trim()));
|
|
5305
|
+
}
|
|
5306
|
+
}
|
|
5307
|
+
return patterns;
|
|
5308
|
+
};
|
|
5309
|
+
var expandPattern = (projectRoot, pattern) => {
|
|
5310
|
+
const segments = normalizePath2(pattern).split("/").filter((segment) => segment.length > 0);
|
|
5311
|
+
let current = [projectRoot];
|
|
5312
|
+
for (const segment of segments) {
|
|
5313
|
+
const next = [];
|
|
5314
|
+
if (segment === "*") {
|
|
5315
|
+
for (const directory of current) {
|
|
5316
|
+
if (!existsSync22(directory)) {
|
|
5317
|
+
continue;
|
|
5318
|
+
}
|
|
5319
|
+
for (const entry of readdirSync(directory, { withFileTypes: true })) {
|
|
5320
|
+
if (entry.isDirectory()) {
|
|
5321
|
+
next.push(join22(directory, entry.name));
|
|
5322
|
+
}
|
|
5323
|
+
}
|
|
5324
|
+
}
|
|
5325
|
+
} else {
|
|
5326
|
+
for (const directory of current) {
|
|
5327
|
+
const candidate = join22(directory, segment);
|
|
5328
|
+
if (existsSync22(candidate) && statSync(candidate).isDirectory()) {
|
|
5329
|
+
next.push(candidate);
|
|
5330
|
+
}
|
|
5331
|
+
}
|
|
5332
|
+
}
|
|
5333
|
+
current = next;
|
|
5334
|
+
}
|
|
5335
|
+
return current;
|
|
5336
|
+
};
|
|
5337
|
+
var discoverWorkspacePackages = (projectRoot) => {
|
|
5338
|
+
const absoluteRoot = resolve22(projectRoot);
|
|
5339
|
+
const packageJsonPatterns = readWorkspacePatternsFromPackageJson(absoluteRoot);
|
|
5340
|
+
const pnpmPatterns = readWorkspacePatternsFromPnpmWorkspace(absoluteRoot);
|
|
5341
|
+
const patterns = packageJsonPatterns.length > 0 ? packageJsonPatterns : pnpmPatterns;
|
|
5342
|
+
const includePatterns = patterns.filter((pattern) => !pattern.startsWith("!"));
|
|
5343
|
+
const excludePatterns = patterns.filter((pattern) => pattern.startsWith("!")).map((pattern) => pattern.slice(1));
|
|
5344
|
+
const excludedPaths = new Set(
|
|
5345
|
+
excludePatterns.flatMap((pattern) => expandPattern(absoluteRoot, pattern)).map((path) => normalizePath2(relative2(absoluteRoot, path)))
|
|
5346
|
+
);
|
|
5347
|
+
const packagesByPath = /* @__PURE__ */ new Map();
|
|
5348
|
+
for (const pattern of includePatterns) {
|
|
5349
|
+
for (const absoluteWorkspacePath of expandPattern(absoluteRoot, pattern)) {
|
|
5350
|
+
const relativePath = normalizePath2(relative2(absoluteRoot, absoluteWorkspacePath));
|
|
5351
|
+
if (relativePath.length === 0 || relativePath.startsWith("..") || excludedPaths.has(relativePath)) {
|
|
5352
|
+
continue;
|
|
5353
|
+
}
|
|
5354
|
+
const packageJsonPath2 = join22(absoluteWorkspacePath, "package.json");
|
|
5355
|
+
if (!existsSync22(packageJsonPath2)) {
|
|
5356
|
+
continue;
|
|
5357
|
+
}
|
|
5358
|
+
const packageJson = readPackageJson2(packageJsonPath2);
|
|
5359
|
+
packagesByPath.set(relativePath, {
|
|
5360
|
+
name: packageJson?.name ?? basename3(absoluteWorkspacePath),
|
|
5361
|
+
path: relativePath,
|
|
5362
|
+
kind: inferWorkspaceKind(relativePath)
|
|
5363
|
+
});
|
|
5364
|
+
}
|
|
5365
|
+
}
|
|
5366
|
+
return [...packagesByPath.values()].sort((a, b) => a.path.localeCompare(b.path));
|
|
5367
|
+
};
|
|
4965
5368
|
var buildProjectGraphSummary = (input) => {
|
|
4966
|
-
const
|
|
5369
|
+
const workspaces = discoverWorkspacePackages(input.projectPath);
|
|
5370
|
+
const parsedProject = parseTypescriptProject(input.projectPath, input.onProgress, workspaces);
|
|
4967
5371
|
const graphData = createGraphData(parsedProject.nodes, parsedProject.edges);
|
|
4968
|
-
return createGraphAnalysisSummary(input.projectPath, graphData);
|
|
5372
|
+
return createGraphAnalysisSummary(input.projectPath, graphData, workspaces);
|
|
4969
5373
|
};
|
|
4970
5374
|
|
|
4971
5375
|
// ../git-analyzer/dist/index.js
|
|
@@ -5666,9 +6070,9 @@ var createDimensionTrace = (dimension, health, factors) => ({
|
|
|
5666
6070
|
factors: factors.map((factor) => toFactorTrace(factor))
|
|
5667
6071
|
});
|
|
5668
6072
|
var filePaths = (structural) => structural.files.map((file) => file.relativePath);
|
|
5669
|
-
var
|
|
6073
|
+
var normalizePath3 = (value) => value.replaceAll("\\", "/").toLowerCase();
|
|
5670
6074
|
var isTestPath = (path) => {
|
|
5671
|
-
const normalized =
|
|
6075
|
+
const normalized = normalizePath3(path);
|
|
5672
6076
|
return normalized.includes("/__tests__/") || normalized.includes("/tests/") || normalized.includes("/test/") || normalized.includes(".test.") || normalized.includes(".spec.");
|
|
5673
6077
|
};
|
|
5674
6078
|
var isSourcePath = (path) => {
|
|
@@ -5678,7 +6082,7 @@ var isSourcePath = (path) => {
|
|
|
5678
6082
|
return !isTestPath(path);
|
|
5679
6083
|
};
|
|
5680
6084
|
var hasTestDirectory = (paths) => paths.some((path) => {
|
|
5681
|
-
const normalized =
|
|
6085
|
+
const normalized = normalizePath3(path);
|
|
5682
6086
|
return normalized.includes("/__tests__/") || normalized.includes("/tests/") || normalized.includes("/test/");
|
|
5683
6087
|
});
|
|
5684
6088
|
var moduleNameFromPath = (path) => {
|
|
@@ -6568,7 +6972,7 @@ var normalizeWithScale = (value, scale) => {
|
|
|
6568
6972
|
}
|
|
6569
6973
|
return toUnitInterval((value - scale.lower) / (scale.upper - scale.lower));
|
|
6570
6974
|
};
|
|
6571
|
-
var
|
|
6975
|
+
var normalizePath4 = (path) => path.replaceAll("\\", "/");
|
|
6572
6976
|
var computeAggregatorAttenuation = (input) => {
|
|
6573
6977
|
const { fanIn, fanOut, inCycle, evolutionMetrics, config } = input;
|
|
6574
6978
|
if (!config.enabled || inCycle > 0) {
|
|
@@ -6643,7 +7047,7 @@ var computeEvolutionHistoryConfidence = (structural, evolution, evolutionByFile)
|
|
|
6643
7047
|
}
|
|
6644
7048
|
let coveredFiles = 0;
|
|
6645
7049
|
for (const file of structural.files) {
|
|
6646
|
-
if (evolutionByFile.has(
|
|
7050
|
+
if (evolutionByFile.has(normalizePath4(file.id))) {
|
|
6647
7051
|
coveredFiles += 1;
|
|
6648
7052
|
}
|
|
6649
7053
|
}
|
|
@@ -6837,7 +7241,7 @@ var mapEvolutionByFile = (evolution) => {
|
|
|
6837
7241
|
return /* @__PURE__ */ new Map();
|
|
6838
7242
|
}
|
|
6839
7243
|
return new Map(
|
|
6840
|
-
evolution.files.map((fileMetrics) => [
|
|
7244
|
+
evolution.files.map((fileMetrics) => [normalizePath4(fileMetrics.filePath), fileMetrics])
|
|
6841
7245
|
);
|
|
6842
7246
|
};
|
|
6843
7247
|
var computeEvolutionScales = (evolutionByFile, config) => {
|
|
@@ -6861,7 +7265,7 @@ var computeEvolutionScales = (evolutionByFile, config) => {
|
|
|
6861
7265
|
};
|
|
6862
7266
|
};
|
|
6863
7267
|
var inferModuleName = (filePath, config) => {
|
|
6864
|
-
const normalized =
|
|
7268
|
+
const normalized = normalizePath4(filePath);
|
|
6865
7269
|
const parts = normalized.split("/").filter((part) => part.length > 0);
|
|
6866
7270
|
if (parts.length <= 1) {
|
|
6867
7271
|
return config.module.rootLabel;
|
|
@@ -6882,7 +7286,7 @@ var buildFragileClusters = (structural, evolution, fileScoresByFile, config) =>
|
|
|
6882
7286
|
const clusters = [];
|
|
6883
7287
|
let cycleClusterCount = 0;
|
|
6884
7288
|
for (const cycle of structural.cycles) {
|
|
6885
|
-
const files = [...new Set(cycle.nodes.map((node) =>
|
|
7289
|
+
const files = [...new Set(cycle.nodes.map((node) => normalizePath4(node)))].filter(
|
|
6886
7290
|
(filePath) => fileScoresByFile.has(filePath)
|
|
6887
7291
|
);
|
|
6888
7292
|
if (files.length < 2) {
|
|
@@ -6914,8 +7318,8 @@ var buildFragileClusters = (structural, evolution, fileScoresByFile, config) =>
|
|
|
6914
7318
|
)
|
|
6915
7319
|
);
|
|
6916
7320
|
const selectedPairs = candidates.filter((pair) => pair.couplingScore >= threshold).map((pair) => ({
|
|
6917
|
-
fileA:
|
|
6918
|
-
fileB:
|
|
7321
|
+
fileA: normalizePath4(pair.fileA),
|
|
7322
|
+
fileB: normalizePath4(pair.fileB),
|
|
6919
7323
|
couplingScore: pair.couplingScore
|
|
6920
7324
|
})).filter(
|
|
6921
7325
|
(pair) => pair.fileA !== pair.fileB && fileScoresByFile.has(pair.fileA) && fileScoresByFile.has(pair.fileB)
|
|
@@ -6993,7 +7397,7 @@ var computeRiskSummary = (structural, evolution, external, config, traceCollecto
|
|
|
6993
7397
|
);
|
|
6994
7398
|
const evolutionScales = computeEvolutionScales(evolutionByFile, config);
|
|
6995
7399
|
const cycleFileSet = new Set(
|
|
6996
|
-
structural.cycles.flatMap((cycle) => cycle.nodes.map((node) =>
|
|
7400
|
+
structural.cycles.flatMap((cycle) => cycle.nodes.map((node) => normalizePath4(node)))
|
|
6997
7401
|
);
|
|
6998
7402
|
const fanInScale = buildQuantileScale(
|
|
6999
7403
|
structural.files.map((file) => logScale(file.fanIn)),
|
|
@@ -7016,7 +7420,7 @@ var computeRiskSummary = (structural, evolution, external, config, traceCollecto
|
|
|
7016
7420
|
external: external.available
|
|
7017
7421
|
});
|
|
7018
7422
|
const fileRiskContexts = structural.files.map((file) => {
|
|
7019
|
-
const filePath =
|
|
7423
|
+
const filePath = normalizePath4(file.id);
|
|
7020
7424
|
const inCycle = cycleFileSet.has(filePath) ? 1 : 0;
|
|
7021
7425
|
const fanInRisk = normalizeWithScale(logScale(file.fanIn), fanInScale);
|
|
7022
7426
|
const fanOutRisk = normalizeWithScale(logScale(file.fanOut), fanOutScale);
|
|
@@ -7975,7 +8379,7 @@ var runCheckCommand = async (inputPath, authorIdentityMode, options, logger = cr
|
|
|
7975
8379
|
|
|
7976
8380
|
// src/application/run-ci-command.ts
|
|
7977
8381
|
import { readFile as readFile4, writeFile as writeFile4 } from "fs/promises";
|
|
7978
|
-
import { relative as
|
|
8382
|
+
import { relative as relative3, resolve as resolve4 } from "path";
|
|
7979
8383
|
var isPathOutsideBase = (value) => {
|
|
7980
8384
|
return value === ".." || value.startsWith("../") || value.startsWith("..\\");
|
|
7981
8385
|
};
|
|
@@ -8042,7 +8446,7 @@ var runCiCommand = async (inputPath, authorIdentityMode, options, logger = creat
|
|
|
8042
8446
|
repositoryPath: resolvedTargetPath,
|
|
8043
8447
|
baselineRef,
|
|
8044
8448
|
analyzeWorktree: async (worktreePath, repositoryRoot) => {
|
|
8045
|
-
const relativeTargetPath =
|
|
8449
|
+
const relativeTargetPath = relative3(repositoryRoot, resolvedTargetPath);
|
|
8046
8450
|
if (isPathOutsideBase(relativeTargetPath)) {
|
|
8047
8451
|
throw new GovernanceConfigurationError(
|
|
8048
8452
|
`target path is outside git repository root: ${resolvedTargetPath}`
|
|
@@ -8122,12 +8526,12 @@ ${ciMarkdown}`;
|
|
|
8122
8526
|
};
|
|
8123
8527
|
|
|
8124
8528
|
// src/application/run-report-command.ts
|
|
8125
|
-
import { join as
|
|
8529
|
+
import { join as join9 } from "path";
|
|
8126
8530
|
import { readFile as readFile6, writeFile as writeFile6 } from "fs/promises";
|
|
8127
8531
|
|
|
8128
8532
|
// src/application/html-report.ts
|
|
8129
8533
|
import { mkdir as mkdir3, readFile as readFile5, rm, stat as stat2, writeFile as writeFile5 } from "fs/promises";
|
|
8130
|
-
import { dirname as dirname2, join as
|
|
8534
|
+
import { dirname as dirname2, join as join8, resolve as resolve5 } from "path";
|
|
8131
8535
|
import { fileURLToPath } from "url";
|
|
8132
8536
|
var HTML_REPORT_DIR = ".codesentinel/report";
|
|
8133
8537
|
var getBundledHtmlAppPath = () => resolve5(dirname2(fileURLToPath(import.meta.url)), "html-report-app");
|
|
@@ -8190,7 +8594,7 @@ var assertHtmlAppAssets = async (assetPath) => {
|
|
|
8190
8594
|
};
|
|
8191
8595
|
var resolveHtmlReportOutputPath = (repositoryPath, outputPath) => {
|
|
8192
8596
|
const invocationCwd = process.env["INIT_CWD"] ?? process.cwd();
|
|
8193
|
-
return resolve5(invocationCwd, outputPath ??
|
|
8597
|
+
return resolve5(invocationCwd, outputPath ?? join8(repositoryPath, HTML_REPORT_DIR));
|
|
8194
8598
|
};
|
|
8195
8599
|
var writeHtmlReportBundle = async (report, options) => {
|
|
8196
8600
|
const bundledAppPath = options.bundledAppPath ?? getBundledHtmlAppPath();
|
|
@@ -8272,7 +8676,7 @@ var runReportCommand = async (inputPath, authorIdentityMode, options, logger = c
|
|
|
8272
8676
|
...options.outputPath === void 0 ? {} : { outputPath: options.outputPath }
|
|
8273
8677
|
});
|
|
8274
8678
|
if (options.open === true) {
|
|
8275
|
-
const opened = await openPath(
|
|
8679
|
+
const opened = await openPath(join9(bundlePath, "index.html"));
|
|
8276
8680
|
if (!opened) {
|
|
8277
8681
|
logger.warn("unable to open html report automatically on this platform");
|
|
8278
8682
|
}
|
|
@@ -8364,7 +8768,7 @@ var runExplainCommand = async (inputPath, authorIdentityMode, options, logger =
|
|
|
8364
8768
|
// src/index.ts
|
|
8365
8769
|
var program = new Command();
|
|
8366
8770
|
var packageJsonPath = resolve6(dirname3(fileURLToPath2(import.meta.url)), "../package.json");
|
|
8367
|
-
var { version } = JSON.parse(
|
|
8771
|
+
var { version } = JSON.parse(readFileSync3(packageJsonPath, "utf8"));
|
|
8368
8772
|
var parseRecentWindowDays = (value) => {
|
|
8369
8773
|
const parsed = Number.parseInt(value, 10);
|
|
8370
8774
|
if (!Number.isInteger(parsed) || parsed <= 0) {
|