ccw-mcp 0.1.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.
Files changed (44) hide show
  1. ccw_mcp-0.1.0/LICENSE +21 -0
  2. ccw_mcp-0.1.0/PKG-INFO +393 -0
  3. ccw_mcp-0.1.0/README.md +369 -0
  4. ccw_mcp-0.1.0/pyproject.toml +49 -0
  5. ccw_mcp-0.1.0/setup.cfg +4 -0
  6. ccw_mcp-0.1.0/src/ccw/__init__.py +3 -0
  7. ccw_mcp-0.1.0/src/ccw/__main__.py +5 -0
  8. ccw_mcp-0.1.0/src/ccw/classify.py +65 -0
  9. ccw_mcp-0.1.0/src/ccw/cli.py +185 -0
  10. ccw_mcp-0.1.0/src/ccw/compile.py +406 -0
  11. ccw_mcp-0.1.0/src/ccw/conductor.py +120 -0
  12. ccw_mcp-0.1.0/src/ccw/config.py +35 -0
  13. ccw_mcp-0.1.0/src/ccw/episodes.py +57 -0
  14. ccw_mcp-0.1.0/src/ccw/facts.py +39 -0
  15. ccw_mcp-0.1.0/src/ccw/index.py +878 -0
  16. ccw_mcp-0.1.0/src/ccw/init.py +90 -0
  17. ccw_mcp-0.1.0/src/ccw/mcp_server.py +546 -0
  18. ccw_mcp-0.1.0/src/ccw/pipeline.py +196 -0
  19. ccw_mcp-0.1.0/src/ccw/recipe.py +114 -0
  20. ccw_mcp-0.1.0/src/ccw/schema.py +245 -0
  21. ccw_mcp-0.1.0/src/ccw/session.py +160 -0
  22. ccw_mcp-0.1.0/src/ccw/update.py +29 -0
  23. ccw_mcp-0.1.0/src/ccw/validate.py +81 -0
  24. ccw_mcp-0.1.0/src/ccw_mcp.egg-info/PKG-INFO +393 -0
  25. ccw_mcp-0.1.0/src/ccw_mcp.egg-info/SOURCES.txt +42 -0
  26. ccw_mcp-0.1.0/src/ccw_mcp.egg-info/dependency_links.txt +1 -0
  27. ccw_mcp-0.1.0/src/ccw_mcp.egg-info/entry_points.txt +3 -0
  28. ccw_mcp-0.1.0/src/ccw_mcp.egg-info/requires.txt +1 -0
  29. ccw_mcp-0.1.0/src/ccw_mcp.egg-info/top_level.txt +1 -0
  30. ccw_mcp-0.1.0/tests/test_cli_classify.py +234 -0
  31. ccw_mcp-0.1.0/tests/test_cli_compile.py +259 -0
  32. ccw_mcp-0.1.0/tests/test_cli_conductor.py +88 -0
  33. ccw_mcp-0.1.0/tests/test_cli_episodes.py +199 -0
  34. ccw_mcp-0.1.0/tests/test_cli_facts.py +187 -0
  35. ccw_mcp-0.1.0/tests/test_cli_index.py +943 -0
  36. ccw_mcp-0.1.0/tests/test_cli_init.py +436 -0
  37. ccw_mcp-0.1.0/tests/test_cli_session.py +219 -0
  38. ccw_mcp-0.1.0/tests/test_cli_update.py +245 -0
  39. ccw_mcp-0.1.0/tests/test_compile.py +767 -0
  40. ccw_mcp-0.1.0/tests/test_integration_mcp_value.py +197 -0
  41. ccw_mcp-0.1.0/tests/test_mcp_server.py +102 -0
  42. ccw_mcp-0.1.0/tests/test_pipeline.py +319 -0
  43. ccw_mcp-0.1.0/tests/test_recipes.py +193 -0
  44. ccw_mcp-0.1.0/tests/test_session.py +175 -0
