Skip to content

Resolution

dotagents._resolve

Contract A resolution for dotagents.

Preserves the precedence walk and filename resolution from the precursor agentic.

get_file_paths(*names, agents_dir, project_root, global_scope=False, include_missing=False)

Resolve file paths across the precedence hierarchy (Contract A).

Precedence order: 1. overlays (in ~/.agents/overlays or equivalent) 2. system (/etc/agents) 3. user (agents_dir) 4. project (project_root / .agents) -- skipped if global_scope 5. project-root (project_root) -- skipped if global_scope

Source code in src/dotagents/_resolve.py
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
def get_file_paths(
    *names: str | dict[str, str],
    agents_dir: Path,
    project_root: Path,
    global_scope: bool = False,
    include_missing: bool = False,
) -> list[tuple[str, Path, Path | None]]:
    """Resolve file paths across the precedence hierarchy (Contract A).

    Precedence order:
    1. overlays (in ~/.agents/overlays or equivalent)
    2. system (/etc/agents)
    3. user (agents_dir)
    4. project (project_root / .agents) -- skipped if global_scope
    5. project-root (project_root) -- skipped if global_scope
    """
    files: list[tuple[str, Path, Path | None]] = []

    def add_name_paths(
        location: Path, level: str, root: Path | None = None, is_overlay: bool = False
    ) -> None:
        for name in names:
            if isinstance(name, str):
                name_dict = {level: name}
            else:
                name_dict = name

            default = name_dict.get("default")
            if is_overlay:
                default = name_dict.get("overlay", default)

            template = name_dict.get(level, default)
            if not template:
                continue

            files.append((level, location / template, root))

    # 1. Overlays
    #
    # An installed overlay is any directory under ``overlays/`` whose name is a
    # valid overlay name -- the EXACT rule ``_scope.discover_overlays`` uses (the
    # two must agree on what counts). No manifest of any kind is required -- not
    # ``CONTEXT.md``, not ``overlay.toml``. The old ``CONTEXT.md`` gate was a
    # precursor leftover (`agentic` used CONTEXT.md as an overlay manifest;
    # dotagents ships none) that silently excluded EVERY real dotagents overlay
    # from the Contract-A walk -- overlay-level bin/env/cmds resolution never fired
    # (D84). ``is_valid_overlay_name`` skips ``.git``/``__pycache__``/dotfiles.
    from dotagents._scope import is_valid_overlay_name

    overlay_root = agents_dir / "overlays"
    if overlay_root.is_dir():
        for overlay_dir in sorted(overlay_root.iterdir()):
            if overlay_dir.is_dir() and is_valid_overlay_name(overlay_dir.name):
                add_name_paths(
                    overlay_dir, overlay_dir.name, root=overlay_dir, is_overlay=True
                )

    # 2. System
    add_name_paths(Path("/etc/agents"), "system")

    # 3. User
    add_name_paths(agents_dir, "user")

    # 4 & 5. Project (if not global)
    if not global_scope:
        add_name_paths(project_root / ".agents", "project")
        add_name_paths(project_root, "project-root")

    if include_missing:
        return files
    return [(level, path, root) for level, path, root in files if path.exists()]