"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
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.
| 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 |
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)
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
| 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 |
| 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 |
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 EXISTImpact: npm test is broken. Zero test coverage for new implementations.
Status: 🔴 BLOCKING for production deployment
| 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.
| 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.
None! All 10 defined tools have real implementations.
| 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 | Exists in gate-transitions.ts but not exposed | |
| gate_learning_to_regeneration | Exists in gate-transitions.ts but not exposed |
Finding: 2 gates implemented but not exposed as tools. 7 tools removed entirely.
| 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 |
| 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 |
| 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 |
| 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 |
| 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 |
| Script | Status | Notes |
|---|---|---|
| scripts/benchmark.py | ✅ WORKING | Golden ratio chaos, Fibonacci scoring |
| scripts/smoke.mjs | Not analyzed (may reference old arch) | |
| improve.md | ✅ ACCURATE | Documents benchmark workflow |
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)
- Fix test suite - Rewrite
__tests__/tools.test.tsfor new architecture - Update README - Remove ATOM-AUTH diagrams, clarify what's implemented
- Expose missing gates - Add
gate_knowledge_to_intentionandgate_learning_to_regenerationto TOOLS array - Add .npmignore - Exclude dist/, tests/, src/ from package
- Add authentication - Implement MCP-level auth or bring back bearer tokens
- Add audit logging - Write tool invocations to
.atom-trail/audit.jsonl - Make paths configurable - Environment variables for SpiralSafe path, API URL
- Update docs/ - Rewrite for single-file architecture
- Add rate limiting - Per-tool invocation limits
- Restore Discord adapter - Rebuild for media pipeline
- Restore Minecraft adapter - Rebuild for Quantum Valley integration
- Add benchmarks - Performance tests for all tools
- Enable TypeScript strict mode - Fix type issues
- Add error boundaries - Prevent server crashes
For teams using the OLD architecture (dist/):
- Authentication: ATOM-AUTH removed. Use MCP client-level auth.
- Configuration:
config.jsremoved. Use environment variables. - Adapters: Discord/Minecraft removed. Tools not available.
- Resource registry: Removed. Use tool calls directly.
- Audit logging: Removed. Implement at client level.
# 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 rewriteFollowing the methodology from SpiralSafe/docs/USER_JOURNEY_GAP_ANALYSIS.md:
✅ 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
- Architectural comparison - Old vs new side-by-side
- Feature matrix - What was kept, removed, improved
- Test coverage analysis - Zero coverage identified
- SpiralSafe integration audit - Mount points, API calls
- Security audit - Auth removal flagged
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
dist/ ~500 lines 📦 ARCHIVED (old implementation)
__tests__/tools.test.ts 127 lines 🔴 BROKEN (imports old arch)
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
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,
- Modularity - Single src/index.ts vs distributed tools/
- Configurability - Hardcoded paths vs config system
- Security - No auth, rate limiting, audit logging
- Media integrations - Discord, Minecraft adapters gone
- Test coverage - 100% → 0%
- Real implementations - 10/10 tools now functional
- Self-contained - No external CLI dependencies
- Type safety - TypeScript vs plain JavaScript
- SpiralSafe integration - Direct file system + API access
- Better WAVE analysis - Statistical NLP vs simple heuristics
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.