weavatrix 0.3.6 → 0.3.8

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.
@@ -0,0 +1,37 @@
1
+ # Weavatrix 0.3.7
2
+
3
+ 0.3.7 fixes three defects surfaced by cross-repository validation: a
4
+ reverse-shell detection gap, an unbounded ripgrep-path probe that could hang the
5
+ server, and a `search_code` path that excluded `node_modules` only through the
6
+ gitignore stack.
7
+
8
+ ## Reverse-shell pre-filter now covers the confirming regex
9
+
10
+ The malware content sweep uses each rule's `pattern` as the ripgrep pre-filter
11
+ and only then applies the stricter `re` to confirm. The reverse-shell `pattern`
12
+ had drifted narrower than its `re`: it required `SOCK_STREAM` followed by
13
+ `/bin/sh` or `exec`, so socket-backed shells using `connect`, `subprocess`,
14
+ `pty.spawn` or `os.dup2` — and default `socket.socket()` calls with no
15
+ `SOCK_STREAM` literal — were dropped before they could be confirmed. The
16
+ pre-filter is now a superset of the confirming regex, and a new invariant test
17
+ asserts that every payload the confirming regex flags is also surfaced by the
18
+ pre-filter.
19
+
20
+ A separate, deeper case is deliberately left for a follow-up: multi-line reverse
21
+ shells, where ripgrep's per-line matching cannot span a `socket` call and the
22
+ shell invocation on different lines.
23
+
24
+ ## Bounded ripgrep-path probe
25
+
26
+ The `where`/`which rg` fallback in the MCP ripgrep resolver ran `spawnSync`
27
+ without a timeout on the main thread, so a slow or unreachable PATH entry (for
28
+ example a disconnected network drive) could hang the server. The probe now runs
29
+ with a three-second timeout and `windowsHide`.
30
+
31
+ ## search_code excludes node_modules explicitly
32
+
33
+ The `search_code` ripgrep invocation passed `--hidden` with only a `.git`
34
+ exclusion, leaving `node_modules` out of results solely through ripgrep's
35
+ implicit gitignore stack — which fails for repositories that commit their
36
+ dependency tree or lack a gitignore. An explicit `!node_modules` glob is now
37
+ applied; a caller-supplied glob is still appended afterward and wins.
@@ -0,0 +1,21 @@
1
+ # Weavatrix 0.3.8
2
+
3
+ 0.3.8 is a documentation and internal-structure release. Tool behavior and
4
+ output are unchanged.
5
+
6
+ ## Slimmer README
7
+
8
+ The README is refocused on the current release — install, configuration, tools,
9
+ benchmarks and the security model — and the accumulated per-version changelog is
10
+ removed in favor of the existing per-version notes under
11
+ [docs/releases/](../releases/). This also slims the README rendered on the npm
12
+ package page.
13
+
14
+ ## Internal module split
15
+
16
+ `src/analysis/dead-code-review.js` is split along the repository's existing
17
+ facade convention: the per-candidate record builders (`symbolCandidate`,
18
+ `fileCandidate`) move to `src/analysis/dead-code-review/candidates.js`, while the
19
+ orchestrator and the public `computeDeadCodeReview` export stay in place.
20
+ Importers and returned records are unchanged, and both files are now within the
21
+ 300-line owner-module budget.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "weavatrix",
3
- "version": "0.3.6",
3
+ "version": "0.3.8",
4
4
  "type": "module",
5
5
  "description": "Local repository intelligence MCP for AI coding agents: reusable architecture graph for fast application understanding, Health, dead code, clones, history, blast radius and architecture safeguards.",
6
6
  "author": "Sergii Ziborov <sergii.ziborov@gmail.com>",
@@ -40,6 +40,8 @@
40
40
  "docs/releases/v0.3.4.md",
41
41
  "docs/releases/v0.3.5.md",
42
42
  "docs/releases/v0.3.6.md",
43
+ "docs/releases/v0.3.7.md",
44
+ "docs/releases/v0.3.8.md",
43
45
  "docs/releases/v0.2.19.md",
