writing-context-rtfm 0.5.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.
- writing_context_rtfm-0.5.0/.github/workflows/publish.yml +52 -0
- writing_context_rtfm-0.5.0/.gitignore +58 -0
- writing_context_rtfm-0.5.0/CHANGELOG.md +44 -0
- writing_context_rtfm-0.5.0/LICENSE +21 -0
- writing_context_rtfm-0.5.0/PKG-INFO +265 -0
- writing_context_rtfm-0.5.0/README.md +236 -0
- writing_context_rtfm-0.5.0/docs/features_guide.md +155 -0
- writing_context_rtfm-0.5.0/docs/testing_strategy.md +25 -0
- writing_context_rtfm-0.5.0/docs/writing-context-rtfm_architecture.md +910 -0
- writing_context_rtfm-0.5.0/docs/writing-context-rtfm_detailed_design.md +982 -0
- writing_context_rtfm-0.5.0/docs/writing-context-rtfm_workflow_guide.md +109 -0
- writing_context_rtfm-0.5.0/examples/.writing-context/config.yaml +22 -0
- writing_context_rtfm-0.5.0/examples/.writing-context/section_cards.yaml +41 -0
- writing_context_rtfm-0.5.0/prompts/agent_instructions.md +68 -0
- writing_context_rtfm-0.5.0/prompts/generate_section_cards.md +154 -0
- writing_context_rtfm-0.5.0/pyproject.toml +47 -0
- writing_context_rtfm-0.5.0/scratch/test_mcp.py +64 -0
- writing_context_rtfm-0.5.0/scratch/test_mcp_call.py +74 -0
- writing_context_rtfm-0.5.0/scripts/ab_test_generation.py +146 -0
- writing_context_rtfm-0.5.0/scripts/build_prompts.py +106 -0
- writing_context_rtfm-0.5.0/src/writing_context_rtfm/__init__.py +2 -0
- writing_context_rtfm-0.5.0/src/writing_context_rtfm/cli.py +642 -0
- writing_context_rtfm-0.5.0/src/writing_context_rtfm/config.py +103 -0
- writing_context_rtfm-0.5.0/src/writing_context_rtfm/context_pack.py +1029 -0
- writing_context_rtfm-0.5.0/src/writing_context_rtfm/features.py +360 -0
- writing_context_rtfm-0.5.0/src/writing_context_rtfm/hashing.py +38 -0
- writing_context_rtfm-0.5.0/src/writing_context_rtfm/latex.py +205 -0
- writing_context_rtfm-0.5.0/src/writing_context_rtfm/proofread.py +269 -0
- writing_context_rtfm-0.5.0/src/writing_context_rtfm/rtfm_adapter.py +89 -0
- writing_context_rtfm-0.5.0/src/writing_context_rtfm/schemas.py +12 -0
- writing_context_rtfm-0.5.0/src/writing_context_rtfm/section_cards.py +108 -0
- writing_context_rtfm-0.5.0/src/writing_context_rtfm/server.py +960 -0
- writing_context_rtfm-0.5.0/src/writing_context_rtfm/storage.py +258 -0
- writing_context_rtfm-0.5.0/src/writing_context_rtfm/token_budget.py +29 -0
- writing_context_rtfm-0.5.0/src/writing_context_rtfm/utils.py +68 -0
- writing_context_rtfm-0.5.0/tests/__init__.py +0 -0
- writing_context_rtfm-0.5.0/tests/conftest.py +11 -0
- writing_context_rtfm-0.5.0/tests/eval/__init__.py +0 -0
- writing_context_rtfm-0.5.0/tests/eval/metrics.py +45 -0
- writing_context_rtfm-0.5.0/tests/eval/rubric.py +21 -0
- writing_context_rtfm-0.5.0/tests/fixtures/expected_sources.yaml +6 -0
- writing_context_rtfm-0.5.0/tests/fixtures/gold/03_approach.tex +19 -0
- writing_context_rtfm-0.5.0/tests/fixtures/masked/03_approach.tex +2 -0
- writing_context_rtfm-0.5.0/tests/fixtures/mini_latex_project/.writing-context/section_cards.yaml +22 -0
- writing_context_rtfm-0.5.0/tests/fixtures/mini_latex_project/main.tex +36 -0
- writing_context_rtfm-0.5.0/tests/fixtures/mini_latex_project/sections/01_intro.tex +9 -0
- writing_context_rtfm-0.5.0/tests/fixtures/mini_latex_project/sections/02_related.tex +7 -0
- writing_context_rtfm-0.5.0/tests/fixtures/mini_latex_project/sections/03_approach.tex +19 -0
- writing_context_rtfm-0.5.0/tests/fixtures/mini_latex_project/sections/04_results.tex +20 -0
- writing_context_rtfm-0.5.0/tests/fixtures/rubrics/methodology_missing.yaml +22 -0
- writing_context_rtfm-0.5.0/tests/test_caching_robustness.py +99 -0
- writing_context_rtfm-0.5.0/tests/test_cli_init.py +145 -0
- writing_context_rtfm-0.5.0/tests/test_config.py +12 -0
- writing_context_rtfm-0.5.0/tests/test_context_pack.py +171 -0
- writing_context_rtfm-0.5.0/tests/test_context_pack_retrieval.py +70 -0
- writing_context_rtfm-0.5.0/tests/test_imports.py +22 -0
- writing_context_rtfm-0.5.0/tests/test_latex_parser.py +181 -0
- writing_context_rtfm-0.5.0/tests/test_masked_section_eval.py +41 -0
- writing_context_rtfm-0.5.0/tests/test_mcp_contract.py +128 -0
- writing_context_rtfm-0.5.0/tests/test_milestone1.py +257 -0
- writing_context_rtfm-0.5.0/tests/test_milestone2.py +342 -0
- writing_context_rtfm-0.5.0/tests/test_milestone3.py +266 -0
- writing_context_rtfm-0.5.0/tests/test_new_features.py +381 -0
- writing_context_rtfm-0.5.0/tests/test_pack_stabilization.py +254 -0
- writing_context_rtfm-0.5.0/tests/test_proofread.py +231 -0
- writing_context_rtfm-0.5.0/tests/test_rtfm_adapter.py +198 -0
- writing_context_rtfm-0.5.0/tests/test_storage.py +185 -0
- writing_context_rtfm-0.5.0/tests/test_token_budget.py +39 -0
- writing_context_rtfm-0.5.0/tests/test_token_reduction.py +62 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- 'v*'
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
test:
|
|
10
|
+
name: Run Test Suite
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
steps:
|
|
13
|
+
- name: Checkout repository
|
|
14
|
+
uses: actions/checkout@v4
|
|
15
|
+
|
|
16
|
+
- name: Install uv
|
|
17
|
+
uses: astral-sh/setup-uv@v5
|
|
18
|
+
with:
|
|
19
|
+
enable-cache: true
|
|
20
|
+
|
|
21
|
+
- name: Set up Python
|
|
22
|
+
uses: actions/setup-python@v5
|
|
23
|
+
with:
|
|
24
|
+
python-version: "3.11"
|
|
25
|
+
|
|
26
|
+
- name: Install dependencies and run tests
|
|
27
|
+
run: |
|
|
28
|
+
uv sync --all-extras --dev
|
|
29
|
+
uv run pytest
|
|
30
|
+
|
|
31
|
+
publish:
|
|
32
|
+
name: Publish to PyPI
|
|
33
|
+
needs: test
|
|
34
|
+
runs-on: ubuntu-latest
|
|
35
|
+
# This environment name should match the environment defined in your PyPI trusted publisher config (optional, but recommended)
|
|
36
|
+
environment: release
|
|
37
|
+
permissions:
|
|
38
|
+
# CRITICAL: This permission is required for Trusted Publishing (OIDC) authentication
|
|
39
|
+
id-token: write
|
|
40
|
+
contents: read
|
|
41
|
+
steps:
|
|
42
|
+
- name: Checkout repository
|
|
43
|
+
uses: actions/checkout@v4
|
|
44
|
+
|
|
45
|
+
- name: Install uv
|
|
46
|
+
uses: astral-sh/setup-uv@v5
|
|
47
|
+
|
|
48
|
+
- name: Build package
|
|
49
|
+
run: uv build
|
|
50
|
+
|
|
51
|
+
- name: Publish package to PyPI
|
|
52
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# Environments
|
|
2
|
+
.env
|
|
3
|
+
.venv
|
|
4
|
+
venv/
|
|
5
|
+
env/
|
|
6
|
+
ENV/
|
|
7
|
+
|
|
8
|
+
# Python
|
|
9
|
+
__pycache__/
|
|
10
|
+
*.py[cod]
|
|
11
|
+
*$py.class
|
|
12
|
+
*.so
|
|
13
|
+
build/
|
|
14
|
+
develop-eggs/
|
|
15
|
+
dist/
|
|
16
|
+
downloads/
|
|
17
|
+
eggs/
|
|
18
|
+
.eggs/
|
|
19
|
+
lib/
|
|
20
|
+
lib64/
|
|
21
|
+
parts/
|
|
22
|
+
sdist/
|
|
23
|
+
var/
|
|
24
|
+
wheels/
|
|
25
|
+
*.egg-info/
|
|
26
|
+
.installed.cfg
|
|
27
|
+
*.egg
|
|
28
|
+
uv.lock
|
|
29
|
+
|
|
30
|
+
# SQLite / Local Databases
|
|
31
|
+
*.db
|
|
32
|
+
*.sqlite
|
|
33
|
+
*.sqlite3
|
|
34
|
+
|
|
35
|
+
# OS / IDE
|
|
36
|
+
.DS_Store
|
|
37
|
+
.idea/
|
|
38
|
+
.vscode/
|
|
39
|
+
.gemini/
|
|
40
|
+
|
|
41
|
+
# Generated outputs
|
|
42
|
+
tests/fixtures/output/
|
|
43
|
+
prompt_a_full.txt
|
|
44
|
+
prompt_b_pack.txt
|
|
45
|
+
result_a.txt
|
|
46
|
+
result_b.txt
|
|
47
|
+
|
|
48
|
+
# RTFM / Writing Context Cache
|
|
49
|
+
.rtfm/
|
|
50
|
+
.writing-context/context_cache.sqlite
|
|
51
|
+
*.log
|
|
52
|
+
|
|
53
|
+
# Simulation Sandbox
|
|
54
|
+
sandbox/
|
|
55
|
+
|
|
56
|
+
# Local configuration and guidelines
|
|
57
|
+
.claude/
|
|
58
|
+
GEMINI.md
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## [0.5.0] - 2026-05-22
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- **Enhanced Project Initialization**: `init` command now auto-configures and updates `.gitignore` to ignore the local database, `.mcp.json` to register the MCP server (auto-detecting `uv`), and guideline files (`CLAUDE.md`, `AGENTS.md`, `GEMINI.md`) with rules blocks.
|
|
14
|
+
- **Rules Anchoring**: Guidelines are updated non-destructively using comments `<!-- writing-context-rtfm MCP tools -->` to prevent duplication.
|
|
15
|
+
- **Self-Documenting Configuration**: The generated config template is fully commented, explaining how to configure default budgets, reserved margins, and role budget allocations.
|
|
16
|
+
- **Unified Token Budget Tuning**: Spans dropped due to token limit caps calculate and recommend a minimum target budget size to allow LLM client agents to self-correct dynamically.
|
|
17
|
+
|
|
18
|
+
### Changed
|
|
19
|
+
- **Dynamic Server Versioning**: Server initialization dynamically returns the package version instead of a hardcoded string.
|
|
20
|
+
|
|
21
|
+
### Fixed
|
|
22
|
+
- **UnboundLocalError in Context Packer**: Corrected variable naming to prevent referencing unbound variables when checking target source spans.
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## [0.1.0] - 2026-05-20
|
|
27
|
+
|
|
28
|
+
### Added
|
|
29
|
+
- **Interactive Scaffolding**: Added `initialize_section_cards` tool and CLI subcommand to auto-scan `.tex`/`.md` files and populate `.writing-context/section_cards.yaml`.
|
|
30
|
+
- **Context Pagination**: Added support for progressive retrieval with `request_more_context` and SQLite schema integration (`selected` flag) to load remaining background context spans.
|
|
31
|
+
- **Feedback Loops**: Added evaluation recording using `submit_generation_feedback` to persist metric scores (`helpfulness`, `hallucinations`, `constraint_violated`) into `evaluation_records`.
|
|
32
|
+
- **Terminology Auditing**: Added `audit_manuscript_terminology` tool to cross-examine key terms in section cards against index occurrences and detect undeclared usage or missing definitions.
|
|
33
|
+
- **Native Prompts Integration**: Exposed standard MCP prompt endpoints (`write_section`, `proofread_section`).
|
|
34
|
+
- **Cache Management CLI**: Added subcommands `writing-context-rtfm cache stats` and `writing-context-rtfm cache clear`.
|
|
35
|
+
|
|
36
|
+
### Changed
|
|
37
|
+
- **Robust Cache Invalidation**: Migrated static caching hashes to SHA-256 content hashes.
|
|
38
|
+
- **Dynamic Fingerprinting**: Replaced the static index fingerprint with a dynamic SHA-256 value computed from the modification time and file size of `.rtfm/library.db`.
|
|
39
|
+
- **Dependency Classification**: Classify retrieved key terms for dependencies under `"dep_key_term"`.
|
|
40
|
+
|
|
41
|
+
### Fixed
|
|
42
|
+
- **Proofreading Bounds Clamping**: Swapped and clamped invalid line numbers early during proofread context generation.
|
|
43
|
+
- **Path Normalization**: Resolved relative paths to absolute paths before validating file matches.
|
|
44
|
+
- **Search Resilience**: Wrapped terminology searches in try-except blocks.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Joao Carlos
|
|
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.
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: writing-context-rtfm
|
|
3
|
+
Version: 0.5.0
|
|
4
|
+
Summary: MCP extension for writing-context retrieval relying on RTFM
|
|
5
|
+
Author: João Carlos N. Bittencourt
|
|
6
|
+
License: MIT
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Keywords: context-reduction,llm-writing,mcp,mcp-server,rtfm
|
|
9
|
+
Classifier: Development Status :: 4 - Beta
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
17
|
+
Requires-Python: >=3.11
|
|
18
|
+
Requires-Dist: pylatexenc
|
|
19
|
+
Requires-Dist: pyyaml
|
|
20
|
+
Requires-Dist: rtfm-ai
|
|
21
|
+
Provides-Extra: dev
|
|
22
|
+
Requires-Dist: mypy; extra == 'dev'
|
|
23
|
+
Requires-Dist: pytest; extra == 'dev'
|
|
24
|
+
Requires-Dist: ruff; extra == 'dev'
|
|
25
|
+
Requires-Dist: types-pyyaml; extra == 'dev'
|
|
26
|
+
Provides-Extra: tiktoken
|
|
27
|
+
Requires-Dist: tiktoken; extra == 'tiktoken'
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
|
|
30
|
+
<!-- mcp-name: writing-context-rtfm -->
|
|
31
|
+
<div align="center">
|
|
32
|
+
|
|
33
|
+
***Surgical Context for Writing Agents***
|
|
34
|
+
|
|
35
|
+
Stop giving your AI agent the entire manuscript to write one section. Give it the exact paragraphs, constraints, and dependencies it needs to succeed. No token bloat. No hallucinations.
|
|
36
|
+
|
|
37
|
+
**`Lightweight · Task-Focused · Extension · MIT`**
|
|
38
|
+
|
|
39
|
+
<br>
|
|
40
|
+
|
|
41
|
+
[](https://opensource.org/licenses/MIT) [](https://www.python.org/) [](https://modelcontextprotocol.io/) [](https://github.com/roomi-fields/rtfm)
|
|
42
|
+
|
|
43
|
+
</div>
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
<!-- ─────────── TIER 1 — Pain & promise ─────────── -->
|
|
48
|
+
|
|
49
|
+
Your writing agent is drowning in tokens.
|
|
50
|
+
|
|
51
|
+
You ask Claude or Cursor to "Write the methodology section." To give it context, you feed it your 50-page manuscript, your related works, and your notes. The agent gets overwhelmed by the global narrative, loses track of the specific hyper-parameters you wanted to include, and writes a generic, repetitive summary that reads like a high-school essay.
|
|
52
|
+
|
|
53
|
+
The bottleneck isn't the model's writing ability — it's the **noise**.
|
|
54
|
+
|
|
55
|
+
**`writing-context-rtfm` fixes the noise.** It is a lightweight MCP extension built on top of `rtfm-ai`. Instead of letting the agent grep freely, it acts as a gatekeeper. It takes the agent's task, queries the underlying RTFM index, aggressively filters out background noise, and packs only the *essential* and *supporting* source chunks into a tight, highly-focused prompt.
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
python3 src/writing_context_rtfm/cli.py pack \
|
|
59
|
+
--task "Write the methodology section detailing dataset and quantization" \
|
|
60
|
+
--target section_approach
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
3 seconds later, the agent receives an 800-token context pack containing exactly the 3 paragraphs about the dataset, the 1 paragraph about quantization, and the stylistic constraints for the section. The agent writes perfectly.
|
|
64
|
+
|
|
65
|
+
> **Token budgets respected. Constraints enforced. Progressive disclosure over context dumps.**
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
## Installation & MCP Integration
|
|
70
|
+
|
|
71
|
+
`writing-context-rtfm` functions as an MCP (Model Context Protocol) server. You can run it dynamically using `uvx` (recommended) or install it globally on your system.
|
|
72
|
+
|
|
73
|
+
### Option A: Dynamic Run (Recommended)
|
|
74
|
+
You do not need to install the package manually. You can prefix commands with `uvx` (or `npx` equivalent) to run the server on demand.
|
|
75
|
+
|
|
76
|
+
### Option B: Global Installation
|
|
77
|
+
If you prefer a static global installation:
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
# Using uv
|
|
81
|
+
uv tool install writing-context-rtfm
|
|
82
|
+
|
|
83
|
+
# Using pipx
|
|
84
|
+
pipx install writing-context-rtfm
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Once installed, use `writing-context-rtfm serve` as the server command instead of `uvx writing-context-rtfm serve`.
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
### 1. Claude Desktop
|
|
92
|
+
Add this to your `claude_desktop_config.json` (on macOS: `~/Library/Application Support/Claude/claude_desktop_config.json`):
|
|
93
|
+
|
|
94
|
+
```json
|
|
95
|
+
{
|
|
96
|
+
"mcpServers": {
|
|
97
|
+
"writing-context-rtfm": {
|
|
98
|
+
"command": "uvx",
|
|
99
|
+
"args": [
|
|
100
|
+
"writing-context-rtfm",
|
|
101
|
+
"serve"
|
|
102
|
+
]
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### 2. Cursor IDE
|
|
109
|
+
1. Open Cursor Settings (`Cmd + ,`).
|
|
110
|
+
2. Navigate to **Features** > **MCP** and click **+ Add New MCP Server**.
|
|
111
|
+
3. **Name:** `writing-context-rtfm`
|
|
112
|
+
4. **Type:** `command`
|
|
113
|
+
5. **Command:** `uvx writing-context-rtfm serve`
|
|
114
|
+
|
|
115
|
+
### 3. VS Code Extensions (Cline, Roo Code)
|
|
116
|
+
Update your MCP settings file (e.g., `cline_mcp_settings.json`):
|
|
117
|
+
|
|
118
|
+
```json
|
|
119
|
+
{
|
|
120
|
+
"mcpServers": {
|
|
121
|
+
"writing-context-rtfm": {
|
|
122
|
+
"command": "uvx",
|
|
123
|
+
"args": [
|
|
124
|
+
"writing-context-rtfm",
|
|
125
|
+
"serve"
|
|
126
|
+
]
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### 4. Claude Code (Anthropic CLI Agent)
|
|
133
|
+
You can configure the server globally for Claude Code using:
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
claude mcp add --scope user --transport stdio writing-context-rtfm -- uvx writing-context-rtfm serve
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
Or for a specific project/repository:
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
claude mcp add --scope local --transport stdio writing-context-rtfm -- uvx writing-context-rtfm serve
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### 5. Codex (CLI & Desktop)
|
|
146
|
+
To add the server using the Codex CLI:
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
codex mcp add writing-context-rtfm -- uvx writing-context-rtfm serve
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
Alternatively, you can manually append it to your Codex configuration file (`~/.codex/config.toml`):
|
|
153
|
+
|
|
154
|
+
```toml
|
|
155
|
+
[mcp_servers.writing-context-rtfm]
|
|
156
|
+
command = "uvx"
|
|
157
|
+
args = ["writing-context-rtfm", "serve"]
|
|
158
|
+
enabled = true
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
*(If testing locally before publishing, you can use `uvx --from /absolute/path/to/writing-context-rtfm writing-context-rtfm serve` or `uv run python -m writing_context_rtfm.cli serve` instead).*
|
|
162
|
+
|
|
163
|
+
---
|
|
164
|
+
|
|
165
|
+
<!-- ─────────── TIER 2 — Positioning & buzz ─────────── -->
|
|
166
|
+
|
|
167
|
+
## The Core Philosophy: RTFM Retrieves, We Pack
|
|
168
|
+
|
|
169
|
+
| **Tool** | **Role** | **Action** | **Output** |
|
|
170
|
+
|----------|----------|------------|------------|
|
|
171
|
+
| `rtfm-ai` | The Retrieval Layer | Indexes everything, runs FTS/Semantic search, returns raw hits. | 25 raw chunks |
|
|
172
|
+
| `writing-context-rtfm` | The Curation Layer | Filters noise, applies constraints, ranks by structural priority. | 4 essential chunks |
|
|
173
|
+
|
|
174
|
+
We do **not** replace or fork RTFM. We wrap it. RTFM is built to fetch memory. `writing-context-rtfm` is built to decide *what is enough memory to write a specific section*.
|
|
175
|
+
|
|
176
|
+
---
|
|
177
|
+
|
|
178
|
+
## The Section Cards Pattern
|
|
179
|
+
Writing agents need rules. We enforce them using a `.writing-context/section_cards.yaml` file.
|
|
180
|
+
|
|
181
|
+
```yaml
|
|
182
|
+
version: 1
|
|
183
|
+
document:
|
|
184
|
+
title: "TinyML Fault Detection"
|
|
185
|
+
sections:
|
|
186
|
+
section_approach:
|
|
187
|
+
title: "Proposed approach"
|
|
188
|
+
path: "sections/03_approach.tex"
|
|
189
|
+
key_terms: ["CNN", "quantization"]
|
|
190
|
+
must_preserve:
|
|
191
|
+
- "The train-test split is fixed and reproducible."
|
|
192
|
+
avoid:
|
|
193
|
+
- "real-time deployment claims"
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
When the agent asks for context to write `section_approach`, we:
|
|
197
|
+
1. **Expand the query**: We don't just search the agent's prompt. We search the section title and key terms.
|
|
198
|
+
2. **Post-filter Avoids**: If an RTFM result matches an `avoid` term, it is instantly discarded.
|
|
199
|
+
3. **Inject Constraints**: The returned context pack explicitly feeds the `must_preserve` rules directly to the LLM.
|
|
200
|
+
|
|
201
|
+
> [!IMPORTANT]
|
|
202
|
+
> **Modular documents are required.** This extension's noise-reduction algorithms heavily rely on the `path` defined in your section cards to perform "Target Boosts" and semantic scoping. If your entire manuscript is just a single monolithic `main.tex` or `main.md` file, the packer won't be able to distinguish the target section from background noise. Keep your writing modular (e.g., `sections/01_intro.tex`, `sections/02_methodology.tex`) for optimal results.
|
|
203
|
+
|
|
204
|
+
---
|
|
205
|
+
|
|
206
|
+
## What we measured: A/B Testing
|
|
207
|
+
|
|
208
|
+
We tested a Gemini 2.5 agent trying to write a methodology section using two context strategies:
|
|
209
|
+
|
|
210
|
+
| Strategy | Context Size | Result Quality |
|
|
211
|
+
|----------|--------------|----------------|
|
|
212
|
+
| **Agent A (Full Repo Context)** | 3,000+ tokens | Wrote a generic paper summary. Hallucinated an introduction. Skipped hyperparameters entirely because it lost focus. |
|
|
213
|
+
| **Agent B (MCP Context Pack)** | **~600 tokens** | Jumped straight to the methodology. Correctly documented the CNN architecture, Adam optimizer, and learning rates. Followed all constraints. |
|
|
214
|
+
|
|
215
|
+
When you restrict an agent's vision to exactly what matters, its writing becomes sharper, more structured, and deeply accurate.
|
|
216
|
+
|
|
217
|
+
---
|
|
218
|
+
|
|
219
|
+
<!-- ─────────── TIER 3 — Technical depth ─────────── -->
|
|
220
|
+
|
|
221
|
+
### Intelligent Scoring & Priority
|
|
222
|
+
Raw search scores aren't enough for structural writing. We combine semantic relevance with manuscript structure:
|
|
223
|
+
- **RTFM Score**: Baseline semantic/FTS relevance.
|
|
224
|
+
- **Target Boost**: Chunks coming from the file the agent is supposed to be writing (`03_approach.tex`) get an automatic +0.8 boost.
|
|
225
|
+
- **Key-Term Scoping**: If a chunk matches a key term (e.g., "CNN") but comes from the *Conclusion* file, it receives a severe 75% score penalty to prevent background noise from polluting the context.
|
|
226
|
+
|
|
227
|
+
Chunks are finally classified as `[Priority: essential]`, `supporting`, or `background` so the LLM knows what to focus on.
|
|
228
|
+
|
|
229
|
+
### CLI Reference
|
|
230
|
+
```bash
|
|
231
|
+
# Initialize project config and SQLite cache
|
|
232
|
+
writing-context-rtfm init
|
|
233
|
+
writing-context-rtfm init-db
|
|
234
|
+
|
|
235
|
+
# Sync the underlying RTFM index
|
|
236
|
+
writing-context-rtfm sync --corpus manuscript
|
|
237
|
+
|
|
238
|
+
# Generate a context pack directly in the terminal
|
|
239
|
+
writing-context-rtfm pack \
|
|
240
|
+
--task "Update the introduction" \
|
|
241
|
+
--target section_intro \
|
|
242
|
+
--budget 4000
|
|
243
|
+
|
|
244
|
+
# Start MCP Server
|
|
245
|
+
writing-context-rtfm serve
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
---
|
|
249
|
+
|
|
250
|
+
## Where this fits
|
|
251
|
+
|
|
252
|
+
```
|
|
253
|
+
┌─────────────────────────────────┐
|
|
254
|
+
│ AI Agent / LLM Client │ ← Execution (Cursor, Claude)
|
|
255
|
+
├─────────────────────────────────┤
|
|
256
|
+
│ writing-context-rtfm │ ← Curation (Packs, Filters, Rules)
|
|
257
|
+
├─────────────────────────────────┤
|
|
258
|
+
│ rtfm-ai │ ← Retrieval (Index, FTS, Semantic)
|
|
259
|
+
└─────────────────────────────────┘
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
Without the context packer, your agent retrieves 50 documents and hopes for the best. With it, the agent receives a surgically precise, prioritized briefing.
|
|
263
|
+
|
|
264
|
+
## License
|
|
265
|
+
[MIT License](LICENSE) — use it, fork it, extend it.
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
<!-- mcp-name: writing-context-rtfm -->
|
|
2
|
+
<div align="center">
|
|
3
|
+
|
|
4
|
+
***Surgical Context for Writing Agents***
|
|
5
|
+
|
|
6
|
+
Stop giving your AI agent the entire manuscript to write one section. Give it the exact paragraphs, constraints, and dependencies it needs to succeed. No token bloat. No hallucinations.
|
|
7
|
+
|
|
8
|
+
**`Lightweight · Task-Focused · Extension · MIT`**
|
|
9
|
+
|
|
10
|
+
<br>
|
|
11
|
+
|
|
12
|
+
[](https://opensource.org/licenses/MIT) [](https://www.python.org/) [](https://modelcontextprotocol.io/) [](https://github.com/roomi-fields/rtfm)
|
|
13
|
+
|
|
14
|
+
</div>
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
<!-- ─────────── TIER 1 — Pain & promise ─────────── -->
|
|
19
|
+
|
|
20
|
+
Your writing agent is drowning in tokens.
|
|
21
|
+
|
|
22
|
+
You ask Claude or Cursor to "Write the methodology section." To give it context, you feed it your 50-page manuscript, your related works, and your notes. The agent gets overwhelmed by the global narrative, loses track of the specific hyper-parameters you wanted to include, and writes a generic, repetitive summary that reads like a high-school essay.
|
|
23
|
+
|
|
24
|
+
The bottleneck isn't the model's writing ability — it's the **noise**.
|
|
25
|
+
|
|
26
|
+
**`writing-context-rtfm` fixes the noise.** It is a lightweight MCP extension built on top of `rtfm-ai`. Instead of letting the agent grep freely, it acts as a gatekeeper. It takes the agent's task, queries the underlying RTFM index, aggressively filters out background noise, and packs only the *essential* and *supporting* source chunks into a tight, highly-focused prompt.
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
python3 src/writing_context_rtfm/cli.py pack \
|
|
30
|
+
--task "Write the methodology section detailing dataset and quantization" \
|
|
31
|
+
--target section_approach
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
3 seconds later, the agent receives an 800-token context pack containing exactly the 3 paragraphs about the dataset, the 1 paragraph about quantization, and the stylistic constraints for the section. The agent writes perfectly.
|
|
35
|
+
|
|
36
|
+
> **Token budgets respected. Constraints enforced. Progressive disclosure over context dumps.**
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## Installation & MCP Integration
|
|
41
|
+
|
|
42
|
+
`writing-context-rtfm` functions as an MCP (Model Context Protocol) server. You can run it dynamically using `uvx` (recommended) or install it globally on your system.
|
|
43
|
+
|
|
44
|
+
### Option A: Dynamic Run (Recommended)
|
|
45
|
+
You do not need to install the package manually. You can prefix commands with `uvx` (or `npx` equivalent) to run the server on demand.
|
|
46
|
+
|
|
47
|
+
### Option B: Global Installation
|
|
48
|
+
If you prefer a static global installation:
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
# Using uv
|
|
52
|
+
uv tool install writing-context-rtfm
|
|
53
|
+
|
|
54
|
+
# Using pipx
|
|
55
|
+
pipx install writing-context-rtfm
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Once installed, use `writing-context-rtfm serve` as the server command instead of `uvx writing-context-rtfm serve`.
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
### 1. Claude Desktop
|
|
63
|
+
Add this to your `claude_desktop_config.json` (on macOS: `~/Library/Application Support/Claude/claude_desktop_config.json`):
|
|
64
|
+
|
|
65
|
+
```json
|
|
66
|
+
{
|
|
67
|
+
"mcpServers": {
|
|
68
|
+
"writing-context-rtfm": {
|
|
69
|
+
"command": "uvx",
|
|
70
|
+
"args": [
|
|
71
|
+
"writing-context-rtfm",
|
|
72
|
+
"serve"
|
|
73
|
+
]
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### 2. Cursor IDE
|
|
80
|
+
1. Open Cursor Settings (`Cmd + ,`).
|
|
81
|
+
2. Navigate to **Features** > **MCP** and click **+ Add New MCP Server**.
|
|
82
|
+
3. **Name:** `writing-context-rtfm`
|
|
83
|
+
4. **Type:** `command`
|
|
84
|
+
5. **Command:** `uvx writing-context-rtfm serve`
|
|
85
|
+
|
|
86
|
+
### 3. VS Code Extensions (Cline, Roo Code)
|
|
87
|
+
Update your MCP settings file (e.g., `cline_mcp_settings.json`):
|
|
88
|
+
|
|
89
|
+
```json
|
|
90
|
+
{
|
|
91
|
+
"mcpServers": {
|
|
92
|
+
"writing-context-rtfm": {
|
|
93
|
+
"command": "uvx",
|
|
94
|
+
"args": [
|
|
95
|
+
"writing-context-rtfm",
|
|
96
|
+
"serve"
|
|
97
|
+
]
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### 4. Claude Code (Anthropic CLI Agent)
|
|
104
|
+
You can configure the server globally for Claude Code using:
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
claude mcp add --scope user --transport stdio writing-context-rtfm -- uvx writing-context-rtfm serve
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Or for a specific project/repository:
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
claude mcp add --scope local --transport stdio writing-context-rtfm -- uvx writing-context-rtfm serve
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### 5. Codex (CLI & Desktop)
|
|
117
|
+
To add the server using the Codex CLI:
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
codex mcp add writing-context-rtfm -- uvx writing-context-rtfm serve
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
Alternatively, you can manually append it to your Codex configuration file (`~/.codex/config.toml`):
|
|
124
|
+
|
|
125
|
+
```toml
|
|
126
|
+
[mcp_servers.writing-context-rtfm]
|
|
127
|
+
command = "uvx"
|
|
128
|
+
args = ["writing-context-rtfm", "serve"]
|
|
129
|
+
enabled = true
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
*(If testing locally before publishing, you can use `uvx --from /absolute/path/to/writing-context-rtfm writing-context-rtfm serve` or `uv run python -m writing_context_rtfm.cli serve` instead).*
|
|
133
|
+
|
|
134
|
+
---
|
|
135
|
+
|
|
136
|
+
<!-- ─────────── TIER 2 — Positioning & buzz ─────────── -->
|
|
137
|
+
|
|
138
|
+
## The Core Philosophy: RTFM Retrieves, We Pack
|
|
139
|
+
|
|
140
|
+
| **Tool** | **Role** | **Action** | **Output** |
|
|
141
|
+
|----------|----------|------------|------------|
|
|
142
|
+
| `rtfm-ai` | The Retrieval Layer | Indexes everything, runs FTS/Semantic search, returns raw hits. | 25 raw chunks |
|
|
143
|
+
| `writing-context-rtfm` | The Curation Layer | Filters noise, applies constraints, ranks by structural priority. | 4 essential chunks |
|
|
144
|
+
|
|
145
|
+
We do **not** replace or fork RTFM. We wrap it. RTFM is built to fetch memory. `writing-context-rtfm` is built to decide *what is enough memory to write a specific section*.
|
|
146
|
+
|
|
147
|
+
---
|
|
148
|
+
|
|
149
|
+
## The Section Cards Pattern
|
|
150
|
+
Writing agents need rules. We enforce them using a `.writing-context/section_cards.yaml` file.
|
|
151
|
+
|
|
152
|
+
```yaml
|
|
153
|
+
version: 1
|
|
154
|
+
document:
|
|
155
|
+
title: "TinyML Fault Detection"
|
|
156
|
+
sections:
|
|
157
|
+
section_approach:
|
|
158
|
+
title: "Proposed approach"
|
|
159
|
+
path: "sections/03_approach.tex"
|
|
160
|
+
key_terms: ["CNN", "quantization"]
|
|
161
|
+
must_preserve:
|
|
162
|
+
- "The train-test split is fixed and reproducible."
|
|
163
|
+
avoid:
|
|
164
|
+
- "real-time deployment claims"
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
When the agent asks for context to write `section_approach`, we:
|
|
168
|
+
1. **Expand the query**: We don't just search the agent's prompt. We search the section title and key terms.
|
|
169
|
+
2. **Post-filter Avoids**: If an RTFM result matches an `avoid` term, it is instantly discarded.
|
|
170
|
+
3. **Inject Constraints**: The returned context pack explicitly feeds the `must_preserve` rules directly to the LLM.
|
|
171
|
+
|
|
172
|
+
> [!IMPORTANT]
|
|
173
|
+
> **Modular documents are required.** This extension's noise-reduction algorithms heavily rely on the `path` defined in your section cards to perform "Target Boosts" and semantic scoping. If your entire manuscript is just a single monolithic `main.tex` or `main.md` file, the packer won't be able to distinguish the target section from background noise. Keep your writing modular (e.g., `sections/01_intro.tex`, `sections/02_methodology.tex`) for optimal results.
|
|
174
|
+
|
|
175
|
+
---
|
|
176
|
+
|
|
177
|
+
## What we measured: A/B Testing
|
|
178
|
+
|
|
179
|
+
We tested a Gemini 2.5 agent trying to write a methodology section using two context strategies:
|
|
180
|
+
|
|
181
|
+
| Strategy | Context Size | Result Quality |
|
|
182
|
+
|----------|--------------|----------------|
|
|
183
|
+
| **Agent A (Full Repo Context)** | 3,000+ tokens | Wrote a generic paper summary. Hallucinated an introduction. Skipped hyperparameters entirely because it lost focus. |
|
|
184
|
+
| **Agent B (MCP Context Pack)** | **~600 tokens** | Jumped straight to the methodology. Correctly documented the CNN architecture, Adam optimizer, and learning rates. Followed all constraints. |
|
|
185
|
+
|
|
186
|
+
When you restrict an agent's vision to exactly what matters, its writing becomes sharper, more structured, and deeply accurate.
|
|
187
|
+
|
|
188
|
+
---
|
|
189
|
+
|
|
190
|
+
<!-- ─────────── TIER 3 — Technical depth ─────────── -->
|
|
191
|
+
|
|
192
|
+
### Intelligent Scoring & Priority
|
|
193
|
+
Raw search scores aren't enough for structural writing. We combine semantic relevance with manuscript structure:
|
|
194
|
+
- **RTFM Score**: Baseline semantic/FTS relevance.
|
|
195
|
+
- **Target Boost**: Chunks coming from the file the agent is supposed to be writing (`03_approach.tex`) get an automatic +0.8 boost.
|
|
196
|
+
- **Key-Term Scoping**: If a chunk matches a key term (e.g., "CNN") but comes from the *Conclusion* file, it receives a severe 75% score penalty to prevent background noise from polluting the context.
|
|
197
|
+
|
|
198
|
+
Chunks are finally classified as `[Priority: essential]`, `supporting`, or `background` so the LLM knows what to focus on.
|
|
199
|
+
|
|
200
|
+
### CLI Reference
|
|
201
|
+
```bash
|
|
202
|
+
# Initialize project config and SQLite cache
|
|
203
|
+
writing-context-rtfm init
|
|
204
|
+
writing-context-rtfm init-db
|
|
205
|
+
|
|
206
|
+
# Sync the underlying RTFM index
|
|
207
|
+
writing-context-rtfm sync --corpus manuscript
|
|
208
|
+
|
|
209
|
+
# Generate a context pack directly in the terminal
|
|
210
|
+
writing-context-rtfm pack \
|
|
211
|
+
--task "Update the introduction" \
|
|
212
|
+
--target section_intro \
|
|
213
|
+
--budget 4000
|
|
214
|
+
|
|
215
|
+
# Start MCP Server
|
|
216
|
+
writing-context-rtfm serve
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
---
|
|
220
|
+
|
|
221
|
+
## Where this fits
|
|
222
|
+
|
|
223
|
+
```
|
|
224
|
+
┌─────────────────────────────────┐
|
|
225
|
+
│ AI Agent / LLM Client │ ← Execution (Cursor, Claude)
|
|
226
|
+
├─────────────────────────────────┤
|
|
227
|
+
│ writing-context-rtfm │ ← Curation (Packs, Filters, Rules)
|
|
228
|
+
├─────────────────────────────────┤
|
|
229
|
+
│ rtfm-ai │ ← Retrieval (Index, FTS, Semantic)
|
|
230
|
+
└─────────────────────────────────┘
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
Without the context packer, your agent retrieves 50 documents and hopes for the best. With it, the agent receives a surgically precise, prioritized briefing.
|
|
234
|
+
|
|
235
|
+
## License
|
|
236
|
+
[MIT License](LICENSE) — use it, fork it, extend it.
|