Skip to content

fix(tier2): allow contained directory aliases - #282

Merged
rng1995 merged 2 commits into
mainfrom
naren/port-tier2-contained-aliases
Nov 5, 2026
Merged

rng1995 merged 2 commits into
mainfrom
naren/port-tier2-contained-aliases

Conversation

@rng1995

@rng1995 rng1995 commented Oct 30, 2026

Copy link
Copy Markdown
Collaborator

Summary

Tier 2 now accepts a directory alias such as .agents -> .claude inside a skill or collection. The alias is never followed. The target directory is scanned once.

  • Both Tier 2 walkers. This covers inter-skill manifest discovery (embedding/extractor.py, used by similarity-check) and intra-skill content collection (deduplication/utils/skill_collector.py, used by context-optimization-check / dedup-scan).
  • New helper tier2_paths.contained_directory_alias_target. It reads only the raw link text and returns a POSIX-style relative target, or None. It rejects:
    • empty text or text containing NUL, and hard-linked aliases (st_nlink != 1)
    • text with an anchor: absolute paths, drive paths and Windows root-relative paths. Windows junctions have absolute targets, so they are rejected too.
    • text that climbs past the scan root, or has .. after a named component (a/../b)
    • targets that name the scan root or one of the alias's own parent directories (a cycle)
  • Walk rules.
    • A linked directory whose name is a selected type stays rejected. In the extractor that is a manifest name (SKILL.md, skill.md, *.mdc). In the collector it is a scannable extension (.md, .mdc, .py, .sh).
    • Any other linked directory goes through the helper. A None result raises the existing error. Otherwise the alias is recorded and dropped from dirnames, so the walk never descends.
    • After the walk, each recorded target must have been enumerated as a regular directory in the same walk. Otherwise the walker raises an error naming alias -> target. This rejects chains (.agents -> .claude -> .canonical) and missing targets.
    • A pruned regular directory (for example evals) is still a valid target. Its contents stay excluded.
    • In the collector, the alias still counts toward the 4,096-path budget, and it is skipped before the per-file link check.
  • Validation before reads. Inter-skill discovery now finishes the walk and validates aliases before it reads any manifest. Before, it read manifests as it walked.
  • Docs (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_files before collect_files runs, and that discovery still rejects every linked directory. A plugin bundle with .agents -> .claude is therefore still rejected, as on main.

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 skill exited 1 with Discovery 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.md file 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

  • Walker structure. Both os.walk walkers and the descriptor-anchored _SecureRoot reads are unchanged. The shared secure discovery helper from open PR feat(plugin): Add Plugin evaluation support across all tiers #28 is not duplicated, and discover_secure_files from Add private manifest discovery and configuration checks #250 is not duplicated or changed.
  • Error contract. Rejected redirects keep the existing unsafe_path check name, rel_path values, "symbolic link or reparse point" messages and suggestions. Existing tests that assert them still pass.
  • Existing protections. The CLAUDE.md -> AGENTS.md alias 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.
  • Hardening beyond a purely lexical check. Two cases are stricter than plain normpath containment, so the claimed target always matches the physical one:
    • .. is allowed only at the start of the link text.
    • Targets that name one of the alias's own parent directories are rejected.

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-skills plus .agents -> .claude discovers the shared skill exactly once.
    • An alias to a pruned evals directory is skipped.
    • Chains, manifest-named aliases, and missing / . / .. / ../outside / absolute targets are rejected.
  • tests/deduplication/utils/test_skill_collector.py:
    • .agents -> .claude collects .claude/shared.md once.
    • The alias counts toward the path budget.
    • An alias to a pruned evals directory is skipped.
    • Chains, scannable-named aliases (guide.md, helper.PY), and missing / . / .. / ../outside are rejected.
  • tests/test_cli.py: similarity-check and context-optimization-check both exit 0 on a collection with .agents -> .claude, and the shared file is embedded exactly once.
  • 8 new tests fail on main: 7 extractor/collector cases and the CLI test. Two of the 7 are the chain rejections. main also rejects chains, but its message does not name alias -> target. The other new rejection tests pass on main and 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 check and ruff format --check on the changed Python files, git diff --check, and scripts/check_oss_boundary.py: pass.
  • The Windows-only junction test (test_rejects_windows_junction_before_walking_target) was not run locally. It runs in the tier2-windows CI job. Junction link text is absolute, so the helper rejects it.

🤖 Generated with Claude Code

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]>

@rng1995 rng1995 left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 chrisknvidia left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@rng1995
rng1995 merged commit fc900e0 into main Nov 5, 2026
21 checks passed
@rng1995
rng1995 deleted the naren/port-tier2-contained-aliases branch November 5, 2026 17:01
rng1995 added a commit that referenced this pull request Nov 5, 2026
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]>
@rng1995 rng1995 mentioned this pull request Nov 6, 2026
7 of 8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants