mdx-code 0.1.0__tar.gz → 0.2.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 (78) hide show
  1. mdx_code-0.2.0/PKG-INFO +269 -0
  2. mdx_code-0.2.0/README.md +229 -0
  3. mdx_code-0.2.0/mcp_servers/__init__.py +1 -0
  4. mdx_code-0.2.0/mcp_servers/audit/__init__.py +1 -0
  5. mdx_code-0.2.0/mcp_servers/audit/server.py +196 -0
  6. mdx_code-0.2.0/mcp_servers/cost/__init__.py +1 -0
  7. mdx_code-0.2.0/mcp_servers/cost/server.py +112 -0
  8. mdx_code-0.2.0/mcp_servers/governance/__init__.py +1 -0
  9. mdx_code-0.2.0/mcp_servers/governance/server.py +136 -0
  10. mdx_code-0.2.0/mdx_code.egg-info/PKG-INFO +269 -0
  11. mdx_code-0.2.0/mdx_code.egg-info/SOURCES.txt +54 -0
  12. mdx_code-0.2.0/mdx_code.egg-info/entry_points.txt +5 -0
  13. mdx_code-0.2.0/mdx_code.egg-info/requires.txt +13 -0
  14. mdx_code-0.2.0/mdx_code.egg-info/top_level.txt +2 -0
  15. mdx_code-0.2.0/mdxcode/__init__.py +3 -0
  16. mdx_code-0.2.0/mdxcode/__main__.py +5 -0
  17. mdx_code-0.2.0/mdxcode/backends/__init__.py +1 -0
  18. mdx_code-0.2.0/mdxcode/backends/base.py +100 -0
  19. mdx_code-0.2.0/mdxcode/backends/circuit_breaker.py +183 -0
  20. mdx_code-0.2.0/mdxcode/backends/claude.py +235 -0
  21. mdx_code-0.2.0/mdxcode/backends/codex.py +231 -0
  22. mdx_code-0.2.0/mdxcode/backends/discovery.py +163 -0
  23. mdx_code-0.2.0/mdxcode/backends/gemini.py +227 -0
  24. mdx_code-0.2.0/mdxcode/backends/opencode.py +104 -0
  25. mdx_code-0.2.0/mdxcode/cli.py +2320 -0
  26. mdx_code-0.2.0/mdxcode/config.py +131 -0
  27. mdx_code-0.2.0/mdxcode/governance/__init__.py +1 -0
  28. mdx_code-0.2.0/mdxcode/governance/audit_trail.py +380 -0
  29. mdx_code-0.2.0/mdxcode/governance/compliance.py +43 -0
  30. mdx_code-0.2.0/mdxcode/governance/policy_engine.py +248 -0
  31. mdx_code-0.2.0/mdxcode/output/__init__.py +9 -0
  32. mdx_code-0.2.0/mdxcode/output/colors.py +24 -0
  33. mdx_code-0.2.0/mdxcode/output/footer.py +111 -0
  34. mdx_code-0.2.0/mdxcode/output/streamer.py +87 -0
  35. mdx_code-0.2.0/mdxcode/py.typed +0 -0
  36. mdx_code-0.2.0/mdxcode/review/__init__.py +1 -0
  37. mdx_code-0.2.0/mdxcode/review/consensus.py +286 -0
  38. mdx_code-0.2.0/mdxcode/review/normalizer.py +210 -0
  39. mdx_code-0.2.0/mdxcode/review/orchestrator.py +317 -0
  40. mdx_code-0.2.0/mdxcode/review/renderer.py +365 -0
  41. mdx_code-0.2.0/mdxcode/router/__init__.py +1 -0
  42. mdx_code-0.2.0/mdxcode/router/cost_tracker.py +229 -0
  43. mdx_code-0.2.0/mdxcode/router/engine.py +211 -0
  44. mdx_code-0.2.0/mdxcode/router/profiles.py +70 -0
  45. mdx_code-0.2.0/mdxcode/router/strategies.py +230 -0
  46. {mdx_code-0.1.0 → mdx_code-0.2.0}/pyproject.toml +28 -43
  47. mdx_code-0.2.0/tests/test_audit.py +255 -0
  48. mdx_code-0.2.0/tests/test_circuit_breaker.py +227 -0
  49. mdx_code-0.2.0/tests/test_codex.py +176 -0
  50. mdx_code-0.2.0/tests/test_config.py +98 -0
  51. mdx_code-0.2.0/tests/test_discovery.py +275 -0
  52. mdx_code-0.2.0/tests/test_gemini.py +176 -0
  53. mdx_code-0.2.0/tests/test_session9a.py +902 -0
  54. mdx_code-0.1.0/PKG-INFO +0 -316
  55. mdx_code-0.1.0/README.md +0 -268
  56. mdx_code-0.1.0/mdx_code.egg-info/PKG-INFO +0 -316
  57. mdx_code-0.1.0/mdx_code.egg-info/SOURCES.txt +0 -24
  58. mdx_code-0.1.0/mdx_code.egg-info/entry_points.txt +0 -2
  59. mdx_code-0.1.0/mdx_code.egg-info/requires.txt +0 -24
  60. mdx_code-0.1.0/mdx_code.egg-info/top_level.txt +0 -1
  61. mdx_code-0.1.0/mdxcode/__init__.py +0 -11
  62. mdx_code-0.1.0/mdxcode/cli.py +0 -269
  63. mdx_code-0.1.0/mdxcode/core/__init__.py +0 -26
  64. mdx_code-0.1.0/mdxcode/core/agent_loop.py +0 -308
  65. mdx_code-0.1.0/mdxcode/core/context_loader.py +0 -209
  66. mdx_code-0.1.0/mdxcode/core/session.py +0 -80
  67. mdx_code-0.1.0/mdxcode/governance/__init__.py +0 -26
  68. mdx_code-0.1.0/mdxcode/governance/audit.py +0 -200
  69. mdx_code-0.1.0/mdxcode/governance/permissions.py +0 -299
  70. mdx_code-0.1.0/mdxcode/governance/security_agent.py +0 -363
  71. mdx_code-0.1.0/mdxcode/models/__init__.py +0 -28
  72. mdx_code-0.1.0/mdxcode/models/auth.py +0 -232
  73. mdx_code-0.1.0/mdxcode/models/router.py +0 -202
  74. mdx_code-0.1.0/mdxcode/tools/__init__.py +0 -18
  75. mdx_code-0.1.0/mdxcode/tools/registry.py +0 -417
  76. {mdx_code-0.1.0 → mdx_code-0.2.0}/LICENSE +0 -0
  77. {mdx_code-0.1.0 → mdx_code-0.2.0}/mdx_code.egg-info/dependency_links.txt +0 -0
  78. {mdx_code-0.1.0 → mdx_code-0.2.0}/setup.cfg +0 -0
