contextos-mcp 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (223) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +260 -0
  3. package/bin/mcp.mjs +61 -0
  4. package/bin/swarm.mjs +45 -0
  5. package/dist/agents/aider.d.ts +12 -0
  6. package/dist/agents/aider.js +192 -0
  7. package/dist/agents/aider.js.map +1 -0
  8. package/dist/agents/claude-code.d.ts +9 -0
  9. package/dist/agents/claude-code.js +236 -0
  10. package/dist/agents/claude-code.js.map +1 -0
  11. package/dist/agents/codex.d.ts +14 -0
  12. package/dist/agents/codex.js +203 -0
  13. package/dist/agents/codex.js.map +1 -0
  14. package/dist/agents/direct-llm.d.ts +22 -0
  15. package/dist/agents/direct-llm.js +254 -0
  16. package/dist/agents/direct-llm.js.map +1 -0
  17. package/dist/agents/mock.d.ts +10 -0
  18. package/dist/agents/mock.js +170 -0
  19. package/dist/agents/mock.js.map +1 -0
  20. package/dist/agents/opencode.d.ts +23 -0
  21. package/dist/agents/opencode.js +631 -0
  22. package/dist/agents/opencode.js.map +1 -0
  23. package/dist/agents/provider.d.ts +11 -0
  24. package/dist/agents/provider.js +31 -0
  25. package/dist/agents/provider.js.map +1 -0
  26. package/dist/compression/compressor.d.ts +28 -0
  27. package/dist/compression/compressor.js +268 -0
  28. package/dist/compression/compressor.js.map +1 -0
  29. package/dist/config.d.ts +43 -0
  30. package/dist/config.js +172 -0
  31. package/dist/config.js.map +1 -0
  32. package/dist/contextos/loader.d.ts +46 -0
  33. package/dist/contextos/loader.js +120 -0
  34. package/dist/contextos/loader.js.map +1 -0
  35. package/dist/contextos/selector.d.ts +46 -0
  36. package/dist/contextos/selector.js +80 -0
  37. package/dist/contextos/selector.js.map +1 -0
  38. package/dist/core/action-dispatcher.d.ts +15 -0
  39. package/dist/core/action-dispatcher.js +28 -0
  40. package/dist/core/action-dispatcher.js.map +1 -0
  41. package/dist/core/action-schema.d.ts +72 -0
  42. package/dist/core/action-schema.js +86 -0
  43. package/dist/core/action-schema.js.map +1 -0
  44. package/dist/core/repl-interface.d.ts +48 -0
  45. package/dist/core/repl-interface.js +5 -0
  46. package/dist/core/repl-interface.js.map +1 -0
  47. package/dist/core/repl.d.ts +59 -0
  48. package/dist/core/repl.js +353 -0
  49. package/dist/core/repl.js.map +1 -0
  50. package/dist/core/rlm.d.ts +65 -0
  51. package/dist/core/rlm.js +564 -0
  52. package/dist/core/rlm.js.map +1 -0
  53. package/dist/core/runtime.py +470 -0
  54. package/dist/core/types.d.ts +265 -0
  55. package/dist/core/types.js +19 -0
  56. package/dist/core/types.js.map +1 -0
  57. package/dist/env.d.ts +10 -0
  58. package/dist/env.js +75 -0
  59. package/dist/env.js.map +1 -0
  60. package/dist/hooks/runner.d.ts +43 -0
  61. package/dist/hooks/runner.js +173 -0
  62. package/dist/hooks/runner.js.map +1 -0
  63. package/dist/labs/cli.d.ts +15 -0
  64. package/dist/labs/cli.js +295 -0
  65. package/dist/labs/cli.js.map +1 -0
  66. package/dist/labs/episodic-memory.d.ts +132 -0
  67. package/dist/labs/episodic-memory.js +391 -0
  68. package/dist/labs/episodic-memory.js.map +1 -0
  69. package/dist/labs/interactive-swarm.d.ts +20 -0
  70. package/dist/labs/interactive-swarm.js +1173 -0
  71. package/dist/labs/interactive-swarm.js.map +1 -0
  72. package/dist/labs/interactive.d.ts +10 -0
  73. package/dist/labs/interactive.js +2099 -0
  74. package/dist/labs/interactive.js.map +1 -0
  75. package/dist/labs/ts-analyzer.d.ts +74 -0
  76. package/dist/labs/ts-analyzer.js +379 -0
  77. package/dist/labs/ts-analyzer.js.map +1 -0
  78. package/dist/labs/viewer.d.ts +12 -0
  79. package/dist/labs/viewer.js +1284 -0
  80. package/dist/labs/viewer.js.map +1 -0
  81. package/dist/main.d.ts +15 -0
  82. package/dist/main.js +247 -0
  83. package/dist/main.js.map +1 -0
  84. package/dist/mcp/server.d.ts +16 -0
  85. package/dist/mcp/server.js +192775 -0
  86. package/dist/mcp/server.js.map +1 -0
  87. package/dist/mcp/session.d.ts +117 -0
  88. package/dist/mcp/session.js +450 -0
  89. package/dist/mcp/session.js.map +1 -0
  90. package/dist/mcp/state.d.ts +42 -0
  91. package/dist/mcp/state.js +537 -0
  92. package/dist/mcp/state.js.map +1 -0
  93. package/dist/mcp/tools/contextos.d.ts +17 -0
  94. package/dist/mcp/tools/contextos.js +583 -0
  95. package/dist/mcp/tools/contextos.js.map +1 -0
  96. package/dist/mcp/tools.d.ts +15 -0
  97. package/dist/mcp/tools.js +393 -0
  98. package/dist/mcp/tools.js.map +1 -0
  99. package/dist/orchestration/reviewer-gate.d.ts +43 -0
  100. package/dist/orchestration/reviewer-gate.js +280 -0
  101. package/dist/orchestration/reviewer-gate.js.map +1 -0
  102. package/dist/orchestration/reviewer-prompt.d.ts +18 -0
  103. package/dist/orchestration/reviewer-prompt.js +67 -0
  104. package/dist/orchestration/reviewer-prompt.js.map +1 -0
  105. package/dist/orchestration/verification-runner.d.ts +53 -0
  106. package/dist/orchestration/verification-runner.js +352 -0
  107. package/dist/orchestration/verification-runner.js.map +1 -0
  108. package/dist/plugins/adapter.d.ts +11 -0
  109. package/dist/plugins/adapter.js +11 -0
  110. package/dist/plugins/adapter.js.map +1 -0
  111. package/dist/plugins/core/archive.d.ts +9 -0
  112. package/dist/plugins/core/archive.js +128 -0
  113. package/dist/plugins/core/archive.js.map +1 -0
  114. package/dist/plugins/core/digest.d.ts +11 -0
  115. package/dist/plugins/core/digest.js +70 -0
  116. package/dist/plugins/core/digest.js.map +1 -0
  117. package/dist/plugins/core/grants.d.ts +22 -0
  118. package/dist/plugins/core/grants.js +90 -0
  119. package/dist/plugins/core/grants.js.map +1 -0
  120. package/dist/plugins/core/index.d.ts +10 -0
  121. package/dist/plugins/core/index.js +11 -0
  122. package/dist/plugins/core/index.js.map +1 -0
  123. package/dist/plugins/core/pinning.d.ts +15 -0
  124. package/dist/plugins/core/pinning.js +86 -0
  125. package/dist/plugins/core/pinning.js.map +1 -0
  126. package/dist/plugins/core/types.d.ts +105 -0
  127. package/dist/plugins/core/types.js +22 -0
  128. package/dist/plugins/core/types.js.map +1 -0
  129. package/dist/plugins/core/updater.d.ts +16 -0
  130. package/dist/plugins/core/updater.js +64 -0
  131. package/dist/plugins/core/updater.js.map +1 -0
  132. package/dist/plugins/loader.d.ts +65 -0
  133. package/dist/plugins/loader.js +110 -0
  134. package/dist/plugins/loader.js.map +1 -0
  135. package/dist/prompts/orchestrator.d.ts +6 -0
  136. package/dist/prompts/orchestrator.js +114 -0
  137. package/dist/prompts/orchestrator.js.map +1 -0
  138. package/dist/routing/model-resolver.d.ts +27 -0
  139. package/dist/routing/model-resolver.js +265 -0
  140. package/dist/routing/model-resolver.js.map +1 -0
  141. package/dist/routing/model-router.d.ts +130 -0
  142. package/dist/routing/model-router.js +515 -0
  143. package/dist/routing/model-router.js.map +1 -0
  144. package/dist/runtime/attestations.cjs +260 -0
  145. package/dist/runtime/reviewer-pipeline.cjs +319 -0
  146. package/dist/runtime/sandbox.cjs +468 -0
  147. package/dist/runtime/state-machine.cjs +885 -0
  148. package/dist/runtime/thread-store.cjs +175 -0
  149. package/dist/runtime/transactional-git.cjs +315 -0
  150. package/dist/runtime/verification-pipeline.cjs +435 -0
  151. package/dist/sandbox/execution.d.ts +165 -0
  152. package/dist/sandbox/execution.js +497 -0
  153. package/dist/sandbox/execution.js.map +1 -0
  154. package/dist/security/file-policy.d.ts +22 -0
  155. package/dist/security/file-policy.js +53 -0
  156. package/dist/security/file-policy.js.map +1 -0
  157. package/dist/security/repository-boundary.d.ts +21 -0
  158. package/dist/security/repository-boundary.js +119 -0
  159. package/dist/security/repository-boundary.js.map +1 -0
  160. package/dist/security/secret-filter.d.ts +36 -0
  161. package/dist/security/secret-filter.js +149 -0
  162. package/dist/security/secret-filter.js.map +1 -0
  163. package/dist/swarm.d.ts +14 -0
  164. package/dist/swarm.js +624 -0
  165. package/dist/swarm.js.map +1 -0
  166. package/dist/threads/cache.d.ts +64 -0
  167. package/dist/threads/cache.js +241 -0
  168. package/dist/threads/cache.js.map +1 -0
  169. package/dist/threads/manager.d.ts +94 -0
  170. package/dist/threads/manager.js +914 -0
  171. package/dist/threads/manager.js.map +1 -0
  172. package/dist/ui/banner.d.ts +14 -0
  173. package/dist/ui/banner.js +42 -0
  174. package/dist/ui/banner.js.map +1 -0
  175. package/dist/ui/dashboard.d.ts +33 -0
  176. package/dist/ui/dashboard.js +135 -0
  177. package/dist/ui/dashboard.js.map +1 -0
  178. package/dist/ui/index.d.ts +11 -0
  179. package/dist/ui/index.js +12 -0
  180. package/dist/ui/index.js.map +1 -0
  181. package/dist/ui/log.d.ts +39 -0
  182. package/dist/ui/log.js +126 -0
  183. package/dist/ui/log.js.map +1 -0
  184. package/dist/ui/onboarding.d.ts +14 -0
  185. package/dist/ui/onboarding.js +755 -0
  186. package/dist/ui/onboarding.js.map +1 -0
  187. package/dist/ui/run-log.d.ts +50 -0
  188. package/dist/ui/run-log.js +60 -0
  189. package/dist/ui/run-log.js.map +1 -0
  190. package/dist/ui/spinner.d.ts +41 -0
  191. package/dist/ui/spinner.js +172 -0
  192. package/dist/ui/spinner.js.map +1 -0
  193. package/dist/ui/streaming-feed.d.ts +72 -0
  194. package/dist/ui/streaming-feed.js +386 -0
  195. package/dist/ui/streaming-feed.js.map +1 -0
  196. package/dist/ui/summary.d.ts +18 -0
  197. package/dist/ui/summary.js +113 -0
  198. package/dist/ui/summary.js.map +1 -0
  199. package/dist/ui/text-input.d.ts +19 -0
  200. package/dist/ui/text-input.js +266 -0
  201. package/dist/ui/text-input.js.map +1 -0
  202. package/dist/ui/theme.d.ts +63 -0
  203. package/dist/ui/theme.js +97 -0
  204. package/dist/ui/theme.js.map +1 -0
  205. package/dist/utils/command-exists.d.ts +11 -0
  206. package/dist/utils/command-exists.js +41 -0
  207. package/dist/utils/command-exists.js.map +1 -0
  208. package/dist/utils/process-security.d.ts +19 -0
  209. package/dist/utils/process-security.js +90 -0
  210. package/dist/utils/process-security.js.map +1 -0
  211. package/dist/utils/rolling-buffer.d.ts +16 -0
  212. package/dist/utils/rolling-buffer.js +30 -0
  213. package/dist/utils/rolling-buffer.js.map +1 -0
  214. package/dist/utils/safe-spawn.d.ts +13 -0
  215. package/dist/utils/safe-spawn.js +49 -0
  216. package/dist/utils/safe-spawn.js.map +1 -0
  217. package/dist/worktree/manager.d.ts +69 -0
  218. package/dist/worktree/manager.js +593 -0
  219. package/dist/worktree/manager.js.map +1 -0
  220. package/dist/worktree/merge.d.ts +58 -0
  221. package/dist/worktree/merge.js +389 -0
  222. package/dist/worktree/merge.js.map +1 -0
  223. package/package.json +63 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025-2026 Vipul Maheshwari
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.
package/README.md ADDED
@@ -0,0 +1,260 @@
1
+ # ContextOS MCP Server
2
+
3
+ MCP integration for [ContextOS](https://github.com/kok-o/contextos-agents).
4
+ The 0.4.0 candidate exposes read-only status, comparison and diff inspection by
5
+ default. Inspection does not create agents, worktrees or runtime sessions.
6
+
7
+ The supported package entrypoint is the `contextos-mcp` executable; a root
8
+ JavaScript library import is not a supported interface.
9
+
10
+ ## Stable and experimental scope
11
+
12
+ - Default MCP registration and read-only handlers are covered by protocol and
13
+ installed-archive tests on Windows, Linux and macOS.
14
+ - Selected context bodies are preserved whole, with source hashes, omissions and
15
+ budget-overflow reporting. Soft limits do not truncate safety instructions.
16
+ - Agent execution, asynchronous delegation, worktree merging/cleanup, Python REPL
17
+ and runtime persistence/recovery require explicit `--enable-runtime` opt-in.
18
+ They remain experimental; seven skipped execution/recovery/concurrency cases
19
+ prevent a stable support claim for those scenarios.
20
+ - Worktrees provide Git isolation. Processes still have host-user privileges;
21
+ this is not an operating-system sandbox or proof of production security.
22
+
23
+ See the [support boundaries](https://github.com/kok-o/contextos-agents/blob/main/docs/PRODUCT_BOUNDARIES.md)
24
+ and [skipped-test inventory](https://github.com/kok-o/contextos-agents/blob/main/docs/MCP_SKIPPED_TESTS.md).
25
+
26
+ ## Security & Execution Model
27
+
28
+ The ContextOS MCP execution runtime applies strict defense-in-depth isolation across all supported subagent backends:
29
+
30
+ - **Isolated Git Worktrees (`.swarm-worktrees/`):** Every subagent operates in a private git worktree branch (`swarm/<threadId>`). The developer's primary workspace and active staging area cannot be altered or reset during subagent execution.
31
+ - **Headless CLI Execution & `--dangerously-skip-permissions`:**
32
+ - Non-interactive agents (like Claude Code) execute with `--dangerously-skip-permissions` to allow headless autonomous editing without interactive user prompts.
33
+ - **Trust Boundary & Isolation Details:**
34
+ 1. **Workspace & Branch Protection:** Subagents operate in dedicated Git worktree branches (`swarm/<threadId>`), preventing race conditions and keeping the user's primary working directory clean;
35
+ 2. **Pre-Commit File Filtering:** Changed files are filtered before git staging (`isBlockedPath`, `isPathAllowed`), preventing commits of sensitive files (`.env`, SSH keys, `.git`);
36
+ 3. **Environment Sanitization:** Child processes receive an allowlisted environment (`getSanitizedEnv`) to prevent accidental token propagation;
37
+ 4. **OS-Level Isolation Notice:** Subagent processes run under host user privileges. Git worktrees and pre-commit checks provide version control safety, not kernel-level OS sandboxing. For multi-tenant or untrusted agent workflows, ContextOS must be paired with an OS-level container (Docker/Podman) or OS sandbox (e.g. bubblewrap / seatbelt).
38
+ - **Python Sandbox Restrictions:** The embedded Python REPL (`runtime.py`) enforces strict AST validation, forbids dangerous dunder attributes (`__subclasses__`, `__globals__`, `__reduce__`), restricts module imports to safe standard libraries (`json`, `math`, `re`, `datetime`, `random`, `collections`), and blocks dynamic class creation via 3-argument `type()`.
39
+ - **Egress Secret Redaction:** All output channels (episodic memory, compression diffs, MCP error messages, direct LLM prompts) pass through `SecretFilter` (`redactSecrets`) to redact API keys and tokens.
40
+ - **Safe Verification & Non-Destructive Merges:**
41
+ - `verify_command` enforces a strict whitelist of verification binaries (`npm`, `pytest`, `cargo`, `go`, etc.), sanitizes environment variables, and rejects shell metacharacters and operator chaining (`&&`, `;`, `|`).
42
+ - Merge failures invoke `git merge --abort` and strictly forbid destructive commands like `git reset --hard HEAD` in the user's workspace.
43
+
44
+ ---
45
+
46
+ ## Usage
47
+
48
+ ### MCP Server (Primary Interface)
49
+
50
+ The MCP server is the primary way to use ContextOS MCP. It exposes tools for Claude Code, Antigravity, Cursor, or any MCP-compatible agent:
51
+
52
+ ```bash
53
+ npx contextos-mcp
54
+ npx contextos-mcp --dir ./my-project
55
+ ```
56
+
57
+ **Tools exposed (`contextos_*`):**
58
+
59
+ | Tool | Description |
60
+ |------|-------------|
61
+ | `contextos_delegate` | Delegate task(s) to isolated git worktree agents with automatic skill selection, secret filtering, and proof-of-work verification |
62
+ | `contextos_status` | Query active task lifecycle, thread states, verification results, and token costs |
63
+ | `contextos_compare` | Benchmark and compare competing candidate thread solutions (tests, tokens, diff size) |
64
+ | `contextos_diff` | Inspect the clean, structured Git diff produced by a thread before deciding to merge |
65
+ | `contextos_merge` | Perform a safe 3-way Git merge with conflict detection and non-destructive rollback |
66
+ | `contextos_cleanup` | Clean up active worktree sessions or safely purge orphaned `swarm/*` branches |
67
+
68
+ **IDE / MCP Client Setup (Claude Code, Antigravity, Cursor):**
69
+
70
+ Add to your project's `.mcp.json` or MCP settings:
71
+
72
+ ```json
73
+ {
74
+ "mcpServers": {
75
+ "contextos": {
76
+ "command": "npx",
77
+ "args": ["-y", "contextos-mcp", "--dir", "."],
78
+ "env": {
79
+ "ANTHROPIC_API_KEY": "${ANTHROPIC_API_KEY}",
80
+ "OPENAI_API_KEY": "${OPENAI_API_KEY}"
81
+ }
82
+ }
83
+ }
84
+ }
85
+ ```
86
+
87
+ Once configured, your host orchestrator can invoke `contextos_delegate` to spawn subagents, inspect progress with `contextos_status` and `contextos_diff`, and safely integrate changes with `contextos_merge`.
88
+
89
+ ### Supported Providers
90
+
91
+ | Provider | Env Variable | Default Model |
92
+ |----------|-------------|---------------|
93
+ | **Anthropic** | `ANTHROPIC_API_KEY` | `claude-sonnet-4-6` |
94
+ | **OpenAI** | `OPENAI_API_KEY` | `gpt-4o` |
95
+ | **Google** | `GEMINI_API_KEY` | `gemini-2.5-flash` |
96
+ | **OpenRouter** | `OPENROUTER_API_KEY` | (configurable) |
97
+ | **Groq** | `GROQ_API_KEY` | (configurable) |
98
+ | **Ollama** | *(local)* | (configurable) |
99
+
100
+ ### Agent Backends
101
+
102
+ | Agent | Description | Best for |
103
+ |-------|------------|----------|
104
+ | `opencode` (default) | Open-source, multi-provider, tool-capable | General coding, testing |
105
+ | `claude-code` | Anthropic's Claude Code CLI | Deep analysis, refactoring |
106
+ | `codex` | OpenAI's Codex CLI | Shell commands, OpenAI models |
107
+ | `aider` | Git-aware AI coding assistant | Targeted edits, minimal changes |
108
+ | `direct-llm` | Bare LLM call, no agent wrapper | Analysis, planning, classification |
109
+
110
+ ### Swarm Mode — Parallel Coding Agents
111
+
112
+ Point the CLI at a repo with a task. It scans the codebase, decomposes the work, and spawns coding agents in isolated git worktrees:
113
+
114
+ ```bash
115
+ npx contextos-mcp swarm --dir ./my-project "add error handling to all API routes"
116
+ ```
117
+
118
+ The orchestrator LLM writes code that calls `thread()` to spawn agents and `merge_threads()` to integrate changes:
119
+
120
+ ```bash
121
+ # Dry run — plan without executing
122
+ npx contextos-mcp swarm --dir ./project --dry-run "refactor auth module"
123
+
124
+ # Budget cap
125
+ npx contextos-mcp swarm --dir ./project --max-budget 5.00 "add comprehensive tests"
126
+
127
+ # Specific agent backend
128
+ npx contextos-mcp swarm --dir ./project --agent claude-code "review and fix security issues"
129
+ ```
130
+
131
+ ### Interactive Mode
132
+
133
+ Run with `--dir` but no task to enter interactive mode — a persistent REPL with live thread monitoring:
134
+
135
+ ```bash
136
+ npx contextos-mcp interactive --dir ./my-project
137
+ ```
138
+
139
+ Commands:
140
+
141
+ | Command | Description |
142
+ |---------|-------------|
143
+ | `/threads` | List all threads with status, cost, duration |
144
+ | `/thread <id>` | Show thread detail (files changed, diff, result) |
145
+ | `/merge` | Merge all completed thread branches |
146
+ | `/reject <id>` | Reject a thread's changes |
147
+ | `/dag` | Show thread DAG with timing bars |
148
+ | `/budget` | Show budget breakdown |
149
+ | `/status` | Show session stats |
150
+ | `/help` | List commands |
151
+ | `/quit` | Cleanup and exit |
152
+
153
+ ### Orchestrator Primitives
154
+
155
+ The RLM orchestrator executes JavaScript/TypeScript code (or Python via `--python-repl` fallback) using these primitives:
156
+
157
+ ```javascript
158
+ // Lightweight LLM query (no file changes)
159
+ const analysis = await llm_query(context.slice(0, 5000), "List all API endpoints");
160
+
161
+ // Spawn a coding agent in an isolated worktree
162
+ const result = await thread("Fix the auth bug", { files: ["src/auth.ts"] });
163
+
164
+ // Parallel threads
165
+ const [users, orders] = await Promise.all([
166
+ thread("Add validation to POST /users", { files: ["src/routes/users.ts"] }),
167
+ thread("Add validation to POST /orders", { files: ["src/routes/orders.ts"] }),
168
+ ]);
169
+
170
+ // Merge all thread branches back to main
171
+ await merge_threads();
172
+
173
+ // Return final answer
174
+ FINAL("Added input validation to all API routes");
175
+ ```
176
+
177
+ > **Note:** Python 3 is no longer required. The default execution engine uses a native `node:vm` sandbox (`NodeVmRepl`). Pass `--python-repl` or `--repl python` to use the legacy Python runtime.
178
+
179
+ ## How It Works
180
+
181
+ 1. **Scan**: Codebase is scanned and loaded as context
182
+ 2. **Orchestrate**: The RLM loop runs — the LLM writes orchestrator code using swarm primitives
183
+ 3. **Decompose**: Tasks are broken into independent, parallelizable units
184
+ 4. **Spawn**: `thread()` spawns coding agents in isolated git worktrees
185
+ 5. **Compress**: Agent output is filtered to successful operations only (episode quality)
186
+ 6. **Merge**: `merge_threads()` integrates worktree branches back to main
187
+ 7. **Verify**: Optional test thread validates the merged result
188
+
189
+ ## Configuration
190
+
191
+ Create `swarm_config.yaml` in your project root:
192
+
193
+ ```yaml
194
+ # Concurrency
195
+ max_threads: 5 # Max concurrent threads
196
+ max_total_threads: 20 # Max threads per session
197
+ thread_timeout_ms: 300000 # 5min per thread
198
+
199
+ # Budget
200
+ max_thread_budget_usd: 1.00 # Per-thread cost cap
201
+ max_session_budget_usd: 10.00 # Total session cost cap
202
+
203
+ # Agent
204
+ default_agent: opencode # opencode, claude-code, codex, aider, direct-llm
205
+ default_model: anthropic/claude-sonnet-4-6
206
+
207
+ # Compression
208
+ compression_strategy: structured # structured, diff-only, truncate, llm-summary
209
+ ```
210
+
211
+ ## Architecture
212
+
213
+ ```
214
+ src/
215
+ ├── main.ts CLI entry point
216
+ ├── swarm.ts Swarm orchestration (single-shot)
217
+ ├── interactive-swarm.ts Interactive REPL with live monitoring
218
+ ├── cli.ts RLM text mode
219
+ ├── core/
220
+ │ ├── rlm.ts Core RLM loop (Algorithm 1)
221
+ │ ├── repl.ts Python REPL bridge (legacy fallback)
222
+ │ ├── node-repl.ts Native node:vm sandbox (default)
223
+ │ ├── repl-interface.ts Common Repl interface
224
+ │ ├── runtime.py Python runtime (legacy fallback)
225
+ │ └── types.ts Shared type definitions
226
+ ├── agents/ Agent backend implementations
227
+ ├── threads/ Thread lifecycle + caching
228
+ ├── worktree/ Git worktree CRUD + merging
229
+ ├── compression/ Result compression strategies
230
+ ├── routing/ Auto model/agent selection
231
+ ├── memory/ Cross-session strategy learning
232
+ ├── prompts/ Orchestrator system prompts
233
+ ├── mcp/ MCP server (stdio transport)
234
+ ├── ui/ CLI UI (onboarding, spinner, dashboard)
235
+ └── viewer.ts Trajectory TUI + DAG viewer
236
+ ```
237
+
238
+ ## Development
239
+
240
+ ```bash
241
+ npm install # Install deps
242
+ npx tsx src/main.ts --dir . # Run in dev mode
243
+ npm run build # Compile TypeScript
244
+ npm test # Run tests
245
+ ```
246
+
247
+ ---
248
+
249
+ ## Attribution
250
+
251
+ The MCP execution layer is derived from [swarm-code](https://github.com/kingjulio8238/swarm-code) by [@kingjulio8238](https://github.com/kingjulio8238), based on the Recursive Language Model ([arXiv:2512.24601](https://arxiv.org/abs/2512.24601)), licensed under MIT. ContextOS extends it with:
252
+
253
+ - Native TypeScript `node:vm` sandbox (no Python 3 dependency)
254
+ - Dynamic context-aware skill loading from `.agents/` directory
255
+ - Security hardening (secret filtering, path traversal blocking, prompt injection scanning)
256
+ - Multi-provider support (Anthropic, OpenAI, Google, OpenRouter, Groq, Ollama)
257
+
258
+ ## License
259
+
260
+ MIT
package/bin/mcp.mjs ADDED
@@ -0,0 +1,61 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * contextos-mcp - ContextOS Execution Layer and MCP Server CLI
5
+ *
6
+ * This binary directly boots the ContextOS MCP server via stdio transport.
7
+ * It targets compiled dist/mcp/server.js in production, falling back to
8
+ * src/mcp/server.ts with tsx in local development.
9
+ */
10
+
11
+ import { existsSync, readFileSync } from "node:fs";
12
+ import { dirname, join } from "node:path";
13
+ import { fileURLToPath, pathToFileURL } from "node:url";
14
+
15
+ const __dirname = dirname(fileURLToPath(import.meta.url));
16
+ const distServer = join(__dirname, "..", "dist", "mcp", "server.js");
17
+
18
+ if (process.argv.includes("--version") || process.argv.includes("-v")) {
19
+ const pkg = JSON.parse(readFileSync(join(__dirname, "..", "package.json"), "utf8"));
20
+ console.log(pkg.version);
21
+ process.exit(0);
22
+ }
23
+
24
+ if (process.argv.includes("--help") || process.argv.includes("-h")) {
25
+ console.log(`
26
+ contextos-mcp - ContextOS Execution Layer and MCP Server CLI
27
+
28
+ Usage:
29
+ contextos-mcp [options]
30
+
31
+ Options:
32
+ --dir <path> Target repository directory (default: current working directory)
33
+ --version, -v Show version number
34
+ --help, -h Show this help message
35
+ `);
36
+ process.exit(0);
37
+ }
38
+
39
+ if (existsSync(distServer)) {
40
+ try {
41
+ const mod = await import(pathToFileURL(distServer).href);
42
+ if (typeof mod.startMcpServer === "function") {
43
+ await mod.startMcpServer(process.argv.slice(2));
44
+ }
45
+ } catch (err) {
46
+ process.stderr.write(`[contextos-mcp] Startup error: ${err}\n`);
47
+ process.exit(1);
48
+ }
49
+ } else {
50
+ const srcServer = join(__dirname, "..", "src", "mcp", "server.ts");
51
+ const { spawn } = await import("node:child_process");
52
+ const tsxCli = join(__dirname, "..", "node_modules", "tsx", "dist", "cli.mjs");
53
+ const child = spawn(process.execPath, [tsxCli, srcServer, ...process.argv.slice(2)], {
54
+ stdio: "inherit",
55
+ });
56
+ child.on("exit", (code) => process.exit(code ?? 1));
57
+ child.on("error", (err) => {
58
+ process.stderr.write(`[contextos-mcp] Failed to start tsx: ${err.message}\n`);
59
+ process.exit(1);
60
+ });
61
+ }
package/bin/swarm.mjs ADDED
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * swarm — Swarm-Native Coding Agent CLI
5
+ *
6
+ * This shim boots the CLI entry point. It tries the compiled dist first,
7
+ * then falls back to tsx for development.
8
+ */
9
+
10
+ import { existsSync } from "node:fs";
11
+ import { dirname, join } from "node:path";
12
+ import { fileURLToPath, pathToFileURL } from "node:url";
13
+
14
+ const __dirname = dirname(fileURLToPath(import.meta.url));
15
+ const distEntry = join(__dirname, "..", "dist", "main.js");
16
+
17
+ if (existsSync(distEntry)) {
18
+ // Production: use compiled JS (pathToFileURL needed for Windows)
19
+ await import(pathToFileURL(distEntry).href);
20
+ } else {
21
+ // Development: use tsx to run TypeScript directly
22
+ const srcEntry = join(__dirname, "..", "src", "main.ts");
23
+ const { register } = await import("node:module");
24
+
25
+ // Try to register tsx loader, then import
26
+ try {
27
+ const tsxPath = join(__dirname, "..", "node_modules", "tsx", "dist", "esm", "index.mjs");
28
+ if (existsSync(tsxPath)) {
29
+ register(pathToFileURL(tsxPath).href);
30
+ }
31
+ await import(pathToFileURL(srcEntry).href);
32
+ } catch {
33
+ // Fallback: spawn tsx as a child process
34
+ const { spawn } = await import("node:child_process");
35
+ const tsxBin = join(__dirname, "..", "node_modules", ".bin", "tsx");
36
+ const child = spawn(tsxBin, [srcEntry, ...process.argv.slice(2)], {
37
+ stdio: "inherit",
38
+ });
39
+ child.on("exit", (code) => process.exit(code ?? 1));
40
+ child.on("error", (err) => {
41
+ console.error(`Failed to start swarm: ${err.message}`);
42
+ process.exit(1);
43
+ });
44
+ }
45
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Aider agent backend.
3
+ *
4
+ * Runs tasks via `aider --yes-always --no-auto-commits --message "prompt"` subprocess.
5
+ * Aider is a git-aware AI coding assistant that makes targeted edits.
6
+ *
7
+ * Output format: Plain text (no JSON mode available).
8
+ * Edit confirmations appear as "Applied edit to <file>" lines.
9
+ */
10
+ import type { AgentProvider } from "../core/types.js";
11
+ declare const aiderProvider: AgentProvider;
12
+ export default aiderProvider;
@@ -0,0 +1,192 @@
1
+ /**
2
+ * Aider agent backend.
3
+ *
4
+ * Runs tasks via `aider --yes-always --no-auto-commits --message "prompt"` subprocess.
5
+ * Aider is a git-aware AI coding assistant that makes targeted edits.
6
+ *
7
+ * Output format: Plain text (no JSON mode available).
8
+ * Edit confirmations appear as "Applied edit to <file>" lines.
9
+ */
10
+ import * as os from "node:os";
11
+ import { commandExists } from "../utils/command-exists.js";
12
+ import { RollingBuffer } from "../utils/rolling-buffer.js";
13
+ import { safeSpawn } from "../utils/safe-spawn.js";
14
+ import { registerAgent } from "./provider.js";
15
+ /** Whitelist of env vars safe to pass to agent subprocess. */
16
+ function buildAgentEnv() {
17
+ const homeDir = os.homedir();
18
+ return {
19
+ PATH: process.env.PATH,
20
+ HOME: homeDir,
21
+ USERPROFILE: homeDir,
22
+ SHELL: process.env.SHELL,
23
+ TERM: process.env.TERM,
24
+ LANG: process.env.LANG,
25
+ // Aider supports multiple providers via these keys
26
+ ANTHROPIC_API_KEY: process.env.ANTHROPIC_API_KEY,
27
+ OPENAI_API_KEY: process.env.OPENAI_API_KEY,
28
+ GEMINI_API_KEY: process.env.GEMINI_API_KEY,
29
+ // Aider-specific env vars
30
+ AIDER_MODEL: process.env.AIDER_MODEL,
31
+ AIDER_DARK_MODE: process.env.AIDER_DARK_MODE,
32
+ // Git config
33
+ GIT_AUTHOR_NAME: process.env.GIT_AUTHOR_NAME,
34
+ GIT_AUTHOR_EMAIL: process.env.GIT_AUTHOR_EMAIL,
35
+ GIT_COMMITTER_NAME: process.env.GIT_COMMITTER_NAME,
36
+ GIT_COMMITTER_EMAIL: process.env.GIT_COMMITTER_EMAIL,
37
+ // Python (aider is Python-based)
38
+ VIRTUAL_ENV: process.env.VIRTUAL_ENV,
39
+ CONDA_DEFAULT_ENV: process.env.CONDA_DEFAULT_ENV,
40
+ PYTHONPATH: process.env.PYTHONPATH,
41
+ // Windows
42
+ ...(process.env.SystemRoot ? { SystemRoot: process.env.SystemRoot } : {}),
43
+ ...(process.env.SYSTEMROOT ? { SYSTEMROOT: process.env.SYSTEMROOT } : {}),
44
+ };
45
+ }
46
+ /** Map provider/model format to aider model flag. */
47
+ function resolveModel(model) {
48
+ // Aider accepts provider/model format natively (e.g., "anthropic/claude-sonnet-4-6")
49
+ // It also has short aliases: sonnet, opus, haiku, 4o, etc.
50
+ return model;
51
+ }
52
+ /** Parse aider output to extract edited file paths. */
53
+ function extractFilesChanged(output) {
54
+ const files = [];
55
+ // Aider outputs lines like:
56
+ // "Applied edit to src/auth.ts"
57
+ // "Wrote src/auth.ts"
58
+ // "Committing src/auth.ts ..."
59
+ // "Created new file src/utils.ts"
60
+ const patterns = [
61
+ /Applied edit to\s+(.+?)(?:\s*$)/gm,
62
+ /Wrote\s+(.+?)(?:\s*$)/gm,
63
+ /Committing\s+(.+?)(?:\s+\.\.\.|\s*$)/gm,
64
+ /(?:Created|Added)\s+new file\s+(.+?)(?:\s*$)/gm,
65
+ ];
66
+ for (const pattern of patterns) {
67
+ let match;
68
+ while ((match = pattern.exec(output)) !== null) {
69
+ const file = match[1].trim();
70
+ if (file) {
71
+ files.push(file);
72
+ }
73
+ }
74
+ }
75
+ return [...new Set(files)];
76
+ }
77
+ const aiderProvider = {
78
+ name: "aider",
79
+ async isAvailable() {
80
+ return commandExists("aider");
81
+ },
82
+ async run(options) {
83
+ const { task, workDir, model, files, signal } = options;
84
+ const startTime = Date.now();
85
+ const args = [
86
+ "--yes-always", // Auto-confirm all prompts (except shell commands)
87
+ "--no-auto-commits", // Don't auto-commit (worktree manager handles commits)
88
+ "--no-pretty", // Disable ANSI colors for clean parsing
89
+ "--no-stream", // Don't stream (capture full output)
90
+ "--no-fancy-input", // Disable prompt toolkit input
91
+ "--no-suggest-shell-commands", // Suppress shell command suggestions
92
+ "--no-detect-urls", // Suppress URL detection prompts
93
+ ];
94
+ if (model) {
95
+ args.push("--model", resolveModel(model));
96
+ }
97
+ // Pass the task via --message (non-interactive mode)
98
+ args.push("--message", task);
99
+ // Add specific files to edit if provided
100
+ if (files && files.length > 0) {
101
+ for (const file of files) {
102
+ args.push("--file", file);
103
+ }
104
+ }
105
+ let proc;
106
+ try {
107
+ proc = await safeSpawn("aider", args, {
108
+ cwd: workDir,
109
+ stdio: ["ignore", "pipe", "pipe"],
110
+ env: buildAgentEnv(),
111
+ });
112
+ }
113
+ catch (err) {
114
+ return {
115
+ success: false,
116
+ output: "",
117
+ filesChanged: [],
118
+ diff: "",
119
+ error: `Failed to spawn aider: ${err instanceof Error ? err.message : String(err)}`,
120
+ durationMs: 0,
121
+ };
122
+ }
123
+ return new Promise((resolve) => {
124
+ const stdoutBuf = new RollingBuffer(2 * 1024 * 1024); // 2MB
125
+ const stderrBuf = new RollingBuffer(512 * 1024); // 512KB
126
+ let resolved = false;
127
+ const doResolve = (result) => {
128
+ if (resolved)
129
+ return;
130
+ resolved = true;
131
+ resolve(result);
132
+ };
133
+ proc.stdout?.on("data", (chunk) => {
134
+ const text = chunk.toString();
135
+ stdoutBuf.append(text);
136
+ options.onOutput?.(text);
137
+ });
138
+ proc.stderr?.on("data", (chunk) => {
139
+ stderrBuf.append(chunk.toString());
140
+ });
141
+ if (signal) {
142
+ const onAbort = () => {
143
+ proc.kill("SIGTERM");
144
+ const killTimer = setTimeout(() => {
145
+ try {
146
+ if (proc.exitCode === null)
147
+ proc.kill("SIGKILL");
148
+ }
149
+ catch {
150
+ /* already dead */
151
+ }
152
+ }, 3000);
153
+ proc.on("exit", () => clearTimeout(killTimer));
154
+ };
155
+ if (signal.aborted) {
156
+ onAbort();
157
+ }
158
+ else {
159
+ signal.addEventListener("abort", onAbort, { once: true });
160
+ proc.on("exit", () => signal.removeEventListener("abort", onAbort));
161
+ }
162
+ }
163
+ proc.on("close", (code) => {
164
+ const stdout = stdoutBuf.toString();
165
+ const stderr = stderrBuf.toString();
166
+ const durationMs = Date.now() - startTime;
167
+ const filesChanged = extractFilesChanged(stdout);
168
+ doResolve({
169
+ success: code === 0,
170
+ output: stdout || stderr,
171
+ filesChanged,
172
+ diff: "", // Diff is captured separately by worktree manager
173
+ durationMs,
174
+ error: code !== 0 ? `aider exited with code ${code}${stderr ? `: ${stderr.slice(0, 500)}` : ""}` : undefined,
175
+ });
176
+ });
177
+ proc.on("error", (err) => {
178
+ doResolve({
179
+ success: false,
180
+ output: "",
181
+ filesChanged: [],
182
+ diff: "",
183
+ durationMs: Date.now() - startTime,
184
+ error: `Failed to spawn aider: ${err.message}`,
185
+ });
186
+ });
187
+ });
188
+ },
189
+ };
190
+ registerAgent(aiderProvider);
191
+ export default aiderProvider;
192
+ //# sourceMappingURL=aider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aider.js","sourceRoot":"","sources":["../../src/agents/aider.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAE9B,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAE9C,8DAA8D;AAC9D,SAAS,aAAa;IACrB,MAAM,OAAO,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC;IAC7B,OAAO;QACN,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,IAAI;QACtB,IAAI,EAAE,OAAO;QACb,WAAW,EAAE,OAAO;QACpB,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,KAAK;QACxB,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,IAAI;QACtB,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,IAAI;QACtB,mDAAmD;QACnD,iBAAiB,EAAE,OAAO,CAAC,GAAG,CAAC,iBAAiB;QAChD,cAAc,EAAE,OAAO,CAAC,GAAG,CAAC,cAAc;QAC1C,cAAc,EAAE,OAAO,CAAC,GAAG,CAAC,cAAc;QAC1C,0BAA0B;QAC1B,WAAW,EAAE,OAAO,CAAC,GAAG,CAAC,WAAW;QACpC,eAAe,EAAE,OAAO,CAAC,GAAG,CAAC,eAAe;QAC5C,aAAa;QACb,eAAe,EAAE,OAAO,CAAC,GAAG,CAAC,eAAe;QAC5C,gBAAgB,EAAE,OAAO,CAAC,GAAG,CAAC,gBAAgB;QAC9C,kBAAkB,EAAE,OAAO,CAAC,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BACT,OAAO,EAAE,IAAI,KAAK,CAAC;oBACnB,MAAM,EAAE,MAAM,IAAI,MAAM;oBACxB,YAAY;oBACZ,IAAI,EAAE,EAAE,EAAE,kDAAkD;oBAC5D,UAAU;oBACV,KAAK,EAAE,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,0BAA0B,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,KAAK,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS;iBAC5G,CAAC,CAAC;YACJ,CAAC,CAAC,CAAC;YAEH,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE;gBACxB,SAAS,CAAC;oBACT,OAAO,EAAE,KAAK;oBACd,MAAM,EAAE,EAAE;oBACV,YAAY,EAAE,EAAE;oBAChB,IAAI,EAAE,EAAE;oBACR,UAAU,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS;oBAClC,KAAK,EAAE,0BAA0B,GAAG,CAAC,OAAO,EAAE;iBAC9C,CAAC,CAAC;YACJ,CAAC,CAAC,CAAC;QACJ,CAAC,CAAC,CAAC;IACJ,CAAC;CACD,CAAC;AAEF,aAAa,CAAC,aAAa,CAAC,CAAC;AAC7B,eAAe,aAAa,CAAC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Claude Code agent backend.
3
+ *
4
+ * Runs tasks via `claude -p --output-format json "prompt"` subprocess.
5
+ * Parses structured JSON output for results, cost, and file changes.
6
+ */
7
+ import type { AgentProvider } from "../core/types.js";
8
+ declare const claudeCodeProvider: AgentProvider;
9
+ export default claudeCodeProvider;