grokmap 0.2.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.
@@ -0,0 +1,10 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ .venv/
4
+ dist/
5
+ build/
6
+ *.egg-info/
7
+ .pytest_cache/
8
+ .ruff_cache/
9
+ .grokmap/cache.json
10
+ grokmap-report.html
grokmap-0.2.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 K. L. Aadithya
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.
grokmap-0.2.0/PKG-INFO ADDED
@@ -0,0 +1,266 @@
1
+ Metadata-Version: 2.5
2
+ Name: grokmap
3
+ Version: 0.2.0
4
+ Summary: Measure comprehension debt: the AI-written code in your repo that nobody understands.
5
+ Project-URL: Homepage, https://github.com/Aadithya-kl/grokmap
6
+ Project-URL: Issues, https://github.com/Aadithya-kl/grokmap/issues
7
+ Author: K. L. Aadithya
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Keywords: agent-skills,ai,claude-code,code-review,codex,comprehension-debt,copilot,git
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Environment :: Console
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Topic :: Software Development :: Quality Assurance
17
+ Classifier: Topic :: Software Development :: Version Control :: Git
18
+ Requires-Python: >=3.11
19
+ Provides-Extra: dev
20
+ Requires-Dist: pytest>=8; extra == 'dev'
21
+ Requires-Dist: ruff>=0.6; extra == 'dev'
22
+ Description-Content-Type: text/markdown
23
+
24
+ <div align="center">
25
+
26
+ # grokmap
27
+
28
+ **Find the AI-written code nobody on your team understands, and pay it down one short quiz at a time.**
29
+
30
+ [![ci](https://github.com/Aadithya-kl/grokmap/actions/workflows/ci.yml/badge.svg)](https://github.com/Aadithya-kl/grokmap/actions/workflows/ci.yml)
31
+ ![python](https://img.shields.io/badge/python-3.11%2B-blue)
32
+ ![dependencies](https://img.shields.io/badge/dependencies-0-brightgreen)
33
+ ![license](https://img.shields.io/badge/license-MIT-lightgrey)
34
+
35
+ **[▶ Open the live demo](https://aadithya-kl.github.io/grokmap/)** · [Install](#install) · [Agent skill](#add-the-skill-to-your-coding-agent) · [CI and PR comments](#in-ci)
36
+
37
+ <picture>
38
+ <source media="(prefers-color-scheme: dark)" srcset="docs/report-dark.png">
39
+ <img src="docs/report-light.png" alt="grokmap report: 35% comprehension debt, a bar of every line by who understands it, a weekly chart of who wrote the code, and a treemap of files colored by debt" width="900">
40
+ </picture>
41
+
42
+ </div>
43
+
44
+ ---
45
+
46
+ Coding agents now write a large share of the code we ship. The tests pass, the diff looks clean, it gets merged. A month later something breaks at 2am, and nobody on the team can explain how that module works.
47
+
48
+ That gap has a name: **comprehension debt**, the difference between how much code is in your system and how much of it any person actually understands. It doesn't show up in linters, coverage or code review dashboards.
49
+
50
+ **grokmap measures it.** It traces every line in your repo to the commit that wrote it, recognises commits made by AI agents (Claude Code, Copilot, Cursor, Codex, Aider, Devin, Gemini…), and checks them against a shared ledger of who has *shown* they understand that code. Then it draws you a map.
51
+
52
+ ```
53
+ $ grokmap status
54
+ grokmap · shopcart @ c3088b29ff
55
+
56
+ Comprehension debt 34.5%
57
+ Lines scanned 255 in 12 files
58
+ Written by AI 218 lines (85.5%) — claude 141, copilot 56, cursor 21
59
+ understood 83 (38%)
60
+ fading 21
61
+ skimmed 73
62
+ nobody checked 41
63
+ Critical paths 40.7% debt over 86 lines
64
+ Understood by alex@example.com (53), priya@example.com (51)
65
+
66
+ Riskiest files lines AI unread debt
67
+ src/shopcart/payments/client.py 64 64 33 52%
68
+ src/shopcart/api/routes.py 33 33 0 50%
69
+ src/shopcart/api/auth.py 23 23 0 50%
70
+
71
+ Pay it down: ask your coding agent to run `grokmap quiz <file>` and quiz you.
72
+ ```
73
+
74
+ ## How you pay it down: your agent quizzes you
75
+
76
+ grokmap ships an **agent skill**. After your coding agent writes something substantial, it offers a two-minute quiz on exactly the lines you haven't shown you understand, grades you honestly, and records the result:
77
+
78
+ ```text
79
+ you > yes, quiz me before I commit
80
+ agent > (runs: grokmap quiz --uncommitted)
81
+ Q1 of 3. A charge request times out after the provider already took the money.
82
+ What stops the retry from charging the customer twice?
83
+ you > the idempotency key — it's a hash of order id and amount, so the retry reuses it
84
+ agent > Correct (1/1). The provider sees the same Idempotency-Key and returns the first charge.
85
+ Q2 of 3. A card is declined with HTTP 402. How many times do we call the API, and why?
86
+ you > three times? because of the retry decorator
87
+ agent > Not quite (0/1). 4xx errors are raised with retryable=False, and the decorator re-raises
88
+ those immediately, so it's one call. Only 5xx and network errors are retried.
89
+ ...
90
+ agent > Score 0.67. Recorded (grokmap mark … --score 0.67 --method quiz).
91
+ Worth rereading the error handling in charge() — that's where the retry rules live.
92
+ ```
93
+
94
+ Understanding is tracked **per line**. If the agent later rewrites a line you were quizzed on, that line counts as new, not-yet-understood code again. Understanding older than 180 days shows as *fading*.
95
+
96
+ ## Install
97
+
98
+ ```bash
99
+ pipx install git+https://github.com/Aadithya-kl/grokmap
100
+ ```
101
+
102
+ Or try it without installing: `uvx --from git+https://github.com/Aadithya-kl/grokmap grokmap status`
103
+
104
+ Python 3.11+ and git. No other dependencies, no network calls, nothing leaves your machine.
105
+
106
+ ### Add the skill to your coding agent
107
+
108
+ **Claude Code:**
109
+
110
+ ```text
111
+ /plugin install grokmap --marketplace Aadithya-kl/grokmap
112
+ ```
113
+
114
+ (or `/plugin marketplace add Aadithya-kl/grokmap`, then `/plugin install grokmap@grokmap`)
115
+
116
+ **Any agent that reads `SKILL.md` files** (Codex, Cursor, Gemini CLI, OpenCode…):
117
+
118
+ ```bash
119
+ npx skills add Aadithya-kl/grokmap
120
+ ```
121
+
122
+ or copy [`skills/grokmap/`](skills/grokmap/SKILL.md) into your agent's skills folder.
123
+
124
+ Then just say **"quiz me on the payments module"**, or let the agent offer after it finishes a change.
125
+
126
+ ## Quick start
127
+
128
+ ```bash
129
+ cd your-repo
130
+ grokmap init # .grokmap.toml + ledger + a merge rule for it
131
+ grokmap status # the numbers
132
+ grokmap report --open # the interactive heatmap
133
+ ```
134
+
135
+ Commit `.grokmap/ledger.jsonl` so your whole team shares one map. It's one JSON object per line with a `merge=union` git rule, so merges don't conflict.
136
+
137
+ ## Commands
138
+
139
+ | Command | What it does |
140
+ |---|---|
141
+ | `grokmap status` | Debt, AI share, who understands what, riskiest files. `--json` and `--markdown` for scripts and PR comments. |
142
+ | `grokmap report [-o file] [--open]` | Self-contained HTML heatmap: a zoomable treemap, hover details, filterable file table, light and dark themes. |
143
+ | `grokmap quiz [paths] [--uncommitted \| --staged \| --diff main]` | A quiz brief for your agent: the exact lines you haven't shown you understand, plus grading rules. |
144
+ | `grokmap mark <files…> --score 0.8 [--method quiz\|explain\|review]` | Record understanding. `path:10-40` or `--lines` for line ranges, folders expand to their files. |
145
+ | `grokmap diff [--base origin/main]` | The AI-written lines a branch adds and how many are understood. `--markdown` for a PR comment, `--max-unread N` to gate merges. |
146
+ | `grokmap trend [--by week\|month]` | How much of the code added over time was written by each agent. |
147
+ | `grokmap who <path>` | Who understands the AI-written code in a file or folder. |
148
+ | `grokmap check [--max-debt 40] [--critical]` | Exits 1 above the limit. For CI. |
149
+ | `grokmap badge` | An SVG badge for your README: ![comprehension debt badge](docs/badge-example.svg) |
150
+ | `grokmap init` | Adds config, ledger and `.gitattributes`. |
151
+
152
+ ## In CI
153
+
154
+ ```yaml
155
+ # .github/workflows/grokmap.yml
156
+ on: [pull_request]
157
+ permissions:
158
+ contents: read
159
+ pull-requests: write # for the PR comment
160
+ jobs:
161
+ grokmap:
162
+ runs-on: ubuntu-latest
163
+ steps:
164
+ - uses: actions/checkout@v4
165
+ with:
166
+ fetch-depth: 0 # blame needs full history
167
+ - uses: Aadithya-kl/grokmap@main
168
+ with:
169
+ max-debt: 40 # optional: fail above 40% debt
170
+ max-unread: 200 # optional: fail if the PR adds >200 unchecked AI lines
171
+ ```
172
+
173
+ On every pull request it posts **one comment** (and keeps it up to date) like this:
174
+
175
+ > ### grokmap: comprehension check
176
+ >
177
+ > This change adds **5 AI-written lines** (claude 5) and 1 human-written line. **4 of the AI lines (80%)** have been understood by someone on the team.
178
+ >
179
+ > | File | AI lines | Understood | Not checked |
180
+ > |---|---:|---:|---:|
181
+ > | `src/shopcart/pricing.py` | 1 | 0 | 1 |
182
+ > | `src/shopcart/loyalty.py` | 4 | 4 | 0 |
183
+ >
184
+ > Before merging, the author can ask their coding agent to run `grokmap quiz --diff origin/main` for a 2-minute quiz on the unchecked lines.
185
+
186
+ It also writes the repo summary to the job page, uploads the heatmap as an artifact, and exposes `debt` and `ai-lines` as outputs. Everything is report-only unless you set a limit.
187
+
188
+ ## How it works
189
+
190
+ 1. **Attribution.** For every tracked text file, `git blame -w` maps each line at `HEAD` to the commit that last changed it. Blank lines and lone brackets are ignored.
191
+ 2. **AI detection.** A commit counts as AI-written only when it carries evidence the tools themselves leave behind:
192
+
193
+ | Agent | Signals |
194
+ |---|---|
195
+ | Claude / Claude Code | `Co-Authored-By: Claude`, "Generated with Claude Code", `Claude-Session:`, `claude[bot]` |
196
+ | GitHub Copilot | Copilot coding agent as author, `Co-authored-by: Copilot` |
197
+ | Cursor | `cursoragent@cursor.com` author or co-author |
198
+ | OpenAI Codex | `chatgpt-codex` / `codex[bot]`, Codex co-author |
199
+ | Aider | `aider:` message prefix, `(aider)` author suffix |
200
+ | Devin, Gemini / Jules, Amazon Q, Windsurf | their bot authors or co-author trailers |
201
+ | Your own | any regex in `[grokmap.ai_patterns]`, or specific commits in `[grokmap.ai_commits]` |
202
+
203
+ Squash merges keep co-author trailers, so detection survives the usual GitHub workflow.
204
+ 3. **Understanding.** Each ledger record stores short hashes of the lines a person was quizzed on. A line is *understood* when someone passed a quiz on its current content, *skimmed* for a low score or a `review`, *fading* when the pass is older than `decay_days`.
205
+ 4. **Debt** = unread AI lines + ½ × (skimmed + fading) AI lines, divided by all meaningful lines.
206
+
207
+ `grokmap trend` uses `git log --numstat` with the same detection, so you can see when AI started writing most of your code.
208
+
209
+ Results are cached per file blob in `.grokmap/cache.json`. A 318,000-line repo with 3,000 files takes about 17 seconds the first time and about a second after that.
210
+
211
+ ## Configuration
212
+
213
+ `.grokmap.toml` (or `[tool.grokmap]` in `pyproject.toml`):
214
+
215
+ ```toml
216
+ [grokmap]
217
+ pass_score = 0.7 # quiz score that counts as understood
218
+ decay_days = 180 # 0 = understanding never fades
219
+ max_debt = 40 # default limit for `grokmap check`
220
+ exclude = ["docs/**", "examples/**"]
221
+ critical = ["src/payments/**", "src/auth/**"]
222
+
223
+ [grokmap.ai_patterns]
224
+ internal-bot = "^co-authored-by:.*internal-bot"
225
+ render-farm = "author:render-farm"
226
+
227
+ [grokmap.ai_commits]
228
+ "3f2a9c1" = "claude" # before your team added trailers
229
+ ```
230
+
231
+ Lock files, build output, vendored code, minified files, media and binaries are skipped by default.
232
+
233
+ ## FAQ
234
+
235
+ **Is this surveillance?** No. grokmap measures *code*, not people. Nobody is quizzed unless they ask, the ledger only holds what people chose to record, and the main number is about the codebase. If your team would use it to rank people, don't adopt it.
236
+
237
+ **What about AI code pasted from a chat window?** grokmap can't see it, so it counts as human-written. Detection is deliberately conservative: it only flags commits with real evidence and never guesses from code style. Adding an `AI-Assisted:` trailer (or your own pattern) fixes this going forward.
238
+
239
+ **Can I game it?** You can mark code as understood without a quiz, the same way you can approve a PR without reading it. The point is an honest map for your own team, and the skill is written to never record a score the person didn't earn.
240
+
241
+ **Does the quiz send my code anywhere?** grokmap itself makes no network calls. Your coding agent reads the brief like any other file it already works with.
242
+
243
+ ## Why "grokmap"?
244
+
245
+ To *grok* is to understand something so thoroughly it becomes part of you. This is a map of what your team groks.
246
+
247
+ ## Roadmap
248
+
249
+ Ideas the project wants help with are tracked as [issues](https://github.com/Aadithya-kl/grokmap/issues). The [good first issues](https://github.com/Aadithya-kl/grokmap/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22) are small and well scoped. The biggest ones: an editor extension that colors understood and unread lines in the gutter, keeping understanding across file renames, and detection for more agents.
250
+
251
+ ## Contributing
252
+
253
+ See [CONTRIBUTING.md](CONTRIBUTING.md). The short version:
254
+
255
+ ```bash
256
+ git clone https://github.com/Aadithya-kl/grokmap && cd grokmap
257
+ python -m venv .venv && . .venv/bin/activate && pip install -e ".[dev]"
258
+ pytest && ruff check src tests
259
+ python scripts/make_demo.py /tmp/grokmap-demo && grokmap -C /tmp/grokmap-demo report --open
260
+ ```
261
+
262
+ Most useful contributions: detection signatures for more agents (with a real example commit), and reports of false positives.
263
+
264
+ ## License
265
+
266
+ MIT
@@ -0,0 +1,243 @@
1
+ <div align="center">
2
+
3
+ # grokmap
4
+
5
+ **Find the AI-written code nobody on your team understands, and pay it down one short quiz at a time.**
6
+
7
+ [![ci](https://github.com/Aadithya-kl/grokmap/actions/workflows/ci.yml/badge.svg)](https://github.com/Aadithya-kl/grokmap/actions/workflows/ci.yml)
8
+ ![python](https://img.shields.io/badge/python-3.11%2B-blue)
9
+ ![dependencies](https://img.shields.io/badge/dependencies-0-brightgreen)
10
+ ![license](https://img.shields.io/badge/license-MIT-lightgrey)
11
+
12
+ **[▶ Open the live demo](https://aadithya-kl.github.io/grokmap/)** · [Install](#install) · [Agent skill](#add-the-skill-to-your-coding-agent) · [CI and PR comments](#in-ci)
13
+
14
+ <picture>
15
+ <source media="(prefers-color-scheme: dark)" srcset="docs/report-dark.png">
16
+ <img src="docs/report-light.png" alt="grokmap report: 35% comprehension debt, a bar of every line by who understands it, a weekly chart of who wrote the code, and a treemap of files colored by debt" width="900">
17
+ </picture>
18
+
19
+ </div>
20
+
21
+ ---
22
+
23
+ Coding agents now write a large share of the code we ship. The tests pass, the diff looks clean, it gets merged. A month later something breaks at 2am, and nobody on the team can explain how that module works.
24
+
25
+ That gap has a name: **comprehension debt**, the difference between how much code is in your system and how much of it any person actually understands. It doesn't show up in linters, coverage or code review dashboards.
26
+
27
+ **grokmap measures it.** It traces every line in your repo to the commit that wrote it, recognises commits made by AI agents (Claude Code, Copilot, Cursor, Codex, Aider, Devin, Gemini…), and checks them against a shared ledger of who has *shown* they understand that code. Then it draws you a map.
28
+
29
+ ```
30
+ $ grokmap status
31
+ grokmap · shopcart @ c3088b29ff
32
+
33
+ Comprehension debt 34.5%
34
+ Lines scanned 255 in 12 files
35
+ Written by AI 218 lines (85.5%) — claude 141, copilot 56, cursor 21
36
+ understood 83 (38%)
37
+ fading 21
38
+ skimmed 73
39
+ nobody checked 41
40
+ Critical paths 40.7% debt over 86 lines
41
+ Understood by alex@example.com (53), priya@example.com (51)
42
+
43
+ Riskiest files lines AI unread debt
44
+ src/shopcart/payments/client.py 64 64 33 52%
45
+ src/shopcart/api/routes.py 33 33 0 50%
46
+ src/shopcart/api/auth.py 23 23 0 50%
47
+
48
+ Pay it down: ask your coding agent to run `grokmap quiz <file>` and quiz you.
49
+ ```
50
+
51
+ ## How you pay it down: your agent quizzes you
52
+
53
+ grokmap ships an **agent skill**. After your coding agent writes something substantial, it offers a two-minute quiz on exactly the lines you haven't shown you understand, grades you honestly, and records the result:
54
+
55
+ ```text
56
+ you > yes, quiz me before I commit
57
+ agent > (runs: grokmap quiz --uncommitted)
58
+ Q1 of 3. A charge request times out after the provider already took the money.
59
+ What stops the retry from charging the customer twice?
60
+ you > the idempotency key — it's a hash of order id and amount, so the retry reuses it
61
+ agent > Correct (1/1). The provider sees the same Idempotency-Key and returns the first charge.
62
+ Q2 of 3. A card is declined with HTTP 402. How many times do we call the API, and why?
63
+ you > three times? because of the retry decorator
64
+ agent > Not quite (0/1). 4xx errors are raised with retryable=False, and the decorator re-raises
65
+ those immediately, so it's one call. Only 5xx and network errors are retried.
66
+ ...
67
+ agent > Score 0.67. Recorded (grokmap mark … --score 0.67 --method quiz).
68
+ Worth rereading the error handling in charge() — that's where the retry rules live.
69
+ ```
70
+
71
+ Understanding is tracked **per line**. If the agent later rewrites a line you were quizzed on, that line counts as new, not-yet-understood code again. Understanding older than 180 days shows as *fading*.
72
+
73
+ ## Install
74
+
75
+ ```bash
76
+ pipx install git+https://github.com/Aadithya-kl/grokmap
77
+ ```
78
+
79
+ Or try it without installing: `uvx --from git+https://github.com/Aadithya-kl/grokmap grokmap status`
80
+
81
+ Python 3.11+ and git. No other dependencies, no network calls, nothing leaves your machine.
82
+
83
+ ### Add the skill to your coding agent
84
+
85
+ **Claude Code:**
86
+
87
+ ```text
88
+ /plugin install grokmap --marketplace Aadithya-kl/grokmap
89
+ ```
90
+
91
+ (or `/plugin marketplace add Aadithya-kl/grokmap`, then `/plugin install grokmap@grokmap`)
92
+
93
+ **Any agent that reads `SKILL.md` files** (Codex, Cursor, Gemini CLI, OpenCode…):
94
+
95
+ ```bash
96
+ npx skills add Aadithya-kl/grokmap
97
+ ```
98
+
99
+ or copy [`skills/grokmap/`](skills/grokmap/SKILL.md) into your agent's skills folder.
100
+
101
+ Then just say **"quiz me on the payments module"**, or let the agent offer after it finishes a change.
102
+
103
+ ## Quick start
104
+
105
+ ```bash
106
+ cd your-repo
107
+ grokmap init # .grokmap.toml + ledger + a merge rule for it
108
+ grokmap status # the numbers
109
+ grokmap report --open # the interactive heatmap
110
+ ```
111
+
112
+ Commit `.grokmap/ledger.jsonl` so your whole team shares one map. It's one JSON object per line with a `merge=union` git rule, so merges don't conflict.
113
+
114
+ ## Commands
115
+
116
+ | Command | What it does |
117
+ |---|---|
118
+ | `grokmap status` | Debt, AI share, who understands what, riskiest files. `--json` and `--markdown` for scripts and PR comments. |
119
+ | `grokmap report [-o file] [--open]` | Self-contained HTML heatmap: a zoomable treemap, hover details, filterable file table, light and dark themes. |
120
+ | `grokmap quiz [paths] [--uncommitted \| --staged \| --diff main]` | A quiz brief for your agent: the exact lines you haven't shown you understand, plus grading rules. |
121
+ | `grokmap mark <files…> --score 0.8 [--method quiz\|explain\|review]` | Record understanding. `path:10-40` or `--lines` for line ranges, folders expand to their files. |
122
+ | `grokmap diff [--base origin/main]` | The AI-written lines a branch adds and how many are understood. `--markdown` for a PR comment, `--max-unread N` to gate merges. |
123
+ | `grokmap trend [--by week\|month]` | How much of the code added over time was written by each agent. |
124
+ | `grokmap who <path>` | Who understands the AI-written code in a file or folder. |
125
+ | `grokmap check [--max-debt 40] [--critical]` | Exits 1 above the limit. For CI. |
126
+ | `grokmap badge` | An SVG badge for your README: ![comprehension debt badge](docs/badge-example.svg) |
127
+ | `grokmap init` | Adds config, ledger and `.gitattributes`. |
128
+
129
+ ## In CI
130
+
131
+ ```yaml
132
+ # .github/workflows/grokmap.yml
133
+ on: [pull_request]
134
+ permissions:
135
+ contents: read
136
+ pull-requests: write # for the PR comment
137
+ jobs:
138
+ grokmap:
139
+ runs-on: ubuntu-latest
140
+ steps:
141
+ - uses: actions/checkout@v4
142
+ with:
143
+ fetch-depth: 0 # blame needs full history
144
+ - uses: Aadithya-kl/grokmap@main
145
+ with:
146
+ max-debt: 40 # optional: fail above 40% debt
147
+ max-unread: 200 # optional: fail if the PR adds >200 unchecked AI lines
148
+ ```
149
+
150
+ On every pull request it posts **one comment** (and keeps it up to date) like this:
151
+
152
+ > ### grokmap: comprehension check
153
+ >
154
+ > This change adds **5 AI-written lines** (claude 5) and 1 human-written line. **4 of the AI lines (80%)** have been understood by someone on the team.
155
+ >
156
+ > | File | AI lines | Understood | Not checked |
157
+ > |---|---:|---:|---:|
158
+ > | `src/shopcart/pricing.py` | 1 | 0 | 1 |
159
+ > | `src/shopcart/loyalty.py` | 4 | 4 | 0 |
160
+ >
161
+ > Before merging, the author can ask their coding agent to run `grokmap quiz --diff origin/main` for a 2-minute quiz on the unchecked lines.
162
+
163
+ It also writes the repo summary to the job page, uploads the heatmap as an artifact, and exposes `debt` and `ai-lines` as outputs. Everything is report-only unless you set a limit.
164
+
165
+ ## How it works
166
+
167
+ 1. **Attribution.** For every tracked text file, `git blame -w` maps each line at `HEAD` to the commit that last changed it. Blank lines and lone brackets are ignored.
168
+ 2. **AI detection.** A commit counts as AI-written only when it carries evidence the tools themselves leave behind:
169
+
170
+ | Agent | Signals |
171
+ |---|---|
172
+ | Claude / Claude Code | `Co-Authored-By: Claude`, "Generated with Claude Code", `Claude-Session:`, `claude[bot]` |
173
+ | GitHub Copilot | Copilot coding agent as author, `Co-authored-by: Copilot` |
174
+ | Cursor | `cursoragent@cursor.com` author or co-author |
175
+ | OpenAI Codex | `chatgpt-codex` / `codex[bot]`, Codex co-author |
176
+ | Aider | `aider:` message prefix, `(aider)` author suffix |
177
+ | Devin, Gemini / Jules, Amazon Q, Windsurf | their bot authors or co-author trailers |
178
+ | Your own | any regex in `[grokmap.ai_patterns]`, or specific commits in `[grokmap.ai_commits]` |
179
+
180
+ Squash merges keep co-author trailers, so detection survives the usual GitHub workflow.
181
+ 3. **Understanding.** Each ledger record stores short hashes of the lines a person was quizzed on. A line is *understood* when someone passed a quiz on its current content, *skimmed* for a low score or a `review`, *fading* when the pass is older than `decay_days`.
182
+ 4. **Debt** = unread AI lines + ½ × (skimmed + fading) AI lines, divided by all meaningful lines.
183
+
184
+ `grokmap trend` uses `git log --numstat` with the same detection, so you can see when AI started writing most of your code.
185
+
186
+ Results are cached per file blob in `.grokmap/cache.json`. A 318,000-line repo with 3,000 files takes about 17 seconds the first time and about a second after that.
187
+
188
+ ## Configuration
189
+
190
+ `.grokmap.toml` (or `[tool.grokmap]` in `pyproject.toml`):
191
+
192
+ ```toml
193
+ [grokmap]
194
+ pass_score = 0.7 # quiz score that counts as understood
195
+ decay_days = 180 # 0 = understanding never fades
196
+ max_debt = 40 # default limit for `grokmap check`
197
+ exclude = ["docs/**", "examples/**"]
198
+ critical = ["src/payments/**", "src/auth/**"]
199
+
200
+ [grokmap.ai_patterns]
201
+ internal-bot = "^co-authored-by:.*internal-bot"
202
+ render-farm = "author:render-farm"
203
+
204
+ [grokmap.ai_commits]
205
+ "3f2a9c1" = "claude" # before your team added trailers
206
+ ```
207
+
208
+ Lock files, build output, vendored code, minified files, media and binaries are skipped by default.
209
+
210
+ ## FAQ
211
+
212
+ **Is this surveillance?** No. grokmap measures *code*, not people. Nobody is quizzed unless they ask, the ledger only holds what people chose to record, and the main number is about the codebase. If your team would use it to rank people, don't adopt it.
213
+
214
+ **What about AI code pasted from a chat window?** grokmap can't see it, so it counts as human-written. Detection is deliberately conservative: it only flags commits with real evidence and never guesses from code style. Adding an `AI-Assisted:` trailer (or your own pattern) fixes this going forward.
215
+
216
+ **Can I game it?** You can mark code as understood without a quiz, the same way you can approve a PR without reading it. The point is an honest map for your own team, and the skill is written to never record a score the person didn't earn.
217
+
218
+ **Does the quiz send my code anywhere?** grokmap itself makes no network calls. Your coding agent reads the brief like any other file it already works with.
219
+
220
+ ## Why "grokmap"?
221
+
222
+ To *grok* is to understand something so thoroughly it becomes part of you. This is a map of what your team groks.
223
+
224
+ ## Roadmap
225
+
226
+ Ideas the project wants help with are tracked as [issues](https://github.com/Aadithya-kl/grokmap/issues). The [good first issues](https://github.com/Aadithya-kl/grokmap/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22) are small and well scoped. The biggest ones: an editor extension that colors understood and unread lines in the gutter, keeping understanding across file renames, and detection for more agents.
227
+
228
+ ## Contributing
229
+
230
+ See [CONTRIBUTING.md](CONTRIBUTING.md). The short version:
231
+
232
+ ```bash
233
+ git clone https://github.com/Aadithya-kl/grokmap && cd grokmap
234
+ python -m venv .venv && . .venv/bin/activate && pip install -e ".[dev]"
235
+ pytest && ruff check src tests
236
+ python scripts/make_demo.py /tmp/grokmap-demo && grokmap -C /tmp/grokmap-demo report --open
237
+ ```
238
+
239
+ Most useful contributions: detection signatures for more agents (with a real example commit), and reports of false positives.
240
+
241
+ ## License
242
+
243
+ MIT
@@ -0,0 +1,131 @@
1
+ name: grokmap
2
+ description: Measure comprehension debt (AI-written code nobody has shown they understand), publish the heatmap, and optionally fail above a limit.
3
+ author: K. L. Aadithya
4
+ branding:
5
+ icon: map
6
+ color: red
7
+
8
+ inputs:
9
+ max-debt:
10
+ description: Fail when comprehension debt (%) is above this. Leave empty to only report.
11
+ required: false
12
+ default: ""
13
+ critical:
14
+ description: Set to "true" to check only the paths listed as critical in .grokmap.toml.
15
+ required: false
16
+ default: "false"
17
+ report:
18
+ description: Upload the HTML heatmap as a workflow artifact.
19
+ required: false
20
+ default: "true"
21
+ comment:
22
+ description: "On pull requests, post (and keep updating) one comment with the AI-written lines the PR adds and how many are understood. Needs the pull-requests write permission."
23
+ required: false
24
+ default: "true"
25
+ max-unread:
26
+ description: On pull requests, fail when the PR adds more than this many AI-written lines nobody has checked. Leave empty to only report.
27
+ required: false
28
+ default: ""
29
+ github-token:
30
+ description: Token used to post the PR comment.
31
+ required: false
32
+ default: ${{ github.token }}
33
+ working-directory:
34
+ description: Folder inside the repository to run in.
35
+ required: false
36
+ default: "."
37
+
38
+ outputs:
39
+ debt:
40
+ description: Comprehension debt in percent.
41
+ value: ${{ steps.measure.outputs.debt }}
42
+ ai-lines:
43
+ description: Number of AI-written lines at HEAD.
44
+ value: ${{ steps.measure.outputs.ai_lines }}
45
+
46
+ runs:
47
+ using: composite
48
+ steps:
49
+ - uses: actions/setup-python@v5
50
+ with:
51
+ python-version: "3.12"
52
+
53
+ - name: Install grokmap
54
+ shell: bash
55
+ run: python -m pip install --quiet "${{ github.action_path }}"
56
+
57
+ - name: Check history depth
58
+ shell: bash
59
+ working-directory: ${{ inputs.working-directory }}
60
+ run: |
61
+ if [ "$(git rev-parse --is-shallow-repository)" = "true" ]; then
62
+ echo "::warning title=grokmap::Shallow clone: blame stops at the clone boundary, so authorship is incomplete. Use actions/checkout with fetch-depth: 0."
63
+ fi
64
+
65
+ - name: Measure
66
+ id: measure
67
+ shell: bash
68
+ working-directory: ${{ inputs.working-directory }}
69
+ run: |
70
+ grokmap status --markdown --top 10 >> "$GITHUB_STEP_SUMMARY"
71
+ grokmap status --json > "$RUNNER_TEMP/grokmap.json"
72
+ python - "$RUNNER_TEMP/grokmap.json" >> "$GITHUB_OUTPUT" <<'PY'
73
+ import json, sys
74
+ t = json.load(open(sys.argv[1]))["total"]
75
+ print(f"debt={t['debt_pct']}")
76
+ print(f"ai_lines={t['ai']}")
77
+ PY
78
+ grokmap report -o "$RUNNER_TEMP/grokmap-report/index.html"
79
+
80
+ - name: Upload heatmap
81
+ if: inputs.report == 'true'
82
+ uses: actions/upload-artifact@v4
83
+ with:
84
+ name: grokmap-report
85
+ path: ${{ runner.temp }}/grokmap-report/index.html
86
+
87
+ - name: Summarize the pull request
88
+ id: pr
89
+ if: github.event_name == 'pull_request'
90
+ shell: bash
91
+ working-directory: ${{ inputs.working-directory }}
92
+ env:
93
+ BASE: ${{ github.base_ref }}
94
+ run: |
95
+ git rev-parse --verify -q "origin/$BASE" >/dev/null || git fetch --quiet origin "$BASE:refs/remotes/origin/$BASE"
96
+ grokmap diff --base "origin/$BASE" --markdown > "$RUNNER_TEMP/grokmap-pr.md"
97
+ cat "$RUNNER_TEMP/grokmap-pr.md" >> "$GITHUB_STEP_SUMMARY"
98
+
99
+ - name: Comment on the pull request
100
+ if: github.event_name == 'pull_request' && inputs.comment == 'true' && steps.pr.outcome == 'success'
101
+ continue-on-error: true # forks get a read-only token; the job summary still has the table
102
+ shell: bash
103
+ env:
104
+ GH_TOKEN: ${{ inputs.github-token }}
105
+ PR: ${{ github.event.pull_request.number }}
106
+ run: |
107
+ marker='<!-- grokmap:pr-summary -->'
108
+ id=$(gh api "repos/$GITHUB_REPOSITORY/issues/$PR/comments" --paginate \
109
+ --jq ".[] | select((.body // \"\") | startswith(\"$marker\")) | .id" | head -n 1)
110
+ if [ -n "$id" ]; then
111
+ gh api -X PATCH "repos/$GITHUB_REPOSITORY/issues/comments/$id" -F body=@"$RUNNER_TEMP/grokmap-pr.md" > /dev/null
112
+ else
113
+ gh api -X POST "repos/$GITHUB_REPOSITORY/issues/$PR/comments" -F body=@"$RUNNER_TEMP/grokmap-pr.md" > /dev/null
114
+ fi
115
+
116
+ - name: Enforce PR limit
117
+ if: github.event_name == 'pull_request' && inputs.max-unread != ''
118
+ shell: bash
119
+ working-directory: ${{ inputs.working-directory }}
120
+ env:
121
+ BASE: ${{ github.base_ref }}
122
+ run: grokmap diff --base "origin/$BASE" --max-unread "${{ inputs.max-unread }}"
123
+
124
+ - name: Enforce limit
125
+ if: inputs.max-debt != ''
126
+ shell: bash
127
+ working-directory: ${{ inputs.working-directory }}
128
+ run: |
129
+ args=(--max-debt "${{ inputs.max-debt }}")
130
+ if [ "${{ inputs.critical }}" = "true" ]; then args+=(--critical); fi
131
+ grokmap check "${args[@]}"