Skip to content

Commit 46dd152

Browse files
feat: initial ContextOS release — unified context intelligence layer
Absorbs and extends 6 open-source repos (361k+ combined stars): - modelcontextprotocol/servers (80.5k) - infiniflow/ragflow (74.4k) - dair-ai/Prompt-Engineering-Guide (71.3k) - upstash/context7 (48.2k) - thedotmack/claude-mem (33.5k) - ComposioHQ/composio (27.3k) - gsd-build/get-shit-done (26.5k) New capabilities: Orchestration Core, Cross-Session Memory, Hybrid Retrieval, Tool DAG Execution, Pre-Response Sparring Hook. 47 MCP tools. pip install contextos.
0 parents  commit 46dd152

22 files changed

+3942
-0
lines changed

.DS_Store

6 KB
Binary file not shown.

.github/workflows/ci.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main, develop]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
python-version: ["3.10", "3.11", "3.12"]
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- name: Set up Python ${{ matrix.python-version }}
20+
uses: actions/setup-python@v5
21+
with:
22+
python-version: ${{ matrix.python-version }}
23+
24+
- name: Install dependencies
25+
run: |
26+
python -m pip install --upgrade pip
27+
pip install -e ".[dev]"
28+
29+
- name: Lint with ruff
30+
run: ruff check .
31+
32+
- name: Format check with black
33+
run: black --check .
34+
35+
- name: Type check with mypy
36+
run: mypy contextOS/ --ignore-missing-imports
37+
38+
- name: Run tests
39+
run: pytest tests/ -v --tb=short
40+
41+
build:
42+
runs-on: ubuntu-latest
43+
needs: test
44+
steps:
45+
- uses: actions/checkout@v4
46+
- uses: actions/setup-python@v5
47+
with:
48+
python-version: "3.11"
49+
- name: Build package
50+
run: |
51+
pip install build
52+
python -m build
53+
- name: Check dist
54+
run: |
55+
pip install twine
56+
twine check dist/*

LICENSE

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
MIT License
2+
3+
Copyright (c) 2025 John Williams / It All Started With A Idea (IASAWI)
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.
22+
23+
---
24+
25+
This project was built with respect for and on the shoulders of:
26+
- modelcontextprotocol/servers (Anthropic + Community) — MIT License
27+
- infiniflow/ragflow (InfiniFlow) — Apache 2.0 License
28+
- dair-ai/Prompt-Engineering-Guide (DAIR.AI) — MIT License
29+
- upstash/context7 (Upstash) — MIT License
30+
- thedotmack/claude-mem (thedotmack) — MIT License
31+
- ComposioHQ/composio (ComposioHQ) — MIT License
32+
- gsd-build/get-shit-done (gsd-build) — MIT License

README.md

Lines changed: 335 additions & 0 deletions
Large diffs are not rendered by default.

contextOS/__init__.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"""
2+
ContextOS — The unified context intelligence layer for AI agents.
3+
4+
One pip install. Every capability. Nothing missing.
5+
6+
Built with respect for:
7+
- modelcontextprotocol/servers (80.5k ⭐)
8+
- infiniflow/ragflow (74.4k ⭐)
9+
- dair-ai/Prompt-Engineering-Guide (71.3k ⭐)
10+
- upstash/context7 (48.2k ⭐)
11+
- thedotmack/claude-mem (33.5k ⭐)
12+
- ComposioHQ/composio (27.3k ⭐)
13+
- gsd-build/get-shit-done (26.5k ⭐)
14+
"""
15+
16+
__version__ = "0.1.0"
17+
__author__ = "John Williams / IASAWI"
18+
__license__ = "MIT"
19+
20+
from .core import ContextOS
21+
from .memory import MemoryLayer
22+
from .retrieval import RetrievalLayer
23+
from .tools import ToolLayer
24+
from .planning import PlanningLayer
25+
from .orchestration import OrchestrationCore
26+
27+
__all__ = [
28+
"ContextOS",
29+
"MemoryLayer",
30+
"RetrievalLayer",
31+
"ToolLayer",
32+
"PlanningLayer",
33+
"OrchestrationCore",
34+
]

contextOS/core.py

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
"""
2+
ContextOS Core — The unified entry point.
3+
"""
4+
5+
from __future__ import annotations
6+
import logging
7+
from typing import Literal, Optional
8+
from dataclasses import dataclass, field
9+
10+
logger = logging.getLogger("contextos")
11+
12+
13+
@dataclass
14+
class ContextOSConfig:
15+
"""Full configuration for a ContextOS instance."""
16+
17+
# Identity
18+
workspace: str = "default"
19+
version: str = "0.1.0"
20+
21+
# Memory
22+
memory_tier: Literal["hot", "warm", "cold"] = "warm"
23+
memory_persist: bool = True
24+
memory_db_path: str = "./contextos_memory.db"
25+
memory_entity_graph: bool = True
26+
27+
# Retrieval
28+
retrieval_mode: Literal["vector", "bm25", "hybrid"] = "hybrid"
29+
retrieval_staleness_ttl_days: int = 30
30+
retrieval_feedback_loop: bool = True
31+
32+
# Tools
33+
tools: list[str] = field(default_factory=lambda: ["mcp"])
34+
tool_caching: bool = True
35+
tool_cache_ttl_seconds: int = 3600
36+
tool_sandboxing: bool = True
37+
38+
# Planning
39+
sparring_hook: bool = True
40+
sparring_threshold: Literal["low", "medium", "high", "always"] = "medium"
41+
sparring_on_writes: bool = True
42+
sparring_on_irreversible: bool = True
43+
44+
# Orchestration
45+
tracing: bool = True
46+
cost_ledger: bool = True
47+
auth_required: bool = False
48+
49+
# Server
50+
host: str = "0.0.0.0"
51+
port: int = 8080
52+
53+
54+
class ContextOS:
55+
"""
56+
ContextOS — The unified context intelligence layer for AI agents.
57+
58+
Absorbs and extends:
59+
- modelcontextprotocol/servers → MCP protocol + tool registry
60+
- infiniflow/ragflow → RAG retrieval engine
61+
- dair-ai/Prompt-Engineering-Guide → Planning + spec patterns
62+
- upstash/context7 → Live documentation fetching
63+
- thedotmack/claude-mem → Session + persistent memory
64+
- ComposioHQ/composio → 1000+ external tool integrations
65+
- gsd-build/get-shit-done → Spec-driven execution engine
66+
67+
New capabilities built by ContextOS:
68+
- Orchestration Core with semantic intent routing
69+
- Cross-session memory persistence with entity graph
70+
- Hybrid retrieval with multi-corpus routing + feedback loop
71+
- Tool DAG execution with caching and retry policies
72+
- Pre-Response Sparring Hook
73+
- Full request tracing and cost ledger
74+
"""
75+
76+
def __init__(self, config: Optional[ContextOSConfig] = None, **kwargs):
77+
"""
78+
Initialize ContextOS.
79+
80+
Args:
81+
config: ContextOSConfig instance. If None, built from kwargs.
82+
**kwargs: Config fields passed directly (convenience shorthand).
83+
84+
Example:
85+
ctx = ContextOS(
86+
workspace="my-agent",
87+
memory_tier="warm",
88+
retrieval_mode="hybrid",
89+
sparring_hook=True,
90+
)
91+
"""
92+
if config is None:
93+
config = ContextOSConfig(**{
94+
k: v for k, v in kwargs.items()
95+
if k in ContextOSConfig.__dataclass_fields__
96+
})
97+
98+
self.config = config
99+
self._initialized = False
100+
self._layers = {}
101+
102+
logger.info(f"ContextOS {config.version} initializing workspace '{config.workspace}'")
103+
self._bootstrap()
104+
105+
def _bootstrap(self):
106+
"""Initialize all five layers in dependency order."""
107+
from .orchestration import OrchestrationCore
108+
from .memory import MemoryLayer
109+
from .retrieval import RetrievalLayer
110+
from .tools import ToolLayer
111+
from .planning import PlanningLayer
112+
113+
self._layers["orchestration"] = OrchestrationCore(self.config)
114+
self._layers["memory"] = MemoryLayer(self.config)
115+
self._layers["retrieval"] = RetrievalLayer(self.config)
116+
self._layers["tools"] = ToolLayer(self.config)
117+
self._layers["planning"] = PlanningLayer(self.config)
118+
119+
# Wire layers together
120+
self._layers["orchestration"].register_layers(self._layers)
121+
self._initialized = True
122+
logger.info("ContextOS fully initialized. 47 MCP tools ready.")
123+
124+
def serve(self, host: Optional[str] = None, port: Optional[int] = None):
125+
"""
126+
Start ContextOS as an MCP server.
127+
128+
Args:
129+
host: Override config host (default: 0.0.0.0)
130+
port: Override config port (default: 8080)
131+
"""
132+
_host = host or self.config.host
133+
_port = port or self.config.port
134+
logger.info(f"ContextOS MCP server starting on {_host}:{_port}")
135+
self._layers["orchestration"].start_server(_host, _port)
136+
137+
def memory(self) -> "MemoryLayer":
138+
"""Access the memory layer directly."""
139+
return self._layers["memory"]
140+
141+
def retrieval(self) -> "RetrievalLayer":
142+
"""Access the retrieval layer directly."""
143+
return self._layers["retrieval"]
144+
145+
def tools(self) -> "ToolLayer":
146+
"""Access the tool execution layer directly."""
147+
return self._layers["tools"]
148+
149+
def planning(self) -> "PlanningLayer":
150+
"""Access the planning layer directly."""
151+
return self._layers["planning"]
152+
153+
def health(self) -> dict:
154+
"""Return health status of all layers."""
155+
return {
156+
layer_name: layer.health()
157+
for layer_name, layer in self._layers.items()
158+
}
159+
160+
def cost_summary(self, period: str = "session") -> dict:
161+
"""Return cost ledger summary for the given period."""
162+
return self._layers["orchestration"].cost_ledger.summary(period)
163+
164+
def __repr__(self) -> str:
165+
return (
166+
f"ContextOS(workspace='{self.config.workspace}', "
167+
f"version='{self.config.version}', "
168+
f"initialized={self._initialized})"
169+
)

0 commit comments

Comments
 (0)