AgentSkillsCN

project_utils

从 langchain 导入项目实用工具技能

SKILL.md
--- frontmatter
description: Imported skill project_utils from langchain
name: project_utils
signature: 9d9f2571bd799b99518324419075f20cde57364792e5e27130b92d0455a28ec6
source: /a0/tmp/skills_research/langchain/libs/deepagents-cli/deepagents_cli/project_utils.py

"""Utilities for project root detection and project-specific configuration."""

from pathlib import Path

def find_project_root(start_path: Path | None = None) -> Path | None: """Find the project root by looking for .git directory.

code
Walks up the directory tree from start_path (or cwd) looking for a .git
directory, which indicates the project root.

Args:
    start_path: Directory to start searching from. Defaults to current working directory.

Returns:
    Path to the project root if found, None otherwise.
"""
current = Path(start_path or Path.cwd()).resolve()

# Walk up the directory tree
for parent in [current, *list(current.parents)]:
    git_dir = parent / ".git"
    if git_dir.exists():
        return parent

return None

def find_project_agent_md(project_root: Path) -> list[Path]: """Find project-specific agent.md file(s).

code
Checks two locations and returns ALL that exist:
1. project_root/.deepagents/agent.md
2. project_root/agent.md

Both files will be loaded and combined if both exist.

Args:
    project_root: Path to the project root directory.

Returns:
    List of paths to project agent.md files (may contain 0, 1, or 2 paths).
"""
paths = []

# Check .deepagents/agent.md (preferred)
deepagents_md = project_root / ".deepagents" / "agent.md"
if deepagents_md.exists():
    paths.append(deepagents_md)

# Check root agent.md (fallback, but also include if both exist)
root_md = project_root / "agent.md"
if root_md.exists():
    paths.append(root_md)

return paths