@praneeth_54/agentdoctor 0.3.0-beta → 1.1.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/CHANGELOG.md +105 -1
- package/README.md +64 -31
- package/dist/agents/inspect.js +58 -51
- package/dist/cli/commands/brain-mcp.d.ts +9 -0
- package/dist/cli/commands/brain-mcp.js +38 -0
- package/dist/cli/commands/explain.js +1 -1
- package/dist/cli/commands/fix.js +22 -6
- package/dist/cli/commands/scan.d.ts +5 -0
- package/dist/cli/commands/scan.js +25 -6
- package/dist/cli/commands/verify.d.ts +6 -0
- package/dist/cli/commands/verify.js +25 -11
- package/dist/cli/program.js +61 -7
- package/dist/constants.d.ts +1 -1
- package/dist/constants.js +1 -1
- package/dist/core/fix/apply.d.ts +5 -1
- package/dist/core/fix/apply.js +34 -14
- package/dist/core/fix/plan.d.ts +1 -1
- package/dist/core/fix/plan.js +110 -3
- package/dist/core/fix/render.d.ts +2 -0
- package/dist/core/fix/render.js +57 -9
- package/dist/core/fix/run.js +5 -1
- package/dist/core/fix/types.d.ts +1 -1
- package/dist/core/fix/types.js +5 -1
- package/dist/core/fix/writers/claude-settings.d.ts +16 -0
- package/dist/core/fix/writers/claude-settings.js +100 -0
- package/dist/core/fix/writers/codex-config.d.ts +22 -0
- package/dist/core/fix/writers/codex-config.js +183 -0
- package/dist/core/fix/writers/cursorignore.js +2 -8
- package/dist/core/path-resolution/index.d.ts +5 -0
- package/dist/core/path-resolution/index.js +5 -0
- package/dist/core/path-resolution/prepare.d.ts +33 -0
- package/dist/core/path-resolution/prepare.js +98 -0
- package/dist/core/policy/evaluate.d.ts +44 -0
- package/dist/core/policy/evaluate.js +120 -0
- package/dist/core/rules/claude-deny.d.ts +8 -0
- package/dist/core/rules/claude-deny.js +39 -0
- package/dist/core/rules/codex-deny.d.ts +5 -0
- package/dist/core/rules/codex-deny.js +42 -0
- package/dist/core/rules/context/generated-directory.js +43 -9
- package/dist/core/rules/context/large-log-file.js +27 -10
- package/dist/core/rules/ignore.js +2 -5
- package/dist/core/rules/instructions/missing-path-reference.d.ts +5 -1
- package/dist/core/rules/instructions/missing-path-reference.js +24 -6
- package/dist/core/rules/path-kind.d.ts +15 -2
- package/dist/core/rules/path-kind.js +113 -10
- package/dist/core/rules/security/env-file-exposure.js +9 -24
- package/dist/core/rules/text-cache.js +46 -40
- package/dist/core/understanding/architecture/index.d.ts +4 -0
- package/dist/core/understanding/architecture/index.js +3 -0
- package/dist/core/understanding/architecture/infer.d.ts +6 -0
- package/dist/core/understanding/architecture/infer.js +39 -0
- package/dist/core/understanding/architecture/models.d.ts +23 -0
- package/dist/core/understanding/architecture/models.js +127 -0
- package/dist/core/understanding/architecture/patterns/distribution.d.ts +2 -0
- package/dist/core/understanding/architecture/patterns/distribution.js +115 -0
- package/dist/core/understanding/architecture/patterns/index.d.ts +2 -0
- package/dist/core/understanding/architecture/patterns/index.js +8 -0
- package/dist/core/understanding/architecture/patterns/layered.d.ts +2 -0
- package/dist/core/understanding/architecture/patterns/layered.js +279 -0
- package/dist/core/understanding/architecture/patterns/structural.d.ts +2 -0
- package/dist/core/understanding/architecture/patterns/structural.js +197 -0
- package/dist/core/understanding/architecture/rules.d.ts +4 -0
- package/dist/core/understanding/architecture/rules.js +6 -0
- package/dist/core/understanding/architecture/types.d.ts +52 -0
- package/dist/core/understanding/architecture/types.js +1 -0
- package/dist/core/understanding/brain/build.d.ts +13 -0
- package/dist/core/understanding/brain/build.js +158 -0
- package/dist/core/understanding/brain/claims/index.d.ts +3 -0
- package/dist/core/understanding/brain/claims/index.js +2 -0
- package/dist/core/understanding/brain/claims/lifecycle.d.ts +16 -0
- package/dist/core/understanding/brain/claims/lifecycle.js +78 -0
- package/dist/core/understanding/brain/claims/types.d.ts +32 -0
- package/dist/core/understanding/brain/claims/types.js +25 -0
- package/dist/core/understanding/brain/components/index.d.ts +17 -0
- package/dist/core/understanding/brain/components/index.js +97 -0
- package/dist/core/understanding/brain/components/types.d.ts +16 -0
- package/dist/core/understanding/brain/components/types.js +8 -0
- package/dist/core/understanding/brain/confidence.d.ts +19 -0
- package/dist/core/understanding/brain/confidence.js +39 -0
- package/dist/core/understanding/brain/contract.d.ts +17 -0
- package/dist/core/understanding/brain/contract.js +100 -0
- package/dist/core/understanding/brain/contradictions/index.d.ts +12 -0
- package/dist/core/understanding/brain/contradictions/index.js +57 -0
- package/dist/core/understanding/brain/contradictions/types.d.ts +12 -0
- package/dist/core/understanding/brain/contradictions/types.js +8 -0
- package/dist/core/understanding/brain/delta.d.ts +25 -0
- package/dist/core/understanding/brain/delta.js +116 -0
- package/dist/core/understanding/brain/evidence/index.d.ts +3 -0
- package/dist/core/understanding/brain/evidence/index.js +2 -0
- package/dist/core/understanding/brain/evidence/redact.d.ts +4 -0
- package/dist/core/understanding/brain/evidence/redact.js +36 -0
- package/dist/core/understanding/brain/evidence/types.d.ts +34 -0
- package/dist/core/understanding/brain/evidence/types.js +35 -0
- package/dist/core/understanding/brain/explain.d.ts +17 -0
- package/dist/core/understanding/brain/explain.js +33 -0
- package/dist/core/understanding/brain/index.d.ts +28 -0
- package/dist/core/understanding/brain/index.js +16 -0
- package/dist/core/understanding/brain/migrate.d.ts +21 -0
- package/dist/core/understanding/brain/migrate.js +47 -0
- package/dist/core/understanding/brain/query.d.ts +60 -0
- package/dist/core/understanding/brain/query.js +92 -0
- package/dist/core/understanding/brain/security.d.ts +3 -0
- package/dist/core/understanding/brain/security.js +43 -0
- package/dist/core/understanding/brain/storage/index.d.ts +2 -0
- package/dist/core/understanding/brain/storage/index.js +1 -0
- package/dist/core/understanding/brain/storage/store.d.ts +53 -0
- package/dist/core/understanding/brain/storage/store.js +305 -0
- package/dist/core/understanding/brain/trace.d.ts +24 -0
- package/dist/core/understanding/brain/trace.js +207 -0
- package/dist/core/understanding/brain/types.d.ts +32 -0
- package/dist/core/understanding/brain/types.js +8 -0
- package/dist/core/understanding/brain/version.d.ts +13 -0
- package/dist/core/understanding/brain/version.js +7 -0
- package/dist/core/understanding/delta/compare.d.ts +26 -0
- package/dist/core/understanding/delta/compare.js +74 -0
- package/dist/core/understanding/delta/index.d.ts +2 -0
- package/dist/core/understanding/delta/index.js +1 -0
- package/dist/core/understanding/dependencies/discover.d.ts +7 -0
- package/dist/core/understanding/dependencies/discover.js +550 -0
- package/dist/core/understanding/dependencies/extract.d.ts +10 -0
- package/dist/core/understanding/dependencies/extract.js +189 -0
- package/dist/core/understanding/dependencies/index.d.ts +4 -0
- package/dist/core/understanding/dependencies/index.js +3 -0
- package/dist/core/understanding/dependencies/models.d.ts +12 -0
- package/dist/core/understanding/dependencies/models.js +125 -0
- package/dist/core/understanding/dependencies/types.d.ts +27 -0
- package/dist/core/understanding/dependencies/types.js +1 -0
- package/dist/core/understanding/domain/discover.d.ts +14 -0
- package/dist/core/understanding/domain/discover.js +90 -0
- package/dist/core/understanding/domain/index.d.ts +2 -0
- package/dist/core/understanding/domain/index.js +1 -0
- package/dist/core/understanding/entrypoints/discover.d.ts +6 -0
- package/dist/core/understanding/entrypoints/discover.js +62 -0
- package/dist/core/understanding/entrypoints/extract.d.ts +19 -0
- package/dist/core/understanding/entrypoints/extract.js +43 -0
- package/dist/core/understanding/entrypoints/index.d.ts +4 -0
- package/dist/core/understanding/entrypoints/index.js +3 -0
- package/dist/core/understanding/entrypoints/models.d.ts +26 -0
- package/dist/core/understanding/entrypoints/models.js +216 -0
- package/dist/core/understanding/entrypoints/types.d.ts +20 -0
- package/dist/core/understanding/entrypoints/types.js +1 -0
- package/dist/core/understanding/index.d.ts +32 -0
- package/dist/core/understanding/index.js +18 -0
- package/dist/core/understanding/mind/build.d.ts +16 -0
- package/dist/core/understanding/mind/build.js +134 -0
- package/dist/core/understanding/mind/index.d.ts +6 -0
- package/dist/core/understanding/mind/index.js +3 -0
- package/dist/core/understanding/mind/query.d.ts +33 -0
- package/dist/core/understanding/mind/query.js +39 -0
- package/dist/core/understanding/mind/types.d.ts +24 -0
- package/dist/core/understanding/mind/types.js +7 -0
- package/dist/core/understanding/model/builder.d.ts +9 -0
- package/dist/core/understanding/model/builder.js +209 -0
- package/dist/core/understanding/model/ids.d.ts +7 -0
- package/dist/core/understanding/model/ids.js +48 -0
- package/dist/core/understanding/model/index.d.ts +7 -0
- package/dist/core/understanding/model/index.js +6 -0
- package/dist/core/understanding/model/schema.d.ts +12 -0
- package/dist/core/understanding/model/schema.js +33 -0
- package/dist/core/understanding/model/serializer.d.ts +9 -0
- package/dist/core/understanding/model/serializer.js +46 -0
- package/dist/core/understanding/model/types.d.ts +110 -0
- package/dist/core/understanding/model/types.js +1 -0
- package/dist/core/understanding/model/validator.d.ts +5 -0
- package/dist/core/understanding/model/validator.js +126 -0
- package/dist/core/understanding/model/version.d.ts +9 -0
- package/dist/core/understanding/model/version.js +7 -0
- package/dist/core/understanding/ownership/discover.d.ts +12 -0
- package/dist/core/understanding/ownership/discover.js +242 -0
- package/dist/core/understanding/ownership/index.d.ts +2 -0
- package/dist/core/understanding/ownership/index.js +1 -0
- package/dist/core/understanding/ownership/types.d.ts +23 -0
- package/dist/core/understanding/ownership/types.js +1 -0
- package/dist/core/understanding/query/engine.d.ts +24 -0
- package/dist/core/understanding/query/engine.js +35 -0
- package/dist/core/understanding/query/errors.d.ts +13 -0
- package/dist/core/understanding/query/errors.js +26 -0
- package/dist/core/understanding/query/executor.d.ts +8 -0
- package/dist/core/understanding/query/executor.js +34 -0
- package/dist/core/understanding/query/index.d.ts +7 -0
- package/dist/core/understanding/query/index.js +5 -0
- package/dist/core/understanding/query/models.d.ts +102 -0
- package/dist/core/understanding/query/models.js +1 -0
- package/dist/core/understanding/query/query.d.ts +68 -0
- package/dist/core/understanding/query/query.js +145 -0
- package/dist/core/understanding/query/registry.d.ts +8 -0
- package/dist/core/understanding/query/registry.js +340 -0
- package/dist/core/understanding/query/types.d.ts +63 -0
- package/dist/core/understanding/query/types.js +1 -0
- package/dist/core/understanding/relationships/discover.d.ts +11 -0
- package/dist/core/understanding/relationships/discover.js +517 -0
- package/dist/core/understanding/relationships/extract.d.ts +14 -0
- package/dist/core/understanding/relationships/extract.js +165 -0
- package/dist/core/understanding/relationships/index.d.ts +4 -0
- package/dist/core/understanding/relationships/index.js +3 -0
- package/dist/core/understanding/relationships/models.d.ts +21 -0
- package/dist/core/understanding/relationships/models.js +185 -0
- package/dist/core/understanding/relationships/types.d.ts +42 -0
- package/dist/core/understanding/relationships/types.js +1 -0
- package/dist/core/understanding/risks/discover.d.ts +8 -0
- package/dist/core/understanding/risks/discover.js +155 -0
- package/dist/core/understanding/risks/index.d.ts +2 -0
- package/dist/core/understanding/risks/index.js +1 -0
- package/dist/core/understanding/risks/types.d.ts +26 -0
- package/dist/core/understanding/risks/types.js +1 -0
- package/dist/core/understanding/shared/domain-lexicon.d.ts +9 -0
- package/dist/core/understanding/shared/domain-lexicon.js +107 -0
- package/dist/core/understanding/shared/index.d.ts +2 -0
- package/dist/core/understanding/shared/index.js +2 -0
- package/dist/core/understanding/shared/tokens.d.ts +7 -0
- package/dist/core/understanding/shared/tokens.js +141 -0
- package/dist/core/understanding/snapshot/identity.d.ts +24 -0
- package/dist/core/understanding/snapshot/identity.js +79 -0
- package/dist/core/understanding/snapshot/index.d.ts +2 -0
- package/dist/core/understanding/snapshot/index.js +1 -0
- package/dist/core/understanding/types/index.d.ts +22 -0
- package/dist/core/understanding/types/index.js +1 -0
- package/dist/core/understanding/understand/formatter.d.ts +10 -0
- package/dist/core/understanding/understand/formatter.js +115 -0
- package/dist/core/understanding/understand/index.d.ts +4 -0
- package/dist/core/understanding/understand/index.js +3 -0
- package/dist/core/understanding/understand/service.d.ts +17 -0
- package/dist/core/understanding/understand/service.js +76 -0
- package/dist/core/understanding/understand/summary.d.ts +14 -0
- package/dist/core/understanding/understand/summary.js +39 -0
- package/dist/core/understanding/understand/types.d.ts +31 -0
- package/dist/core/understanding/understand/types.js +1 -0
- package/dist/discovery/files.js +7 -2
- package/dist/discovery/log-like.d.ts +2 -0
- package/dist/discovery/log-like.js +7 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/mcp/brain/compile.d.ts +9 -0
- package/dist/mcp/brain/compile.js +42 -0
- package/dist/mcp/brain/errors.d.ts +12 -0
- package/dist/mcp/brain/errors.js +23 -0
- package/dist/mcp/brain/index.d.ts +11 -0
- package/dist/mcp/brain/index.js +8 -0
- package/dist/mcp/brain/provenance.d.ts +29 -0
- package/dist/mcp/brain/provenance.js +59 -0
- package/dist/mcp/brain/schemas.d.ts +13 -0
- package/dist/mcp/brain/schemas.js +105 -0
- package/dist/mcp/brain/security/root.d.ts +6 -0
- package/dist/mcp/brain/security/root.js +66 -0
- package/dist/mcp/brain/server.d.ts +12 -0
- package/dist/mcp/brain/server.js +46 -0
- package/dist/mcp/brain/session.d.ts +33 -0
- package/dist/mcp/brain/session.js +117 -0
- package/dist/mcp/brain/tools/handlers.d.ts +13 -0
- package/dist/mcp/brain/tools/handlers.js +483 -0
- package/dist/mcp/brain/tools/registry.d.ts +9 -0
- package/dist/mcp/brain/tools/registry.js +191 -0
- package/dist/reporters/github/annotations.d.ts +8 -0
- package/dist/reporters/github/annotations.js +42 -0
- package/dist/reporters/github/emit.d.ts +23 -0
- package/dist/reporters/github/emit.js +31 -0
- package/dist/reporters/github/summary.d.ts +20 -0
- package/dist/reporters/github/summary.js +111 -0
- package/dist/reporters/terminal/report.d.ts +5 -0
- package/dist/reporters/terminal/report.js +68 -5
- package/dist/reporters/verify/terminal.d.ts +4 -0
- package/dist/reporters/verify/terminal.js +26 -0
- package/dist/utils/fs.d.ts +5 -0
- package/dist/utils/fs.js +34 -0
- package/dist/utils/path.d.ts +5 -0
- package/dist/utils/path.js +16 -0
- package/package.json +15 -1
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
function normalize(value) {
|
|
2
|
+
return value.replace(/\\/g, "/").toLowerCase();
|
|
3
|
+
}
|
|
4
|
+
/** Prefer exact path match; fall back to path-segment containment (not bare substring). */
|
|
5
|
+
function pathMatches(value, target) {
|
|
6
|
+
const v = normalize(value);
|
|
7
|
+
const t = normalize(target);
|
|
8
|
+
if (t.length === 0) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
if (v === t) {
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
// Segment-aware containment: "/foo/bar" matches target "foo/bar" or "bar" as a segment.
|
|
15
|
+
if (t.length < 2) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
return (v.endsWith(`/${t}`) ||
|
|
19
|
+
v.includes(`/${t}/`) ||
|
|
20
|
+
v.startsWith(`${t}/`) ||
|
|
21
|
+
t.endsWith(`/${v}`) ||
|
|
22
|
+
t.includes(`/${v}/`));
|
|
23
|
+
}
|
|
24
|
+
const MAX_DEPTH = 25;
|
|
25
|
+
const MAX_EDGES = 5_000;
|
|
26
|
+
export function traceBrain(brain, target, mode = "blast-radius") {
|
|
27
|
+
const nodes = new Map();
|
|
28
|
+
const edgeKeys = new Set();
|
|
29
|
+
const edges = [];
|
|
30
|
+
const visiting = new Set();
|
|
31
|
+
const expanded = new Set();
|
|
32
|
+
const cycles = [];
|
|
33
|
+
const addNode = (node) => {
|
|
34
|
+
if (!nodes.has(node.id)) {
|
|
35
|
+
nodes.set(node.id, node);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
const addEdge = (edge) => {
|
|
39
|
+
if (edges.length >= MAX_EDGES) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const key = `${edge.from}\0${edge.to}\0${edge.type}`;
|
|
43
|
+
if (edgeKeys.has(key)) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
edgeKeys.add(key);
|
|
47
|
+
edges.push(edge);
|
|
48
|
+
};
|
|
49
|
+
const rootId = `root:${target}`;
|
|
50
|
+
addNode({
|
|
51
|
+
id: rootId,
|
|
52
|
+
label: target,
|
|
53
|
+
kind: "component",
|
|
54
|
+
path: target,
|
|
55
|
+
confidence: 1,
|
|
56
|
+
});
|
|
57
|
+
if (mode === "domain-modules") {
|
|
58
|
+
for (const domain of brain.model.domains) {
|
|
59
|
+
if (!pathMatches(domain.name, target) && !domain.paths.some((p) => pathMatches(p, target))) {
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
const domainNode = `domain:${domain.name}`;
|
|
63
|
+
addNode({
|
|
64
|
+
id: domainNode,
|
|
65
|
+
label: domain.name,
|
|
66
|
+
kind: "domain",
|
|
67
|
+
confidence: domain.confidence,
|
|
68
|
+
});
|
|
69
|
+
addEdge({
|
|
70
|
+
from: rootId,
|
|
71
|
+
to: domainNode,
|
|
72
|
+
type: "domain",
|
|
73
|
+
evidence: [...domain.evidence],
|
|
74
|
+
confidence: domain.confidence,
|
|
75
|
+
});
|
|
76
|
+
for (const comp of brain.components) {
|
|
77
|
+
if (!comp.domainIds.includes(domain.id) &&
|
|
78
|
+
!domain.paths.some((p) => pathMatches(comp.path, p))) {
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
addNode({
|
|
82
|
+
id: comp.id,
|
|
83
|
+
label: comp.name,
|
|
84
|
+
kind: "component",
|
|
85
|
+
path: comp.path,
|
|
86
|
+
confidence: comp.confidence,
|
|
87
|
+
});
|
|
88
|
+
addEdge({
|
|
89
|
+
from: domainNode,
|
|
90
|
+
to: comp.id,
|
|
91
|
+
type: "contains",
|
|
92
|
+
evidence: [...comp.evidenceIds],
|
|
93
|
+
confidence: comp.confidence,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
const walk = (current, depth) => {
|
|
100
|
+
if (depth > MAX_DEPTH || edges.length >= MAX_EDGES) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
if (visiting.has(current)) {
|
|
104
|
+
cycles.push(current);
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
if (expanded.has(current)) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
visiting.add(current);
|
|
111
|
+
for (const dep of brain.model.dependencies) {
|
|
112
|
+
const fromMatch = pathMatches(dep.from, current);
|
|
113
|
+
const toMatch = pathMatches(dep.to, current);
|
|
114
|
+
if (mode === "dependencies" && !fromMatch) {
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
if (mode === "dependents" && !toMatch) {
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
if (mode === "entrypoint-downstream" && depth === 0) {
|
|
121
|
+
if (!pathMatches(dep.from, target) && !pathMatches(dep.to, target)) {
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
else if (mode === "blast-radius" || mode === "entrypoint-downstream") {
|
|
126
|
+
if (!fromMatch && !toMatch) {
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
const fromId = `node:${dep.from}`;
|
|
131
|
+
const toId = `node:${dep.to}`;
|
|
132
|
+
addNode({
|
|
133
|
+
id: fromId,
|
|
134
|
+
label: dep.from,
|
|
135
|
+
kind: "dependency-endpoint",
|
|
136
|
+
path: dep.from,
|
|
137
|
+
confidence: dep.confidence,
|
|
138
|
+
});
|
|
139
|
+
addNode({
|
|
140
|
+
id: toId,
|
|
141
|
+
label: dep.to,
|
|
142
|
+
kind: "dependency-endpoint",
|
|
143
|
+
path: dep.to,
|
|
144
|
+
confidence: dep.confidence,
|
|
145
|
+
});
|
|
146
|
+
addEdge({
|
|
147
|
+
from: fromId,
|
|
148
|
+
to: toId,
|
|
149
|
+
type: dep.type,
|
|
150
|
+
evidence: [...dep.evidence],
|
|
151
|
+
confidence: dep.confidence,
|
|
152
|
+
});
|
|
153
|
+
if (mode === "dependencies" ||
|
|
154
|
+
mode === "blast-radius" ||
|
|
155
|
+
mode === "entrypoint-downstream") {
|
|
156
|
+
if (fromMatch) {
|
|
157
|
+
walk(dep.to, depth + 1);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
if (mode === "dependents" || mode === "blast-radius") {
|
|
161
|
+
if (toMatch) {
|
|
162
|
+
walk(dep.from, depth + 1);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
if (mode === "entrypoint-downstream" || mode === "blast-radius") {
|
|
167
|
+
for (const entry of brain.model.entrypoints) {
|
|
168
|
+
if (!pathMatches(entry.file, current) && !pathMatches(entry.file, target)) {
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
const entryId = `entry:${entry.file}`;
|
|
172
|
+
addNode({
|
|
173
|
+
id: entryId,
|
|
174
|
+
label: entry.file,
|
|
175
|
+
kind: "entrypoint",
|
|
176
|
+
path: entry.file,
|
|
177
|
+
confidence: entry.confidence,
|
|
178
|
+
});
|
|
179
|
+
addEdge({
|
|
180
|
+
from: rootId,
|
|
181
|
+
to: entryId,
|
|
182
|
+
type: "entrypoint",
|
|
183
|
+
evidence: [...entry.evidence],
|
|
184
|
+
confidence: entry.confidence,
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
visiting.delete(current);
|
|
189
|
+
expanded.add(current);
|
|
190
|
+
};
|
|
191
|
+
walk(target, 0);
|
|
192
|
+
}
|
|
193
|
+
const nodeList = [...nodes.values()].sort((a, b) => a.id.localeCompare(b.id));
|
|
194
|
+
const edgeList = edges
|
|
195
|
+
.map((e) => ({ ...e, evidence: [...e.evidence].sort() }))
|
|
196
|
+
.sort((a, b) => a.from.localeCompare(b.from) || a.to.localeCompare(b.to) || a.type.localeCompare(b.type));
|
|
197
|
+
const confidence = edgeList.length === 0
|
|
198
|
+
? 0
|
|
199
|
+
: Math.round((edgeList.reduce((s, e) => s + e.confidence, 0) / edgeList.length) * 100) / 100;
|
|
200
|
+
return {
|
|
201
|
+
root: target,
|
|
202
|
+
nodes: nodeList,
|
|
203
|
+
edges: edgeList,
|
|
204
|
+
cycles: [...new Set(cycles)].sort(),
|
|
205
|
+
confidence,
|
|
206
|
+
};
|
|
207
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ProjectModel } from "../model/types.js";
|
|
2
|
+
import type { OwnershipDiscoveryResult } from "../ownership/types.js";
|
|
3
|
+
import type { RiskDiscoveryResult } from "../risks/types.js";
|
|
4
|
+
import type { SnapshotIdentity } from "../snapshot/index.js";
|
|
5
|
+
import type { BrainClaim } from "./claims/types.js";
|
|
6
|
+
import type { BrainComponent } from "./components/types.js";
|
|
7
|
+
import type { ConfidenceMetadata } from "./confidence.js";
|
|
8
|
+
import type { BrainContradiction } from "./contradictions/types.js";
|
|
9
|
+
import type { BrainEvidence } from "./evidence/types.js";
|
|
10
|
+
import type { ProjectBrainSchemaVersion } from "./version.js";
|
|
11
|
+
export interface ProjectBrainMetadata {
|
|
12
|
+
schemaVersion: ProjectBrainSchemaVersion;
|
|
13
|
+
brainId: string;
|
|
14
|
+
projectName: string;
|
|
15
|
+
createdAt: string;
|
|
16
|
+
updatedAt: string;
|
|
17
|
+
}
|
|
18
|
+
export interface ProjectBrain {
|
|
19
|
+
metadata: ProjectBrainMetadata;
|
|
20
|
+
snapshot: SnapshotIdentity;
|
|
21
|
+
model: ProjectModel;
|
|
22
|
+
ownership: OwnershipDiscoveryResult;
|
|
23
|
+
risks: RiskDiscoveryResult;
|
|
24
|
+
components: readonly BrainComponent[];
|
|
25
|
+
claims: readonly BrainClaim[];
|
|
26
|
+
evidence: readonly BrainEvidence[];
|
|
27
|
+
contradictions: readonly BrainContradiction[];
|
|
28
|
+
unknowns: readonly string[];
|
|
29
|
+
limitations: readonly string[];
|
|
30
|
+
confidenceContract: ConfidenceMetadata;
|
|
31
|
+
}
|
|
32
|
+
export declare const PROJECT_BRAIN_LIMITATIONS: readonly ["Project Brain is deterministic and local-only", "Domains are path-inferred unless stronger evidence exists", "Ownership requires explicit CODEOWNERS / MAINTAINERS / package.json evidence", "Risks describe change-danger, not vulnerability scanning", "Business rules and design intent remain unknown", "Evidence never includes secret file contents"];
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export const PROJECT_BRAIN_LIMITATIONS = [
|
|
2
|
+
"Project Brain is deterministic and local-only",
|
|
3
|
+
"Domains are path-inferred unless stronger evidence exists",
|
|
4
|
+
"Ownership requires explicit CODEOWNERS / MAINTAINERS / package.json evidence",
|
|
5
|
+
"Risks describe change-danger, not vulnerability scanning",
|
|
6
|
+
"Business rules and design intent remain unknown",
|
|
7
|
+
"Evidence never includes secret file contents",
|
|
8
|
+
];
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** Project Brain schema / storage format versions (independent of AgentDoctor package). */
|
|
2
|
+
export declare const PROJECT_BRAIN_SCHEMA_VERSION: "1.0.0";
|
|
3
|
+
export declare const CLAIM_SCHEMA_VERSION: "1.0.0";
|
|
4
|
+
export declare const EVIDENCE_SCHEMA_VERSION: "1.0.0";
|
|
5
|
+
export declare const DELTA_SCHEMA_VERSION: "1.0.0";
|
|
6
|
+
export declare const SNAPSHOT_META_SCHEMA_VERSION: "1.0.0";
|
|
7
|
+
export declare const BRAIN_STORAGE_FORMAT_VERSION: "1.0.0";
|
|
8
|
+
export type ProjectBrainSchemaVersion = typeof PROJECT_BRAIN_SCHEMA_VERSION;
|
|
9
|
+
export type ClaimSchemaVersion = typeof CLAIM_SCHEMA_VERSION;
|
|
10
|
+
export type EvidenceSchemaVersion = typeof EVIDENCE_SCHEMA_VERSION;
|
|
11
|
+
export type DeltaSchemaVersion = typeof DELTA_SCHEMA_VERSION;
|
|
12
|
+
export type SnapshotMetaSchemaVersion = typeof SNAPSHOT_META_SCHEMA_VERSION;
|
|
13
|
+
export type BrainStorageFormatVersion = typeof BRAIN_STORAGE_FORMAT_VERSION;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Project Brain schema / storage format versions (independent of AgentDoctor package). */
|
|
2
|
+
export const PROJECT_BRAIN_SCHEMA_VERSION = "1.0.0";
|
|
3
|
+
export const CLAIM_SCHEMA_VERSION = "1.0.0";
|
|
4
|
+
export const EVIDENCE_SCHEMA_VERSION = "1.0.0";
|
|
5
|
+
export const DELTA_SCHEMA_VERSION = "1.0.0";
|
|
6
|
+
export const SNAPSHOT_META_SCHEMA_VERSION = "1.0.0";
|
|
7
|
+
export const BRAIN_STORAGE_FORMAT_VERSION = "1.0.0";
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { ProjectModel } from "../model/types.js";
|
|
2
|
+
import { type SnapshotIdentity } from "../snapshot/index.js";
|
|
3
|
+
export interface SetDelta<T> {
|
|
4
|
+
added: readonly T[];
|
|
5
|
+
removed: readonly T[];
|
|
6
|
+
unchanged: readonly T[];
|
|
7
|
+
}
|
|
8
|
+
export interface UnderstandingDelta {
|
|
9
|
+
before: SnapshotIdentity;
|
|
10
|
+
after: SnapshotIdentity;
|
|
11
|
+
structuralEqual: boolean;
|
|
12
|
+
domains: SetDelta<string>;
|
|
13
|
+
entrypoints: SetDelta<string>;
|
|
14
|
+
dependencies: SetDelta<string>;
|
|
15
|
+
relationships: SetDelta<string>;
|
|
16
|
+
architectures: SetDelta<string>;
|
|
17
|
+
/** Model object ids present before but absent after. */
|
|
18
|
+
invalidatedIds: readonly string[];
|
|
19
|
+
/** Human-readable summary lines. */
|
|
20
|
+
summary: readonly string[];
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Compare two ProjectModel snapshots into an understanding delta.
|
|
24
|
+
* Does not re-scan the repository.
|
|
25
|
+
*/
|
|
26
|
+
export declare function compareProjectModels(before: ProjectModel, after: ProjectModel): UnderstandingDelta;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { createSnapshotIdentity } from "../snapshot/index.js";
|
|
2
|
+
function setDelta(before, after) {
|
|
3
|
+
const beforeSet = new Set(before);
|
|
4
|
+
const afterSet = new Set(after);
|
|
5
|
+
const added = after.filter((item) => !beforeSet.has(item)).sort((a, b) => a.localeCompare(b));
|
|
6
|
+
const removed = before.filter((item) => !afterSet.has(item)).sort((a, b) => a.localeCompare(b));
|
|
7
|
+
const unchanged = before.filter((item) => afterSet.has(item)).sort((a, b) => a.localeCompare(b));
|
|
8
|
+
return { added, removed, unchanged };
|
|
9
|
+
}
|
|
10
|
+
function collectIds(model) {
|
|
11
|
+
return [
|
|
12
|
+
model.metadata.id,
|
|
13
|
+
model.metadata.project.id,
|
|
14
|
+
...model.domains.map((d) => d.id),
|
|
15
|
+
...model.entrypoints.map((e) => e.id),
|
|
16
|
+
...model.dependencies.map((d) => d.id),
|
|
17
|
+
...model.relationships.map((r) => r.id),
|
|
18
|
+
...model.architectures.map((a) => a.id),
|
|
19
|
+
];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Compare two ProjectModel snapshots into an understanding delta.
|
|
23
|
+
* Does not re-scan the repository.
|
|
24
|
+
*/
|
|
25
|
+
export function compareProjectModels(before, after) {
|
|
26
|
+
const beforeSnap = createSnapshotIdentity(before);
|
|
27
|
+
const afterSnap = createSnapshotIdentity(after);
|
|
28
|
+
const domains = setDelta(before.domains.map((d) => d.name), after.domains.map((d) => d.name));
|
|
29
|
+
const entrypoints = setDelta(before.entrypoints.map((e) => `${e.framework}:${e.file}`), after.entrypoints.map((e) => `${e.framework}:${e.file}`));
|
|
30
|
+
const dependencies = setDelta(before.dependencies.map((d) => `${d.from}->${d.to}:${d.type}`), after.dependencies.map((d) => `${d.from}->${d.to}:${d.type}`));
|
|
31
|
+
const relationships = setDelta(before.relationships.map((r) => `${r.source}->${r.target}:${r.relationship}`), after.relationships.map((r) => `${r.source}->${r.target}:${r.relationship}`));
|
|
32
|
+
const architectures = setDelta(before.architectures.map((a) => a.pattern), after.architectures.map((a) => a.pattern));
|
|
33
|
+
const afterIds = new Set(collectIds(after));
|
|
34
|
+
const invalidatedIds = collectIds(before)
|
|
35
|
+
.filter((id) => !afterIds.has(id))
|
|
36
|
+
.sort((a, b) => a.localeCompare(b));
|
|
37
|
+
const structuralEqual = beforeSnap.contentHash === afterSnap.contentHash;
|
|
38
|
+
const summary = [];
|
|
39
|
+
if (structuralEqual) {
|
|
40
|
+
summary.push("No structural understanding changes");
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
if (domains.added.length || domains.removed.length) {
|
|
44
|
+
summary.push(`Domains +${domains.added.length}/-${domains.removed.length}`);
|
|
45
|
+
}
|
|
46
|
+
if (entrypoints.added.length || entrypoints.removed.length) {
|
|
47
|
+
summary.push(`Entrypoints +${entrypoints.added.length}/-${entrypoints.removed.length}`);
|
|
48
|
+
}
|
|
49
|
+
if (dependencies.added.length || dependencies.removed.length) {
|
|
50
|
+
summary.push(`Dependencies +${dependencies.added.length}/-${dependencies.removed.length}`);
|
|
51
|
+
}
|
|
52
|
+
if (relationships.added.length || relationships.removed.length) {
|
|
53
|
+
summary.push(`Relationships +${relationships.added.length}/-${relationships.removed.length}`);
|
|
54
|
+
}
|
|
55
|
+
if (architectures.added.length || architectures.removed.length) {
|
|
56
|
+
summary.push(`Architectures +${architectures.added.length}/-${architectures.removed.length}`);
|
|
57
|
+
}
|
|
58
|
+
if (invalidatedIds.length > 0) {
|
|
59
|
+
summary.push(`Invalidated claims: ${invalidatedIds.length}`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return {
|
|
63
|
+
before: beforeSnap,
|
|
64
|
+
after: afterSnap,
|
|
65
|
+
structuralEqual,
|
|
66
|
+
domains,
|
|
67
|
+
entrypoints,
|
|
68
|
+
dependencies,
|
|
69
|
+
relationships,
|
|
70
|
+
architectures,
|
|
71
|
+
invalidatedIds,
|
|
72
|
+
summary,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { compareProjectModels } from "./compare.js";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { DependencyDiscoveryOptions, DependencyDiscoveryResult, DependencyRelationType } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Discover structural repository dependencies via deterministic import/reference heuristics.
|
|
4
|
+
* Isolated from scan — internal understanding API only.
|
|
5
|
+
*/
|
|
6
|
+
export declare function discoverDependencies(options?: DependencyDiscoveryOptions): Promise<DependencyDiscoveryResult>;
|
|
7
|
+
export declare function scoreDependencyConfidence(type: DependencyRelationType): number;
|