44
46
  "README.md",
45
47
  "SECURITY.md",
@@ -0,0 +1,194 @@
1
+ // Per-candidate review records for the dead-code review queue, split out of dead-code-review.js so the
2
+ // orchestrator stays within the file budget. The confidence, caveat, evidence and verification model is
3
+ // unchanged; symbolCandidate and fileCandidate are pure over the context built by computeDeadCodeReview.
4
+ import { isFrameworkEntryFile } from "../dead-check.js";
5
+ import {
6
+ hasDynamicCode, REFLECTION_CODE_RE as REFLECTION_RE, normalizedReviewPath as normalizedPath,
7
+ } from "./policy.js";
8
+
9
+ const lineOf = (node) => {
10
+ const match = /@(\d+)$/.exec(String(node?.id || "")) || /L(\d+)/.exec(String(node?.source_location || ""));
11
+ return match ? Number(match[1]) : 0;
12
+ };
13
+ const bareLabel = (value) => String(value || "").replace(/\s*\(.*$/, "").replace(/[()]/g, "").trim();
14
+
15
+ function kindOf(node) {
16
+ const symbolKind = String(node?.symbol_kind || "").toLowerCase();
17
+ if (symbolKind === "method" || symbolKind === "constructor") return "method";
18
+ if (["function", "function_definition", "func", "fn"].includes(symbolKind)) return "function";
19
+ // Old graphs may not retain symbol_kind. Only use call syntax as a compatibility fallback;
20
+ // member_of alone also describes fields and must never promote them to methods.
21
+ if (!symbolKind && /\([^)]*\)\s*$/.test(String(node?.label || ""))) return node?.member_of ? "method" : "function";
22
+ return "symbol";
23
+ }
24
+
25
+ function isPublicSurface(node) {
26
+ const visibility = String(node?.visibility || "").toLowerCase();
27
+ return node?.exported === true || visibility === "public" || visibility === "protected";
28
+ }
29
+
30
+ export function symbolCandidate(item, node, context) {
31
+ const file = normalizedPath(item.file);
32
+ const source = String(context.sources.get(file) || "");
33
+ const pathInfo = context.classify(file, source);
34
+ const publicSurface = isPublicSurface(node);
35
+ const testOnly = item.testOnly === true;
36
+ const externalEntry = context.entrySet.has(file) || isFrameworkEntryFile(file);
37
+ const framework = context.frameworkByFile.get(file) || null;
38
+ const dynamicFile = context.dynamicTargets.has(file) || hasDynamicCode(source, file);
39
+ const reflectionFile = REFLECTION_RE.test(source);
40
+ const kind = kindOf(node);
41
+ const exactNoReference = context.exactNoReferenceIds.has(String(item.id));
42
+ const internallyScoped = String(node?.visibility || "").toLowerCase() === "private"
43
+ || (!publicSurface && ["method", "function"].includes(kind));
44
+ // Static absence alone is never high-confidence dead code. High is reserved for a successfully
45
+ // queried semantic declaration whose language server also returned no in-workspace references.
46
+ let confidence = internallyScoped && exactNoReference ? "high" : "medium";
47
+ const caveats = [];
48
+
49
+ if (internallyScoped && !exactNoReference) {
50
+ caveats.push("No complete exact semantic no-reference result is available for this declaration; static absence remains medium confidence.");
51
+ }
52
+
53
+ if (publicSurface) {
54
+ confidence = "low";
55
+ caveats.push("Public/exported APIs can be consumed by downstream packages, interfaces, reflection, dependency injection, templates, or configuration outside this repository.");
56
+ }
57
+ if (externalEntry || framework) {
58
+ confidence = "low";
59
+ caveats.push(framework?.reason || "This file is an externally entered or framework-owned surface; static inbound edges are not complete usage evidence.");
60
+ }
61
+ if (node?.decorated) {
62
+ confidence = "low";
63
+ caveats.push("Decorators/annotations can register this symbol without a direct caller.");
64
+ }
65
+ if (dynamicFile) {
66
+ confidence = "low";
67
+ caveats.push("The declaring file uses or is reached through dynamic loading, so the static graph can miss callers.");
68
+ }
69
+ if (reflectionFile || (publicSurface && context.repoSignals.reflection)) {
70
+ confidence = "low";
71
+ caveats.push("Reflection is present and may invoke names without a resolvable static edge.");
72
+ }
73
+
74
+ const evidenceTier = confidence === "high" && exactNoReference
75
+ ? "STRONG_STATIC_EVIDENCE"
76
+ : confidence === "low" ? "HIGH_UNCERTAINTY" : "BOUNDED_STATIC_EVIDENCE";
77
+ const remainingChecks = [
78
+ ...(!exactNoReference ? ["Run an exact language-server reference query for this declaration."] : []),
79
+ ...(publicSurface ? ["Check downstream/external consumers of the public API."] : []),
80
+ ...(externalEntry || framework ? ["Inspect framework registration and externally entered call paths."] : []),
81
+ ...(dynamicFile ? ["Resolve dynamic import/require targets and name-based dispatch."] : []),
82
+ ...(reflectionFile || (publicSurface && context.repoSignals.reflection) ? ["Inspect reflection/annotation/configuration consumers."] : []),
83
+ "Run targeted tests after any removal.",
84
+ ];
85
+
86
+ return {
87
+ id: String(item.id),
88
+ kind,
89
+ classification: testOnly ? `test-only-${kind}` : publicSurface ? `public-${kind}` : kind === "method" ? "internal-method" : kind === "function" ? "internal-function" : "unreferenced-symbol",
90
+ file,
91
+ line: lineOf(node),
92
+ symbol: bareLabel(node?.label || item.label),
93
+ owner: node?.member_of || null,
94
+ symbolKind: node?.symbol_kind || null,
95
+ visibility: node?.visibility || (node?.exported ? "exported" : "internal"),
96
+ confidence,
97
+ evidenceTier,
98
+ actionability: evidenceTier === "STRONG_STATIC_EVIDENCE" ? "PRIORITY_MANUAL_REVIEW" : "MANUAL_REVIEW",
99
+ reason: item.reason,
100
+ evidence: [
101
+ ...(testOnly ? [{kind: item.evidence || "graph", fact: `Only test/e2e consumers were found${item.testConsumerFiles?.length ? `: ${item.testConsumerFiles.join(", ")}` : "."}`}]
102
+ : [{ kind: "graph", fact: "No inbound non-structural graph edge targets this symbol." }, { kind: "source-index", fact: "Its identifier has no second indexed occurrence that establishes a caller." }]),
103
+ ...(exactNoReference ? [{kind: "exact-lsp", fact: "The active language server returned no in-workspace references for this exact declaration."}] : []),
104
+ ],
105
+ caveats,
106
+ publicApi: publicSurface,
107
+ externallyEnteredFile: externalEntry,
108
+ pathClasses: pathInfo.classes || [],
109
+ matchedPathRule: pathInfo.matchedRule || null,
110
+ verification: {
111
+ graphInboundRuntimeEdge: "NOT_FOUND",
112
+ indexedSecondOccurrence: testOnly ? "TEST_ONLY" : "NOT_FOUND",
113
+ exactLanguageServerReferences: exactNoReference ? "ZERO_CONFIRMED" : "NOT_CHECKED_OR_INCOMPLETE",
114
+ recognizedEntryPoint: externalEntry ? "FOUND" : "NOT_FOUND",
115
+ dynamicLoadingRisk: dynamicFile ? "PRESENT" : "NOT_OBSERVED_IN_DECLARING_FILE",
116
+ reflectionRisk: reflectionFile || (publicSurface && context.repoSignals.reflection) ? "PRESENT" : "NOT_OBSERVED",
117
+ publicApi: publicSurface ? "YES" : "NO",
118
+ decision: "MANUAL_REVIEW_REQUIRED",
119
+ },
120
+ remainingChecks,
121
+ autoDelete: false,
122
+ reviewAction: testOnly
123
+ ? "Confirm that no production/config/framework consumer exists; decide whether the declaration is intentional test support or removable with its tests. Never auto-delete."
124
+ : "Confirm with read_source, get_dependents, exact search, framework/config inspection and tests; never auto-delete.",
125
+ };
126
+ }
127
+
128
+ export function fileCandidate(item, symbols, context) {
129
+ const file = normalizedPath(item.file);
130
+ const source = String(context.sources.get(file) || "");
131
+ const pathInfo = context.classify(file, source);
132
+ const publicSymbols = symbols.filter((symbol) => symbol.publicApi);
133
+ const dynamicFile = context.dynamicTargets.has(file) || hasDynamicCode(source, file);
134
+ const reflectionFile = REFLECTION_RE.test(source);
135
+ // Whole-file liveness always remains at most medium: external launchers/manifests can exist outside
136
+ // the indexed import graph even when every internal symbol signal is otherwise strong.
137
+ let confidence = "medium";
138
+ const caveats = ["Files can be launched by scripts, plugins, manifests, framework conventions, generated consumers, or external tooling without an import edge."];
139
+ if (publicSymbols.length) {
140
+ confidence = "low";
141
+ caveats.push(`${publicSymbols.length} indexed public/exported symbol(s) may be consumed outside this repository.`);
142
+ }
143
+ if (dynamicFile) {
144
+ confidence = "low";
145
+ caveats.push("Dynamic loading is present in or targets this file.");
146
+ }
147
+ if (reflectionFile) {
148
+ confidence = "low";
149
+ caveats.push("Reflection is present in this file.");
150
+ }
151
+ const remainingChecks = [
152
+ "Inspect package scripts, manifests, framework/plugin discovery and deployment configuration.",
153
+ "Check external launchers and consumers outside the indexed repository.",
154
+ ...(dynamicFile ? ["Resolve dynamic import/require targets."] : []),
155
+ ...(reflectionFile ? ["Inspect reflection/name-based consumers."] : []),
156
+ "Run targeted tests after any removal.",
157
+ ];
158
+ return {
159
+ id: `file:${file}`,
160
+ kind: "file",
161
+ classification: "unreferenced-file",
162
+ file,
163
+ line: 1,
164
+ symbol: null,
165
+ owner: null,
166
+ symbolKind: null,
167
+ visibility: null,
168
+ confidence,
169
+ evidenceTier: confidence === "low" ? "HIGH_UNCERTAINTY" : "BOUNDED_STATIC_EVIDENCE",
170
+ actionability: "MANUAL_REVIEW",
171
+ reason: item.reason,
172
+ evidence: [
173
+ { kind: "graph", fact: "No indexed module imports this file." },
174
+ { kind: "symbol-liveness", fact: "Every indexed symbol in the file is statically unreferenced." },
175
+ ],
176
+ caveats,
177
+ publicApi: publicSymbols.length > 0,
178
+ externallyEnteredFile: false,
179
+ pathClasses: pathInfo.classes || [],
180
+ matchedPathRule: pathInfo.matchedRule || null,
181
+ verification: {
182
+ graphInboundModuleEdge: "NOT_FOUND",
183
+ indexedSymbolsReferenced: "NONE",
184
+ recognizedEntryPoint: "NOT_FOUND",
185
+ dynamicLoadingRisk: dynamicFile ? "PRESENT" : "NOT_OBSERVED",
186
+ reflectionRisk: reflectionFile ? "PRESENT" : "NOT_OBSERVED",
187
+ externalConsumerCheck: "NOT_POSSIBLE_FROM_REPOSITORY_GRAPH",
188
+ decision: "MANUAL_REVIEW_REQUIRED",
189
+ },
190
+ remainingChecks,
191
+ autoDelete: false,
192
+ reviewAction: "Verify package scripts, manifests, framework discovery, dynamic loading and external consumers; never auto-delete.",
193
+ };
194
+ }
@@ -1,200 +1,16 @@
1
1
  // Conservative, source-free review queue for statically unreferenced code. This deliberately builds
