cap-cli 1.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.
- cap_cli-1.0.1/PKG-INFO +364 -0
- cap_cli-1.0.1/README.md +336 -0
- cap_cli-1.0.1/cap_cli/__init__.py +5 -0
- cap_cli-1.0.1/cap_cli/commands/__init__.py +5 -0
- cap_cli-1.0.1/cap_cli/commands/init.py +94 -0
- cap_cli-1.0.1/cap_cli/commands/serve.py +52 -0
- cap_cli-1.0.1/cap_cli/commands/validate.py +103 -0
- cap_cli-1.0.1/cap_cli/main.py +34 -0
- cap_cli-1.0.1/cap_cli/meta.py +3 -0
- cap_cli-1.0.1/cap_cli/utils/__init__.py +14 -0
- cap_cli-1.0.1/cap_cli/utils/output.py +27 -0
- cap_cli-1.0.1/cap_cli/utils/workspace.py +45 -0
- cap_cli-1.0.1/cap_cli.egg-info/PKG-INFO +364 -0
- cap_cli-1.0.1/cap_cli.egg-info/SOURCES.txt +18 -0
- cap_cli-1.0.1/cap_cli.egg-info/dependency_links.txt +1 -0
- cap_cli-1.0.1/cap_cli.egg-info/entry_points.txt +2 -0
- cap_cli-1.0.1/cap_cli.egg-info/requires.txt +3 -0
- cap_cli-1.0.1/cap_cli.egg-info/top_level.txt +1 -0
- cap_cli-1.0.1/pyproject.toml +55 -0
- cap_cli-1.0.1/setup.cfg +4 -0
cap_cli-1.0.1/PKG-INFO
ADDED
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: cap-cli
|
|
3
|
+
Version: 1.0.1
|
|
4
|
+
Summary: CAP CLI: Command-line interface for Codebase Awareness Protocol
|
|
5
|
+
Author-email: Domas Leščinskas <domas.lescinskas@gmail.com>
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/domasles/cap
|
|
8
|
+
Project-URL: Bug Reports, https://github.com/domasles/cap/issues
|
|
9
|
+
Project-URL: Source, https://github.com/domasles/cap
|
|
10
|
+
Project-URL: Documentation, https://github.com/domasles/cap#readme
|
|
11
|
+
Keywords: ai,mcp,cli,codebase,developer-tools
|
|
12
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
15
|
+
Classifier: Topic :: Software Development :: Documentation
|
|
16
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
21
|
+
Classifier: Operating System :: OS Independent
|
|
22
|
+
Classifier: Environment :: Console
|
|
23
|
+
Requires-Python: >=3.11
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
Requires-Dist: click>=8.3.1
|
|
26
|
+
Requires-Dist: rich>=13.3.2
|
|
27
|
+
Requires-Dist: cap-mcp==1.0.1
|
|
28
|
+
|
|
29
|
+
# CAP
|
|
30
|
+
|
|
31
|
+
**Codebase Awareness Protocol**
|
|
32
|
+
|
|
33
|
+
[](https://github.com/psf/black)
|
|
34
|
+
[](LICENSE)
|
|
35
|
+
[](https://python.org)
|
|
36
|
+
[](https://nodejs.org)
|
|
37
|
+
[](https://code.visualstudio.com/)
|
|
38
|
+
|
|
39
|
+
> Give AI coding agents the context they need - architecture, dependencies, and API - so they stop guessing and start respecting your codebase.
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
## Philosophy
|
|
44
|
+
|
|
45
|
+
AI coding agents are powerful, but they are blind. They see files, not architecture. They read imports, not intent. Without explicit context, they silently violate boundaries, import forbidden packages, and ignore the structure you spent months building.
|
|
46
|
+
|
|
47
|
+
**CAP fixes this.** You describe your codebase once in three small YAML files. CAP serves that knowledge to any AI agent through the [Model Context Protocol (MCP)](https://modelcontextprotocol.io/), the open standard for connecting AI to tools.
|
|
48
|
+
|
|
49
|
+
The result: agents that understand your layers, respect your dependency rules, and use your public API - without you repeating yourself in every prompt.
|
|
50
|
+
|
|
51
|
+
### Three principles
|
|
52
|
+
|
|
53
|
+
1. **Declarative over discovery** - You know your codebase better than static analysis. Write it down once, in plain YAML.
|
|
54
|
+
2. **Protocol over prompts** - Structured MCP tool responses beat pasted context every time.
|
|
55
|
+
3. **Zero lock-in** - YAML files live in your repo. No SaaS, no accounts, no telemetry.
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
## Getting Started
|
|
60
|
+
|
|
61
|
+
### VS Code Extension (recommended)
|
|
62
|
+
|
|
63
|
+
The fastest path. The extension handles Python, installs CAP, runs the MCP server, and connects it to your AI agent - all automatically.
|
|
64
|
+
|
|
65
|
+
**1. Install the extension**
|
|
66
|
+
|
|
67
|
+
Search for **"CAP - Codebase Awareness Protocol"** in the VS Code Extensions Marketplace, or install from the command line:
|
|
68
|
+
|
|
69
|
+
```
|
|
70
|
+
code --install-extension domasles.cap-vscode
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
**2. Initialize your workspace**
|
|
74
|
+
|
|
75
|
+
Open the Command Palette (`Ctrl+Shift+P`) and run:
|
|
76
|
+
|
|
77
|
+
```
|
|
78
|
+
CAP: Initialize Configuration
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
This creates a `.cap/` directory with three template files:
|
|
82
|
+
|
|
83
|
+
```
|
|
84
|
+
.cap/
|
|
85
|
+
├── api.yaml # What your code exports
|
|
86
|
+
├── architecture.yaml # How your code is organized
|
|
87
|
+
└── dependencies.yaml # What your code depends on
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Edit them to match your project. That's all the setup you need.
|
|
91
|
+
|
|
92
|
+
**3. Enable the MCP server**
|
|
93
|
+
|
|
94
|
+
When `.cap/` is created, the extension shows a notification prompting you to enable the MCP server. Click **Open Chat** to go to the Copilot panel, then enable the **CAP** server in the MCP tools list.
|
|
95
|
+
|
|
96
|
+
Once enabled, every AI agent conversation has access to three tools:
|
|
97
|
+
|
|
98
|
+
| Tool | What the agent gets |
|
|
99
|
+
|---|---|
|
|
100
|
+
| `get_architecture` | Layers, modules, ownership, architectural rules |
|
|
101
|
+
| `get_dependencies` | Runtime/dev packages, versions, forbidden patterns |
|
|
102
|
+
| `get_api` | Public/internal exports, stability, access rules |
|
|
103
|
+
|
|
104
|
+
The agent calls these tools when it needs context. You don't need to prompt for it.
|
|
105
|
+
|
|
106
|
+
### CLI
|
|
107
|
+
|
|
108
|
+
If you prefer working from the terminal or want CAP without VS Code:
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
pip install cap-cli
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
**Initialize:**
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
cap init # Create .cap/ with templates
|
|
118
|
+
cap init --minimal # Bare minimum scaffolding
|
|
119
|
+
cap init --force # Overwrite existing files
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
**Validate your configuration:**
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
cap validate # Pretty terminal output
|
|
126
|
+
cap validate --json # Machine-readable for CI
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
**Start the MCP server:**
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
cap serve
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
This runs a [stdio MCP server](https://modelcontextprotocol.io/docs/concepts/transports#standard-io-stdio) that any MCP-compatible client can connect to. Point your AI tool at the `cap serve` command and it will discover the three tools automatically.
|
|
136
|
+
|
|
137
|
+
---
|
|
138
|
+
|
|
139
|
+
## The `.cap/` Files
|
|
140
|
+
|
|
141
|
+
### `architecture.yaml`
|
|
142
|
+
|
|
143
|
+
Defines the structural skeleton of your codebase.
|
|
144
|
+
|
|
145
|
+
```yaml
|
|
146
|
+
architecture:
|
|
147
|
+
style: "hexagonal"
|
|
148
|
+
|
|
149
|
+
layers:
|
|
150
|
+
domain:
|
|
151
|
+
owns: "src/domain/**"
|
|
152
|
+
may_import: []
|
|
153
|
+
|
|
154
|
+
application:
|
|
155
|
+
owns: "src/application/**"
|
|
156
|
+
may_import:
|
|
157
|
+
- "domain"
|
|
158
|
+
|
|
159
|
+
infrastructure:
|
|
160
|
+
owns: "src/infrastructure/**"
|
|
161
|
+
may_import:
|
|
162
|
+
- "domain"
|
|
163
|
+
|
|
164
|
+
modules:
|
|
165
|
+
core:
|
|
166
|
+
owns: "src/core/**"
|
|
167
|
+
purpose: "Core business logic and domain models"
|
|
168
|
+
|
|
169
|
+
rules:
|
|
170
|
+
forbid:
|
|
171
|
+
- path: "src/domain/**"
|
|
172
|
+
calls: "requests.get"
|
|
173
|
+
reason: "Domain must not make HTTP calls"
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
### `dependencies.yaml`
|
|
177
|
+
|
|
178
|
+
Lists every dependency with its purpose and defines what layers cannot use.
|
|
179
|
+
|
|
180
|
+
```yaml
|
|
181
|
+
dependencies:
|
|
182
|
+
python:
|
|
183
|
+
runtime:
|
|
184
|
+
pydantic:
|
|
185
|
+
version: ">=2.0"
|
|
186
|
+
reason: "Data validation using type annotations"
|
|
187
|
+
dev:
|
|
188
|
+
pytest:
|
|
189
|
+
version: ">=7.0"
|
|
190
|
+
reason: "Testing framework"
|
|
191
|
+
|
|
192
|
+
rules:
|
|
193
|
+
forbid:
|
|
194
|
+
- layer: "domain"
|
|
195
|
+
dependency: "requests"
|
|
196
|
+
reason: "Domain should not make HTTP calls directly"
|
|
197
|
+
|
|
198
|
+
notes:
|
|
199
|
+
- "Prefer standard library when possible"
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### `api.yaml`
|
|
203
|
+
|
|
204
|
+
Maps what your code exports and who should use it.
|
|
205
|
+
|
|
206
|
+
```yaml
|
|
207
|
+
api:
|
|
208
|
+
public:
|
|
209
|
+
core:
|
|
210
|
+
location: "src/api.py"
|
|
211
|
+
exports:
|
|
212
|
+
- "initialize"
|
|
213
|
+
- "process_data"
|
|
214
|
+
stability: "stable"
|
|
215
|
+
|
|
216
|
+
internal:
|
|
217
|
+
utilities:
|
|
218
|
+
location: "src/utils/**"
|
|
219
|
+
exports:
|
|
220
|
+
- "helper_function"
|
|
221
|
+
stability: "experimental"
|
|
222
|
+
warning: "Internal only - use the public API instead"
|
|
223
|
+
|
|
224
|
+
rules:
|
|
225
|
+
forbid:
|
|
226
|
+
- path: "src/plugins/**"
|
|
227
|
+
api: "internal.utilities"
|
|
228
|
+
reason: "Plugins must use the public API"
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
All fields are validated with strict schemas. Unknown keys are rejected. Run `cap validate` to catch mistakes before your agent does.
|
|
232
|
+
|
|
233
|
+
---
|
|
234
|
+
|
|
235
|
+
## Architecture
|
|
236
|
+
|
|
237
|
+
CAP itself follows hexagonal architecture. The monorepo contains three packages with a strict one-way dependency flow:
|
|
238
|
+
|
|
239
|
+
```
|
|
240
|
+
Dependency flow: cli -> mcp -> core. Never the reverse.
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
```
|
|
244
|
+
cap/
|
|
245
|
+
├── core/ # cap-core - parsing, validation, formatting
|
|
246
|
+
│ └── cap_core/
|
|
247
|
+
│ ├── domain/ # Pydantic models - pure data, no I/O
|
|
248
|
+
│ │ └── models/
|
|
249
|
+
│ ├── infrastructure/ # FileReader - the only class that touches disk
|
|
250
|
+
│ └── application/ # ConfigService, ValidationService, MCPFormatter
|
|
251
|
+
│ └── services/
|
|
252
|
+
├── mcp/ # cap-mcp - FastMCP server with stdio transport
|
|
253
|
+
│ └── cap_mcp/
|
|
254
|
+
│ ├── server.py # Composition root - wires ConfigService into tools
|
|
255
|
+
│ └── tools/ # One file per MCP tool
|
|
256
|
+
├── shells/
|
|
257
|
+
│ ├── cli/ # cap-cli - click-based CLI
|
|
258
|
+
│ │ └── cap_cli/
|
|
259
|
+
│ │ ├── commands/ # init, serve, validate
|
|
260
|
+
│ │ ├── templates/ # Default .cap/ YAML files
|
|
261
|
+
│ │ └── utils/ # Workspace detection, output helpers
|
|
262
|
+
│ └── vscode/ # VS Code extension - TypeScript
|
|
263
|
+
│ └── src/
|
|
264
|
+
│ ├── setup/ # Python discovery, venv management, updates
|
|
265
|
+
│ ├── cap/ # CLI runner, init commands, validation
|
|
266
|
+
│ ├── mcp/ # MCP server provider, enable notice
|
|
267
|
+
│ └── utils/ # Shared workspace/venv/watcher helpers
|
|
268
|
+
└── .cap/ # CAP's own configuration (we eat our own dogfood)
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
### Key design decisions
|
|
272
|
+
|
|
273
|
+
- **Domain models are pure data.** Pydantic `BaseModel` subclasses with `extra="forbid"` - no I/O, no side effects, strict validation.
|
|
274
|
+
- **`ConfigService` is the main facade.** All config loading goes through it. Shells never touch `FileReader` directly.
|
|
275
|
+
- **One MCP tool per file.** Each tool module exposes a `register(mcp, config_service)` function.
|
|
276
|
+
- **The VS Code extension calls `cap` as a subprocess.** It never imports Python - it installs `cap-cli` into an isolated venv and runs commands through it.
|
|
277
|
+
|
|
278
|
+
---
|
|
279
|
+
|
|
280
|
+
## Development
|
|
281
|
+
|
|
282
|
+
### Prerequisites
|
|
283
|
+
|
|
284
|
+
- **Python** ≥ 3.11
|
|
285
|
+
- **Node.js** ≥ 20 (VS Code extension only)
|
|
286
|
+
- **VS Code** ≥ 1.109.0 (VS Code extension only)
|
|
287
|
+
- **Git** (for version control integration)
|
|
288
|
+
|
|
289
|
+
### Setup
|
|
290
|
+
|
|
291
|
+
Clone and install all packages in editable mode:
|
|
292
|
+
|
|
293
|
+
```bash
|
|
294
|
+
git clone https://github.com/domasles/cap.git
|
|
295
|
+
cd cap
|
|
296
|
+
|
|
297
|
+
pip install -e core/
|
|
298
|
+
pip install -e mcp/
|
|
299
|
+
pip install -e shells/cli/
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
Verify everything works:
|
|
303
|
+
|
|
304
|
+
```bash
|
|
305
|
+
cap --version
|
|
306
|
+
cap validate
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
### VS Code Extension Development
|
|
310
|
+
|
|
311
|
+
```bash
|
|
312
|
+
cd shells/vscode
|
|
313
|
+
npm install
|
|
314
|
+
npm run build
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
Press `F5` in VS Code to launch the Extension Development Host. In dev mode, the extension skips venv setup and expects `cap` to be installed on your PATH (from the editable installs above).
|
|
318
|
+
|
|
319
|
+
### Project structure cheat sheet
|
|
320
|
+
|
|
321
|
+
| Package | Language | Entry point | Install |
|
|
322
|
+
|---|---|---|---|
|
|
323
|
+
| cap-core | Python | `cap_core.ConfigService` | `pip install -e core/` |
|
|
324
|
+
| cap-mcp | Python | `cap_mcp.create_server()` | `pip install -e mcp/` |
|
|
325
|
+
| cap-cli | Python | `cap` CLI command | `pip install -e shells/cli/` |
|
|
326
|
+
| cap-vscode | TypeScript | `src/extension.ts` | `npm install` in `shells/vscode/` |
|
|
327
|
+
|
|
328
|
+
### Running tests
|
|
329
|
+
|
|
330
|
+
```bash
|
|
331
|
+
cap validate --json # Validate .cap/ files
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
### Adding a new shell
|
|
335
|
+
|
|
336
|
+
CAP is designed to be extended with new shells (IDE plugins, web UIs, etc.). A shell:
|
|
337
|
+
|
|
338
|
+
1. Calls `cap` CLI commands as a subprocess - it does not import core or mcp directly
|
|
339
|
+
2. Never adds logic to core - it only wires CLI output into its own UI
|
|
340
|
+
3. Lives in `shells/<name>/`
|
|
341
|
+
4. Gets its own build system and entry point
|
|
342
|
+
|
|
343
|
+
---
|
|
344
|
+
|
|
345
|
+
## Contributing
|
|
346
|
+
|
|
347
|
+
Contributions are welcome. Before you start:
|
|
348
|
+
|
|
349
|
+
1. **Open an issue first** for non-trivial changes so we can discuss the approach.
|
|
350
|
+
2. **Run `cap validate`** to make sure your `.cap/` files are correct.
|
|
351
|
+
3. **Respect the architecture.** The layer rules in `architecture.yaml` aren't suggestions - they're the contract.
|
|
352
|
+
4. **Keep the dependency flow.** `cli -> mcp -> core`. If you find yourself importing from a shell into core, stop and rethink.
|
|
353
|
+
|
|
354
|
+
### Style
|
|
355
|
+
|
|
356
|
+
- Python: [Black](https://github.com/psf/black) formatter, type hints everywhere
|
|
357
|
+
- TypeScript: Strict mode, no `any`
|
|
358
|
+
- YAML: 2-space indent, comments for anything non-obvious
|
|
359
|
+
|
|
360
|
+
---
|
|
361
|
+
|
|
362
|
+
## License
|
|
363
|
+
|
|
364
|
+
[Apache License 2.0](LICENSE)
|
cap_cli-1.0.1/README.md
ADDED
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
# CAP
|
|
2
|
+
|
|
3
|
+
**Codebase Awareness Protocol**
|
|
4
|
+
|
|
5
|
+
[](https://github.com/psf/black)
|
|
6
|
+
[](LICENSE)
|
|
7
|
+
[](https://python.org)
|
|
8
|
+
[](https://nodejs.org)
|
|
9
|
+
[](https://code.visualstudio.com/)
|
|
10
|
+
|
|
11
|
+
> Give AI coding agents the context they need - architecture, dependencies, and API - so they stop guessing and start respecting your codebase.
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## Philosophy
|
|
16
|
+
|
|
17
|
+
AI coding agents are powerful, but they are blind. They see files, not architecture. They read imports, not intent. Without explicit context, they silently violate boundaries, import forbidden packages, and ignore the structure you spent months building.
|
|
18
|
+
|
|
19
|
+
**CAP fixes this.** You describe your codebase once in three small YAML files. CAP serves that knowledge to any AI agent through the [Model Context Protocol (MCP)](https://modelcontextprotocol.io/), the open standard for connecting AI to tools.
|
|
20
|
+
|
|
21
|
+
The result: agents that understand your layers, respect your dependency rules, and use your public API - without you repeating yourself in every prompt.
|
|
22
|
+
|
|
23
|
+
### Three principles
|
|
24
|
+
|
|
25
|
+
1. **Declarative over discovery** - You know your codebase better than static analysis. Write it down once, in plain YAML.
|
|
26
|
+
2. **Protocol over prompts** - Structured MCP tool responses beat pasted context every time.
|
|
27
|
+
3. **Zero lock-in** - YAML files live in your repo. No SaaS, no accounts, no telemetry.
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## Getting Started
|
|
32
|
+
|
|
33
|
+
### VS Code Extension (recommended)
|
|
34
|
+
|
|
35
|
+
The fastest path. The extension handles Python, installs CAP, runs the MCP server, and connects it to your AI agent - all automatically.
|
|
36
|
+
|
|
37
|
+
**1. Install the extension**
|
|
38
|
+
|
|
39
|
+
Search for **"CAP - Codebase Awareness Protocol"** in the VS Code Extensions Marketplace, or install from the command line:
|
|
40
|
+
|
|
41
|
+
```
|
|
42
|
+
code --install-extension domasles.cap-vscode
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
**2. Initialize your workspace**
|
|
46
|
+
|
|
47
|
+
Open the Command Palette (`Ctrl+Shift+P`) and run:
|
|
48
|
+
|
|
49
|
+
```
|
|
50
|
+
CAP: Initialize Configuration
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
This creates a `.cap/` directory with three template files:
|
|
54
|
+
|
|
55
|
+
```
|
|
56
|
+
.cap/
|
|
57
|
+
├── api.yaml # What your code exports
|
|
58
|
+
├── architecture.yaml # How your code is organized
|
|
59
|
+
└── dependencies.yaml # What your code depends on
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Edit them to match your project. That's all the setup you need.
|
|
63
|
+
|
|
64
|
+
**3. Enable the MCP server**
|
|
65
|
+
|
|
66
|
+
When `.cap/` is created, the extension shows a notification prompting you to enable the MCP server. Click **Open Chat** to go to the Copilot panel, then enable the **CAP** server in the MCP tools list.
|
|
67
|
+
|
|
68
|
+
Once enabled, every AI agent conversation has access to three tools:
|
|
69
|
+
|
|
70
|
+
| Tool | What the agent gets |
|
|
71
|
+
|---|---|
|
|
72
|
+
| `get_architecture` | Layers, modules, ownership, architectural rules |
|
|
73
|
+
| `get_dependencies` | Runtime/dev packages, versions, forbidden patterns |
|
|
74
|
+
| `get_api` | Public/internal exports, stability, access rules |
|
|
75
|
+
|
|
76
|
+
The agent calls these tools when it needs context. You don't need to prompt for it.
|
|
77
|
+
|
|
78
|
+
### CLI
|
|
79
|
+
|
|
80
|
+
If you prefer working from the terminal or want CAP without VS Code:
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
pip install cap-cli
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
**Initialize:**
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
cap init # Create .cap/ with templates
|
|
90
|
+
cap init --minimal # Bare minimum scaffolding
|
|
91
|
+
cap init --force # Overwrite existing files
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
**Validate your configuration:**
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
cap validate # Pretty terminal output
|
|
98
|
+
cap validate --json # Machine-readable for CI
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
**Start the MCP server:**
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
cap serve
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
This runs a [stdio MCP server](https://modelcontextprotocol.io/docs/concepts/transports#standard-io-stdio) that any MCP-compatible client can connect to. Point your AI tool at the `cap serve` command and it will discover the three tools automatically.
|
|
108
|
+
|
|
109
|
+
---
|
|
110
|
+
|
|
111
|
+
## The `.cap/` Files
|
|
112
|
+
|
|
113
|
+
### `architecture.yaml`
|
|
114
|
+
|
|
115
|
+
Defines the structural skeleton of your codebase.
|
|
116
|
+
|
|
117
|
+
```yaml
|
|
118
|
+
architecture:
|
|
119
|
+
style: "hexagonal"
|
|
120
|
+
|
|
121
|
+
layers:
|
|
122
|
+
domain:
|
|
123
|
+
owns: "src/domain/**"
|
|
124
|
+
may_import: []
|
|
125
|
+
|
|
126
|
+
application:
|
|
127
|
+
owns: "src/application/**"
|
|
128
|
+
may_import:
|
|
129
|
+
- "domain"
|
|
130
|
+
|
|
131
|
+
infrastructure:
|
|
132
|
+
owns: "src/infrastructure/**"
|
|
133
|
+
may_import:
|
|
134
|
+
- "domain"
|
|
135
|
+
|
|
136
|
+
modules:
|
|
137
|
+
core:
|
|
138
|
+
owns: "src/core/**"
|
|
139
|
+
purpose: "Core business logic and domain models"
|
|
140
|
+
|
|
141
|
+
rules:
|
|
142
|
+
forbid:
|
|
143
|
+
- path: "src/domain/**"
|
|
144
|
+
calls: "requests.get"
|
|
145
|
+
reason: "Domain must not make HTTP calls"
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### `dependencies.yaml`
|
|
149
|
+
|
|
150
|
+
Lists every dependency with its purpose and defines what layers cannot use.
|
|
151
|
+
|
|
152
|
+
```yaml
|
|
153
|
+
dependencies:
|
|
154
|
+
python:
|
|
155
|
+
runtime:
|
|
156
|
+
pydantic:
|
|
157
|
+
version: ">=2.0"
|
|
158
|
+
reason: "Data validation using type annotations"
|
|
159
|
+
dev:
|
|
160
|
+
pytest:
|
|
161
|
+
version: ">=7.0"
|
|
162
|
+
reason: "Testing framework"
|
|
163
|
+
|
|
164
|
+
rules:
|
|
165
|
+
forbid:
|
|
166
|
+
- layer: "domain"
|
|
167
|
+
dependency: "requests"
|
|
168
|
+
reason: "Domain should not make HTTP calls directly"
|
|
169
|
+
|
|
170
|
+
notes:
|
|
171
|
+
- "Prefer standard library when possible"
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### `api.yaml`
|
|
175
|
+
|
|
176
|
+
Maps what your code exports and who should use it.
|
|
177
|
+
|
|
178
|
+
```yaml
|
|
179
|
+
api:
|
|
180
|
+
public:
|
|
181
|
+
core:
|
|
182
|
+
location: "src/api.py"
|
|
183
|
+
exports:
|
|
184
|
+
- "initialize"
|
|
185
|
+
- "process_data"
|
|
186
|
+
stability: "stable"
|
|
187
|
+
|
|
188
|
+
internal:
|
|
189
|
+
utilities:
|
|
190
|
+
location: "src/utils/**"
|
|
191
|
+
exports:
|
|
192
|
+
- "helper_function"
|
|
193
|
+
stability: "experimental"
|
|
194
|
+
warning: "Internal only - use the public API instead"
|
|
195
|
+
|
|
196
|
+
rules:
|
|
197
|
+
forbid:
|
|
198
|
+
- path: "src/plugins/**"
|
|
199
|
+
api: "internal.utilities"
|
|
200
|
+
reason: "Plugins must use the public API"
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
All fields are validated with strict schemas. Unknown keys are rejected. Run `cap validate` to catch mistakes before your agent does.
|
|
204
|
+
|
|
205
|
+
---
|
|
206
|
+
|
|
207
|
+
## Architecture
|
|
208
|
+
|
|
209
|
+
CAP itself follows hexagonal architecture. The monorepo contains three packages with a strict one-way dependency flow:
|
|
210
|
+
|
|
211
|
+
```
|
|
212
|
+
Dependency flow: cli -> mcp -> core. Never the reverse.
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
```
|
|
216
|
+
cap/
|
|
217
|
+
├── core/ # cap-core - parsing, validation, formatting
|
|
218
|
+
│ └── cap_core/
|
|
219
|
+
│ ├── domain/ # Pydantic models - pure data, no I/O
|
|
220
|
+
│ │ └── models/
|
|
221
|
+
│ ├── infrastructure/ # FileReader - the only class that touches disk
|
|
222
|
+
│ └── application/ # ConfigService, ValidationService, MCPFormatter
|
|
223
|
+
│ └── services/
|
|
224
|
+
├── mcp/ # cap-mcp - FastMCP server with stdio transport
|
|
225
|
+
│ └── cap_mcp/
|
|
226
|
+
│ ├── server.py # Composition root - wires ConfigService into tools
|
|
227
|
+
│ └── tools/ # One file per MCP tool
|
|
228
|
+
├── shells/
|
|
229
|
+
│ ├── cli/ # cap-cli - click-based CLI
|
|
230
|
+
│ │ └── cap_cli/
|
|
231
|
+
│ │ ├── commands/ # init, serve, validate
|
|
232
|
+
│ │ ├── templates/ # Default .cap/ YAML files
|
|
233
|
+
│ │ └── utils/ # Workspace detection, output helpers
|
|
234
|
+
│ └── vscode/ # VS Code extension - TypeScript
|
|
235
|
+
│ └── src/
|
|
236
|
+
│ ├── setup/ # Python discovery, venv management, updates
|
|
237
|
+
│ ├── cap/ # CLI runner, init commands, validation
|
|
238
|
+
│ ├── mcp/ # MCP server provider, enable notice
|
|
239
|
+
│ └── utils/ # Shared workspace/venv/watcher helpers
|
|
240
|
+
└── .cap/ # CAP's own configuration (we eat our own dogfood)
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
### Key design decisions
|
|
244
|
+
|
|
245
|
+
- **Domain models are pure data.** Pydantic `BaseModel` subclasses with `extra="forbid"` - no I/O, no side effects, strict validation.
|
|
246
|
+
- **`ConfigService` is the main facade.** All config loading goes through it. Shells never touch `FileReader` directly.
|
|
247
|
+
- **One MCP tool per file.** Each tool module exposes a `register(mcp, config_service)` function.
|
|
248
|
+
- **The VS Code extension calls `cap` as a subprocess.** It never imports Python - it installs `cap-cli` into an isolated venv and runs commands through it.
|
|
249
|
+
|
|
250
|
+
---
|
|
251
|
+
|
|
252
|
+
## Development
|
|
253
|
+
|
|
254
|
+
### Prerequisites
|
|
255
|
+
|
|
256
|
+
- **Python** ≥ 3.11
|
|
257
|
+
- **Node.js** ≥ 20 (VS Code extension only)
|
|
258
|
+
- **VS Code** ≥ 1.109.0 (VS Code extension only)
|
|
259
|
+
- **Git** (for version control integration)
|
|
260
|
+
|
|
261
|
+
### Setup
|
|
262
|
+
|
|
263
|
+
Clone and install all packages in editable mode:
|
|
264
|
+
|
|
265
|
+
```bash
|
|
266
|
+
git clone https://github.com/domasles/cap.git
|
|
267
|
+
cd cap
|
|
268
|
+
|
|
269
|
+
pip install -e core/
|
|
270
|
+
pip install -e mcp/
|
|
271
|
+
pip install -e shells/cli/
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
Verify everything works:
|
|
275
|
+
|
|
276
|
+
```bash
|
|
277
|
+
cap --version
|
|
278
|
+
cap validate
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
### VS Code Extension Development
|
|
282
|
+
|
|
283
|
+
```bash
|
|
284
|
+
cd shells/vscode
|
|
285
|
+
npm install
|
|
286
|
+
npm run build
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
Press `F5` in VS Code to launch the Extension Development Host. In dev mode, the extension skips venv setup and expects `cap` to be installed on your PATH (from the editable installs above).
|
|
290
|
+
|
|
291
|
+
### Project structure cheat sheet
|
|
292
|
+
|
|
293
|
+
| Package | Language | Entry point | Install |
|
|
294
|
+
|---|---|---|---|
|
|
295
|
+
| cap-core | Python | `cap_core.ConfigService` | `pip install -e core/` |
|
|
296
|
+
| cap-mcp | Python | `cap_mcp.create_server()` | `pip install -e mcp/` |
|
|
297
|
+
| cap-cli | Python | `cap` CLI command | `pip install -e shells/cli/` |
|
|
298
|
+
| cap-vscode | TypeScript | `src/extension.ts` | `npm install` in `shells/vscode/` |
|
|
299
|
+
|
|
300
|
+
### Running tests
|
|
301
|
+
|
|
302
|
+
```bash
|
|
303
|
+
cap validate --json # Validate .cap/ files
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
### Adding a new shell
|
|
307
|
+
|
|
308
|
+
CAP is designed to be extended with new shells (IDE plugins, web UIs, etc.). A shell:
|
|
309
|
+
|
|
310
|
+
1. Calls `cap` CLI commands as a subprocess - it does not import core or mcp directly
|
|
311
|
+
2. Never adds logic to core - it only wires CLI output into its own UI
|
|
312
|
+
3. Lives in `shells/<name>/`
|
|
313
|
+
4. Gets its own build system and entry point
|
|
314
|
+
|
|
315
|
+
---
|
|
316
|
+
|
|
317
|
+
## Contributing
|
|
318
|
+
|
|
319
|
+
Contributions are welcome. Before you start:
|
|
320
|
+
|
|
321
|
+
1. **Open an issue first** for non-trivial changes so we can discuss the approach.
|
|
322
|
+
2. **Run `cap validate`** to make sure your `.cap/` files are correct.
|
|
323
|
+
3. **Respect the architecture.** The layer rules in `architecture.yaml` aren't suggestions - they're the contract.
|
|
324
|
+
4. **Keep the dependency flow.** `cli -> mcp -> core`. If you find yourself importing from a shell into core, stop and rethink.
|
|
325
|
+
|
|
326
|
+
### Style
|
|
327
|
+
|
|
328
|
+
- Python: [Black](https://github.com/psf/black) formatter, type hints everywhere
|
|
329
|
+
- TypeScript: Strict mode, no `any`
|
|
330
|
+
- YAML: 2-space indent, comments for anything non-obvious
|
|
331
|
+
|
|
332
|
+
---
|
|
333
|
+
|
|
334
|
+
## License
|
|
335
|
+
|
|
336
|
+
[Apache License 2.0](LICENSE)
|