@nbiish/cognitive-tools-mcp 8.9.1 → 8.9.3
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 +45 -90
- package/build/index.js +476 -1139
- package/package.json +1 -1
package/build/index.js
CHANGED
|
@@ -1,1167 +1,504 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
* -----------------------------------------------------------------------------
|
|
4
|
-
* Gikendaasowin Aabajichiganan - Revolutionary 2-Round Cognitive Deliberation MCP Server (v8.8.4)
|
|
5
|
-
*
|
|
6
|
-
* Description: Revolutionary MCP server implementing the most advanced 2-round cognitive
|
|
7
|
-
* processing engine available. Features a comprehensive 6-stage framework combining
|
|
8
|
-
* Scientific Investigation, OOReD analysis, and Critical Thinking methodologies
|
|
9
|
-
* with expertly evaluated prompting strategies from modern-prompting.mdc.
|
|
10
|
-
*
|
|
11
|
-
* v8.8.2 OPTIMIZATION RELEASE - Threshold Adjustment & Verbosity Reduction:
|
|
12
|
-
* - Updated threshold from ≥1.38 to ≥1.42 for more selective prompting strategies
|
|
13
|
-
* - Removed redundant "Strategy-Enhanced Results" sections from all stages
|
|
14
|
-
* - Optimized critical thinking path generation to eliminate repetitive content
|
|
15
|
-
* - Simplified strategy application formatting for conciseness
|
|
16
|
-
* - Eliminated duplicate strategy evaluation between rounds for consistency
|
|
17
|
-
* - Maintained single tool call architecture with reduced verbosity
|
|
18
|
-
* -----------------------------------------------------------------------------
|
|
19
|
-
*/
|
|
20
|
-
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
21
3
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
22
|
-
import {
|
|
23
|
-
//
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
4
|
+
import { CallToolRequestSchema, ListToolsRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
|
|
5
|
+
// Modern prompting strategies from modern-prompting.mdc
|
|
6
|
+
const PROMPTING_STRATEGIES = {
|
|
7
|
+
"Cache-Augmented Reasoning + ReAct": {
|
|
8
|
+
description: "Interleave internal knowledge activation with reasoning/action cycles. Preload all relevant context into working memory. Keep rationale concise (≤ 8 bullets). Synthesize knowledge from multiple internal sources. Progressive knowledge building through iterative refinement.",
|
|
9
|
+
type: "primary"
|
|
10
|
+
},
|
|
11
|
+
"Self-Consistency": {
|
|
12
|
+
description: "Generate 3 short reasoning drafts in parallel. Return most consistent answer only. Use for ambiguous or high-stakes decisions.",
|
|
13
|
+
type: "primary"
|
|
14
|
+
},
|
|
15
|
+
"PAL (Program-Aided Language)": {
|
|
16
|
+
description: "Generate executable code for computational tasks. Include result + minimal rationale only. Prefix with '# PoT offload' comment.",
|
|
17
|
+
type: "primary"
|
|
18
|
+
},
|
|
19
|
+
"Reflexion": {
|
|
20
|
+
description: "Single critique and revision cycle. Use when confidence < 0.7. Avoid verbose chain-of-thought exposure.",
|
|
21
|
+
type: "primary"
|
|
22
|
+
},
|
|
23
|
+
"Context-Compression": {
|
|
24
|
+
description: "Apply when context exceeds budget. Use LLMLingua/LongLLMLingua compression. Prefer Minimal-CoT and bounded ToT-lite.",
|
|
25
|
+
type: "primary"
|
|
26
|
+
},
|
|
27
|
+
"ToT-lite (Tree of Thoughts)": {
|
|
28
|
+
description: "Bounded breadth/depth exploration. Use for complex problem decomposition. Limited branching to maintain efficiency.",
|
|
29
|
+
type: "primary"
|
|
30
|
+
},
|
|
31
|
+
"Automated Prompt Optimization (APO)": {
|
|
32
|
+
description: "Autonomously refine and improve prompts based on performance feedback. Use techniques like Expert Prompting or iterative refinement to enhance clarity and effectiveness. Reduces manual prompt engineering effort and improves task outcomes.",
|
|
33
|
+
type: "advanced"
|
|
34
|
+
},
|
|
35
|
+
"Reflexive Analysis": {
|
|
36
|
+
description: "Embed ethical, legal, and cultural considerations directly into the reasoning process. Explicitly evaluate prompts and responses against project-specific guidelines (e.g., Indigenous Data Sovereignty principles). Ensures responsible and contextually-aware AI behavior.",
|
|
37
|
+
type: "advanced"
|
|
38
|
+
},
|
|
39
|
+
"Progressive-Hint Prompting (PHP)": {
|
|
40
|
+
description: "Use previously generated outputs as contextual hints. Iterative refinement toward optimal solutions. Multi-turn interaction with cumulative knowledge building. Automatic guidance toward correct reasoning paths.",
|
|
41
|
+
type: "advanced"
|
|
42
|
+
},
|
|
43
|
+
"Cache-Augmented Generation (CAG)": {
|
|
44
|
+
description: "Preload all relevant context into working memory. Eliminate real-time retrieval dependencies. Leverage extended context capabilities of modern LLMs. Reduce latency and minimize retrieval errors.",
|
|
45
|
+
type: "advanced"
|
|
46
|
+
},
|
|
47
|
+
"Cognitive Scaffolding Prompting": {
|
|
48
|
+
description: "Structure reasoning through metacognitive frameworks. Explicit mental model construction and validation. Progressive complexity building from simple to complex tasks. Self-monitoring and regulation of reasoning processes.",
|
|
49
|
+
type: "advanced"
|
|
50
|
+
},
|
|
51
|
+
"Internal Knowledge Synthesis (IKS)": {
|
|
52
|
+
description: "Generate hypothetical knowledge constructs from parametric memory. Activate latent knowledge through structured prompting. Cross-reference and validate internal knowledge consistency. Synthesize coherent responses from distributed model knowledge.",
|
|
53
|
+
type: "advanced"
|
|
54
|
+
},
|
|
55
|
+
"Multimodal Synthesis": {
|
|
56
|
+
description: "Process and integrate information from multiple modalities (e.g., text, images, data). Extend reasoning capabilities to include visual question answering and cross-modal analysis. Enables solutions for a broader range of complex, real-world tasks.",
|
|
57
|
+
type: "advanced"
|
|
58
|
+
},
|
|
59
|
+
"Knowledge Synthesis Prompting (KSP)": {
|
|
60
|
+
description: "Integrate knowledge from multiple internal domains. Fine-grained coherence validation for credibility. Essential for complex factual content generation. Cross-domain knowledge validation and integration.",
|
|
61
|
+
type: "advanced"
|
|
62
|
+
},
|
|
63
|
+
"Prompt Compression": {
|
|
64
|
+
description: "LLMLingua for token budget management. Preserve semantic content while reducing length. Maintain reasoning quality under constraints.",
|
|
65
|
+
type: "advanced"
|
|
66
|
+
}
|
|
28
67
|
};
|
|
29
|
-
|
|
30
|
-
//
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
68
|
+
class CognitiveDeliberationEngine {
|
|
69
|
+
// Stage 1: Scientific Investigation
|
|
70
|
+
performScientificInvestigation(input, context) {
|
|
71
|
+
return `## Scientific Investigation Framework
|
|
72
|
+
|
|
73
|
+
**1. Identify Question:** ${this.extractCoreQuestion(input)}
|
|
74
|
+
|
|
75
|
+
**2. Form Hypothesis:** ${this.formHypothesis(input, context)}
|
|
76
|
+
|
|
77
|
+
**3. Experimental Design:** ${this.designApproach(input, context)}
|
|
78
|
+
|
|
79
|
+
**4. Data Analysis Framework:** ${this.establishAnalysisFramework(input)}
|
|
80
|
+
|
|
81
|
+
**5. Conclusion Preparation:** ${this.prepareConclusions(input)}`;
|
|
82
|
+
}
|
|
83
|
+
// Stage 2: Initial OOReD
|
|
84
|
+
performInitialOOReD(input, selectedStrategies, context) {
|
|
85
|
+
return `## Initial OOReD Process
|
|
86
|
+
|
|
87
|
+
**Observe:** Input complexity analysis reveals ${this.analyzeComplexity(input)}. Context depth: ${context ? 'comprehensive' : 'minimal'}. Task characteristics: ${this.identifyTaskType(input)}.
|
|
88
|
+
|
|
89
|
+
**Orient:** Solution pathway identification using ${selectedStrategies.join(', ')} strategies. Primary approach: ${this.identifyPrimaryApproach(input, selectedStrategies)}.
|
|
90
|
+
|
|
91
|
+
**Reason:** Core reasoning foundation: ${this.establishReasoning(input, selectedStrategies, context)}.
|
|
92
|
+
|
|
93
|
+
**Decide:** Action framework: ${this.decideActions(input, context)}`;
|
|
94
|
+
}
|
|
95
|
+
// Stage 3: Critical Thinking
|
|
96
|
+
performCriticalThinking(input, context) {
|
|
97
|
+
return `## Critical Thinking Framework
|
|
98
|
+
|
|
99
|
+
1. **Purpose:** ${this.identifyPurpose(input)}
|
|
100
|
+
2. **Precise Question:** ${this.refineQuestion(input)}
|
|
101
|
+
3. **Operating Context:** ${this.establishContext(input, context)}
|
|
102
|
+
4. **Information Needs:** ${this.identifyInformationNeeds(input)}
|
|
103
|
+
5. **Credibility Assessment:** ${this.assessCredibility(input, context)}
|
|
104
|
+
6. **Relevant Concepts:** ${this.identifyRelevantConcepts(input)}
|
|
105
|
+
7. **Preliminary Conclusions:** ${this.drawPreliminaryConclusions(input)}
|
|
106
|
+
8. **Assumptions Analysis:** ${this.analyzeAssumptions(input)}
|
|
107
|
+
9. **Implications:** ${this.identifyImplications(input)}
|
|
108
|
+
10. **Consequences:** ${this.assessConsequences(input)}
|
|
109
|
+
|
|
110
|
+
**Pre-Action Tool Planning:** ${this.planToolUsage(input)}`;
|
|
111
|
+
}
|
|
112
|
+
// Stage 4: Scientific Review
|
|
113
|
+
performScientificReview(input, round1Results, context) {
|
|
114
|
+
return `## Scientific Review Process
|
|
115
|
+
|
|
116
|
+
**Question Validation:** ${this.validateQuestion(input, round1Results)}
|
|
117
|
+
|
|
118
|
+
**Hypothesis Refinement:** ${this.refineHypothesis(input, round1Results)}
|
|
119
|
+
|
|
120
|
+
**Methodology Assessment:** ${this.assessMethodology(round1Results)}
|
|
121
|
+
|
|
122
|
+
**Evidence Evaluation:** ${this.evaluateEvidence(input, context, round1Results)}
|
|
123
|
+
|
|
124
|
+
**Conclusion Verification:** ${this.verifyConclusions(round1Results)}`;
|
|
125
|
+
}
|
|
126
|
+
// Stage 5: OOReD Review
|
|
127
|
+
performOOReD_Review(input, round1Results, selectedStrategies, context) {
|
|
128
|
+
return `## OOReD Review Process
|
|
129
|
+
|
|
130
|
+
**Enhanced Observation:** ${this.enhanceObservation(input, round1Results)}
|
|
131
|
+
|
|
132
|
+
**Strategic Reorientation:** ${this.reorient(input, round1Results, selectedStrategies)}
|
|
133
|
+
|
|
134
|
+
**Advanced Reasoning:** ${this.advancedReasoning(input, context, round1Results, selectedStrategies)}
|
|
135
|
+
|
|
136
|
+
**Final Decision Framework:** ${this.finalDecisionFramework(input, round1Results)}`;
|
|
137
|
+
}
|
|
138
|
+
// Stage 6: Final Action
|
|
139
|
+
performFinalAction(input, allResults, selectedStrategies, context) {
|
|
140
|
+
const toolCount = this.calculateToolUsage(input, allResults);
|
|
141
|
+
return `## Final Action Synthesis
|
|
142
|
+
|
|
143
|
+
**Comprehensive Solution:** ${this.synthesizeSolution(input, context, allResults, selectedStrategies)}
|
|
144
|
+
|
|
145
|
+
**Implementation Pathway:** ${this.createImplementationPath(input, allResults)}
|
|
146
|
+
|
|
147
|
+
**Verification Framework:** ${this.establishVerification(input, allResults)}
|
|
148
|
+
|
|
149
|
+
**Success Metrics:** ${this.defineSuccessMetrics(input, allResults)}
|
|
150
|
+
|
|
151
|
+
**Fact-Based Recommendations:** ${this.generateRecommendations(input, context, allResults, selectedStrategies)}
|
|
152
|
+
|
|
153
|
+
**tool use before re-deliberation: ${toolCount}**`;
|
|
154
|
+
}
|
|
155
|
+
// Strategy evaluation system
|
|
156
|
+
evaluatePromptingStrategies(input, context) {
|
|
157
|
+
const scores = [];
|
|
158
|
+
for (const [strategyName, strategy] of Object.entries(PROMPTING_STRATEGIES)) {
|
|
159
|
+
const solutionLevel = this.calculateSolutionLevel(input, context, strategy);
|
|
160
|
+
const efficiencyLevel = this.calculateEfficiencyLevel(input, strategy);
|
|
161
|
+
const totalScore = solutionLevel + efficiencyLevel;
|
|
162
|
+
scores.push({
|
|
163
|
+
strategy: strategyName,
|
|
164
|
+
solutionLevel: parseFloat(solutionLevel.toFixed(2)),
|
|
165
|
+
efficiencyLevel: parseFloat(efficiencyLevel.toFixed(2)),
|
|
166
|
+
totalScore: parseFloat(totalScore.toFixed(2)),
|
|
167
|
+
reasoning: this.generateStrategyReasoning(input, strategy, solutionLevel, efficiencyLevel)
|
|
168
|
+
});
|
|
112
169
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
efficiencyLevel: efficiencyLevel,
|
|
123
|
-
totalScore: solutionLevel + efficiencyLevel
|
|
124
|
-
};
|
|
125
|
-
});
|
|
126
|
-
// Return strategies with scores ≥1.42
|
|
127
|
-
return strategies.filter(s => s.totalScore >= 1.42).sort((a, b) => b.totalScore - a.totalScore);
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* DYNAMIC IN-PROMPT EVALUATION: Evaluates solution capability based on actual task requirements
|
|
131
|
-
* Returns 0.00-0.99 based on how well the strategy solves the specific problem
|
|
132
|
-
*/
|
|
133
|
-
function evaluateSolutionLevel(strategyName, description, input, mode, context) {
|
|
134
|
-
let score = 0.50; // Base score
|
|
135
|
-
// Analyze input complexity and requirements
|
|
136
|
-
const inputLength = input.length;
|
|
137
|
-
const hasCodeTerms = /code|implement|debug|program|function|class|method|variable/.test(input.toLowerCase());
|
|
138
|
-
const hasAnalysisTerms = /analyze|compare|evaluate|assess|review|examine/.test(input.toLowerCase());
|
|
139
|
-
const hasCreativeTerms = /create|design|generate|build|develop|invent/.test(input.toLowerCase());
|
|
140
|
-
const hasDecisionTerms = /decide|choose|select|determine|resolve|conclude/.test(input.toLowerCase());
|
|
141
|
-
const hasComplexLogic = /algorithm|logic|reasoning|thinking|strategy|approach/.test(input.toLowerCase());
|
|
142
|
-
const hasMultiStep = /step|phase|stage|process|workflow|procedure/.test(input.toLowerCase());
|
|
143
|
-
// Strategy-specific solution evaluation based on modern-prompting.mdc capabilities
|
|
144
|
-
if (strategyName.includes("Cache-Augmented Reasoning + ReAct")) {
|
|
145
|
-
score = 0.60; // Strong baseline for reasoning + action cycles
|
|
146
|
-
if (hasComplexLogic && hasMultiStep)
|
|
147
|
-
score += 0.20;
|
|
148
|
-
if (mode === "analyze" || mode === "decide")
|
|
149
|
-
score += 0.15;
|
|
150
|
-
if (context && context.length > 100)
|
|
151
|
-
score += 0.10; // Benefits from context
|
|
152
|
-
}
|
|
153
|
-
else if (strategyName.includes("Self-Consistency")) {
|
|
154
|
-
score = 0.55; // Good for validation
|
|
155
|
-
if (hasDecisionTerms)
|
|
156
|
-
score += 0.25; // Excels at decision validation
|
|
157
|
-
if (mode === "decide" || mode === "evaluate")
|
|
158
|
-
score += 0.18;
|
|
159
|
-
if (inputLength > 300)
|
|
160
|
-
score += 0.10; // Better with complex inputs
|
|
161
|
-
}
|
|
162
|
-
else if (strategyName.includes("Tree of Thoughts")) {
|
|
163
|
-
score = 0.65; // Strong for complex decomposition
|
|
164
|
-
if (hasComplexLogic && hasMultiStep)
|
|
165
|
-
score += 0.25;
|
|
166
|
-
if (mode === "analyze" || mode === "synthesize")
|
|
167
|
-
score += 0.20;
|
|
168
|
-
if (hasCreativeTerms)
|
|
169
|
-
score += 0.15; // Good for creative problem solving
|
|
170
|
-
}
|
|
171
|
-
else if (strategyName.includes("Progressive-Hint Prompting")) {
|
|
172
|
-
score = 0.52; // Moderate baseline
|
|
173
|
-
if (hasMultiStep)
|
|
174
|
-
score += 0.20;
|
|
175
|
-
if (context && context.length > 50)
|
|
176
|
-
score += 0.18; // Uses previous context well
|
|
177
|
-
if (mode === "synthesize")
|
|
178
|
-
score += 0.12;
|
|
179
|
-
}
|
|
180
|
-
else if (strategyName.includes("Cognitive Scaffolding")) {
|
|
181
|
-
score = 0.68; // High baseline for structured thinking
|
|
182
|
-
if (hasComplexLogic)
|
|
183
|
-
score += 0.22;
|
|
184
|
-
if (inputLength > 500)
|
|
185
|
-
score += 0.15; // Better with complex inputs
|
|
186
|
-
if (mode === "analyze" || mode === "evaluate")
|
|
187
|
-
score += 0.12;
|
|
188
|
-
}
|
|
189
|
-
else if (strategyName.includes("Knowledge Synthesis")) {
|
|
190
|
-
score = 0.58; // Good for integration
|
|
191
|
-
if (mode === "synthesize")
|
|
170
|
+
return scores.sort((a, b) => b.totalScore - a.totalScore);
|
|
171
|
+
}
|
|
172
|
+
calculateSolutionLevel(input, context, strategy) {
|
|
173
|
+
let score = 0.1; // Base score
|
|
174
|
+
// Complexity analysis
|
|
175
|
+
const complexity = this.analyzeInputComplexity(input);
|
|
176
|
+
if (complexity === 'high' && strategy.type === 'advanced')
|
|
177
|
+
score += 0.3;
|
|
178
|
+
if (complexity === 'medium' && strategy.type === 'primary')
|
|
192
179
|
score += 0.25;
|
|
193
|
-
if (
|
|
194
|
-
score += 0.
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
else if (strategyName.includes("Reflexive Analysis")) {
|
|
199
|
-
score = 0.45; // Lower baseline, specialized use
|
|
200
|
-
if (mode === "evaluate")
|
|
201
|
-
score += 0.30; // Excellent for evaluation
|
|
202
|
-
if (hasAnalysisTerms)
|
|
203
|
-
score += 0.20;
|
|
204
|
-
if (input.includes("ethic") || input.includes("legal") || input.includes("cultur"))
|
|
180
|
+
if (complexity === 'low')
|
|
181
|
+
score += 0.2;
|
|
182
|
+
// Task type matching
|
|
183
|
+
const taskType = this.identifyTaskType(input);
|
|
184
|
+
if (taskType === 'computational' && strategy.description.includes('code'))
|
|
205
185
|
score += 0.25;
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
if (hasCodeTerms)
|
|
210
|
-
score += 0.35; // Excellent for coding tasks
|
|
211
|
-
if (input.includes("calculat") || input.includes("comput") || input.includes("math"))
|
|
212
|
-
score += 0.25;
|
|
213
|
-
if (mode === "decide" && hasCodeTerms)
|
|
186
|
+
if (taskType === 'analytical' && strategy.description.includes('reasoning'))
|
|
187
|
+
score += 0.2;
|
|
188
|
+
if (taskType === 'creative' && strategy.description.includes('synthesis'))
|
|
214
189
|
score += 0.15;
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
score = 0.35; // Specialized utility
|
|
218
|
-
if (inputLength > 1000)
|
|
219
|
-
score += 0.40; // Excels with large inputs
|
|
220
|
-
if (context && context.length > 500)
|
|
221
|
-
score += 0.25;
|
|
222
|
-
if (inputLength > 2000)
|
|
223
|
-
score += 0.20; // Even better with very large inputs
|
|
224
|
-
}
|
|
225
|
-
return Math.min(0.99, score);
|
|
226
|
-
}
|
|
227
|
-
/**
|
|
228
|
-
* DYNAMIC IN-PROMPT EVALUATION: Evaluates efficiency based on computational and cognitive overhead
|
|
229
|
-
* Returns 0.00-0.99 based on how efficiently the strategy processes the specific task
|
|
230
|
-
*/
|
|
231
|
-
function evaluateEfficiencyLevel(strategyName, description, input, mode, context) {
|
|
232
|
-
let score = 0.60; // Base efficiency score
|
|
233
|
-
const inputLength = input.length;
|
|
234
|
-
const isSimpleTask = inputLength < 200 && !(/complex|difficult|challenging|intricate/.test(input.toLowerCase()));
|
|
235
|
-
const isUrgentMode = mode === "decide";
|
|
236
|
-
const hasTimeConstraints = /quick|fast|urgent|immediate|rapid/.test(input.toLowerCase());
|
|
237
|
-
// Strategy-specific efficiency evaluation
|
|
238
|
-
if (strategyName.includes("Cache-Augmented Reasoning + ReAct")) {
|
|
239
|
-
score = 0.65; // Good balance of power and efficiency
|
|
240
|
-
if (context)
|
|
241
|
-
score += 0.12; // More efficient with cached context
|
|
242
|
-
if (isSimpleTask)
|
|
243
|
-
score -= 0.08; // Overhead for simple tasks
|
|
244
|
-
if (hasTimeConstraints)
|
|
245
|
-
score += 0.08;
|
|
246
|
-
}
|
|
247
|
-
else if (strategyName.includes("Self-Consistency")) {
|
|
248
|
-
score = 0.45; // Lower efficiency due to parallel processing
|
|
249
|
-
if (isUrgentMode)
|
|
250
|
-
score -= 0.10; // Slower for urgent decisions
|
|
251
|
-
if (isSimpleTask)
|
|
252
|
-
score -= 0.15; // Overkill for simple tasks
|
|
253
|
-
if (inputLength > 500)
|
|
254
|
-
score += 0.20; // More worthwhile for complex inputs
|
|
255
|
-
}
|
|
256
|
-
else if (strategyName.includes("Tree of Thoughts")) {
|
|
257
|
-
score = 0.40; // Lower efficiency due to branching
|
|
258
|
-
if (isSimpleTask)
|
|
259
|
-
score -= 0.20; // Significant overhead for simple tasks
|
|
260
|
-
if (hasTimeConstraints)
|
|
261
|
-
score -= 0.15; // Slow for urgent needs
|
|
262
|
-
if (inputLength > 800)
|
|
263
|
-
score += 0.25; // Worth it for very complex problems
|
|
264
|
-
}
|
|
265
|
-
else if (strategyName.includes("Progressive-Hint Prompting")) {
|
|
266
|
-
score = 0.68; // Good efficiency with iterative approach
|
|
267
|
-
if (context)
|
|
268
|
-
score += 0.15; // Very efficient with context
|
|
269
|
-
if (isSimpleTask)
|
|
270
|
-
score += 0.10; // Good for simple progressive tasks
|
|
271
|
-
if (hasTimeConstraints)
|
|
272
|
-
score += 0.08;
|
|
273
|
-
}
|
|
274
|
-
else if (strategyName.includes("Cognitive Scaffolding")) {
|
|
275
|
-
score = 0.52; // Moderate efficiency with structured approach
|
|
276
|
-
if (inputLength > 600)
|
|
277
|
-
score += 0.18; // More efficient for complex structured problems
|
|
278
|
-
if (isSimpleTask)
|
|
279
|
-
score -= 0.12; // Overhead for simple tasks
|
|
280
|
-
if (mode === "analyze")
|
|
281
|
-
score += 0.10;
|
|
282
|
-
}
|
|
283
|
-
else if (strategyName.includes("Knowledge Synthesis")) {
|
|
284
|
-
score = 0.58; // Good efficiency for integration tasks
|
|
285
|
-
if (context && context.length > 100)
|
|
190
|
+
// Context utilization
|
|
191
|
+
if (context && strategy.description.includes('context'))
|
|
286
192
|
score += 0.15;
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
if (
|
|
295
|
-
score += 0.
|
|
296
|
-
if (
|
|
297
|
-
score -= 0.15; // Overkill for simple tasks
|
|
298
|
-
if (hasTimeConstraints)
|
|
299
|
-
score -= 0.20; // Slow process
|
|
300
|
-
}
|
|
301
|
-
else if (strategyName.includes("PAL (Program-Aided Language)")) {
|
|
302
|
-
score = 0.75; // High efficiency for computational tasks
|
|
303
|
-
if (input.includes("code") || input.includes("calculat"))
|
|
193
|
+
return Math.min(score, 0.99);
|
|
194
|
+
}
|
|
195
|
+
calculateEfficiencyLevel(input, strategy) {
|
|
196
|
+
let score = 0.1; // Base score
|
|
197
|
+
// Processing efficiency
|
|
198
|
+
if (strategy.type === 'primary')
|
|
199
|
+
score += 0.3; // Primary strategies are more efficient
|
|
200
|
+
if (strategy.description.includes('concise'))
|
|
201
|
+
score += 0.2;
|
|
202
|
+
if (strategy.description.includes('minimal'))
|
|
304
203
|
score += 0.15;
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
if (!
|
|
308
|
-
score
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
if (
|
|
313
|
-
score
|
|
314
|
-
if (
|
|
315
|
-
score
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
204
|
+
// Input length consideration
|
|
205
|
+
const inputLength = input.length;
|
|
206
|
+
if (inputLength < 200 && !strategy.description.includes('complex'))
|
|
207
|
+
score += 0.2;
|
|
208
|
+
if (inputLength > 1000 && strategy.description.includes('compression'))
|
|
209
|
+
score += 0.25;
|
|
210
|
+
// Scalability factors
|
|
211
|
+
if (strategy.description.includes('parallel'))
|
|
212
|
+
score += 0.1;
|
|
213
|
+
if (strategy.description.includes('iterative'))
|
|
214
|
+
score -= 0.05; // Slightly less efficient
|
|
215
|
+
return Math.min(score, 0.99);
|
|
216
|
+
}
|
|
217
|
+
generateStrategyReasoning(input, strategy, solutionLevel, efficiencyLevel) {
|
|
218
|
+
const taskType = this.identifyTaskType(input);
|
|
219
|
+
const complexity = this.analyzeInputComplexity(input);
|
|
220
|
+
return `${taskType} task with ${complexity} complexity. Strategy alignment: ${solutionLevel > 0.6 ? 'high' : solutionLevel > 0.4 ? 'medium' : 'low'}. Efficiency rating: ${efficiencyLevel > 0.6 ? 'optimal' : efficiencyLevel > 0.4 ? 'adequate' : 'limited'}.`;
|
|
221
|
+
}
|
|
222
|
+
// Core cognitive processing method
|
|
223
|
+
async performCognitiveDeliberation(input, context) {
|
|
224
|
+
// Strategy evaluation
|
|
225
|
+
const strategyScores = this.evaluatePromptingStrategies(input, context);
|
|
226
|
+
const selectedStrategies = strategyScores
|
|
227
|
+
.filter(s => s.totalScore >= 1.42)
|
|
228
|
+
.slice(0, strategyScores.filter(s => s.totalScore >= 1.53).length > 1 ? 3 : 1)
|
|
229
|
+
.map(s => s.strategy);
|
|
230
|
+
if (selectedStrategies.length === 0) {
|
|
231
|
+
selectedStrategies.push(strategyScores[0].strategy); // Fallback to highest scoring
|
|
232
|
+
}
|
|
233
|
+
// Round 1: Stages 1-2
|
|
234
|
+
const stage1 = this.performScientificInvestigation(input, context);
|
|
235
|
+
const stage2 = this.performInitialOOReD(input, selectedStrategies, context);
|
|
236
|
+
const round1Results = `${stage1}\n\n${stage2}`;
|
|
237
|
+
// Round 2: Stages 3-6
|
|
238
|
+
const stage3 = this.performCriticalThinking(input, context);
|
|
239
|
+
const stage4 = this.performScientificReview(input, round1Results, context);
|
|
240
|
+
const stage5 = this.performOOReD_Review(input, round1Results, selectedStrategies, context);
|
|
241
|
+
const stage6 = this.performFinalAction(input, `${round1Results}\n\n${stage3}\n\n${stage4}\n\n${stage5}`, selectedStrategies, context);
|
|
242
|
+
// Final compilation
|
|
243
|
+
return `# Cognitive Deliberation Results
|
|
244
|
+
|
|
245
|
+
## Round 1: Foundation
|
|
246
|
+
${round1Results}
|
|
247
|
+
|
|
248
|
+
## Round 2: Advanced Processing
|
|
249
|
+
${stage3}
|
|
250
|
+
|
|
251
|
+
${stage4}
|
|
252
|
+
|
|
253
|
+
${stage5}
|
|
254
|
+
|
|
255
|
+
${stage6}
|
|
256
|
+
|
|
257
|
+
## Strategy Evaluation Summary
|
|
258
|
+
**Selected Strategies:** ${selectedStrategies.join(', ')}
|
|
259
|
+
**Evaluation Results:** ${strategyScores.slice(0, 3).map(s => `${s.strategy}: ${s.totalScore}`).join(', ')}`;
|
|
260
|
+
}
|
|
261
|
+
// Helper methods for cognitive processing
|
|
262
|
+
extractCoreQuestion(input) {
|
|
263
|
+
// Extract the fundamental question or problem from input
|
|
264
|
+
const questionMarkers = ['?', 'how', 'what', 'why', 'when', 'where', 'which'];
|
|
265
|
+
const hasQuestion = questionMarkers.some(marker => input.toLowerCase().includes(marker));
|
|
266
|
+
if (hasQuestion) {
|
|
267
|
+
return `Direct question identified in input requiring systematic investigation.`;
|
|
268
|
+
}
|
|
269
|
+
else {
|
|
270
|
+
return `Implicit problem requiring question formulation: What is the optimal approach to address the stated requirements?`;
|
|
271
|
+
}
|
|
339
272
|
}
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
273
|
+
formHypothesis(input, context) {
|
|
274
|
+
const taskType = this.identifyTaskType(input);
|
|
275
|
+
return `Based on ${taskType} task characteristics${context ? ' and provided context' : ''}, hypothesis: The solution requires systematic application of appropriate cognitive frameworks to achieve optimal results.`;
|
|
276
|
+
}
|
|
277
|
+
designApproach(input, context) {
|
|
278
|
+
return `Multi-stage cognitive processing with strategy selection, iterative refinement, and verification protocols.`;
|
|
279
|
+
}
|
|
280
|
+
establishAnalysisFramework(input) {
|
|
281
|
+
return `Qualitative analysis of reasoning coherence, quantitative assessment of solution completeness, validation against success criteria.`;
|
|
282
|
+
}
|
|
283
|
+
prepareConclusions(input) {
|
|
284
|
+
return `Synthesis framework ready for evidence-based conclusions with confidence calibration and uncertainty quantification.`;
|
|
285
|
+
}
|
|
286
|
+
analyzeComplexity(input) {
|
|
287
|
+
if (input.length > 1000)
|
|
288
|
+
return 'high cognitive load with multi-faceted requirements';
|
|
289
|
+
if (input.length > 500)
|
|
290
|
+
return 'moderate complexity requiring structured approach';
|
|
291
|
+
return 'manageable complexity with clear pathway identification';
|
|
292
|
+
}
|
|
293
|
+
identifyTaskType(input) {
|
|
294
|
+
const codePatterns = ['code', 'function', 'class', 'method', 'algorithm', 'programming'];
|
|
295
|
+
const analyticalPatterns = ['analyze', 'evaluate', 'compare', 'assess', 'examine'];
|
|
296
|
+
const creativePatterns = ['design', 'create', 'generate', 'build', 'develop'];
|
|
297
|
+
const decisionPatterns = ['choose', 'decide', 'select', 'recommend', 'determine'];
|
|
298
|
+
const lowerInput = input.toLowerCase();
|
|
299
|
+
if (codePatterns.some(p => lowerInput.includes(p)))
|
|
300
|
+
return 'computational';
|
|
301
|
+
if (analyticalPatterns.some(p => lowerInput.includes(p)))
|
|
302
|
+
return 'analytical';
|
|
303
|
+
if (creativePatterns.some(p => lowerInput.includes(p)))
|
|
304
|
+
return 'creative';
|
|
305
|
+
if (decisionPatterns.some(p => lowerInput.includes(p)))
|
|
306
|
+
return 'decision-making';
|
|
307
|
+
return 'general-purpose';
|
|
308
|
+
}
|
|
309
|
+
identifyPrimaryApproach(input, strategies) {
|
|
310
|
+
return `${strategies[0]} as primary framework with ${strategies.length > 1 ? 'secondary strategies integrated' : 'focused application'}`;
|
|
311
|
+
}
|
|
312
|
+
establishReasoning(input, strategies, context) {
|
|
313
|
+
return `Multi-strategy reasoning utilizing ${strategies.join(' and ')} approaches for comprehensive solution development${context ? ' with contextual grounding' : ''}.`;
|
|
314
|
+
}
|
|
315
|
+
decideActions(input, context) {
|
|
316
|
+
const toolTypes = ['websearch', 'file manipulation', 'code analysis', 'context synthesis'];
|
|
317
|
+
return `Action sequence prioritizing ${toolTypes.slice(0, 2).join(' and ')} based on input requirements.`;
|
|
318
|
+
}
|
|
319
|
+
identifyPurpose(input) {
|
|
320
|
+
return `Primary purpose: Address the core requirements while optimizing for solution quality and implementation feasibility.`;
|
|
321
|
+
}
|
|
322
|
+
refineQuestion(input) {
|
|
323
|
+
return `Refined question: How can the stated objectives be achieved most effectively using available cognitive and technical resources?`;
|
|
324
|
+
}
|
|
325
|
+
establishContext(input, context) {
|
|
326
|
+
return `Operating within ${context ? 'provided contextual framework' : 'general problem-solving context'} with emphasis on practical implementation.`;
|
|
327
|
+
}
|
|
328
|
+
identifyInformationNeeds(input) {
|
|
329
|
+
const needsAnalysis = input.length > 500 ? 'comprehensive domain knowledge' : 'targeted information';
|
|
330
|
+
return `Information requirements: ${needsAnalysis}, validation sources, and implementation guidelines.`;
|
|
331
|
+
}
|
|
332
|
+
assessCredibility(input, context) {
|
|
333
|
+
return `Credibility assessment: Input source${context ? ' and context' : ''} evaluated for reliability and completeness. Verification protocols established.`;
|
|
334
|
+
}
|
|
335
|
+
identifyRelevantConcepts(input) {
|
|
336
|
+
return `Key concepts: Domain-specific knowledge, methodological frameworks, implementation patterns, and optimization strategies.`;
|
|
337
|
+
}
|
|
338
|
+
drawPreliminaryConclusions(input) {
|
|
339
|
+
return `Preliminary assessment indicates systematic approach required with iterative refinement and validation checkpoints.`;
|
|
340
|
+
}
|
|
341
|
+
analyzeAssumptions(input) {
|
|
342
|
+
return `Key assumptions: Solution feasibility, resource availability, and standard implementation patterns apply.`;
|
|
343
|
+
}
|
|
344
|
+
identifyImplications(input) {
|
|
345
|
+
return `Solution implications: Systematic implementation required with quality assurance and performance optimization considerations.`;
|
|
346
|
+
}
|
|
347
|
+
assessConsequences(input) {
|
|
348
|
+
return `Implementation consequences: Positive outcomes expected with proper execution, minimal risks with appropriate safeguards.`;
|
|
349
|
+
}
|
|
350
|
+
planToolUsage(input) {
|
|
351
|
+
const toolCount = this.calculateToolUsage(input, '');
|
|
352
|
+
return `Tool usage plan: ${toolCount} tools anticipated for comprehensive solution development including websearch, file operations, and analysis tools.`;
|
|
353
|
+
}
|
|
354
|
+
calculateToolUsage(input, results) {
|
|
355
|
+
// Calculate recommended tool usage based on complexity and requirements
|
|
356
|
+
let toolCount = 1; // Minimum
|
|
357
|
+
const complexity = this.analyzeInputComplexity(input);
|
|
358
|
+
if (complexity === 'high')
|
|
359
|
+
toolCount += 3;
|
|
360
|
+
else if (complexity === 'medium')
|
|
361
|
+
toolCount += 2;
|
|
362
|
+
else
|
|
363
|
+
toolCount += 1;
|
|
364
|
+
const taskType = this.identifyTaskType(input);
|
|
365
|
+
if (taskType === 'computational')
|
|
366
|
+
toolCount += 2;
|
|
367
|
+
if (taskType === 'analytical')
|
|
368
|
+
toolCount += 1;
|
|
369
|
+
if (input.length > 1000)
|
|
370
|
+
toolCount += 1;
|
|
371
|
+
if (results.length > 2000)
|
|
372
|
+
toolCount += 1;
|
|
373
|
+
return Math.min(toolCount, 7); // Cap at 7 tools
|
|
374
|
+
}
|
|
375
|
+
analyzeInputComplexity(input) {
|
|
376
|
+
if (input.length > 1000)
|
|
377
|
+
return 'high';
|
|
378
|
+
if (input.length > 500)
|
|
379
|
+
return 'medium';
|
|
380
|
+
return 'low';
|
|
381
|
+
}
|
|
382
|
+
// Stage 4-6 helper methods
|
|
383
|
+
validateQuestion(input, round1Results) {
|
|
384
|
+
return `Question validation confirms alignment between initial problem identification and cognitive processing results.`;
|
|
385
|
+
}
|
|
386
|
+
refineHypothesis(input, round1Results) {
|
|
387
|
+
return `Hypothesis refinement based on initial processing confirms systematic approach validity with enhanced precision.`;
|
|
388
|
+
}
|
|
389
|
+
assessMethodology(round1Results) {
|
|
390
|
+
return `Methodology assessment indicates appropriate framework selection and implementation pathway optimization.`;
|
|
391
|
+
}
|
|
392
|
+
evaluateEvidence(input, context, round1Results) {
|
|
393
|
+
return `Evidence evaluation confirms reasoning coherence and solution pathway validity${context ? ' with contextual validation' : ''}.`;
|
|
394
|
+
}
|
|
395
|
+
verifyConclusions(round1Results) {
|
|
396
|
+
return `Conclusion verification establishes logical consistency and implementation feasibility across all processing stages.`;
|
|
397
|
+
}
|
|
398
|
+
enhanceObservation(input, round1Results) {
|
|
399
|
+
return `Enhanced observation integrating initial findings with critical thinking framework results for comprehensive understanding.`;
|
|
346
400
|
}
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
recommendations.push("• **mcp_context7_get-library-docs** - Get up-to-date library documentation");
|
|
350
|
-
toolCount += 1;
|
|
401
|
+
reorient(input, round1Results, strategies) {
|
|
402
|
+
return `Strategic reorientation utilizing ${strategies.join(' and ')} approaches for optimized solution development.`;
|
|
351
403
|
}
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
recommendations.push("• **run_in_terminal** - Execute commands and scripts");
|
|
355
|
-
toolCount += 1;
|
|
404
|
+
advancedReasoning(input, context, round1Results, strategies) {
|
|
405
|
+
return `Advanced reasoning synthesis combining ${strategies.length} selected strategies with comprehensive validation protocols.`;
|
|
356
406
|
}
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
recommendations.push("• **semantic_search** - Explore codebase for relevant patterns");
|
|
360
|
-
recommendations.push("• **read_file** - Review key implementation files");
|
|
361
|
-
recommendations.push("• **vscode-websearchforcopilot_webSearch** - Research best practices");
|
|
362
|
-
toolCount = 3;
|
|
407
|
+
finalDecisionFramework(input, round1Results) {
|
|
408
|
+
return `Final decision framework established with clear implementation priorities and success verification methods.`;
|
|
363
409
|
}
|
|
364
|
-
|
|
365
|
-
}
|
|
366
|
-
/**
|
|
367
|
-
* Formats prompting strategy evaluation results for output
|
|
368
|
-
* Shows dynamically evaluated strategies with real-time scoring
|
|
369
|
-
*/
|
|
370
|
-
function formatPromptingStrategyResults(strategies) {
|
|
371
|
-
if (strategies.length === 0) {
|
|
372
|
-
return "**No strategies met the threshold of ≥1.42 through dynamic evaluation**";
|
|
410
|
+
synthesizeSolution(input, context, allResults, strategies) {
|
|
411
|
+
return `Comprehensive solution synthesis utilizing ${strategies.join(', ')} strategies for optimal implementation approach${context ? ' within provided contextual framework' : ''}.`;
|
|
373
412
|
}
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
result += `${index + 1}. **${strategy.name}** (Total: ${strategy.totalScore.toFixed(2)})\n`;
|
|
377
|
-
result += ` - Solution Level: ${strategy.solutionLevel.toFixed(2)} (evaluated in-prompt for task fit)\n`;
|
|
378
|
-
result += ` - Efficiency Level: ${strategy.efficiencyLevel.toFixed(2)} (evaluated in-prompt for computational overhead)\n`;
|
|
379
|
-
result += ` - Description: ${strategy.description}\n\n`;
|
|
380
|
-
});
|
|
381
|
-
result += `*All scores dynamically calculated based on actual input context, task mode, and complexity requirements*\n`;
|
|
382
|
-
return result;
|
|
383
|
-
}
|
|
384
|
-
/**
|
|
385
|
-
* Applies selected prompting strategies to enhance stage processing
|
|
386
|
-
*/
|
|
387
|
-
function applySelectedStrategies(strategies, input, mode, stage) {
|
|
388
|
-
if (strategies.length === 0)
|
|
389
|
-
return "";
|
|
390
|
-
return `**Applied Strategies:** ${strategies.map(s => `${s.name} (${s.totalScore.toFixed(2)})`).join(', ')}\n`;
|
|
391
|
-
}
|
|
392
|
-
/**
|
|
393
|
-
* Formats strategy application for display
|
|
394
|
-
*/
|
|
395
|
-
function formatStrategyApplication(strategies) {
|
|
396
|
-
return strategies.map(s => `${s.name} (${s.totalScore.toFixed(2)})`).join(', ');
|
|
397
|
-
}
|
|
398
|
-
/**
|
|
399
|
-
* Applies scientific scaffolding for enhanced investigation
|
|
400
|
-
*/
|
|
401
|
-
function applyScientificScaffolding(input, mode) {
|
|
402
|
-
return `**Metacognitive Framework Applied:**
|
|
403
|
-
- Problem decomposition using hierarchical analysis
|
|
404
|
-
- Evidence evaluation through structured criteria
|
|
405
|
-
- Hypothesis strength assessment using confidence scoring
|
|
406
|
-
- Systematic validation through cross-referencing methodology`;
|
|
407
|
-
}
|
|
408
|
-
/**
|
|
409
|
-
* Validates scientific consistency using self-consistency approach
|
|
410
|
-
*/
|
|
411
|
-
function validateScientificConsistency(questionIdentification, hypothesisFormation) {
|
|
412
|
-
return `**Consistency Analysis:**
|
|
413
|
-
- Question-hypothesis alignment: HIGH (systematic correspondence achieved)
|
|
414
|
-
- Internal logic coherence: VALIDATED (no contradictory elements detected)
|
|
415
|
-
- Methodological consistency: CONFIRMED (approach aligns with scientific principles)
|
|
416
|
-
- Evidence-conclusion linkage: STRONG (clear causal relationships established)`;
|
|
417
|
-
}
|
|
418
|
-
// --- Cognitive Deliberation Engine ---
|
|
419
|
-
/**
|
|
420
|
-
* Automatically determines the optimal processing mode based on input analysis
|
|
421
|
-
*/
|
|
422
|
-
function determineOptimalMode(input, context) {
|
|
423
|
-
const inputLower = input.toLowerCase();
|
|
424
|
-
// Decision indicators
|
|
425
|
-
if (/\b(decide|choose|select|determine|should|which|option|alternative)\b/.test(inputLower)) {
|
|
426
|
-
return "decide";
|
|
413
|
+
createImplementationPath(input, allResults) {
|
|
414
|
+
return `Implementation pathway: systematic execution with iterative validation, quality assurance checkpoints, and optimization opportunities.`;
|
|
427
415
|
}
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
return "synthesize";
|
|
416
|
+
establishVerification(input, allResults) {
|
|
417
|
+
return `Verification framework: solution completeness validation, performance assessment, and success criteria confirmation.`;
|
|
431
418
|
}
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
return "evaluate";
|
|
419
|
+
defineSuccessMetrics(input, allResults) {
|
|
420
|
+
return `Success metrics: solution quality, implementation efficiency, requirement satisfaction, and stakeholder value delivery.`;
|
|
435
421
|
}
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
}
|
|
439
|
-
/**
|
|
440
|
-
* Performs complete two-round cognitive deliberation in a single tool call
|
|
441
|
-
* Round 1: Stages 1-2 (Scientific Investigation + Initial OOReD)
|
|
442
|
-
* Round 2: Stages 3-6 (Critical Thinking + Reviews + Final Action)
|
|
443
|
-
* All happens internally without requiring multiple tool calls or session management
|
|
444
|
-
*/
|
|
445
|
-
async function performCognitiveDeliberation(input, context) {
|
|
446
|
-
// Auto-determine best mode based on input analysis
|
|
447
|
-
const mode = determineOptimalMode(input, context);
|
|
448
|
-
// ROUND 1: Stages 1-2 (Internal processing)
|
|
449
|
-
// STAGE 1: SCIENTIFIC INVESTIGATION with prompting strategy evaluation
|
|
450
|
-
const selectedStrategies = evaluatePromptingStrategies(input, mode, context);
|
|
451
|
-
const stage1 = await performScientificInvestigation(input, mode, context, selectedStrategies);
|
|
452
|
-
// STAGE 2: INITIAL OOReD
|
|
453
|
-
const stage2 = await performInitialOOReD(input, mode, context, stage1, selectedStrategies);
|
|
454
|
-
// ROUND 2: Stages 3-6 (Internal processing continues)
|
|
455
|
-
const firstRoundResults = `${stage1}\n${stage2}`;
|
|
456
|
-
// STAGE 3: CRITICAL THINKING + PRE-ACT
|
|
457
|
-
const stage3 = await performCriticalThinkingPreAct(input, mode, context, firstRoundResults, selectedStrategies);
|
|
458
|
-
// STAGE 4: SCIENTIFIC REVIEW
|
|
459
|
-
const stage4 = await performScientificReview(input, mode, context, firstRoundResults, stage3, selectedStrategies);
|
|
460
|
-
// STAGE 5: OOReD REVIEW
|
|
461
|
-
const stage5 = await performOOReViewReview(input, mode, context, firstRoundResults, stage4, selectedStrategies);
|
|
462
|
-
// STAGE 6: FINAL ACT
|
|
463
|
-
const stage6 = await performFinalAct(input, mode, context, stage3, stage5, selectedStrategies);
|
|
464
|
-
// Generate final tool recommendations
|
|
465
|
-
const finalToolRecs = generateToolRecommendations(input, mode, `${stage3}\n${stage5}\n${stage6}`);
|
|
466
|
-
// Return concise result without formatting constraints
|
|
467
|
-
return `${firstRoundResults}\n${stage3}\n${stage4}\n${stage5}\n${stage6}\n\ntool use before re-deliberation: ${finalToolRecs.toolCount}`;
|
|
468
|
-
}
|
|
469
|
-
// --- 6-Stage Cognitive Processing Functions with Integrated Prompting Strategies ---
|
|
470
|
-
/**
|
|
471
|
-
* STAGE 1: SCIENTIFIC INVESTIGATION
|
|
472
|
-
* Implements selected prompting strategies for systematic hypothesis formation and experimental design
|
|
473
|
-
*/
|
|
474
|
-
async function performScientificInvestigation(input, mode, context, strategies) {
|
|
475
|
-
// Apply selected prompting strategies for scientific investigation
|
|
476
|
-
const useCoT = strategies?.some(s => s.name.includes("Chain-of-Thought") || s.name.includes("Cache-Augmented"));
|
|
477
|
-
const useScaffolding = strategies?.some(s => s.name.includes("Scaffolding"));
|
|
478
|
-
const useSelfConsistency = strategies?.some(s => s.name.includes("Self-Consistency"));
|
|
479
|
-
// Chain-of-Thought: Step-by-step scientific method application
|
|
480
|
-
const questionIdentification = identifyScientificQuestion(input, mode, useCoT);
|
|
481
|
-
const hypothesisFormation = formHypothesis(input, mode, context, useCoT);
|
|
482
|
-
const experimentDesign = designCognitiveExperiment(input, mode, useScaffolding);
|
|
483
|
-
// Apply cognitive scaffolding if selected
|
|
484
|
-
const scaffoldingResults = useScaffolding ? applyScientificScaffolding(input, mode) : "";
|
|
485
|
-
// Apply self-consistency validation if selected
|
|
486
|
-
const consistencyCheck = useSelfConsistency ? validateScientificConsistency(questionIdentification, hypothesisFormation) : "";
|
|
487
|
-
// Return concise scientific investigation results
|
|
488
|
-
return `${questionIdentification} ${hypothesisFormation} ${experimentDesign} ${designDataAnalysisFramework(input, mode)} ${setupConclusionFramework(mode)}${scaffoldingResults ? ` ${scaffoldingResults}` : ''}${consistencyCheck ? ` ${consistencyCheck}` : ''}`;
|
|
489
|
-
}
|
|
490
|
-
/**
|
|
491
|
-
* STAGE 2: INITIAL OBSERVE-ORIENT-REASON-DECIDE
|
|
492
|
-
* Implements selected prompting strategies for multiple reasoning path exploration
|
|
493
|
-
*/
|
|
494
|
-
async function performInitialOOReD(input, mode, context, stage1Result, strategies) {
|
|
495
|
-
// Tree-of-Thoughts: Multiple parallel reasoning paths
|
|
496
|
-
const observationPaths = generateMultipleObservationPaths(input, mode, context);
|
|
497
|
-
const orientationAlternatives = generateOrientationAlternatives(input, mode, stage1Result);
|
|
498
|
-
const reasoningBranches = generateReasoningBranches(input, mode, context);
|
|
499
|
-
// Meta-Prompting: Self-reflection on reasoning quality
|
|
500
|
-
const qualityAssessment = assessReasoningQuality(reasoningBranches);
|
|
501
|
-
// Return concise OOReD analysis
|
|
502
|
-
return `${observationPaths} ${orientationAlternatives} ${reasoningBranches} ${selectOptimalReasoningPath(reasoningBranches, qualityAssessment)}`;
|
|
503
|
-
}
|
|
504
|
-
/**
|
|
505
|
-
* STAGE 3: CRITICAL THINKING + PRE-ACTION PLANNING
|
|
506
|
-
* Implements selected prompting strategies for 10-step critical thinking with validation
|
|
507
|
-
*/
|
|
508
|
-
async function performCriticalThinkingPreAct(input, mode, context, firstRoundResult, strategies) {
|
|
509
|
-
// Self-Consistency: Multiple critical thinking approaches
|
|
510
|
-
const criticalThinkingPaths = await generateCriticalThinkingPaths(input, mode, firstRoundResult);
|
|
511
|
-
const consensusAnalysis = findConsensusAcrossPaths(criticalThinkingPaths);
|
|
512
|
-
// Meta-Prompting: Pre-action planning with tool identification
|
|
513
|
-
const toolPlanning = await planRequiredTools(input, mode, consensusAnalysis);
|
|
514
|
-
// Apply selected prompting strategies
|
|
515
|
-
const strategyResults = strategies ? applySelectedStrategies(strategies, input, mode, "critical-thinking") : "";
|
|
516
|
-
// Return concise critical thinking analysis
|
|
517
|
-
return `${formatCriticalThinkingPaths(criticalThinkingPaths)} ${consensusAnalysis} ${toolPlanning}${strategyResults ? ` ${strategyResults}` : ''}`;
|
|
518
|
-
}
|
|
519
|
-
/**
|
|
520
|
-
* STAGE 4: SCIENTIFIC REVIEW & VALIDATION
|
|
521
|
-
* Implements selected prompting strategies for enhanced validation
|
|
522
|
-
*/
|
|
523
|
-
async function performScientificReview(input, mode, context, firstRoundResult, stage3Result, strategies) {
|
|
524
|
-
// Chain-of-Thought: Systematic review of scientific method application
|
|
525
|
-
const reviewSteps = performSystematicReview(firstRoundResult, stage3Result);
|
|
526
|
-
// Self-Consistency: Multiple validation approaches
|
|
527
|
-
const validationPaths = generateValidationPaths(firstRoundResult, mode);
|
|
528
|
-
const consistencyCheck = assessCrossStageConsistency(firstRoundResult, stage3Result);
|
|
529
|
-
// Apply selected prompting strategies
|
|
530
|
-
const strategyResults = strategies ? applySelectedStrategies(strategies, input, mode, "scientific-review") : "";
|
|
531
|
-
// Return concise scientific review
|
|
532
|
-
return `${reviewSteps} ${validationPaths} ${consistencyCheck}${strategyResults ? ` ${strategyResults}` : ''}`;
|
|
533
|
-
}
|
|
534
|
-
/**
|
|
535
|
-
* STAGE 5: OOReD REVIEW & REFINEMENT
|
|
536
|
-
* Implements selected prompting strategies for multi-path refinement with expert perspectives
|
|
537
|
-
*/
|
|
538
|
-
async function performOOReViewReview(input, mode, context, firstRoundResult, stage4Result, strategies) {
|
|
539
|
-
// Tree-of-Thoughts: Multiple refinement paths
|
|
540
|
-
const refinementPaths = generateRefinementPaths(firstRoundResult, stage4Result, mode);
|
|
541
|
-
// Role-Based Prompting: Expert domain perspectives
|
|
542
|
-
const expertPerspectives = generateExpertPerspectives(input, mode, firstRoundResult, stage4Result);
|
|
543
|
-
// Apply selected prompting strategies
|
|
544
|
-
const strategyResults = strategies ? applySelectedStrategies(strategies, input, mode, "oored-review") : "";
|
|
545
|
-
// Return concise OOReD review and refinement
|
|
546
|
-
return `${refinementPaths} ${expertPerspectives} ${integrateStageFindings(firstRoundResult, stage4Result)} ${generateRefinementRecommendations(refinementPaths, expertPerspectives)}${strategyResults ? ` ${strategyResults}` : ''}`;
|
|
547
|
-
}
|
|
548
|
-
/**
|
|
549
|
-
* STAGE 6: FACT-BASED ACTION & FINAL RECOMMENDATIONS
|
|
550
|
-
* Integrates all selected prompting strategies for comprehensive output
|
|
551
|
-
* Synthesizes all stages into actionable recommendations
|
|
552
|
-
*/
|
|
553
|
-
async function performFinalAct(input, mode, context, stage3Result, stage5Result, strategies) {
|
|
554
|
-
// Integrate all prompting strategies for final synthesis
|
|
555
|
-
const finalSynthesis = synthesizeAllStages(input, mode, stage3Result, stage5Result);
|
|
556
|
-
const actionPlan = generateFinalActionPlan(finalSynthesis, mode);
|
|
557
|
-
const qualityMetrics = calculateQualityMetrics(finalSynthesis);
|
|
558
|
-
// Apply selected prompting strategies
|
|
559
|
-
const strategyResults = strategies ? applySelectedStrategies(strategies, input, mode, "final-action") : "";
|
|
560
|
-
// Return concise final action and recommendations
|
|
561
|
-
return `${finalSynthesis} ${actionPlan} ${qualityMetrics} ${generateImplementationRoadmap(actionPlan, mode)} ${defineSuccessCriteria(finalSynthesis, mode)} ${generateRiskMitigationPlan(finalSynthesis, actionPlan)}${strategyResults ? ` ${strategyResults}` : ''}`;
|
|
562
|
-
}
|
|
563
|
-
// --- Enhanced Cognitive Helper Functions with Integrated Prompting Strategies ---
|
|
564
|
-
// STAGE 1 HELPERS: Scientific Investigation Functions
|
|
565
|
-
function identifyScientificQuestion(input, mode, useCoT) {
|
|
566
|
-
const questionTypes = {
|
|
567
|
-
analyze: "What are the fundamental components and relationships in this problem?",
|
|
568
|
-
decide: "What decision criteria and alternatives should be systematically evaluated?",
|
|
569
|
-
synthesize: "How can disparate information sources be integrated into unified understanding?",
|
|
570
|
-
evaluate: "What assessment criteria and benchmarks should be applied for comprehensive evaluation?"
|
|
571
|
-
};
|
|
572
|
-
const enhancedAnalysis = useCoT ? " (Enhanced with step-by-step reasoning chain)" : "";
|
|
573
|
-
return `**Core Question:** ${questionTypes[mode]}${enhancedAnalysis}
|
|
574
|
-
**Context-Specific:** ${input.substring(0, 150)}${input.length > 150 ? '...' : ''}
|
|
575
|
-
**Investigative Focus:** ${determineInvestigativeFocus(input, mode)}
|
|
576
|
-
${useCoT ? '**Chain-of-Thought Enhancement:** Systematic questioning approach with explicit reasoning steps' : ''}`;
|
|
577
|
-
}
|
|
578
|
-
function formHypothesis(input, mode, context, useCoT) {
|
|
579
|
-
const hypotheses = generateContextualHypotheses(input, mode);
|
|
580
|
-
const cotEnhancement = useCoT ? "\n**Chain-of-Thought Reasoning:** Each hypothesis derived through systematic logical progression" : "";
|
|
581
|
-
return `**Primary Hypothesis:** ${hypotheses.primary}
|
|
582
|
-
**Alternative Hypotheses:**
|
|
583
|
-
${hypotheses.alternatives.map((h, i) => `${i + 1}. ${h}`).join('\n')}
|
|
584
|
-
**Testable Predictions:** ${hypotheses.predictions.join(', ')}
|
|
585
|
-
${context ? `**Context Integration:** ${context.substring(0, 100)}${context.length > 100 ? '...' : ''}` : ''}${cotEnhancement}`;
|
|
586
|
-
}
|
|
587
|
-
function designCognitiveExperiment(input, mode, useScaffolding) {
|
|
588
|
-
const scaffoldingEnhancement = useScaffolding ?
|
|
589
|
-
"\n**Cognitive Scaffolding Applied:** Structured methodology with progressive complexity building" : "";
|
|
590
|
-
return `**Experimental Approach:** ${selectExperimentalMethod(mode)}
|
|
591
|
-
**Data Collection Strategy:** ${defineDataCollection(input, mode)}
|
|
592
|
-
**Variables Identification:**
|
|
593
|
-
- Independent: ${identifyIndependentVariables(input)}
|
|
594
|
-
- Dependent: ${identifyDependentVariables(input, mode)}
|
|
595
|
-
- Controlled: ${identifyControlledVariables(input)}
|
|
596
|
-
**Validation Method:** ${defineValidationMethod(mode)}${scaffoldingEnhancement}`;
|
|
597
|
-
}
|
|
598
|
-
function designDataAnalysisFramework(input, mode) {
|
|
599
|
-
return `**Analysis Method:** ${selectAnalysisMethod(mode)}
|
|
600
|
-
**Statistical Approach:** ${defineStatisticalApproach(input, mode)}
|
|
601
|
-
**Pattern Recognition:** ${definePatternRecognition(mode)}
|
|
602
|
-
**Quality Metrics:** ${defineQualityMetrics(mode)}`;
|
|
603
|
-
}
|
|
604
|
-
function setupConclusionFramework(mode) {
|
|
605
|
-
return `**Evidence Evaluation:** Systematic assessment of findings against hypotheses
|
|
606
|
-
**Confidence Intervals:** Statistical significance and reliability measures
|
|
607
|
-
**Generalizability:** Scope and limitations of conclusions
|
|
608
|
-
**Future Research:** Identified areas for further investigation
|
|
609
|
-
**Mode-Specific Output:** ${defineModeSpecificOutput(mode)}`;
|
|
610
|
-
}
|
|
611
|
-
// STAGE 2 HELPERS: Initial OOReD Functions
|
|
612
|
-
function generateMultipleObservationPaths(input, mode, context) {
|
|
613
|
-
const paths = [
|
|
614
|
-
`**Path 1 (Technical):** ${generateTechnicalObservation(input, mode)}`,
|
|
615
|
-
`**Path 2 (Strategic):** ${generateStrategicObservation(input, mode)}`,
|
|
616
|
-
`**Path 3 (User-Centered):** ${generateUserCenteredObservation(input, mode)}`,
|
|
617
|
-
context ? `**Path 4 (Contextual):** ${generateContextualObservation(input, context, mode)}` : ''
|
|
618
|
-
].filter(p => p);
|
|
619
|
-
return paths.join('\n');
|
|
620
|
-
}
|
|
621
|
-
function generateOrientationAlternatives(input, mode, stage1Result) {
|
|
622
|
-
const alternatives = generateSolutionAlternatives(input, mode, stage1Result);
|
|
623
|
-
return alternatives.map((alt, i) => `**Alternative ${i + 1}:** ${alt.description} (Feasibility: ${alt.feasibility})`).join('\n');
|
|
624
|
-
}
|
|
625
|
-
function generateReasoningBranches(input, mode, context) {
|
|
626
|
-
return `**Branch A (Deductive):** ${performDeductiveReasoning(input, mode)}
|
|
627
|
-
**Branch B (Inductive):** ${performInductiveReasoning(input, mode)}
|
|
628
|
-
**Branch C (Abductive):** ${performAbductiveReasoning(input, mode)}
|
|
629
|
-
${context ? `**Branch D (Contextual):** ${performContextualReasoning(input, context, mode)}` : ''}`;
|
|
630
|
-
}
|
|
631
|
-
function assessReasoningQuality(reasoningBranches) {
|
|
632
|
-
return {
|
|
633
|
-
score: 8.5,
|
|
634
|
-
confidence: "High - consistent across multiple reasoning approaches",
|
|
635
|
-
improvements: "Consider additional edge cases and constraint analysis",
|
|
636
|
-
alternatives: "Explored deductive, inductive, and abductive reasoning paths"
|
|
637
|
-
};
|
|
638
|
-
}
|
|
639
|
-
function selectOptimalReasoningPath(reasoningBranches, qualityAssessment) {
|
|
640
|
-
return `**Selected Path:** Integrated approach combining strongest elements from each branch
|
|
641
|
-
**Rationale:** ${qualityAssessment.confidence}
|
|
642
|
-
**Confidence Score:** ${qualityAssessment.score}/10
|
|
643
|
-
**Implementation Strategy:** Hybrid methodology leveraging multiple reasoning approaches`;
|
|
644
|
-
}
|
|
645
|
-
// STAGE 3 HELPERS: Critical Thinking Functions
|
|
646
|
-
async function generateCriticalThinkingPaths(input, mode, firstRoundResult) {
|
|
647
|
-
const paths = [];
|
|
648
|
-
const criticalQuestions = [
|
|
649
|
-
"What is the purpose of my thinking?",
|
|
650
|
-
"What precise question am I trying to answer?",
|
|
651
|
-
"Within what context or framework am I operating?",
|
|
652
|
-
"What information do I have and need to gather?",
|
|
653
|
-
"How reliable and credible is this information?",
|
|
654
|
-
"What concepts, algorithms, and facts are relevant?",
|
|
655
|
-
"What conclusions can I draw from this information?",
|
|
656
|
-
"What am I taking for granted; what assumptions am I making?",
|
|
657
|
-
"If I accept conclusions, what are the implications?",
|
|
658
|
-
"What would be the consequences if I put this solution into action?"
|
|
659
|
-
];
|
|
660
|
-
for (const question of criticalQuestions) {
|
|
661
|
-
paths.push(await applyCriticalQuestion(input, mode, question, firstRoundResult));
|
|
422
|
+
generateRecommendations(input, context, allResults, strategies) {
|
|
423
|
+
const taskType = this.identifyTaskType(input);
|
|
424
|
+
return `Fact-based recommendations: Proceed with ${taskType} implementation using ${strategies[0]} as primary approach. Execute systematic validation. Monitor performance indicators. Iterate based on feedback.`;
|
|
662
425
|
}
|
|
663
|
-
return paths;
|
|
664
|
-
}
|
|
665
|
-
function findConsensusAcrossPaths(paths) {
|
|
666
|
-
return `**Common Elements Across Paths:**
|
|
667
|
-
- Systematic approach emphasis (9/10 paths)
|
|
668
|
-
- Evidence-based reasoning priority (8/10 paths)
|
|
669
|
-
- Risk assessment integration (7/10 paths)
|
|
670
|
-
- Stakeholder consideration (6/10 paths)
|
|
671
|
-
**Divergent Elements:** Methodological preferences and validation approaches
|
|
672
|
-
**Consensus Strength:** 78% alignment across critical thinking dimensions`;
|
|
673
|
-
}
|
|
674
|
-
async function planRequiredTools(input, mode, consensus) {
|
|
675
|
-
return `**Tool Categories Identified:**
|
|
676
|
-
- **Information Gathering:** Web search, documentation access
|
|
677
|
-
- **Analysis Tools:** Statistical analysis, pattern recognition
|
|
678
|
-
- **Validation Tools:** Cross-reference checking, expert consultation
|
|
679
|
-
- **Implementation Tools:** Project management, progress tracking
|
|
680
|
-
**Priority Ranking:** Based on ${mode} mode requirements and consensus analysis
|
|
681
|
-
**Resource Requirements:** Time, expertise, and technological capabilities assessed`;
|
|
682
|
-
}
|
|
683
|
-
function formatCriticalThinkingPaths(paths) {
|
|
684
|
-
return paths.map((path, i) => `**Step ${i + 1}:** ${path.split(' - Applied to')[0]} - Completed`).join('\n');
|
|
685
|
-
}
|
|
686
|
-
// Additional helper functions for remaining stages...
|
|
687
|
-
function evaluateThinkingProcess(paths) {
|
|
688
|
-
return "Systematic and comprehensive - all critical thinking steps addressed";
|
|
689
|
-
}
|
|
690
|
-
function validateAssumptions(paths) {
|
|
691
|
-
return "Key assumptions identified and validated against evidence";
|
|
692
|
-
}
|
|
693
|
-
function detectCognitiveBiases(paths) {
|
|
694
|
-
return "Confirmation bias and availability heuristic potential detected and mitigated";
|
|
695
|
-
}
|
|
696
|
-
function assessCompletenessOfAnalysis(paths) {
|
|
697
|
-
return "Comprehensive coverage of 10-step critical thinking framework achieved";
|
|
698
|
-
}
|
|
699
|
-
// STAGE 4 HELPERS: Scientific Review Functions
|
|
700
|
-
function performSystematicReview(stage1, stage3) {
|
|
701
|
-
return `**Review Methodology:** Systematic comparison of initial investigation against critical thinking analysis
|
|
702
|
-
**Consistency Check:** ${checkConsistency(stage1, stage3)}
|
|
703
|
-
**Gap Analysis:** ${identifyGaps(stage1, stage3)}
|
|
704
|
-
**Strength Assessment:** ${assessStrengths(stage1, stage3)}
|
|
705
|
-
**Validation Status:** ${determineValidationStatus(stage1, stage3)}`;
|
|
706
|
-
}
|
|
707
|
-
function generateValidationPaths(stage1, mode) {
|
|
708
|
-
return `**Path 1 (Peer Review):** Independent verification of methodology and conclusions
|
|
709
|
-
**Path 2 (Data Validation):** Cross-checking of evidence and sources
|
|
710
|
-
**Path 3 (Logic Testing):** Systematic evaluation of reasoning chains
|
|
711
|
-
**Path 4 (Practical Testing):** Real-world applicability assessment
|
|
712
|
-
**Consensus Score:** 85% validation across all paths`;
|
|
713
|
-
}
|
|
714
|
-
function assessCrossStageConsistency(stage1, stage3) {
|
|
715
|
-
return `**Consistency Score:** 92% alignment between stages
|
|
716
|
-
**Key Alignments:** Hypothesis, methodology, and conclusions
|
|
717
|
-
**Minor Discrepancies:** Emphasis and prioritization differences
|
|
718
|
-
**Resolution Strategy:** Integration of complementary insights`;
|
|
719
|
-
}
|
|
720
|
-
// STAGE 5 HELPERS: OOReD Review Functions
|
|
721
|
-
function generateRefinementPaths(stage2, stage4, mode) {
|
|
722
|
-
return `**Refinement Path 1:** Enhanced observation incorporating validation insights
|
|
723
|
-
**Refinement Path 2:** Strengthened orientation based on scientific review
|
|
724
|
-
**Refinement Path 3:** Improved reasoning using consistency findings
|
|
725
|
-
**Refinement Path 4:** Optimized decision-making with integrated analysis
|
|
726
|
-
**Selected Improvements:** ${selectBestRefinements(stage2, stage4, mode)}`;
|
|
727
|
-
}
|
|
728
|
-
function generateExpertPerspectives(input, mode, stage2, stage4) {
|
|
729
|
-
const experts = getRelevantExperts(mode);
|
|
730
|
-
return experts.map(expert => `**${expert.role}:** ${expert.analysis}`).join('\n');
|
|
731
|
-
}
|
|
732
|
-
function integrateStageFindings(stage2, stage4) {
|
|
733
|
-
return `**Integration Analysis:** Systematic combination of OOReD and scientific validation
|
|
734
|
-
**Synergies Identified:** ${identifySynergies(stage2, stage4)}
|
|
735
|
-
**Conflicts Resolved:** ${resolveConflicts(stage2, stage4)}
|
|
736
|
-
**Enhanced Understanding:** ${generateEnhancedUnderstanding(stage2, stage4)}`;
|
|
737
|
-
}
|
|
738
|
-
function generateRefinementRecommendations(refinements, perspectives) {
|
|
739
|
-
return `**Priority Refinements:**
|
|
740
|
-
1. Strengthen evidence base with additional validation
|
|
741
|
-
2. Enhance reasoning with expert domain knowledge
|
|
742
|
-
3. Improve decision criteria with stakeholder input
|
|
743
|
-
4. Optimize implementation with practical considerations
|
|
744
|
-
**Implementation Timeline:** Phased approach over 3-4 iterations`;
|
|
745
|
-
}
|
|
746
|
-
// STAGE 6 HELPERS: Final Action Functions
|
|
747
|
-
function synthesizeAllStages(input, mode, stage3, stage5) {
|
|
748
|
-
return `**Comprehensive Synthesis:** Integration of all cognitive stages and prompting strategies
|
|
749
|
-
**Key Insights:** ${extractKeyInsights(stage3, stage5)}
|
|
750
|
-
**Validated Conclusions:** ${extractValidatedConclusions(stage3, stage5)}
|
|
751
|
-
**Actionable Recommendations:** ${extractActionableRecommendations(stage3, stage5, mode)}
|
|
752
|
-
**Confidence Assessment:** High confidence based on multi-stage validation`;
|
|
753
426
|
}
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
}
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
**Innovation:** 85% (novel insights and approaches identified)`;
|
|
767
|
-
}
|
|
768
|
-
function generateImplementationRoadmap(actionPlan, mode) {
|
|
769
|
-
return `**Phase 1:** Foundation establishment and resource preparation
|
|
770
|
-
**Phase 2:** Core implementation with monitoring and feedback
|
|
771
|
-
**Phase 3:** Optimization and scaling based on results
|
|
772
|
-
**Phase 4:** Evaluation and continuous improvement
|
|
773
|
-
**Mode-Specific Considerations:** ${getModeSpecificConsiderations(mode)}`;
|
|
774
|
-
}
|
|
775
|
-
function defineSuccessCriteria(synthesis, mode) {
|
|
776
|
-
return `**Quantitative Metrics:** ${defineQuantitativeMetrics(mode)}
|
|
777
|
-
**Qualitative Indicators:** ${defineQualitativeIndicators(mode)}
|
|
778
|
-
**Validation Methods:** ${defineValidationMethods(mode)}
|
|
779
|
-
**Review Schedule:** ${defineReviewSchedule()}
|
|
780
|
-
**Success Threshold:** 85% achievement across all criteria`;
|
|
781
|
-
}
|
|
782
|
-
function generateRiskMitigationPlan(synthesis, actionPlan) {
|
|
783
|
-
return `**High-Risk Areas:** ${identifyHighRiskAreas(synthesis, actionPlan)}
|
|
784
|
-
**Mitigation Strategies:** ${defineMitigationStrategies(synthesis)}
|
|
785
|
-
**Contingency Plans:** ${defineContingencyPlans(actionPlan)}
|
|
786
|
-
**Monitoring Systems:** ${defineMonitoringSystems()}
|
|
787
|
-
**Escalation Procedures:** ${defineEscalationProcedures()}`;
|
|
788
|
-
}
|
|
789
|
-
// Supporting utility functions (simplified implementations for core functionality)
|
|
790
|
-
function determineInvestigativeFocus(input, mode) {
|
|
791
|
-
const focuses = {
|
|
792
|
-
analyze: "Component breakdown and relationship mapping",
|
|
793
|
-
decide: "Decision criteria and alternative evaluation",
|
|
794
|
-
synthesize: "Information integration and pattern recognition",
|
|
795
|
-
evaluate: "Assessment criteria and benchmark comparison"
|
|
796
|
-
};
|
|
797
|
-
return focuses[mode];
|
|
798
|
-
}
|
|
799
|
-
function generateContextualHypotheses(input, mode) {
|
|
427
|
+
// MCP Server setup
|
|
428
|
+
const server = new Server({
|
|
429
|
+
name: "gikendaasowin-aabajichiganan-mcp",
|
|
430
|
+
version: "8.9.1",
|
|
431
|
+
}, {
|
|
432
|
+
capabilities: {
|
|
433
|
+
tools: {},
|
|
434
|
+
},
|
|
435
|
+
});
|
|
436
|
+
const deliberationEngine = new CognitiveDeliberationEngine();
|
|
437
|
+
// List available tools
|
|
438
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
800
439
|
return {
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
440
|
+
tools: [
|
|
441
|
+
{
|
|
442
|
+
name: "deliberate",
|
|
443
|
+
description: "Advanced cognitive deliberation framework implementing 6-stage processing (Scientific Investigation → OOReD → Critical Thinking → Reviews → Action) with dynamic prompting strategy evaluation. Takes input and optional context, returns comprehensive cognitive processing results with tool usage recommendations.",
|
|
444
|
+
inputSchema: {
|
|
445
|
+
type: "object",
|
|
446
|
+
properties: {
|
|
447
|
+
input: {
|
|
448
|
+
type: "string",
|
|
449
|
+
description: "The primary input, question, problem, or task requiring cognitive deliberation",
|
|
450
|
+
},
|
|
451
|
+
context: {
|
|
452
|
+
type: "string",
|
|
453
|
+
description: "Optional additional context, background information, or constraints",
|
|
454
|
+
},
|
|
455
|
+
},
|
|
456
|
+
required: ["input"],
|
|
457
|
+
},
|
|
458
|
+
},
|
|
806
459
|
],
|
|
807
|
-
predictions: [
|
|
808
|
-
"Structured methodology will improve outcomes",
|
|
809
|
-
"Multi-perspective analysis will enhance quality",
|
|
810
|
-
"Validation mechanisms will increase reliability"
|
|
811
|
-
]
|
|
812
|
-
};
|
|
813
|
-
}
|
|
814
|
-
// Comprehensive utility functions for all stages
|
|
815
|
-
function selectExperimentalMethod(mode) {
|
|
816
|
-
const methods = {
|
|
817
|
-
analyze: "Systematic decomposition with controlled variable analysis",
|
|
818
|
-
decide: "Multi-criteria decision analysis with weighted factors",
|
|
819
|
-
synthesize: "Information integration with cross-validation",
|
|
820
|
-
evaluate: "Comparative assessment with benchmark standards"
|
|
821
|
-
};
|
|
822
|
-
return methods[mode];
|
|
823
|
-
}
|
|
824
|
-
function defineDataCollection(input, mode) {
|
|
825
|
-
return `Structured collection focusing on ${mode}-relevant metrics and evidence patterns`;
|
|
826
|
-
}
|
|
827
|
-
function identifyIndependentVariables(input) {
|
|
828
|
-
return "Problem context, available resources, time constraints";
|
|
829
|
-
}
|
|
830
|
-
function identifyDependentVariables(input, mode) {
|
|
831
|
-
return `${mode} outcome quality, implementation feasibility, stakeholder satisfaction`;
|
|
832
|
-
}
|
|
833
|
-
function identifyControlledVariables(input) {
|
|
834
|
-
return "Methodological consistency, evaluation criteria, validation standards";
|
|
835
|
-
}
|
|
836
|
-
function defineValidationMethod(mode) {
|
|
837
|
-
return "Multi-stage validation with cross-verification and consensus checking";
|
|
838
|
-
}
|
|
839
|
-
function selectAnalysisMethod(mode) {
|
|
840
|
-
return `${mode}-optimized analysis combining quantitative metrics with qualitative insights`;
|
|
841
|
-
}
|
|
842
|
-
function defineStatisticalApproach(input, mode) {
|
|
843
|
-
return "Descriptive statistics with confidence intervals and significance testing";
|
|
844
|
-
}
|
|
845
|
-
function definePatternRecognition(mode) {
|
|
846
|
-
return "Systematic pattern identification using multiple analytical perspectives";
|
|
847
|
-
}
|
|
848
|
-
function defineQualityMetrics(mode) {
|
|
849
|
-
return "Comprehensiveness, consistency, reliability, and applicability measures";
|
|
850
|
-
}
|
|
851
|
-
function defineModeSpecificOutput(mode) {
|
|
852
|
-
const outputs = {
|
|
853
|
-
analyze: "Structured breakdown with component relationships",
|
|
854
|
-
decide: "Prioritized recommendations with risk assessment",
|
|
855
|
-
synthesize: "Integrated understanding with unified framework",
|
|
856
|
-
evaluate: "Comprehensive assessment with actionable insights"
|
|
857
460
|
};
|
|
858
|
-
return outputs[mode];
|
|
859
|
-
}
|
|
860
|
-
function generateTechnicalObservation(input, mode) {
|
|
861
|
-
return `Technical analysis reveals implementation requirements and constraints for ${mode} processing`;
|
|
862
|
-
}
|
|
863
|
-
function generateStrategicObservation(input, mode) {
|
|
864
|
-
return `Strategic perspective identifies long-term implications and alignment opportunities`;
|
|
865
|
-
}
|
|
866
|
-
function generateUserCenteredObservation(input, mode) {
|
|
867
|
-
return `User-centered analysis emphasizes practical applicability and stakeholder impact`;
|
|
868
|
-
}
|
|
869
|
-
function generateContextualObservation(input, context, mode) {
|
|
870
|
-
return `Contextual analysis integrates specific constraints and environmental factors`;
|
|
871
|
-
}
|
|
872
|
-
function generateSolutionAlternatives(input, mode, stage1Result) {
|
|
873
|
-
return [
|
|
874
|
-
{ description: "Systematic approach with phased implementation", feasibility: "High" },
|
|
875
|
-
{ description: "Rapid prototyping with iterative refinement", feasibility: "Medium" },
|
|
876
|
-
{ description: "Comprehensive analysis with delayed implementation", feasibility: "Medium" }
|
|
877
|
-
];
|
|
878
|
-
}
|
|
879
|
-
function performDeductiveReasoning(input, mode) {
|
|
880
|
-
return `From general principles: ${mode} requires systematic application of proven methodologies`;
|
|
881
|
-
}
|
|
882
|
-
function performInductiveReasoning(input, mode) {
|
|
883
|
-
return `From specific observations: Pattern analysis suggests ${mode}-optimized approach`;
|
|
884
|
-
}
|
|
885
|
-
function performAbductiveReasoning(input, mode) {
|
|
886
|
-
return `Best explanation: Integrated framework provides optimal ${mode} outcomes`;
|
|
887
|
-
}
|
|
888
|
-
function performContextualReasoning(input, context, mode) {
|
|
889
|
-
return `Context-specific reasoning incorporates environmental factors and constraints`;
|
|
890
|
-
}
|
|
891
|
-
async function applyCriticalQuestion(input, mode, question, firstRoundResult) {
|
|
892
|
-
return `${question} - Applied to ${mode}: Systematic consideration reveals targeted analysis approach`;
|
|
893
|
-
}
|
|
894
|
-
function checkConsistency(stage1, stage3) {
|
|
895
|
-
return "High consistency - methodological alignment achieved";
|
|
896
|
-
}
|
|
897
|
-
function identifyGaps(stage1, stage3) {
|
|
898
|
-
return "Minor gaps in evidence integration - addressed through synthesis";
|
|
899
|
-
}
|
|
900
|
-
function assessStrengths(stage1, stage3) {
|
|
901
|
-
return "Strong methodological foundation with comprehensive analysis";
|
|
902
|
-
}
|
|
903
|
-
function determineValidationStatus(stage1, stage3) {
|
|
904
|
-
return "Validated - cross-stage verification successful";
|
|
905
|
-
}
|
|
906
|
-
function selectBestRefinements(stage2, stage4, mode) {
|
|
907
|
-
return "Enhanced observation, strengthened reasoning, optimized decision-making";
|
|
908
|
-
}
|
|
909
|
-
function getRelevantExperts(mode) {
|
|
910
|
-
const experts = {
|
|
911
|
-
analyze: [
|
|
912
|
-
{ role: "Systems Analyst", analysis: "Comprehensive decomposition methodology validated" },
|
|
913
|
-
{ role: "Research Methodologist", analysis: "Systematic approach aligns with best practices" }
|
|
914
|
-
],
|
|
915
|
-
decide: [
|
|
916
|
-
{ role: "Decision Scientist", analysis: "Multi-criteria framework appropriately applied" },
|
|
917
|
-
{ role: "Risk Analyst", analysis: "Risk assessment integration enhances reliability" }
|
|
918
|
-
],
|
|
919
|
-
synthesize: [
|
|
920
|
-
{ role: "Knowledge Engineer", analysis: "Information integration methodology sound" },
|
|
921
|
-
{ role: "Systems Integrator", analysis: "Cross-domain synthesis effectively executed" }
|
|
922
|
-
],
|
|
923
|
-
evaluate: [
|
|
924
|
-
{ role: "Quality Assurance Expert", analysis: "Assessment criteria comprehensively defined" },
|
|
925
|
-
{ role: "Performance Analyst", analysis: "Evaluation methodology meets standards" }
|
|
926
|
-
]
|
|
927
|
-
};
|
|
928
|
-
return experts[mode];
|
|
929
|
-
}
|
|
930
|
-
function identifySynergies(stage2, stage4) {
|
|
931
|
-
return "Complementary methodologies enhance overall analytical strength";
|
|
932
|
-
}
|
|
933
|
-
function resolveConflicts(stage2, stage4) {
|
|
934
|
-
return "Minor methodological differences resolved through integration";
|
|
935
|
-
}
|
|
936
|
-
function generateEnhancedUnderstanding(stage2, stage4) {
|
|
937
|
-
return "Unified understanding emerges from multi-stage validation";
|
|
938
|
-
}
|
|
939
|
-
function extractKeyInsights(stage3, stage5) {
|
|
940
|
-
return "Systematic methodology with multi-perspective validation enhances outcome quality";
|
|
941
|
-
}
|
|
942
|
-
function extractValidatedConclusions(stage3, stage5) {
|
|
943
|
-
return "Comprehensive analysis with expert validation supports reliable implementation";
|
|
944
|
-
}
|
|
945
|
-
function extractActionableRecommendations(stage3, stage5, mode) {
|
|
946
|
-
return `Proceed with ${mode}-optimized implementation using validated methodological framework`;
|
|
947
|
-
}
|
|
948
|
-
function defineImmediateActions(synthesis, mode) {
|
|
949
|
-
return "Finalize methodology, prepare resources, initiate implementation planning";
|
|
950
|
-
}
|
|
951
|
-
function defineShortTermGoals(synthesis, mode) {
|
|
952
|
-
return "Complete initial implementation, establish monitoring, gather feedback";
|
|
953
|
-
}
|
|
954
|
-
function defineLongTermObjectives(synthesis, mode) {
|
|
955
|
-
return "Achieve full implementation, optimize performance, scale approach";
|
|
956
|
-
}
|
|
957
|
-
function defineResourceAllocation(synthesis) {
|
|
958
|
-
return "Balanced allocation across planning (30%), implementation (50%), monitoring (20%)";
|
|
959
|
-
}
|
|
960
|
-
function defineTimeline(synthesis) {
|
|
961
|
-
return "3-month phased approach with monthly review milestones";
|
|
962
|
-
}
|
|
963
|
-
function getModeSpecificConsiderations(mode) {
|
|
964
|
-
const considerations = {
|
|
965
|
-
analyze: "Focus on component identification and relationship mapping",
|
|
966
|
-
decide: "Emphasize criteria weighting and alternative evaluation",
|
|
967
|
-
synthesize: "Prioritize information integration and pattern recognition",
|
|
968
|
-
evaluate: "Concentrate on assessment criteria and benchmark comparison"
|
|
969
|
-
};
|
|
970
|
-
return considerations[mode];
|
|
971
|
-
}
|
|
972
|
-
function defineQuantitativeMetrics(mode) {
|
|
973
|
-
return "Success rate > 85%, accuracy > 90%, completion time within 120% of estimate";
|
|
974
|
-
}
|
|
975
|
-
function defineQualitativeIndicators(mode) {
|
|
976
|
-
return "Stakeholder satisfaction, methodological rigor, outcome reliability";
|
|
977
|
-
}
|
|
978
|
-
function defineValidationMethods(mode) {
|
|
979
|
-
return "Peer review, expert consultation, empirical testing, stakeholder feedback";
|
|
980
|
-
}
|
|
981
|
-
function defineReviewSchedule() {
|
|
982
|
-
return "Weekly progress reviews, monthly milestone assessments, quarterly comprehensive evaluations";
|
|
983
|
-
}
|
|
984
|
-
function identifyHighRiskAreas(synthesis, actionPlan) {
|
|
985
|
-
return "Implementation complexity, resource availability, stakeholder alignment";
|
|
986
|
-
}
|
|
987
|
-
function defineMitigationStrategies(synthesis) {
|
|
988
|
-
return "Phased approach, contingency planning, stakeholder engagement, quality assurance";
|
|
989
|
-
}
|
|
990
|
-
function defineContingencyPlans(actionPlan) {
|
|
991
|
-
return "Alternative methodologies, resource reallocation, timeline adjustment, scope modification";
|
|
992
|
-
}
|
|
993
|
-
function defineMonitoringSystems() {
|
|
994
|
-
return "Real-time progress tracking, quality metrics monitoring, stakeholder feedback systems";
|
|
995
|
-
}
|
|
996
|
-
function defineEscalationProcedures() {
|
|
997
|
-
return "Clear escalation paths with defined triggers and response protocols";
|
|
998
|
-
}
|
|
999
|
-
// Additional helper functions for Stage 4
|
|
1000
|
-
function assessHypothesisStrength(stage1Result) {
|
|
1001
|
-
return "Strong - well-formed hypotheses with testable predictions";
|
|
1002
|
-
}
|
|
1003
|
-
function assessEvidenceQuality(stage1Result, stage3Result) {
|
|
1004
|
-
return "High quality - multiple sources with cross-validation";
|
|
1005
|
-
}
|
|
1006
|
-
function assessLogicalCoherence(stage1Result, stage3Result) {
|
|
1007
|
-
return "Excellent - logical consistency maintained across analysis stages";
|
|
1008
|
-
}
|
|
1009
|
-
function assessMethodologicalRigor(stage1Result) {
|
|
1010
|
-
return "High rigor - systematic approach with appropriate controls";
|
|
1011
|
-
}
|
|
1012
|
-
// --- Enhanced 6-Stage Cognitive Framework Documentation (2025) ---
|
|
1013
|
-
/**
|
|
1014
|
-
* 🚀 REVOLUTIONARY 2-ROUND COGNITIVE DELIBERATION FRAMEWORK - 2025 EDITION
|
|
1015
|
-
*
|
|
1016
|
-
* This implementation represents the evolution of cognitive processing, integrating:
|
|
1017
|
-
* - Scientific Investigation methodology for systematic hypothesis formation
|
|
1018
|
-
* - OOReD (Observe-Orient-Reason-Decide) framework for strategic analysis
|
|
1019
|
-
* - Critical Thinking 10-step framework for comprehensive evaluation
|
|
1020
|
-
* - Advanced prompting strategy evaluation system with 0.00-1.00 scoring
|
|
1021
|
-
*
|
|
1022
|
-
* 📚 2-ROUND PROCESSING ARCHITECTURE:
|
|
1023
|
-
*
|
|
1024
|
-
* **ROUND 1 - Foundation Building (Stages 1-2):**
|
|
1025
|
-
* - Stage 1: Scientific Investigation with prompting strategy evaluation
|
|
1026
|
-
* - Stage 2: Initial OOReD with selected strategy application
|
|
1027
|
-
* - Output: First round results + tool recommendations for continued processing
|
|
1028
|
-
*
|
|
1029
|
-
* **ROUND 2 - Advanced Analysis (Stages 3-6):**
|
|
1030
|
-
* - Stage 3: Critical Thinking & Pre-Action Planning
|
|
1031
|
-
* - Stage 4: Scientific Review & Validation
|
|
1032
|
-
* - Stage 5: OOReD Review & Refinement
|
|
1033
|
-
* - Stage 6: Fact-Based Action & Final Recommendations
|
|
1034
|
-
*
|
|
1035
|
-
* **PROMPTING STRATEGY EVALUATION:**
|
|
1036
|
-
* - Automatic evaluation of all strategies from modern-prompting.mdc
|
|
1037
|
-
* - Solution Level (0.00-0.99) + Efficiency Level (0.00-0.99) scoring
|
|
1038
|
-
* - Strategies with total score ≥1.42 are automatically selected and applied
|
|
1039
|
-
* - Combined strategy application for scores ≥1.42
|
|
1040
|
-
*
|
|
1041
|
-
* **TOOL RECOMMENDATION ENGINE:**
|
|
1042
|
-
* - Intelligent analysis of input to recommend relevant pair programming tools
|
|
1043
|
-
* - File manipulation tools (read_file, replace_string_in_file, create_file)
|
|
1044
|
-
* - Web search tools (websearch, brave-search) for research tasks
|
|
1045
|
-
* - Code analysis tools (semantic_search, get_errors, list_code_usages)
|
|
1046
|
-
* - Documentation tools (context7 library docs) for API/library information
|
|
1047
|
-
*
|
|
1048
|
-
* 🎯 COGNITIVE ENHANCEMENT BENEFITS:
|
|
1049
|
-
*
|
|
1050
|
-
* **Enhanced Reliability:**
|
|
1051
|
-
* - 2-round validation process with cross-round consistency checking
|
|
1052
|
-
* - Prompting strategy evaluation ensures optimal approach selection
|
|
1053
|
-
* - Session-based state management for complex multi-phase analysis
|
|
1054
|
-
*
|
|
1055
|
-
* **Improved Actionability:**
|
|
1056
|
-
* - Tool usage recommendations with specific count guidance
|
|
1057
|
-
* - Focus on pair programming scenarios and development workflows
|
|
1058
|
-
* - Clear guidance for continuing deliberation with session management
|
|
1059
|
-
*
|
|
1060
|
-
* **Better Integration:**
|
|
1061
|
-
* - Follows tested specifications from new-mcp-flow.md
|
|
1062
|
-
* - Implements 0.00-1.00 scoring system (no percentages)
|
|
1063
|
-
* - Provides markdown formatted output with tool recommendations
|
|
1064
|
-
*
|
|
1065
|
-
* 📊 PERFORMANCE METRICS:
|
|
1066
|
-
* - Strategy Selection Accuracy: 95% optimal strategy identification
|
|
1067
|
-
* - 2-Round Consistency: 92% cross-round alignment
|
|
1068
|
-
* - Tool Recommendation Relevance: 88% actionable suggestions
|
|
1069
|
-
* - Implementation Compliance: 100% specification adherence
|
|
1070
|
-
*/
|
|
1071
|
-
/**
|
|
1072
|
-
* Tool: deliberate (Revolutionary Single-Tool-Call 2-Round Cognitive Processing Engine)
|
|
1073
|
-
*
|
|
1074
|
-
* **REVOLUTIONARY SINGLE-CALL FRAMEWORK:** This tool implements advanced 2-round
|
|
1075
|
-
* cognitive deliberation system in ONE tool call, combining Scientific Investigation,
|
|
1076
|
-
* OOReD analysis, and Critical Thinking frameworks with automatic prompting strategy evaluation.
|
|
1077
|
-
*
|
|
1078
|
-
* **2-ROUND PROCESSING PIPELINE (SINGLE CALL):**
|
|
1079
|
-
* **Round 1 (Foundation):** Stages 1-2 - Scientific Investigation + Initial OOReD
|
|
1080
|
-
* **Round 2 (Advanced):** Stages 3-6 - Critical Thinking + Reviews + Final Action
|
|
1081
|
-
*
|
|
1082
|
-
* **KEY FEATURES:**
|
|
1083
|
-
* - **SINGLE TOOL CALL:** Complete 6-stage deliberation without session management
|
|
1084
|
-
* - **Automatic Strategy Evaluation:** Analyzes all modern-prompting.mdc strategies
|
|
1085
|
-
* - **0.00-1.00 Scoring System:** Solution + Efficiency levels with ≥1.42 threshold
|
|
1086
|
-
* - **Internal 2-Round Processing:** All deliberation happens within one tool invocation
|
|
1087
|
-
* - **Tool Recommendations:** Intelligent suggestions for pair programming workflows
|
|
1088
|
-
* - **Concise Output:** Raw cognitive processing results without formatting constraints
|
|
1089
|
-
*
|
|
1090
|
-
* **📥 INPUT:** Complex problems requiring systematic 2-round cognitive analysis
|
|
1091
|
-
* **📤 OUTPUT:** Processed cognitive analysis with tool recommendations in single response
|
|
1092
|
-
*/
|
|
1093
|
-
server.tool("deliberate", {
|
|
1094
|
-
input: z
|
|
1095
|
-
.string()
|
|
1096
|
-
.describe("The problem, question, decision, or situation that needs cognitive deliberation and analysis."),
|
|
1097
|
-
context: z
|
|
1098
|
-
.string()
|
|
1099
|
-
.optional()
|
|
1100
|
-
.describe("Additional context, constraints, or background information relevant to the deliberation.")
|
|
1101
|
-
}, async ({ input, context }) => {
|
|
1102
|
-
const toolName = 'deliberate';
|
|
1103
|
-
logToolCall(toolName, `Input length: ${input.length}`);
|
|
1104
|
-
try {
|
|
1105
|
-
// Single tool call that performs complete 2-round cognitive deliberation
|
|
1106
|
-
const deliberationResult = await performCognitiveDeliberation(input, context);
|
|
1107
|
-
logToolResult(toolName, true, `Complete 2-round deliberation finished`);
|
|
1108
|
-
return { content: [{ type: "text", text: deliberationResult }] };
|
|
1109
|
-
}
|
|
1110
|
-
catch (error) {
|
|
1111
|
-
return logToolError(toolName, error);
|
|
1112
|
-
}
|
|
1113
461
|
});
|
|
1114
|
-
//
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
462
|
+
// Handle tool calls
|
|
463
|
+
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
464
|
+
const { name, arguments: args } = request.params;
|
|
465
|
+
if (name === "deliberate") {
|
|
466
|
+
try {
|
|
467
|
+
const { input, context } = args;
|
|
468
|
+
if (!input || typeof input !== "string") {
|
|
469
|
+
throw new Error("Input parameter is required and must be a string");
|
|
470
|
+
}
|
|
471
|
+
const result = await deliberationEngine.performCognitiveDeliberation(input, context);
|
|
472
|
+
return {
|
|
473
|
+
content: [
|
|
474
|
+
{
|
|
475
|
+
type: "text",
|
|
476
|
+
text: result,
|
|
477
|
+
},
|
|
478
|
+
],
|
|
479
|
+
};
|
|
480
|
+
}
|
|
481
|
+
catch (error) {
|
|
482
|
+
return {
|
|
483
|
+
content: [
|
|
484
|
+
{
|
|
485
|
+
type: "text",
|
|
486
|
+
text: `Error in cognitive deliberation: ${error instanceof Error ? error.message : String(error)}`,
|
|
487
|
+
},
|
|
488
|
+
],
|
|
489
|
+
isError: true,
|
|
490
|
+
};
|
|
491
|
+
}
|
|
1128
492
|
}
|
|
1129
|
-
}
|
|
1130
|
-
// Setup signal handlers
|
|
1131
|
-
process.on('SIGINT', shutdown);
|
|
1132
|
-
process.on('SIGTERM', shutdown);
|
|
1133
|
-
// Setup global error handlers
|
|
1134
|
-
process.on('uncaughtException', (error, origin) => {
|
|
1135
|
-
const timestamp = new Date().toISOString();
|
|
1136
|
-
console.error(`[${timestamp}] [MCP Server] FATAL: Uncaught Exception at: ${origin}`, error);
|
|
1137
|
-
shutdown().catch(() => process.exit(1)); // Attempt graceful shutdown, then force exit
|
|
493
|
+
throw new Error(`Unknown tool: ${name}`);
|
|
1138
494
|
});
|
|
1139
|
-
|
|
1140
|
-
const timestamp = new Date().toISOString();
|
|
1141
|
-
console.error(`[${timestamp}] [MCP Server] FATAL: Unhandled Promise Rejection:`, reason);
|
|
1142
|
-
shutdown().catch(() => process.exit(1)); // Attempt graceful shutdown, then force exit
|
|
1143
|
-
});
|
|
1144
|
-
// --- Start the Server (Internal - No changes needed as per user comments) ---
|
|
1145
|
-
/**
|
|
1146
|
-
* Initializes and starts the MCP server.
|
|
1147
|
-
*/
|
|
495
|
+
// Start the server
|
|
1148
496
|
async function main() {
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
const border = '==================== Gikendaasowin MCP ====================';
|
|
1153
|
-
console.error(border);
|
|
1154
|
-
console.error(`Name: ${serverInfo.name}`);
|
|
1155
|
-
console.error(`Version: ${serverInfo.version}`);
|
|
1156
|
-
console.error(`Description: ${serverInfo.description}`);
|
|
1157
|
-
console.error('Status: Running on stdio, awaiting MCP requests...');
|
|
1158
|
-
console.error('==========================================================');
|
|
1159
|
-
}
|
|
1160
|
-
catch (error) {
|
|
1161
|
-
const timestamp = new Date().toISOString();
|
|
1162
|
-
console.error(`[${timestamp}] [MCP Server] Fatal error during startup:`, error);
|
|
1163
|
-
process.exit(1);
|
|
1164
|
-
}
|
|
497
|
+
const transport = new StdioServerTransport();
|
|
498
|
+
await server.connect(transport);
|
|
499
|
+
console.error("Gikendaasowin Aabajichiganan MCP server running on stdio");
|
|
1165
500
|
}
|
|
1166
|
-
|
|
1167
|
-
main();
|
|
501
|
+
main().catch((error) => {
|
|
502
|
+
console.error("Fatal error in main():", error);
|
|
503
|
+
process.exit(1);
|
|
504
|
+
});
|