@noanswer/context-compose
Version:
Orchestrate complex AI interactions with Context Compose. A powerful CLI and server for building, validating, and managing context for large language models using the Model Context Protocol (MCP).
307 lines (203 loc) โข 12.3 kB
Markdown
# Context Compose
**Composable Contexts for High-Quality, AI-Powered Development**
## Why Context Compose?
While high-level requirements documents (like PRDs) provide overall project goals, they often lack the detailed, task-specific context needed for day-to-day development. Each unit of workโbe it a new feature, a bug fix, or a refactorโrequires its own focused set of rules, expert perspectives, and guidelines to ensure consistency and quality.
Context Compose provides a simple yet powerful system for defining, composing, and managing these granular contexts. It's like Docker Compose, but for your AI development workflow.
**The Problem:**
- High-level documents are too broad for specific coding tasks.
- Developers constantly switch between tasks that require different mindsets and rules.
- Inconsistent approaches across team members for similar tasks lead to quality issues.
- Repetitive and manual context-setting for AI assistants is time-consuming.
**The Solution:**
Context Compose allows you to define reusable, task-specific contexts that can be composed on demand. This ensures every task is approached with the right expertise and standards, leading to consistent, high-quality results across your entire team.
## Key Features
- ๐ฏ **Task-Specific Contexts**: Create dedicated contexts for features, bug fixes, refactoring, API design, and more.
- ๐งฉ **Composable Architecture**: Mix and match componentsโlike expert personas, coding rules, and specialized toolsโto build the perfect context for any task.
- ๐ง **Fully Customizable**: The system is built on a simple directory structure. You can override existing assets or create entirely new categories (e.g., `security`, `testing-philosophy`) to fit your project's unique needs.
- โจ๏ธ **Simple CLI**: A straightforward command-line interface (`start-context`) makes it easy to load contexts and integrate with your existing workflows.
- ๐ **Clear File-Based Structure**: All contexts and assets are managed as simple YAML files, making them easy to version control, share, and edit.
## MCP Server Integration
To integrate Context Compose with an MCP-compatible client (like an IDE extension), you can register it as an MCP server.
For integration with automated tools, use the following configuration in your settings file:
```json
{
"mcpServers": {
"context-compose": {
"command": "npx",
"args": ["-y", "@noanswer/context-compose@latest"]
}
}
}
```
This configuration tells the client how to start the `context-compose` server, ensuring it runs non-interactively.
## Project Initialization
Before using contexts, you need to initialize your project. This sets up the necessary `.contextcompose` directory and default assets.
Copy and paste the following into your prompt to run it.
```
initialize my project using context-compose
```
**What happens**:
- The `init` command runs.
- A `.contextcompose` directory is created in your project root.
- Default assets (personas, rules, etc.) are copied into it, ready for you to use or customize.
## How It Works
Context Compose works by reading a main context file and dynamically assembling a final, detailed prompt from various component files. The entire system is driven by a special directory in your project root: `.contextcompose/`.
1. **The `.contextcompose/` Directory**: When you start a task, you tell Context Compose which context to use (e.g., `feature`).
2. **Main Context File**: It looks for a corresponding file, like `.contextcompose/feature-context.yaml`.
3. **The `context` Block**: Inside this file, a `context` block lists all the components to include. It references other YAML files organized by category (e.g., `personas`, `rules`).
4. **Dynamic Composition**: The tool reads each referenced file, extracts its prompt, and combines everything into a single, comprehensive prompt.
**The best part? It's fully extensible.** You can create any category you want. If you add a `security:` section to your context file, the tool will automatically look for files in a `.contextcompose/security/` directory.
### Context Structure Example
Here is an example of what a `.contextcompose/api-context.yaml` file might look like. It defines the context for building a new API endpoint.
```yaml
# .contextcompose/api-context.yaml
version: 1
kind: context
name: 'api-development'
description: 'Context for creating new API endpoints.'
# This is the base prompt for the main context file itself.
prompt: 'You are building a new API endpoint. Follow all the guidelines provided.'
enhanced-prompt: 'Your mission is to construct a robust, secure, and well-documented API endpoint. Pay close attention to the expert advice from the persona, adhere strictly to all specified rules, and utilize the recommended tools (MCPs).'
# Here we compose the context from other files.
context:
personas:
- personas/uncle-bob.yaml
rules:
- rules/api-design.yaml
- rules/clean-code.yaml
# This is a custom category!
security:
- security/owasp-top-10.yaml
mcps:
- mcps/sequential-thinking.yaml
```
## ๐ ๏ธ Customization in Detail
Customizing Context Compose is its core strength. You can override built-in assets or create new ones from scratch.
**Scenario**: Let's add a new category for "Company-Wide Principles".
1. **Create a New Directory**: Inside your project's `.contextcompose/` directory, create a new folder named `principles`.
```
.contextcompose/
โโโ principles/
โโโ ...
```
2. **Create Your Asset File**: Inside the new directory, create a YAML file. The `kind` should match the singular version of the directory name.
```yaml
# .contextcompose/principles/team-values.yaml
version: 1
kind: principle # Matches the 'principles' directory
name: 'team-values'
description: 'The core values our engineering team follows.'
prompt: |
- Always prioritize clarity over cleverness.
- Leave code better than you found it.
- Communicate proactively.
```
3. **Reference it in Your Context**: Now, you can add `principles` to any `*-context.yaml` file.
```yaml
# .contextcompose/feature-context.yaml
version: 1
kind: context
name: 'feature'
# ...
context:
personas: - personas/frontend-expert.yaml
rules: - rules/typescript-best-practices.yaml
# Your new custom category is now part of the context!
principles: - principles/team-values.yaml
`When you run`context-compose start-context feature`, the content of `team-values.yaml` will be automatically included in the final prompt.
```
4. **Validate Your Assets**
After creating or modifying asset files, it's a good practice to validate them. Context Compose provides a `validate` command to check for common errors.
```bash
npx @noanswer/context-compose validate
```
This command will check all your asset files inside the `.contextcompose` directory and verify that:
- The YAML syntax is correct.
- All required fields (`version`, `kind`, `name`, `description`, `prompt`) are present.
This helps you catch errors early and ensures your contexts are correctly structured.
## ๐ญ User Scenarios
### 1. Project Initialization
Before using contexts, you need to initialize your project. This sets up the necessary `.contextcompose` directory and default assets.
> initialize my project using context-compose
**What happens**:
- The `init` command runs.
- A `.contextcompose` directory is created in your project root.
- Default assets (personas, rules, etc.) are copied into it, ready for you to use or customize.
### 2. Frontend Developer: Building a New React Component
A developer is tasked with building a new search component using React and TypeScript. They would start by telling their AI assistant:
> start-context react-feature -e using context-compose
**What they get**:
- Guidance from a **React Expert Persona** on component structure and state management.
- Strict **TypeScript Rules** for type safety and best practices.
- Checklists from **Testing Rules** to ensure Jest/RTL coverage.
- A **Sequential Thinking** framework to break down the task.
### 3. Backend Developer: Creating a Secure API Endpoint
A developer needs to create a new RESTful API endpoint for user authentication. They would start by telling their AI assistant:
> start-context secure-api using context-compose
**What they get**:
- Principles from **API Design Rules** for RESTful patterns.
- Critical reminders from custom **Security Rules** based on OWASP guidelines.
- Best practices from **Clean Code Rules** for maintainability.
### 4. Team Lead: Performing a Code Review
A team lead wants to ensure a consistent and thorough code review process. They would start by telling their AI assistant:
> start-context code-review using context-compose
**What they get**:
- A **Code Quality Checklist** from the rules to standardize the review.
- The perspective of an **Architecture Expert Persona** to check for anti-patterns.
- Guidelines on providing constructive feedback.
## ๐งช ํ
์คํธ ์๋ํ
Context Compose๋ ์ฝ๋ ์์ ํ CLI์ MCP ๋๊ตฌ์ ์ ์ ๋์์ ์๋์ผ๋ก ๊ฒ์ฆํ๋ ํฌ๊ด์ ์ธ ํ
์คํธ ์์คํ
์ ์ ๊ณตํฉ๋๋ค.
### ํ
์คํธ ์ค์ํธ
- **๐ฅ Smoke Tests**: ํต์ฌ ๊ธฐ๋ฅ๋ค์ ๋น ๋ฅธ ๊ฒ์ฆ
- **๐งฉ Unit Tests**: ๊ฐ๋ณ ํจ์์ ๋ชจ๋์ ์์ธ ํ
์คํธ
- **๐ Integration Tests**: MCP ์๋ฒ์ CLI์ ํตํฉ ํ
์คํธ
- **๐ E2E Tests**: ์ค์ ์ฌ์ฉ์ ์๋๋ฆฌ์ค ํ
์คํธ
### ํ
์คํธ ์คํ ๋ช
๋ น์ด
```bash
# ๋ชจ๋ ํ
์คํธ ์คํ
npm run test:all
# ๊ฐ๋ณ ํ
์คํธ ์ค์ํธ ์คํ
npm run test:smoke # ๋น ๋ฅธ ๊ฒ์ฆ
npm run test:unit # ๋จ์ ํ
์คํธ
# ํ
์คํธ ์ปค๋ฒ๋ฆฌ์ง ํ์ธ
npm run test:coverage
# ์๋ํ ์คํฌ๋ฆฝํธ ์คํ (๋ชจ๋ ๊ฒ์ฆ ํฌํจ)
npm run test:automation
```
### ์๋ํ๋ ๊ฒ์ฆ ํญ๋ชฉ
โ
**CLI ๋ช
๋ น์ด ๋์ ํ์ธ**
- `init`, `start-context`, `validate` ๋ช
๋ น์ด ์ ์ ์คํ
- ์๋ฌ ์ผ์ด์ค ์ฒ๋ฆฌ ๊ฒ์ฆ
- ๋ค์ํ ํ๋ก์ ํธ ๊ตฌ์กฐ์์์ ๋์ ํ
์คํธ
โ
**MCP ์๋ฒ ํตํฉ ๊ฒ์ฆ**
- ์๋ฒ ์์/์ข
๋ฃ ํ
์คํธ
- ๊ฐ ๋๊ตฌ์ ์ ์ ๋์ ํ์ธ
- ์คํค๋ง ๊ฒ์ฆ ๋ฐ ์๋ฌ ์ฒ๋ฆฌ
โ
**ํ์ผ ์์คํ
์์
๊ฒ์ฆ**
- ํ๋ก์ ํธ ์ด๊ธฐํ ํ์ธ
- ์ปจํ
์คํธ ํ์ผ ์์ฑ/์ฝ๊ธฐ ํ
์คํธ
- ๊ถํ ๋ฐ ๊ฒฝ๋ก ์ฒ๋ฆฌ ๊ฒ์ฆ
โ
**์์ ์ฑ ํ
์คํธ**
- ๋์ ์คํ ์์ ์ฑ
- ๋ฉ๋ชจ๋ฆฌ ์ฌ์ฉ๋ ๋ชจ๋ํฐ๋ง
### CI/CD ํตํฉ
GitHub Actions๋ฅผ ํตํด ๋ชจ๋ ์ปค๋ฐ๊ณผ PR์์ ์๋์ผ๋ก ํ
์คํธ๊ฐ ์คํ๋ฉ๋๋ค:
1. **์ฝ๋ ํ์ง ๊ฒ์ฌ** - Biome ๋ฆฐํ
๋ฐ TypeScript ํ์
๊ฒ์ฌ
2. **Smoke ํ
์คํธ** - ํต์ฌ ๊ธฐ๋ฅ ๋น ๋ฅธ ๊ฒ์ฆ
3. **๋ณ๋ ฌ ํ
์คํธ ์คํ** - ๋จ์ ํ
์คํธ ๋์ ์คํ
4. **ํ
์คํธ ๊ฒฐ๊ณผ ์์ฝ** - ์์ธํ ๊ฒฐ๊ณผ ๋ฆฌํฌํธ ์์ฑ
### ๊ฐ๋ฐ์๋ฅผ ์ํ ํํ
๐ **์์ ๊ฐ ์๋ ๋ฐฐํฌ**: ๋ชจ๋ ํ
์คํธ ํต๊ณผ ์ CLI์ MCP ๋๊ตฌ์ ์ ์ ๋์ ๋ณด์ฅ
๐ง **๋น ๋ฅธ ํผ๋๋ฐฑ**: Smoke ํ
์คํธ๋ก ํต์ฌ ๊ธฐ๋ฅ ๋ฌธ์ ๋ฅผ ์ฆ์ ๋ฐ๊ฒฌ
๐ **ํฌ๋ช
ํ ํ์ง**: ํ
์คํธ ์ปค๋ฒ๋ฆฌ์ง๋ก ์ฝ๋ ํ์ง ์ถ์
โก **ํจ์จ์ ์ธ ๊ฐ๋ฐ**: ์๋ ๊ฒ์ฆ ์์ด ์๋ํ๋ ํ
์คํธ๋ก ๊ฐ๋ฐ ์๋ ํฅ์
## ๐ฆ Built-in Assets Structure
Context Compose comes with a set of pre-built assets to get you started. You can use them as is or override them by creating files with the same name in your project's `.contextcompose/` directory.
- **`assets/personas/`**: Expert personas providing specialized knowledge (e.g., `frontend-expert`, `backend-expert`, `devops-expert`).
- **`assets/rules/`**: Development guidelines and best practices (e.g., `clean-code`, `api-design`, `testing-principles`).
- **`assets/actions/`**: Definitions for specific AI tasks and operations.
- **`assets/mcps/`**: Integrations with Model Context Protocols for enhanced AI capabilities (e.g., `sequential-thinking`, `web-search`).
## ๐ Links
- [GitHub Repository](https://github.com/weproud/context-compose)
- [Issue Tracker](https://github.com/weproud/context-compose/issues)
- [NPM Package](https://www.npmjs.com/package/@noanswer/context-compose)