mason-context 0.1.0 → 0.2.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/README.md CHANGED
@@ -1,154 +1,116 @@
1
- # Mason
1
+ # Mason – the context builder for LLMs 👷
2
2
 
3
- A context engineering tool that helps LLMs understand your codebase. Mason handles the expensive parts aggregating git history, selecting architecturally important files, mapping test coverage, and persisting project knowledge across sessions — so the LLM can focus on interpretation.
3
+ Mason gives LLMs a persistent map of your codebase so they stop exploring from scratch every session.
4
4
 
5
- Works as an **MCP server** (for Claude Code, Cursor, etc.) or as a **standalone CLI** with any LLM provider.
5
+ **The problem:** Every time an LLM starts a new conversation about your code, it greps, reads files, and pieces together the architecture — burning tokens on context it already understood yesterday. On a 164-file project, answering "what features does this app have?" requires reading 8+ files across multiple tool calls.
6
6
 
7
- ## Quick start
8
-
9
- ```bash
10
- npx mason-ai setup # registers Mason with Claude Code
11
- ```
12
-
13
- Restart Claude Code, then ask: "use mason to analyze this project and generate a CLAUDE.md."
7
+ **Mason's fix:** A concept map that persists across sessions. One tool call returns a feature-to-file lookup table — the LLM knows exactly where to look, without exploring.
14
8
 
