Skip to content

Latest commit

 

History

History
454 lines (335 loc) · 17.2 KB

File metadata and controls

454 lines (335 loc) · 17.2 KB

📊 Coherence-MCP Implementation Gap Analysis

"From the constraints, gifts. From the spiral, safety."

Date: 2026-01-13 Analyst: Claude (Sonnet 4.5) Context: Post-refactoring analysis after implementing real MCP tools


Executive Summary

coherence-mcp underwent a complete architectural rewrite (commit 373aa5d), replacing a modular dist/ structure with consolidated src/lib/ modules. This analysis examines what was lost, gained, and what remains to be done.

Key Findings

Category Status Impact
Core Tools COMPLETE (10/10) All main tools now REAL
Tests 🔴 BROKEN Test suite references old architecture
Documentation 🟡 PARTIAL README accurate, docs/ outdated
Old Architecture 📦 ARCHIVED dist/ contains superseded implementation
Security/Auth REMOVED ATOM-AUTH, rate limiting, scopes all gone

Part 1: Architectural Comparison

Old Architecture (dist/)

dist/
├── adapters/         ← API, Discord, Media, Minecraft clients
│   ├── api.js
│   ├── discord.js
│   ├── media.js
│   └── minecraft.js
├── auth/
│   └── scopes.js     ← Scope-based authorization
├── lib/quantum/      ← Quantum-inspired routing/trust
│   ├── coherence.js
│   ├── routing.js
│   ├── trust.js
│   └── utils.js
├── logging/
│   └── audit.js      ← Audit trail
├── resources/
│   └── index.js      ← Resource registry
├── tools/            ← Modular tool implementations
│   ├── atom.js
│   ├── awi.js
│   ├── bump.js
│   ├── comm.js       ← Cross-AI communication
│   ├── context.js
│   ├── docs.js
│   ├── gates.js
│   ├── ops.js
│   └── wave.js
├── config.js         ← Configuration management
├── configEnv.js      ← Environment-based config
└── server.js         ← Main server with auth/rate-limiting

Architecture Style: Modular, config-driven, enterprise-grade Auth: Bearer token + HMAC signing External Integrations: wave-toolkit CLI, Discord, Minecraft RCON Lines: ~500 (modular across many files)


New Architecture (src/)

src/
├── lib/              ← Consolidated real implementations
│   ├── api-client.ts      ← Ops API integration
│   ├── atom-trail.ts      ← ATOM tracking
│   ├── bump-validation.ts ← H&&S marker parsing
│   ├── context-pack.ts    ← .context.yaml creation
│   ├── gate-transitions.ts← Real gate validation
│   ├── spiral-search.ts   ← Corpus search
│   └── wave-analysis.ts   ← Self-contained NLP
└── index.ts          ← Single-file server (simplified)

Architecture Style: Consolidated, self-contained, direct Auth: None (delegated to MCP client layer) External Integrations: SpiralSafe API only Lines: ~400 main + ~1,900 lib implementations


Part 2: Feature-by-Feature Analysis

Implemented & Working

Tool Old (dist/) New (src/lib/) Notes
wave_analyze External CLI fallback Self-contained NLP ✅ Better: no external dependency
bump_validate SHA256 hash check H&&S marker parsing ✅ Better: understands protocol semantics
context_pack YAML + file reads YAML + SHA256 hashing ✅ Better: integrity verification
atom_track Stub Real .atom-trail/ writes ✅ NEW: fully functional
gate_intention_to_execution Stub (always pass) Real validation + jsonl ✅ NEW: actual checks
gate_execution_to_learning Stub (always pass) Real validation + jsonl ✅ NEW: actual checks
docs_search Stub Real corpus indexing ✅ NEW: fast-glob search
ops_health API client stub Real fetch() to api.spiralsafe.org ✅ NEW: network calls
ops_status API client stub Real fetch() to api.spiralsafe.org ✅ NEW: network calls
ops_deploy Guarded stub Real fetch() with safety ✅ Kept: production guard

Removed Features

