@nbiish/cognitive-tools-mcp 8.9.1 → 8.9.8
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 -88
- package/build/index.js +204 -1156
- package/package.json +1 -1
package/build/index.js
CHANGED
|
@@ -1,1167 +1,215 @@
|
|
|
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
|
-
|
|
28
|
-
}
|
|
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
|
-
name: "ToT-lite (Tree of Thoughts)",
|
|
87
|
-
description: "Bounded breadth/depth exploration for complex problem decomposition"
|
|
88
|
-
},
|
|
89
|
-
{
|
|
90
|
-
name: "Progressive-Hint Prompting (PHP)",
|
|
91
|
-
description: "Use previously generated outputs as contextual hints"
|
|
92
|
-
},
|
|
93
|
-
{
|
|
94
|
-
name: "Cognitive Scaffolding Prompting",
|
|
95
|
-
description: "Structure reasoning through metacognitive frameworks"
|
|
96
|
-
},
|
|
97
|
-
{
|
|
98
|
-
name: "Knowledge Synthesis Prompting (KSP)",
|
|
99
|
-
description: "Integrate knowledge from multiple internal domains"
|
|
100
|
-
},
|
|
101
|
-
{
|
|
102
|
-
name: "Reflexive Analysis",
|
|
103
|
-
description: "Embed ethical, legal, and cultural considerations"
|
|
104
|
-
},
|
|
105
|
-
{
|
|
106
|
-
name: "PAL (Program-Aided Language)",
|
|
107
|
-
description: "Generate executable code for computational tasks"
|
|
108
|
-
},
|
|
109
|
-
{
|
|
110
|
-
name: "Context-Compression",
|
|
111
|
-
description: "Apply when context exceeds budget using LLMLingua"
|
|
112
|
-
}
|
|
113
|
-
];
|
|
114
|
-
// DYNAMIC IN-PROMPT EVALUATION: Score each strategy based on actual input and context
|
|
115
|
-
const strategies = strategyTemplates.map(template => {
|
|
116
|
-
const solutionLevel = evaluateSolutionLevel(template.name, template.description, input, mode, context);
|
|
117
|
-
const efficiencyLevel = evaluateEfficiencyLevel(template.name, template.description, input, mode, context);
|
|
118
|
-
return {
|
|
119
|
-
name: template.name,
|
|
120
|
-
description: template.description,
|
|
121
|
-
solutionLevel: solutionLevel,
|
|
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")
|
|
192
|
-
score += 0.25;
|
|
193
|
-
if (hasAnalysisTerms)
|
|
194
|
-
score += 0.18;
|
|
195
|
-
if (context && hasComplexLogic)
|
|
196
|
-
score += 0.15;
|
|
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"))
|
|
205
|
-
score += 0.25;
|
|
206
|
-
}
|
|
207
|
-
else if (strategyName.includes("PAL (Program-Aided Language)")) {
|
|
208
|
-
score = 0.40; // Specialized for computation
|
|
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)
|
|
214
|
-
score += 0.15;
|
|
215
|
-
}
|
|
216
|
-
else if (strategyName.includes("Context-Compression")) {
|
|
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)
|
|
286
|
-
score += 0.15;
|
|
287
|
-
if (mode === "synthesize")
|
|
288
|
-
score += 0.12;
|
|
289
|
-
if (isSimpleTask)
|
|
290
|
-
score -= 0.08;
|
|
291
|
-
}
|
|
292
|
-
else if (strategyName.includes("Reflexive Analysis")) {
|
|
293
|
-
score = 0.35; // Lower efficiency due to deep reflection
|
|
294
|
-
if (mode === "evaluate")
|
|
295
|
-
score += 0.25; // More efficient in evaluation mode
|
|
296
|
-
if (isSimpleTask)
|
|
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"))
|
|
304
|
-
score += 0.15;
|
|
305
|
-
if (isSimpleTask && input.includes("comput"))
|
|
306
|
-
score += 0.10;
|
|
307
|
-
if (!input.match(/code|math|calculat|comput|program/))
|
|
308
|
-
score -= 0.30; // Inefficient for non-computational tasks
|
|
309
|
-
}
|
|
310
|
-
else if (strategyName.includes("Context-Compression")) {
|
|
311
|
-
score = 0.85; // Very high efficiency for compression
|
|
312
|
-
if (inputLength < 500)
|
|
313
|
-
score -= 0.25; // Unnecessary for short inputs
|
|
314
|
-
if (inputLength > 1500)
|
|
315
|
-
score += 0.10; // More valuable for very long inputs
|
|
316
|
-
if (hasTimeConstraints)
|
|
317
|
-
score += 0.05;
|
|
318
|
-
}
|
|
319
|
-
return Math.min(0.99, score);
|
|
320
|
-
}
|
|
321
|
-
/**
|
|
322
|
-
* Generates tool usage recommendations for pair programming scenarios
|
|
323
|
-
*/
|
|
324
|
-
function generateToolRecommendations(input, mode, deliberationResults) {
|
|
325
|
-
const recommendations = [];
|
|
326
|
-
let toolCount = 0;
|
|
327
|
-
// File manipulation tools
|
|
328
|
-
if (input.includes("file") || input.includes("code") || input.includes("implement")) {
|
|
329
|
-
recommendations.push("• **read_file** - Read relevant source files for context");
|
|
330
|
-
recommendations.push("• **replace_string_in_file** - Make targeted code changes");
|
|
331
|
-
recommendations.push("• **create_file** - Create new files as needed");
|
|
332
|
-
toolCount += 3;
|
|
333
|
-
}
|
|
334
|
-
// Web search tools
|
|
335
|
-
if (input.includes("research") || input.includes("latest") || input.includes("current") || mode === "evaluate") {
|
|
336
|
-
recommendations.push("• **vscode-websearchforcopilot_webSearch** - Search for current information");
|
|
337
|
-
recommendations.push("• **mcp_brave-search_brave_web_search** - Comprehensive web search");
|
|
338
|
-
toolCount += 2;
|
|
339
|
-
}
|
|
340
|
-
// Code analysis tools
|
|
341
|
-
if (input.includes("debug") || input.includes("error") || input.includes("analyze")) {
|
|
342
|
-
recommendations.push("• **get_errors** - Check for compilation/lint errors");
|
|
343
|
-
recommendations.push("• **semantic_search** - Find relevant code patterns");
|
|
344
|
-
recommendations.push("• **list_code_usages** - Analyze function/class usage");
|
|
345
|
-
toolCount += 3;
|
|
346
|
-
}
|
|
347
|
-
// Documentation tools
|
|
348
|
-
if (input.includes("documentation") || input.includes("library") || input.includes("api")) {
|
|
349
|
-
recommendations.push("• **mcp_context7_get-library-docs** - Get up-to-date library documentation");
|
|
350
|
-
toolCount += 1;
|
|
351
|
-
}
|
|
352
|
-
// Terminal execution
|
|
353
|
-
if (input.includes("run") || input.includes("execute") || input.includes("install")) {
|
|
354
|
-
recommendations.push("• **run_in_terminal** - Execute commands and scripts");
|
|
355
|
-
toolCount += 1;
|
|
356
|
-
}
|
|
357
|
-
// Default minimum recommendations for pair programming
|
|
358
|
-
if (toolCount === 0) {
|
|
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;
|
|
363
|
-
}
|
|
364
|
-
return { toolCount: Math.min(8, toolCount), recommendations };
|
|
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**";
|
|
373
|
-
}
|
|
374
|
-
let result = `**SELECTED PROMPTING STRATEGIES (Score ≥1.42 - Dynamically Evaluated):**\n`;
|
|
375
|
-
strategies.forEach((strategy, index) => {
|
|
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";
|
|
427
|
-
}
|
|
428
|
-
// Synthesis indicators
|
|
429
|
-
if (/\b(combine|integrate|synthesize|merge|unify|connect|relate|together)\b/.test(inputLower)) {
|
|
430
|
-
return "synthesize";
|
|
431
|
-
}
|
|
432
|
-
// Evaluation indicators
|
|
433
|
-
if (/\b(evaluate|assess|judge|rate|compare|review|quality|effectiveness)\b/.test(inputLower)) {
|
|
434
|
-
return "evaluate";
|
|
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"
|
|
435
66
|
}
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
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));
|
|
662
|
-
}
|
|
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
|
-
}
|
|
754
|
-
function generateFinalActionPlan(synthesis, mode) {
|
|
755
|
-
return `**Immediate Actions:** ${defineImmediateActions(synthesis, mode)}
|
|
756
|
-
**Short-term Goals:** ${defineShortTermGoals(synthesis, mode)}
|
|
757
|
-
**Long-term Objectives:** ${defineLongTermObjectives(synthesis, mode)}
|
|
758
|
-
**Resource Allocation:** ${defineResourceAllocation(synthesis)}
|
|
759
|
-
**Timeline:** ${defineTimeline(synthesis)}`;
|
|
760
|
-
}
|
|
761
|
-
function calculateQualityMetrics(synthesis) {
|
|
762
|
-
return `**Comprehensiveness:** 94% (all major aspects covered)
|
|
763
|
-
**Consistency:** 91% (high alignment across stages)
|
|
764
|
-
**Reliability:** 88% (strong validation and verification)
|
|
765
|
-
**Applicability:** 89% (practical implementation feasibility)
|
|
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) {
|
|
67
|
+
};
|
|
68
|
+
class DeliberationEngine {
|
|
69
|
+
deliberate(input, context) {
|
|
70
|
+
// Generate the deliberation framework that prompts the LLM to evaluate strategies itself
|
|
71
|
+
const availableStrategies = Object.entries(PROMPTING_STRATEGIES)
|
|
72
|
+
.map(([name, strategy]) => `**${name}** (${strategy.type}): ${strategy.description}`)
|
|
73
|
+
.join('\n');
|
|
74
|
+
return `DELIBERATION: You are now entering a 6-stage cognitive deliberation process. Please work through each stage systematically:
|
|
75
|
+
|
|
76
|
+
## Stage 1: Scientific Investigation
|
|
77
|
+
**Your Task:** Analyze the following input using scientific methodology:
|
|
78
|
+
- **Input:** "${input}"
|
|
79
|
+
${context ? `- **Context:** "${context}"` : ''}
|
|
80
|
+
|
|
81
|
+
**Please identify:**
|
|
82
|
+
1. Core question/problem
|
|
83
|
+
2. Initial hypothesis about the best approach
|
|
84
|
+
3. What type of task this is (computational, reasoning, creative, analysis, planning, general)
|
|
85
|
+
4. Task complexity level (low, medium, high)
|
|
86
|
+
|
|
87
|
+
## Stage 2: OOReD Process - Strategy Evaluation
|
|
88
|
+
**Orient Stage:** You have access to these cognitive techniques:
|
|
89
|
+
|
|
90
|
+
${availableStrategies}
|
|
91
|
+
|
|
92
|
+
**Your Evaluation Task:**
|
|
93
|
+
For each technique, consider:
|
|
94
|
+
- How well would this technique solve the specific problem? (Solution Level 0.00-0.99)
|
|
95
|
+
- How efficiently can this technique be applied here? (Efficiency Level 0.00-0.99)
|
|
96
|
+
- Total Score = Solution Level + Efficiency Level
|
|
97
|
+
|
|
98
|
+
**Selection Rule:** Choose techniques with total scores ≥1.53 for combined effectiveness
|
|
99
|
+
|
|
100
|
+
## Stage 3: Critical Thinking Framework
|
|
101
|
+
Apply these questions:
|
|
102
|
+
1. What is the purpose of my thinking?
|
|
103
|
+
2. What precise question am I trying to answer?
|
|
104
|
+
3. Within what context am I operating?
|
|
105
|
+
4. What information do I need to gather?
|
|
106
|
+
5. How reliable is this information?
|
|
107
|
+
6. What concepts are relevant to my thinking?
|
|
108
|
+
7. What conclusions can I draw?
|
|
109
|
+
8. What assumptions am I making?
|
|
110
|
+
9. What are the implications?
|
|
111
|
+
10. What are the consequences?
|
|
112
|
+
|
|
113
|
+
## Stage 4 & 5: Review Cycles
|
|
114
|
+
- Review your strategy selections against the ≥1.53 threshold
|
|
115
|
+
- Validate your reasoning approach
|
|
116
|
+
- Refine your methodology
|
|
117
|
+
|
|
118
|
+
## Stage 6: Final Action Synthesis
|
|
119
|
+
**Present your analysis in this format:**
|
|
120
|
+
|
|
121
|
+
**Selected Cognitive Technique(s):** [List techniques scoring ≥1.53]
|
|
122
|
+
|
|
123
|
+
**Strategy Evaluation Results (0.00-0.99 scale):**
|
|
124
|
+
[Show your evaluations like:]
|
|
125
|
+
- TechniqueName: solution=X.XX, efficiency=Y.YY, total=Z.ZZ ✓ (if ≥1.53)
|
|
126
|
+
|
|
127
|
+
**Estimated Tools Needed:** [1-8 tools for implementation]
|
|
128
|
+
|
|
129
|
+
**Recommended Pair Programmer Tools:**
|
|
130
|
+
- websearch (for current information and validation)
|
|
131
|
+
- file manipulation tools (for code and document management)
|
|
132
|
+
- code analysis tools (for computational problem solving)
|
|
133
|
+
- context synthesis tools (for information integration)
|
|
134
|
+
- debugging and testing tools (for solution verification)
|
|
135
|
+
|
|
136
|
+
Return to 'deliberate' after using the following tools: [Your estimated tool count]
|
|
137
|
+
|
|
138
|
+
# To accomplish Task:
|
|
139
|
+
[Describe the task using your selected cognitive approach]
|
|
140
|
+
|
|
141
|
+
---
|
|
142
|
+
|
|
143
|
+
**Now:** Apply your selected cognitive technique(s) to actually solve the original problem "${input}" using your enhanced reasoning framework.`;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
// MCP Server setup
|
|
147
|
+
const server = new Server({
|
|
148
|
+
name: "gikendaasowin-aabajichiganan-mcp",
|
|
149
|
+
version: "8.9.4",
|
|
150
|
+
}, {
|
|
151
|
+
capabilities: {
|
|
152
|
+
tools: {},
|
|
153
|
+
},
|
|
154
|
+
});
|
|
155
|
+
const deliberationEngine = new DeliberationEngine();
|
|
156
|
+
// List available tools
|
|
157
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
800
158
|
return {
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
159
|
+
tools: [
|
|
160
|
+
{
|
|
161
|
+
name: "deliberate",
|
|
162
|
+
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.",
|
|
163
|
+
inputSchema: {
|
|
164
|
+
type: "object",
|
|
165
|
+
properties: {
|
|
166
|
+
input: {
|
|
167
|
+
type: "string",
|
|
168
|
+
description: "The primary input, question, problem, or task requiring cognitive deliberation",
|
|
169
|
+
},
|
|
170
|
+
context: {
|
|
171
|
+
type: "string",
|
|
172
|
+
description: "Optional additional context, background information, or constraints",
|
|
173
|
+
},
|
|
174
|
+
},
|
|
175
|
+
required: ["input"],
|
|
176
|
+
},
|
|
177
|
+
},
|
|
806
178
|
],
|
|
807
|
-
predictions: [
|
|
808
|
-
"Structured methodology will improve outcomes",
|
|
809
|
-
"Multi-perspective analysis will enhance quality",
|
|
810
|
-
"Validation mechanisms will increase reliability"
|
|
811
|
-
]
|
|
812
179
|
};
|
|
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
|
-
};
|
|
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
180
|
});
|
|
1114
|
-
//
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
181
|
+
// Handle tool calls
|
|
182
|
+
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
183
|
+
const { name, arguments: args } = request.params;
|
|
184
|
+
if (name === "deliberate") {
|
|
185
|
+
const { input, context } = args;
|
|
186
|
+
if (!input || typeof input !== "string") {
|
|
187
|
+
throw new Error("Input is required and must be a string");
|
|
188
|
+
}
|
|
189
|
+
try {
|
|
190
|
+
const result = deliberationEngine.deliberate(input, context);
|
|
191
|
+
return {
|
|
192
|
+
content: [
|
|
193
|
+
{
|
|
194
|
+
type: "text",
|
|
195
|
+
text: result,
|
|
196
|
+
},
|
|
197
|
+
],
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
catch (error) {
|
|
201
|
+
throw new Error(`Deliberation failed: ${error}`);
|
|
202
|
+
}
|
|
1128
203
|
}
|
|
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
|
|
1138
|
-
});
|
|
1139
|
-
process.on('unhandledRejection', (reason, promise) => {
|
|
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
|
|
204
|
+
throw new Error(`Unknown tool: ${name}`);
|
|
1143
205
|
});
|
|
1144
|
-
//
|
|
1145
|
-
/**
|
|
1146
|
-
* Initializes and starts the MCP server.
|
|
1147
|
-
*/
|
|
206
|
+
// Start the server
|
|
1148
207
|
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
|
-
}
|
|
208
|
+
const transport = new StdioServerTransport();
|
|
209
|
+
await server.connect(transport);
|
|
210
|
+
console.error("Gikendaasowin Aabajichiganan MCP server running on stdio");
|
|
1165
211
|
}
|
|
1166
|
-
|
|
1167
|
-
main();
|
|
212
|
+
main().catch((error) => {
|
|
213
|
+
console.error("Fatal error in main():", error);
|
|
214
|
+
process.exit(1);
|
|
215
|
+
});
|