opensrc

repository·main·Indexed 25 days ago

https://github.com/vercel-labs/opensrc

A tool that provides coding agents with programmatic access to the source code of packages across registries including npm, PyPI, and crates.io, as well as GitHub, GitLab, and Bitbucket. It fetches and caches source code locally, allowing users to resolve absolute paths to package sources via the `opensrc path` command for use with CLI tools like rg, cat, find, and grep.

Tokens
9.2K
Snippets
38
Records
85
Agent score
82%

What's inside opensrc

  1. Understand the opensrc resolution process

    main

    When you run opensrc path <package>, the tool performs the following steps to locate and provide the source code:

    1. Registry lookup: Queries the registry (e.g., npm) for package metadata.
    2. Repository detection: Extracts the repository field from package.json to find the source URL.
    3. Version tagging: Maps the version to a git tag.
    4. Shallow clone: Performs a git clone --depth 1 for the specific version.
    5. Cache storage: Saves the source in the local cache.
    6. Path output: Prints the absolute path to stdout (progress information is sent to stderr to ensure compatibility with subshells).

    Subsequent requests for the same package and version skip steps 1-4 and return the cached path immediately.

  2. Access packages from different registries

    main

    The opensrc path command supports various registries by using a prefix. This allows you to explore source code for PyPI, Crates.io, or GitHub packages.

    Examples:

    • PyPI: pypi:<package>
    • Crates.io: crates:<package>
    • GitHub: <user>/<repo>
    find $(opensrc path pypi:requests) -name "*.py"
    ls $(opensrc path crates:serde)/src/
    grep -r "Router" $(opensrc path vercel/next.js)/packages/next/src/
  3. Authenticate with GitHub

    main

    To access private GitHub repositories and increase your API rate limit from 60 to 5,000 requests/hour, set the GITHUB_TOKEN environment variable.

    Required permissions:

    • Fine-grained PAT: read-only "Contents" access to the target repositories.
    • Classic PAT: repo scope.

    Tokens are used for both resolving the default branch via the GitHub API and for git clone operations over HTTPS.

    export GITHUB_TOKEN=ghp_your_token_here
    opensrc path vercel/private-repo
  4. Set up the opensrc development environment

    main

    This project is a Turborepo monorepo using pnpm workspaces. To develop locally, ensure you are using Node.js 24+ and pnpm 11.

    Run the following commands to install dependencies and start the build/dev processes:

    pnpm install
    turbo build
    turbo dev
  5. Authenticate with Bitbucket

    main

    To access private Bitbucket repositories, set the BITBUCKET_TOKEN environment variable.

    Requirements:

    • Use a workspace, project, or repository access token with read access to the repository.
    • Bitbucket Cloud is phasing out app passwords; access tokens are preferred.

    Tokens are used for both resolving the default branch via the Bitbucket API and for git clone operations over HTTPS.

    export BITBUCKET_TOKEN=your_access_token
    opensrc path bitbucket:workspace/private-repo