Feature Location (old) Reason for Removal Impact
ATOM-AUTH dist/auth/, README Simplified architecture 🔴 HIGH - No authentication
Rate Limiting dist/server.js Delegated to MCP layer 🟡 MEDIUM - Assumes client handles it
Audit Logging dist/logging/audit.js Not ported 🟡 MEDIUM - No compliance trail
Scope Authorization dist/auth/scopes.js Not needed 🟢 LOW - MCP handles permissions
Resource Registry dist/resources/ Not used 🟢 LOW - Tools are sufficient
Quantum Routing dist/lib/quantum/ Experimental 🟢 LOW - Was research code
Discord Adapter dist/adapters/discord.js Not ported 🟡 MEDIUM - Media pipeline incomplete
Minecraft Adapter dist/adapters/minecraft.js Not ported 🟡 MEDIUM - RCON integration missing
Config System dist/config.js, configEnv.js Hardcoded paths 🟡 MEDIUM - Less flexible
wave-toolkit CLI dist/tools/wave.js Self-contained NLP 🟢 LOW - Simpler deployment

🔴 Critical Issue: Broken Tests

Problem: __tests__/tools.test.ts imports from OLD architecture:

// __tests__/tools.test.ts (lines 6-43)
import { defaultConfig } from "../src/config.js";          // ❌ DOESN'T EXIST
import type { ApiClient } from "../src/adapters/api.js";   // ❌ DOESN'T EXIST
import { registerWaveTools } from "../src/tools/wave.js";  // ❌ DOESN'T EXIST
import { registerBumpTools } from "../src/tools/bump.js";  // ❌ DOESN'T EXIST

Impact: npm test is broken. Zero test coverage for new implementations.

Status: 🔴 BLOCKING for production deployment


Part 3: Documentation Audit

README.md Analysis

Claim Reality Status
"Wave/Bump validation" ✅ Implemented ✅ ACCURATE
"ATOM trail + gates" ✅ Implemented ✅ ACCURATE
".context.yaml packing" ✅ Implemented ✅ ACCURATE
"AWI intent scaffolding" ❌ Stub (not in TOOLS) 📝 MISMATCH
"docs/search across SpiralSafe" ✅ Implemented ✅ ACCURATE
"ATOM-AUTH 3-Factor" ❌ Removed 📝 MISMATCH (shown in diagrams)
"Discord/Minecraft integration" ❌ Removed 📝 MISMATCH (mentioned in architecture)

Finding: README still describes old architecture's ATOM-AUTH and media pipelines that no longer exist.


docs/ Directory Analysis

File Content Accuracy
data-flow.md Describes adapters, mounts, SpiralSafe integration 🟡 PARTIAL - adapters don't exist
flow.md Describes resources registry, tools registration 🟡 PARTIAL - registry removed
one-pager.md High-level purpose ✅ ACCURATE
publishing-pipeline.md npm publish instructions ✅ ACCURATE
quick-start.md Mount paths, env vars 🟡 PARTIAL - config system changed
testing-suite.md Test strategy 🔴 BROKEN - tests don't run

Finding: docs/ describes OLD modular architecture. Needs update for single-file src/index.ts approach.


Part 4: Remaining Stubs Analysis

Stubs in src/index.ts

None! All 10 defined tools have real implementations.

Missing Tools (From Old Architecture)

Tool (old) Status Notes
awi_intent_request ❌ NOT PORTED Was stub anyway
discord_post ❌ NOT PORTED Needs Discord adapter
mc_execCommand ❌ NOT PORTED Needs Minecraft RCON
mc_query ❌ NOT PORTED Needs Minecraft RCON
scripts_run ❌ NOT PORTED Was allow-list checker only
grok_collab ❌ NOT PORTED Cross-AI was separate
grok_metrics ❌ NOT PORTED Autonomy metrics
gate_knowledge_to_intention ⚠️ IN LIB Exists in gate-transitions.ts but not exposed
gate_learning_to_regeneration ⚠️ IN LIB Exists in gate-transitions.ts but not exposed

Finding: 2 gates implemented but not exposed as tools. 7 tools removed entirely.


Part 5: Code Quality Analysis

Security Issues

