@gkoreli/ghx 0.1.0
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.
- package/LICENSE +21 -0
- package/README.md +101 -0
- package/ggcode +192 -0
- package/package.json +19 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Goga Koreli
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# ggcode
|
|
2
|
+
|
|
3
|
+
GitHub code exploration for agents and humans. One command does what takes 3-5 API calls with any other tool.
|
|
4
|
+
|
|
5
|
+
- **Explore** a repo (tree + README) in 1 API call
|
|
6
|
+
- **Read** 1-10 files in 1 API call via GraphQL batching
|
|
7
|
+
- **Map** code structure with ~92% token reduction
|
|
8
|
+
- **Search** code with full GitHub search syntax
|
|
9
|
+
|
|
10
|
+
~135 lines of bash. One dependency: `gh` CLI.
|
|
11
|
+
|
|
12
|
+
## Install
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
# Homebrew (macOS/Linux)
|
|
16
|
+
brew install gkoreli/tap/ggcode
|
|
17
|
+
|
|
18
|
+
# gh extension (coming soon — requires separate gh-ggcode repo)
|
|
19
|
+
gh extension install gkoreli/gh-ggcode
|
|
20
|
+
|
|
21
|
+
# npx (zero install)
|
|
22
|
+
npx ggcode --help
|
|
23
|
+
|
|
24
|
+
# curl
|
|
25
|
+
curl -sf https://raw.githubusercontent.com/gkoreli/ggcode/main/install.sh | sh
|
|
26
|
+
|
|
27
|
+
# Manual — just copy the script
|
|
28
|
+
curl -sf https://raw.githubusercontent.com/gkoreli/ggcode/main/ggcode -o ~/.local/bin/ggcode && chmod +x ~/.local/bin/ggcode
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Requires [`gh` CLI](https://cli.github.com/) authenticated (`gh auth login`).
|
|
32
|
+
|
|
33
|
+
## Usage
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
# Explore a repo — branch, file tree, and README in 1 API call
|
|
37
|
+
ggcode explore plausible/analytics
|
|
38
|
+
|
|
39
|
+
# Read multiple files in 1 API call
|
|
40
|
+
ggcode read plausible/analytics mix.exs assets/js/dashboard/stats/bar.js
|
|
41
|
+
|
|
42
|
+
# Code map — signatures, imports, types only (~92% token reduction)
|
|
43
|
+
ggcode read plausible/analytics --map lib/plausible/stats/query.ex
|
|
44
|
+
|
|
45
|
+
# Grep within a remote file (2 lines context)
|
|
46
|
+
ggcode read plausible/analytics --grep "defmodule" lib/plausible/stats/query.ex
|
|
47
|
+
|
|
48
|
+
# Read specific line range
|
|
49
|
+
ggcode read plausible/analytics --lines 42-80 lib/plausible/stats/query.ex
|
|
50
|
+
|
|
51
|
+
# Search code (full GitHub search syntax)
|
|
52
|
+
ggcode search "useState repo:facebook/react"
|
|
53
|
+
ggcode search "path:llms.txt extension:txt"
|
|
54
|
+
|
|
55
|
+
# Full recursive tree
|
|
56
|
+
ggcode tree plausible/analytics assets/js
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Why
|
|
60
|
+
|
|
61
|
+
AI agents exploring GitHub repos face a tooling gap:
|
|
62
|
+
|
|
63
|
+
| Tool | Files per API call | Context overhead | Dependencies |
|
|
64
|
+
|------|-------------------|-----------------|-------------|
|
|
65
|
+
| GitHub MCP | 1 | ~10K tokens (50+ tool schemas) | Go binary |
|
|
66
|
+
| Octocode MCP | 1 (parallel) | ~10K tokens | npm + Docker |
|
|
67
|
+
| Raw `gh` CLI | 1 | 0 | `gh` |
|
|
68
|
+
| Gitingest | N (clones first) | 0 | pip + tiktoken |
|
|
69
|
+
| **ggcode** | **1-10 (GraphQL batch)** | **0** | **`gh`** |
|
|
70
|
+
|
|
71
|
+
`ggcode` reads 10 files in 1 API call. No other tool does this.
|
|
72
|
+
|
|
73
|
+
## Code Map (`--map`)
|
|
74
|
+
|
|
75
|
+
The `--map` flag extracts only structural declarations — imports, exports, function signatures, class definitions, type declarations. Implementation bodies are stripped.
|
|
76
|
+
|
|
77
|
+
Tested on 6 real files across TypeScript, Python, and Go:
|
|
78
|
+
|
|
79
|
+
| File | Full | Map | Reduction |
|
|
80
|
+
|------|------|-----|-----------|
|
|
81
|
+
| repomix/parseFile.ts | 5,599 | 812 | 86% |
|
|
82
|
+
| github-mcp/repositories.go | 68,862 | 1,551 | 97.7% |
|
|
83
|
+
| aider/repomap.py | 27,346 | 1,496 | 94.5% |
|
|
84
|
+
|
|
85
|
+
Average: **92% reduction**. An agent can map 16 files in the space of reading 1 file fully.
|
|
86
|
+
|
|
87
|
+
Supported: TypeScript/JavaScript, Python, Go, Rust, Java/Kotlin, Ruby. Falls back to generic pattern for unknown extensions.
|
|
88
|
+
|
|
89
|
+
## How It Works
|
|
90
|
+
|
|
91
|
+
`ggcode` wraps `gh` CLI with GraphQL batching. The `explore` command fetches tree + README in 1 GraphQL call. The `read` command uses GraphQL aliases (`f0:`, `f1:`, ...) to fetch up to 10 files in 1 call. The `search` command hits the REST `/search/code` endpoint directly (GraphQL has no code search).
|
|
92
|
+
|
|
93
|
+
The `--map` flag applies per-language regex patterns to extract structural declarations from the fetched content. No Tree-sitter, no AST parsing — just regex on the first line of each declaration. This works because structural declarations in most languages start at the beginning of a line with a keyword (`function`, `class`, `def`, `func`, `export`, `import`, etc.).
|
|
94
|
+
|
|
95
|
+
## License
|
|
96
|
+
|
|
97
|
+
MIT
|
|
98
|
+
|
|
99
|
+
## For AI Agents
|
|
100
|
+
|
|
101
|
+
See [`SKILL.md`](./SKILL.md) for agent-optimized instructions — chain of thought, gotchas, anti-patterns, and examples.
|
package/ggcode
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# ggcode — GitHub code exploration for agents and humans
|
|
3
|
+
# Efficient GitHub repo exploration via GraphQL batching, code maps, and targeted extraction.
|
|
4
|
+
# One command does what takes 3-5 API calls with any other tool.
|
|
5
|
+
|
|
6
|
+
set -euo pipefail
|
|
7
|
+
|
|
8
|
+
cmd="${1:-help}"
|
|
9
|
+
shift || true
|
|
10
|
+
|
|
11
|
+
case "$cmd" in
|
|
12
|
+
|
|
13
|
+
# ─── explore: branch + tree + README in one GraphQL call ───
|
|
14
|
+
explore)
|
|
15
|
+
repo="$1"; shift || true
|
|
16
|
+
path="${1:-}"
|
|
17
|
+
owner="${repo%%/*}"
|
|
18
|
+
name="${repo##*/}"
|
|
19
|
+
|
|
20
|
+
# First get default branch
|
|
21
|
+
branch=$(gh repo view "$repo" --json defaultBranchRef --jq '.defaultBranchRef.name')
|
|
22
|
+
|
|
23
|
+
if [[ -z "$path" ]]; then
|
|
24
|
+
# Root exploration: tree + README
|
|
25
|
+
gh api graphql -f query="
|
|
26
|
+
{
|
|
27
|
+
repository(owner: \"$owner\", name: \"$name\") {
|
|
28
|
+
description
|
|
29
|
+
tree: object(expression: \"$branch:\") {
|
|
30
|
+
... on Tree { entries { name type } }
|
|
31
|
+
}
|
|
32
|
+
readme: object(expression: \"$branch:README.md\") {
|
|
33
|
+
... on Blob { text }
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}" --jq '{
|
|
37
|
+
description: .data.repository.description,
|
|
38
|
+
branch: "'"$branch"'",
|
|
39
|
+
files: [.data.repository.tree.entries[] | "\(if .type == "tree" then .name + "/" else .name end)"],
|
|
40
|
+
readme: (.data.repository.readme.text // "(no README.md)")
|
|
41
|
+
}'
|
|
42
|
+
else
|
|
43
|
+
# Subdir exploration: tree listing
|
|
44
|
+
gh api graphql -f query="
|
|
45
|
+
{
|
|
46
|
+
repository(owner: \"$owner\", name: \"$name\") {
|
|
47
|
+
tree: object(expression: \"$branch:$path\") {
|
|
48
|
+
... on Tree { entries { name type } }
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}" --jq '{
|
|
52
|
+
path: "'"$path"'",
|
|
53
|
+
entries: [.data.repository.tree.entries[] | "\(if .type == "tree" then .name + "/" else .name end)"]
|
|
54
|
+
}'
|
|
55
|
+
fi
|
|
56
|
+
;;
|
|
57
|
+
|
|
58
|
+
# ─── read: read 1-10 files in one GraphQL call ───
|
|
59
|
+
# Supports --grep "pattern" to filter output to matching lines (with 2 lines context)
|
|
60
|
+
# Supports --lines N-M to extract specific line ranges
|
|
61
|
+
read)
|
|
62
|
+
repo="$1"; shift
|
|
63
|
+
owner="${repo%%/*}"
|
|
64
|
+
name="${repo##*/}"
|
|
65
|
+
|
|
66
|
+
# Parse flags (must come before file paths)
|
|
67
|
+
grep_pattern=""
|
|
68
|
+
line_range=""
|
|
69
|
+
map_mode=""
|
|
70
|
+
files=()
|
|
71
|
+
while [[ $# -gt 0 ]]; do
|
|
72
|
+
case "$1" in
|
|
73
|
+
--grep) grep_pattern="$2"; shift 2 ;;
|
|
74
|
+
--lines) line_range="$2"; shift 2 ;;
|
|
75
|
+
--map) map_mode=1; shift ;;
|
|
76
|
+
*) files+=("$1"); shift ;;
|
|
77
|
+
esac
|
|
78
|
+
done
|
|
79
|
+
|
|
80
|
+
if [[ ${#files[@]} -eq 0 ]]; then
|
|
81
|
+
echo "Usage: ggcode read <owner/repo> <path1> [path2] [--grep pattern] [--lines N-M]" >&2
|
|
82
|
+
exit 1
|
|
83
|
+
fi
|
|
84
|
+
|
|
85
|
+
# Get default branch
|
|
86
|
+
branch=$(gh repo view "$repo" --json defaultBranchRef --jq '.defaultBranchRef.name')
|
|
87
|
+
|
|
88
|
+
# Build GraphQL query with aliases
|
|
89
|
+
query="{ repository(owner: \"$owner\", name: \"$name\") {"
|
|
90
|
+
for i in "${!files[@]}"; do
|
|
91
|
+
query+=" f$i: object(expression: \"$branch:${files[$i]}\") { ... on Blob { text byteSize } }"
|
|
92
|
+
done
|
|
93
|
+
query+=" } }"
|
|
94
|
+
|
|
95
|
+
# Execute and format output
|
|
96
|
+
result=$(gh api graphql -f query="$query")
|
|
97
|
+
|
|
98
|
+
for i in "${!files[@]}"; do
|
|
99
|
+
text=$(echo "$result" | jq -r ".data.repository.f$i.text // empty")
|
|
100
|
+
size=$(echo "$result" | jq -r ".data.repository.f$i.byteSize // empty")
|
|
101
|
+
if [[ -n "$text" ]]; then
|
|
102
|
+
echo "=== ${files[$i]} ($size bytes) ==="
|
|
103
|
+
if [[ -n "$grep_pattern" ]]; then
|
|
104
|
+
echo "$text" | grep -n -i -C2 "$grep_pattern" || echo "(no matches for '$grep_pattern')"
|
|
105
|
+
elif [[ -n "$line_range" ]]; then
|
|
106
|
+
start="${line_range%-*}"
|
|
107
|
+
end="${line_range#*-}"
|
|
108
|
+
echo "$text" | sed -n "${start},${end}p"
|
|
109
|
+
elif [[ -n "$map_mode" ]]; then
|
|
110
|
+
ext="${files[$i]##*.}"
|
|
111
|
+
case "$ext" in
|
|
112
|
+
ts|tsx|js|jsx|mjs) pat='^(import |export |const |let |var |function |class |interface |type |enum )' ;;
|
|
113
|
+
py) pat='^(import |from |class |def | def | def |@)' ;;
|
|
114
|
+
go) pat='^(package |import |func |type |var |const )' ;;
|
|
115
|
+
rs) pat='^(use |pub |fn |struct |enum |trait |impl |type |mod |const )' ;;
|
|
116
|
+
java|kt) pat='^(import |public |private |protected |class |interface |enum |@)' ;;
|
|
117
|
+
rb) pat='^(require |class |module |def | def | def )' ;;
|
|
118
|
+
*) pat='^(import |export |function |class |def |func |type |const |pub )' ;;
|
|
119
|
+
esac
|
|
120
|
+
echo "$text" | grep -nE "$pat" || echo "(no signatures detected)"
|
|
121
|
+
chars=$(echo "$text" | wc -c | tr -d ' ')
|
|
122
|
+
map_chars=$(echo "$text" | grep -E "$pat" | wc -c | tr -d ' ')
|
|
123
|
+
echo "# map: ${map_chars}/${chars} chars (~$(( chars / 4 )) tokens full, ~$(( map_chars / 4 )) tokens map)"
|
|
124
|
+
else
|
|
125
|
+
echo "$text"
|
|
126
|
+
fi
|
|
127
|
+
echo ""
|
|
128
|
+
else
|
|
129
|
+
echo "=== ${files[$i]} (not found) ==="
|
|
130
|
+
echo ""
|
|
131
|
+
fi
|
|
132
|
+
done
|
|
133
|
+
;;
|
|
134
|
+
|
|
135
|
+
# ─── search: code search via REST API (supports full query syntax) ───
|
|
136
|
+
search)
|
|
137
|
+
query="$*"
|
|
138
|
+
if [[ -z "$query" ]]; then
|
|
139
|
+
echo "Usage: ggcode search <query>" >&2
|
|
140
|
+
echo "Query syntax: 'term1 term2 repo:owner/repo' (AND), 'term1 OR term2 repo:owner/repo'" >&2
|
|
141
|
+
echo "Filters: path:src/ extension:tsx language:typescript" >&2
|
|
142
|
+
exit 1
|
|
143
|
+
fi
|
|
144
|
+
gh api /search/code --method GET -f q="$query" --jq '.items[] | "\(.repository.full_name) \(.path):\(.name)"'
|
|
145
|
+
;;
|
|
146
|
+
|
|
147
|
+
# ─── tree: recursive tree listing via REST API ───
|
|
148
|
+
tree)
|
|
149
|
+
repo="$1"; shift || true
|
|
150
|
+
path="${1:-}"
|
|
151
|
+
owner="${repo%%/*}"
|
|
152
|
+
name="${repo##*/}"
|
|
153
|
+
|
|
154
|
+
branch=$(gh repo view "$repo" --json defaultBranchRef --jq '.defaultBranchRef.name')
|
|
155
|
+
|
|
156
|
+
gh api "repos/$owner/$name/git/trees/$branch?recursive=1" --jq '
|
|
157
|
+
[.tree[] | select(.type == "blob") | .path] |
|
|
158
|
+
if "'"$path"'" != "" then
|
|
159
|
+
[.[] | select(startswith("'"$path"'/"))] |
|
|
160
|
+
map(ltrimstr("'"$path"'/"))
|
|
161
|
+
else . end |
|
|
162
|
+
.[]
|
|
163
|
+
'
|
|
164
|
+
;;
|
|
165
|
+
|
|
166
|
+
# ─── help ───
|
|
167
|
+
help|*)
|
|
168
|
+
cat <<'EOF'
|
|
169
|
+
ggcode — GitHub code exploration for agents and humans
|
|
170
|
+
|
|
171
|
+
Commands:
|
|
172
|
+
ggcode explore <owner/repo> [path] Branch + tree + README in 1 API call
|
|
173
|
+
ggcode read <owner/repo> <f1> [f2..] Read 1-10 files in 1 API call
|
|
174
|
+
ggcode search <query> Code search (full syntax: AND, OR, path:, extension:, language:)
|
|
175
|
+
ggcode tree <owner/repo> [path] Full recursive tree listing
|
|
176
|
+
|
|
177
|
+
Read flags:
|
|
178
|
+
--grep <pattern> Filter output to matching lines (case-insensitive, 2 lines context)
|
|
179
|
+
--lines <N-M> Extract specific line range
|
|
180
|
+
|
|
181
|
+
Examples:
|
|
182
|
+
ggcode explore plausible/analytics
|
|
183
|
+
ggcode read plausible/analytics mix.exs assets/js/dashboard/stats/bar.js
|
|
184
|
+
ggcode read plausible/analytics src/app.ts --grep "useState"
|
|
185
|
+
ggcode read plausible/analytics src/app.ts --lines 42-80
|
|
186
|
+
ggcode search "useState repo:plausible/analytics"
|
|
187
|
+
ggcode search "bar OR percentage repo:plausible/analytics"
|
|
188
|
+
ggcode tree plausible/analytics assets/js
|
|
189
|
+
EOF
|
|
190
|
+
;;
|
|
191
|
+
|
|
192
|
+
esac
|
package/package.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@gkoreli/ghx",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "GitHub code exploration for agents and humans. Batch file reads, code maps, search — all via gh CLI.",
|
|
5
|
+
"bin": {
|
|
6
|
+
"ghx": "./ggcode"
|
|
7
|
+
},
|
|
8
|
+
"keywords": ["github", "cli", "code-exploration", "agent", "graphql", "code-map"],
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/gkoreli/ggcode"
|
|
13
|
+
},
|
|
14
|
+
"files": ["ggcode", "README.md", "LICENSE"],
|
|
15
|
+
"os": ["darwin", "linux"],
|
|
16
|
+
"engines": {
|
|
17
|
+
"node": ">=16"
|
|
18
|
+
}
|
|
19
|
+
}
|