mcp-adr-analysis-server 2.1.20 → 2.1.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/.tsbuildinfo +1 -1
- package/dist/src/config/ai-config.d.ts +54 -6
- package/dist/src/config/ai-config.d.ts.map +1 -1
- package/dist/src/config/ai-config.js +69 -6
- package/dist/src/config/ai-config.js.map +1 -1
- package/dist/src/config/ape-descriptions.d.ts +77 -0
- package/dist/src/config/ape-descriptions.d.ts.map +1 -0
- package/dist/src/config/ape-descriptions.js +177 -0
- package/dist/src/config/ape-descriptions.js.map +1 -0
- package/dist/src/index.d.ts +40 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +564 -8
- package/dist/src/index.js.map +1 -1
- package/dist/src/prompts/adr-suggestion-prompts.d.ts +5 -0
- package/dist/src/prompts/adr-suggestion-prompts.d.ts.map +1 -1
- package/dist/src/prompts/adr-suggestion-prompts.js +22 -1
- package/dist/src/prompts/adr-suggestion-prompts.js.map +1 -1
- package/dist/src/prompts/prompt-catalog.d.ts +95 -0
- package/dist/src/prompts/prompt-catalog.d.ts.map +1 -0
- package/dist/src/prompts/prompt-catalog.js +300 -0
- package/dist/src/prompts/prompt-catalog.js.map +1 -0
- package/dist/src/resources/adrs-discovered-resource.d.ts +124 -0
- package/dist/src/resources/adrs-discovered-resource.d.ts.map +1 -0
- package/dist/src/resources/adrs-discovered-resource.js +174 -0
- package/dist/src/resources/adrs-discovered-resource.js.map +1 -0
- package/dist/src/resources/adrs-review-resource.d.ts +82 -0
- package/dist/src/resources/adrs-review-resource.d.ts.map +1 -0
- package/dist/src/resources/adrs-review-resource.js +160 -0
- package/dist/src/resources/adrs-review-resource.js.map +1 -0
- package/dist/src/resources/architectural-context-resource.d.ts +95 -0
- package/dist/src/resources/architectural-context-resource.d.ts.map +1 -0
- package/dist/src/resources/architectural-context-resource.js +428 -0
- package/dist/src/resources/architectural-context-resource.js.map +1 -0
- package/dist/src/resources/conversation-snapshot-resource.d.ts +92 -0
- package/dist/src/resources/conversation-snapshot-resource.d.ts.map +1 -0
- package/dist/src/resources/conversation-snapshot-resource.js +122 -0
- package/dist/src/resources/conversation-snapshot-resource.js.map +1 -0
- package/dist/src/resources/deployment-status-resource.js +1 -1
- package/dist/src/resources/deployment-status-resource.js.map +1 -1
- package/dist/src/resources/environment-analysis-resource.js +1 -1
- package/dist/src/resources/environment-analysis-resource.js.map +1 -1
- package/dist/src/resources/knowledge-graph-resource.d.ts +129 -0
- package/dist/src/resources/knowledge-graph-resource.d.ts.map +1 -0
- package/dist/src/resources/knowledge-graph-resource.js +217 -0
- package/dist/src/resources/knowledge-graph-resource.js.map +1 -0
- package/dist/src/resources/memory-expand-resource.d.ts +90 -0
- package/dist/src/resources/memory-expand-resource.d.ts.map +1 -0
- package/dist/src/resources/memory-expand-resource.js +176 -0
- package/dist/src/resources/memory-expand-resource.js.map +1 -0
- package/dist/src/resources/memory-stats-resource.d.ts +77 -0
- package/dist/src/resources/memory-stats-resource.d.ts.map +1 -0
- package/dist/src/resources/memory-stats-resource.js +108 -0
- package/dist/src/resources/memory-stats-resource.js.map +1 -0
- package/dist/src/resources/project-metrics-resource.js +1 -1
- package/dist/src/resources/project-metrics-resource.js.map +1 -1
- package/dist/src/resources/resource-cache.d.ts.map +1 -1
- package/dist/src/resources/resource-cache.js +2 -1
- package/dist/src/resources/resource-cache.js.map +1 -1
- package/dist/src/resources/server-context-resource.d.ts +69 -0
- package/dist/src/resources/server-context-resource.d.ts.map +1 -0
- package/dist/src/resources/server-context-resource.js +104 -0
- package/dist/src/resources/server-context-resource.js.map +1 -0
- package/dist/src/resources/tool-catalog-resource.d.ts +122 -0
- package/dist/src/resources/tool-catalog-resource.d.ts.map +1 -0
- package/dist/src/resources/tool-catalog-resource.js +167 -0
- package/dist/src/resources/tool-catalog-resource.js.map +1 -0
- package/dist/src/tools/adr-bootstrap-validation-tool.d.ts.map +1 -1
- package/dist/src/tools/adr-bootstrap-validation-tool.js +7 -6
- package/dist/src/tools/adr-bootstrap-validation-tool.js.map +1 -1
- package/dist/src/tools/adr-suggestion-tool.d.ts +5 -0
- package/dist/src/tools/adr-suggestion-tool.d.ts.map +1 -1
- package/dist/src/tools/adr-suggestion-tool.js +40 -71
- package/dist/src/tools/adr-suggestion-tool.js.map +1 -1
- package/dist/src/tools/bootstrap-validation-loop-tool.d.ts +23 -1
- package/dist/src/tools/bootstrap-validation-loop-tool.d.ts.map +1 -1
- package/dist/src/tools/bootstrap-validation-loop-tool.js +15 -5
- package/dist/src/tools/bootstrap-validation-loop-tool.js.map +1 -1
- package/dist/src/tools/ce-mcp-tools.d.ts +291 -0
- package/dist/src/tools/ce-mcp-tools.d.ts.map +1 -0
- package/dist/src/tools/ce-mcp-tools.js +1188 -0
- package/dist/src/tools/ce-mcp-tools.js.map +1 -0
- package/dist/src/tools/content-masking-tool.d.ts +11 -0
- package/dist/src/tools/content-masking-tool.d.ts.map +1 -1
- package/dist/src/tools/content-masking-tool.js +13 -6
- package/dist/src/tools/content-masking-tool.js.map +1 -1
- package/dist/src/tools/deployment-readiness-tool.d.ts +11 -0
- package/dist/src/tools/deployment-readiness-tool.d.ts.map +1 -1
- package/dist/src/tools/deployment-readiness-tool.js +10 -4
- package/dist/src/tools/deployment-readiness-tool.js.map +1 -1
- package/dist/src/tools/environment-analysis-tool.d.ts +96 -1
- package/dist/src/tools/environment-analysis-tool.d.ts.map +1 -1
- package/dist/src/tools/environment-analysis-tool.js +38 -46
- package/dist/src/tools/environment-analysis-tool.js.map +1 -1
- package/dist/src/tools/research-question-tool.d.ts.map +1 -1
- package/dist/src/tools/research-question-tool.js +3 -2
- package/dist/src/tools/research-question-tool.js.map +1 -1
- package/dist/src/tools/review-existing-adrs-tool.d.ts +5 -0
- package/dist/src/tools/review-existing-adrs-tool.d.ts.map +1 -1
- package/dist/src/tools/review-existing-adrs-tool.js +123 -42
- package/dist/src/tools/review-existing-adrs-tool.js.map +1 -1
- package/dist/src/tools/rule-generation-tool.d.ts.map +1 -1
- package/dist/src/tools/rule-generation-tool.js +3 -5
- package/dist/src/tools/rule-generation-tool.js.map +1 -1
- package/dist/src/tools/search-codebase-tool.d.ts +148 -0
- package/dist/src/tools/search-codebase-tool.d.ts.map +1 -0
- package/dist/src/tools/search-codebase-tool.js +406 -0
- package/dist/src/tools/search-codebase-tool.js.map +1 -0
- package/dist/src/tools/smart-git-push-tool-v2.js +1 -1
- package/dist/src/tools/smart-git-push-tool-v2.js.map +1 -1
- package/dist/src/tools/tool-catalog.d.ts +134 -0
- package/dist/src/tools/tool-catalog.d.ts.map +1 -0
- package/dist/src/tools/tool-catalog.js +1431 -0
- package/dist/src/tools/tool-catalog.js.map +1 -0
- package/dist/src/tools/tool-chain-orchestrator.d.ts +11 -2
- package/dist/src/tools/tool-chain-orchestrator.d.ts.map +1 -1
- package/dist/src/tools/tool-chain-orchestrator.js +11 -2
- package/dist/src/tools/tool-chain-orchestrator.js.map +1 -1
- package/dist/src/tools/tool-dispatcher.d.ts +98 -0
- package/dist/src/tools/tool-dispatcher.d.ts.map +1 -0
- package/dist/src/tools/tool-dispatcher.js +225 -0
- package/dist/src/tools/tool-dispatcher.js.map +1 -0
- package/dist/src/tools/tree-sitter-code-tools.d.ts +184 -0
- package/dist/src/tools/tree-sitter-code-tools.d.ts.map +1 -0
- package/dist/src/tools/tree-sitter-code-tools.js +642 -0
- package/dist/src/tools/tree-sitter-code-tools.js.map +1 -0
- package/dist/src/tools/troubleshoot-guided-workflow-tool.d.ts +22 -0
- package/dist/src/tools/troubleshoot-guided-workflow-tool.d.ts.map +1 -1
- package/dist/src/tools/troubleshoot-guided-workflow-tool.js +20 -3
- package/dist/src/tools/troubleshoot-guided-workflow-tool.js.map +1 -1
- package/dist/src/tools/update-knowledge-tool.d.ts +89 -0
- package/dist/src/tools/update-knowledge-tool.d.ts.map +1 -0
- package/dist/src/tools/update-knowledge-tool.js +222 -0
- package/dist/src/tools/update-knowledge-tool.js.map +1 -0
- package/dist/src/types/ce-mcp.d.ts +248 -0
- package/dist/src/types/ce-mcp.d.ts.map +1 -0
- package/dist/src/types/ce-mcp.js +27 -0
- package/dist/src/types/ce-mcp.js.map +1 -0
- package/dist/src/utils/adr-context-detector.js +1 -1
- package/dist/src/utils/adr-context-detector.js.map +1 -1
- package/dist/src/utils/adr-planning-task-integration.d.ts +260 -0
- package/dist/src/utils/adr-planning-task-integration.d.ts.map +1 -0
- package/dist/src/utils/adr-planning-task-integration.js +466 -0
- package/dist/src/utils/adr-planning-task-integration.js.map +1 -0
- package/dist/src/utils/adr-timeline-extractor.d.ts.map +1 -1
- package/dist/src/utils/adr-timeline-extractor.js +3 -2
- package/dist/src/utils/adr-timeline-extractor.js.map +1 -1
- package/dist/src/utils/ai-executor.d.ts +10 -0
- package/dist/src/utils/ai-executor.d.ts.map +1 -1
- package/dist/src/utils/ai-executor.js +14 -3
- package/dist/src/utils/ai-executor.js.map +1 -1
- package/dist/src/utils/automatic-prompt-engineering.d.ts +5 -0
- package/dist/src/utils/automatic-prompt-engineering.d.ts.map +1 -1
- package/dist/src/utils/automatic-prompt-engineering.js +10 -90
- package/dist/src/utils/automatic-prompt-engineering.js.map +1 -1
- package/dist/src/utils/bootstrap-task-integration.d.ts +214 -0
- package/dist/src/utils/bootstrap-task-integration.d.ts.map +1 -0
- package/dist/src/utils/bootstrap-task-integration.js +365 -0
- package/dist/src/utils/bootstrap-task-integration.js.map +1 -0
- package/dist/src/utils/dag-executor.js +1 -1
- package/dist/src/utils/dag-executor.js.map +1 -1
- package/dist/src/utils/deployment-task-integration.d.ts +260 -0
- package/dist/src/utils/deployment-task-integration.d.ts.map +1 -0
- package/dist/src/utils/deployment-task-integration.js +393 -0
- package/dist/src/utils/deployment-task-integration.js.map +1 -0
- package/dist/src/utils/dynamic-deployment-intelligence.js +1 -1
- package/dist/src/utils/dynamic-deployment-intelligence.js.map +1 -1
- package/dist/src/utils/enhanced-logging.d.ts +3 -0
- package/dist/src/utils/enhanced-logging.d.ts.map +1 -1
- package/dist/src/utils/enhanced-logging.js +9 -30
- package/dist/src/utils/enhanced-logging.js.map +1 -1
- package/dist/src/utils/environment-capability-registry.js +1 -1
- package/dist/src/utils/environment-capability-registry.js.map +1 -1
- package/dist/src/utils/file-system.d.ts.map +1 -1
- package/dist/src/utils/file-system.js +33 -3
- package/dist/src/utils/file-system.js.map +1 -1
- package/dist/src/utils/gitleaks-detector.js +1 -1
- package/dist/src/utils/gitleaks-detector.js.map +1 -1
- package/dist/src/utils/knowledge-graph-manager.d.ts +13 -0
- package/dist/src/utils/knowledge-graph-manager.d.ts.map +1 -1
- package/dist/src/utils/knowledge-graph-manager.js +13 -0
- package/dist/src/utils/knowledge-graph-manager.js.map +1 -1
- package/dist/src/utils/prompt-execution.d.ts +29 -1
- package/dist/src/utils/prompt-execution.d.ts.map +1 -1
- package/dist/src/utils/prompt-execution.js +29 -1
- package/dist/src/utils/prompt-execution.js.map +1 -1
- package/dist/src/utils/research-orchestrator.d.ts +87 -1
- package/dist/src/utils/research-orchestrator.d.ts.map +1 -1
- package/dist/src/utils/research-orchestrator.js +121 -17
- package/dist/src/utils/research-orchestrator.js.map +1 -1
- package/dist/src/utils/research-task-integration.d.ts +297 -0
- package/dist/src/utils/research-task-integration.d.ts.map +1 -0
- package/dist/src/utils/research-task-integration.js +449 -0
- package/dist/src/utils/research-task-integration.js.map +1 -0
- package/dist/src/utils/ripgrep-wrapper.d.ts.map +1 -1
- package/dist/src/utils/ripgrep-wrapper.js +17 -3
- package/dist/src/utils/ripgrep-wrapper.js.map +1 -1
- package/dist/src/utils/sandbox-executor.d.ts +145 -0
- package/dist/src/utils/sandbox-executor.d.ts.map +1 -0
- package/dist/src/utils/sandbox-executor.js +642 -0
- package/dist/src/utils/sandbox-executor.js.map +1 -0
- package/dist/src/utils/server-context-generator.d.ts +5 -0
- package/dist/src/utils/server-context-generator.d.ts.map +1 -1
- package/dist/src/utils/server-context-generator.js +38 -0
- package/dist/src/utils/server-context-generator.js.map +1 -1
- package/dist/src/utils/task-manager.d.ts +239 -0
- package/dist/src/utils/task-manager.d.ts.map +1 -0
- package/dist/src/utils/task-manager.js +528 -0
- package/dist/src/utils/task-manager.js.map +1 -0
- package/dist/src/utils/task-persistence.d.ts +82 -0
- package/dist/src/utils/task-persistence.d.ts.map +1 -0
- package/dist/src/utils/task-persistence.js +248 -0
- package/dist/src/utils/task-persistence.js.map +1 -0
- package/dist/src/utils/test-aware-defaults.d.ts +57 -0
- package/dist/src/utils/test-aware-defaults.d.ts.map +1 -0
- package/dist/src/utils/test-aware-defaults.js +71 -0
- package/dist/src/utils/test-aware-defaults.js.map +1 -0
- package/dist/src/utils/tree-sitter-analyzer.d.ts +42 -5
- package/dist/src/utils/tree-sitter-analyzer.d.ts.map +1 -1
- package/dist/src/utils/tree-sitter-analyzer.js +499 -17
- package/dist/src/utils/tree-sitter-analyzer.js.map +1 -1
- package/package.json +24 -19
- package/dist/src/tools/smart-git-push-tool.d.ts +0 -55
- package/dist/src/tools/smart-git-push-tool.d.ts.map +0 -1
- package/dist/src/tools/smart-git-push-tool.js +0 -1011
- package/dist/src/tools/smart-git-push-tool.js.map +0 -1
|
@@ -0,0 +1,1188 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CE-MCP Tool Wrappers
|
|
3
|
+
*
|
|
4
|
+
* This module provides CE-MCP directive-based versions of high-token-cost tools.
|
|
5
|
+
* Instead of executing prompts directly with OpenRouter, these tools return
|
|
6
|
+
* orchestration directives that the host LLM can execute with minimal context.
|
|
7
|
+
*
|
|
8
|
+
* @see ADR-014: CE-MCP Architecture
|
|
9
|
+
* @see docs/IMPLEMENTATION-PLAN.md Phase 2
|
|
10
|
+
*/
|
|
11
|
+
import { getKnowledgeEnhancementDefault } from '../utils/test-aware-defaults.js';
|
|
12
|
+
/**
|
|
13
|
+
* CE-MCP version of analyzeProjectEcosystem
|
|
14
|
+
*
|
|
15
|
+
* Returns an orchestration directive instead of executing the analysis directly.
|
|
16
|
+
* This reduces token usage from ~12K to ~4K by:
|
|
17
|
+
* - Deferring context assembly to sandbox operations
|
|
18
|
+
* - Using lazy prompt loading
|
|
19
|
+
* - Eliminating intermediate LLM calls
|
|
20
|
+
*
|
|
21
|
+
* Token Savings Breakdown:
|
|
22
|
+
* - Knowledge generation: 3K → on-demand
|
|
23
|
+
* - Memory retrieval: 2K → on-demand
|
|
24
|
+
* - Environment analysis: 2.5K → on-demand
|
|
25
|
+
* - Project structure: 2K → on-demand
|
|
26
|
+
* - Reflexion context: 2K → on-demand
|
|
27
|
+
*/
|
|
28
|
+
export function createAnalyzeProjectEcosystemDirective(args) {
|
|
29
|
+
const { projectPath, analysisDepth = 'comprehensive', includeEnvironment = true, knowledgeEnhancement = getKnowledgeEnhancementDefault(), // Environment-aware default
|
|
30
|
+
// learningEnabled is used for future reflexion integration
|
|
31
|
+
learningEnabled: _learningEnabled = true, technologyFocus = [], analysisScope = [], } = args;
|
|
32
|
+
void _learningEnabled; // Mark as intentionally unused for now
|
|
33
|
+
const operations = [
|
|
34
|
+
// Phase 1: Load project structure
|
|
35
|
+
{
|
|
36
|
+
op: 'analyzeFiles',
|
|
37
|
+
args: {
|
|
38
|
+
patterns: ['**/*.ts', '**/*.js', '**/*.json', '**/*.yaml', '**/*.yml'],
|
|
39
|
+
maxFiles: analysisDepth === 'basic' ? 50 : analysisDepth === 'standard' ? 100 : 200,
|
|
40
|
+
},
|
|
41
|
+
store: 'projectFiles',
|
|
42
|
+
},
|
|
43
|
+
// Phase 2: Scan environment configuration
|
|
44
|
+
{
|
|
45
|
+
op: 'scanEnvironment',
|
|
46
|
+
store: 'environmentConfig',
|
|
47
|
+
},
|
|
48
|
+
// Phase 3: Load architectural knowledge (conditional on knowledgeEnhancement)
|
|
49
|
+
...(knowledgeEnhancement
|
|
50
|
+
? [
|
|
51
|
+
{
|
|
52
|
+
op: 'loadKnowledge',
|
|
53
|
+
args: {
|
|
54
|
+
domain: 'architecture',
|
|
55
|
+
scope: 'project',
|
|
56
|
+
technologies: technologyFocus,
|
|
57
|
+
},
|
|
58
|
+
store: 'architecturalKnowledge',
|
|
59
|
+
},
|
|
60
|
+
]
|
|
61
|
+
: []),
|
|
62
|
+
// Phase 4: Load analysis prompt (lazy loading)
|
|
63
|
+
{
|
|
64
|
+
op: 'loadPrompt',
|
|
65
|
+
args: {
|
|
66
|
+
name: 'analysis',
|
|
67
|
+
section: 'project_analysis',
|
|
68
|
+
},
|
|
69
|
+
store: 'analysisPrompt',
|
|
70
|
+
},
|
|
71
|
+
// Phase 5: Generate combined context
|
|
72
|
+
{
|
|
73
|
+
op: 'generateContext',
|
|
74
|
+
args: {
|
|
75
|
+
type: 'ecosystem-analysis',
|
|
76
|
+
depth: analysisDepth,
|
|
77
|
+
includeEnvironment,
|
|
78
|
+
technologyFocus,
|
|
79
|
+
analysisScope,
|
|
80
|
+
},
|
|
81
|
+
inputs: ['projectFiles', 'environmentConfig', 'architecturalKnowledge', 'analysisPrompt'],
|
|
82
|
+
store: 'analysisContext',
|
|
83
|
+
},
|
|
84
|
+
// Phase 6: Cache the context for potential reuse
|
|
85
|
+
{
|
|
86
|
+
op: 'cacheResult',
|
|
87
|
+
args: {
|
|
88
|
+
key: `ecosystem-analysis:${projectPath}:${analysisDepth}`,
|
|
89
|
+
ttl: 3600, // 1 hour cache
|
|
90
|
+
},
|
|
91
|
+
input: 'analysisContext',
|
|
92
|
+
},
|
|
93
|
+
// Phase 7: Compose final result
|
|
94
|
+
{
|
|
95
|
+
op: 'composeResult',
|
|
96
|
+
inputs: ['projectFiles', 'environmentConfig', 'architecturalKnowledge', 'analysisContext'],
|
|
97
|
+
return: true,
|
|
98
|
+
},
|
|
99
|
+
];
|
|
100
|
+
return {
|
|
101
|
+
type: 'orchestration_directive',
|
|
102
|
+
version: '1.0',
|
|
103
|
+
tool: 'analyze_project_ecosystem',
|
|
104
|
+
description: `Comprehensive ecosystem analysis for ${projectPath} with ${analysisDepth} depth`,
|
|
105
|
+
sandbox_operations: operations,
|
|
106
|
+
compose: {
|
|
107
|
+
sections: [
|
|
108
|
+
{ source: 'projectFiles', key: 'projectStructure', transform: 'summarize' },
|
|
109
|
+
{ source: 'environmentConfig', key: 'environment' },
|
|
110
|
+
{ source: 'architecturalKnowledge', key: 'knowledge', transform: 'extract' },
|
|
111
|
+
{ source: 'analysisContext', key: 'analysisContext' },
|
|
112
|
+
],
|
|
113
|
+
template: 'ecosystem_analysis_report',
|
|
114
|
+
format: 'markdown',
|
|
115
|
+
},
|
|
116
|
+
output_schema: {
|
|
117
|
+
type: 'object',
|
|
118
|
+
properties: {
|
|
119
|
+
projectStructure: {
|
|
120
|
+
type: 'object',
|
|
121
|
+
description: 'Summary of project files and structure',
|
|
122
|
+
},
|
|
123
|
+
environment: {
|
|
124
|
+
type: 'object',
|
|
125
|
+
description: 'Environment configuration analysis',
|
|
126
|
+
},
|
|
127
|
+
knowledge: {
|
|
128
|
+
type: 'object',
|
|
129
|
+
description: 'Architectural knowledge context',
|
|
130
|
+
},
|
|
131
|
+
analysisContext: {
|
|
132
|
+
type: 'object',
|
|
133
|
+
description: 'Combined analysis context',
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
metadata: {
|
|
138
|
+
estimated_tokens: 4000, // Down from ~12K
|
|
139
|
+
complexity: 'high',
|
|
140
|
+
cacheable: true,
|
|
141
|
+
cache_key: `ecosystem-${projectPath}-${analysisDepth}`,
|
|
142
|
+
},
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* CE-MCP version of suggest_adrs
|
|
147
|
+
*
|
|
148
|
+
* Returns a state machine directive for multi-step ADR generation.
|
|
149
|
+
* Reduces token usage from ~3.5K to ~1.5K by:
|
|
150
|
+
* - Lazy loading ADR templates
|
|
151
|
+
* - Deferring code analysis to sandbox
|
|
152
|
+
* - Using state machine for sequential steps
|
|
153
|
+
*/
|
|
154
|
+
export function createSuggestAdrsDirective(args) {
|
|
155
|
+
const { projectPath, codeChanges, focusAreas = [], maxSuggestions = 5 } = args;
|
|
156
|
+
return {
|
|
157
|
+
type: 'state_machine_directive',
|
|
158
|
+
version: '1.0',
|
|
159
|
+
initial_state: {
|
|
160
|
+
projectPath,
|
|
161
|
+
codeChanges,
|
|
162
|
+
focusAreas,
|
|
163
|
+
maxSuggestions,
|
|
164
|
+
suggestions: [],
|
|
165
|
+
},
|
|
166
|
+
transitions: [
|
|
167
|
+
{
|
|
168
|
+
name: 'load_adr_knowledge',
|
|
169
|
+
from: 'initial',
|
|
170
|
+
operation: {
|
|
171
|
+
op: 'loadKnowledge',
|
|
172
|
+
args: { domain: 'adr', scope: 'project' },
|
|
173
|
+
store: 'adrKnowledge',
|
|
174
|
+
},
|
|
175
|
+
next_state: 'knowledge_loaded',
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
name: 'analyze_codebase',
|
|
179
|
+
from: 'knowledge_loaded',
|
|
180
|
+
operation: {
|
|
181
|
+
op: 'analyzeFiles',
|
|
182
|
+
args: {
|
|
183
|
+
patterns: ['**/*.ts', '**/*.js'],
|
|
184
|
+
maxFiles: 100,
|
|
185
|
+
},
|
|
186
|
+
store: 'codeAnalysis',
|
|
187
|
+
},
|
|
188
|
+
next_state: 'code_analyzed',
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
name: 'load_adr_template',
|
|
192
|
+
from: 'code_analyzed',
|
|
193
|
+
operation: {
|
|
194
|
+
op: 'loadPrompt',
|
|
195
|
+
args: {
|
|
196
|
+
name: 'adr-suggestion',
|
|
197
|
+
section: 'recommendation_template',
|
|
198
|
+
},
|
|
199
|
+
store: 'adrTemplate',
|
|
200
|
+
},
|
|
201
|
+
next_state: 'template_loaded',
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
name: 'generate_suggestions',
|
|
205
|
+
from: 'template_loaded',
|
|
206
|
+
operation: {
|
|
207
|
+
op: 'generateContext',
|
|
208
|
+
args: {
|
|
209
|
+
type: 'adr-suggestions',
|
|
210
|
+
maxSuggestions,
|
|
211
|
+
focusAreas,
|
|
212
|
+
},
|
|
213
|
+
inputs: ['adrKnowledge', 'codeAnalysis', 'adrTemplate'],
|
|
214
|
+
store: 'suggestions',
|
|
215
|
+
},
|
|
216
|
+
next_state: 'suggestions_generated',
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
name: 'validate_suggestions',
|
|
220
|
+
from: 'suggestions_generated',
|
|
221
|
+
operation: {
|
|
222
|
+
op: 'validateOutput',
|
|
223
|
+
args: {
|
|
224
|
+
schema: {
|
|
225
|
+
type: 'array',
|
|
226
|
+
items: { type: 'object' },
|
|
227
|
+
},
|
|
228
|
+
},
|
|
229
|
+
input: 'suggestions',
|
|
230
|
+
store: 'validatedSuggestions',
|
|
231
|
+
},
|
|
232
|
+
next_state: 'done',
|
|
233
|
+
on_error: 'skip',
|
|
234
|
+
},
|
|
235
|
+
],
|
|
236
|
+
final_state: 'done',
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* CE-MCP version of generate_rules
|
|
241
|
+
*
|
|
242
|
+
* Returns an orchestration directive for rule generation.
|
|
243
|
+
* Reduces token usage from ~4K to ~1.5K by:
|
|
244
|
+
* - Lazy loading rule templates
|
|
245
|
+
* - Deferring validation to sandbox
|
|
246
|
+
* - Caching generated rules
|
|
247
|
+
*/
|
|
248
|
+
export function createGenerateRulesDirective(args) {
|
|
249
|
+
const { projectPath, ruleType, targetFramework, severity = 'warning' } = args;
|
|
250
|
+
return {
|
|
251
|
+
type: 'orchestration_directive',
|
|
252
|
+
version: '1.0',
|
|
253
|
+
tool: 'generate_rules',
|
|
254
|
+
description: `Generate ${ruleType} rules for ${projectPath}`,
|
|
255
|
+
sandbox_operations: [
|
|
256
|
+
{
|
|
257
|
+
op: 'loadKnowledge',
|
|
258
|
+
args: {
|
|
259
|
+
domain: ruleType,
|
|
260
|
+
scope: 'rules',
|
|
261
|
+
},
|
|
262
|
+
store: 'ruleKnowledge',
|
|
263
|
+
},
|
|
264
|
+
{
|
|
265
|
+
op: 'loadPrompt',
|
|
266
|
+
args: {
|
|
267
|
+
name: 'rule-generation',
|
|
268
|
+
section: 'rule_template',
|
|
269
|
+
},
|
|
270
|
+
store: 'ruleTemplate',
|
|
271
|
+
},
|
|
272
|
+
{
|
|
273
|
+
op: 'analyzeFiles',
|
|
274
|
+
args: {
|
|
275
|
+
patterns: targetFramework
|
|
276
|
+
? [`**/*.${targetFramework === 'typescript' ? 'ts' : 'js'}`]
|
|
277
|
+
: ['**/*.ts', '**/*.js'],
|
|
278
|
+
maxFiles: 50,
|
|
279
|
+
},
|
|
280
|
+
store: 'codePatterns',
|
|
281
|
+
},
|
|
282
|
+
{
|
|
283
|
+
op: 'generateContext',
|
|
284
|
+
args: {
|
|
285
|
+
type: 'rule-generation',
|
|
286
|
+
ruleType,
|
|
287
|
+
severity,
|
|
288
|
+
targetFramework,
|
|
289
|
+
},
|
|
290
|
+
inputs: ['ruleKnowledge', 'ruleTemplate', 'codePatterns'],
|
|
291
|
+
store: 'rules',
|
|
292
|
+
},
|
|
293
|
+
{
|
|
294
|
+
op: 'validateOutput',
|
|
295
|
+
args: {
|
|
296
|
+
schema: {
|
|
297
|
+
type: 'object',
|
|
298
|
+
properties: {
|
|
299
|
+
rules: { type: 'array' },
|
|
300
|
+
},
|
|
301
|
+
},
|
|
302
|
+
},
|
|
303
|
+
input: 'rules',
|
|
304
|
+
store: 'validatedRules',
|
|
305
|
+
},
|
|
306
|
+
{
|
|
307
|
+
op: 'cacheResult',
|
|
308
|
+
args: {
|
|
309
|
+
key: `rules:${projectPath}:${ruleType}`,
|
|
310
|
+
ttl: 7200, // 2 hour cache
|
|
311
|
+
},
|
|
312
|
+
input: 'validatedRules',
|
|
313
|
+
},
|
|
314
|
+
{
|
|
315
|
+
op: 'composeResult',
|
|
316
|
+
input: 'validatedRules',
|
|
317
|
+
return: true,
|
|
318
|
+
},
|
|
319
|
+
],
|
|
320
|
+
metadata: {
|
|
321
|
+
estimated_tokens: 1500,
|
|
322
|
+
complexity: 'medium',
|
|
323
|
+
cacheable: true,
|
|
324
|
+
cache_key: `rules-${ruleType}-${projectPath}`,
|
|
325
|
+
},
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* CE-MCP version of analyze_environment
|
|
330
|
+
*
|
|
331
|
+
* Returns an orchestration directive for environment analysis.
|
|
332
|
+
* Reduces token usage from ~2.5K to ~1K by:
|
|
333
|
+
* - Deferring file scanning to sandbox
|
|
334
|
+
* - Using cached environment patterns
|
|
335
|
+
* - Lazy loading environment prompts
|
|
336
|
+
*/
|
|
337
|
+
export function createAnalyzeEnvironmentDirective(args) {
|
|
338
|
+
const { projectPath, analysisType = 'standard', includeInfrastructure = true } = args;
|
|
339
|
+
return {
|
|
340
|
+
type: 'orchestration_directive',
|
|
341
|
+
version: '1.0',
|
|
342
|
+
tool: 'analyze_environment',
|
|
343
|
+
description: `Analyze environment for ${projectPath} (${analysisType})`,
|
|
344
|
+
sandbox_operations: [
|
|
345
|
+
{
|
|
346
|
+
op: 'scanEnvironment',
|
|
347
|
+
store: 'envConfig',
|
|
348
|
+
},
|
|
349
|
+
{
|
|
350
|
+
op: 'analyzeFiles',
|
|
351
|
+
args: {
|
|
352
|
+
patterns: [
|
|
353
|
+
'Dockerfile*',
|
|
354
|
+
'docker-compose*.yml',
|
|
355
|
+
'*.yaml',
|
|
356
|
+
'.env*',
|
|
357
|
+
'package.json',
|
|
358
|
+
'tsconfig.json',
|
|
359
|
+
],
|
|
360
|
+
maxFiles: 20,
|
|
361
|
+
},
|
|
362
|
+
store: 'configFiles',
|
|
363
|
+
},
|
|
364
|
+
// Only load infrastructure prompt if includeInfrastructure is true
|
|
365
|
+
...(includeInfrastructure
|
|
366
|
+
? [
|
|
367
|
+
{
|
|
368
|
+
op: 'loadPrompt',
|
|
369
|
+
args: {
|
|
370
|
+
name: 'environment-analysis',
|
|
371
|
+
section: analysisType === 'comprehensive' ? 'infrastructure_review' : 'config_validation',
|
|
372
|
+
},
|
|
373
|
+
store: 'envPrompt',
|
|
374
|
+
},
|
|
375
|
+
]
|
|
376
|
+
: []),
|
|
377
|
+
{
|
|
378
|
+
op: 'generateContext',
|
|
379
|
+
args: {
|
|
380
|
+
type: 'environment-analysis',
|
|
381
|
+
analysisType,
|
|
382
|
+
includeInfrastructure,
|
|
383
|
+
},
|
|
384
|
+
inputs: ['envConfig', 'configFiles', 'envPrompt'],
|
|
385
|
+
store: 'envAnalysis',
|
|
386
|
+
},
|
|
387
|
+
{
|
|
388
|
+
op: 'composeResult',
|
|
389
|
+
input: 'envAnalysis',
|
|
390
|
+
return: true,
|
|
391
|
+
},
|
|
392
|
+
],
|
|
393
|
+
compose: {
|
|
394
|
+
sections: [
|
|
395
|
+
{ source: 'envConfig', key: 'configuration' },
|
|
396
|
+
{ source: 'configFiles', key: 'configurationFiles' },
|
|
397
|
+
{ source: 'envAnalysis', key: 'analysis' },
|
|
398
|
+
],
|
|
399
|
+
template: 'environment_report',
|
|
400
|
+
format: 'markdown',
|
|
401
|
+
},
|
|
402
|
+
metadata: {
|
|
403
|
+
estimated_tokens: 1000,
|
|
404
|
+
complexity: 'low',
|
|
405
|
+
cacheable: true,
|
|
406
|
+
cache_key: `env-${projectPath}-${analysisType}`,
|
|
407
|
+
},
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* CE-MCP version of deployment_readiness
|
|
412
|
+
*
|
|
413
|
+
* Returns a state machine directive for deployment checks.
|
|
414
|
+
* Reduces token usage from ~2K to ~800 tokens by:
|
|
415
|
+
* - Sequential check execution in state machine
|
|
416
|
+
* - Lazy loading of deployment patterns
|
|
417
|
+
* - Early termination on critical failures
|
|
418
|
+
*/
|
|
419
|
+
export function createDeploymentReadinessDirective(args) {
|
|
420
|
+
const { projectPath, targetEnvironment, checkTypes = ['dependencies', 'tests', 'security', 'configuration'], } = args;
|
|
421
|
+
return {
|
|
422
|
+
type: 'state_machine_directive',
|
|
423
|
+
version: '1.0',
|
|
424
|
+
initial_state: {
|
|
425
|
+
projectPath,
|
|
426
|
+
targetEnvironment,
|
|
427
|
+
checkTypes,
|
|
428
|
+
results: {},
|
|
429
|
+
passed: true,
|
|
430
|
+
},
|
|
431
|
+
transitions: [
|
|
432
|
+
{
|
|
433
|
+
name: 'scan_environment',
|
|
434
|
+
from: 'initial',
|
|
435
|
+
operation: {
|
|
436
|
+
op: 'scanEnvironment',
|
|
437
|
+
store: 'envScan',
|
|
438
|
+
},
|
|
439
|
+
next_state: 'env_scanned',
|
|
440
|
+
},
|
|
441
|
+
{
|
|
442
|
+
name: 'load_deployment_patterns',
|
|
443
|
+
from: 'env_scanned',
|
|
444
|
+
operation: {
|
|
445
|
+
op: 'loadPrompt',
|
|
446
|
+
args: {
|
|
447
|
+
name: 'deployment-analysis',
|
|
448
|
+
section: 'validation_criteria',
|
|
449
|
+
},
|
|
450
|
+
store: 'deploymentPatterns',
|
|
451
|
+
},
|
|
452
|
+
next_state: 'patterns_loaded',
|
|
453
|
+
},
|
|
454
|
+
{
|
|
455
|
+
name: 'analyze_configuration',
|
|
456
|
+
from: 'patterns_loaded',
|
|
457
|
+
operation: {
|
|
458
|
+
op: 'analyzeFiles',
|
|
459
|
+
args: {
|
|
460
|
+
patterns: ['package.json', 'tsconfig.json', '.env*', 'Dockerfile*'],
|
|
461
|
+
maxFiles: 10,
|
|
462
|
+
},
|
|
463
|
+
store: 'configAnalysis',
|
|
464
|
+
},
|
|
465
|
+
next_state: 'config_analyzed',
|
|
466
|
+
},
|
|
467
|
+
{
|
|
468
|
+
name: 'validate_readiness',
|
|
469
|
+
from: 'config_analyzed',
|
|
470
|
+
operation: {
|
|
471
|
+
op: 'validateOutput',
|
|
472
|
+
args: {
|
|
473
|
+
schema: {
|
|
474
|
+
type: 'object',
|
|
475
|
+
required: ['ready', 'checks'],
|
|
476
|
+
},
|
|
477
|
+
},
|
|
478
|
+
inputs: ['envScan', 'configAnalysis', 'deploymentPatterns'],
|
|
479
|
+
store: 'readinessResult',
|
|
480
|
+
},
|
|
481
|
+
next_state: 'validated',
|
|
482
|
+
on_error: 'abort',
|
|
483
|
+
},
|
|
484
|
+
{
|
|
485
|
+
name: 'cache_result',
|
|
486
|
+
from: 'validated',
|
|
487
|
+
operation: {
|
|
488
|
+
op: 'cacheResult',
|
|
489
|
+
args: {
|
|
490
|
+
key: `deployment-readiness:${projectPath}:${targetEnvironment}`,
|
|
491
|
+
ttl: 1800, // 30 minute cache
|
|
492
|
+
},
|
|
493
|
+
input: 'readinessResult',
|
|
494
|
+
},
|
|
495
|
+
next_state: 'done',
|
|
496
|
+
on_error: 'skip',
|
|
497
|
+
},
|
|
498
|
+
],
|
|
499
|
+
final_state: 'done',
|
|
500
|
+
};
|
|
501
|
+
}
|
|
502
|
+
/**
|
|
503
|
+
* CE-MCP version of smart_score
|
|
504
|
+
*
|
|
505
|
+
* Returns an orchestration directive for code quality scoring.
|
|
506
|
+
* Reduces token usage from ~6K to ~2K by:
|
|
507
|
+
* - Lazy loading scoring templates
|
|
508
|
+
* - Deferring file analysis to sandbox
|
|
509
|
+
* - Caching scoring results
|
|
510
|
+
*/
|
|
511
|
+
export function createSmartScoreDirective(args) {
|
|
512
|
+
const { projectPath, includeDetails = true, scoringAreas = [] } = args;
|
|
513
|
+
return {
|
|
514
|
+
type: 'orchestration_directive',
|
|
515
|
+
version: '1.0',
|
|
516
|
+
tool: 'smart_score',
|
|
517
|
+
description: `Calculate code quality scores for ${projectPath}`,
|
|
518
|
+
sandbox_operations: [
|
|
519
|
+
{
|
|
520
|
+
op: 'analyzeFiles',
|
|
521
|
+
args: {
|
|
522
|
+
patterns: ['**/*.ts', '**/*.js', '**/*.json'],
|
|
523
|
+
maxFiles: 100,
|
|
524
|
+
},
|
|
525
|
+
store: 'codeFiles',
|
|
526
|
+
},
|
|
527
|
+
{
|
|
528
|
+
op: 'loadKnowledge',
|
|
529
|
+
args: {
|
|
530
|
+
domain: 'code-quality',
|
|
531
|
+
scope: 'scoring',
|
|
532
|
+
},
|
|
533
|
+
store: 'scoringKnowledge',
|
|
534
|
+
},
|
|
535
|
+
{
|
|
536
|
+
op: 'loadPrompt',
|
|
537
|
+
args: {
|
|
538
|
+
name: 'analysis',
|
|
539
|
+
section: 'quality_metrics',
|
|
540
|
+
},
|
|
541
|
+
store: 'scoringPrompt',
|
|
542
|
+
},
|
|
543
|
+
{
|
|
544
|
+
op: 'generateContext',
|
|
545
|
+
args: {
|
|
546
|
+
type: 'smart-score',
|
|
547
|
+
includeDetails,
|
|
548
|
+
scoringAreas,
|
|
549
|
+
},
|
|
550
|
+
inputs: ['codeFiles', 'scoringKnowledge', 'scoringPrompt'],
|
|
551
|
+
store: 'scoreResults',
|
|
552
|
+
},
|
|
553
|
+
{
|
|
554
|
+
op: 'cacheResult',
|
|
555
|
+
args: {
|
|
556
|
+
key: `smart-score:${projectPath}`,
|
|
557
|
+
ttl: 3600,
|
|
558
|
+
},
|
|
559
|
+
input: 'scoreResults',
|
|
560
|
+
},
|
|
561
|
+
{
|
|
562
|
+
op: 'composeResult',
|
|
563
|
+
input: 'scoreResults',
|
|
564
|
+
return: true,
|
|
565
|
+
},
|
|
566
|
+
],
|
|
567
|
+
compose: {
|
|
568
|
+
sections: [
|
|
569
|
+
{ source: 'codeFiles', key: 'analyzedFiles', transform: 'summarize' },
|
|
570
|
+
{ source: 'scoreResults', key: 'scores' },
|
|
571
|
+
],
|
|
572
|
+
template: 'quality_score_report',
|
|
573
|
+
format: 'markdown',
|
|
574
|
+
},
|
|
575
|
+
metadata: {
|
|
576
|
+
estimated_tokens: 2000,
|
|
577
|
+
complexity: 'medium',
|
|
578
|
+
cacheable: true,
|
|
579
|
+
cache_key: `score-${projectPath}`,
|
|
580
|
+
},
|
|
581
|
+
};
|
|
582
|
+
}
|
|
583
|
+
/**
|
|
584
|
+
* CE-MCP version of perform_research
|
|
585
|
+
*
|
|
586
|
+
* Returns a state machine directive for research workflows.
|
|
587
|
+
* Reduces token usage from ~10K to ~3K by:
|
|
588
|
+
* - Lazy loading research templates
|
|
589
|
+
* - Sequential research phases in state machine
|
|
590
|
+
* - Caching intermediate results
|
|
591
|
+
*/
|
|
592
|
+
export function createPerformResearchDirective(args) {
|
|
593
|
+
const { topic, depth = 'standard', outputFormat = 'detailed', sources = [] } = args;
|
|
594
|
+
return {
|
|
595
|
+
type: 'state_machine_directive',
|
|
596
|
+
version: '1.0',
|
|
597
|
+
initial_state: {
|
|
598
|
+
topic,
|
|
599
|
+
depth,
|
|
600
|
+
outputFormat,
|
|
601
|
+
sources,
|
|
602
|
+
findings: [],
|
|
603
|
+
},
|
|
604
|
+
transitions: [
|
|
605
|
+
{
|
|
606
|
+
name: 'load_research_template',
|
|
607
|
+
from: 'initial',
|
|
608
|
+
operation: {
|
|
609
|
+
op: 'loadPrompt',
|
|
610
|
+
args: {
|
|
611
|
+
name: 'research-question',
|
|
612
|
+
section: 'research_plan',
|
|
613
|
+
},
|
|
614
|
+
store: 'researchTemplate',
|
|
615
|
+
},
|
|
616
|
+
next_state: 'template_loaded',
|
|
617
|
+
},
|
|
618
|
+
{
|
|
619
|
+
name: 'generate_research_questions',
|
|
620
|
+
from: 'template_loaded',
|
|
621
|
+
operation: {
|
|
622
|
+
op: 'generateContext',
|
|
623
|
+
args: {
|
|
624
|
+
type: 'research-questions',
|
|
625
|
+
topic,
|
|
626
|
+
depth,
|
|
627
|
+
},
|
|
628
|
+
inputs: ['researchTemplate'],
|
|
629
|
+
store: 'researchQuestions',
|
|
630
|
+
},
|
|
631
|
+
next_state: 'questions_generated',
|
|
632
|
+
},
|
|
633
|
+
{
|
|
634
|
+
name: 'load_knowledge_base',
|
|
635
|
+
from: 'questions_generated',
|
|
636
|
+
operation: {
|
|
637
|
+
op: 'loadKnowledge',
|
|
638
|
+
args: {
|
|
639
|
+
domain: 'research',
|
|
640
|
+
scope: topic,
|
|
641
|
+
},
|
|
642
|
+
store: 'knowledgeBase',
|
|
643
|
+
},
|
|
644
|
+
next_state: 'knowledge_loaded',
|
|
645
|
+
},
|
|
646
|
+
{
|
|
647
|
+
name: 'synthesize_findings',
|
|
648
|
+
from: 'knowledge_loaded',
|
|
649
|
+
operation: {
|
|
650
|
+
op: 'generateContext',
|
|
651
|
+
args: {
|
|
652
|
+
type: 'research-synthesis',
|
|
653
|
+
outputFormat,
|
|
654
|
+
},
|
|
655
|
+
inputs: ['researchQuestions', 'knowledgeBase'],
|
|
656
|
+
store: 'findings',
|
|
657
|
+
},
|
|
658
|
+
next_state: 'synthesized',
|
|
659
|
+
},
|
|
660
|
+
{
|
|
661
|
+
name: 'format_output',
|
|
662
|
+
from: 'synthesized',
|
|
663
|
+
operation: {
|
|
664
|
+
op: 'composeResult',
|
|
665
|
+
inputs: ['findings', 'researchQuestions'],
|
|
666
|
+
return: true,
|
|
667
|
+
},
|
|
668
|
+
next_state: 'done',
|
|
669
|
+
},
|
|
670
|
+
],
|
|
671
|
+
final_state: 'done',
|
|
672
|
+
};
|
|
673
|
+
}
|
|
674
|
+
/**
|
|
675
|
+
* CE-MCP version of generate_adrs_from_prd
|
|
676
|
+
*
|
|
677
|
+
* Returns a state machine directive for PRD-to-ADR generation.
|
|
678
|
+
* Reduces token usage from ~8K to ~3K by:
|
|
679
|
+
* - Lazy loading ADR templates
|
|
680
|
+
* - Sequential PRD analysis phases
|
|
681
|
+
* - Caching parsed PRD content
|
|
682
|
+
*/
|
|
683
|
+
export function createGenerateAdrsFromPrdDirective(args) {
|
|
684
|
+
const { prdPath, outputDirectory = 'docs/adrs', maxAdrs = 10, focusAreas = [] } = args;
|
|
685
|
+
return {
|
|
686
|
+
type: 'state_machine_directive',
|
|
687
|
+
version: '1.0',
|
|
688
|
+
initial_state: {
|
|
689
|
+
prdPath,
|
|
690
|
+
outputDirectory,
|
|
691
|
+
maxAdrs,
|
|
692
|
+
focusAreas,
|
|
693
|
+
generatedAdrs: [],
|
|
694
|
+
},
|
|
695
|
+
transitions: [
|
|
696
|
+
{
|
|
697
|
+
name: 'read_prd',
|
|
698
|
+
from: 'initial',
|
|
699
|
+
operation: {
|
|
700
|
+
op: 'analyzeFiles',
|
|
701
|
+
args: {
|
|
702
|
+
patterns: [prdPath],
|
|
703
|
+
maxFiles: 1,
|
|
704
|
+
},
|
|
705
|
+
store: 'prdContent',
|
|
706
|
+
},
|
|
707
|
+
next_state: 'prd_loaded',
|
|
708
|
+
},
|
|
709
|
+
{
|
|
710
|
+
name: 'load_adr_template',
|
|
711
|
+
from: 'prd_loaded',
|
|
712
|
+
operation: {
|
|
713
|
+
op: 'loadPrompt',
|
|
714
|
+
args: {
|
|
715
|
+
name: 'adr-suggestion',
|
|
716
|
+
section: 'recommendation_template',
|
|
717
|
+
},
|
|
718
|
+
store: 'adrTemplate',
|
|
719
|
+
},
|
|
720
|
+
next_state: 'template_loaded',
|
|
721
|
+
},
|
|
722
|
+
{
|
|
723
|
+
name: 'extract_decisions',
|
|
724
|
+
from: 'template_loaded',
|
|
725
|
+
operation: {
|
|
726
|
+
op: 'generateContext',
|
|
727
|
+
args: {
|
|
728
|
+
type: 'prd-decision-extraction',
|
|
729
|
+
maxAdrs,
|
|
730
|
+
focusAreas,
|
|
731
|
+
},
|
|
732
|
+
inputs: ['prdContent', 'adrTemplate'],
|
|
733
|
+
store: 'extractedDecisions',
|
|
734
|
+
},
|
|
735
|
+
next_state: 'decisions_extracted',
|
|
736
|
+
},
|
|
737
|
+
{
|
|
738
|
+
name: 'generate_adrs',
|
|
739
|
+
from: 'decisions_extracted',
|
|
740
|
+
operation: {
|
|
741
|
+
op: 'generateContext',
|
|
742
|
+
args: {
|
|
743
|
+
type: 'adr-generation',
|
|
744
|
+
outputDirectory,
|
|
745
|
+
},
|
|
746
|
+
inputs: ['extractedDecisions', 'adrTemplate'],
|
|
747
|
+
store: 'generatedAdrs',
|
|
748
|
+
},
|
|
749
|
+
next_state: 'adrs_generated',
|
|
750
|
+
},
|
|
751
|
+
{
|
|
752
|
+
name: 'validate_adrs',
|
|
753
|
+
from: 'adrs_generated',
|
|
754
|
+
operation: {
|
|
755
|
+
op: 'validateOutput',
|
|
756
|
+
args: {
|
|
757
|
+
schema: {
|
|
758
|
+
type: 'array',
|
|
759
|
+
items: { type: 'object' },
|
|
760
|
+
},
|
|
761
|
+
},
|
|
762
|
+
input: 'generatedAdrs',
|
|
763
|
+
store: 'validatedAdrs',
|
|
764
|
+
},
|
|
765
|
+
next_state: 'done',
|
|
766
|
+
on_error: 'skip',
|
|
767
|
+
},
|
|
768
|
+
],
|
|
769
|
+
final_state: 'done',
|
|
770
|
+
};
|
|
771
|
+
}
|
|
772
|
+
/**
|
|
773
|
+
* CE-MCP version of interactive_adr_planning
|
|
774
|
+
*
|
|
775
|
+
* Returns a state machine directive for interactive ADR sessions.
|
|
776
|
+
* Reduces token usage from ~6K to ~2K by:
|
|
777
|
+
* - Lazy loading planning templates
|
|
778
|
+
* - Sequential planning phases
|
|
779
|
+
* - Context-aware suggestions
|
|
780
|
+
*/
|
|
781
|
+
export function createInteractiveAdrPlanningDirective(args) {
|
|
782
|
+
const { projectPath, sessionMode = 'guided', existingAdrs = [] } = args;
|
|
783
|
+
return {
|
|
784
|
+
type: 'state_machine_directive',
|
|
785
|
+
version: '1.0',
|
|
786
|
+
initial_state: {
|
|
787
|
+
projectPath,
|
|
788
|
+
sessionMode,
|
|
789
|
+
existingAdrs,
|
|
790
|
+
suggestions: [],
|
|
791
|
+
priorities: [],
|
|
792
|
+
},
|
|
793
|
+
transitions: [
|
|
794
|
+
{
|
|
795
|
+
name: 'analyze_project',
|
|
796
|
+
from: 'initial',
|
|
797
|
+
operation: {
|
|
798
|
+
op: 'analyzeFiles',
|
|
799
|
+
args: {
|
|
800
|
+
patterns: ['**/*.ts', '**/*.js', 'package.json', 'tsconfig.json'],
|
|
801
|
+
maxFiles: 50,
|
|
802
|
+
},
|
|
803
|
+
store: 'projectAnalysis',
|
|
804
|
+
},
|
|
805
|
+
next_state: 'project_analyzed',
|
|
806
|
+
},
|
|
807
|
+
{
|
|
808
|
+
name: 'load_existing_adrs',
|
|
809
|
+
from: 'project_analyzed',
|
|
810
|
+
operation: {
|
|
811
|
+
op: 'loadKnowledge',
|
|
812
|
+
args: {
|
|
813
|
+
domain: 'adr',
|
|
814
|
+
scope: 'existing',
|
|
815
|
+
},
|
|
816
|
+
store: 'existingAdrKnowledge',
|
|
817
|
+
},
|
|
818
|
+
next_state: 'adrs_loaded',
|
|
819
|
+
},
|
|
820
|
+
{
|
|
821
|
+
name: 'load_planning_template',
|
|
822
|
+
from: 'adrs_loaded',
|
|
823
|
+
operation: {
|
|
824
|
+
op: 'loadPrompt',
|
|
825
|
+
args: {
|
|
826
|
+
name: 'adr-suggestion',
|
|
827
|
+
section: sessionMode === 'guided' ? 'implicit_decisions' : 'recommendation_template',
|
|
828
|
+
},
|
|
829
|
+
store: 'planningTemplate',
|
|
830
|
+
},
|
|
831
|
+
next_state: 'template_loaded',
|
|
832
|
+
},
|
|
833
|
+
{
|
|
834
|
+
name: 'generate_suggestions',
|
|
835
|
+
from: 'template_loaded',
|
|
836
|
+
operation: {
|
|
837
|
+
op: 'generateContext',
|
|
838
|
+
args: {
|
|
839
|
+
type: 'adr-planning',
|
|
840
|
+
sessionMode,
|
|
841
|
+
},
|
|
842
|
+
inputs: ['projectAnalysis', 'existingAdrKnowledge', 'planningTemplate'],
|
|
843
|
+
store: 'planningResults',
|
|
844
|
+
},
|
|
845
|
+
next_state: 'done',
|
|
846
|
+
},
|
|
847
|
+
],
|
|
848
|
+
final_state: 'done',
|
|
849
|
+
};
|
|
850
|
+
}
|
|
851
|
+
/**
|
|
852
|
+
* CE-MCP version of mcp_planning
|
|
853
|
+
*
|
|
854
|
+
* Returns an orchestration directive for MCP server planning.
|
|
855
|
+
* Reduces token usage from ~6K to ~2K by:
|
|
856
|
+
* - Lazy loading MCP patterns
|
|
857
|
+
* - Deferring analysis to sandbox
|
|
858
|
+
* - Caching planning results
|
|
859
|
+
*/
|
|
860
|
+
export function createMcpPlanningDirective(args) {
|
|
861
|
+
const { goal, constraints = [], existingTools = [] } = args;
|
|
862
|
+
return {
|
|
863
|
+
type: 'orchestration_directive',
|
|
864
|
+
version: '1.0',
|
|
865
|
+
tool: 'mcp_planning',
|
|
866
|
+
description: `Plan MCP implementation for: ${goal}`,
|
|
867
|
+
sandbox_operations: [
|
|
868
|
+
{
|
|
869
|
+
op: 'loadKnowledge',
|
|
870
|
+
args: {
|
|
871
|
+
domain: 'mcp',
|
|
872
|
+
scope: 'patterns',
|
|
873
|
+
},
|
|
874
|
+
store: 'mcpPatterns',
|
|
875
|
+
},
|
|
876
|
+
{
|
|
877
|
+
op: 'loadPrompt',
|
|
878
|
+
args: {
|
|
879
|
+
name: 'analysis',
|
|
880
|
+
section: 'architecture_assessment',
|
|
881
|
+
},
|
|
882
|
+
store: 'planningPrompt',
|
|
883
|
+
},
|
|
884
|
+
{
|
|
885
|
+
op: 'generateContext',
|
|
886
|
+
args: {
|
|
887
|
+
type: 'mcp-planning',
|
|
888
|
+
goal,
|
|
889
|
+
constraints,
|
|
890
|
+
existingTools,
|
|
891
|
+
},
|
|
892
|
+
inputs: ['mcpPatterns', 'planningPrompt'],
|
|
893
|
+
store: 'planningContext',
|
|
894
|
+
},
|
|
895
|
+
{
|
|
896
|
+
op: 'composeResult',
|
|
897
|
+
input: 'planningContext',
|
|
898
|
+
return: true,
|
|
899
|
+
},
|
|
900
|
+
],
|
|
901
|
+
compose: {
|
|
902
|
+
sections: [
|
|
903
|
+
{ source: 'mcpPatterns', key: 'patterns' },
|
|
904
|
+
{ source: 'planningContext', key: 'plan' },
|
|
905
|
+
],
|
|
906
|
+
template: 'mcp_planning_report',
|
|
907
|
+
format: 'markdown',
|
|
908
|
+
},
|
|
909
|
+
metadata: {
|
|
910
|
+
estimated_tokens: 2000,
|
|
911
|
+
complexity: 'high',
|
|
912
|
+
cacheable: true,
|
|
913
|
+
cache_key: `mcp-plan-${goal.slice(0, 50)}`,
|
|
914
|
+
},
|
|
915
|
+
};
|
|
916
|
+
}
|
|
917
|
+
/**
|
|
918
|
+
* CE-MCP version of troubleshoot_guided_workflow
|
|
919
|
+
*
|
|
920
|
+
* Returns a state machine directive for troubleshooting workflows.
|
|
921
|
+
* Reduces token usage from ~7K to ~2.5K by:
|
|
922
|
+
* - Lazy loading troubleshooting guides
|
|
923
|
+
* - Sequential diagnostic phases
|
|
924
|
+
* - Context-aware remediation
|
|
925
|
+
*/
|
|
926
|
+
export function createTroubleshootGuidedWorkflowDirective(args) {
|
|
927
|
+
const { issue, context = '', previousSteps = [] } = args;
|
|
928
|
+
return {
|
|
929
|
+
type: 'state_machine_directive',
|
|
930
|
+
version: '1.0',
|
|
931
|
+
initial_state: {
|
|
932
|
+
issue,
|
|
933
|
+
context,
|
|
934
|
+
previousSteps,
|
|
935
|
+
diagnostics: [],
|
|
936
|
+
remediation: null,
|
|
937
|
+
},
|
|
938
|
+
transitions: [
|
|
939
|
+
{
|
|
940
|
+
name: 'load_troubleshooting_guide',
|
|
941
|
+
from: 'initial',
|
|
942
|
+
operation: {
|
|
943
|
+
op: 'loadPrompt',
|
|
944
|
+
args: {
|
|
945
|
+
name: 'deployment-analysis',
|
|
946
|
+
section: 'validation_criteria',
|
|
947
|
+
},
|
|
948
|
+
store: 'troubleshootingGuide',
|
|
949
|
+
},
|
|
950
|
+
next_state: 'guide_loaded',
|
|
951
|
+
},
|
|
952
|
+
{
|
|
953
|
+
name: 'scan_environment',
|
|
954
|
+
from: 'guide_loaded',
|
|
955
|
+
operation: {
|
|
956
|
+
op: 'scanEnvironment',
|
|
957
|
+
store: 'environmentState',
|
|
958
|
+
},
|
|
959
|
+
next_state: 'environment_scanned',
|
|
960
|
+
},
|
|
961
|
+
{
|
|
962
|
+
name: 'analyze_issue',
|
|
963
|
+
from: 'environment_scanned',
|
|
964
|
+
operation: {
|
|
965
|
+
op: 'generateContext',
|
|
966
|
+
args: {
|
|
967
|
+
type: 'issue-analysis',
|
|
968
|
+
issue,
|
|
969
|
+
context,
|
|
970
|
+
},
|
|
971
|
+
inputs: ['troubleshootingGuide', 'environmentState'],
|
|
972
|
+
store: 'issueAnalysis',
|
|
973
|
+
},
|
|
974
|
+
next_state: 'issue_analyzed',
|
|
975
|
+
},
|
|
976
|
+
{
|
|
977
|
+
name: 'generate_diagnostics',
|
|
978
|
+
from: 'issue_analyzed',
|
|
979
|
+
operation: {
|
|
980
|
+
op: 'generateContext',
|
|
981
|
+
args: {
|
|
982
|
+
type: 'diagnostic-steps',
|
|
983
|
+
previousSteps,
|
|
984
|
+
},
|
|
985
|
+
inputs: ['issueAnalysis'],
|
|
986
|
+
store: 'diagnostics',
|
|
987
|
+
},
|
|
988
|
+
next_state: 'diagnostics_generated',
|
|
989
|
+
},
|
|
990
|
+
{
|
|
991
|
+
name: 'suggest_remediation',
|
|
992
|
+
from: 'diagnostics_generated',
|
|
993
|
+
operation: {
|
|
994
|
+
op: 'generateContext',
|
|
995
|
+
args: {
|
|
996
|
+
type: 'remediation-plan',
|
|
997
|
+
},
|
|
998
|
+
inputs: ['diagnostics', 'issueAnalysis'],
|
|
999
|
+
store: 'remediation',
|
|
1000
|
+
},
|
|
1001
|
+
next_state: 'done',
|
|
1002
|
+
},
|
|
1003
|
+
],
|
|
1004
|
+
final_state: 'done',
|
|
1005
|
+
};
|
|
1006
|
+
}
|
|
1007
|
+
/**
|
|
1008
|
+
* CE-MCP version of tool_chain_orchestrator
|
|
1009
|
+
*
|
|
1010
|
+
* Returns an orchestration directive for tool chain planning.
|
|
1011
|
+
* This eliminates the OpenRouter dependency by having the host LLM
|
|
1012
|
+
* (which already has full context) generate the tool execution plan directly.
|
|
1013
|
+
*
|
|
1014
|
+
* Key insight: The host LLM is better positioned to create plans because:
|
|
1015
|
+
* 1. It has the full conversation context
|
|
1016
|
+
* 2. It knows what tools it has already tried
|
|
1017
|
+
* 3. It can directly execute the plan without roundtrips
|
|
1018
|
+
*
|
|
1019
|
+
* Reduces token usage from ~8K to ~2K by:
|
|
1020
|
+
* - Eliminating OpenRouter API call overhead
|
|
1021
|
+
* - Providing structured directive format
|
|
1022
|
+
* - Enabling direct host LLM execution
|
|
1023
|
+
*/
|
|
1024
|
+
export function createToolChainOrchestratorDirective(args) {
|
|
1025
|
+
const { operation, userRequest, projectContext, constraints = {}, customInstructions = '', sessionContext = {}, } = args;
|
|
1026
|
+
// Available tools for planning (subset of full catalog)
|
|
1027
|
+
const planningTools = [
|
|
1028
|
+
'analyze_project_ecosystem',
|
|
1029
|
+
'generate_adrs_from_prd',
|
|
1030
|
+
'suggest_adrs',
|
|
1031
|
+
'analyze_content_security',
|
|
1032
|
+
'generate_rules',
|
|
1033
|
+
'generate_adr_todo',
|
|
1034
|
+
'compare_adr_progress',
|
|
1035
|
+
'manage_todo',
|
|
1036
|
+
'generate_deployment_guidance',
|
|
1037
|
+
'smart_score',
|
|
1038
|
+
'troubleshoot_guided_workflow',
|
|
1039
|
+
'smart_git_push',
|
|
1040
|
+
'perform_research',
|
|
1041
|
+
'validate_rules',
|
|
1042
|
+
];
|
|
1043
|
+
const sandbox_operations = [
|
|
1044
|
+
// Phase 1: Load tool catalog
|
|
1045
|
+
{
|
|
1046
|
+
op: 'loadKnowledge',
|
|
1047
|
+
args: {
|
|
1048
|
+
type: 'tool-catalog',
|
|
1049
|
+
filter: {
|
|
1050
|
+
names: planningTools,
|
|
1051
|
+
},
|
|
1052
|
+
},
|
|
1053
|
+
store: 'availableTools',
|
|
1054
|
+
},
|
|
1055
|
+
// Phase 2: Scan environment
|
|
1056
|
+
{
|
|
1057
|
+
op: 'scanEnvironment',
|
|
1058
|
+
store: 'environmentState',
|
|
1059
|
+
},
|
|
1060
|
+
// Phase 3: Generate execution plan context
|
|
1061
|
+
{
|
|
1062
|
+
op: 'generateContext',
|
|
1063
|
+
args: {
|
|
1064
|
+
type: 'tool-chain-plan',
|
|
1065
|
+
operation,
|
|
1066
|
+
userRequest,
|
|
1067
|
+
customInstructions,
|
|
1068
|
+
projectContext: {
|
|
1069
|
+
projectPath: projectContext.projectPath,
|
|
1070
|
+
adrDirectory: projectContext.adrDirectory || 'docs/adrs',
|
|
1071
|
+
todoPath: projectContext.todoPath || 'TODO.md',
|
|
1072
|
+
hasADRs: projectContext.hasADRs ?? false,
|
|
1073
|
+
hasTODO: projectContext.hasTODO ?? false,
|
|
1074
|
+
projectType: projectContext.projectType || 'unknown',
|
|
1075
|
+
},
|
|
1076
|
+
constraints: {
|
|
1077
|
+
maxSteps: constraints.maxSteps ?? 10,
|
|
1078
|
+
prioritizeSpeed: constraints.prioritizeSpeed ?? false,
|
|
1079
|
+
excludeTools: constraints.excludeTools || [],
|
|
1080
|
+
},
|
|
1081
|
+
sessionContext: {
|
|
1082
|
+
conversationLength: sessionContext.conversationLength ?? 0,
|
|
1083
|
+
previousActions: sessionContext.previousActions || [],
|
|
1084
|
+
confusionIndicators: sessionContext.confusionIndicators || [],
|
|
1085
|
+
lastSuccessfulAction: sessionContext.lastSuccessfulAction || '',
|
|
1086
|
+
stuckOnTask: sessionContext.stuckOnTask || '',
|
|
1087
|
+
},
|
|
1088
|
+
},
|
|
1089
|
+
inputs: ['availableTools', 'environmentState'],
|
|
1090
|
+
store: 'executionPlan',
|
|
1091
|
+
},
|
|
1092
|
+
// Phase 4: Compose final result
|
|
1093
|
+
{
|
|
1094
|
+
op: 'composeResult',
|
|
1095
|
+
inputs: ['availableTools', 'environmentState', 'executionPlan'],
|
|
1096
|
+
return: true,
|
|
1097
|
+
},
|
|
1098
|
+
];
|
|
1099
|
+
return {
|
|
1100
|
+
type: 'orchestration_directive',
|
|
1101
|
+
version: '1.0',
|
|
1102
|
+
tool: 'tool_chain_orchestrator',
|
|
1103
|
+
description: `Generate tool execution plan for: "${userRequest}" (operation: ${operation})`,
|
|
1104
|
+
sandbox_operations,
|
|
1105
|
+
metadata: {
|
|
1106
|
+
estimated_tokens: 2000,
|
|
1107
|
+
complexity: 'medium',
|
|
1108
|
+
cacheable: false, // Plans are context-specific
|
|
1109
|
+
},
|
|
1110
|
+
};
|
|
1111
|
+
}
|
|
1112
|
+
// ============================================================================
|
|
1113
|
+
// CE-MCP TOOL REGISTRY
|
|
1114
|
+
// ============================================================================
|
|
1115
|
+
/**
|
|
1116
|
+
* Check if a tool should use CE-MCP directive mode
|
|
1117
|
+
*/
|
|
1118
|
+
export function shouldUseCEMCPDirective(toolName, config) {
|
|
1119
|
+
const cemcpTools = [
|
|
1120
|
+
// Phase 2 tools
|
|
1121
|
+
'analyze_project_ecosystem',
|
|
1122
|
+
'suggest_adrs',
|
|
1123
|
+
'generate_rules',
|
|
1124
|
+
'analyze_environment',
|
|
1125
|
+
'deployment_readiness',
|
|
1126
|
+
// Phase 4.2 tools
|
|
1127
|
+
'smart_score',
|
|
1128
|
+
'perform_research',
|
|
1129
|
+
'generate_adrs_from_prd',
|
|
1130
|
+
'interactive_adr_planning',
|
|
1131
|
+
'mcp_planning',
|
|
1132
|
+
'troubleshoot_guided_workflow',
|
|
1133
|
+
// Phase 5: OpenRouter Elimination
|
|
1134
|
+
'tool_chain_orchestrator',
|
|
1135
|
+
];
|
|
1136
|
+
return ((config.mode === 'ce-mcp' || config.mode === 'directive' || config.mode === 'hybrid') &&
|
|
1137
|
+
cemcpTools.includes(toolName));
|
|
1138
|
+
}
|
|
1139
|
+
/**
|
|
1140
|
+
* Get CE-MCP directive for a tool
|
|
1141
|
+
*/
|
|
1142
|
+
export function getCEMCPDirective(toolName, args) {
|
|
1143
|
+
switch (toolName) {
|
|
1144
|
+
// Phase 2 tools
|
|
1145
|
+
case 'analyze_project_ecosystem':
|
|
1146
|
+
return createAnalyzeProjectEcosystemDirective(args);
|
|
1147
|
+
case 'suggest_adrs':
|
|
1148
|
+
return createSuggestAdrsDirective(args);
|
|
1149
|
+
case 'generate_rules':
|
|
1150
|
+
return createGenerateRulesDirective(args);
|
|
1151
|
+
case 'analyze_environment':
|
|
1152
|
+
return createAnalyzeEnvironmentDirective(args);
|
|
1153
|
+
case 'deployment_readiness':
|
|
1154
|
+
return createDeploymentReadinessDirective(args);
|
|
1155
|
+
// Phase 4.2 tools
|
|
1156
|
+
case 'smart_score':
|
|
1157
|
+
return createSmartScoreDirective(args);
|
|
1158
|
+
case 'perform_research':
|
|
1159
|
+
return createPerformResearchDirective(args);
|
|
1160
|
+
case 'generate_adrs_from_prd':
|
|
1161
|
+
return createGenerateAdrsFromPrdDirective(args);
|
|
1162
|
+
case 'interactive_adr_planning':
|
|
1163
|
+
return createInteractiveAdrPlanningDirective(args);
|
|
1164
|
+
case 'mcp_planning':
|
|
1165
|
+
return createMcpPlanningDirective(args);
|
|
1166
|
+
case 'troubleshoot_guided_workflow':
|
|
1167
|
+
return createTroubleshootGuidedWorkflowDirective(args);
|
|
1168
|
+
// Phase 5: OpenRouter Elimination
|
|
1169
|
+
case 'tool_chain_orchestrator':
|
|
1170
|
+
return createToolChainOrchestratorDirective(args);
|
|
1171
|
+
default:
|
|
1172
|
+
return null;
|
|
1173
|
+
}
|
|
1174
|
+
}
|
|
1175
|
+
/**
|
|
1176
|
+
* Format CE-MCP directive as MCP response
|
|
1177
|
+
*/
|
|
1178
|
+
export function formatDirectiveResponse(directive) {
|
|
1179
|
+
return {
|
|
1180
|
+
content: [
|
|
1181
|
+
{
|
|
1182
|
+
type: 'text',
|
|
1183
|
+
text: JSON.stringify(directive, null, 2),
|
|
1184
|
+
},
|
|
1185
|
+
],
|
|
1186
|
+
};
|
|
1187
|
+
}
|
|
1188
|
+
//# sourceMappingURL=ce-mcp-tools.js.map
|