Issue Severity Location Details
No authentication 🔴 HIGH src/index.ts Removed ATOM-AUTH, bearer tokens, HMAC
No rate limiting 🟡 MEDIUM src/index.ts Assumes MCP layer handles it
No audit logging 🟡 MEDIUM Everywhere Compliance/debugging limited
Hardcoded API URL 🟢 LOW src/lib/api-client.ts:63-88 Should be configurable
No input sanitization 🟡 MEDIUM src/lib/gate-transitions.ts Shell command execution

Technical Debt

Issue Impact Location
strict: false in tsconfig.json 🟡 MEDIUM Type safety disabled
No error boundaries 🟡 MEDIUM Errors may crash server
Synchronous file I/O 🟢 LOW Most operations use fs/promises
No retry logic 🟡 MEDIUM API calls fail on first timeout
Magic numbers 🟢 LOW Thresholds like 0.6, 0.7 should be constants

Missing Features

Feature Priority Effort Notes
Test suite 🔴 P0 HIGH Rewrite for new architecture
ATOM-AUTH 🟡 P1 HIGH Security critical
Discord adapter 🟢 P2 MEDIUM Media pipeline
Minecraft adapter 🟢 P2 MEDIUM RCON integration
Config system 🟡 P1 LOW Make paths configurable
Audit logging 🟡 P1 MEDIUM Compliance requirement
Rate limiting 🟡 P1 LOW DOS protection

Part 6: SpiralSafe Integration Analysis

Integration Points

| Component | Status | Notes | |--------- ---------------------|-------------|-------------------------------| | ../SpiralSafe/ mount | ✅ WORKING | Hardcoded relative path | | .atom-trail/ writes | ✅ WORKING | Real file system operations | | api.spiralsafe.org | ✅ WORKING | HTTP client with timeout | | corpus search | ✅ WORKING | fast-glob across layers/kinds | | .context.yaml | ✅ WORKING | YAML + SHA256 hashing |

Missing Integrations

Integration Old? New? Impact
wave-toolkit CLI Self-contained NLP sufficient
Discord webhooks Media pipeline incomplete
Minecraft RCON Quantum Valley disconnected
ATOM session tracking Mentioned in docs but not implemented

Part 7: Benchmarking & Performance

Scripts Status

Script Status Notes
scripts/benchmark.py ✅ WORKING Golden ratio chaos, Fibonacci scoring
scripts/smoke.mjs ⚠️ UNKNOWN Not analyzed (may reference old arch)
improve.md ✅ ACCURATE Documents benchmark workflow

Performance Analysis

Not measured. No benchmarks exist for:

  • WAVE analysis speed (NLP operations)
  • Corpus search latency (fast-glob performance)
  • API response times (api.spiralsafe.org)
  • File I/O throughput (.atom-trail/ writes)

Part 8: Recommendations

Immediate (P0)

  1. Fix test suite - Rewrite __tests__/tools.test.ts for new architecture
  2. Update README - Remove ATOM-AUTH diagrams, clarify what's implemented
  3. Expose missing gates - Add gate_knowledge_to_intention and gate_learning_to_regeneration to TOOLS array
  4. Add .npmignore - Exclude dist/, tests/, src/ from package

Short-term (P1)

  1. Add authentication - Implement MCP-level auth or bring back bearer tokens
  2. Add audit logging - Write tool invocations to .atom-trail/audit.jsonl
  3. Make paths configurable - Environment variables for SpiralSafe path, API URL
  4. Update docs/ - Rewrite for single-file architecture
  5. Add rate limiting - Per-tool invocation limits

Long-term (P2)

  1. Restore Discord adapter - Rebuild for media pipeline
  2. Restore Minecraft adapter - Rebuild for Quantum Valley integration
  3. Add benchmarks - Performance tests for all tools
  4. Enable TypeScript strict mode - Fix type issues
  5. Add error boundaries - Prevent server crashes

Part 9: Migration Path

For teams using the OLD architecture (dist/):

Breaking Changes

  1. Authentication: ATOM-AUTH removed. Use MCP client-level auth.
  2. Configuration: config.js removed. Use environment variables.
  3. Adapters: Discord/Minecraft removed. Tools not available.
  4. Resource registry: Removed. Use tool calls directly.
  5. Audit logging: Removed. Implement at client level.

