# Final Plan: Phase 1 - Core Integration Architecture (250825)
**Objective:** To integrate `co-lint` for real-time, non-disruptive creative orientation validation, as specified in `specifications/CoLintIntegration.md`.
---
### **Step 1: Create the Integration Module**
* **Action:** Create the file `mcp-coaia-sequential-thinking/mcp_coaia_sequential_thinking/colint_integration.py`.
* **Content:** This file will contain the `CoLintIntegration` class with `validate_thought_content` and `validate_summary_content` methods, as defined in the specification.
* **Rationale:** This centralizes the integration logic, making it maintainable and reusable.
---
### **Step 2: Update the Data Model (`models.py`)**
* **File:** `mcp-coaia-sequential-thinking/mcp_coaia_sequential_thinking/models.py`
* **Action:** Add a new field to the `ThoughtData` Pydantic model to store the validation results.
* **Proposed Change:**
* Add `from typing import Dict, Any` to the imports at the top of the file.
* Inside the `ThoughtData` class definition, just before the `timestamp` field, add the following line:
```python
colint_violations: List[Dict[str, Any]] = Field(default_factory=list, description="Stores results from co-lint validation.")
```
* **Rationale:** This structurally prepares the application to persist compliance data for each thought, enabling future analysis and coaching.
---
### **Step 3: Modify `process_thought` in `server.py`**
* **File:** `mcp-coaia-sequential-thinking/mcp_coaia_sequential_thinking/server.py`
* **Action:** Inject the validation logic into the `process_thought` tool.
* **Proposed Changes:**
1. **Import:** Add `from .colint_integration import CoLintIntegration` to the `try...except` import block.
2. **Instantiate:** After the `storage = ThoughtStorage(storage_dir)` line, add `colint = CoLintIntegration()`.
3. **Modify `process_thought`:**
* After the line `thought_data.validate()`, insert the following block to perform validation and store the results:
```python
# Perform co-lint validation
validation_results = colint.validate_thought_content(thought_data.thought, thought_data.stage.value)
thought_data.colint_violations = validation_results.get('violations', [])
```
* After the line `analysis = ThoughtAnalyzer.analyze_thought(thought_data, all_thoughts)`, insert the following to add the validation results to the immediate response:
```python
# Add validation results to the response
analysis['creativeOrientationValidation'] = validation_results
```
* **Rationale:** This injects validation at the correct point (after creation, before storage) and makes the results available both in the stored object and in the immediate return value, fulfilling the spec.
---
### **Step 4: Modify `generate_summary` in `server.py`**
* **File:** `mcp-coaia-sequential-thinking/mcp_coaia_sequential_thinking/server.py`
* **Action:** Inject the summary validation and quality gating logic.
* **Proposed Changes:**
1. **Modify `generate_summary`:**
* After the line `summary_result = ThoughtAnalyzer.generate_summary(all_thoughts)`, insert the following block:
```python
# Perform co-lint validation on the summary
summary_text = json.dumps(summary_result.get('summary', {}))
validation_results = colint.validate_summary_content(summary_text)
```
* Find the line `summary = summary_result.get('summary', {})`. **Replace it** with these two lines to ensure the `summary` variable is defined before being used:
```python
summary = summary_result.get('summary', {})
summary['creativeOrientationCompliance'] = validation_results
```
* Find the line `if chart_readiness.get('readyForChartCreation', False):`. **Replace it** with the new quality-gated condition:
```python
# Trigger chart creation if ready AND compliant
if chart_readiness.get('readyForChartCreation', False) and validation_results.get('compliance_score', 0.0) > 0.8:
```
* **Rationale:** This validates the final output and implements the crucial quality gate, ensuring that only structurally and linguistically sound thinking sequences proceed to chart creation, as required by the plan.