mcp-adr-analysis-server 1.1.0 → 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.
Files changed (118) hide show
  1. package/README.md +367 -150
  2. package/dist/src/config/ai-config.d.ts +81 -0
  3. package/dist/src/config/ai-config.d.ts.map +1 -0
  4. package/dist/src/config/ai-config.js +134 -0
  5. package/dist/src/config/ai-config.js.map +1 -0
  6. package/dist/src/index.d.ts +97 -1
  7. package/dist/src/index.d.ts.map +1 -1
  8. package/dist/src/index.js +2430 -186
  9. package/dist/src/index.js.map +1 -1
  10. package/dist/src/prompts/adr-suggestion-prompts.d.ts +2 -2
  11. package/dist/src/prompts/adr-suggestion-prompts.d.ts.map +1 -1
  12. package/dist/src/prompts/adr-suggestion-prompts.js +25 -17
  13. package/dist/src/prompts/adr-suggestion-prompts.js.map +1 -1
  14. package/dist/src/prompts/analysis-prompts.js +1 -1
  15. package/dist/src/prompts/analysis-prompts.js.map +1 -1
  16. package/dist/src/resources/index.d.ts +1 -1
  17. package/dist/src/resources/index.d.ts.map +1 -1
  18. package/dist/src/resources/index.js +52 -44
  19. package/dist/src/resources/index.js.map +1 -1
  20. package/dist/src/templates/domain-knowledge-templates.d.ts +36 -0
  21. package/dist/src/templates/domain-knowledge-templates.d.ts.map +1 -0
  22. package/dist/src/templates/domain-knowledge-templates.js +376 -0
  23. package/dist/src/templates/domain-knowledge-templates.js.map +1 -0
  24. package/dist/src/tools/adr-suggestion-tool.d.ts +8 -3
  25. package/dist/src/tools/adr-suggestion-tool.d.ts.map +1 -1
  26. package/dist/src/tools/adr-suggestion-tool.js +561 -172
  27. package/dist/src/tools/adr-suggestion-tool.js.map +1 -1
  28. package/dist/src/tools/content-masking-tool.d.ts.map +1 -1
  29. package/dist/src/tools/content-masking-tool.js +168 -22
  30. package/dist/src/tools/content-masking-tool.js.map +1 -1
  31. package/dist/src/tools/deployment-analysis-tool.d.ts.map +1 -1
  32. package/dist/src/tools/deployment-analysis-tool.js +64 -27
  33. package/dist/src/tools/deployment-analysis-tool.js.map +1 -1
  34. package/dist/src/tools/environment-analysis-tool.d.ts.map +1 -1
  35. package/dist/src/tools/environment-analysis-tool.js +65 -29
  36. package/dist/src/tools/environment-analysis-tool.js.map +1 -1
  37. package/dist/src/tools/research-question-tool.d.ts.map +1 -1
  38. package/dist/src/tools/research-question-tool.js +150 -49
  39. package/dist/src/tools/research-question-tool.js.map +1 -1
  40. package/dist/src/tools/rule-generation-tool.d.ts.map +1 -1
  41. package/dist/src/tools/rule-generation-tool.js +328 -143
  42. package/dist/src/tools/rule-generation-tool.js.map +1 -1
  43. package/dist/src/types/ape-framework.d.ts +566 -0
  44. package/dist/src/types/ape-framework.d.ts.map +1 -0
  45. package/dist/src/types/ape-framework.js +98 -0
  46. package/dist/src/types/ape-framework.js.map +1 -0
  47. package/dist/src/types/index.d.ts +96 -93
  48. package/dist/src/types/index.d.ts.map +1 -1
  49. package/dist/src/types/knowledge-generation.d.ts +671 -0
  50. package/dist/src/types/knowledge-generation.d.ts.map +1 -0
  51. package/dist/src/types/knowledge-generation.js +107 -0
  52. package/dist/src/types/knowledge-generation.js.map +1 -0
  53. package/dist/src/types/reflexion-framework.d.ts +652 -0
  54. package/dist/src/types/reflexion-framework.d.ts.map +1 -0
  55. package/dist/src/types/reflexion-framework.js +85 -0
  56. package/dist/src/types/reflexion-framework.js.map +1 -0
  57. package/dist/src/utils/adr-suggestions.d.ts +1 -1
  58. package/dist/src/utils/adr-suggestions.d.ts.map +1 -1
  59. package/dist/src/utils/adr-suggestions.js +8 -50
  60. package/dist/src/utils/adr-suggestions.js.map +1 -1
  61. package/dist/src/utils/ai-executor.d.ts +125 -0
  62. package/dist/src/utils/ai-executor.d.ts.map +1 -0
  63. package/dist/src/utils/ai-executor.js +292 -0
  64. package/dist/src/utils/ai-executor.js.map +1 -0
  65. package/dist/src/utils/automatic-prompt-engineering.d.ts +72 -0
  66. package/dist/src/utils/automatic-prompt-engineering.d.ts.map +1 -0
  67. package/dist/src/utils/automatic-prompt-engineering.js +820 -0
  68. package/dist/src/utils/automatic-prompt-engineering.js.map +1 -0
  69. package/dist/src/utils/cache.d.ts +54 -22
  70. package/dist/src/utils/cache.d.ts.map +1 -1
  71. package/dist/src/utils/cache.js +1234 -143
  72. package/dist/src/utils/cache.js.map +1 -1
  73. package/dist/src/utils/config.d.ts +2 -2
  74. package/dist/src/utils/config.js +3 -3
  75. package/dist/src/utils/config.js.map +1 -1
  76. package/dist/src/utils/deployment-analysis.d.ts.map +1 -1
  77. package/dist/src/utils/deployment-analysis.js +57 -38
  78. package/dist/src/utils/deployment-analysis.js.map +1 -1
  79. package/dist/src/utils/environment-analysis.d.ts.map +1 -1
  80. package/dist/src/utils/environment-analysis.js +113 -100
  81. package/dist/src/utils/environment-analysis.js.map +1 -1
  82. package/dist/src/utils/file-system.d.ts +42 -13
  83. package/dist/src/utils/file-system.d.ts.map +1 -1
  84. package/dist/src/utils/file-system.js +795 -89
  85. package/dist/src/utils/file-system.js.map +1 -1
  86. package/dist/src/utils/index.d.ts +9 -0
  87. package/dist/src/utils/index.d.ts.map +1 -0
  88. package/dist/src/utils/index.js +13 -0
  89. package/dist/src/utils/index.js.map +1 -0
  90. package/dist/src/utils/knowledge-generation.d.ts +79 -0
  91. package/dist/src/utils/knowledge-generation.d.ts.map +1 -0
  92. package/dist/src/utils/knowledge-generation.js +646 -0
  93. package/dist/src/utils/knowledge-generation.js.map +1 -0
  94. package/dist/src/utils/output-masking.d.ts.map +1 -1
  95. package/dist/src/utils/output-masking.js +2 -1
  96. package/dist/src/utils/output-masking.js.map +1 -1
  97. package/dist/src/utils/prompt-composition.d.ts +234 -0
  98. package/dist/src/utils/prompt-composition.d.ts.map +1 -0
  99. package/dist/src/utils/prompt-composition.js +379 -0
  100. package/dist/src/utils/prompt-composition.js.map +1 -0
  101. package/dist/src/utils/prompt-execution.d.ts +88 -0
  102. package/dist/src/utils/prompt-execution.d.ts.map +1 -0
  103. package/dist/src/utils/prompt-execution.js +227 -0
  104. package/dist/src/utils/prompt-execution.js.map +1 -0
  105. package/dist/src/utils/reflexion.d.ts +92 -0
  106. package/dist/src/utils/reflexion.d.ts.map +1 -0
  107. package/dist/src/utils/reflexion.js +1100 -0
  108. package/dist/src/utils/reflexion.js.map +1 -0
  109. package/dist/src/utils/research-integration.d.ts.map +1 -1
  110. package/dist/src/utils/research-integration.js +156 -100
  111. package/dist/src/utils/research-integration.js.map +1 -1
  112. package/dist/src/utils/research-questions.d.ts.map +1 -1
  113. package/dist/src/utils/research-questions.js +85 -24
  114. package/dist/src/utils/research-questions.js.map +1 -1
  115. package/dist/src/utils/rule-generation.d.ts.map +1 -1
  116. package/dist/src/utils/rule-generation.js +92 -108
  117. package/dist/src/utils/rule-generation.js.map +1 -1
  118. package/package.json +9 -3