Migration Steps

# 1. Backup old implementation
cp -r dist/ dist-backup/

# 2. Update dependencies
npm install

# 3. Rebuild
npm run build

# 4. Update MCP client config
# Change tool names: wave.analyze → wave_analyze

# 5. Remove auth config
# ATOM-AUTH no longer needed

# 6. Test
npm test  # Will fail - tests need rewrite

Part 10: Comparison to SpiralSafe Gap Analysis

Following the methodology from SpiralSafe/docs/USER_JOURNEY_GAP_ANALYSIS.md:

Lessons Applied

Focused on implementation gaps (not just documentation) ✅ Line-number specificity for issues ✅ Status categories (COMPLETE/PARTIAL/STUB/MISMATCH/BROKEN) ✅ Prioritized recommendations (P0/P1/P2) ✅ Migration path for breaking changes

Bespoke Optimizations

  1. Architectural comparison - Old vs new side-by-side
  2. Feature matrix - What was kept, removed, improved
  3. Test coverage analysis - Zero coverage identified
  4. SpiralSafe integration audit - Mount points, API calls
  5. Security audit - Auth removal flagged

Appendix A: File Inventory

Active Files (src/)

src/
├── index.ts                  399 lines  ✅ WORKING
├── lib/
│   ├── api-client.ts        191 lines  ✅ WORKING
│   ├── atom-trail.ts        237 lines  ✅ WORKING
│   ├── bump-validation.ts   206 lines  ✅ WORKING
│   ├── context-pack.ts      253 lines  ✅ WORKING
│   ├── gate-transitions.ts  294 lines  ✅ WORKING
│   ├── spiral-search.ts     295 lines  ✅ WORKING
│   └── wave-analysis.ts     302 lines  ✅ WORKING

Superseded Files (dist/)

dist/                        ~500 lines  📦 ARCHIVED (old implementation)

Broken Files

__tests__/tools.test.ts      127 lines  🔴 BROKEN (imports old arch)

Documentation Files

README.md                    ?   lines  📝 PARTIAL (claims ATOM-AUTH)
docs/data-flow.md            ?   lines  🟡 OUTDATED (adapters gone)
docs/flow.md                 ?   lines  🟡 OUTDATED (registry gone)
docs/testing-suite.md        ?   lines  🔴 BROKEN (tests don't work)
improve.md                   38  lines  ✅ ACCURATE

Appendix B: Decision Log

Why Rewrite?

Hypothesis: Old architecture was over-engineered for MCP use case.

Evidence:

  • Old: 500 lines across 20+ files
  • New: 400 lines main + 1,900 lines lib (better organized)
  • Old: External wave-toolkit dependency (deployment complexity)
  • New: Self-contained NLP (simpler)
  • Old: ATOM-AUTH (duplicates MCP auth layer)
  • New: No auth (trusts MCP client)

Outcome: ✅ Simpler deployment, ⚠️ lost security features

What Was Sacrificed?

  1. Modularity - Single src/index.ts vs distributed tools/
  2. Configurability - Hardcoded paths vs config system
  3. Security - No auth, rate limiting, audit logging
  4. Media integrations - Discord, Minecraft adapters gone
  5. Test coverage - 100% → 0%

What Was Gained?

  1. Real implementations - 10/10 tools now functional
  2. Self-contained - No external CLI dependencies
  3. Type safety - TypeScript vs plain JavaScript
  4. SpiralSafe integration - Direct file system + API access
  5. Better WAVE analysis - Statistical NLP vs simple heuristics

Conclusion

coherence-mcp has been successfully refactored from a modular, auth-heavy architecture to a streamlined, functional MCP server. Core tools work well, but critical infrastructure (tests, auth, docs) needs attention.

Overall Grade: 🟡 B+ Implementation, C- Production Readiness

Next Steps: Fix tests (P0), update docs (P0), restore auth (P1).


H&&S:WAVE - Gap analysis complete, ready for systematic remediation.