ccw_mcp-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 CCW contributors
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.
ccw_mcp-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,393 @@
1
+ Metadata-Version: 2.4
2
+ Name: ccw-mcp
3
+ Version: 0.1.0
4
+ Summary: Deterministic context compiler for small-window coding models
5
+ Author-email: Felipe Ferrari <fmferrari@github.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/fmferrari/ccw
8
+ Project-URL: Repository, https://github.com/fmferrari/ccw
9
+ Project-URL: Issues, https://github.com/fmferrari/ccw/issues
10
+ Project-URL: Documentation, https://github.com/fmferrari/ccw#readme
11
+ Keywords: context compiler,developer tools,mcp,repository indexing,small-window models
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Topic :: Software Development :: Libraries
19
+ Requires-Python: >=3.11
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Requires-Dist: mcp>=1.0
23
+ Dynamic: license-file
24
+
25
+ # ccw
26
+
27
+ **CCW is a deterministic context compiler for small-window coding models.**
28
+
29
+ Most context pipelines give a model either everything (too noisy) or
30
+ an embedding-retrieved guess (unverifiable). CCW does neither. It walks the
31
+ repo, records explicit facts and run history, and assembles a bounded,
32
+ grounded markdown artifact whose every file path, symbol, and constraint traces
33
+ back to the real index. No vector store. No LLM in the critical path. Receipts
34
+ included.
35
+
36
+ The compiled artifact and a portable session bundle are the primary surfaces.
37
+ An MCP server exposes the same pipeline as callable tools so an agent framework
38
+ can drive the full loop without shelling out.
39
+
40
+ CCW intentionally keeps workflow packaging, harness adapters, and
41
+ orchestrator-specific definitions in a separate companion repo (`ccw-stack`)
42
+ so this core stays deterministic and inspectable.
43
+
44
+ ## Why deterministic compilation matters
45
+
46
+ A small-window model working on a real codebase needs:
47
+
48
+ - **Relevance** — only files and symbols related to the task
49
+ - **Boundedness** — a hard token budget it cannot overflow
50
+ - **Grounding** — every cited path must exist in the index; invented paths fail validation
51
+ - **Memory** — project constraints and past decisions the raw code does not contain
52
+ - **Freshness** — the model should never silently trust a stale artifact
53
+
54
+ CCW enforces all five. The integration test (`tests/test_integration_mcp_value.py`)
55
+ asserts each claim deterministically without an LLM.
56
+
57
+ ## Install
58
+
59
+ Requires Python 3.11 or newer.
60
+
61
+ **Stable install from PyPI:**
62
+
63
+ ```bash
64
+ pip install ccw-mcp
65
+ ```
66
+
67
+ **Isolated CLI install (recommended — keeps ccw out of your project's environment):**
68
+
69
+ ```bash
70
+ pipx install ccw-mcp
71
+ ```
72
+
73
+ **Zero-install MCP server launch via [uv](https://github.com/astral-sh/uv):**
74
+
75
+ ```bash
76
+ uvx ccw-mcp
77
+ ```
78
+
79
+ **Install through Microsoft APM:**
80
+
81
+ ```bash
82
+ apm install fmferrari/ccw --target copilot
83
+ ```
84
+
85
+ This package publishes CCW as an APM package that installs the MCP server
86
+ declaration into supported harnesses. The server itself is launched with
87
+ `uvx ccw-mcp`, so consumers need both `apm` and `uv` available on `PATH`.
88
+
89
+ For maintainers: this public repo can mount a private wiki clone locally via
90
+ `scripts/link-private-wiki.sh`.
91
+
92
+ **Development install from source:**
93
+
94
+ ```bash
95
+ git clone https://github.com/fmferrari/ccw
96
+ cd ccw
97
+ python -m venv .venv && source .venv/bin/activate
98
+ pip install -e .
99
+ ```
100
+
101
+ The `mcp` dependency installs automatically. Verify:
102
+
103
+ ```bash
104
+ ccw --help
105
+ python -c "import ccw; print(ccw.__version__)"
106
+ ```
107
+
108
+ ## End-to-end demo
109
+
110
+ The full value loop in five CLI steps:
111
+
112
+ ```bash
113
+ # 1. Bootstrap local state for this repo
114
+ ccw init
115
+
116
+ # 2. Index the repo: files, symbols, imports, edges, git signals
117
+ ccw index .
118
+
119
+ # 3. Record an explicit constraint that the raw code does not contain
120
+ ccw facts add constraint "Never log plaintext passwords"
121
+
122
+ # 4. Compile a task-scoped context artifact (auto-classifies mode and budget)
123
+ ccw compile --task "Fix the login bug that rejects valid credentials"
124
+
125
+ # 5. Validate: only real paths, required sections present, no invented symbols
126
+ ccw validate .ccw/compiled/latest.md
127
+ ```
128
+
129
+ The compiled artifact is `.ccw/compiled/latest.md` by default, a markdown file
130
+ with YAML frontmatter carrying the task, mode, token budget, and an
131
+ `index_hash` that pins the artifact to the exact repo state it was built from.
132
+ Pass `--out <path>` to write somewhere else.
133
+
134
+ After a run completes:
135
+
136
+ ```bash
137
+ ccw update --run "Fixed the login bug" --touched-files "login.py" \
138
+ --decision "Treat empty credentials as invalid"
139
+ ```
140
+
141
+ This re-indexes the repo and appends an episode and optional decision fact so
142
+ future compilations include the run outcome.
143
+
144
+ ## How compilation works
145
+
146
+ `ccw compile` runs a named pass pipeline:
147
+
148
+ 1. **ResolveTask** — classifies the task (`bugfix`, `implementation`, `review`, `refactor`) and selects the matching recipe with per-section budgets
149
+ 2. **RankFiles** — scores indexed files by keyword overlap, fuzzy prefix match, symbol-name match, and git freshness; caps at the recipe file limit
150
+ 3. **ExtractSnippets** — pulls line-anchored code snippets up to each section's token allocation
151
+ 4. **LoadMemory** — loads explicit facts, episodes, and constraints from the append-only store
152
+ 5. **Assemble** — composes ranked files, snippets, memory, and constraints into a `CompiledContext`, then renders to bounded markdown
153
+
154
+ Token budgets per mode:
155
+
156
+ | Mode | Default budget |
157
+ |------|---------------|
158
+ | `bugfix` | 6 000 tokens |
159
+ | `implementation` | 8 000 tokens |
160
+ | `review` | 8 000 tokens |
161
+ | `refactor` | 10 000 tokens |
162
+
163
+ ## MCP server
164
+
165
+ `ccw-mcp` exposes the full pipeline as MCP tools so an agent framework can
166
+ drive the entire loop without shelling out. The target repo is set via the
167
+ `CCW_TARGET_ROOT` environment variable or the `target_path` parameter on each
168
+ tool call.
169
+
170
+ ```bash
171
+ # Manual launch (for testing)
172
+ CCW_TARGET_ROOT=/path/to/project ccw-mcp
173
+ ```
174
+
175
+ Available tools:
176
+
177
+ | Tool | What it does |
178
+ |------|-------------|
179
+ | `init_repo` | Bootstrap `.ccw/` local state |
180
+ | `index_repo` | Walk and index the repo into SQLite |
181
+ | `record_fact` | Append an explicit fact (constraint, decision, preference) |
182
+ | `record_episode` | Append a completed-run episode with touched files |
183
+ | `classify_task` | Deterministically classify task text into a compile mode |
184
+ | `compile_task_context` | Compile a bounded, grounded context artifact |
185
+ | `prepare_session` | Compile and package a portable session bundle |
186
+ | `validate_session` | Check bundle freshness against the current index hash |
187
+ | `update_memory` | Re-index and record a post-run episode and optional decision |
188
+ | `validate_compiled_artifact` | Validate frontmatter, sections, and file paths |
189
+
190
+ Every tool accepts an explicit `target_path`. If omitted, CCW reads
191
+ `CCW_TARGET_ROOT` from the environment.
192
+
193
+ ## APM distribution
194
+
195
+ CCW can also be consumed as a Microsoft APM package. In APM terms, this repo is
196
+ primarily an MCP primitive package: when a consumer runs `apm install`, APM
197
+ writes the `ccw` MCP server entry into each detected harness config.
198
+
199
+ Consumer install:
200
+
201
+ ```bash
202
+ apm install fmferrari/ccw --target copilot
203
+ ```
204
+
205
+ What APM installs for the consumer is equivalent to this self-defined MCP
206
+ server declaration:
207
+
208
+ ```yaml
209
+ dependencies:
210
+ mcp:
211
+ - name: ccw
212
+ registry: false
213
+ transport: stdio
214
+ command: uvx
215
+ args: ["ccw-mcp"]
216
+ ```
217
+
218
+ Important constraints:
219
+
220
+ - APM distributes the harness configuration, not the Python wheel.
221
+ - `uvx ccw-mcp` is what makes the server portable here: `uvx` resolves and runs
222
+ the PyPI package on demand.
223
+ - If the harness does not launch the MCP server from the repo root, pass
224
+ `target_path` explicitly on tool calls or set `CCW_TARGET_ROOT` in the
225
+ generated config.
226
+ - Because this is a self-defined MCP server (`registry: false`), consumers
227
+ should install it as a direct dependency, not rely on it flowing transitively.
228
+
229
+ ### Connecting CCW to your project
230
+
231
+ Add this to your project's `.mcp.json` (or equivalent harness config).
232
+
233
+ **Option A — zero-install via `uvx` (recommended if you have [uv](https://github.com/astral-sh/uv)):**
234
+
235
+ ```json
236
+ {
237
+ "mcpServers": {
238
+ "ccw": {
239
+ "command": "uvx",
240
+ "args": ["ccw-mcp"],
241
+ "env": {
242
+ "CCW_TARGET_ROOT": "/absolute/path/to/your/project"
243
+ }
244
+ }
245
+ }
246
+ }
247
+ ```
248
+
249
+ **Option B — after `pip install ccw-mcp` or `pipx install ccw-mcp`:**
250
+
251
+ ```json
252
+ {
253
+ "mcpServers": {
254
+ "ccw": {
255
+ "command": "ccw-mcp",
256
+ "env": {
257
+ "CCW_TARGET_ROOT": "/absolute/path/to/your/project"
258
+ }
259
+ }
260
+ }
261
+ }
262
+ ```
263
+
264
+ **Option C — development checkout:**
265
+
266
+ ```json
267
+ {
268
+ "mcpServers": {
269
+ "ccw": {
270
+ "command": "/path/to/ccw/.venv/bin/python",
271
+ "args": ["-m", "ccw.mcp_server"],
272
+ "env": {
273
+ "CCW_TARGET_ROOT": "/absolute/path/to/your/project"
274
+ }
275
+ }
276
+ }
277
+ }
278
+ ```
279
+
280
+ ### `.ccw/` in your target repo
281
+
282
+ CCW creates a `.ccw/` directory at your project root. The SQLite database
283
+ (`.ccw/index.sqlite`) stores both the regenerable file index and your durable
284
+ project memory (facts and episodes).
285
+
286
+ **Recommended `.gitignore` additions for your project:**
287
+
288
+ ```gitignore
289
+ # CCW ephemeral artifacts — regenerated on demand
290
+ .ccw/compiled/
291
+ .ccw/session/
292
+ .ccw/snapshots/
293
+ ```
294
+
295
+ Leave `.ccw/index.sqlite` and `.ccw/config.yaml` **uncommitted** if CCW is
296
+ personal tooling, or **commit them** if you want the team to share facts and
297
+ episodes across clones. Either works; the index portion regenerates in seconds
298
+ with `ccw index`.
299
+
300
+ ## Session bundle
301
+
302
+ A session bundle is a portable, file-only handoff that any agent, script, or
303
+ CI step can consume without MCP, provider APIs, or workflow orchestration.
304
+
305
+ ```bash
306
+ ccw session prepare --task "Fix the login bug" --mode implementation
307
+ ```
308
+
309
+ The bundle lives at `.ccw/session/latest/` by default:
310
+
311
+ | File | Role |
312
+ |------|------|
313
+ | `SESSION.md` | Model-facing entry file — instructs the model to use the compiled context before re-gathering repo context and to request a refresh on mismatch |
314
+ | `compiled-context.md` | The grounded, budgeted context artifact |
315
+ | `session.json` | Machine-readable metadata: task, mode, budget, `index_hash`, and timestamps |
316
+
317
+ ### File-only consumption
318
+
319
+ ```python
320
+ import json
321
+ from pathlib import Path
322
+
323
+ bundle = Path(".ccw/session/latest/")
324
+
325
+ session_md = (bundle / "SESSION.md").read_text()
326
+ compiled_context = (bundle / "compiled-context.md").read_text()
327
+ metadata = json.loads((bundle / "session.json").read_text())
328
+ ```
329
+
330
+ Validate that the bundle is internally consistent and the `index_hash` still
331
+ matches the current repo state:
332
+
333
+ ```bash
334
+ ccw session validate .ccw/session/latest/
335
+ ```
336
+
337
+ For multi-repo or harness-managed workflows:
338
+
339
+ ```bash
340
+ ccw session prepare \
341
+ --task "Refactor auth module" \
342
+ --mode refactor \
343
+ --out-dir /shared/sessions/auth-refactor \
344
+ /path/to/repo
345
+ ```
346
+
347
+ ### Consumption contract
348
+
349
+ 1. Read `SESSION.md` first — it explains the grounded task context.
350
+ 2. Use `compiled-context.md` as the authoritative task-scoped repo state. Do not re-gather repo context unless the bundle is stale.
351
+ 3. Check `session.json` — if the `index_hash`, task, or mode no longer match, request a refreshed bundle rather than silently trusting stale context.
352
+
353
+ ## Conductor workflow scaffold
354
+
355
+ ```bash
356
+ ccw conductor init
357
+ ```
358
+
359
+ Generates a `ccw-code-task/` directory with a shell script showing the full
360
+ pipeline as script steps (init → index → classify → compile → session prepare →
361
+ validate) and a README explaining the consumption contract.
362
+
363
+ Full Conductor workflow packaging and harness adapters belong in the companion
364
+ `ccw-stack` repo.
365
+
366
+ ## Architecture boundary
367
+
368
+ - **CCW** — deterministic context compiler and post-run update engine (this repo)
369
+ - **CCW Stack** — companion repo for Conductor workflow packaging, harness adapters, and optional portable brain behavior
370
+ - **Conductor** — the external workflow orchestrator that calls CCW as a script or tool step
371
+ - **Model provider** — the inference backend that consumes CCW artifacts (OpenAI, Anthropic, GitHub Models, etc.)
372
+
373
+ ## Development
374
+
375
+ ```bash
376
+ python -m unittest
377
+ ```
378
+
379
+ 146 tests covering CLI surfaces, compiler passes, pipeline composition, MCP
380
+ tools, session bundle, Conductor scaffold, and the end-to-end value integration.
381
+
382
+ See `CONTRIBUTING.md` for contribution flow and documentation expectations.
383
+
384
+ ## Community
385
+
386
+ - Contribution guide: `CONTRIBUTING.md`
387
+ - Code of conduct: `CODE_OF_CONDUCT.md`
388
+ - Security reporting: `SECURITY.md`
389
+ - Bug reports and feature requests: GitHub Issues
390
+
391
+ ## License
392
+
393
+ CCW is licensed under the MIT License. See `LICENSE`.