github-context-tools 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- github_context_tools-0.1.0/.github/workflows/ci.yml +31 -0
- github_context_tools-0.1.0/.github/workflows/publish.yml +36 -0
- github_context_tools-0.1.0/.gitignore +36 -0
- github_context_tools-0.1.0/CHANGELOG.md +20 -0
- github_context_tools-0.1.0/LICENSE +9 -0
- github_context_tools-0.1.0/PKG-INFO +163 -0
- github_context_tools-0.1.0/README.md +130 -0
- github_context_tools-0.1.0/manual_test.py +475 -0
- github_context_tools-0.1.0/pyproject.toml +51 -0
- github_context_tools-0.1.0/src/github_context_tools/__init__.py +70 -0
- github_context_tools-0.1.0/src/github_context_tools/_request.py +106 -0
- github_context_tools-0.1.0/src/github_context_tools/_utils.py +25 -0
- github_context_tools-0.1.0/src/github_context_tools/exceptions.py +18 -0
- github_context_tools-0.1.0/src/github_context_tools/models.py +157 -0
- github_context_tools-0.1.0/src/github_context_tools/py.typed +0 -0
- github_context_tools-0.1.0/src/github_context_tools/tools/__init__.py +3 -0
- github_context_tools-0.1.0/src/github_context_tools/tools/code.py +211 -0
- github_context_tools-0.1.0/src/github_context_tools/tools/conventions.py +53 -0
- github_context_tools-0.1.0/src/github_context_tools/tools/factory.py +90 -0
- github_context_tools-0.1.0/src/github_context_tools/tools/history.py +192 -0
- github_context_tools-0.1.0/src/github_context_tools/tools/issues.py +55 -0
- github_context_tools-0.1.0/src/github_context_tools/tools/pr.py +159 -0
- github_context_tools-0.1.0/tests/test_models.py +429 -0
- github_context_tools-0.1.0/tests/test_request.py +227 -0
- github_context_tools-0.1.0/tests/test_tools.py +1480 -0
- github_context_tools-0.1.0/uv.lock +189 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
test:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
strategy:
|
|
13
|
+
matrix:
|
|
14
|
+
python-version: ["3.12", "3.13"]
|
|
15
|
+
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@v4
|
|
18
|
+
|
|
19
|
+
- name: Install uv
|
|
20
|
+
uses: astral-sh/setup-uv@v4
|
|
21
|
+
with:
|
|
22
|
+
enable-cache: true
|
|
23
|
+
|
|
24
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
25
|
+
run: uv python install ${{ matrix.python-version }}
|
|
26
|
+
|
|
27
|
+
- name: Install dependencies
|
|
28
|
+
run: uv sync --all-groups
|
|
29
|
+
|
|
30
|
+
- name: Run tests
|
|
31
|
+
run: uv run pytest
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- "v*"
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
publish:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
environment: pypi
|
|
12
|
+
permissions:
|
|
13
|
+
id-token: write # required for trusted publishing
|
|
14
|
+
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@v4
|
|
17
|
+
|
|
18
|
+
- name: Install uv
|
|
19
|
+
uses: astral-sh/setup-uv@v4
|
|
20
|
+
with:
|
|
21
|
+
enable-cache: true
|
|
22
|
+
|
|
23
|
+
- name: Set up Python
|
|
24
|
+
run: uv python install 3.12
|
|
25
|
+
|
|
26
|
+
- name: Install dependencies
|
|
27
|
+
run: uv sync --all-groups
|
|
28
|
+
|
|
29
|
+
- name: Run tests
|
|
30
|
+
run: uv run pytest
|
|
31
|
+
|
|
32
|
+
- name: Build package
|
|
33
|
+
run: uv build
|
|
34
|
+
|
|
35
|
+
- name: Publish to PyPI
|
|
36
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# Environment & secrets
|
|
2
|
+
.env
|
|
3
|
+
.env.*
|
|
4
|
+
*.env
|
|
5
|
+
|
|
6
|
+
# Virtual environment
|
|
7
|
+
.venv/
|
|
8
|
+
venv/
|
|
9
|
+
env/
|
|
10
|
+
|
|
11
|
+
# Build artifacts
|
|
12
|
+
dist/
|
|
13
|
+
build/
|
|
14
|
+
*.egg-info/
|
|
15
|
+
|
|
16
|
+
# Python cache
|
|
17
|
+
__pycache__/
|
|
18
|
+
*.py[cod]
|
|
19
|
+
*.pyo
|
|
20
|
+
.mypy_cache/
|
|
21
|
+
.ruff_cache/
|
|
22
|
+
|
|
23
|
+
# Test & coverage
|
|
24
|
+
.pytest_cache/
|
|
25
|
+
.coverage
|
|
26
|
+
htmlcov/
|
|
27
|
+
|
|
28
|
+
# IDE
|
|
29
|
+
.vscode/
|
|
30
|
+
.idea/
|
|
31
|
+
|
|
32
|
+
# macOS
|
|
33
|
+
.DS_Store
|
|
34
|
+
|
|
35
|
+
# Claude
|
|
36
|
+
.claude
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format follows [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|
6
|
+
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [0.1.0] - 2026-05-23
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- `make_tools()` factory returning all tools as plain annotated callables
|
|
12
|
+
- **PR entry points**: `get_pr_metadata`, `get_parsed_pr_diff`
|
|
13
|
+
- **PR intent**: `get_pr_description`, `get_pr_comments`
|
|
14
|
+
- **Code understanding**: `get_file_at_ref`, `get_directory_tree`, `search_codebase`, `get_sibling_files`
|
|
15
|
+
- **History**: `get_file_commit_history`, `get_commit_diff`, `get_blame`
|
|
16
|
+
- **Issues**: `get_linked_issue`
|
|
17
|
+
- **Conventions**: `get_repo_conventions`
|
|
18
|
+
- Structured output models: `PRMetadata`, `PRDiff`, `PRDescription`, `PRComment`, `FileContent`, `SearchResult`, `CommitSummary`, `CommitDiff`, `BlameEntry`, `Issue`, `IssueComment`, `RepoConventions`
|
|
19
|
+
- Typed exceptions: `GitHubAPIError`, `NotFoundError`, `AuthenticationError`, `RateLimitError`
|
|
20
|
+
- Token resolution from `GH_TOKEN` / `GITHUB_TOKEN` environment variables
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Kruthi Shiva Kumar
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: github-context-tools
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Typed GitHub API tools for fetching context in LLM-based workflows
|
|
5
|
+
Project-URL: Homepage, https://github.com/kruthis123/github-context-tools
|
|
6
|
+
Project-URL: Repository, https://github.com/kruthis123/github-context-tools
|
|
7
|
+
Project-URL: Bug Tracker, https://github.com/kruthis123/github-context-tools/issues
|
|
8
|
+
Project-URL: Changelog, https://github.com/kruthis123/github-context-tools/blob/main/CHANGELOG.md
|
|
9
|
+
Author-email: Kruthi Shiva Kumar <kruthis2601@gmail.com>
|
|
10
|
+
License: MIT License
|
|
11
|
+
|
|
12
|
+
Copyright (c) 2026 Kruthi Shiva Kumar
|
|
13
|
+
|
|
14
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
15
|
+
|
|
16
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
17
|
+
|
|
18
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
19
|
+
License-File: LICENSE
|
|
20
|
+
Keywords: code-review,context,diff,github,llm,pull-request
|
|
21
|
+
Classifier: Development Status :: 3 - Alpha
|
|
22
|
+
Classifier: Intended Audience :: Developers
|
|
23
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
24
|
+
Classifier: Programming Language :: Python :: 3
|
|
25
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
26
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
27
|
+
Classifier: Topic :: Software Development :: Version Control :: Git
|
|
28
|
+
Classifier: Typing :: Typed
|
|
29
|
+
Requires-Python: >=3.12
|
|
30
|
+
Requires-Dist: git-unified-diff-parse>=0.1.1
|
|
31
|
+
Requires-Dist: httpx>=0.27
|
|
32
|
+
Description-Content-Type: text/markdown
|
|
33
|
+
|
|
34
|
+
# github-context-tools
|
|
35
|
+
|
|
36
|
+
Typed GitHub API tools that give LLMs structured access to pull requests, code, history, and issues.
|
|
37
|
+
|
|
38
|
+
## Installation
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
pip install github-context-tools
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Quickstart
|
|
45
|
+
|
|
46
|
+
```python
|
|
47
|
+
from github_context_tools import make_tools
|
|
48
|
+
|
|
49
|
+
tools = make_tools(token="ghp_...") # or set GH_TOKEN / GITHUB_TOKEN env var
|
|
50
|
+
|
|
51
|
+
# Pass the list to your agent framework's tool registry
|
|
52
|
+
agent.run(tools=tools)
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## How it works
|
|
56
|
+
|
|
57
|
+
`make_tools()` returns a list of plain Python functions. You pass that list directly to your agent framework's tool registry — no adapters or glue code needed.
|
|
58
|
+
|
|
59
|
+
Each tool is fully typed using `Annotated[type, "description"]` on every parameter and return value. Agent frameworks (Anthropic SDK, LangChain, OpenAI, etc.) read these annotations to automatically generate tool schemas, so the LLM always knows what each tool does, what to pass in, and what to expect back.
|
|
60
|
+
|
|
61
|
+
## Available tools
|
|
62
|
+
|
|
63
|
+
### Pull requests
|
|
64
|
+
|
|
65
|
+
| Tool | Description | Returns |
|
|
66
|
+
|---|---|---|
|
|
67
|
+
| [`get_pr_metadata`](https://github.com/kruthis123/github-context-tools/blob/master/src/github_context_tools/tools/pr.py#L11) | Title, author, branch names, SHAs, state, and change stats for a PR | `PRMetadata` |
|
|
68
|
+
| [`get_parsed_pr_diff`](https://github.com/kruthis123/github-context-tools/blob/master/src/github_context_tools/tools/pr.py#L46) | Structured diff of every file changed in a PR, broken into hunks and individual lines | `PRDiff` |
|
|
69
|
+
| [`get_pr_description`](https://github.com/kruthis123/github-context-tools/blob/master/src/github_context_tools/tools/pr.py#L71) | Title, body, and labels of a PR | `PRDescription` |
|
|
70
|
+
| [`get_pr_comments`](https://github.com/kruthis123/github-context-tools/blob/master/src/github_context_tools/tools/pr.py#L89) | All inline review comments and conversation comments on a PR | `list[PRComment]` |
|
|
71
|
+
|
|
72
|
+
### Code
|
|
73
|
+
|
|
74
|
+
| Tool | Description | Returns |
|
|
75
|
+
|---|---|---|
|
|
76
|
+
| [`get_file_at_ref`](https://github.com/kruthis123/github-context-tools/blob/master/src/github_context_tools/tools/code.py#L85) | Contents of a file at any branch, tag, or commit SHA | `FileContent` |
|
|
77
|
+
| [`get_directory_tree`](https://github.com/kruthis123/github-context-tools/blob/master/src/github_context_tools/tools/code.py#L115) | Recursive file tree for a repo or subdirectory at a given ref | `dict` |
|
|
78
|
+
| [`search_codebase`](https://github.com/kruthis123/github-context-tools/blob/master/src/github_context_tools/tools/code.py#L142) | Search a repo by content, file path, filename, or symbol name | `list[SearchResult]` |
|
|
79
|
+
| [`get_sibling_files`](https://github.com/kruthis123/github-context-tools/blob/master/src/github_context_tools/tools/code.py#L189) | All other files in the same directory as a given file | `list[str]` |
|
|
80
|
+
|
|
81
|
+
### History
|
|
82
|
+
|
|
83
|
+
| Tool | Description | Returns |
|
|
84
|
+
|---|---|---|
|
|
85
|
+
| [`get_file_commit_history`](https://github.com/kruthis123/github-context-tools/blob/master/src/github_context_tools/tools/history.py#L60) | Recent commits that touched a file, newest-first. Supports filtering by author, date range, and branch | `list[CommitSummary]` |
|
|
86
|
+
| [`get_commit_diff`](https://github.com/kruthis123/github-context-tools/blob/master/src/github_context_tools/tools/history.py#L123) | Structured diff introduced by a single commit | `CommitDiff` |
|
|
87
|
+
| [`get_blame`](https://github.com/kruthis123/github-context-tools/blob/master/src/github_context_tools/tools/history.py#L154) | Blame ranges for an entire file, each annotated with the commit, author, and a recency score | `list[BlameEntry]` |
|
|
88
|
+
|
|
89
|
+
### Issues
|
|
90
|
+
|
|
91
|
+
| Tool | Description | Returns |
|
|
92
|
+
|---|---|---|
|
|
93
|
+
| [`get_linked_issue`](https://github.com/kruthis123/github-context-tools/blob/master/src/github_context_tools/tools/issues.py#L9) | Title, body, author, labels, state, and comments for a GitHub issue | `Issue` |
|
|
94
|
+
|
|
95
|
+
### Conventions
|
|
96
|
+
|
|
97
|
+
| Tool | Description | Returns |
|
|
98
|
+
|---|---|---|
|
|
99
|
+
| [`get_repo_conventions`](https://github.com/kruthis123/github-context-tools/blob/master/src/github_context_tools/tools/conventions.py#L36) | Contents of well-known convention and context files from the default branch (`CONTRIBUTING.md`, `CLAUDE.md`, `AGENTS.md`, `.cursor/rules`, `.cursorrules`, `.github/copilot-instructions.md`, `docs/architecture.md`, `docs/ARCHITECTURE.md`, `docs/development.md`, `DEVELOPMENT.md`) | `RepoConventions` |
|
|
100
|
+
|
|
101
|
+
## Selecting tools
|
|
102
|
+
|
|
103
|
+
By default `make_tools()` returns all 13 tools. Use `include` or `exclude` to control which tools are registered with your agent.
|
|
104
|
+
|
|
105
|
+
**Include only the tools you need:**
|
|
106
|
+
|
|
107
|
+
```python
|
|
108
|
+
tools = make_tools(
|
|
109
|
+
token="ghp_...",
|
|
110
|
+
include={"get_pr_metadata", "get_parsed_pr_diff", "get_pr_comments"},
|
|
111
|
+
)
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
**Exclude tools you don't want:**
|
|
115
|
+
|
|
116
|
+
```python
|
|
117
|
+
tools = make_tools(
|
|
118
|
+
token="ghp_...",
|
|
119
|
+
exclude={"get_blame", "search_codebase"},
|
|
120
|
+
)
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
Both parameters accept a `set[str]` of tool names (the function names listed in the [Available tools](#available-tools) table). Unrecognised names raise a `ValueError` immediately.
|
|
124
|
+
|
|
125
|
+
## Authentication
|
|
126
|
+
|
|
127
|
+
Pass a token directly or set an environment variable:
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
export GH_TOKEN=ghp_...
|
|
131
|
+
# or
|
|
132
|
+
export GITHUB_TOKEN=ghp_...
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
```python
|
|
136
|
+
tools = make_tools(token="ghp_...")
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### Required token scopes
|
|
140
|
+
|
|
141
|
+
Use a classic personal access token (PAT) with the following scopes:
|
|
142
|
+
|
|
143
|
+
| Scope | Required for |
|
|
144
|
+
|---|---|
|
|
145
|
+
| `repo` | All tools on **private** repositories |
|
|
146
|
+
| `public_repo` | All tools on **public** repositories only |
|
|
147
|
+
|
|
148
|
+
Fine-grained PATs work too. Grant **read-only** access to the following permissions on the target repositories:
|
|
149
|
+
|
|
150
|
+
| Permission | Required for |
|
|
151
|
+
|---|---|
|
|
152
|
+
| Contents | `get_file_at_ref`, `get_directory_tree`, `get_sibling_files`, `get_repo_conventions` |
|
|
153
|
+
| Pull requests | `get_pr_metadata`, `get_parsed_pr_diff`, `get_pr_description`, `get_pr_comments` |
|
|
154
|
+
| Issues | `get_linked_issue` |
|
|
155
|
+
| Metadata | Required by GitHub for all repository access (granted automatically) |
|
|
156
|
+
|
|
157
|
+
`get_file_commit_history`, `get_commit_diff`, and `get_blame` use the Commits and GraphQL APIs, which are covered by the Contents and Metadata permissions above.
|
|
158
|
+
|
|
159
|
+
The token is captured in a closure and never appears in any tool signature, so it is never exposed to the LLM or included in generated schemas.
|
|
160
|
+
|
|
161
|
+
## License
|
|
162
|
+
|
|
163
|
+
[MIT](https://github.com/kruthis123/github-context-tools/blob/master/LICENSE)
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
# github-context-tools
|
|
2
|
+
|
|
3
|
+
Typed GitHub API tools that give LLMs structured access to pull requests, code, history, and issues.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install github-context-tools
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quickstart
|
|
12
|
+
|
|
13
|
+
```python
|
|
14
|
+
from github_context_tools import make_tools
|
|
15
|
+
|
|
16
|
+
tools = make_tools(token="ghp_...") # or set GH_TOKEN / GITHUB_TOKEN env var
|
|
17
|
+
|
|
18
|
+
# Pass the list to your agent framework's tool registry
|
|
19
|
+
agent.run(tools=tools)
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## How it works
|
|
23
|
+
|
|
24
|
+
`make_tools()` returns a list of plain Python functions. You pass that list directly to your agent framework's tool registry — no adapters or glue code needed.
|
|
25
|
+
|
|
26
|
+
Each tool is fully typed using `Annotated[type, "description"]` on every parameter and return value. Agent frameworks (Anthropic SDK, LangChain, OpenAI, etc.) read these annotations to automatically generate tool schemas, so the LLM always knows what each tool does, what to pass in, and what to expect back.
|
|
27
|
+
|
|
28
|
+
## Available tools
|
|
29
|
+
|
|
30
|
+
### Pull requests
|
|
31
|
+
|
|
32
|
+
| Tool | Description | Returns |
|
|
33
|
+
|---|---|---|
|
|
34
|
+
| [`get_pr_metadata`](https://github.com/kruthis123/github-context-tools/blob/master/src/github_context_tools/tools/pr.py#L11) | Title, author, branch names, SHAs, state, and change stats for a PR | `PRMetadata` |
|
|
35
|
+
| [`get_parsed_pr_diff`](https://github.com/kruthis123/github-context-tools/blob/master/src/github_context_tools/tools/pr.py#L46) | Structured diff of every file changed in a PR, broken into hunks and individual lines | `PRDiff` |
|
|
36
|
+
| [`get_pr_description`](https://github.com/kruthis123/github-context-tools/blob/master/src/github_context_tools/tools/pr.py#L71) | Title, body, and labels of a PR | `PRDescription` |
|
|
37
|
+
| [`get_pr_comments`](https://github.com/kruthis123/github-context-tools/blob/master/src/github_context_tools/tools/pr.py#L89) | All inline review comments and conversation comments on a PR | `list[PRComment]` |
|
|
38
|
+
|
|
39
|
+
### Code
|
|
40
|
+
|
|
41
|
+
| Tool | Description | Returns |
|
|
42
|
+
|---|---|---|
|
|
43
|
+
| [`get_file_at_ref`](https://github.com/kruthis123/github-context-tools/blob/master/src/github_context_tools/tools/code.py#L85) | Contents of a file at any branch, tag, or commit SHA | `FileContent` |
|
|
44
|
+
| [`get_directory_tree`](https://github.com/kruthis123/github-context-tools/blob/master/src/github_context_tools/tools/code.py#L115) | Recursive file tree for a repo or subdirectory at a given ref | `dict` |
|
|
45
|
+
| [`search_codebase`](https://github.com/kruthis123/github-context-tools/blob/master/src/github_context_tools/tools/code.py#L142) | Search a repo by content, file path, filename, or symbol name | `list[SearchResult]` |
|
|
46
|
+
| [`get_sibling_files`](https://github.com/kruthis123/github-context-tools/blob/master/src/github_context_tools/tools/code.py#L189) | All other files in the same directory as a given file | `list[str]` |
|
|
47
|
+
|
|
48
|
+
### History
|
|
49
|
+
|
|
50
|
+
| Tool | Description | Returns |
|
|
51
|
+
|---|---|---|
|
|
52
|
+
| [`get_file_commit_history`](https://github.com/kruthis123/github-context-tools/blob/master/src/github_context_tools/tools/history.py#L60) | Recent commits that touched a file, newest-first. Supports filtering by author, date range, and branch | `list[CommitSummary]` |
|
|
53
|
+
| [`get_commit_diff`](https://github.com/kruthis123/github-context-tools/blob/master/src/github_context_tools/tools/history.py#L123) | Structured diff introduced by a single commit | `CommitDiff` |
|
|
54
|
+
| [`get_blame`](https://github.com/kruthis123/github-context-tools/blob/master/src/github_context_tools/tools/history.py#L154) | Blame ranges for an entire file, each annotated with the commit, author, and a recency score | `list[BlameEntry]` |
|
|
55
|
+
|
|
56
|
+
### Issues
|
|
57
|
+
|
|
58
|
+
| Tool | Description | Returns |
|
|
59
|
+
|---|---|---|
|
|
60
|
+
| [`get_linked_issue`](https://github.com/kruthis123/github-context-tools/blob/master/src/github_context_tools/tools/issues.py#L9) | Title, body, author, labels, state, and comments for a GitHub issue | `Issue` |
|
|
61
|
+
|
|
62
|
+
### Conventions
|
|
63
|
+
|
|
64
|
+
| Tool | Description | Returns |
|
|
65
|
+
|---|---|---|
|
|
66
|
+
| [`get_repo_conventions`](https://github.com/kruthis123/github-context-tools/blob/master/src/github_context_tools/tools/conventions.py#L36) | Contents of well-known convention and context files from the default branch (`CONTRIBUTING.md`, `CLAUDE.md`, `AGENTS.md`, `.cursor/rules`, `.cursorrules`, `.github/copilot-instructions.md`, `docs/architecture.md`, `docs/ARCHITECTURE.md`, `docs/development.md`, `DEVELOPMENT.md`) | `RepoConventions` |
|
|
67
|
+
|
|
68
|
+
## Selecting tools
|
|
69
|
+
|
|
70
|
+
By default `make_tools()` returns all 13 tools. Use `include` or `exclude` to control which tools are registered with your agent.
|
|
71
|
+
|
|
72
|
+
**Include only the tools you need:**
|
|
73
|
+
|
|
74
|
+
```python
|
|
75
|
+
tools = make_tools(
|
|
76
|
+
token="ghp_...",
|
|
77
|
+
include={"get_pr_metadata", "get_parsed_pr_diff", "get_pr_comments"},
|
|
78
|
+
)
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
**Exclude tools you don't want:**
|
|
82
|
+
|
|
83
|
+
```python
|
|
84
|
+
tools = make_tools(
|
|
85
|
+
token="ghp_...",
|
|
86
|
+
exclude={"get_blame", "search_codebase"},
|
|
87
|
+
)
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Both parameters accept a `set[str]` of tool names (the function names listed in the [Available tools](#available-tools) table). Unrecognised names raise a `ValueError` immediately.
|
|
91
|
+
|
|
92
|
+
## Authentication
|
|
93
|
+
|
|
94
|
+
Pass a token directly or set an environment variable:
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
export GH_TOKEN=ghp_...
|
|
98
|
+
# or
|
|
99
|
+
export GITHUB_TOKEN=ghp_...
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
tools = make_tools(token="ghp_...")
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### Required token scopes
|
|
107
|
+
|
|
108
|
+
Use a classic personal access token (PAT) with the following scopes:
|
|
109
|
+
|
|
110
|
+
| Scope | Required for |
|
|
111
|
+
|---|---|
|
|
112
|
+
| `repo` | All tools on **private** repositories |
|
|
113
|
+
| `public_repo` | All tools on **public** repositories only |
|
|
114
|
+
|
|
115
|
+
Fine-grained PATs work too. Grant **read-only** access to the following permissions on the target repositories:
|
|
116
|
+
|
|
117
|
+
| Permission | Required for |
|
|
118
|
+
|---|---|
|
|
119
|
+
| Contents | `get_file_at_ref`, `get_directory_tree`, `get_sibling_files`, `get_repo_conventions` |
|
|
120
|
+
| Pull requests | `get_pr_metadata`, `get_parsed_pr_diff`, `get_pr_description`, `get_pr_comments` |
|
|
121
|
+
| Issues | `get_linked_issue` |
|
|
122
|
+
| Metadata | Required by GitHub for all repository access (granted automatically) |
|
|
123
|
+
|
|
124
|
+
`get_file_commit_history`, `get_commit_diff`, and `get_blame` use the Commits and GraphQL APIs, which are covered by the Contents and Metadata permissions above.
|
|
125
|
+
|
|
126
|
+
The token is captured in a closure and never appears in any tool signature, so it is never exposed to the LLM or included in generated schemas.
|
|
127
|
+
|
|
128
|
+
## License
|
|
129
|
+
|
|
130
|
+
[MIT](https://github.com/kruthis123/github-context-tools/blob/master/LICENSE)
|