fix: quiet the secret scan, narrow the CLI to what exists, name unknown intents
The secret-shaped scan walked the entire tree with rglob and filtered afterwards, so a repository with gigabytes of gitignored vendor material paid for statting all of it, and reported findings Git had already been told to ignore. It also reported every hit under ADOPT_SECRET_TRACKED regardless of whether the path was tracked, so a blocker code appeared on files that were merely present -- including an `icon-show-password.png` inside an unpacked vendor manual. A code named TRACKED firing on untracked files teaches people to ignore it. --strategy normalize and --recipe were advertised by the CLI while normalize raised unconditionally and --recipe was never read anywhere, which is the thing AGENTS.md asks us not to do. An unknown intent returned an empty bundle in silence, indistinguishable from a topic that genuinely has no content -- easy to hit by passing a topic id where an intent belongs. - prune ignored directories during the walk; drop ignored matches; skip formats that cannot carry a credential - split ADOPT_SECRET_SHAPED_UNTRACKED from the ADOPT_SECRET_TRACKED blocker - remove the normalize choice and the dead --recipe argument - warn CONTEXT_INTENT_UNKNOWN with the closest declared intents Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
a4b0fa5a8b
commit
005419a0ba
+53
-17
@@ -10,6 +10,7 @@ for this first cut beyond structural support in the AdoptionPlan schema.
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import fnmatch
|
import fnmatch
|
||||||
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
@@ -103,6 +104,14 @@ _SECRET_SHAPED_GLOBS = [
|
|||||||
".env", ".env.*", "*.env", "*password*", "*secret*", "*.pfx", "*.p12",
|
".env", ".env.*", "*.env", "*password*", "*secret*", "*.pfx", "*.p12",
|
||||||
]
|
]
|
||||||
_SECRET_EXCLUDE_SUFFIXES = (".pub", ".schema.json", ".example")
|
_SECRET_EXCLUDE_SUFFIXES = (".pub", ".schema.json", ".example")
|
||||||
|
# Name patterns like "*password*" match documentation assets such as
|
||||||
|
# `icon-show-password.png`; no credential is ever carried in these formats.
|
||||||
|
_SECRET_BINARY_SUFFIXES = (
|
||||||
|
".png", ".jpg", ".jpeg", ".gif", ".svg", ".ico", ".webp", ".bmp",
|
||||||
|
".pdf", ".epub", ".woff", ".woff2", ".ttf", ".eot",
|
||||||
|
".zip", ".gz", ".tar", ".7z", ".xz", ".mp4", ".exe", ".msi",
|
||||||
|
)
|
||||||
|
_SECRET_SKIP_DIRS = {".git", ".venv", "node_modules", "__pycache__"}
|
||||||
|
|
||||||
# Weighted because presence alone is weak evidence: `docs/` exists in almost
|
# Weighted because presence alone is weak evidence: `docs/` exists in almost
|
||||||
# every repository and must not outvote a marker that actually identifies the
|
# every repository and must not outvote a marker that actually identifies the
|
||||||
@@ -152,22 +161,42 @@ def _finding(severity: str, code: str, path: str | None = None, message: str | N
|
|||||||
return item
|
return item
|
||||||
|
|
||||||
|
|
||||||
def _detect_secret_shaped_paths(root: Path) -> list[tuple[str, bool]]:
|
def _detect_secret_shaped_paths(root: Path) -> list[tuple[str, str]]:
|
||||||
"""Return (relative_path, is_tracked) for files matching secret-shaped name patterns."""
|
"""Return (relative_path, "tracked" | "untracked") for secret-shaped filenames.
|
||||||
|
|
||||||
|
Prunes ignored directories while walking rather than filtering afterwards:
|
||||||
|
a repository may keep gigabytes of gitignored vendor material, and statting
|
||||||
|
all of it to reach a decision Git already made is pure cost. Paths the
|
||||||
|
repository deliberately ignores are dropped entirely; what matters is a
|
||||||
|
secret that is tracked, or one sitting unignored where it could be added.
|
||||||
|
"""
|
||||||
tracked = gitutil.tracked_files(root)
|
tracked = gitutil.tracked_files(root)
|
||||||
found: list[tuple[str, bool]] = []
|
matches: list[str] = []
|
||||||
for path in root.rglob("*"):
|
for dirpath, dirnames, filenames in os.walk(root):
|
||||||
if not path.is_file():
|
rel_dir = Path(dirpath).relative_to(root).as_posix()
|
||||||
|
prefix = "" if rel_dir == "." else f"{rel_dir}/"
|
||||||
|
dirnames[:] = [name for name in dirnames if name not in _SECRET_SKIP_DIRS]
|
||||||
|
if dirnames:
|
||||||
|
candidates = [f"{prefix}{name}" for name in dirnames]
|
||||||
|
skipped = gitutil.ignored(root, candidates)
|
||||||
|
dirnames[:] = [
|
||||||
|
name
|
||||||
|
for name, candidate in zip(dirnames, candidates, strict=True)
|
||||||
|
if candidate not in skipped
|
||||||
|
]
|
||||||
|
for name in filenames:
|
||||||
|
lowered = name.lower()
|
||||||
|
if lowered.endswith(_SECRET_EXCLUDE_SUFFIXES) or lowered.endswith(_SECRET_BINARY_SUFFIXES):
|
||||||
continue
|
continue
|
||||||
if ".git" in path.parts or ".venv" in path.parts or "node_modules" in path.parts:
|
if any(fnmatch.fnmatch(lowered, pattern) for pattern in _SECRET_SHAPED_GLOBS):
|
||||||
continue
|
matches.append(f"{prefix}{name}")
|
||||||
name = path.name
|
|
||||||
if name.lower().endswith(_SECRET_EXCLUDE_SUFFIXES):
|
ignored_matches = gitutil.ignored(root, matches)
|
||||||
continue
|
return [
|
||||||
if any(fnmatch.fnmatch(name.lower(), pattern) for pattern in _SECRET_SHAPED_GLOBS):
|
(rel, "tracked" if rel in tracked else "untracked")
|
||||||
rel = path.relative_to(root).as_posix()
|
for rel in matches
|
||||||
found.append((rel, rel in tracked))
|
if rel in tracked or rel not in ignored_matches
|
||||||
return found
|
]
|
||||||
|
|
||||||
|
|
||||||
def _knowledge_format(path: Path) -> str:
|
def _knowledge_format(path: Path) -> str:
|
||||||
@@ -293,11 +322,18 @@ def assess(root: Path) -> dict[str, Any]:
|
|||||||
if (root / "kdb" / "kdb.yaml").exists() and (root / "kdb.yaml").exists():
|
if (root / "kdb" / "kdb.yaml").exists() and (root / "kdb.yaml").exists():
|
||||||
findings.append(_finding("warning", "ADOPT_KDB_CANONICAL_PATH_OCCUPIED", "kdb/kdb.yaml"))
|
findings.append(_finding("warning", "ADOPT_KDB_CANONICAL_PATH_OCCUPIED", "kdb/kdb.yaml"))
|
||||||
|
|
||||||
for rel, tracked in _detect_secret_shaped_paths(root):
|
for rel, status in _detect_secret_shaped_paths(root):
|
||||||
if tracked:
|
if status == "tracked":
|
||||||
findings.append(_finding("error", "ADOPT_SECRET_TRACKED", rel, "Tracked path matches a secret-shaped filename pattern"))
|
findings.append(_finding("error", "ADOPT_SECRET_TRACKED", rel, "Tracked path matches a secret-shaped filename pattern"))
|
||||||
else:
|
else:
|
||||||
findings.append(_finding("info", "ADOPT_SECRET_TRACKED", rel, "Untracked secret-shaped path (path only, content not read)"))
|
findings.append(
|
||||||
|
_finding(
|
||||||
|
"info",
|
||||||
|
"ADOPT_SECRET_SHAPED_UNTRACKED",
|
||||||
|
rel,
|
||||||
|
"Untracked and unignored secret-shaped path (path only, content not read)",
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
if dirty:
|
if dirty:
|
||||||
findings.append(_finding("warning", "ADOPT_WORKTREE_DIRTY"))
|
findings.append(_finding("warning", "ADOPT_WORKTREE_DIRTY"))
|
||||||
|
|||||||
@@ -333,8 +333,9 @@ def build_parser() -> argparse.ArgumentParser:
|
|||||||
choices=sorted(REPOSITORY_TYPES),
|
choices=sorted(REPOSITORY_TYPES),
|
||||||
help="Confirm the repository type that assess could only propose",
|
help="Confirm the repository type that assess could only propose",
|
||||||
)
|
)
|
||||||
p_adopt.add_argument("--strategy", default="overlay", choices=["overlay", "normalize"])
|
# `normalize` and its recipes are specified but not implemented; offering the
|
||||||
p_adopt.add_argument("--recipe")
|
# choice advertised an operation that could only ever raise.
|
||||||
|
p_adopt.add_argument("--strategy", default="overlay", choices=["overlay"])
|
||||||
p_adopt.add_argument("--plan")
|
p_adopt.add_argument("--plan")
|
||||||
p_adopt.add_argument("--approve")
|
p_adopt.add_argument("--approve")
|
||||||
p_adopt.set_defaults(func=cmd_adopt)
|
p_adopt.set_defaults(func=cmd_adopt)
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import difflib
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any
|
from typing import Any
|
||||||
@@ -67,6 +68,28 @@ def build_context(
|
|||||||
matched.sort(key=lambda t: (-(t.get("priority") or 50), t.get("id") or ""))
|
matched.sort(key=lambda t: (-(t.get("priority") or 50), t.get("id") or ""))
|
||||||
topics_selected.extend(matched)
|
topics_selected.extend(matched)
|
||||||
|
|
||||||
|
if not matched:
|
||||||
|
# An empty bundle is a legitimate answer, but silence cannot distinguish
|
||||||
|
# "no topic covers this yet" from a mistyped intent -- or from reaching
|
||||||
|
# for a topic id, which is not what intents are.
|
||||||
|
known: set[str] = set()
|
||||||
|
for topic in all_topics:
|
||||||
|
if isinstance(topic, dict):
|
||||||
|
known.update(topic.get("intents") or [])
|
||||||
|
if not known:
|
||||||
|
warnings.append(
|
||||||
|
"warning:CONTEXT_INTENT_UNKNOWN:The knowledge index declares no intents yet, "
|
||||||
|
f"so no context can be selected for {intent!r}"
|
||||||
|
)
|
||||||
|
elif intent not in known:
|
||||||
|
hint = ", ".join(difflib.get_close_matches(intent, sorted(known), n=3)) or ", ".join(
|
||||||
|
sorted(known)[:3]
|
||||||
|
)
|
||||||
|
warnings.append(
|
||||||
|
f"warning:CONTEXT_INTENT_UNKNOWN:No topic declares intent {intent!r}. "
|
||||||
|
f"Closest known intents: {hint}"
|
||||||
|
)
|
||||||
|
|
||||||
if include_related:
|
if include_related:
|
||||||
related_ids: set[str] = set()
|
related_ids: set[str] = set()
|
||||||
for topic in matched:
|
for topic in matched:
|
||||||
|
|||||||
Reference in New Issue
Block a user