tachibot-mcp 2.0.2
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/.env.example +260 -0
- package/CHANGELOG.md +54 -0
- package/CODE_OF_CONDUCT.md +56 -0
- package/CONTRIBUTING.md +54 -0
- package/Dockerfile +36 -0
- package/LICENSE +644 -0
- package/README.md +201 -0
- package/SECURITY.md +95 -0
- package/dist/personality/komaai-expressions.js +12 -0
- package/dist/profiles/balanced.json +33 -0
- package/dist/profiles/code_focus.json +33 -0
- package/dist/profiles/full.json +33 -0
- package/dist/profiles/minimal.json +33 -0
- package/dist/profiles/research_power.json +33 -0
- package/dist/scripts/build-profiles.js +46 -0
- package/dist/src/application/services/focus/FocusModeRegistry.js +46 -0
- package/dist/src/application/services/focus/FocusTool.service.js +109 -0
- package/dist/src/application/services/focus/ModeRegistry.js +46 -0
- package/dist/src/application/services/focus/modes/focus-deep.mode.js +27 -0
- package/dist/src/application/services/focus/modes/status.mode.js +50 -0
- package/dist/src/application/services/focus/modes/tachibot-status.mode.js +50 -0
- package/dist/src/collaborative-orchestrator.js +391 -0
- package/dist/src/config/model-constants.js +188 -0
- package/dist/src/config/model-defaults.js +57 -0
- package/dist/src/config/model-preferences.js +382 -0
- package/dist/src/config/timeout-config.js +130 -0
- package/dist/src/config.js +173 -0
- package/dist/src/domain/interfaces/IFocusMode.js +5 -0
- package/dist/src/domain/interfaces/IProvider.js +6 -0
- package/dist/src/domain/interfaces/ITool.js +5 -0
- package/dist/src/focus-deep.js +245 -0
- package/dist/src/infrastructure/ascii/art/robots.ascii.js +16 -0
- package/dist/src/mcp-client.js +90 -0
- package/dist/src/memory/index.js +17 -0
- package/dist/src/memory/memory-config.js +135 -0
- package/dist/src/memory/memory-interface.js +174 -0
- package/dist/src/memory/memory-manager.js +383 -0
- package/dist/src/memory/providers/devlog-provider.js +385 -0
- package/dist/src/memory/providers/hybrid-provider.js +399 -0
- package/dist/src/memory/providers/local-provider.js +388 -0
- package/dist/src/memory/providers/mem0-provider.js +337 -0
- package/dist/src/modes/architect.js +477 -0
- package/dist/src/modes/auditor.js +362 -0
- package/dist/src/modes/challenger.js +841 -0
- package/dist/src/modes/code-reviewer.js +382 -0
- package/dist/src/modes/commit-guardian.js +424 -0
- package/dist/src/modes/documentation-writer.js +572 -0
- package/dist/src/modes/scout.js +587 -0
- package/dist/src/modes/shared/helpers/challenger-helpers.js +454 -0
- package/dist/src/modes/shared/helpers/index.js +17 -0
- package/dist/src/modes/shared/helpers/scout-helpers.js +270 -0
- package/dist/src/modes/shared/helpers/verifier-helpers.js +332 -0
- package/dist/src/modes/test-architect.js +767 -0
- package/dist/src/modes/verifier.js +378 -0
- package/dist/src/monitoring/performance-monitor.js +435 -0
- package/dist/src/optimization/batch-executor.js +121 -0
- package/dist/src/optimization/context-pruner.js +196 -0
- package/dist/src/optimization/cost-monitor.js +338 -0
- package/dist/src/optimization/index.js +65 -0
- package/dist/src/optimization/model-router.js +264 -0
- package/dist/src/optimization/result-cache.js +114 -0
- package/dist/src/optimization/token-optimizer.js +257 -0
- package/dist/src/optimization/token-tracker.js +118 -0
- package/dist/src/orchestrator-instructions.js +128 -0
- package/dist/src/orchestrator-lite.js +139 -0
- package/dist/src/orchestrator.js +191 -0
- package/dist/src/orchestrators/collaborative/interfaces/IToolExecutionEngine.js +1 -0
- package/dist/src/orchestrators/collaborative/interfaces/IToolExecutionStrategy.js +5 -0
- package/dist/src/orchestrators/collaborative/interfaces/IVisualizationRenderer.js +1 -0
- package/dist/src/orchestrators/collaborative/registries/ModelProviderRegistry.js +95 -0
- package/dist/src/orchestrators/collaborative/registries/ToolAdapterRegistry.js +64 -0
- package/dist/src/orchestrators/collaborative/services/tool-execution/ToolExecutionService.js +502 -0
- package/dist/src/orchestrators/collaborative/services/visualization/VisualizationService.js +206 -0
- package/dist/src/orchestrators/collaborative/types/session-types.js +5 -0
- package/dist/src/profiles/balanced.js +37 -0
- package/dist/src/profiles/code_focus.js +37 -0
- package/dist/src/profiles/debug_intensive.js +59 -0
- package/dist/src/profiles/full.js +37 -0
- package/dist/src/profiles/minimal.js +37 -0
- package/dist/src/profiles/research_code.js +59 -0
- package/dist/src/profiles/research_power.js +37 -0
- package/dist/src/profiles/types.js +5 -0
- package/dist/src/profiles/workflow_builder.js +53 -0
- package/dist/src/prompt-engineer-lite.js +78 -0
- package/dist/src/prompt-engineer.js +399 -0
- package/dist/src/reasoning-chain.js +508 -0
- package/dist/src/sequential-thinking.js +291 -0
- package/dist/src/server-diagnostic.js +74 -0
- package/dist/src/server-raw.js +158 -0
- package/dist/src/server-simple.js +58 -0
- package/dist/src/server.js +514 -0
- package/dist/src/session/session-logger.js +617 -0
- package/dist/src/session/session-manager.js +571 -0
- package/dist/src/session/session-tools.js +400 -0
- package/dist/src/tools/advanced-modes.js +200 -0
- package/dist/src/tools/claude-integration.js +356 -0
- package/dist/src/tools/consolidated/ai-router.js +174 -0
- package/dist/src/tools/consolidated/ai-tool.js +48 -0
- package/dist/src/tools/consolidated/brainstorm-tool.js +87 -0
- package/dist/src/tools/consolidated/environment-detector.js +80 -0
- package/dist/src/tools/consolidated/index.js +50 -0
- package/dist/src/tools/consolidated/search-tool.js +110 -0
- package/dist/src/tools/consolidated/workflow-tool.js +238 -0
- package/dist/src/tools/gemini-tools.js +329 -0
- package/dist/src/tools/grok-enhanced.js +376 -0
- package/dist/src/tools/grok-tools.js +299 -0
- package/dist/src/tools/lmstudio-tools.js +223 -0
- package/dist/src/tools/openai-tools.js +498 -0
- package/dist/src/tools/openrouter-tools.js +317 -0
- package/dist/src/tools/optimized-wrapper.js +204 -0
- package/dist/src/tools/perplexity-tools.js +294 -0
- package/dist/src/tools/pingpong-tool.js +343 -0
- package/dist/src/tools/qwen-wrapper.js +74 -0
- package/dist/src/tools/tool-router.js +444 -0
- package/dist/src/tools/unified-ai-provider.js +260 -0
- package/dist/src/tools/workflow-runner.js +425 -0
- package/dist/src/tools/workflow-validator-tool.js +107 -0
- package/dist/src/types.js +23 -0
- package/dist/src/utils/input-validator.js +130 -0
- package/dist/src/utils/model-router.js +91 -0
- package/dist/src/utils/progress-stream.js +255 -0
- package/dist/src/utils/provider-router.js +88 -0
- package/dist/src/utils/smart-api-client.js +146 -0
- package/dist/src/utils/table-builder.js +218 -0
- package/dist/src/utils/timestamp-formatter.js +134 -0
- package/dist/src/utils/tool-compressor.js +257 -0
- package/dist/src/utils/tool-config.js +201 -0
- package/dist/src/validators/dependency-graph-validator.js +147 -0
- package/dist/src/validators/interpolation-validator.js +222 -0
- package/dist/src/validators/output-usage-validator.js +151 -0
- package/dist/src/validators/syntax-validator.js +102 -0
- package/dist/src/validators/tool-registry-validator.js +123 -0
- package/dist/src/validators/tool-types.js +97 -0
- package/dist/src/validators/types.js +8 -0
- package/dist/src/validators/workflow-validator.js +134 -0
- package/dist/src/visualizer-lite.js +42 -0
- package/dist/src/visualizer.js +179 -0
- package/dist/src/workflows/circuit-breaker.js +199 -0
- package/dist/src/workflows/custom-workflows.js +451 -0
- package/dist/src/workflows/engine/AutoSynthesizer.js +97 -0
- package/dist/src/workflows/engine/StepParameterResolver.js +74 -0
- package/dist/src/workflows/engine/VariableInterpolator.js +123 -0
- package/dist/src/workflows/engine/WorkflowDiscovery.js +125 -0
- package/dist/src/workflows/engine/WorkflowExecutionEngine.js +485 -0
- package/dist/src/workflows/engine/WorkflowExecutor.js +113 -0
- package/dist/src/workflows/engine/WorkflowFileManager.js +244 -0
- package/dist/src/workflows/engine/WorkflowHelpers.js +114 -0
- package/dist/src/workflows/engine/WorkflowOutputFormatter.js +83 -0
- package/dist/src/workflows/engine/events/WorkflowEventBus.js +132 -0
- package/dist/src/workflows/engine/events/interfaces/IEventBus.js +5 -0
- package/dist/src/workflows/engine/handlers/ErrorRecoveryHandler.js +162 -0
- package/dist/src/workflows/engine/handlers/PromptEnhancementHandler.js +115 -0
- package/dist/src/workflows/engine/handlers/SessionPersistenceHandler.js +167 -0
- package/dist/src/workflows/engine/handlers/StepExecutionHandler.js +231 -0
- package/dist/src/workflows/engine/handlers/ToolInvocationHandler.js +46 -0
- package/dist/src/workflows/engine/interfaces/IAutoSynthesizer.js +5 -0
- package/dist/src/workflows/engine/interfaces/IStepParameterResolver.js +5 -0
- package/dist/src/workflows/engine/interfaces/IVariableInterpolator.js +5 -0
- package/dist/src/workflows/engine/interfaces/IWorkflowDiscovery.js +4 -0
- package/dist/src/workflows/engine/interfaces/IWorkflowFileManager.js +5 -0
- package/dist/src/workflows/engine/interfaces/IWorkflowOutputFormatter.js +5 -0
- package/dist/src/workflows/engine/state/WorkflowStateMachine.js +194 -0
- package/dist/src/workflows/engine/state/interfaces/IStateMachine.js +17 -0
- package/dist/src/workflows/fallback-strategies.js +373 -0
- package/dist/src/workflows/message-queue.js +455 -0
- package/dist/src/workflows/model-router.js +189 -0
- package/dist/src/workflows/orchestrator-examples.js +174 -0
- package/dist/src/workflows/orchestrator-integration.js +200 -0
- package/dist/src/workflows/self-healing.js +524 -0
- package/dist/src/workflows/tool-mapper.js +407 -0
- package/dist/src/workflows/tool-orchestrator.js +796 -0
- package/dist/src/workflows/workflow-engine.js +573 -0
- package/dist/src/workflows/workflow-parser.js +283 -0
- package/dist/src/workflows/workflow-types.js +95 -0
- package/dist/src/workflows.js +568 -0
- package/dist/test-workflow-file-output.js +93 -0
- package/docs/API_KEYS.md +570 -0
- package/docs/CLAUDE_CODE_SETUP.md +181 -0
- package/docs/CLAUDE_DESKTOP_MANUAL.md +127 -0
- package/docs/CONFIGURATION.md +745 -0
- package/docs/FOCUS_MODES.md +240 -0
- package/docs/INSTALLATION_BOTH.md +145 -0
- package/docs/TERMS.md +352 -0
- package/docs/TOOLS_REFERENCE.md +1622 -0
- package/docs/TOOL_PARAMETERS.md +496 -0
- package/docs/TOOL_PROFILES.md +236 -0
- package/docs/WORKFLOWS.md +987 -0
- package/docs/WORKFLOW_OUTPUT.md +198 -0
- package/docs/WORKFLOW_PROGRESS_TRACKING.md +305 -0
- package/docs/workflows/design-brainstorm.md +335 -0
- package/package.json +97 -0
- package/profiles/balanced.json +37 -0
- package/profiles/code_focus.json +37 -0
- package/profiles/debug_intensive.json +34 -0
- package/profiles/full.json +37 -0
- package/profiles/minimal.json +37 -0
- package/profiles/research_power.json +37 -0
- package/profiles/workflow_builder.json +37 -0
- package/smithery.yaml +66 -0
- package/start.sh +8 -0
- package/tools.config.json +81 -0
- package/tsconfig.json +18 -0
- package/workflows/accessibility-code-audit.yaml +92 -0
- package/workflows/code-architecture-review.yaml +202 -0
- package/workflows/code-review.yaml +142 -0
- package/workflows/core/iterative-problem-solver.yaml +283 -0
- package/workflows/creative-brainstorm-yaml.yaml +215 -0
- package/workflows/pingpong.yaml +141 -0
- package/workflows/system/README.md +412 -0
- package/workflows/system/challenger.yaml +175 -0
- package/workflows/system/scout.yaml +164 -0
- package/workflows/system/verifier.yaml +133 -0
- package/workflows/ultra-creative-brainstorm.yaml +318 -0
- package/workflows/ux-research-flow.yaml +92 -0
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
export class PromptEngineer {
|
|
2
|
+
constructor() {
|
|
3
|
+
this.techniques = new Map();
|
|
4
|
+
this.modelProfiles = new Map();
|
|
5
|
+
this.initializeTechniques();
|
|
6
|
+
this.initializeModelProfiles();
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Initialize model profiles for better prompt adaptation
|
|
10
|
+
*/
|
|
11
|
+
initializeModelProfiles() {
|
|
12
|
+
// OpenAI models - structured, reasoning-focused
|
|
13
|
+
this.modelProfiles.set('openai', {
|
|
14
|
+
patterns: ['^gpt', '^o1', '^o3'],
|
|
15
|
+
strengths: ['reasoning', 'structured-output', 'code-generation'],
|
|
16
|
+
promptStyle: 'structured',
|
|
17
|
+
contextWindow: 128000,
|
|
18
|
+
suffix: '\n\nProvide a well-structured response with clear reasoning steps.'
|
|
19
|
+
});
|
|
20
|
+
// Gemini - creative, multimodal
|
|
21
|
+
this.modelProfiles.set('gemini', {
|
|
22
|
+
patterns: ['^gemini'],
|
|
23
|
+
strengths: ['creativity', 'analysis', 'long-context'],
|
|
24
|
+
promptStyle: 'creative',
|
|
25
|
+
contextWindow: 1000000,
|
|
26
|
+
suffix: '\n\nBe creative and think outside conventional boundaries.'
|
|
27
|
+
});
|
|
28
|
+
// Perplexity - research, factual
|
|
29
|
+
this.modelProfiles.set('perplexity', {
|
|
30
|
+
patterns: ['perplexity', 'sonar'],
|
|
31
|
+
strengths: ['research', 'fact-checking', 'citations'],
|
|
32
|
+
promptStyle: 'concise',
|
|
33
|
+
contextWindow: 127000,
|
|
34
|
+
suffix: '\n\nFocus on finding concrete data, statistics, and credible sources with citations.'
|
|
35
|
+
});
|
|
36
|
+
// Grok - reasoning, analysis
|
|
37
|
+
this.modelProfiles.set('grok', {
|
|
38
|
+
patterns: ['^grok'],
|
|
39
|
+
strengths: ['reasoning', 'analysis', 'humor'],
|
|
40
|
+
promptStyle: 'detailed',
|
|
41
|
+
contextWindow: 131072,
|
|
42
|
+
suffix: '\n\nProvide detailed analysis with clear reasoning and practical insights.'
|
|
43
|
+
});
|
|
44
|
+
// Moonshot Kimi - long context, Chinese/English
|
|
45
|
+
this.modelProfiles.set('moonshot', {
|
|
46
|
+
patterns: ['^kimi', '^moonshot'],
|
|
47
|
+
strengths: ['long-context', 'bilingual', 'thinking'],
|
|
48
|
+
promptStyle: 'structured',
|
|
49
|
+
contextWindow: 1000000,
|
|
50
|
+
suffix: '\n\nThink step-by-step and provide comprehensive analysis.'
|
|
51
|
+
});
|
|
52
|
+
// Claude - balanced, helpful
|
|
53
|
+
this.modelProfiles.set('claude', {
|
|
54
|
+
patterns: ['^claude'],
|
|
55
|
+
strengths: ['reasoning', 'safety', 'helpfulness'],
|
|
56
|
+
promptStyle: 'structured',
|
|
57
|
+
contextWindow: 200000,
|
|
58
|
+
suffix: '\n\nProvide clear, helpful analysis with attention to nuance.'
|
|
59
|
+
});
|
|
60
|
+
// Think MCP - metacognitive
|
|
61
|
+
this.modelProfiles.set('think', {
|
|
62
|
+
patterns: ['^think'],
|
|
63
|
+
strengths: ['metacognition', 'reasoning', 'reflection'],
|
|
64
|
+
promptStyle: 'structured',
|
|
65
|
+
contextWindow: 32000
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
initializeTechniques() {
|
|
69
|
+
// Creative techniques
|
|
70
|
+
this.techniques.set('what_if_speculation', {
|
|
71
|
+
apply: (query) => [
|
|
72
|
+
`What if we approached "${query}" from a completely different angle?`,
|
|
73
|
+
`Imagine a world where the constraints of "${query}" don't exist. What becomes possible?`,
|
|
74
|
+
`What if the opposite of what we assume about "${query}" were true?`,
|
|
75
|
+
`Consider the most ambitious version of solving "${query}". What would that look like?`
|
|
76
|
+
].join('\n\n')
|
|
77
|
+
});
|
|
78
|
+
this.techniques.set('alternative_perspectives', {
|
|
79
|
+
apply: (query) => [
|
|
80
|
+
`Analyze "${query}" from these different perspectives:`,
|
|
81
|
+
`1. From a child's innocent viewpoint`,
|
|
82
|
+
`2. From a skeptical scientist's perspective`,
|
|
83
|
+
`3. From an artist's creative lens`,
|
|
84
|
+
`4. From a business strategist's angle`,
|
|
85
|
+
`5. From a futurist's vision`,
|
|
86
|
+
`What unique insights does each perspective reveal?`
|
|
87
|
+
].join('\n')
|
|
88
|
+
});
|
|
89
|
+
this.techniques.set('creative_applications', {
|
|
90
|
+
apply: (query, context) => {
|
|
91
|
+
const basePrompt = `Given ${context ? `the research findings about "${query}"` : `"${query}"`}, `;
|
|
92
|
+
return basePrompt + [
|
|
93
|
+
`brainstorm creative applications across different domains:`,
|
|
94
|
+
`- How could this transform education?`,
|
|
95
|
+
`- What entertainment possibilities does this open?`,
|
|
96
|
+
`- How might this revolutionize healthcare?`,
|
|
97
|
+
`- What environmental benefits could emerge?`,
|
|
98
|
+
`- How could this enhance human creativity?`,
|
|
99
|
+
`Think beyond obvious applications.`
|
|
100
|
+
].join('\n');
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
this.techniques.set('innovative_solutions', {
|
|
104
|
+
apply: (query) => [
|
|
105
|
+
`Generate creative, unconventional solutions for "${query}".`,
|
|
106
|
+
`Think creatively and explore multiple angles:`,
|
|
107
|
+
`- How can existing processes be rethought or redesigned?`,
|
|
108
|
+
`- What inspiration can we draw from other industries or domains?`,
|
|
109
|
+
`- What becomes possible if we remove typical constraints?`,
|
|
110
|
+
`- How might different methods or approaches be combined?`,
|
|
111
|
+
`Provide at least 3 novel, practical approaches with clear reasoning.`
|
|
112
|
+
].join('\n')
|
|
113
|
+
});
|
|
114
|
+
// Research techniques
|
|
115
|
+
this.techniques.set('comprehensive_investigation', {
|
|
116
|
+
apply: (query) => [
|
|
117
|
+
`Conduct a comprehensive investigation of "${query}" addressing:`,
|
|
118
|
+
`WHO: Key players, stakeholders, and affected parties`,
|
|
119
|
+
`WHAT: Core components, mechanisms, and definitions`,
|
|
120
|
+
`WHEN: Timeline, historical context, and future projections`,
|
|
121
|
+
`WHERE: Geographic relevance, applicable domains, and contexts`,
|
|
122
|
+
`WHY: Root causes, motivations, and underlying principles`,
|
|
123
|
+
`HOW: Processes, methods, and implementation details`,
|
|
124
|
+
`Include recent developments, controversies, and expert opinions.`
|
|
125
|
+
].join('\n')
|
|
126
|
+
});
|
|
127
|
+
this.techniques.set('evidence_gathering', {
|
|
128
|
+
apply: (query, context) => {
|
|
129
|
+
const focus = context ? `Based on the analysis of "${query}"` : `For "${query}"`;
|
|
130
|
+
return [
|
|
131
|
+
`${focus}, gather evidence to:`,
|
|
132
|
+
`1. Support the main hypothesis or approach`,
|
|
133
|
+
`2. Challenge assumptions with contradicting data`,
|
|
134
|
+
`3. Find real-world case studies and examples`,
|
|
135
|
+
`4. Identify statistical trends and patterns`,
|
|
136
|
+
`5. Discover expert opinions and research papers`,
|
|
137
|
+
`Prioritize recent, credible sources.`
|
|
138
|
+
].join('\n');
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
// Analytical techniques
|
|
142
|
+
this.techniques.set('systematic_analysis', {
|
|
143
|
+
apply: (query, context) => {
|
|
144
|
+
const intro = context ? `Building on the research about "${query}"` : `Analyzing "${query}"`;
|
|
145
|
+
return [
|
|
146
|
+
`${intro}, provide a systematic analysis:`,
|
|
147
|
+
`1. Break down the core components`,
|
|
148
|
+
`2. Examine relationships and dependencies`,
|
|
149
|
+
`3. Identify patterns and anomalies`,
|
|
150
|
+
`4. Evaluate strengths and weaknesses`,
|
|
151
|
+
`5. Assess risks and opportunities`,
|
|
152
|
+
`6. Draw logical conclusions`,
|
|
153
|
+
`Use structured reasoning and clear logic chains.`
|
|
154
|
+
].join('\n');
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
this.techniques.set('first_principles', {
|
|
158
|
+
apply: (query) => [
|
|
159
|
+
`Apply first principles thinking to "${query}":`,
|
|
160
|
+
`1. What are the fundamental truths we know for certain?`,
|
|
161
|
+
`2. What assumptions are we making that might not be true?`,
|
|
162
|
+
`3. If we built this from scratch, knowing only basic principles, what would we create?`,
|
|
163
|
+
`4. What are the atomic units that cannot be broken down further?`,
|
|
164
|
+
`5. How can we reconstruct a solution from these basic elements?`,
|
|
165
|
+
`Challenge every assumption and rebuild from the ground up.`
|
|
166
|
+
].join('\n')
|
|
167
|
+
});
|
|
168
|
+
this.techniques.set('feasibility_analysis', {
|
|
169
|
+
apply: (query, context) => {
|
|
170
|
+
const ideas = context ? `the creative ideas generated for "${query}"` : `"${query}"`;
|
|
171
|
+
return [
|
|
172
|
+
`Evaluate the feasibility of ${ideas} considering:`,
|
|
173
|
+
`1. Technical feasibility: Can it be built with current/near-future technology?`,
|
|
174
|
+
`2. Economic viability: Cost-benefit analysis and ROI potential`,
|
|
175
|
+
`3. Time requirements: Realistic timeline for implementation`,
|
|
176
|
+
`4. Resource needs: Human, financial, and material resources`,
|
|
177
|
+
`5. Risk assessment: What could go wrong and mitigation strategies`,
|
|
178
|
+
`6. Success metrics: How would we measure achievement?`,
|
|
179
|
+
`Rank options by overall feasibility score.`
|
|
180
|
+
].join('\n');
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
// Reflective techniques
|
|
184
|
+
this.techniques.set('quick_reflection', {
|
|
185
|
+
apply: (query, context) => {
|
|
186
|
+
const prompt = context ?
|
|
187
|
+
`Reflect on the insights gathered so far about "${query}":` :
|
|
188
|
+
`Take a moment to reflect on "${query}":`;
|
|
189
|
+
return [
|
|
190
|
+
prompt,
|
|
191
|
+
`- What patterns are emerging?`,
|
|
192
|
+
`- What surprises or contradictions do we see?`,
|
|
193
|
+
`- What's the most important insight so far?`,
|
|
194
|
+
`- What questions remain unanswered?`,
|
|
195
|
+
`- What should we explore next?`
|
|
196
|
+
].join('\n');
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
this.techniques.set('pattern_recognition', {
|
|
200
|
+
apply: (query, context) => {
|
|
201
|
+
const data = context ? `the research on "${query}"` : `"${query}"`;
|
|
202
|
+
return [
|
|
203
|
+
`Identify patterns and connections in ${data}:`,
|
|
204
|
+
`1. Recurring themes across different sources`,
|
|
205
|
+
`2. Cause-and-effect relationships`,
|
|
206
|
+
`3. Cyclical or temporal patterns`,
|
|
207
|
+
`4. Structural similarities to other domains`,
|
|
208
|
+
`5. Anomalies that break expected patterns`,
|
|
209
|
+
`What do these patterns reveal about the underlying system?`
|
|
210
|
+
].join('\n');
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
this.techniques.set('problem_decomposition', {
|
|
214
|
+
apply: (query) => [
|
|
215
|
+
`Break down "${query}" into manageable components:`,
|
|
216
|
+
`1. What is the core problem we're trying to solve?`,
|
|
217
|
+
`2. What are the sub-problems that make up this challenge?`,
|
|
218
|
+
`3. Which components are dependent on others?`,
|
|
219
|
+
`4. What constraints limit our options?`,
|
|
220
|
+
`5. What resources do we have available?`,
|
|
221
|
+
`6. What would a step-by-step solution look like?`,
|
|
222
|
+
`Create a clear problem hierarchy.`
|
|
223
|
+
].join('\n')
|
|
224
|
+
});
|
|
225
|
+
this.techniques.set('integration_reflection', {
|
|
226
|
+
apply: (query, context) => [
|
|
227
|
+
`Synthesize all perspectives on "${query}" into unified insights:`,
|
|
228
|
+
`1. What are the convergent themes across all analyses?`,
|
|
229
|
+
`2. Where do different approaches complement each other?`,
|
|
230
|
+
`3. What contradictions need to be resolved?`,
|
|
231
|
+
`4. What is the meta-pattern that emerges?`,
|
|
232
|
+
`5. What is the single most important takeaway?`,
|
|
233
|
+
`Create a coherent narrative that incorporates all viewpoints.`
|
|
234
|
+
].join('\n')
|
|
235
|
+
});
|
|
236
|
+
// Default technique
|
|
237
|
+
this.techniques.set('default', {
|
|
238
|
+
apply: (query) => query
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Apply prompt engineering technique with enhanced context
|
|
243
|
+
*
|
|
244
|
+
* @param tool - Tool/model name (e.g., 'gemini_brainstorm', 'perplexity_research')
|
|
245
|
+
* @param technique - Technique to apply (e.g., 'first_principles', 'systematic_analysis')
|
|
246
|
+
* @param query - Original query/prompt
|
|
247
|
+
* @param previousResults - Legacy: Array of previous tool results (deprecated, use enhancementContext)
|
|
248
|
+
* @param enhancementContext - NEW: Rich workflow context for better prompt adaptation
|
|
249
|
+
*/
|
|
250
|
+
applyTechnique(tool, technique, query, previousResults, enhancementContext) {
|
|
251
|
+
const handler = this.techniques.get(technique) || this.techniques.get('default');
|
|
252
|
+
// Extract context - use new context if available, otherwise legacy
|
|
253
|
+
let context;
|
|
254
|
+
if (enhancementContext && enhancementContext.previousSteps && enhancementContext.previousSteps.length > 0) {
|
|
255
|
+
// NEW: Smart context extraction from workflow state
|
|
256
|
+
context = this.extractWorkflowContext(enhancementContext);
|
|
257
|
+
}
|
|
258
|
+
else if (previousResults && previousResults.length > 0) {
|
|
259
|
+
// LEGACY: Simple context extraction from results
|
|
260
|
+
const recentResult = previousResults[previousResults.length - 1];
|
|
261
|
+
context = this.extractRelevantContext(recentResult.output);
|
|
262
|
+
}
|
|
263
|
+
// Apply the technique with context
|
|
264
|
+
const enhancedPrompt = handler.apply(query, context);
|
|
265
|
+
// Add workflow progress indicator if available
|
|
266
|
+
let promptWithContext = enhancedPrompt;
|
|
267
|
+
if (enhancementContext?.stepNumber && enhancementContext?.totalSteps) {
|
|
268
|
+
const progress = `[Workflow Step ${enhancementContext.stepNumber}/${enhancementContext.totalSteps}]`;
|
|
269
|
+
promptWithContext = `${progress}\n\n${enhancedPrompt}`;
|
|
270
|
+
}
|
|
271
|
+
// Add tool-specific modifications using model profiles
|
|
272
|
+
return this.adaptPromptForModel(tool, promptWithContext, query, enhancementContext);
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Extract context from workflow state (NEW - Phase 3)
|
|
276
|
+
* Smarter than legacy extractRelevantContext()
|
|
277
|
+
*/
|
|
278
|
+
extractWorkflowContext(context) {
|
|
279
|
+
if (!context.previousSteps || context.previousSteps.length === 0) {
|
|
280
|
+
return '';
|
|
281
|
+
}
|
|
282
|
+
const insights = [];
|
|
283
|
+
// Get last 2-3 steps for recency
|
|
284
|
+
const recentSteps = context.previousSteps.slice(-3);
|
|
285
|
+
for (const step of recentSteps) {
|
|
286
|
+
// Extract key insights using patterns
|
|
287
|
+
const stepInsights = this.extractKeyInsights(step.output);
|
|
288
|
+
if (stepInsights) {
|
|
289
|
+
insights.push(`**From ${step.name}:**\n${stepInsights}`);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
// Add workflow variables if relevant
|
|
293
|
+
if (context.workflowVariables && Object.keys(context.workflowVariables).length > 0) {
|
|
294
|
+
const vars = Object.entries(context.workflowVariables)
|
|
295
|
+
.slice(0, 3) // Top 3 most relevant
|
|
296
|
+
.map(([k, v]) => `${k}: ${v}`)
|
|
297
|
+
.join(', ');
|
|
298
|
+
insights.push(`**Context:** ${vars}`);
|
|
299
|
+
}
|
|
300
|
+
return insights.join('\n\n');
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Smart insight extraction using patterns
|
|
304
|
+
* Extracts: conclusions, key findings, numbers, entities
|
|
305
|
+
*/
|
|
306
|
+
extractKeyInsights(output) {
|
|
307
|
+
const lines = output.split('\n').filter(line => line.trim());
|
|
308
|
+
const insights = [];
|
|
309
|
+
// Pattern 1: Look for conclusion/summary sections
|
|
310
|
+
const summaryIndex = lines.findIndex(line => /summary|conclusion|key findings|takeaways|insights/i.test(line));
|
|
311
|
+
if (summaryIndex >= 0 && summaryIndex < lines.length - 1) {
|
|
312
|
+
// Get 2-3 lines after summary header
|
|
313
|
+
const summaryLines = lines.slice(summaryIndex + 1, summaryIndex + 4)
|
|
314
|
+
.filter(l => l.trim().length > 20); // Meaningful lines only
|
|
315
|
+
insights.push(...summaryLines);
|
|
316
|
+
}
|
|
317
|
+
// Pattern 2: Extract bullet points (likely key findings)
|
|
318
|
+
const bullets = lines.filter(line => /^[-*•]\s+/.test(line.trim()) && line.length > 30).slice(0, 3); // Top 3 bullets
|
|
319
|
+
insights.push(...bullets);
|
|
320
|
+
// Pattern 3: Extract numbered findings
|
|
321
|
+
const numberedFindings = lines.filter(line => /^\d+\.\s+/.test(line.trim()) && line.length > 30).slice(0, 3);
|
|
322
|
+
insights.push(...numberedFindings);
|
|
323
|
+
// Pattern 4: Extract key metrics/numbers
|
|
324
|
+
const metricsLines = lines.filter(line => /\d+%|\$\d+|increase|decrease|improvement/i.test(line) && line.length > 20).slice(0, 2);
|
|
325
|
+
insights.push(...metricsLines);
|
|
326
|
+
// Deduplicate and limit
|
|
327
|
+
const uniqueInsights = [...new Set(insights)].slice(0, 5);
|
|
328
|
+
return uniqueInsights.length > 0
|
|
329
|
+
? uniqueInsights.join('\n')
|
|
330
|
+
: lines.slice(0, 3).join('\n'); // Fallback to first 3 lines
|
|
331
|
+
}
|
|
332
|
+
extractRelevantContext(output) {
|
|
333
|
+
// Extract key insights or summary from previous output
|
|
334
|
+
// Simple implementation - can be enhanced
|
|
335
|
+
const lines = output.split('\n').filter(line => line.trim());
|
|
336
|
+
// Look for summary sections
|
|
337
|
+
const summaryIndex = lines.findIndex(line => line.toLowerCase().includes('summary') ||
|
|
338
|
+
line.toLowerCase().includes('key') ||
|
|
339
|
+
line.toLowerCase().includes('conclusion'));
|
|
340
|
+
if (summaryIndex >= 0) {
|
|
341
|
+
return lines.slice(summaryIndex, summaryIndex + 5).join('\n');
|
|
342
|
+
}
|
|
343
|
+
// Otherwise, take first few meaningful lines
|
|
344
|
+
return lines.slice(0, 3).join('\n');
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Adapt prompt for specific model using model profiles (NEW - Phase 3)
|
|
348
|
+
* Replaces hardcoded adaptPromptForTool() with intelligent model matching
|
|
349
|
+
*/
|
|
350
|
+
adaptPromptForModel(tool, prompt, originalQuery, context) {
|
|
351
|
+
// Find matching model profile
|
|
352
|
+
const profileEntry = Array.from(this.modelProfiles.entries()).find(([_key, profile]) => profile.patterns.some(pattern => new RegExp(pattern, 'i').test(tool)));
|
|
353
|
+
if (!profileEntry) {
|
|
354
|
+
// No profile found - return as-is
|
|
355
|
+
return prompt;
|
|
356
|
+
}
|
|
357
|
+
const [profileName, profile] = profileEntry;
|
|
358
|
+
let adaptedPrompt = prompt;
|
|
359
|
+
// Add prefix if specified
|
|
360
|
+
if (profile.prefix) {
|
|
361
|
+
adaptedPrompt = `${profile.prefix}\n\n${adaptedPrompt}`;
|
|
362
|
+
}
|
|
363
|
+
// Add suffix if specified
|
|
364
|
+
if (profile.suffix) {
|
|
365
|
+
adaptedPrompt = `${adaptedPrompt}${profile.suffix}`;
|
|
366
|
+
}
|
|
367
|
+
// Add context window hint for long-context models
|
|
368
|
+
if (profile.contextWindow > 500000 && context?.previousSteps && context.previousSteps.length > 3) {
|
|
369
|
+
adaptedPrompt = `[Long-context mode enabled]\n\n${adaptedPrompt}`;
|
|
370
|
+
}
|
|
371
|
+
return adaptedPrompt;
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Legacy method for backwards compatibility
|
|
375
|
+
* @deprecated Use adaptPromptForModel() instead
|
|
376
|
+
*/
|
|
377
|
+
adaptPromptForTool(tool, prompt, originalQuery) {
|
|
378
|
+
return this.adaptPromptForModel(tool, prompt, originalQuery);
|
|
379
|
+
}
|
|
380
|
+
// Get a human-readable description of the current technique
|
|
381
|
+
getTechniqueDescription(technique) {
|
|
382
|
+
const descriptions = {
|
|
383
|
+
what_if_speculation: 'Exploring "What if..." possibilities',
|
|
384
|
+
alternative_perspectives: 'Viewing from multiple angles',
|
|
385
|
+
creative_applications: 'Finding innovative uses',
|
|
386
|
+
innovative_solutions: 'Generating novel approaches',
|
|
387
|
+
comprehensive_investigation: 'Deep systematic research',
|
|
388
|
+
evidence_gathering: 'Finding supporting data',
|
|
389
|
+
systematic_analysis: 'Structured examination',
|
|
390
|
+
first_principles: 'Fundamental truth analysis',
|
|
391
|
+
feasibility_analysis: 'Practical evaluation',
|
|
392
|
+
quick_reflection: 'Pattern recognition',
|
|
393
|
+
pattern_recognition: 'Identifying connections',
|
|
394
|
+
problem_decomposition: 'Breaking down complexity',
|
|
395
|
+
integration_reflection: 'Synthesizing insights'
|
|
396
|
+
};
|
|
397
|
+
return descriptions[technique] || technique;
|
|
398
|
+
}
|
|
399
|
+
}
|