agentic-qe 1.6.1 → 1.8.0
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/.claude/skills/sherlock-review/SKILL.md +786 -0
- package/CHANGELOG.md +651 -0
- package/README.md +52 -8
- package/dist/agents/BaseAgent.d.ts +30 -10
- package/dist/agents/BaseAgent.d.ts.map +1 -1
- package/dist/agents/BaseAgent.js +115 -43
- package/dist/agents/BaseAgent.js.map +1 -1
- package/dist/agents/CoverageAnalyzerAgent.js +2 -2
- package/dist/agents/CoverageAnalyzerAgent.js.map +1 -1
- package/dist/agents/FleetCommanderAgent.d.ts +16 -0
- package/dist/agents/FleetCommanderAgent.d.ts.map +1 -1
- package/dist/agents/FleetCommanderAgent.js +35 -20
- package/dist/agents/FleetCommanderAgent.js.map +1 -1
- package/dist/agents/LearningAgent.d.ts +2 -2
- package/dist/agents/LearningAgent.d.ts.map +1 -1
- package/dist/agents/LearningAgent.js +4 -4
- package/dist/agents/LearningAgent.js.map +1 -1
- package/dist/agents/TestExecutorAgent.d.ts +9 -0
- package/dist/agents/TestExecutorAgent.d.ts.map +1 -1
- package/dist/agents/TestExecutorAgent.js +60 -0
- package/dist/agents/TestExecutorAgent.js.map +1 -1
- package/dist/agents/examples/batchAnalyze.d.ts +252 -0
- package/dist/agents/examples/batchAnalyze.d.ts.map +1 -0
- package/dist/agents/examples/batchAnalyze.js +259 -0
- package/dist/agents/examples/batchAnalyze.js.map +1 -0
- package/dist/agents/examples/batchGenerate.d.ts +153 -0
- package/dist/agents/examples/batchGenerate.d.ts.map +1 -0
- package/dist/agents/examples/batchGenerate.js +166 -0
- package/dist/agents/examples/batchGenerate.js.map +1 -0
- package/dist/agents/generateWithPII.d.ts +128 -0
- package/dist/agents/generateWithPII.d.ts.map +1 -0
- package/dist/agents/generateWithPII.js +175 -0
- package/dist/agents/generateWithPII.js.map +1 -0
- package/dist/agents/index.d.ts.map +1 -1
- package/dist/agents/index.js +0 -2
- package/dist/agents/index.js.map +1 -1
- package/dist/agents/lifecycle/AgentLifecycleManager.d.ts +5 -0
- package/dist/agents/lifecycle/AgentLifecycleManager.d.ts.map +1 -1
- package/dist/agents/lifecycle/AgentLifecycleManager.js +10 -0
- package/dist/agents/lifecycle/AgentLifecycleManager.js.map +1 -1
- package/dist/cli/commands/agentdb/learn.d.ts.map +1 -1
- package/dist/cli/commands/agentdb/learn.js +190 -71
- package/dist/cli/commands/agentdb/learn.js.map +1 -1
- package/dist/cli/commands/debug/agent.d.ts.map +1 -1
- package/dist/cli/commands/debug/agent.js +40 -13
- package/dist/cli/commands/debug/agent.js.map +1 -1
- package/dist/cli/commands/debug/diagnostics.js +38 -11
- package/dist/cli/commands/debug/diagnostics.js.map +1 -1
- package/dist/cli/commands/debug/health-check.js +47 -12
- package/dist/cli/commands/debug/health-check.js.map +1 -1
- package/dist/cli/commands/debug/profile.js +7 -7
- package/dist/cli/commands/debug/profile.js.map +1 -1
- package/dist/cli/commands/debug/trace.js +4 -4
- package/dist/cli/commands/debug/trace.js.map +1 -1
- package/dist/cli/commands/debug/troubleshoot.js +41 -27
- package/dist/cli/commands/debug/troubleshoot.js.map +1 -1
- package/dist/cli/commands/init.d.ts +6 -3
- package/dist/cli/commands/init.d.ts.map +1 -1
- package/dist/cli/commands/init.js +71 -54
- package/dist/cli/commands/init.js.map +1 -1
- package/dist/cli/commands/learn/index.d.ts +4 -0
- package/dist/cli/commands/learn/index.d.ts.map +1 -1
- package/dist/cli/commands/learn/index.js +57 -0
- package/dist/cli/commands/learn/index.js.map +1 -1
- package/dist/cli/commands/test/clean.d.ts.map +1 -1
- package/dist/cli/commands/test/clean.js +26 -9
- package/dist/cli/commands/test/clean.js.map +1 -1
- package/dist/cli/commands/test/debug.js +6 -7
- package/dist/cli/commands/test/debug.js.map +1 -1
- package/dist/cli/commands/test/diff.js +4 -37
- package/dist/cli/commands/test/diff.js.map +1 -1
- package/dist/cli/commands/test/profile.js +7 -40
- package/dist/cli/commands/test/profile.js.map +1 -1
- package/dist/cli/commands/test/trace.js +4 -37
- package/dist/cli/commands/test/trace.js.map +1 -1
- package/dist/cli/index.js +14 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/core/ArtifactWorkflow.d.ts +4 -0
- package/dist/core/ArtifactWorkflow.d.ts.map +1 -1
- package/dist/core/ArtifactWorkflow.js +34 -13
- package/dist/core/ArtifactWorkflow.js.map +1 -1
- package/dist/core/coordination/BlackboardCoordination.d.ts +4 -0
- package/dist/core/coordination/BlackboardCoordination.d.ts.map +1 -1
- package/dist/core/coordination/BlackboardCoordination.js +28 -22
- package/dist/core/coordination/BlackboardCoordination.js.map +1 -1
- package/dist/core/coordination/ConsensusGating.d.ts +4 -0
- package/dist/core/coordination/ConsensusGating.d.ts.map +1 -1
- package/dist/core/coordination/ConsensusGating.js +25 -18
- package/dist/core/coordination/ConsensusGating.js.map +1 -1
- package/dist/core/memory/AgentDBManager.d.ts +5 -0
- package/dist/core/memory/AgentDBManager.d.ts.map +1 -1
- package/dist/core/memory/AgentDBManager.js +19 -1
- package/dist/core/memory/AgentDBManager.js.map +1 -1
- package/dist/core/memory/AgentDBService.d.ts.map +1 -1
- package/dist/core/memory/AgentDBService.js +6 -3
- package/dist/core/memory/AgentDBService.js.map +1 -1
- package/dist/core/memory/RealAgentDBAdapter.d.ts +8 -0
- package/dist/core/memory/RealAgentDBAdapter.d.ts.map +1 -1
- package/dist/core/memory/RealAgentDBAdapter.js +74 -17
- package/dist/core/memory/RealAgentDBAdapter.js.map +1 -1
- package/dist/core/memory/ReasoningBankAdapter.d.ts +4 -0
- package/dist/core/memory/ReasoningBankAdapter.d.ts.map +1 -1
- package/dist/core/memory/ReasoningBankAdapter.js +20 -0
- package/dist/core/memory/ReasoningBankAdapter.js.map +1 -1
- package/dist/core/memory/SwarmMemoryManager.d.ts +8 -0
- package/dist/core/memory/SwarmMemoryManager.d.ts.map +1 -1
- package/dist/core/memory/SwarmMemoryManager.js +33 -0
- package/dist/core/memory/SwarmMemoryManager.js.map +1 -1
- package/dist/learning/ImprovementLoop.js +2 -2
- package/dist/learning/ImprovementLoop.js.map +1 -1
- package/dist/learning/LearningEngine.d.ts +11 -7
- package/dist/learning/LearningEngine.d.ts.map +1 -1
- package/dist/learning/LearningEngine.js +157 -73
- package/dist/learning/LearningEngine.js.map +1 -1
- package/dist/learning/StateExtractor.d.ts +1 -1
- package/dist/learning/StateExtractor.d.ts.map +1 -1
- package/dist/learning/StateExtractor.js +62 -13
- package/dist/learning/StateExtractor.js.map +1 -1
- package/dist/mcp/handlers/filtered/coverage-analyzer-filtered.d.ts +83 -0
- package/dist/mcp/handlers/filtered/coverage-analyzer-filtered.d.ts.map +1 -0
- package/dist/mcp/handlers/filtered/coverage-analyzer-filtered.js +130 -0
- package/dist/mcp/handlers/filtered/coverage-analyzer-filtered.js.map +1 -0
- package/dist/mcp/handlers/filtered/flaky-detector-filtered.d.ts +58 -0
- package/dist/mcp/handlers/filtered/flaky-detector-filtered.d.ts.map +1 -0
- package/dist/mcp/handlers/filtered/flaky-detector-filtered.js +84 -0
- package/dist/mcp/handlers/filtered/flaky-detector-filtered.js.map +1 -0
- package/dist/mcp/handlers/filtered/index.d.ts +47 -0
- package/dist/mcp/handlers/filtered/index.d.ts.map +1 -0
- package/dist/mcp/handlers/filtered/index.js +63 -0
- package/dist/mcp/handlers/filtered/index.js.map +1 -0
- package/dist/mcp/handlers/filtered/performance-tester-filtered.d.ts +57 -0
- package/dist/mcp/handlers/filtered/performance-tester-filtered.d.ts.map +1 -0
- package/dist/mcp/handlers/filtered/performance-tester-filtered.js +83 -0
- package/dist/mcp/handlers/filtered/performance-tester-filtered.js.map +1 -0
- package/dist/mcp/handlers/filtered/quality-assessor-filtered.d.ts +57 -0
- package/dist/mcp/handlers/filtered/quality-assessor-filtered.d.ts.map +1 -0
- package/dist/mcp/handlers/filtered/quality-assessor-filtered.js +93 -0
- package/dist/mcp/handlers/filtered/quality-assessor-filtered.js.map +1 -0
- package/dist/mcp/handlers/filtered/security-scanner-filtered.d.ts +54 -0
- package/dist/mcp/handlers/filtered/security-scanner-filtered.d.ts.map +1 -0
- package/dist/mcp/handlers/filtered/security-scanner-filtered.js +73 -0
- package/dist/mcp/handlers/filtered/security-scanner-filtered.js.map +1 -0
- package/dist/mcp/handlers/filtered/test-executor-filtered.d.ts +61 -0
- package/dist/mcp/handlers/filtered/test-executor-filtered.d.ts.map +1 -0
- package/dist/mcp/handlers/filtered/test-executor-filtered.js +117 -0
- package/dist/mcp/handlers/filtered/test-executor-filtered.js.map +1 -0
- package/dist/mcp/handlers/phase2/Phase2Tools.js +2 -2
- package/dist/mcp/handlers/phase2/Phase2Tools.js.map +1 -1
- package/dist/mcp/tools/deprecated.d.ts +8 -8
- package/dist/scripts/backup-helper.d.ts +64 -0
- package/dist/scripts/backup-helper.d.ts.map +1 -0
- package/dist/scripts/backup-helper.js +251 -0
- package/dist/scripts/backup-helper.js.map +1 -0
- package/dist/scripts/migrate-with-backup.d.ts +15 -0
- package/dist/scripts/migrate-with-backup.d.ts.map +1 -0
- package/dist/scripts/migrate-with-backup.js +194 -0
- package/dist/scripts/migrate-with-backup.js.map +1 -0
- package/dist/security/pii-tokenization.d.ts +216 -0
- package/dist/security/pii-tokenization.d.ts.map +1 -0
- package/dist/security/pii-tokenization.js +325 -0
- package/dist/security/pii-tokenization.js.map +1 -0
- package/dist/utils/Config.d.ts.map +1 -1
- package/dist/utils/Config.js +14 -5
- package/dist/utils/Config.js.map +1 -1
- package/dist/utils/Database.d.ts.map +1 -1
- package/dist/utils/Database.js +5 -2
- package/dist/utils/Database.js.map +1 -1
- package/dist/utils/EmbeddingGenerator.d.ts +35 -0
- package/dist/utils/EmbeddingGenerator.d.ts.map +1 -0
- package/dist/utils/EmbeddingGenerator.js +72 -0
- package/dist/utils/EmbeddingGenerator.js.map +1 -0
- package/dist/utils/Logger.d.ts +1 -1
- package/dist/utils/Logger.d.ts.map +1 -1
- package/dist/utils/Logger.js +4 -4
- package/dist/utils/Logger.js.map +1 -1
- package/dist/utils/SecurityScanner.js +1 -1
- package/dist/utils/SecurityScanner.js.map +1 -1
- package/dist/utils/batch-operations.d.ts +215 -0
- package/dist/utils/batch-operations.d.ts.map +1 -0
- package/dist/utils/batch-operations.js +266 -0
- package/dist/utils/batch-operations.js.map +1 -0
- package/dist/utils/filtering.d.ts +180 -0
- package/dist/utils/filtering.d.ts.map +1 -0
- package/dist/utils/filtering.js +288 -0
- package/dist/utils/filtering.js.map +1 -0
- package/dist/utils/prompt-cache-examples.d.ts +111 -0
- package/dist/utils/prompt-cache-examples.d.ts.map +1 -0
- package/dist/utils/prompt-cache-examples.js +416 -0
- package/dist/utils/prompt-cache-examples.js.map +1 -0
- package/dist/utils/prompt-cache.d.ts +305 -0
- package/dist/utils/prompt-cache.d.ts.map +1 -0
- package/dist/utils/prompt-cache.js +448 -0
- package/dist/utils/prompt-cache.js.map +1 -0
- package/package.json +6 -3
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prompt Caching Infrastructure (CO-1)
|
|
3
|
+
*
|
|
4
|
+
* Implements Anthropic's prompt caching with proper cache key management and invalidation.
|
|
5
|
+
*
|
|
6
|
+
* IMPORTANT: Anthropic caching requirements:
|
|
7
|
+
* 1. Minimum 1024 tokens per cached block
|
|
8
|
+
* 2. Cache control on LAST 3 blocks only
|
|
9
|
+
* 3. 5-minute automatic TTL
|
|
10
|
+
*
|
|
11
|
+
* Cost model:
|
|
12
|
+
* - Cache write: 25% premium on input tokens
|
|
13
|
+
* - Cache hit: 90% discount on cached tokens
|
|
14
|
+
* - Regular tokens: Standard $3.00 per 1M input tokens
|
|
15
|
+
*
|
|
16
|
+
* @module utils/prompt-cache
|
|
17
|
+
*/
|
|
18
|
+
import Anthropic from '@anthropic-ai/sdk';
|
|
19
|
+
/**
|
|
20
|
+
* Content that can be cached with TTL and priority
|
|
21
|
+
*/
|
|
22
|
+
export interface CacheableContent {
|
|
23
|
+
/** Text content to cache */
|
|
24
|
+
text: string;
|
|
25
|
+
/** Time-to-live in milliseconds (optional, defaults to 5 minutes) */
|
|
26
|
+
ttl?: number;
|
|
27
|
+
/** Priority hint for cache management */
|
|
28
|
+
priority?: 'high' | 'medium' | 'low';
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Cache performance statistics
|
|
32
|
+
*/
|
|
33
|
+
export interface CacheStats {
|
|
34
|
+
/** Number of cache hits */
|
|
35
|
+
hits: number;
|
|
36
|
+
/** Number of cache misses */
|
|
37
|
+
misses: number;
|
|
38
|
+
/** Number of cache writes */
|
|
39
|
+
writes: number;
|
|
40
|
+
/** Hit rate as percentage (0-1) */
|
|
41
|
+
hitRate: number;
|
|
42
|
+
/** Total cost savings in dollars */
|
|
43
|
+
costSavings: number;
|
|
44
|
+
/** Total tokens written to cache */
|
|
45
|
+
tokensWritten: number;
|
|
46
|
+
/** Total tokens read from cache */
|
|
47
|
+
tokensRead: number;
|
|
48
|
+
/** Total regular input tokens */
|
|
49
|
+
tokensRegular: number;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* PromptCacheManager
|
|
53
|
+
*
|
|
54
|
+
* Manages Anthropic prompt caching with content-addressable cache keys,
|
|
55
|
+
* TTL-based invalidation, and cost accounting.
|
|
56
|
+
*
|
|
57
|
+
* Features:
|
|
58
|
+
* - SHA-256 based cache keys for content addressability
|
|
59
|
+
* - 5-minute TTL with automatic pruning
|
|
60
|
+
* - Cost tracking for cache writes (25% premium) vs hits (90% discount)
|
|
61
|
+
* - Statistics for cache hit rate and cost savings
|
|
62
|
+
* - Support for up to 3 cached blocks per request
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```typescript
|
|
66
|
+
* const cacheManager = new PromptCacheManager(process.env.ANTHROPIC_API_KEY!);
|
|
67
|
+
*
|
|
68
|
+
* const response = await cacheManager.createWithCache({
|
|
69
|
+
* model: 'claude-sonnet-4',
|
|
70
|
+
* systemPrompts: [
|
|
71
|
+
* { text: AGENT_SYSTEM_PROMPT, priority: 'high' },
|
|
72
|
+
* ],
|
|
73
|
+
* projectContext: [
|
|
74
|
+
* { text: JSON.stringify(projectStructure), priority: 'medium' },
|
|
75
|
+
* ],
|
|
76
|
+
* messages: [
|
|
77
|
+
* { role: 'user', content: 'Generate tests for this code...' },
|
|
78
|
+
* ],
|
|
79
|
+
* });
|
|
80
|
+
*
|
|
81
|
+
* const stats = cacheManager.getStats();
|
|
82
|
+
* console.log(`Cache hit rate: ${(stats.hitRate * 100).toFixed(1)}%`);
|
|
83
|
+
* console.log(`Cost savings: $${stats.costSavings.toFixed(4)}`);
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
export declare class PromptCacheManager {
|
|
87
|
+
private anthropic;
|
|
88
|
+
private cacheKeys;
|
|
89
|
+
private stats;
|
|
90
|
+
/** Cache TTL in milliseconds (5 minutes as per Anthropic specs) */
|
|
91
|
+
private readonly CACHE_TTL;
|
|
92
|
+
/** Minimum tokens required for caching */
|
|
93
|
+
private readonly MIN_CACHE_TOKENS;
|
|
94
|
+
/** Cost per million tokens */
|
|
95
|
+
private readonly COST_PER_MILLION;
|
|
96
|
+
/** Cache write premium (25%) */
|
|
97
|
+
private readonly CACHE_WRITE_PREMIUM;
|
|
98
|
+
/** Cache read discount (90%) */
|
|
99
|
+
private readonly CACHE_READ_DISCOUNT;
|
|
100
|
+
/**
|
|
101
|
+
* Create a new PromptCacheManager
|
|
102
|
+
*
|
|
103
|
+
* @param apiKey - Anthropic API key
|
|
104
|
+
*/
|
|
105
|
+
constructor(apiKey: string);
|
|
106
|
+
/**
|
|
107
|
+
* Create message with cached content
|
|
108
|
+
*
|
|
109
|
+
* IMPORTANT: Anthropic caching requires:
|
|
110
|
+
* 1. Minimum 1024 tokens per cached block
|
|
111
|
+
* 2. Cache control on LAST 3 blocks only
|
|
112
|
+
* 3. 5-minute TTL (automatic)
|
|
113
|
+
*
|
|
114
|
+
* This method automatically:
|
|
115
|
+
* - Checks content size before caching (must be >= 1024 tokens)
|
|
116
|
+
* - Adds cache control to last 3 blocks
|
|
117
|
+
* - Tracks cache hits/misses via content hashing
|
|
118
|
+
* - Updates cost statistics
|
|
119
|
+
*
|
|
120
|
+
* @param params - Message parameters with cacheable content
|
|
121
|
+
* @returns Anthropic message response
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* ```typescript
|
|
125
|
+
* const response = await cacheManager.createWithCache({
|
|
126
|
+
* model: 'claude-sonnet-4',
|
|
127
|
+
* systemPrompts: [
|
|
128
|
+
* { text: SYSTEM_PROMPT, priority: 'high' },
|
|
129
|
+
* ],
|
|
130
|
+
* projectContext: [
|
|
131
|
+
* { text: projectData, priority: 'medium' },
|
|
132
|
+
* ],
|
|
133
|
+
* messages: [{ role: 'user', content: userQuery }],
|
|
134
|
+
* });
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
createWithCache(params: {
|
|
138
|
+
model: string;
|
|
139
|
+
messages: Anthropic.MessageParam[];
|
|
140
|
+
systemPrompts: CacheableContent[];
|
|
141
|
+
projectContext?: CacheableContent[];
|
|
142
|
+
maxTokens?: number;
|
|
143
|
+
temperature?: number;
|
|
144
|
+
}): Promise<Anthropic.Message>;
|
|
145
|
+
/**
|
|
146
|
+
* Generate cache key from content using SHA-256
|
|
147
|
+
*
|
|
148
|
+
* Creates a content-addressable cache key by hashing all text blocks.
|
|
149
|
+
* Only cached blocks (those with cache_control) are included in the hash.
|
|
150
|
+
*
|
|
151
|
+
* @param content - Text blocks to hash
|
|
152
|
+
* @returns SHA-256 hash of content
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* ```typescript
|
|
156
|
+
* const key = cacheManager.generateCacheKey([
|
|
157
|
+
* { type: 'text', text: 'system prompt', cache_control: { type: 'ephemeral' } },
|
|
158
|
+
* { type: 'text', text: 'project context', cache_control: { type: 'ephemeral' } },
|
|
159
|
+
* ]);
|
|
160
|
+
* // Returns: "a3f2c8b9..." (SHA-256 hash)
|
|
161
|
+
* ```
|
|
162
|
+
*/
|
|
163
|
+
private generateCacheKey;
|
|
164
|
+
/**
|
|
165
|
+
* Check if cache key exists and is fresh (within 5 minutes)
|
|
166
|
+
*
|
|
167
|
+
* @param cacheKey - Cache key to check
|
|
168
|
+
* @returns true if cache hit, false if cache miss
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* ```typescript
|
|
172
|
+
* const isHit = cacheManager.isCacheHit('a3f2c8b9...');
|
|
173
|
+
* if (isHit) {
|
|
174
|
+
* console.log('Cache hit! Will save 90% on cached tokens');
|
|
175
|
+
* }
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
private isCacheHit;
|
|
179
|
+
/**
|
|
180
|
+
* Update cache statistics from API response
|
|
181
|
+
*
|
|
182
|
+
* Tracks:
|
|
183
|
+
* - Cache creation tokens (write with 25% premium)
|
|
184
|
+
* - Cache read tokens (hit with 90% discount)
|
|
185
|
+
* - Regular input tokens (standard cost)
|
|
186
|
+
* - Cost savings calculation
|
|
187
|
+
*
|
|
188
|
+
* @param response - Anthropic API response
|
|
189
|
+
* @param wasHit - Whether this was a cache hit
|
|
190
|
+
*/
|
|
191
|
+
private updateStats;
|
|
192
|
+
/**
|
|
193
|
+
* Get cache statistics
|
|
194
|
+
*
|
|
195
|
+
* @returns Current cache statistics including hit rate and cost savings
|
|
196
|
+
*
|
|
197
|
+
* @example
|
|
198
|
+
* ```typescript
|
|
199
|
+
* const stats = cacheManager.getStats();
|
|
200
|
+
* console.log(`Hit rate: ${(stats.hitRate * 100).toFixed(1)}%`);
|
|
201
|
+
* console.log(`Cost savings: $${stats.costSavings.toFixed(4)}`);
|
|
202
|
+
* console.log(`Total hits: ${stats.hits}, misses: ${stats.misses}`);
|
|
203
|
+
* ```
|
|
204
|
+
*/
|
|
205
|
+
getStats(): CacheStats;
|
|
206
|
+
/**
|
|
207
|
+
* Clear cache keys older than TTL
|
|
208
|
+
*
|
|
209
|
+
* Automatically prunes expired cache entries to prevent memory bloat.
|
|
210
|
+
* Should be called periodically in long-running processes.
|
|
211
|
+
*
|
|
212
|
+
* @returns Number of entries pruned
|
|
213
|
+
*
|
|
214
|
+
* @example
|
|
215
|
+
* ```typescript
|
|
216
|
+
* // Run every 5 minutes
|
|
217
|
+
* setInterval(() => {
|
|
218
|
+
* const pruned = cacheManager.pruneCache();
|
|
219
|
+
* console.log(`Pruned ${pruned} expired cache entries`);
|
|
220
|
+
* }, 5 * 60 * 1000);
|
|
221
|
+
* ```
|
|
222
|
+
*/
|
|
223
|
+
pruneCache(): number;
|
|
224
|
+
/**
|
|
225
|
+
* Reset statistics
|
|
226
|
+
*
|
|
227
|
+
* Clears all cache statistics. Useful for testing or when starting
|
|
228
|
+
* a new measurement period.
|
|
229
|
+
*
|
|
230
|
+
* @example
|
|
231
|
+
* ```typescript
|
|
232
|
+
* // Reset stats at start of each day
|
|
233
|
+
* cacheManager.resetStats();
|
|
234
|
+
* ```
|
|
235
|
+
*/
|
|
236
|
+
resetStats(): void;
|
|
237
|
+
/**
|
|
238
|
+
* Clear all cache keys
|
|
239
|
+
*
|
|
240
|
+
* Removes all cache entries. Does not affect statistics.
|
|
241
|
+
*
|
|
242
|
+
* @example
|
|
243
|
+
* ```typescript
|
|
244
|
+
* // Clear cache when deploying new version
|
|
245
|
+
* cacheManager.clearCache();
|
|
246
|
+
* ```
|
|
247
|
+
*/
|
|
248
|
+
clearCache(): void;
|
|
249
|
+
/**
|
|
250
|
+
* Check if content should be cached based on token count
|
|
251
|
+
*
|
|
252
|
+
* Anthropic requires minimum 1024 tokens for caching to be effective.
|
|
253
|
+
*
|
|
254
|
+
* @param text - Text content to check
|
|
255
|
+
* @returns true if content is large enough to cache
|
|
256
|
+
*/
|
|
257
|
+
private shouldCache;
|
|
258
|
+
/**
|
|
259
|
+
* Estimate token count for content blocks
|
|
260
|
+
*
|
|
261
|
+
* Uses rough heuristic: 4 characters per token (conservative estimate)
|
|
262
|
+
*
|
|
263
|
+
* @param content - Text blocks to estimate
|
|
264
|
+
* @returns Estimated token count
|
|
265
|
+
*/
|
|
266
|
+
private estimateTokens;
|
|
267
|
+
/**
|
|
268
|
+
* Get cache size (number of entries)
|
|
269
|
+
*
|
|
270
|
+
* @returns Number of cache entries
|
|
271
|
+
*/
|
|
272
|
+
getCacheSize(): number;
|
|
273
|
+
/**
|
|
274
|
+
* Get expected hit rate target
|
|
275
|
+
*
|
|
276
|
+
* According to the MCP improvement plan, we should target
|
|
277
|
+
* 60-80% cache hit rate over 5-minute windows.
|
|
278
|
+
*
|
|
279
|
+
* @returns Target hit rate range
|
|
280
|
+
*/
|
|
281
|
+
static getTargetHitRate(): {
|
|
282
|
+
min: number;
|
|
283
|
+
max: number;
|
|
284
|
+
};
|
|
285
|
+
/**
|
|
286
|
+
* Calculate break-even point
|
|
287
|
+
*
|
|
288
|
+
* Cache writes cost 25% more than regular calls.
|
|
289
|
+
* Cache hits save 90% on cached tokens.
|
|
290
|
+
*
|
|
291
|
+
* Break-even: 1 write + N hits where total cost equals regular cost
|
|
292
|
+
*
|
|
293
|
+
* @param cacheTokens - Number of tokens in cached content
|
|
294
|
+
* @returns Number of hits needed to break even
|
|
295
|
+
*/
|
|
296
|
+
static calculateBreakEven(cacheTokens: number): {
|
|
297
|
+
hitsToBreakEven: number;
|
|
298
|
+
savings: {
|
|
299
|
+
atBreakEven: number;
|
|
300
|
+
at5Hits: number;
|
|
301
|
+
at10Hits: number;
|
|
302
|
+
};
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
//# sourceMappingURL=prompt-cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt-cache.d.ts","sourceRoot":"","sources":["../../src/utils/prompt-cache.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,SAAS,MAAM,mBAAmB,CAAC;AAG1C;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,4BAA4B;IAC5B,IAAI,EAAE,MAAM,CAAC;IAC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