2
2
  // on computeDead instead of inventing a second liveness model. Candidates are evidence for review,
3
3
  // never deletion instructions: framework entry, dynamic loading, reflection and public API surfaces
4
- // lower confidence and remain explicit in the returned record.
5
- import { computeDead, isFrameworkEntryFile } from "./dead-check.js";
4
+ // lower confidence and remain explicit in the returned record. Per-candidate record shapes live in
5
+ // dead-code-review/candidates.js; this module owns collection, filtering and the summary envelope.
6
+ import { computeDead } from "./dead-check.js";
6
7
  import { createPathClassifier } from "../path-classification.js";
7
8
  import {
8
9
  DEAD_CODE_CONFIDENCE_RANK as CONFIDENCE_RANK, hasDynamicCode,
9
10
  REFLECTION_CODE_RE as REFLECTION_RE, deadCodePathAllowed as pathAllowed,
10
11
  normalizedReviewPath as normalizedPath,
11
12
  } from './dead-code-review/policy.js'
12
- const lineOf = (node) => {
13
- const match = /@(\d+)$/.exec(String(node?.id || "")) || /L(\d+)/.exec(String(node?.source_location || ""));
14
- return match ? Number(match[1]) : 0;
15
- };
16
- const bareLabel = (value) => String(value || "").replace(/\s*\(.*$/, "").replace(/[()]/g, "").trim();
17
-
18
- function kindOf(node) {
19
- const symbolKind = String(node?.symbol_kind || "").toLowerCase();
20
- if (symbolKind === "method" || symbolKind === "constructor") return "method";
21
- if (["function", "function_definition", "func", "fn"].includes(symbolKind)) return "function";
22
- // Old graphs may not retain symbol_kind. Only use call syntax as a compatibility fallback;
23
- // member_of alone also describes fields and must never promote them to methods.
24
- if (!symbolKind && /\([^)]*\)\s*$/.test(String(node?.label || ""))) return node?.member_of ? "method" : "function";
25
- return "symbol";
26
- }
27
-
28
- function isPublicSurface(node) {
29
- const visibility = String(node?.visibility || "").toLowerCase();
30
- return node?.exported === true || visibility === "public" || visibility === "protected";
31
- }
32
-
33
- function symbolCandidate(item, node, context) {
34
- const file = normalizedPath(item.file);
35
- const source = String(context.sources.get(file) || "");
36
- const pathInfo = context.classify(file, source);
37
- const publicSurface = isPublicSurface(node);
38
- const testOnly = item.testOnly === true;
39
- const externalEntry = context.entrySet.has(file) || isFrameworkEntryFile(file);
40
- const framework = context.frameworkByFile.get(file) || null;
41
- const dynamicFile = context.dynamicTargets.has(file) || hasDynamicCode(source, file);
42
- const reflectionFile = REFLECTION_RE.test(source);
43
- const kind = kindOf(node);
44
- const exactNoReference = context.exactNoReferenceIds.has(String(item.id));
45
- const internallyScoped = String(node?.visibility || "").toLowerCase() === "private"
46
- || (!publicSurface && ["method", "function"].includes(kind));
47
- // Static absence alone is never high-confidence dead code. High is reserved for a successfully
48
- // queried semantic declaration whose language server also returned no in-workspace references.
49
- let confidence = internallyScoped && exactNoReference ? "high" : "medium";
50
- const caveats = [];
51
-
52
- if (internallyScoped && !exactNoReference) {
53
- caveats.push("No complete exact semantic no-reference result is available for this declaration; static absence remains medium confidence.");
54
- }
55
-
56
- if (publicSurface) {
57
- confidence = "low";
58
- caveats.push("Public/exported APIs can be consumed by downstream packages, interfaces, reflection, dependency injection, templates, or configuration outside this repository.");
59
- }
60
- if (externalEntry || framework) {
61
- confidence = "low";
62
- caveats.push(framework?.reason || "This file is an externally entered or framework-owned surface; static inbound edges are not complete usage evidence.");
63
- }
64
- if (node?.decorated) {
65
- confidence = "low";
66
- caveats.push("Decorators/annotations can register this symbol without a direct caller.");
67
- }
68
- if (dynamicFile) {
69
- confidence = "low";
70
- caveats.push("The declaring file uses or is reached through dynamic loading, so the static graph can miss callers.");
71
- }
72
- if (reflectionFile || (publicSurface && context.repoSignals.reflection)) {
73
- confidence = "low";
74
- caveats.push("Reflection is present and may invoke names without a resolvable static edge.");
75
- }
76
-
77
- const evidenceTier = confidence === "high" && exactNoReference
78
- ? "STRONG_STATIC_EVIDENCE"
79
- : confidence === "low" ? "HIGH_UNCERTAINTY" : "BOUNDED_STATIC_EVIDENCE";
80
- const remainingChecks = [
81
- ...(!exactNoReference ? ["Run an exact language-server reference query for this declaration."] : []),
82
- ...(publicSurface ? ["Check downstream/external consumers of the public API."] : []),
83
- ...(externalEntry || framework ? ["Inspect framework registration and externally entered call paths."] : []),
84
- ...(dynamicFile ? ["Resolve dynamic import/require targets and name-based dispatch."] : []),
85
- ...(reflectionFile || (publicSurface && context.repoSignals.reflection) ? ["Inspect reflection/annotation/configuration consumers."] : []),
86
- "Run targeted tests after any removal.",
87
- ];
88
-
89
- return {
90
- id: String(item.id),
91
- kind,
92
- classification: testOnly ? `test-only-${kind}` : publicSurface ? `public-${kind}` : kind === "method" ? "internal-method" : kind === "function" ? "internal-function" : "unreferenced-symbol",
93
- file,
94
- line: lineOf(node),
95
- symbol: bareLabel(node?.label || item.label),
96
- owner: node?.member_of || null,
97
- symbolKind: node?.symbol_kind || null,
98
- visibility: node?.visibility || (node?.exported ? "exported" : "internal"),
99
- confidence,
100
- evidenceTier,
101
- actionability: evidenceTier === "STRONG_STATIC_EVIDENCE" ? "PRIORITY_MANUAL_REVIEW" : "MANUAL_REVIEW",
102
- reason: item.reason,
103
- evidence: [
104
- ...(testOnly ? [{kind: item.evidence || "graph", fact: `Only test/e2e consumers were found${item.testConsumerFiles?.length ? `: ${item.testConsumerFiles.join(", ")}` : "."}`}]
105
- : [{ kind: "graph", fact: "No inbound non-structural graph edge targets this symbol." }, { kind: "source-index", fact: "Its identifier has no second indexed occurrence that establishes a caller." }]),
106
- ...(exactNoReference ? [{kind: "exact-lsp", fact: "The active language server returned no in-workspace references for this exact declaration."}] : []),
107
- ],
108
- caveats,
109
- publicApi: publicSurface,
110
- externallyEnteredFile: externalEntry,
111
- pathClasses: pathInfo.classes || [],
112
- matchedPathRule: pathInfo.matchedRule || null,
113
- verification: {
114
- graphInboundRuntimeEdge: "NOT_FOUND",
115
- indexedSecondOccurrence: testOnly ? "TEST_ONLY" : "NOT_FOUND",
116
- exactLanguageServerReferences: exactNoReference ? "ZERO_CONFIRMED" : "NOT_CHECKED_OR_INCOMPLETE",
117
- recognizedEntryPoint: externalEntry ? "FOUND" : "NOT_FOUND",
118
- dynamicLoadingRisk: dynamicFile ? "PRESENT" : "NOT_OBSERVED_IN_DECLARING_FILE",
119
- reflectionRisk: reflectionFile || (publicSurface && context.repoSignals.reflection) ? "PRESENT" : "NOT_OBSERVED",
120
- publicApi: publicSurface ? "YES" : "NO",
121
- decision: "MANUAL_REVIEW_REQUIRED",
122
- },
123
- remainingChecks,
124
- autoDelete: false,
125
- reviewAction: testOnly
126
- ? "Confirm that no production/config/framework consumer exists; decide whether the declaration is intentional test support or removable with its tests. Never auto-delete."
127
- : "Confirm with read_source, get_dependents, exact search, framework/config inspection and tests; never auto-delete.",
128
- };
129
- }
130
-
131
- function fileCandidate(item, symbols, context) {
132
- const file = normalizedPath(item.file);
133
- const source = String(context.sources.get(file) || "");
134
- const pathInfo = context.classify(file, source);
135
- const publicSymbols = symbols.filter((symbol) => symbol.publicApi);
136
- const dynamicFile = context.dynamicTargets.has(file) || hasDynamicCode(source, file);
137
- const reflectionFile = REFLECTION_RE.test(source);
138
- // Whole-file liveness always remains at most medium: external launchers/manifests can exist outside
139
- // the indexed import graph even when every internal symbol signal is otherwise strong.
140
- let confidence = "medium";
141
- const caveats = ["Files can be launched by scripts, plugins, manifests, framework conventions, generated consumers, or external tooling without an import edge."];
142
- if (publicSymbols.length) {
143
- confidence = "low";
144
- caveats.push(`${publicSymbols.length} indexed public/exported symbol(s) may be consumed outside this repository.`);
145
- }
146
- if (dynamicFile) {
147
- confidence = "low";
148
- caveats.push("Dynamic loading is present in or targets this file.");
149
- }
150
- if (reflectionFile) {
151
- confidence = "low";
152
- caveats.push("Reflection is present in this file.");
153
- }
154
- const remainingChecks = [
155
- "Inspect package scripts, manifests, framework/plugin discovery and deployment configuration.",
156
- "Check external launchers and consumers outside the indexed repository.",
157
- ...(dynamicFile ? ["Resolve dynamic import/require targets."] : []),
158
- ...(reflectionFile ? ["Inspect reflection/name-based consumers."] : []),
159
- "Run targeted tests after any removal.",
160
- ];
161
- return {
162
- id: `file:${file}`,
163
- kind: "file",
164
- classification: "unreferenced-file",
165
- file,
166
- line: 1,
167
- symbol: null,
168
- owner: null,
169
- symbolKind: null,
170
- visibility: null,
171
- confidence,
172
- evidenceTier: confidence === "low" ? "HIGH_UNCERTAINTY" : "BOUNDED_STATIC_EVIDENCE",
173
- actionability: "MANUAL_REVIEW",
174
- reason: item.reason,
175
- evidence: [
176
- { kind: "graph", fact: "No indexed module imports this file." },
177
- { kind: "symbol-liveness", fact: "Every indexed symbol in the file is statically unreferenced." },
178
- ],
179
- caveats,
180
- publicApi: publicSymbols.length > 0,
181
- externallyEnteredFile: false,
182
- pathClasses: pathInfo.classes || [],
183
- matchedPathRule: pathInfo.matchedRule || null,
184
- verification: {
185
- graphInboundModuleEdge: "NOT_FOUND",
186
- indexedSymbolsReferenced: "NONE",
187
- recognizedEntryPoint: "NOT_FOUND",
188
- dynamicLoadingRisk: dynamicFile ? "PRESENT" : "NOT_OBSERVED",
189
- reflectionRisk: reflectionFile ? "PRESENT" : "NOT_OBSERVED",
190
- externalConsumerCheck: "NOT_POSSIBLE_FROM_REPOSITORY_GRAPH",
191
- decision: "MANUAL_REVIEW_REQUIRED",
192
- },
193
- remainingChecks,
194
- autoDelete: false,
195
- reviewAction: "Verify package scripts, manifests, framework discovery, dynamic loading and external consumers; never auto-delete.",
196
- };
197
- }
13
+ import { symbolCandidate, fileCandidate } from './dead-code-review/candidates.js'
198
14
 
