Commit 356b58c
committed
fix(scan): disable user-scope walk when CLI scans a single file
PR #53 closed the cross-scan leak for skill-dir scans but not for
single-file scans of configs like ~/.claude/settings.json. Symptom:
$ codegate-ai scan ~/.claude/settings.json
→ finding with file_path=~/.agents/skills/api-design-guide/.../SKILL.md
Root cause: the CLI stages single-file targets into a temp dir outside
$HOME. The staged dir is not inside homeDir, so
shouldKeepUserScopeCandidate short-circuits to `return true` and every
sibling user-scope match (e.g. a hidden-unicode hit in a completely
unrelated skill) gets attributed to the config scan.
Fix:
- cli.ts: when resolvedTarget.explicitCandidates is non-empty (the
target was a staged local file), force scan_user_scope=false for that
scan. Explicit opt-in via --include-user-scope still overrides. This
matches user expectation: "scan this file" ≠ "scan my whole home."
- scan.ts: shouldKeepUserScopeCandidate now also handles engine-level
file targets correctly (if the target is a file inside homeDir, only
the target file itself is a valid user-scope candidate). This is
defence in depth for library callers that bypass the CLI.
Tests:
- Existing 3 cases in tests/layer2/cross-scan-attribution.test.ts still
pass.
- New: engine-level file-target scan drops sibling user-scope candidates.
Verified 154 test files / 720 tests pass. Lint + prettier clean.1 parent 98cd395 commit 356b58c
3 files changed
Lines changed: 92 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
493 | 493 | | |
494 | 494 | | |
495 | 495 | | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
496 | 503 | | |
497 | | - | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
498 | 509 | | |
499 | 510 | | |
500 | 511 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
260 | 260 | | |
261 | 261 | | |
262 | 262 | | |
263 | | - | |
264 | | - | |
265 | | - | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
266 | 267 | | |
267 | | - | |
268 | | - | |
269 | | - | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
270 | 277 | | |
271 | 278 | | |
272 | 279 | | |
273 | 280 | | |
274 | 281 | | |
275 | 282 | | |
276 | | - | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
277 | 306 | | |
278 | 307 | | |
| 308 | + | |
| 309 | + | |
279 | 310 | | |
280 | 311 | | |
281 | 312 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
155 | 155 | | |
156 | 156 | | |
157 | 157 | | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
158 | 200 | | |
0 commit comments