mogestrator 0.0.1__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,22 @@
1
+ # mogestrator runtime state
2
+ .mog/
3
+ mogestrator.local.yaml
4
+ .env
5
+
6
+ # eval artifacts
7
+ docs/results/*.raw.json
8
+
9
+ # Python
10
+ __pycache__/
11
+ *.py[cod]
12
+ .venv/
13
+ venv/
14
+ build/
15
+ dist/
16
+ *.egg-info/
17
+ .mypy_cache/
18
+ .ruff_cache/
19
+ .pytest_cache/
20
+
21
+ # OS / editors
22
+ .DS_Store
@@ -0,0 +1,56 @@
1
+ # Contributing
2
+
3
+ > The project is in **M0 (planning)**. No product code exists yet, and that is
4
+ > deliberate — read the plan before writing any.
5
+
6
+ ## Read first
7
+
8
+ 1. [docs/PLAN.md](docs/PLAN.md) — the five failures we target, and what we are not building
9
+ 2. [docs/SPEC-context-graph.md](docs/SPEC-context-graph.md) — the core: nodes, anchors, retrieval, working set
10
+ 3. [docs/SPEC-policy.md](docs/SPEC-policy.md) — threat model, prompt layers, taint, egress
11
+ 4. [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md) — module layout and protocols
12
+ 5. [docs/EVALUATION.md](docs/EVALUATION.md) — how we find out if any of this works
13
+ 6. [docs/adr/](docs/adr/) — decisions made, with alternatives rejected
14
+
15
+ ## Where to start
16
+
17
+ The M1 checklist in [docs/ROADMAP.md](docs/ROADMAP.md) is the work queue. Take a
18
+ box, open an issue naming it, keep the PR scoped to it.
19
+
20
+ ## Ground rules
21
+
22
+ - **Specs lead code.** Changing the graph schema, the CLI surface, or a protocol
23
+ means updating its spec in the same PR.
24
+ - **Decisions get an ADR** — with the alternatives you rejected and why. Short is fine.
25
+ - **Context claims need numbers.** A PR that claims better retrieval must move a
26
+ metric in the eval harness against B0/B1/B3. "Feels better" is not a result,
27
+ and a negative result is a publishable one.
28
+ - **Security rules in SPEC-policy are not optional.** Untrusted content stays
29
+ framed and stays out of L0–L2. Memory writes respect origin trust.
30
+ - **Anchors are mandatory.** A derived fact without an anchor cannot be
31
+ invalidated, so it does not get stored.
32
+ - **Cross-platform from the start:** macOS, Linux, Windows.
33
+ - **Tests with behaviour.** Parsers and anchors get unit tests; retrieval gets
34
+ eval-suite coverage; policy gets adversarial tests, not happy-path ones.
35
+
36
+ ## Dev setup (once M1 lands)
37
+
38
+ ```bash
39
+ git clone https://github.com/prayag2301/Mogestrator.git
40
+ cd Mogestrator
41
+ uv venv && source .venv/bin/activate
42
+ pip install -r requirements.txt
43
+ ruff check . && mypy src && pytest
44
+ ```
45
+
46
+ ## Commits and PRs
47
+
48
+ Conventional commits (`feat:`, `fix:`, `docs:`, `perf:`, `sec:`). One concern per
49
+ PR, linked to the roadmap box it closes. State what a reviewer should verify by
50
+ hand.
51
+
52
+ ## Open questions
53
+
54
+ PLAN.md §9 tracks what is still undecided — embedding model, vector store,
55
+ auto-capture, gateway deployment mode, content storage. If your work depends on
56
+ one, resolve it in an ADR rather than picking silently.
@@ -0,0 +1,341 @@
1
+ Metadata-Version: 2.5
2
+ Name: mogestrator
3
+ Version: 0.0.1
4
+ Summary: A context substrate and policy gateway for coding agents: an anchored, self-invalidating code knowledge graph with eviction-and-recall memory, served over MCP.
5
+ Project-URL: Homepage, https://github.com/prayag2301/Mogestrator
6
+ Project-URL: Documentation, https://github.com/prayag2301/Mogestrator/tree/main/docs
7
+ Project-URL: Issues, https://github.com/prayag2301/Mogestrator/issues
8
+ Author: prayag2301
9
+ License: MIT
10
+ Keywords: agents,ai,claude,code-search,context,knowledge-graph,mcp,prompt-injection,rag
11
+ Classifier: Development Status :: 2 - Pre-Alpha
12
+ Classifier: Environment :: Console
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Topic :: Software Development :: Libraries
18
+ Classifier: Topic :: Text Processing :: Indexing
19
+ Requires-Python: >=3.11
20
+ Provides-Extra: all
21
+ Requires-Dist: anthropic>=0.40; extra == 'all'
22
+ Requires-Dist: cryptography>=43.0; extra == 'all'
23
+ Requires-Dist: fastapi>=0.115; extra == 'all'
24
+ Requires-Dist: mcp>=1.2; extra == 'all'
25
+ Requires-Dist: openai>=1.40; extra == 'all'
26
+ Requires-Dist: uvicorn>=0.30; extra == 'all'
27
+ Provides-Extra: api-embeddings
28
+ Requires-Dist: anthropic>=0.40; extra == 'api-embeddings'
29
+ Requires-Dist: openai>=1.40; extra == 'api-embeddings'
30
+ Provides-Extra: dev
31
+ Requires-Dist: mypy>=1.11; extra == 'dev'
32
+ Requires-Dist: pyinstaller>=6.10; extra == 'dev'
33
+ Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
34
+ Requires-Dist: pytest-benchmark>=4.0; extra == 'dev'
35
+ Requires-Dist: pytest>=8.2; extra == 'dev'
36
+ Requires-Dist: ruff>=0.6; extra == 'dev'
37
+ Provides-Extra: gateway
38
+ Requires-Dist: cryptography>=43.0; extra == 'gateway'
39
+ Requires-Dist: fastapi>=0.115; extra == 'gateway'
40
+ Requires-Dist: uvicorn>=0.30; extra == 'gateway'
41
+ Provides-Extra: mcp
42
+ Requires-Dist: mcp>=1.2; extra == 'mcp'
43
+ Description-Content-Type: text/markdown
44
+
45
+ # Mogestrator
46
+
47
+ **A context substrate and policy gateway for coding agents.**
48
+
49
+ Claude Code already orchestrates well — subagents, hooks, skills, MCP, plan mode.
50
+ What it doesn't have is memory that can be *checked*. Mogestrator keeps a live,
51
+ anchored, self-invalidating graph of your codebase and of what agents have
52
+ learned about it, serves precisely-scoped context on demand, and enforces prompt
53
+ integrity and network policy on every tool-using agent.
54
+
55
+ ```bash
56
+ uvx mogestrator index # nothing to install
57
+ mog serve --mcp # Claude Code now has a memory that knows when it's wrong
58
+ ```
59
+
60
+ > **Status: planning (M0).** The design is complete and documented; no code is
61
+ > written. Nothing below is installable today. Every performance and quality
62
+ > claim here is a **design target**, not a measurement — see
63
+ > [EVALUATION.md](docs/EVALUATION.md) for how each one gets validated, and
64
+ > [ROADMAP.md](docs/ROADMAP.md) for progress.
65
+
66
+ ---
67
+
68
+ ## The problem: compaction is a compression answer to a memory problem
69
+
70
+ Five failures show up in every long agentic session:
71
+
72
+ | | Failure | Why it happens |
73
+ |---|---|---|
74
+ | **F1** | After a compact, the agent forgets which file held the flag, the exact test error, the constraint you stated | Summarization keeps prose and drops precise anchors |
75
+ | **F2** | The summary says "auth lives in `middleware.py`". Forty edits later it doesn't, and nothing notices | A prose summary has no link to the code it describes, so it can't be invalidated |
76
+ | **F3** | Every new session — and every subagent spawn — re-derives the same repo facts from zero | No shared substrate; context is copied as text or re-grepped |
77
+ | **F4** | The agent retries the approach it ruled out 30 turns ago, hitting the same wall | The rejection and its reason were the first thing compaction dropped |
78
+ | **F5** | The same file gets read six times in a session to answer questions that needed one signature | Retrieval granularity is "the file" |
79
+
80
+ Compaction treats context as a **compression problem**. Mogestrator treats it as
81
+ a **memory-hierarchy problem** — and memory hierarchies are a solved discipline.
82
+ You don't compress a cache. You index it, score it, evict it, and fetch it back
83
+ on a miss.
84
+
85
+ ## The approach
86
+
87
+ ### 1. A typed graph, not a pile of chunks
88
+
89
+ Nodes are `Symbol`, `File`, `Module`, `Test`, `Config` — plus the half that
90
+ actually matters and that no re-index can rebuild: `Decision`, `Failure`,
91
+ `Constraint`, `Convention`, `Correction`. Edges are real relationships:
92
+ `calls`, `imports`, `tested_by`, `caused_by`, `supersedes`, and `co_changed`
93
+ (mined from git history — two symbols that change together in 8 of 10 commits
94
+ are coupled in a way no import graph shows).
95
+
96
+ ### 2. Anchors make memory falsifiable
97
+
98
+ Every fact carries a content-hash anchor, **never line numbers** — those shift on
99
+ every edit above them:
100
+
101
+ ```
102
+ anchor: { path: src/auth/middleware.py, symbol: verify_token,
103
+ span_hash: sha256:9f3c…, commit: b4ef335 }
104
+ ```
105
+
106
+ Re-index, the hash mismatches, the fact flips to `stale` — labelled and still
107
+ served with a warning, never silently wrong. `mog verify` gives you a drift rate:
108
+ a number for *how much of what the agent believes is no longer true*. A summary
109
+ can't do this, and that's the point.
110
+
111
+ ### 3. Seed-and-spread retrieval
112
+
113
+ ```
114
+ query → embed → k-NN → 8 SEEDS → budgeted graph walk (weighted, hop-decayed)
115
+ → fuse structural + semantic + recency → pack to token budget
116
+ ```
117
+
118
+ **Vectors find the door; edges walk the building.** "What breaks if I change
119
+ `parse_config`?" is answered *exactly* by inverting `calls` + `co_changed`.
120
+ Cosine similarity guesses at it and returns files that merely talk like config
121
+ code. Cost: one embedding call, then indexed SQL.
122
+
123
+ Every result carries its path from a seed, so bad retrieval is debuggable:
124
+
125
+ ```console
126
+ $ mog search "how are refresh tokens validated" --explain --budget 2000
127
+ 1. verify_token src/auth/middleware.py::verify_token L2 fresh
128
+ seed (cosine 0.83)
129
+ 2. TokenStore.refresh src/auth/store.py::refresh L2 fresh
130
+ verify_token ──calls──> refresh
131
+ 3. test_refresh_expiry tests/test_auth.py::test_refresh_expiry L1 fresh
132
+ verify_token ──tested_by──> test_refresh_expiry
133
+ ⚠ 1 related fact is stale: decision d_71 ("use HS256") — config.py changed 4 commits ago
134
+ 1,840 tokens · 32ms
135
+ ```
136
+
137
+ ### 4. Zoom levels — never read a whole file again
138
+
139
+ **L0** repo map (2–4k tokens) → **L1** file skeleton, signatures only → **L2** one
140
+ symbol body + its callers → **L3** full file with blame. Retrieval returns the
141
+ lowest zoom that answers the question.
142
+
143
+ ### 5. Eviction with recall, instead of compaction
144
+
145
+ Live context is a scored cache with an explicit budget:
146
+
147
+ ```
148
+ score = relevance × recency_decay × pin × (1 − staleness) × log(1 + hits)
149
+ ```
150
+
151
+ Over budget, evict lowest-first — and **leave a stub**:
152
+
153
+ ```
154
+ [evicted ctx_8f2a · "auth middleware token-refresh analysis" · 3.2k tokens
155
+ · recall: mog recall ctx_8f2a]
156
+ ```
157
+
158
+ 40 tokens holding the place of 3,200, and the original is recoverable
159
+ **verbatim**. Compaction rewrites those 3.2k tokens into 300 tokens of prose from
160
+ which nothing is recoverable — and doesn't tell the agent what it lost.
161
+ `Correction`, `Constraint`, and pinned items are never evictable.
162
+
163
+ ### 6. Warm subagents
164
+
165
+ A subagent gets a **context handle** — `ctx://run_7a1/task_3`, a query plus
166
+ pinned nodes — not a 20k-token transcript copy. It materializes exactly what it
167
+ needs at the zoom it needs. Cold starts (F3) stop being structural.
168
+
169
+ > Approaches considered and rejected — RAPTOR-style summarization trees, pure
170
+ > chunk RAG, LLMLingua-style token pruning, scratchpad markdown, KV-cache
171
+ > offload — are documented with their reasons in
172
+ > [ADR-0002](docs/adr/0002-graph-memory-over-summarization.md).
173
+
174
+ ---
175
+
176
+ ## The policy plane — for server-based chats
177
+
178
+ A hosted agent with tools has two exposures a local CLI mostly doesn't: a prompt
179
+ assembled from sources of mixed trust, and a network stack that will fetch
180
+ anything. And there's a sharper problem specific to us: **the context graph is
181
+ itself an injection vector.** Better memory without flow control is a
182
+ better-targeted vulnerability.
183
+
184
+ **Layered, signed prompts.** `identity → capability → policy → context → task`.
185
+ L0–L2 are digest-pinned and immutable at run time — retrieved content is
186
+ *structurally incapable* of landing there. Not "the model refuses to be
187
+ overridden": it can't reach the layer. Every layer's digest goes in the audit
188
+ record, so "what exactly was this agent told on Tuesday?" has an exact answer.
189
+
190
+ **Taint labels, not regex DLP.** Content carries `secret`, `repo:private`,
191
+ `web:untrusted`, `user:pii`, `derived`, `verified`, and labels **propagate
192
+ through derivation**. That catches the secret that was base64'd, paraphrased, or
193
+ split across two fields — because provenance is tracked, not strings. Rules are
194
+ flow constraints:
195
+
196
+ ```yaml
197
+ flows:
198
+ - deny: { taint: secret, to: egress }
199
+ - deny: { taint: web:untrusted, to: prompt_layer, at_or_above: policy }
200
+ - deny: { from: untrusted_instruction, to: write_action }
201
+ ```
202
+
203
+ **Default-deny egress firewall.** Per-agent host allowlists; private and
204
+ link-local CIDRs blocked (`169.254.169.254` — the cloud-metadata SSRF path);
205
+ DNS **resolved once and pinned** for the request's lifetime, defeating rebinding;
206
+ off-allowlist redirects refused; body-size and rate caps bounding any successful
207
+ exfiltration. The ledger records **which rule allowed each request**, not just
208
+ that it happened.
209
+
210
+ **Capability tokens** — short-lived, run-scoped, per-user, so the model never
211
+ sees a key and can't be talked into leaking one, and an agent acting for user B
212
+ can't use user A's permissions. **Canary tripwire** — a random token in the
213
+ policy layer; if it ever appears in an outbound payload, the run dies and the
214
+ session is quarantined.
215
+
216
+ In **proxy mode** the security property comes from network topology, not from the
217
+ agent's cooperation. A policy the agent could route around is documentation.
218
+
219
+ Full threat model (T1–T6) and specification: [SPEC-policy.md](docs/SPEC-policy.md).
220
+
221
+ ---
222
+
223
+ ## Installation
224
+
225
+ Full channel matrix and build/signing process: [DISTRIBUTION.md](docs/DISTRIBUTION.md).
226
+ *None of these work yet — they ship in M6.*
227
+
228
+ ```bash
229
+ # zero install — recommended first contact
230
+ uvx mogestrator index
231
+
232
+ # install as a tool
233
+ uv tool install mogestrator
234
+ pipx install mogestrator
235
+ pip install mogestrator
236
+
237
+ # no Python opinion
238
+ brew install prayag2301/tap/mog
239
+ curl -fsSL https://get.mogestrator.dev | sh # signed binary, checksum-verified
240
+ irm https://get.mogestrator.dev/ps1 | iex # Windows
241
+
242
+ # JS teams
243
+ npx @mogestrator/cli index
244
+
245
+ # containers
246
+ docker run --rm -v "$PWD:/w" -w /w ghcr.io/prayag2301/mogestrator index
247
+ ```
248
+
249
+ **In Claude Code** — the primary integration:
250
+
251
+ ```bash
252
+ claude mcp add mog -- mog serve --mcp --watch
253
+ ```
254
+
255
+ Claude Code gains `search_context`, `expand`, `impact`, `why`, `remember`,
256
+ `recall`, `pin`, and `verify` as tools. Also planned: a plugin marketplace entry
257
+ (`/mog-search`, `/mog-why`), `mise`, Nix, Scoop, and a VS Code extension.
258
+
259
+ ## Usage
260
+
261
+ ```bash
262
+ mog init # scaffold mogestrator.yaml, .mog/, .mogignore
263
+ mog index --watch # build the graph; incremental, stays live
264
+ mog status # counts, index age, anchor drift rate
265
+
266
+ mog search "where are refresh tokens validated" --explain --budget 2000
267
+ mog impact verify_token --tests # what breaks, and which tests cover it
268
+ mog why "why not RS256" # decisions, failures, constraints
269
+ mog map # L0 repo map
270
+
271
+ mog remember failure "RS256 rejected: key rotation needs infra we don't have" \
272
+ --anchor src/auth/config.py::load_keys
273
+ mog recall ctx_8f2a # restore an evicted item verbatim
274
+ mog pin n_9f3c
275
+
276
+ mog verify --fix # re-check every anchor, report drift
277
+ mog ws show # working set, scores, budget usage
278
+
279
+ mog serve --mcp --watch # expose to Claude Code / any MCP client
280
+ mog gateway --policy policy/ --port 8080 # policy plane for server-based chats
281
+ mog policy explain api.github.com # which rule allows this, and why
282
+ mog audit --egress --since 24h
283
+ ```
284
+
285
+ Full command reference: [SPEC-cli.md](docs/SPEC-cli.md).
286
+ Config: [SPEC-config.md](docs/SPEC-config.md).
287
+
288
+ ## What this is not
289
+
290
+ Not an agent framework or workflow engine — Claude Code orchestrates, we remember
291
+ and govern. Not a model or router. Not a RAG-over-chunks library (that's the
292
+ baseline we must beat). Not a hosted service in v1. Not a code-search UI for
293
+ humans — the consumer is an agent.
294
+
295
+ ## Does it actually work?
296
+
297
+ Unknown, and we refuse to pretend otherwise. Every claim above is a hypothesis
298
+ until [EVALUATION.md](docs/EVALUATION.md) says otherwise. The harness measures
299
+ against four baselines — `rg` + full file reads (**B0**), chunk RAG (**B1**),
300
+ no management (**B2**), and summarization compaction (**B3**) — on localization,
301
+ impact, multi-session continuity, repeat-failure avoidance, staleness handling,
302
+ and cold subagent start.
303
+
304
+ Hard gates: **M2 doesn't ship** unless seed-and-spread beats both `rg` and chunk
305
+ RAG on tokens-to-correct-answer. **M4 doesn't ship** unless eviction-and-recall
306
+ beats compaction on continuity. **M5 doesn't ship** unless zero injected
307
+ memories reach a high-trust prompt layer.
308
+
309
+ If the graph loses to ripgrep, we publish that and change course. Negative
310
+ results go in `docs/results/` too.
311
+
312
+ ## Documentation
313
+
314
+ | Document | Contents |
315
+ |---|---|
316
+ | [PLAN.md](docs/PLAN.md) | The five failures, the three planes, scope, milestones, risks, open questions |
317
+ | [SPEC-context-graph.md](docs/SPEC-context-graph.md) | **The core** — nodes, edges, anchors, zoom, seed-and-spread, working set, storage, MCP tools |
318
+ | [SPEC-policy.md](docs/SPEC-policy.md) | Threat model, prompt layers, taint flow, egress firewall, capabilities, audit |
319
+ | [ARCHITECTURE.md](docs/ARCHITECTURE.md) | Module layout, protocols, request paths, degradation, perf targets |
320
+ | [EVALUATION.md](docs/EVALUATION.md) | Baselines, suites, metrics, ship gates |
321
+ | [SPEC-cli.md](docs/SPEC-cli.md) · [SPEC-config.md](docs/SPEC-config.md) | `mog` commands · `mogestrator.yaml` |
322
+ | [DISTRIBUTION.md](docs/DISTRIBUTION.md) | 16 install channels, build and signing |
323
+ | [ROADMAP.md](docs/ROADMAP.md) | M1–M6 checklists — the work queue |
324
+ | [adr/](docs/adr/) | Six decisions, each with the alternatives rejected |
325
+
326
+ ## Requirements
327
+
328
+ Python 3.11+ (pip/uv/pipx channels only — binary, Homebrew, npm, and Docker
329
+ bundle their own runtime) · Git · a tree-sitter-supported language for symbol-level
330
+ indexing (Python, TypeScript, Go, Rust at M1; others degrade to file-level).
331
+ No API key needed: embeddings run locally by default and your code never leaves
332
+ the machine.
333
+
334
+ ## Contributing
335
+
336
+ M0 is done; M1 is open. [CONTRIBUTING.md](CONTRIBUTING.md) — specs lead code,
337
+ decisions get an ADR, and context claims need numbers.
338
+
339
+ ## License
340
+
341
+ MIT.