199
15
  // Pure review model. Filesystem collection/entry inference stays in the MCP adapter so tests can pass
200
16
  // exact source maps and convention evidence without touching the working tree.
package/src/mcp-rg.mjs CHANGED
@@ -43,7 +43,7 @@ export function createRgResolver(selfDir) {
43
43
  } catch { /* optional packaged ripgrep path */ }
44
44
  for (const c of editorRgCandidates()) if (existsSync(c)) return (rgPath = c)
45
45
  try {
46
- const probe = spawnSync(process.platform === 'win32' ? 'where' : 'which', ['rg'], {encoding: 'utf8', env: childProcessEnv()})
46
+ const probe = spawnSync(process.platform === 'win32' ? 'where' : 'which', ['rg'], {encoding: 'utf8', env: childProcessEnv(), timeout: 3000, windowsHide: true})
47
47
  const p = probe.status === 0 ? probe.stdout.split(/\r?\n/)[0].trim() : ''
48
48
  if (p && existsSync(p)) return (rgPath = p)
49
49
  } catch { /* optional PATH probe */ }
@@ -14,7 +14,10 @@ const MAX_SOURCE_CONTEXT_LINES = 1000
14
14
  function rgSearch(repoRoot, resolveRg, query, { isRegex, glob, maxResults }, spawnRg = spawnSync) {
15
15
  const rg = resolveRg()
16
16
  if (!rg) return null
17
- const args = ['--line-number', '--no-heading', '--color', 'never', '--hidden', '-g', '!.git/**', '-m', '100', '-i']
17
+ // Exclude node_modules explicitly: --hidden + the default gitignore stack is the only thing that
18
+ // keeps a dependency tree out, which fails for repos that commit node_modules or lack a gitignore.
19
+ // A caller-supplied glob is appended after this and still wins (rg: last matching glob decides).
20
+ const args = ['--line-number', '--no-heading', '--color', 'never', '--hidden', '-g', '!.git/**', '-g', '!node_modules', '-m', '100', '-i']
18
21
  if (!isRegex) args.push('--fixed-strings')
19
22
  if (glob) args.push('-g', glob)
20
23
  // Run from the repository root and search `.` so path globs such as `src/**` are evaluated
@@ -35,7 +35,10 @@ export const CONTENT_RULES = [
35
35
  nearZeroFp: true,
36
36
  // canonical reverse/bind shells — a shell wired to a socket. Essentially never legitimate inside a
37
37
  // published package: /dev/tcp redirection, netcat -e, interactive-shell redirect, mkfifo pipe shell.
38
- pattern: "/dev/tcp/[0-9]|\\bnc(at)?\\s+-e\\b|\\b(ba)?sh\\s+-i\\b\\s*(2)?>&|mkfifo\\b.{0,60}(ba)?sh\\b|0<&196|socket\\.socket\\(.{0,40}(SOCK_STREAM).{0,80}(/bin/sh|exec)",
38
+ // The rg pre-filter must stay a superset of `re` below: rg surfaces lines matching this string and
39
+ // only then is `re` applied to confirm, so a narrower pre-filter silently drops real reverse shells
40
+ // (e.g. socket + pty.spawn / os.dup2 / subprocess, or a default socket.socket() without SOCK_STREAM).
41
+ pattern: "/dev/tcp/[0-9]|\\bnc(at)?\\s+-e\\b|\\b(ba)?sh\\s+-i\\b\\s*(2)?>&|mkfifo\\b.{0,60}(ba)?sh\\b|0<&196|socket\\.socket\\(.{0,120}(connect|SOCK_STREAM).{0,180}(/bin/sh|subprocess|pty\\.spawn|os\\.dup2)",
39
42
  re: /\/dev\/tcp\/[0-9]|\bnc(at)?\s+-e\b|\b(ba)?sh\s+-i\b\s*(2)?>&|mkfifo\b[\s\S]{0,60}?\b(ba)?sh\b|0<&196|socket\.socket\([\s\S]{0,120}?(connect|SOCK_STREAM)[\s\S]{0,180}?(\/bin\/sh|subprocess|pty\.spawn|os\.dup2)/i,
40
43
  what: "reverse/bind-shell pattern (interactive shell wired to a socket)",
41
44
  },