AgentSkillsCN

opensrc

从npm、PyPI、crates.io包以及GitHub/GitLab仓库中抓取源代码,为AI代理提供超越类型与文档的实现上下文。当您需要深入理解某个库的内部运作、排查依赖问题,或探索包的实现细节时,此功能便能大显身手。

SKILL.md
--- frontmatter
name: opensrc
description: Fetch source code for npm, PyPI, or crates.io packages and GitHub/GitLab repos to provide AI agents with implementation context beyond types and docs. Use when needing to understand how a library works internally, debug dependency issues, or explore package implementations.

opensrc

CLI tool to fetch source code for packages/repos, giving AI coding agents deeper implementation context.

When to Use

  • Need to understand how a library/package works internally (not just its interface)
  • Debugging issues where types alone are insufficient
  • Exploring implementation patterns in dependencies
  • Agent needs to reference actual source code of a package

Quick Start

bash
# Install globally or use bunx
bun add -g opensrc

# Fetch npm package (auto-detects installed version from lockfile)
bunx opensrc zod

# Fetch from other registries
bunx opensrc pypi:requests       # Python/PyPI
bunx opensrc crates:serde        # Rust/crates.io

# Fetch GitHub repo directly
bunx opensrc vercel/ai           # owner/repo shorthand
bunx opensrc github:owner/repo   # explicit prefix
bunx opensrc https://github.com/colinhacks/zod  # full URL

# Fetch specific version/ref
bunx opensrc zod@3.22.0
bunx opensrc owner/repo@v1.0.0

Commands

CommandDescription
opensrc <packages...>Fetch source for packages/repos
opensrc listList all fetched sources
opensrc remove <name>Remove specific source
opensrc cleanRemove all sources

Output Structure

After fetching, sources stored in opensrc/ directory:

code
opensrc/
├── settings.json           # User preferences
├── sources.json            # Index of fetched packages/repos
└── repos/
    └── github.com/
        └── owner/
            └── repo/       # Cloned source code

File Modifications

On first run, opensrc prompts to modify:

  • .gitignore - adds opensrc/ to ignore list
  • tsconfig.json - excludes opensrc/ from compilation
  • AGENTS.md - adds section pointing agents to source code

Use --modify or --modify=false to skip prompt.

Key Behaviors

  1. Version Detection - For npm, auto-detects installed version from node_modules, package-lock.json, pnpm-lock.yaml, or yarn.lock
  2. Repository Resolution - Resolves package to its git repo via registry API, clones at matching tag
  3. Monorepo Support - Handles packages in monorepos via repository.directory field
  4. Shallow Clone - Uses --depth 1 for efficient cloning, removes .git after clone
  5. Tag Fallback - Tries v{version}, {version}, then default branch if tag not found

Common Workflows

Fetching a Package

bash
# Agent needs to understand zod's implementation
bunx opensrc zod
# → Detects version from lockfile
# → Finds repo URL from npm registry
# → Clones at matching git tag
# → Source available at opensrc/repos/github.com/colinhacks/zod/

Updating Sources

bash
# Re-run same command to update to currently installed version
bunx opensrc zod
# → Checks if version changed
# → Re-clones if needed

Multiple Sources

bash
# Fetch multiple at once
bunx opensrc react react-dom next
bunx opensrc zod pypi:pydantic vercel/ai

References

For detailed information: