gra-context 0.1.3__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.
- gra_context-0.1.3/LICENSE +11 -0
- gra_context-0.1.3/PKG-INFO +73 -0
- gra_context-0.1.3/PYPI.md +47 -0
- gra_context-0.1.3/README.md +270 -0
- gra_context-0.1.3/pyproject.toml +38 -0
- gra_context-0.1.3/setup.cfg +4 -0
- gra_context-0.1.3/src/gra/__init__.py +0 -0
- gra_context-0.1.3/src/gra/__main__.py +3 -0
- gra_context-0.1.3/src/gra/adapters/__init__.py +0 -0
- gra_context-0.1.3/src/gra/adapters/symbol_graph_store.py +270 -0
- gra_context-0.1.3/src/gra/cli.py +369 -0
- gra_context-0.1.3/src/gra/core/__init__.py +0 -0
- gra_context-0.1.3/src/gra/core/embedding_models.py +76 -0
- gra_context-0.1.3/src/gra/core/env.py +52 -0
- gra_context-0.1.3/src/gra/core/file_locks.py +19 -0
- gra_context-0.1.3/src/gra/core/storage_paths.py +44 -0
- gra_context-0.1.3/src/gra/core/symbol_types.py +62 -0
- gra_context-0.1.3/src/gra/mcp_server.py +334 -0
- gra_context-0.1.3/src/gra/pipelines/__init__.py +0 -0
- gra_context-0.1.3/src/gra/pipelines/code_indexing_pipeline.py +211 -0
- gra_context-0.1.3/src/gra/pipelines/context_retrieval_pipeline.py +176 -0
- gra_context-0.1.3/src/gra/services/__init__.py +0 -0
- gra_context-0.1.3/src/gra/services/context_assembly.py +505 -0
- gra_context-0.1.3/src/gra/services/context_filter.py +153 -0
- gra_context-0.1.3/src/gra/services/culprits.py +129 -0
- gra_context-0.1.3/src/gra/services/python_symbol_extractor.py +394 -0
- gra_context-0.1.3/src/gra/services/remote_explainer.py +92 -0
- gra_context-0.1.3/src/gra/services/session_memory.py +556 -0
- gra_context-0.1.3/src/gra/services/session_transcript.py +429 -0
- gra_context-0.1.3/src/gra/services/symbol_explanation.py +238 -0
- gra_context-0.1.3/src/gra/services/symbol_paths.py +107 -0
- gra_context-0.1.3/src/gra/services/symbol_resolution.py +282 -0
- gra_context-0.1.3/src/gra/services/symbol_search.py +334 -0
- gra_context-0.1.3/src/gra/services/work_log.py +328 -0
- gra_context-0.1.3/src/gra/watcher.py +202 -0
- gra_context-0.1.3/src/gra_context.egg-info/PKG-INFO +73 -0
- gra_context-0.1.3/src/gra_context.egg-info/SOURCES.txt +48 -0
- gra_context-0.1.3/src/gra_context.egg-info/dependency_links.txt +1 -0
- gra_context-0.1.3/src/gra_context.egg-info/entry_points.txt +2 -0
- gra_context-0.1.3/src/gra_context.egg-info/requires.txt +15 -0
- gra_context-0.1.3/src/gra_context.egg-info/top_level.txt +1 -0
- gra_context-0.1.3/tests/test_code_indexing_pipeline.py +375 -0
- gra_context-0.1.3/tests/test_context_filter.py +207 -0
- gra_context-0.1.3/tests/test_context_retrieval.py +290 -0
- gra_context-0.1.3/tests/test_culprits.py +27 -0
- gra_context-0.1.3/tests/test_env.py +31 -0
- gra_context-0.1.3/tests/test_session_memory.py +689 -0
- gra_context-0.1.3/tests/test_setup.py +142 -0
- gra_context-0.1.3/tests/test_symbol_paths.py +78 -0
- gra_context-0.1.3/tests/test_symbol_resolution.py +300 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
Copyright (c) 2026 GRA. All rights reserved.
|
|
2
|
+
|
|
3
|
+
This software (the gra-context package) is proprietary. You may install and run
|
|
4
|
+
it unmodified to use GRA's service with a valid GRA API key. You may not copy,
|
|
5
|
+
modify, merge, publish, distribute, sublicense or sell copies of it, or use it
|
|
6
|
+
to build a competing product, without GRA's written permission.
|
|
7
|
+
|
|
8
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
9
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
10
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL GRA BE LIABLE
|
|
11
|
+
FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY ARISING FROM THE SOFTWARE OR ITS USE.
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: gra-context
|
|
3
|
+
Version: 0.1.3
|
|
4
|
+
Summary: A map of your codebase that coding agents query for context, served to Claude Code and Codex over MCP.
|
|
5
|
+
Author: GRA
|
|
6
|
+
License-Expression: LicenseRef-Proprietary
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: Operating System :: OS Independent
|
|
9
|
+
Requires-Python: >=3.10
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Requires-Dist: langgraph<2,>=1.2
|
|
13
|
+
Requires-Dist: langchain<2,>=1.4
|
|
14
|
+
Requires-Dist: langchain-core<2,>=1.6
|
|
15
|
+
Requires-Dist: pydantic<3,>=2.12
|
|
16
|
+
Requires-Dist: numpy>=1.26
|
|
17
|
+
Requires-Dist: httpx>=0.28
|
|
18
|
+
Requires-Dist: mcp<3,>=2.3
|
|
19
|
+
Requires-Dist: fastembed>=0.9
|
|
20
|
+
Provides-Extra: huggingface
|
|
21
|
+
Requires-Dist: langchain-huggingface>=1.2; extra == "huggingface"
|
|
22
|
+
Requires-Dist: sentence-transformers>=5.1; extra == "huggingface"
|
|
23
|
+
Provides-Extra: test
|
|
24
|
+
Requires-Dist: pytest>=8.4; extra == "test"
|
|
25
|
+
Dynamic: license-file
|
|
26
|
+
|
|
27
|
+
# gra-context
|
|
28
|
+
|
|
29
|
+
GRA gives Claude Code a map of your Python codebase, so it finds the code it
|
|
30
|
+
needs and understands how the parts connect before it starts changing things.
|
|
31
|
+
|
|
32
|
+
Claude asks GRA a question in plain words ("where are redirects followed?") and
|
|
33
|
+
gets back the relevant functions and classes, each with a one-line explanation,
|
|
34
|
+
its file and line range, how it connects to the rest, and the tests that cover
|
|
35
|
+
it. GRA keeps the map current as files are edited, and remembers what earlier
|
|
36
|
+
sessions did in the same code.
|
|
37
|
+
|
|
38
|
+
## Install
|
|
39
|
+
|
|
40
|
+
```
|
|
41
|
+
pipx install gra-context # or: uv tool install gra-context
|
|
42
|
+
cd /path/to/your/codebase
|
|
43
|
+
gra setup
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
The first time, `gra setup` asks for your email and saves a free key on your
|
|
47
|
+
computer. Then start a new Claude Code or Codex session in that codebase. The first
|
|
48
|
+
time, GRA builds the map in the background; after that it follows your edits
|
|
49
|
+
by itself. Codex support is tested with Codex 0.151.0 and 0.164.0; with a newer Codex, GRA tells
|
|
50
|
+
you if it can't record your Codex sessions yet. Run `gra setup` once in each codebase you want GRA in (your key is
|
|
51
|
+
remembered). Installed Claude Code or Codex after setting up GRA? Run `gra setup` again in the repo. On another computer, run `gra key` on this one and `gra setup --api-key <your key>` on the new one.
|
|
52
|
+
|
|
53
|
+
- `--scope project` turns GRA on for everyone working in the repository, through `.mcp.json` and `.codex/config.toml`.
|
|
54
|
+
- `--agents-md` adds a line to `AGENTS.md` telling Claude Code and Codex to start from GRA.
|
|
55
|
+
|
|
56
|
+
## Your code and data
|
|
57
|
+
|
|
58
|
+
The map, the explanations and the work history are stored on your machine
|
|
59
|
+
(`~/.local/share/gra/`), never inside your codebase. To write explanations,
|
|
60
|
+
GRA sends one function's code at a time to GRA's service, which does not store
|
|
61
|
+
it. Searching the map runs locally.
|
|
62
|
+
|
|
63
|
+
## Commands
|
|
64
|
+
|
|
65
|
+
```
|
|
66
|
+
gra setup [--api-key K] turn GRA on for the current codebase
|
|
67
|
+
gra key show your saved key, to use it on another computer
|
|
68
|
+
gra query "question" [--repo R] what Claude gets back for a question
|
|
69
|
+
gra show <name> [repo] a symbol, its explanation and its connections
|
|
70
|
+
gra install [repo] build the map now, plus a git post-commit hook
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Requires Python 3.10+ and a GRA key (free, from `gra setup`). Proprietary software; see LICENSE.
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# gra-context
|
|
2
|
+
|
|
3
|
+
GRA gives Claude Code a map of your Python codebase, so it finds the code it
|
|
4
|
+
needs and understands how the parts connect before it starts changing things.
|
|
5
|
+
|
|
6
|
+
Claude asks GRA a question in plain words ("where are redirects followed?") and
|
|
7
|
+
gets back the relevant functions and classes, each with a one-line explanation,
|
|
8
|
+
its file and line range, how it connects to the rest, and the tests that cover
|
|
9
|
+
it. GRA keeps the map current as files are edited, and remembers what earlier
|
|
10
|
+
sessions did in the same code.
|
|
11
|
+
|
|
12
|
+
## Install
|
|
13
|
+
|
|
14
|
+
```
|
|
15
|
+
pipx install gra-context # or: uv tool install gra-context
|
|
16
|
+
cd /path/to/your/codebase
|
|
17
|
+
gra setup
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
The first time, `gra setup` asks for your email and saves a free key on your
|
|
21
|
+
computer. Then start a new Claude Code or Codex session in that codebase. The first
|
|
22
|
+
time, GRA builds the map in the background; after that it follows your edits
|
|
23
|
+
by itself. Codex support is tested with Codex 0.151.0 and 0.164.0; with a newer Codex, GRA tells
|
|
24
|
+
you if it can't record your Codex sessions yet. Run `gra setup` once in each codebase you want GRA in (your key is
|
|
25
|
+
remembered). Installed Claude Code or Codex after setting up GRA? Run `gra setup` again in the repo. On another computer, run `gra key` on this one and `gra setup --api-key <your key>` on the new one.
|
|
26
|
+
|
|
27
|
+
- `--scope project` turns GRA on for everyone working in the repository, through `.mcp.json` and `.codex/config.toml`.
|
|
28
|
+
- `--agents-md` adds a line to `AGENTS.md` telling Claude Code and Codex to start from GRA.
|
|
29
|
+
|
|
30
|
+
## Your code and data
|
|
31
|
+
|
|
32
|
+
The map, the explanations and the work history are stored on your machine
|
|
33
|
+
(`~/.local/share/gra/`), never inside your codebase. To write explanations,
|
|
34
|
+
GRA sends one function's code at a time to GRA's service, which does not store
|
|
35
|
+
it. Searching the map runs locally.
|
|
36
|
+
|
|
37
|
+
## Commands
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
gra setup [--api-key K] turn GRA on for the current codebase
|
|
41
|
+
gra key show your saved key, to use it on another computer
|
|
42
|
+
gra query "question" [--repo R] what Claude gets back for a question
|
|
43
|
+
gra show <name> [repo] a symbol, its explanation and its connections
|
|
44
|
+
gra install [repo] build the map now, plus a git post-commit hook
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Requires Python 3.10+ and a GRA key (free, from `gra setup`). Proprietary software; see LICENSE.
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
# GRA coding assistant
|
|
2
|
+
|
|
3
|
+
A system dedicated to making coding and contextualizing more efficient.
|
|
4
|
+
|
|
5
|
+
It is an intelligence layer that gives coding agents a broader view of a
|
|
6
|
+
codebase: past pull requests, logs, tickets and other history that sits outside
|
|
7
|
+
the files. It is not a coding agent itself; agents call it for context, so they
|
|
8
|
+
spend less effort gathering it and more on the change itself.
|
|
9
|
+
|
|
10
|
+
Status: a symbol map of a Python codebase, served to Claude Code over MCP,
|
|
11
|
+
with explanations written by GRA's explanation service. This repository began
|
|
12
|
+
as a copy of the GRA research assistant (`Parth424/gra`); that code now lives
|
|
13
|
+
only in its own repository and has been removed here.
|
|
14
|
+
|
|
15
|
+
## Install and set up
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
pipx install gra-context # or uv tool install; from this repository: pip install /path/to/gra-coding-assistant
|
|
19
|
+
cd /path/to/your/codebase
|
|
20
|
+
gra setup # registers the MCP server with Claude Code and Codex here
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
The first `gra setup` asks for an email and saves a free key from GRA's
|
|
24
|
+
service (one per email); `gra setup --api-key <key>` uses a key you already
|
|
25
|
+
have, for example on a second computer.
|
|
26
|
+
|
|
27
|
+
Then start a new Claude Code or Codex session in that codebase. On its first start the
|
|
28
|
+
server builds the map in the background (search is ready first, explanations
|
|
29
|
+
follow within minutes); after that it follows edits and commits by itself for
|
|
30
|
+
as long as Claude Code or Codex is open. Both share the same map and work log,
|
|
31
|
+
so work started in one can be picked up in the other. Codex support is tested with
|
|
32
|
+
Codex 0.151.0 and 0.164.0; with a version not tested yet, GRA checks that it can read the session
|
|
33
|
+
and, if it can't, says so in its first answer in Codex.
|
|
34
|
+
|
|
35
|
+
Installed Claude Code or Codex after setting up GRA? Run `gra setup` again in the repo.
|
|
36
|
+
|
|
37
|
+
Options for `gra setup`:
|
|
38
|
+
|
|
39
|
+
- `--scope project` registers the server for everyone in the repository, through `.mcp.json`
|
|
40
|
+
and `.codex/config.toml` (otherwise `.codex/config.toml` is kept out of git for this clone).
|
|
41
|
+
- `--agents-md` adds a line to `AGENTS.md` telling Claude Code and Codex to start from
|
|
42
|
+
`get_code_context`, and `@AGENTS.md` to `CLAUDE.md` so Claude Code reads it too.
|
|
43
|
+
(`--claude-md` is the old name for it.)
|
|
44
|
+
- `--context-filter off` turns off the model that leaves out noise. It runs on GRA's
|
|
45
|
+
service and is on whenever an API key is set.
|
|
46
|
+
|
|
47
|
+
Settings live in `~/.config/gra/config.env` (or the environment); maps live in
|
|
48
|
+
`~/.local/share/gra/` (or `GRA_DATA_DIR`), never inside the codebase.
|
|
49
|
+
|
|
50
|
+
## What it does
|
|
51
|
+
|
|
52
|
+
**The map.** Reads a Python codebase into symbols (files, classes, functions,
|
|
53
|
+
methods, module-level constants) and the connections between them (contains,
|
|
54
|
+
calls, references, imports, inherits, reads, writes, tests).
|
|
55
|
+
|
|
56
|
+
**Explanations.** Each symbol gets a one-line summary, up to three sentences
|
|
57
|
+
of detail and a short note on side effects. It is written from the symbol's
|
|
58
|
+
code plus the explanations of everything it calls, uses, extends or contains,
|
|
59
|
+
so those are explained first; each symbol is sent as soon as its own
|
|
60
|
+
dependencies are done, up to `EXPLANATION_CONCURRENCY` requests at once
|
|
61
|
+
(default 16). GRA's service writes them: your machine sends the symbol's code
|
|
62
|
+
and those notes, and the service adds its instructions and calls the model. An
|
|
63
|
+
explanation is rewritten only when the symbol's logic changes (comments and
|
|
64
|
+
formatting do not count) or the service's prompt version goes up.
|
|
65
|
+
|
|
66
|
+
**Retrieval.** Claude asks `get_code_context` where the code it needs is and
|
|
67
|
+
how its parts connect, one sentence per question, as questions come up. For
|
|
68
|
+
each question it gets the relevant code (the best-fitting symbols with their
|
|
69
|
+
explanations and file and line ranges; symbols alike in name and shape, such
|
|
70
|
+
as copies of a docs example, described once with their other places listed),
|
|
71
|
+
how it connects (the cheapest route through calls, uses and containment,
|
|
72
|
+
steering clear of shared helpers, with matches more than 4 steps apart left
|
|
73
|
+
unconnected), and one line naming the test files that reach it, with the
|
|
74
|
+
closest test in each. Three lists are kept back until a change breaks
|
|
75
|
+
something and Claude asks for them with `get_gra_details`: `depends_on` (what
|
|
76
|
+
that code calls and reads), `could_break` (the callers and tests that use it)
|
|
77
|
+
and `tests` (the test files in full). Last come notes on questions that turned
|
|
78
|
+
up the same code.
|
|
79
|
+
|
|
80
|
+
**Errors.** When a test fails or an error comes up and the cause is not clear
|
|
81
|
+
from the error, Claude calls `find_culprits`. It covers only the current task: the work since the last
|
|
82
|
+
`get_code_context` answer. GRA reads the output of the commands that failed
|
|
83
|
+
since then from the session's transcript, plus any error Claude passes, and
|
|
84
|
+
names up to three suspects, each with why: in the traceback (or used by a
|
|
85
|
+
failing test), edited since the task started, or on the path between the
|
|
86
|
+
two. With no traceback and no edits, it falls back to the callers of the
|
|
87
|
+
task's code, marked as a fallback.
|
|
88
|
+
No code is returned; Claude reads only the lines it will change. Tasks are
|
|
89
|
+
matched by meaning (a small local embedding model, `EMBEDDING_MODEL`, default
|
|
90
|
+
`fastembed:sentence-transformers/all-MiniLM-L6-v2`) and by words, with
|
|
91
|
+
meaning weighted higher; a symbol named in the task comes first. Between
|
|
92
|
+
equally good matches, the one called or used from more places ranks higher.
|
|
93
|
+
|
|
94
|
+
**Within a session.** `gra serve` runs once per Claude Code session and
|
|
95
|
+
remembers what it has told it, to keep Claude's context from filling up with
|
|
96
|
+
repeats. Answers are numbered. A symbol already described in Relevant code and
|
|
97
|
+
unchanged since comes back as one line marked `[aN]` (GRA answer N has the
|
|
98
|
+
rest), and Claude can fetch an answer it no longer has with
|
|
99
|
+
`get_earlier_answer`. Code edited this session whose explanation is not
|
|
100
|
+
rewritten yet is marked so Claude trusts the code over the summary.
|
|
101
|
+
|
|
102
|
+
**Work log, across sessions.** What Claude did with each answer is kept as one
|
|
103
|
+
record in `work_log.sqlite`, next to the codebase's map and never inside the
|
|
104
|
+
codebase. The record is read from Claude Code's transcript when the next call
|
|
105
|
+
comes, or when the server stops: the tasks, Claude's closing message as its
|
|
106
|
+
conclusion, the files read and edited, the commands run and whether they passed,
|
|
107
|
+
the `get_gra_details` lists used, and each changed symbol's hash before and
|
|
108
|
+
after. A task close to a recorded one (`GRA_RELATED_SIMILARITY`, default 0.5)
|
|
109
|
+
opens with "Earlier work on this": a line per record `[tK]` with how it ended
|
|
110
|
+
and whether its change still stands, worked out against the code at that
|
|
111
|
+
moment: still in place, built on since by a later record (shown first, with the
|
|
112
|
+
earlier ones as its history), undone since, or changed by work the log does not
|
|
113
|
+
know about; a change still in place also says when code it calls or reads has
|
|
114
|
+
changed since. A task whose Relevant code or path holds a symbol a record
|
|
115
|
+
changed, however differently worded, gets "Earlier changes to this code": why
|
|
116
|
+
it was changed and the test that checked it, so the new change keeps the old
|
|
117
|
+
one's goal. `get_earlier_work(K)` gives the whole record. Records older than 30
|
|
118
|
+
days are dropped unless their change is still in place.
|
|
119
|
+
|
|
120
|
+
**Leaving out noise.** Search returns its best matches, and some only share
|
|
121
|
+
words with the task. A fast decision model judges, in one request per answer,
|
|
122
|
+
whether each question needs each match and any related earlier work. Alike
|
|
123
|
+
matches are judged once, together, and the model sees each match as Claude
|
|
124
|
+
would (name, summary, signature), never its rank. What scores under
|
|
125
|
+
`CONTEXT_FILTER_THRESHOLD` (default 0.4) is left out, and the answer says how
|
|
126
|
+
many. A question always keeps at least one match, the one rated highest, and
|
|
127
|
+
symbols it names are never judged. If the model fails or takes more than 2
|
|
128
|
+
seconds, the answer goes out unfiltered; `filter=false` on the tool (or `gra
|
|
129
|
+
query --no-filter`) returns everything. The model (jev) runs behind GRA's
|
|
130
|
+
service: `CONTEXT_FILTER` is `gra:default` or `off`; unset, it is on when
|
|
131
|
+
`GRA_API_KEY` is set and off otherwise. Replayed on the 291 matches of the races up to
|
|
132
|
+
2026-10-20, labelled by whether Claude read them afterwards, jev at 0.4 kept
|
|
133
|
+
51% of the matches and 72 of the 83 Claude read, where keeping the top 3 by
|
|
134
|
+
rank kept 49% and only 56. It answers in about a quarter of a second.
|
|
135
|
+
|
|
136
|
+
**Ranking.** Search runs on your machine: it finds each question's best 50
|
|
137
|
+
matches by words and the best 50 by meaning. GRA's service puts them in their
|
|
138
|
+
final order (the two combined, matches used from more places lifted, symbols the
|
|
139
|
+
question names first), in one request per answer. The request carries only
|
|
140
|
+
positions and scores, no code or names, and adds about 0.05 seconds. Without
|
|
141
|
+
the service the matches come back in the order search found them: named
|
|
142
|
+
symbols, then by meaning.
|
|
143
|
+
|
|
144
|
+
**Staying current.** There are two copies of the map: `working.sqlite`
|
|
145
|
+
follows the files on disk, `symbols.sqlite` is the map as of the last commit.
|
|
146
|
+
The watcher inside the server updates the map about 2 seconds after edits
|
|
147
|
+
stop, so it keeps up with Claude mid-task, but writes explanations only after
|
|
148
|
+
60 seconds without edits, or at a commit. On start it catches up on anything
|
|
149
|
+
that changed while it was not running.
|
|
150
|
+
|
|
151
|
+
## Commands
|
|
152
|
+
|
|
153
|
+
```
|
|
154
|
+
gra setup [--api-key K] register the MCP server for the current codebase
|
|
155
|
+
gra key the GRA key saved on this computer
|
|
156
|
+
gra serve [--repo R] the MCP server itself (what Claude Code runs)
|
|
157
|
+
gra query "task" ... [--repo R] what Claude gets back for these tasks
|
|
158
|
+
gra show <name> [repo] a symbol, its explanation and its connections
|
|
159
|
+
gra index [repo] [--explain] update the map once by hand
|
|
160
|
+
gra watch [repo] keep the map current without Claude Code open
|
|
161
|
+
gra install [repo] first build plus a git post-commit hook
|
|
162
|
+
gra commit [repo] update and merge into the main map (what the hook runs)
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
## The explanation service (operators)
|
|
166
|
+
|
|
167
|
+
`gra-api` runs GRA's explanation service, which calls the model on GRA's
|
|
168
|
+
account (`GRA_API_MODEL`, default Gemini 2.5 Flash-Lite on Vertex AI). It is a
|
|
169
|
+
separate package, `gra-server` in `server/`, which runs on GRA's machines only:
|
|
170
|
+
customers install `gra-context`, which holds none of the service's code. Install
|
|
171
|
+
with `pip install ./server`.
|
|
172
|
+
|
|
173
|
+
```
|
|
174
|
+
gra-api create-key <name> [--monthly-limit N] a new API key, shown once
|
|
175
|
+
gra-api serve [--host H] [--port P] run it (default 127.0.0.1:8787)
|
|
176
|
+
gra-api usage this month's calls per key
|
|
177
|
+
gra-api block <name> / unblock <name> turn a key off or back on
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
Users get free keys themselves from `gra setup` (`/v1/signup`): one per email,
|
|
181
|
+
named by the email, with `FREE_MONTHLY_LIMIT` explanations a month. Emails are
|
|
182
|
+
not confirmed. nginx allows a few sign-ups per address per minute.
|
|
183
|
+
|
|
184
|
+
The service also ranks matches (`/v1/rank`) and runs the context filter
|
|
185
|
+
(`/v1/classify`, the jev model on OpenRouter: `GRA_API_FILTER_MODEL`,
|
|
186
|
+
`OPENROUTER_API_KEY`). Keys are stored only as hashes. Each explanation counts
|
|
187
|
+
against the key's monthly limit; a failed model call is not counted, and
|
|
188
|
+
ranking and filtering are not counted. Clients send a symbol's facts, not a
|
|
189
|
+
prompt: the service builds the prompt (`gra_server/explaining.py`), so it
|
|
190
|
+
explains code and nothing else, and a change to the instructions reaches every
|
|
191
|
+
client at once. Bump `PROMPT_VERSION` there when the instructions or fields
|
|
192
|
+
change; clients then write their explanations again. Code and prompts are sent
|
|
193
|
+
to the model and never stored or logged. Clients find the service at
|
|
194
|
+
`GRA_API_URL`.
|
|
195
|
+
|
|
196
|
+
## Layout
|
|
197
|
+
|
|
198
|
+
```
|
|
199
|
+
src/gra/core/ records, settings, data paths, embedding models, locks
|
|
200
|
+
src/gra/services/ extraction, resolution, explanations, search, answer assembly
|
|
201
|
+
src/gra/adapters/ SQLite store
|
|
202
|
+
src/gra/pipelines/ LangGraph pipelines: indexing, retrieval
|
|
203
|
+
src/gra/watcher.py keeps a map current; commit hook
|
|
204
|
+
src/gra/mcp_server.py the MCP server
|
|
205
|
+
src/gra/cli.py the gra command
|
|
206
|
+
tests/
|
|
207
|
+
server/ gra-server, GRA's service (never shipped to customers):
|
|
208
|
+
src/gra_server/ explanation prompts and models, ranking, the context filter's model, API keys
|
|
209
|
+
tests/
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
## Development
|
|
213
|
+
|
|
214
|
+
```
|
|
215
|
+
pip install -r requirements.txt # both packages in editable mode, with every optional part
|
|
216
|
+
pytest
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
Agentic pipelines are built with LangGraph.
|
|
220
|
+
|
|
221
|
+
**Two copies of the service.** The live one, at https://api.fiatpallet.com,
|
|
222
|
+
runs from its own install in `~/gra-prod`, built from a commit: editing this
|
|
223
|
+
repository never changes what customers get. To try a server change, run the
|
|
224
|
+
working tree's copy on port 8788 with its own keys:
|
|
225
|
+
|
|
226
|
+
```
|
|
227
|
+
scripts/dev-server.sh
|
|
228
|
+
GRA_API_URL=http://127.0.0.1:8788 GRA_API_KEY=$(cat ~/.local/share/gra/explain_api/dev-key) gra query "..."
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
Client changes need no server: the `gra` in `.venv` is this working tree, and
|
|
232
|
+
by default it uses the live service with the `GRA_API_KEY` in
|
|
233
|
+
`~/.config/gra/config.env` (`EXPLANATION_MODEL` there is no longer read). Eval
|
|
234
|
+
races do the same; to race a server change, add
|
|
235
|
+
`GRA_API_URL=http://127.0.0.1:8788` and the dev key to the `gra-context`
|
|
236
|
+
command in the eval's `repo.json`.
|
|
237
|
+
|
|
238
|
+
**Old clients keep working.** Customers upgrade at their own pace, so the
|
|
239
|
+
service must keep answering every published version of gra-context: add
|
|
240
|
+
fields and endpoints, do not rename or remove them.
|
|
241
|
+
|
|
242
|
+
## Releasing
|
|
243
|
+
|
|
244
|
+
The service (customers get it at once, nothing to install):
|
|
245
|
+
|
|
246
|
+
```
|
|
247
|
+
pytest
|
|
248
|
+
git commit ...
|
|
249
|
+
deploy/deploy-server.sh # builds the commit into ~/gra-prod and restarts it
|
|
250
|
+
deploy/deploy-server.sh <commit> # the same for an older commit: a rollback
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
`~/gra-prod/DEPLOYED` names the live commit. The service runs as the `gra-api`
|
|
254
|
+
systemd unit (`deploy/gra-api.service`) behind nginx (`deploy/gra_api.nginx`);
|
|
255
|
+
`journalctl -u gra-api` shows its log. Bump `PROMPT_VERSION` in
|
|
256
|
+
`server/src/gra_server/explaining.py` when the explanation instructions or
|
|
257
|
+
fields change, and every client writes its explanations again.
|
|
258
|
+
|
|
259
|
+
The package (customers run `pipx upgrade gra-context`):
|
|
260
|
+
|
|
261
|
+
```
|
|
262
|
+
# raise version in pyproject.toml (a published version can never be replaced)
|
|
263
|
+
pytest
|
|
264
|
+
rm -rf dist && python -m build --wheel -o dist .
|
|
265
|
+
twine check dist/* && twine upload dist/* # token in ~/.pypirc
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
Publish the wheel only, never the source bundle (it would carry the tests).
|
|
269
|
+
`PYPI.md` is the package's public page: keep internals out of it. When a
|
|
270
|
+
release needs a server change, deploy the server first.
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77"] # license as an SPDX expression
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "gra-context"
|
|
7
|
+
version = "0.1.3"
|
|
8
|
+
description = "A map of your codebase that coding agents query for context, served to Claude Code and Codex over MCP."
|
|
9
|
+
readme = "PYPI.md" # the public package page; README.md is for this repository
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = "LicenseRef-Proprietary"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
13
|
+
authors = [{name = "GRA"}]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Programming Language :: Python :: 3",
|
|
16
|
+
"Operating System :: OS Independent",
|
|
17
|
+
]
|
|
18
|
+
dependencies = [
|
|
19
|
+
"langgraph>=1.2,<2",
|
|
20
|
+
"langchain>=1.4,<2",
|
|
21
|
+
"langchain-core>=1.6,<2",
|
|
22
|
+
"pydantic>=2.12,<3",
|
|
23
|
+
"numpy>=1.26",
|
|
24
|
+
"httpx>=0.28",
|
|
25
|
+
"mcp>=2.3,<3",
|
|
26
|
+
"fastembed>=0.9",
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
[project.optional-dependencies]
|
|
30
|
+
# Meaning search with PyTorch models instead of the default.
|
|
31
|
+
huggingface = ["langchain-huggingface>=1.2", "sentence-transformers>=5.1"]
|
|
32
|
+
test = ["pytest>=8.4"]
|
|
33
|
+
|
|
34
|
+
[project.scripts]
|
|
35
|
+
gra = "gra.cli:main"
|
|
36
|
+
|
|
37
|
+
[tool.setuptools.packages.find]
|
|
38
|
+
where = ["src"]
|
|
File without changes
|
|
File without changes
|