@@ -0,0 +1,88 @@
1
+ /**
2
+ * Prompt Execution Utilities
3
+ *
4
+ * This module provides utilities for executing prompts with AI when enabled,
5
+ * or falling back to returning prompts for external execution.
6
+ */
7
+ import { AIExecutionResult } from './ai-executor.js';
8
+ export interface PromptExecutionOptions {
9
+ /** Whether to force prompt-only mode regardless of configuration */
10
+ forcePromptOnly?: boolean;
11
+ /** Model to use for AI execution */
12
+ model?: string;
13
+ /** Temperature for AI responses */
14
+ temperature?: number;
15
+ /** Maximum tokens for AI responses */
16
+ maxTokens?: number;
17
+ /** System prompt to use */
18
+ systemPrompt?: string;
19
+ /** Expected response format */
20
+ responseFormat?: 'text' | 'json';
21
+ /** Schema for JSON validation (if responseFormat is 'json') */
22
+ schema?: any;
23
+ }
24
+ export interface PromptExecutionResult {
25
+ /** The result content (either AI response or formatted prompt) */
26
+ content: string;
27
+ /** Whether the result was generated by AI or is a prompt */
28
+ isAIGenerated: boolean;
29
+ /** AI execution metadata (if AI was used) */
30
+ aiMetadata?: AIExecutionResult['metadata'];
31
+ /** Token usage (if AI was used) */
32
+ usage?: AIExecutionResult['usage'];
33
+ /** Model used (if AI was used) */
34
+ model?: string;
35
+ }
36
+ /**
37
+ * Execute a prompt with AI if enabled, otherwise return formatted prompt
38
+ */
39
+ export declare function executePromptWithFallback(prompt: string, instructions: string, options?: PromptExecutionOptions): Promise<PromptExecutionResult>;
40
+ /**
41
+ * Execute a prompt that expects structured ADR suggestions
42
+ */
43
+ export declare function executeADRSuggestionPrompt(prompt: string, instructions: string, options?: PromptExecutionOptions): Promise<PromptExecutionResult>;
44
+ /**
45
+ * Execute a prompt that expects to generate actual ADRs
46
+ */
47
+ export declare function executeADRGenerationPrompt(prompt: string, instructions: string, options?: PromptExecutionOptions): Promise<PromptExecutionResult>;
48
+ /**
49
+ * Execute a prompt for project ecosystem analysis
50
+ */
51
+ export declare function executeEcosystemAnalysisPrompt(prompt: string, instructions: string, options?: PromptExecutionOptions): Promise<PromptExecutionResult>;
52
+ /**
53
+ * Execute a prompt for research question generation
54
+ */
55
+ export declare function executeResearchPrompt(prompt: string, instructions: string, options?: PromptExecutionOptions): Promise<PromptExecutionResult>;
56
+ /**
57
+ * Check if AI execution is currently available
58
+ */
59
+ export declare function isAIExecutionAvailable(): boolean;
60
+ /**
61
+ * Get AI execution status for debugging
62
+ */
63
+ export declare function getAIExecutionStatus(): {
64
+ isEnabled: boolean;
65
+ hasApiKey: boolean;
66
+ executionMode: string;
67
+ model: string;
68
+ reason: string | undefined;
69
+ };
70
+ /**
71
+ * Get AI execution status and configuration info (legacy)
72
+ */
73
+ export declare function getAIExecutionInfo(): {
74
+ available: boolean;
75
+ mode: 'full' | 'prompt-only';
76
+ model?: string;
77
+ cacheEnabled?: boolean;
78
+ };
79
+ /**
80
+ * Format execution result for MCP tool response
81
+ */
82
+ export declare function formatMCPResponse(result: PromptExecutionResult): {
83
+ content: Array<{
84
+ type: 'text';
85
+ text: string;
86
+ }>;
87
+ };
88
+ //# sourceMappingURL=prompt-execution.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompt-execution.d.ts","sourceRoot":"","sources":["../../../src/utils/prompt-execution.ts"],"names":[],"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CAchC;AAED;;GAEG;AACH,wBAAsB,8BAA8B,CAClD,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,MAAM,EACpB,OAAO,GAAE,sBAA2B,GACnC,OAAO,CAAC,qBAAqB,CAAC,CAchC;AAED;;GAEG;AACH,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,MAAM,EACpB,OAAO,GAAE,sBAA2B,GACnC,OAAO,CAAC,qBAAqB,CAAC,CAchC;AAED;;GAEG;AACH,wBAAgB,sBAAsB,IAAI,OAAO,CAOhD;AAED;;GAEG;AACH,wBAAgB,oBAAoB,IAAI;IACtC,SAAS,EAAE,OAAO,CAAC;IACnB,SAAS,EAAE,OAAO,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;CAC5B,CA6BA;AAED;;GAEG;AACH,wBAAgB,kBAAkB,IAAI;IACpC,SAAS,EAAE,OAAO,CAAC;IACnB,IAAI,EAAE,MAAM,GAAG,aAAa,CAAC;IAC7B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB,CAeA;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,qBAAqB,GAAG;IAChE,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAChD,CAuBA"}
@@ -0,0 +1,227 @@
1
+ /**
2
+ * Prompt Execution Utilities
3
+ *
4
+ * This module provides utilities for executing prompts with AI when enabled,
5
+ * or falling back to returning prompts for external execution.
6
+ */
7
+ import { getAIExecutor } from './ai-executor.js';
8
+ import { isAIExecutionEnabled, loadAIConfig } from '../config/ai-config.js';
9
+ /**
10
+ * Execute a prompt with AI if enabled, otherwise return formatted prompt
11
+ */
12
+ export async function executePromptWithFallback(prompt, instructions, options = {}) {
13
+ const config = loadAIConfig();
14
+ const shouldUseAI = !options.forcePromptOnly && isAIExecutionEnabled(config);
15
+ if (shouldUseAI) {
16
+ try {
17
+ const executor = getAIExecutor();
18
+ if (options.responseFormat === 'json') {
19
+ const execOptions = {};
20
+ if (options.model !== undefined)
21
+ execOptions.model = options.model;
22
+ if (options.temperature !== undefined)
23
+ execOptions.temperature = options.temperature;
24
+ if (options.maxTokens !== undefined)
25
+ execOptions.maxTokens = options.maxTokens;
26
+ if (options.systemPrompt !== undefined)
27
+ execOptions.systemPrompt = options.systemPrompt;
28
+ const result = await executor.executeStructuredPrompt(prompt, options.schema, execOptions);
29
+ return {
30
+ content: typeof result.data === 'string' ? result.data : JSON.stringify(result.data, null, 2),
31
+ isAIGenerated: true,
32
+ aiMetadata: result.raw.metadata,
33
+ usage: result.raw.usage,
34
+ model: result.raw.model,
35
+ };
36
+ }
37
+ else {
38
+ const execOptions = {};
39
+ if (options.model !== undefined)
40
+ execOptions.model = options.model;
41
+ if (options.temperature !== undefined)
42
+ execOptions.temperature = options.temperature;
43
+ if (options.maxTokens !== undefined)
44
+ execOptions.maxTokens = options.maxTokens;
45
+ if (options.systemPrompt !== undefined)
46
+ execOptions.systemPrompt = options.systemPrompt;
47
+ const result = await executor.executePrompt(prompt, execOptions);
48
+ return {
49
+ content: result.content,
50
+ isAIGenerated: true,
51
+ aiMetadata: result.metadata,
52
+ usage: result.usage,
53
+ model: result.model,
54
+ };
55
+ }
56
+ }
57
+ catch (error) {
58
+ console.error('AI execution failed, falling back to prompt-only mode:', error);
59
+ // Fall through to prompt-only mode
60
+ }
61
+ }
62
+ // Fallback to prompt-only mode
63
+ const formattedPrompt = formatPromptForExternal(prompt, instructions);
64
+ return {
65
+ content: formattedPrompt,
66
+ isAIGenerated: false,
67
+ };
68
+ }
69
+ /**
70
+ * Format a prompt for external execution
71
+ */
72
+ function formatPromptForExternal(prompt, instructions) {
73
+ return `${instructions}\n\n${prompt}`;
74
+ }
75
+ /**
76
+ * Execute a prompt that expects structured ADR suggestions
77
+ */
78
+ export async function executeADRSuggestionPrompt(prompt, instructions, options = {}) {
79
+ const systemPrompt = options.systemPrompt || `
80
+ You are an expert software architect specializing in Architectural Decision Records (ADRs).
81
+ Analyze the provided context and generate specific, actionable ADR suggestions.
82
+ Focus on identifying architectural decisions that need to be documented based on the project context.
83
+ Provide clear reasoning for each suggestion and prioritize them by importance.
84
+ `;
85
+ return executePromptWithFallback(prompt, instructions, {
86
+ ...options,
87
+ systemPrompt,
88
+ temperature: options.temperature ?? 0.1,
89
+ responseFormat: 'text',
90
+ });
91
+ }
92
+ /**
93
+ * Execute a prompt that expects to generate actual ADRs
94
+ */
95
+ export async function executeADRGenerationPrompt(prompt, instructions, options = {}) {
96
+ const systemPrompt = options.systemPrompt || `
97
+ You are an expert software architect who creates comprehensive Architectural Decision Records (ADRs).
98
+ Generate well-structured ADRs that follow best practices and include all necessary sections.
99
+ Ensure each ADR is complete, actionable, and provides clear guidance for the development team.
100
+ Use the standard ADR format with Status, Context, Decision, and Consequences sections.
101
+ `;
102
+ return executePromptWithFallback(prompt, instructions, {
103
+ ...options,
104
+ systemPrompt,
105
+ temperature: options.temperature ?? 0.1,
106
+ responseFormat: 'text',
107
+ });
108
+ }
109
+ /**
110
+ * Execute a prompt for project ecosystem analysis
111
+ */
112
+ export async function executeEcosystemAnalysisPrompt(prompt, instructions, options = {}) {
113
+ const systemPrompt = options.systemPrompt || `
114
+ You are a senior software architect specializing in technology ecosystem analysis.
115
+ Analyze the provided project context to identify technologies, patterns, and architectural decisions.
116
+ Provide comprehensive insights about the project's technical landscape and recommendations for improvement.
117
+ Focus on practical, actionable insights that can guide architectural decisions.
118
+ `;
119
+ return executePromptWithFallback(prompt, instructions, {
120
+ ...options,
121
+ systemPrompt,
122
+ temperature: options.temperature ?? 0.1,
123
+ responseFormat: 'text',
124
+ });
125
+ }
126
+ /**
127
+ * Execute a prompt for research question generation
128
+ */
129
+ export async function executeResearchPrompt(prompt, instructions, options = {}) {
130
+ const systemPrompt = options.systemPrompt || `
131
+ You are a research specialist who generates comprehensive research questions and methodologies.
132
+ Create detailed research plans that help teams investigate architectural decisions and technologies.
133
+ Focus on practical research approaches that can be executed by development teams.
134
+ Provide clear guidance on research methods, success criteria, and expected outcomes.
135
+ `;
136
+ return executePromptWithFallback(prompt, instructions, {
137
+ ...options,
138
+ systemPrompt,
139
+ temperature: options.temperature ?? 0.2, // Slightly higher for creativity
140
+ responseFormat: 'text',
141
+ });
142
+ }
143
+ /**
144
+ * Check if AI execution is currently available
145
+ */
146
+ export function isAIExecutionAvailable() {
147
+ try {
148
+ const executor = getAIExecutor();
149
+ return executor.isAvailable();
150
+ }
151
+ catch {
152
+ return false;
153
+ }
154
+ }
155
+ /**
156
+ * Get AI execution status for debugging
157
+ */
158
+ export function getAIExecutionStatus() {
159
+ try {
160
+ const config = loadAIConfig();
161
+ const hasApiKey = !!config.apiKey;
162
+ const isEnabled = isAIExecutionEnabled(config);
163
+ let reason = undefined;
164
+ if (!hasApiKey) {
165
+ reason = 'Missing OPENROUTER_API_KEY environment variable';
166
+ }
167
+ else if (config.executionMode !== 'full') {
168
+ reason = `EXECUTION_MODE is '${config.executionMode}', should be 'full'`;
169
+ }
170
+ return {
171
+ isEnabled,
172
+ hasApiKey,
173
+ executionMode: config.executionMode,
174
+ model: config.defaultModel,
175
+ reason
176
+ };
177
+ }
178
+ catch (error) {
179
+ return {
180
+ isEnabled: false,
181
+ hasApiKey: false,
182
+ executionMode: 'unknown',
183
+ model: 'unknown',
184
+ reason: `Configuration error: ${error instanceof Error ? error.message : String(error)}`
185
+ };
186
+ }
187
+ }
188
+ /**
189
+ * Get AI execution status and configuration info (legacy)
190
+ */
191
+ export function getAIExecutionInfo() {
192
+ const config = loadAIConfig();
193
+ const available = isAIExecutionAvailable();
194
+ const result = {
195
+ available,
196
+ mode: config.executionMode,
197
+ };
198
+ if (available) {
199
+ result.model = config.defaultModel;
200
+ result.cacheEnabled = config.cacheEnabled;
201
+ }
202
+ return result;
203
+ }
204
+ /**
205
+ * Format execution result for MCP tool response
206
+ */
207
+ export function formatMCPResponse(result) {
208
+ let responseText = result.content;
209
+ // Add metadata footer if AI was used
210
+ if (result.isAIGenerated && result.aiMetadata) {
211
+ const metadata = [
212
+ `\n\n---`,
213
+ `**AI Generated Response**`,
214
+ `- Model: ${result.model}`,
215
+ `- Execution Time: ${result.aiMetadata.executionTime}ms`,
216
+ `- Cached: ${result.aiMetadata.cached ? 'Yes' : 'No'}`,
217
+ ];
218
+ if (result.usage) {
219
+ metadata.push(`- Tokens Used: ${result.usage.totalTokens} (${result.usage.promptTokens} prompt + ${result.usage.completionTokens} completion)`);
220
+ }
221
+ responseText += metadata.join('\n');
222
+ }
223
+ return {
224
+ content: [{ type: 'text', text: responseText }],
225
+ };
226
+ }
227
+ //# sourceMappingURL=prompt-execution.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompt-execution.js","sourceRoot":"","sources":["../../../src/utils/prompt-execution.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,aAAa,EAAqB,MAAM,kBAAkB,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAgC5E;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,yBAAyB,CAC7C,MAAc,EACd,YAAoB,EACpB,UAAkC,EAAE;IAEpC,MAAM,MAAM,GAAG,YAAY,EAAE,CAAC;IAC9B,MAAM,WAAW,GAAG,CAAC,OAAO,CAAC,eAAe,IAAI,oBAAoB,CAAC,MAAM,CAAC,CAAC;IAE7E,IAAI,WAAW,EAAE,CAAC;QAChB,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,aAAa,EAAE,CAAC;YAEjC,IAAI,OAAO,CAAC,cAAc,KAAK,MAAM,EAAE,CAAC;gBACtC,MAAM,WAAW,GAAQ,EAAE,CAAC;gBAC5B,IAAI,OAAO,CAAC,KAAK,KAAK,SAAS;oBAAE,W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AEG;AACH,MAAM,UAAU,iBAAiB,CAAC,MAA6B;IAG7D,IAAI,YAAY,GAAG,MAAM,CAAC,OAAO,CAAC;IAElC,qCAAqC;IACrC,IAAI,MAAM,CAAC,aAAa,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;QAC9C,MAAM,QAAQ,GAAG;YACf,SAAS;YACT,2BAA2B;YAC3B,YAAY,MAAM,CAAC,KAAK,EAAE;YAC1B,qBAAqB,MAAM,CAAC,UAAU,CAAC,aAAa,IAAI;YACxD,aAAa,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE;SACvD,CAAC;QAEF,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;YACjB,QAAQ,CAAC,IAAI,CAAC,kBAAkB,MAAM,CAAC,KAAK,CAAC,WAAW,KAAK,MAAM,CAAC,KAAK,CAAC,YAAY,aAAa,MAAM,CAAC,KAAK,CAAC,gBAAgB,cAAc,CAAC,CAAC;QAClJ,CAAC;QAED,YAAY,IAAI,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACtC,CAAC;IAED,OAAO;QACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC;KAChD,CAAC;AACJ,CAAC"}
@@ -0,0 +1,92 @@
1
+ /**
2
+ * Reflexion Utility Module - 100% Prompt-Driven Architecture
3
+ * Implements Actor-Evaluator-Self-Reflection pattern for continuous learning
4
+ * All functions return prompts for AI execution, never execute operations directly
5
+ */
6
+ import { ReflexionConfig, ReflexionMemory, MemoryType, EvaluationCriterion, ReflectionDepth, MemoryQuery } from '../types/reflexion-framework.js';
7
+ import { PromptObject } from './prompt-composition.js';
8
+ /**
9
+ * Generate AI delegation prompt for executing a task with reflexion learning
10
+ * Returns prompts for AI to execute tasks with memory-enhanced context
11
+ */
12
+ export declare function executeWithReflexion(basePrompt: PromptObject, config?: Partial<ReflexionConfig>): Promise<{
13
+ prompt: string;
14
+ instructions: string;
15
+ context: any;
16
+ }>;
17
+ /**
18
+ * Generate AI delegation prompt for retrieving relevant memories
19
+ * Returns prompts for AI to search and retrieve relevant past experiences
20
+ */
21
+ export declare function retrieveRelevantMemories(taskType: string, context: any, query?: Partial<MemoryQuery>): Promise<{
22
+ prompt: string;
23
+ instructions: string;
24
+ context: any;
25
+ }>;
26
+ /**
27
+ * Generate AI delegation prompt for persisting reflexion memories
28
+ * Returns prompts for AI to save memories using file system operations
29
+ */
30
+ export declare function persistReflexionMemory(memory: ReflexionMemory): Promise<{
31
+ prompt: string;
32
+ instructions: string;
33
+ context: any;
34
+ }>;
35
+ /**
36
+ * Generate AI delegation prompt for tracking learning progress
37
+ * Returns prompts for AI to analyze and report learning progress
38
+ */
39
+ export declare function getLearningProgress(taskType: string): Promise<{
40
+ prompt: string;
41
+ instructions: string;
42
+ context: any;
43
+ }>;
44
+ /**
45
+ * Generate cache key for reflexion requests
46
+ */
47
+ export declare function generateReflexionCacheKey(promptHash: string, config: ReflexionConfig): string;
48
+ /**
49
+ * Get default reflexion configuration
50
+ */
51
+ export declare function getDefaultReflexionConfig(): Required<ReflexionConfig>;
52
+ /**
53
+ * Validate reflexion configuration
54
+ */
55
+ export declare function validateReflexionConfig(config: Partial<ReflexionConfig>): void;
56
+ /**
57
+ * Get supported memory types
58
+ */
59
+ export declare function getSupportedMemoryTypes(): MemoryType[];
60
+ /**
61
+ * Get supported evaluation criteria
62
+ */
63
+ export declare function getSupportedEvaluationCriteria(): EvaluationCriterion[];
64
+ /**
65
+ * Get supported reflection depths
66
+ */
67
+ export declare function getSupportedReflectionDepths(): ReflectionDepth[];
68
+ /**
69
+ * Create tool-specific reflexion configuration
70
+ */
71
+ export declare function createToolReflexionConfig(toolName: string, customConfig?: Partial<ReflexionConfig>): ReflexionConfig;
72
+ /**
73
+ * Generate memory ID for new memories
74
+ */
75
+ export declare function generateMemoryId(memoryType: MemoryType, category: string): string;
76
+ /**
77
+ * Calculate memory expiration date
78
+ */
79
+ export declare function calculateMemoryExpiration(retentionDays: number, importance?: 'low' | 'medium' | 'high' | 'critical'): string;
80
+ /**
81
+ * Create memory query from context
82
+ */
83
+ export declare function createMemoryQuery(taskType: string, context: any, options?: Partial<MemoryQuery>): MemoryQuery;
84
+ /**
85
+ * Enhance prompt with memory context
86
+ */
87
+ export declare function enhancePromptWithMemories(basePrompt: PromptObject, memories: ReflexionMemory[]): Promise<{
88
+ prompt: string;
89
+ instructions: string;
90
+ context: any;
91
+ }>;
92
+ //# sourceMappingURL=reflexion.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reflexion.d.ts","sourceRoot":"","sources":["../../../src/utils/reflexion.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EACL,eAAe,EACf,eAAe,EACf,UAAU,EACV,mBAAmB,EACnB,eAAe,EACf,WAAW,EACZ,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAyBvD;;;GAGG;AACH,wBAAsB,oBAAoB,CACxC,UAAU,EAAE,YAAY,EACxB,MAAM,GAAE,OAAO,CAAC,eAAe,CAAM,GACpC,OAAO,CAAC;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,GAAG,CAAA;CAAE,CAAC,CAkVjE;AAED;;;GAGG;AACH,wBAAsB,wBAAwB,CAC5C,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,GAAG,EACZ,KAAK,GAAE,OAAO,CAAC,WAAW,CAAM,GAC/B,OAAO,CAAC;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,GAAG,CAAA;CAAE,CAAC,CA0KjE;AAED;;;GAGG;AACH,wBAAsB,sBAAsB,CAC1C,MAAM,EAAE,eAAe,GACtB,OAAO,CAAC;IAAE,MAAM,EAAE,MAAM,CAA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