@@ -0,0 +1,269 @@
1
+ Metadata-Version: 2.4
2
+ Name: mdx-code
3
+ Version: 0.2.0
4
+ Summary: The AI Engineering Manager for your codebase.
5
+ Author: MD
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/dhotherm/mdx-code
8
+ Project-URL: Repository, https://github.com/dhotherm/mdx-code
9
+ Project-URL: Documentation, https://github.com/dhotherm/mdx-code#readme
10
+ Project-URL: Bug Tracker, https://github.com/dhotherm/mdx-code/issues
11
+ Project-URL: Changelog, https://github.com/dhotherm/mdx-code/blob/main/CHANGELOG.md
12
+ Keywords: ai,llm,developer-tools,code-review,governance,multi-model,adversarial-review
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Environment :: Console
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: License :: OSI Approved :: MIT License
17
+ Classifier: Operating System :: OS Independent
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Topic :: Software Development :: Quality Assurance
23
+ Classifier: Topic :: Software Development :: Testing
24
+ Classifier: Typing :: Typed
25
+ Requires-Python: >=3.11
26
+ Description-Content-Type: text/markdown
27
+ License-File: LICENSE
28
+ Requires-Dist: typer>=0.12.0
29
+ Requires-Dist: rich>=13.0.0
30
+ Requires-Dist: pyyaml>=6.0
31
+ Requires-Dist: pydantic>=2.0.0
32
+ Provides-Extra: dev
33
+ Requires-Dist: pytest>=8.0.0; extra == "dev"
34
+ Requires-Dist: pytest-asyncio>=0.23.0; extra == "dev"
35
+ Requires-Dist: black>=24.0.0; extra == "dev"
36
+ Requires-Dist: mypy>=1.8.0; extra == "dev"
37
+ Provides-Extra: mcp
38
+ Requires-Dist: mcp>=1.0.0; extra == "mcp"
39
+ Dynamic: license-file
40
+
41
+ [![CI](https://github.com/dhotherm/mdx-code/actions/workflows/ci.yml/badge.svg)](https://github.com/dhotherm/mdx-code/actions/workflows/ci.yml)
42
+ [![Python 3.11+](https://img.shields.io/badge/python-3.11+-blue.svg)](https://www.python.org/downloads/)
43
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
44
+ [![Tests: 430](https://img.shields.io/badge/tests-430-brightgreen.svg)]()
45
+ [![Commands: 21](https://img.shields.io/badge/commands-21-blue.svg)]()
46
+ [![Overhead: <200ms](https://img.shields.io/badge/overhead-<200ms-green.svg)]()
47
+
48
+ # MDx Code
49
+
50
+ **The AI Engineering Manager for your codebase.**
51
+
52
+ Orchestrates multiple AI coding CLIs with governance, adversarial review, audit trails, and cost tracking.
53
+
54
+ ## The Hook
55
+
56
+ Run the same task through two models. Get findings neither would catch alone:
57
+
58
+ ```
59
+ $ mdx review src/auth/
60
+
61
+ Adversarial Review: src/auth/
62
+ ──────────────────────────────
63
+
64
+ Claude found 4 issues Codex found 3 issues
65
+
66
+ Cross-validated: 2 agreed Unique: 3
67
+
68
+ Neither model alone found all 5 real issues.
69
+ ```
70
+
71
+ ## Quick Install
72
+
73
+ ```bash
74
+ curl -fsSL https://raw.githubusercontent.com/dhotherm/mdx-code/main/install.sh | bash
75
+ ```
76
+
77
+ First-run wizard guides you through setup automatically.
78
+
79
+ ### Manual Install
80
+
81
+ ```bash
82
+ pip install -e .
83
+ mdx setup
84
+ ```
85
+
86
+ ## Why MDx Code Exists
87
+
88
+ Every AI coding CLI is a silo. Claude Code is incredible at deep reasoning. Codex is fast and cheap. Gemini handles massive context. But none of them talk to each other...none of them track what they cost you...and none of them give your security team the audit trail they need to say yes.
89
+
90
+ That's the gap. The tools are ready. The governance isn't.
91
+
92
+ If you're in a regulated environment...SOC 2, HIPAA, OSFI...you already know the problem. You can't just let 3 different AI agents push code with no cross-validation, no cost visibility, and no single source of truth. It doesn't fly.
93
+
94
+ MDx Code is the missing layer. It doesn't replace Claude, Codex, or Gemini...it orchestrates them. Routes the right task to the right model at the right cost. Runs adversarial reviews where two models cross-validate each other's work...finding bugs neither catches alone. Logs every action in a chain-hashed audit trail your compliance team can actually verify. And does all of this with less than 200ms of overhead. The wrapper is invisible.
95
+
96
+ Think of it this way...you wouldn't let 3 senior engineers push to production with no code review, no cost tracking, and no audit trail. Why would you let 3 AI coding agents do the same?
97
+
98
+ ## Architecture
99
+
100
+ ```
101
+ ┌─────────────────────────────────────────────────────────────────┐
102
+ │ CLI Layer │
103
+ │ Commands · Flags · Typer/Click · First-run wizard · Banner │
104
+ └──────────────────────────┬──────────────────────────────────────┘
105
+
106
+ ┌──────────────────────────▼──────────────────────────────────────┐
107
+ │ Routing Layer │
108
+ │ Task categorization · Strategy selection · Backend profiles │
109
+ │ Circuit breakers · Cost estimation · Budget guardrails │
110
+ └──────────────────────────┬──────────────────────────────────────┘
111
+
112
+ ┌──────────────────────────▼──────────────────────────────────────┐
113
+ │ Backend Layer │
114
+ │ Claude adapter · Codex adapter · Gemini adapter │
115
+ │ Subprocess spawning · Output streaming · Error classification │
116
+ │ Auto-discovery · Health checks · Fallback recovery │
117
+ └──────────────────────────┬──────────────────────────────────────┘
118
+
119
+ ┌──────────────────────────▼──────────────────────────────────────┐
120
+ │ Governance Layer │
121
+ │ Policy engine · Compliance matrix · Chain-hashed audit trail │
122
+ │ Adversarial review · Finding consensus · Cost tracking (SQLite)│
123
+ └──────────────────────────┬──────────────────────────────────────┘
124
+
125
+ ┌──────────────────────────▼──────────────────────────────────────┐
126
+ │ Output Layer │
127
+ │ Rich streaming · Markdown detection · Footer · Budget display │
128
+ │ NO_COLOR support · Pipe detection · Onboarding tips │
129
+ └─────────────────────────────────────────────────────────────────┘
130
+ ```
131
+
132
+ ## Commands
133
+
134
+ | Command | Description |
135
+ |---------|-------------|
136
+ | `mdx "task"` | Execute via best available backend |
137
+ | `mdx "task" --pick` | Interactively pick a backend |
138
+ | `mdx "task" --backend claude` | Force a specific backend |
139
+ | `mdx "task" --strategy cost` | Override routing strategy |
140
+ | `mdx review src/` | Adversarial multi-model review |
141
+ | `mdx review --last` | Review last change MDx made |
142
+ | `mdx review --diff HEAD~1` | Review a git diff |
143
+ | `mdx cost` | Spending dashboard |
144
+ | `mdx cost --week` | Weekly cost breakdown |
145
+ | `mdx audit` | Audit trail history |
146
+ | `mdx audit --verify` | Verify audit chain integrity |
147
+ | `mdx audit --stats` | Audit summary statistics |
148
+ | `mdx history` | Recent task history |
149
+ | `mdx summary` | Today's AI coding summary |
150
+ | `mdx setup` | Detect available backends |
151
+ | `mdx status` | Backend health and circuit breakers |
152
+ | `mdx policy` | View active policies |
153
+ | `mdx policy init` | Create starter .mdxpolicy |
154
+ | `mdx policy check <files>` | Check files against policies |
155
+ | `mdx compliance` | Regulatory compliance matrix |
156
+ | `mdx hook install` | Git pre-commit hook |
157
+ | `mdx replay` | Replay last task output |
158
+ | `mdx undo` | Revert last backend change |
159
+ | `mdx mcp status` | MCP server availability |
160
+ | `mdx mcp config` | Generate MCP client config |
161
+ | `mdx install-completion` | Shell tab-completion |
162
+
163
+ ## How It Works
164
+
165
+ MDx Code does **not** run its own agent loop. It spawns real AI coding CLIs (`claude`, `codex`, `gemini`) as subprocesses, streams their output in real-time, and wraps everything with orchestration: smart routing, cost tracking, governance policies, and an immutable audit trail.
166
+
167
+ Every task execution flows through:
168
+ 1. **Categorize** — Keyword-based task classification (no LLM call)
169
+ 2. **Route** — Score backends using the selected strategy
170
+ 3. **Execute** — Spawn the CLI subprocess and stream output
171
+ 4. **Track** — Record cost (SQLite) and audit entry (chain-hashed JSONL)
172
+ 5. **Govern** — Evaluate policies and recommend review if triggered
173
+
174
+ ## Key Features
175
+
176
+ - **Multi-backend routing** — Routes tasks to the best available CLI based on cost, quality, or balanced strategies
177
+ - **Adversarial review** — Run code through multiple models and cross-validate findings with consensus scoring
178
+ - **Governance policies** — Define per-path rules for review requirements, approval gates, and minimum reviewers
179
+ - **Cost tracking** — Token and dollar spend across all backends with savings analysis and budget guardrails
180
+ - **Audit trail** — Immutable, chain-hashed JSONL logs with SHA-256 integrity verification
181
+ - **Compliance** — Maps features to SOC 2, HIPAA, SOX, and OSFI regulatory frameworks
182
+ - **MCP servers** — Expose governance, audit, and cost data to MCP-compatible clients
183
+ - **Circuit breakers** — Automatic fallback when a backend is unhealthy (closed → open → half-open)
184
+
185
+ ## Routing Strategies
186
+
187
+ | Strategy | When to Use | How It Works |
188
+ |----------|-------------|--------------|
189
+ | `balanced` | Default. Best all-around. | Scores backends on quality × strength / relative cost |
190
+ | `quality` | Critical code, security-sensitive | Always picks highest-quality backend |
191
+ | `cost` | Bulk tasks, experiments | Picks cheapest available backend |
192
+
193
+ See [docs/routing.md](docs/routing.md) for details on backend profiles, scoring formulas, and circuit breakers.
194
+
195
+ ## Performance
196
+
197
+ | Metric | Value |
198
+ |--------|-------|
199
+ | Cold start | 20ms (20x improvement from lazy imports) |
200
+ | Config loading | < 1ms (module-level cache) |
201
+ | Routing decision | 0.1ms |
202
+ | Total wrapper overhead | < 200ms |
203
+
204
+ The footer displays before async I/O writes (audit, cost tracking) complete — the user never waits for bookkeeping.
205
+
206
+ ## Governance & Compliance
207
+
208
+ Define policies in `.mdxpolicy` to enforce review requirements per path:
209
+
210
+ ```yaml
211
+ policies:
212
+ - name: auth-critical
213
+ paths: ["src/auth/**", "src/security/**"]
214
+ requires:
215
+ adversarial_review: true
216
+ human_approval: true
217
+ severity: critical
218
+ ```
219
+
220
+ MDx Code maps its features to regulatory frameworks:
221
+
222
+ | Framework | Coverage |
223
+ |-----------|----------|
224
+ | SOC 2 | Audit trail, access logging, change tracking |
225
+ | HIPAA | Audit controls, integrity verification |
226
+ | SOX | Approval workflows, immutable records |
227
+ | OSFI B-13 | Model provenance, technology risk controls |
228
+
229
+ Run `mdx compliance` to see the full compliance matrix.
230
+
231
+ ## Configuration
232
+
233
+ MDx Code supports three levels of configuration:
234
+
235
+ - **Global** — `~/.mdx/config.yaml` (routing strategy, budgets, display)
236
+ - **Project** — `.mdx.yaml` in repo root (overrides global for this project)
237
+ - **Governance** — `.mdxpolicy` in repo root (policy rules)
238
+
239
+ See [docs/configuration.md](docs/configuration.md) for all fields and example configs.
240
+
241
+ ## MCP Integration
242
+
243
+ MDx Code ships three MCP servers for integration with AI coding tools:
244
+
245
+ - **Governance server** — Policy checking and compliance data
246
+ - **Audit server** — Audit trail access and verification
247
+ - **Cost server** — Spending data and budget status
248
+
249
+ See [docs/mcp-setup.md](docs/mcp-setup.md) for setup instructions.
250
+
251
+ ## Requirements
252
+
253
+ - Python 3.11+
254
+ - At least one AI coding CLI:
255
+ - [Claude Code](https://github.com/anthropics/claude-code)
256
+ - [Codex CLI](https://github.com/openai/codex)
257
+ - [Gemini CLI](https://github.com/google-gemini/gemini-cli)
258
+
259
+ ## Contributing
260
+
261
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for development setup, code style, and PR process.
262
+
263
+ ## Security
264
+
265
+ See [SECURITY.md](SECURITY.md) for vulnerability reporting and security policy.
266
+
267
+ ## License
268
+
269
+ [MIT](LICENSE)
@@ -0,0 +1,229 @@
1
+ [![CI](https://github.com/dhotherm/mdx-code/actions/workflows/ci.yml/badge.svg)](https://github.com/dhotherm/mdx-code/actions/workflows/ci.yml)
2
+ [![Python 3.11+](https://img.shields.io/badge/python-3.11+-blue.svg)](https://www.python.org/downloads/)
3
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
4
+ [![Tests: 430](https://img.shields.io/badge/tests-430-brightgreen.svg)]()
5
+ [![Commands: 21](https://img.shields.io/badge/commands-21-blue.svg)]()
6
+ [![Overhead: <200ms](https://img.shields.io/badge/overhead-<200ms-green.svg)]()
7
+
8
+ # MDx Code
9
+
10
+ **The AI Engineering Manager for your codebase.**
11
+
12
+ Orchestrates multiple AI coding CLIs with governance, adversarial review, audit trails, and cost tracking.
13
+
14
+ ## The Hook
15
+
16
+ Run the same task through two models. Get findings neither would catch alone:
17
+
18
+ ```
19
+ $ mdx review src/auth/
20
+
21
+ Adversarial Review: src/auth/
22
+ ──────────────────────────────
23
+
24
+ Claude found 4 issues Codex found 3 issues
25
+
26
+ Cross-validated: 2 agreed Unique: 3
27
+
28
+ Neither model alone found all 5 real issues.
29
+ ```
30
+
31
+ ## Quick Install
32
+
33
+ ```bash
34
+ curl -fsSL https://raw.githubusercontent.com/dhotherm/mdx-code/main/install.sh | bash
35
+ ```
36
+
37
+ First-run wizard guides you through setup automatically.
38
+
39
+ ### Manual Install
40
+
41
+ ```bash
42
+ pip install -e .
43
+ mdx setup
44
+ ```
45
+
46
+ ## Why MDx Code Exists
47
+
48
+ Every AI coding CLI is a silo. Claude Code is incredible at deep reasoning. Codex is fast and cheap. Gemini handles massive context. But none of them talk to each other...none of them track what they cost you...and none of them give your security team the audit trail they need to say yes.
49
+
50
+ That's the gap. The tools are ready. The governance isn't.
51
+
52
+ If you're in a regulated environment...SOC 2, HIPAA, OSFI...you already know the problem. You can't just let 3 different AI agents push code with no cross-validation, no cost visibility, and no single source of truth. It doesn't fly.
53
+
54
+ MDx Code is the missing layer. It doesn't replace Claude, Codex, or Gemini...it orchestrates them. Routes the right task to the right model at the right cost. Runs adversarial reviews where two models cross-validate each other's work...finding bugs neither catches alone. Logs every action in a chain-hashed audit trail your compliance team can actually verify. And does all of this with less than 200ms of overhead. The wrapper is invisible.
55
+
56
+ Think of it this way...you wouldn't let 3 senior engineers push to production with no code review, no cost tracking, and no audit trail. Why would you let 3 AI coding agents do the same?
57
+
58
+ ## Architecture
59
+
60
+ ```
61
+ ┌─────────────────────────────────────────────────────────────────┐
62
+ │ CLI Layer │
63
+ │ Commands · Flags · Typer/Click · First-run wizard · Banner │
64
+ └──────────────────────────┬──────────────────────────────────────┘
65
+
66
+ ┌──────────────────────────▼──────────────────────────────────────┐
67
+ │ Routing Layer │
68
+ │ Task categorization · Strategy selection · Backend profiles │
69
+ │ Circuit breakers · Cost estimation · Budget guardrails │
70
+ └──────────────────────────┬──────────────────────────────────────┘
71
+
72
+ ┌──────────────────────────▼──────────────────────────────────────┐
73
+ │ Backend Layer │
74
+ │ Claude adapter · Codex adapter · Gemini adapter │
75
+ │ Subprocess spawning · Output streaming · Error classification │
76
+ │ Auto-discovery · Health checks · Fallback recovery │
77
+ └──────────────────────────┬──────────────────────────────────────┘
78
+
79
+ ┌──────────────────────────▼──────────────────────────────────────┐
80
+ │ Governance Layer │
81
+ │ Policy engine · Compliance matrix · Chain-hashed audit trail │
82
+ │ Adversarial review · Finding consensus · Cost tracking (SQLite)│
83
+ └──────────────────────────┬──────────────────────────────────────┘
84
+
85
+ ┌──────────────────────────▼──────────────────────────────────────┐
86
+ │ Output Layer │
87
+ │ Rich streaming · Markdown detection · Footer · Budget display │
88
+ │ NO_COLOR support · Pipe detection · Onboarding tips │
89
+ └─────────────────────────────────────────────────────────────────┘
90
+ ```
91
+
92
+ ## Commands
93
+
94
+ | Command | Description |
95
+ |---------|-------------|
96
+ | `mdx "task"` | Execute via best available backend |
97
+ | `mdx "task" --pick` | Interactively pick a backend |
98
+ | `mdx "task" --backend claude` | Force a specific backend |
99
+ | `mdx "task" --strategy cost` | Override routing strategy |
100
+ | `mdx review src/` | Adversarial multi-model review |
101
+ | `mdx review --last` | Review last change MDx made |
102
+ | `mdx review --diff HEAD~1` | Review a git diff |
103
+ | `mdx cost` | Spending dashboard |
104
+ | `mdx cost --week` | Weekly cost breakdown |
105
+ | `mdx audit` | Audit trail history |
106
+ | `mdx audit --verify` | Verify audit chain integrity |
107
+ | `mdx audit --stats` | Audit summary statistics |
108
+ | `mdx history` | Recent task history |
109
+ | `mdx summary` | Today's AI coding summary |
110
+ | `mdx setup` | Detect available backends |
111
+ | `mdx status` | Backend health and circuit breakers |
112
+ | `mdx policy` | View active policies |
113
+ | `mdx policy init` | Create starter .mdxpolicy |
114
+ | `mdx policy check <files>` | Check files against policies |
115
+ | `mdx compliance` | Regulatory compliance matrix |
116
+ | `mdx hook install` | Git pre-commit hook |
117
+ | `mdx replay` | Replay last task output |
118
+ | `mdx undo` | Revert last backend change |
119
+ | `mdx mcp status` | MCP server availability |
120
+ | `mdx mcp config` | Generate MCP client config |
121
+ | `mdx install-completion` | Shell tab-completion |
122
+
123
+ ## How It Works
124
+
125
+ MDx Code does **not** run its own agent loop. It spawns real AI coding CLIs (`claude`, `codex`, `gemini`) as subprocesses, streams their output in real-time, and wraps everything with orchestration: smart routing, cost tracking, governance policies, and an immutable audit trail.
126
+
127
+ Every task execution flows through:
128
+ 1. **Categorize** — Keyword-based task classification (no LLM call)
129
+ 2. **Route** — Score backends using the selected strategy
130
+ 3. **Execute** — Spawn the CLI subprocess and stream output
131
+ 4. **Track** — Record cost (SQLite) and audit entry (chain-hashed JSONL)
132
+ 5. **Govern** — Evaluate policies and recommend review if triggered
133
+
134
+ ## Key Features
135
+
136
+ - **Multi-backend routing** — Routes tasks to the best available CLI based on cost, quality, or balanced strategies
137
+ - **Adversarial review** — Run code through multiple models and cross-validate findings with consensus scoring
138
+ - **Governance policies** — Define per-path rules for review requirements, approval gates, and minimum reviewers
139
+ - **Cost tracking** — Token and dollar spend across all backends with savings analysis and budget guardrails
140
+ - **Audit trail** — Immutable, chain-hashed JSONL logs with SHA-256 integrity verification
141
+ - **Compliance** — Maps features to SOC 2, HIPAA, SOX, and OSFI regulatory frameworks
142
+ - **MCP servers** — Expose governance, audit, and cost data to MCP-compatible clients
143
+ - **Circuit breakers** — Automatic fallback when a backend is unhealthy (closed → open → half-open)
144
+
145
+ ## Routing Strategies
146
+
147
+ | Strategy | When to Use | How It Works |
148
+ |----------|-------------|--------------|
149
+ | `balanced` | Default. Best all-around. | Scores backends on quality × strength / relative cost |
150
+ | `quality` | Critical code, security-sensitive | Always picks highest-quality backend |
151
+ | `cost` | Bulk tasks, experiments | Picks cheapest available backend |
152
+
153
+ See [docs/routing.md](docs/routing.md) for details on backend profiles, scoring formulas, and circuit breakers.
154
+
155
+ ## Performance
156
+
157
+ | Metric | Value |
158
+ |--------|-------|
159
+ | Cold start | 20ms (20x improvement from lazy imports) |
160
+ | Config loading | < 1ms (module-level cache) |
161
+ | Routing decision | 0.1ms |
162
+ | Total wrapper overhead | < 200ms |
163
+
164
+ The footer displays before async I/O writes (audit, cost tracking) complete — the user never waits for bookkeeping.
165
+
166
+ ## Governance & Compliance
167
+
168
+ Define policies in `.mdxpolicy` to enforce review requirements per path:
169
+
170
+ ```yaml
171
+ policies:
172
+ - name: auth-critical
173
+ paths: ["src/auth/**", "src/security/**"]
174
+ requires:
175
+ adversarial_review: true
176
+ human_approval: true
177
+ severity: critical
178
+ ```
179
+
180
+ MDx Code maps its features to regulatory frameworks:
181
+
182
+ | Framework | Coverage |
183
+ |-----------|----------|
184
+ | SOC 2 | Audit trail, access logging, change tracking |
185
+ | HIPAA | Audit controls, integrity verification |
186
+ | SOX | Approval workflows, immutable records |
187
+ | OSFI B-13 | Model provenance, technology risk controls |
188
+
189
+ Run `mdx compliance` to see the full compliance matrix.
190
+
191
+ ## Configuration
192
+
193
+ MDx Code supports three levels of configuration:
194
+
195
+ - **Global** — `~/.mdx/config.yaml` (routing strategy, budgets, display)
196
+ - **Project** — `.mdx.yaml` in repo root (overrides global for this project)
197
+ - **Governance** — `.mdxpolicy` in repo root (policy rules)
198
+
199
+ See [docs/configuration.md](docs/configuration.md) for all fields and example configs.
200
+
201
+ ## MCP Integration
202
+
203
+ MDx Code ships three MCP servers for integration with AI coding tools:
204
+
205
+ - **Governance server** — Policy checking and compliance data
206
+ - **Audit server** — Audit trail access and verification
207
+ - **Cost server** — Spending data and budget status
208
+
209
+ See [docs/mcp-setup.md](docs/mcp-setup.md) for setup instructions.
210
+
211
+ ## Requirements
212
+
213
+ - Python 3.11+
214
+ - At least one AI coding CLI:
215
+ - [Claude Code](https://github.com/anthropics/claude-code)
216
+ - [Codex CLI](https://github.com/openai/codex)
217
+ - [Gemini CLI](https://github.com/google-gemini/gemini-cli)
218
+
219
+ ## Contributing
220
+
221
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for development setup, code style, and PR process.
222
+
223
+ ## Security
224
+
225
+ See [SECURITY.md](SECURITY.md) for vulnerability reporting and security policy.
226
+
227
+ ## License
228
+
229
+ [MIT](LICENSE)
@@ -0,0 +1 @@
1
+ """MDx Code MCP servers — governance, audit, and cost tracking."""
@@ -0,0 +1 @@
1
+ """Audit MCP server — immutable audit trail access."""