15
- ## Install
9
+ **Measured result** ([deepeval](https://github.com/confident-ai/deepeval), Claude Sonnet, 164-file KMP project):
16
10
 
17
- ```bash
18
- npm install -g mason-ai
19
- ```
20
-
21
- ## Usage
11
+ | Question | With Mason | Without Mason | Token saving |
12
+ |---|---|---|---|
13
+ | List all features | 10,258 tok | 31,346 tok | **67%** |
14
+ | Trace data flow | 12,010 tok | 15,258 tok | **21%** |
15
+ | Compare platforms | 10,897 tok | 19,353 tok | **44%** |
16
+ | Onboarding flow | 10,271 tok | 11,432 tok | **10%** |
17
+ | **Average** | | | **36%** |
22
18
 
23
- ### As an MCP server (recommended)
19
+ Same answer quality (0.9/1.0 on all tests, both paths). Reproduce: [bench/](bench/).
24
20
 
25
- One-command setup for Claude Code:
26
-
27
- ```bash
28
- mason setup # registers with Claude Code (user scope)
29
- mason setup --scope project # project-scoped instead
30
- ```
31
-
32
- Or manually:
21
+ ## Quick start
33
22
 
34
23
  ```bash
35
- claude mcp add mason -- npx mason-ai mcp
24
+ claude mcp add mason --scope user -- npx mason-context mcp
36
25
  ```
37
26
 
38
- Then ask Claude to generate a CLAUDE.md it will call Mason's tools automatically.
27
+ Restart Claude Code, then ask: *"use mason to analyze this project and create a snapshot."*
39
28
 
40
- Mason exposes 9 tools via MCP:
29
+ That's it — Mason will analyze your codebase and create a concept map. Next session, it loads the map instead of re-exploring everything.
41
30
 
42
- | Tool | What it does |
43
- |---|---|
44
- | `full_analysis` | All-in-one: git stats + project structure + code samples + test map + snapshot |
45
- | `get_snapshot` | Load persistent project snapshot (auto-detects staleness) |
46
- | `save_snapshot` | Save file summaries for future sessions (no API key needed) |
47
- | `configure_project` | Customize sampling — add patterns, always-include files, ignore paths |
48
- | `analyze_project` | Git history stats (commit patterns, stale dirs, hot files) |
49
- | `get_code_samples` | Smart file previews — config, entry points, architectural patterns, tests |
50
- | `get_file_content` | Read any file in full (drill-down after previewing) |
51
- | `get_project_structure` | Directory tree with file counts and extension breakdown |
52
- | `get_test_map` | Map test files to source files by name matching |
53
-
54
- ### Persistent snapshots
55
-
56
- Mason persists its understanding of your project across conversations, saving thousands of tokens per session.
57
-
58
- **Via MCP (no API key needed):**
31
+ ## How it works
59
32
 
60
- Ask your AI assistant to "create a mason snapshot for this project." It will analyze the codebase, summarize key files, and call `save_snapshot` to persist. Next session, it loads the snapshot via `get_snapshot` instead of re-reading everything. If the snapshot is stale (files changed since last update), Mason tells the LLM exactly which files to re-read.
33
+ ### Concept map
61
34
 
62
- **Via CLI (requires LLM provider):**
35
+ Mason's core feature. It persists a feature-to-file map in `.mason/snapshot.json` that survives across conversations. When the LLM needs to understand your project, it reads this map instead of grepping through your entire codebase:
63
36
 
64
- ```bash
65
- mason set-llm gemini AIza-xxx # configure a provider
66
- mason snapshot ~/my-project # generate snapshot
67
- mason snapshot --install-hook # auto-update on every commit
37
+ ```json
38
+ {
39
+ "features": {
40
+ "home screen": {
41
+ "files": ["HomeScreen.kt", "HomeViewModel.kt", "GetWeatherDataUseCase.kt"]
42
+ }
43
+ },
44
+ "flows": {
45
+ "weather fetch": {
46
+ "chain": ["HomeViewModel.kt", "WeatherRepositoryImpl.kt", "WeatherServiceImpl.kt"]
47
+ }
48
+ }
49
+ }
68
50
  ```
69
51
 
70
- ### As a standalone CLI
52
+ The map is generated by the LLM itself — Mason provides the analysis tools, and the LLM interprets your code to decide what the features and flows are. This means the map captures architectural understanding, not just file listings.
71
53
 
72
- Configure an LLM provider once:
54
+ Create one by asking your AI assistant to *"create a mason snapshot"*, or via CLI:
73
55
 
74
56
  ```bash
75
- mason set-llm claude sk-ant-xxx # Anthropic
76
- mason set-llm gemini AIza-xxx # Google (free tier available)
77
- mason set-llm openai sk-xxx # OpenAI
78
- mason set-llm ollama # Local, no API key needed
57
+ mason set-llm gemini # configure a provider (no API key needed)
58
+ mason snapshot ~/my-project # generate concept map
59
+ mason snapshot --install-hook # auto-update on every commit
79
60
  ```
80
61
 
81
- Then generate:
62
+ ### Change impact analysis
82
63
 
83
- ```bash
84
- mason generate # current directory
85
- mason generate ~/my-project # specific directory
86
- mason generate --model claude-haiku-4-5-20251001 # override model
87
- ```
64
+ Before editing a file, Mason can tell you what else might be affected. It combines three signals that would each require multiple tool calls to gather manually:
88
65
 
89
- ### Just analyze (no LLM needed)
66
+ - **Co-change history** files that historically change together in git commits
67
+ - **References** — files that import or mention the target by name
68
+ - **Related tests** — test files paired to the target by naming convention
90
69
 
91
70
  ```bash
92
- mason analyze # print git history findings
71
+ mason impact WeatherRepository.kt -d ~/my-project
93
72
  ```
94
73
 
95
- ## How it works
96
-
97
- Mason's philosophy: **the LLM is smart, Mason is fast.** Instead of trying to understand your code (badly, with regex), Mason does what LLMs can't do cheaply:
74
+ Also available as the `get_impact` MCP tool — ask your assistant *"what would be affected if I changed WeatherRepository?"*
98
75
 
99
- 1. **Aggregate stats** across hundreds of commits — stale directories, hot files, commit conventions
100
- 2. **Select the right files** — architecturally important files the LLM should read, based on naming patterns (ViewModel, Repository, Service, Module, UseCase, etc.)
101
- 3. **Pair interfaces with implementations** — surfaces both `WeatherRepository.kt` and `WeatherRepositoryImpl.kt`
102
- 4. **Include module build files** — so the LLM can infer the dependency graph itself
103
- 5. **Map tests to source** — structural test coverage analysis
104
- 6. **Persist knowledge** — snapshot summaries survive across conversations, eliminating cold-start token waste
76
+ ### Git history analysis
105
77
 
106
- The LLM does all the interpretation identifying conventions, understanding patterns, writing rules. Mason just makes sure it sees the right files and remembers what it learned.
78
+ Mason aggregates hundreds of commits into actionable stats: which files change most often (hot files you should be careful with), which directories haven't been touched in months (potentially stale code), and what commit conventions the team follows. This is the kind of analysis that would take dozens of `git log` calls to compute manually.
107
79
 
108
- ## Smart file sampling
80
+ ```bash
81
+ mason analyze ~/my-project
82
+ ```
109
83
 
110
- Mason doesn't dump your whole repo. It picks ~25 files across these categories:
84
+ ## MCP tools
111
85
 
112
- - **Config files** build configs, linter configs, version catalogs
113
- - **Module build files** — subdirectory build files that reveal dependency graphs
114
- - **Entry points** — main files, app entry points
115
- - **Hot files** — most frequently changed in the last 3 months (from git)
116
- - **Architectural files** — ViewModels, Repositories, Services, DI Modules, UseCases, Mappers, Controllers, Middleware
117
- - **Both interfaces and implementations** — `*Repository.*` and `*RepositoryImpl.*`
118
- - **Test examples** — diverse across languages (JVM, Swift, Python, Go, etc.)
119
- - **Directory representatives** — one source file per top-level directory for breadth
86
+ Mason exposes 6 tools via the Model Context Protocol. Any MCP-compatible client (Claude Code, Cursor, etc.) can use them:
120
87
 
121
- All files are returned as previews (~60 lines) with metadata. The LLM can request full content of any file it wants to dig into.
88
+ | Tool | What it does |
89
+ |---|---|
90
+ | `get_snapshot` | Load the concept map — maps features/flows to files |
91
+ | `save_snapshot` | Persist the concept map for future sessions |
92
+ | `get_impact` | Change impact: co-change history, references, related tests |
93
+ | `analyze_project` | Git history: commit patterns, hot files, stale dirs |
94
+ | `full_analysis` | All-in-one first visit: git stats + structure + code samples + test map |
95
+ | `get_code_samples` | Smart file previews selected by architectural role |
122
96
 
123
- ### Custom patterns
97
+ ## CLI usage
124
98
 
125
- Mason's built-in patterns won't catch everything. If your project uses different naming conventions (e.g., `*Gateway*` instead of `*Repository*`, `*Bloc*` instead of `*ViewModel*`), configure it per-project:
99
+ Mason also works as a standalone CLI for generating CLAUDE.md files and running analysis without an MCP client. Configure an LLM provider once, then use any command:
126
100
 
127
- ```json
128
- // .mason/config.json
129
- {
130
- "patterns": ["**/*Gateway.*", "**/*Bloc.*", "**/*Cubit.*"],
131
- "alwaysInclude": ["src/core/config.ts", "lib/injection.dart"],
132
- "ignore": ["**/fixtures/**", "**/mocks/**"]
133
- }
101
+ ```bash
102
+ mason set-llm claude|gemini|ollama|openai # configure provider
103
+ mason generate # analyze codebase + LLM -> CLAUDE.md
104
+ mason analyze # git stats only (no LLM needed)
105
+ mason impact File.kt # change impact analysis
106
+ mason snapshot # create/update concept map
134
107
  ```
135
108
 
136
- Or let the LLM configure it via the `configure_project` MCP tool when it notices the sampler missed important files.
109
+ Most providers work without an API key `claude`, `gemini`, and `ollama` all use their respective CLIs directly.
137
110
 
138
111
  ## Language support
139
112
 
140
- Mason is completely language-agnostic. It works with any project that has source files and a git history:
141
-
142
- - TypeScript/JavaScript (React, Node, etc.)
143
- - Kotlin (Android, KMP, server)
144
- - Java (Spring, Android)
145
- - Python (Django, FastAPI, etc.)
146
- - Go
147
- - Rust
148
- - Swift (iOS, SwiftUI)
149
- - Ruby, C#, C++, Dart, and more
150
-
151
- No language-specific parsing — the architectural file selection works by naming conventions that are common across ecosystems.
113
+ Mason is completely language-agnostic. It uses file naming patterns and git history rather than language-specific parsing, so it works with any project that has source files and a git repository — TypeScript, Kotlin, Python, Go, Rust, Swift, Java, C#, Dart, and more.
152
114
 
153
115
  ## License
154
116