Repository navigation
fix(tier2): allow contained directory aliases - #282
Conversation
A skill or collection that aliases one agent directory to another, such as `.agents -> .claude`, made `similarity-check` and `context-optimization-check` exit 1 with a "symlink or reparse point" error before any embedding, even though the link stays inside the scan root and Tier 1 discovery accepts the same tree. Only the exact `CLAUDE.md -> AGENTS.md` file alias was tolerated. Both Tier 2 walkers (inter-skill manifest discovery and intra-skill content collection) now accept an unselected directory alias without following it. The alias name must not be a manifest or scannable file type, the alias must be single-link, and its raw link text must be relative, use `..` only as leading segments, and name a directory below the scan root that is neither the root nor one of the alias's own parents. After the walk, the target must have been enumerated as a regular directory, so the canonical directory is scanned once. The alias still counts toward the discovered-path budget. Absolute links and Windows junctions, broken, escaping and chained links, non-link reparse points, and selected-name aliases remain rejected. Inter-skill discovery now finishes the walk before reading any manifest so alias validation happens before content reads. Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
7a3d1c4 to
73439af
Compare
rng1995
left a comment
There was a problem hiding this comment.
Reviewed the alias detection in the collector, the inter-skill extractor and tier2_paths. Link text is validated without following the link, targets must be re-enumerated as regular directories by the same walk (so chains, self links, ancestors, escapes, absolute and junction cases are rejected), and the excluded-directory and path-budget cases are tested. ruff is clean and the dedup, embedding, utils and CLI suites pass locally. No findings.
Reviewed with Claude Code.
Conflicted files: CHANGELOG.md Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
chrisknvidia
left a comment
There was a problem hiding this comment.
Looked at the alias check closely and found nothing blocking. The link text is read without following it, .. is only allowed at the start, absolute and drive-anchored text is rejected, own-parent and self targets are rejected, and the target has to be re-found as a real directory by the same walk, so chains, files, missing targets and case or Unicode spelling mismatches all fail closed. I also ran a few extra cases (mutual links between two real directories, two links to one target, a link to a file, a nested escape) through both walkers and they behave as the description says.
Pick up the Tier 2 contained directory alias fix (#282); no conflicts. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Narendran Raghavan <[email protected]>
Summary
Tier 2 now accepts a directory alias such as
.agents -> .claudeinside a skill or collection. The alias is never followed. The target directory is scanned once.embedding/extractor.py, used bysimilarity-check) and intra-skill content collection (deduplication/utils/skill_collector.py, used bycontext-optimization-check/dedup-scan).tier2_paths.contained_directory_alias_target. It reads only the raw link text and returns a POSIX-style relative target, orNone. It rejects:st_nlink != 1)..after a named component (a/../b)SKILL.md,skill.md,*.mdc). In the collector it is a scannable extension (.md,.mdc,.py,.sh).Noneresult raises the existing error. Otherwise the alias is recorded and dropped fromdirnames, so the walk never descends.alias -> target. This rejects chains (.agents -> .claude -> .canonical) and missing targets.evals) is still a valid target. Its contents stay excluded.docs/tier2-deduplication.mdx, untrusted-input paragraph and both edge-case tables) and CHANGELOG (Fixed) are updated.Open PR #28 moves both walkers onto a shared secure discovery helper, and that helper still rejects directory aliases. Whichever PR merges second needs to carry this behavior over. This PR does not touch #28's code.
Plugin bundles are not changed. The plugin Tier 2 commands from #250 build their inventory with
utils/secure_fs.discover_secure_filesbeforecollect_filesruns, and that discovery still rejects every linked directory. A plugin bundle with.agents -> .claudeis therefore still rejected, as onmain.Why
A skill that shares one agent directory across coding agents, for example
.agents -> .claude, could not be checked by Tier 2.similarity-check <collection> --type skillexited 1 withDiscovery path contains a symlink or reparse point: .agents.context-optimization-check <skill>exited 1 with[CONTENT_DEDUP-CRITICAL] Refusing symbolic link or reparse point: .agents.Both failed before any embedding, so no provider was needed to reproduce them. Tier 1 discovery accepts the same tree, because it skips linked directories that stay inside the root. The two tiers disagreed on the same skill.
Tier 2 already tolerated the
CLAUDE.md -> AGENTS.mdfile alias (#32, fixed by #36). This change adds the same kind of exception for a directory alias, with the same rules: never follow the link, and require the target to be found independently in the same scan.Kept from public
os.walkwalkers and the descriptor-anchored_SecureRootreads are unchanged. The shared secure discovery helper from open PR feat(plugin): Add Plugin evaluation support across all tiers #28 is not duplicated, anddiscover_secure_filesfrom Add private manifest discovery and configuration checks #250 is not duplicated or changed.unsafe_pathcheck name,rel_pathvalues, "symbolic link or reparse point" messages and suggestions. Existing tests that assert them still pass.CLAUDE.md -> AGENTS.mdalias check (is_contained_compatibility_alias) is untouched. So are excluded-directory pruning before the path budget, case-alias exclusion matching, junction and non-link reparse rejection, linked-root rejection, and the resolved-path containment check.normpathcontainment, so the claimed target always matches the physical one:..is allowed only at the start of the link text.Tests
tests/utils/test_tier2_paths.py: helper unit tests. Accepted: sibling, leading..,./. Rejected: root, parent of root, escaping, own parent, own parent by name,..after a named component, absolute text, a regular directory (readlink fails), and a hard-linked alias.tests/embedding/test_extractor.py:.claude/skills -> ../shared-skillsplus.agents -> .claudediscovers the shared skill exactly once.evalsdirectory is skipped.missing/./../../outside/ absolute targets are rejected.tests/deduplication/utils/test_skill_collector.py:.agents -> .claudecollects.claude/shared.mdonce.evalsdirectory is skipped.guide.md,helper.PY), andmissing/./../../outsideare rejected.tests/test_cli.py:similarity-checkandcontext-optimization-checkboth exit 0 on a collection with.agents -> .claude, and the shared file is embedded exactly once.main: 7 extractor/collector cases and the CLI test. Two of the 7 are the chain rejections.mainalso rejects chains, but its message does not namealias -> target. The other new rejection tests pass onmainand on this branch.pytest tests/deduplication tests/embedding tests/utils tests/test_cli.py tests/test_commands.py tests/test_catalog_discovery.py tests/validators/test_similarity.py tests/cli: 1110 passed, 6 skipped.pytest tests/test_oss_packaging.py tests/test_oss_boundary.py tests/test_oss_source_hygiene.py tests/test_benchmark_rollout_docs.py tests/test_ci_change_classifier.py tests/test_accuracy_arithmetic.py tests/test_plugin_inventory.py tests/test_plugin_discovery.py tests/test_plugin_context_cost.py tests/test_plugin_format_profiles.py tests/test_tier2_command_failures.py tests/validators: 2920 passed, 1 skipped.ruff checkandruff format --checkon the changed Python files,git diff --check, andscripts/check_oss_boundary.py: pass.test_rejects_windows_junction_before_walking_target) was not run locally. It runs in thetier2-windowsCI job. Junction link text is absolute, so the helper rejects it.🤖 Generated with Claude Code