Skip to content

Commit 9191a14

Browse files
committed
fixed knip (**/cache/** dirs are ignored), fixed cache busting when prompt changes
1 parent 1dce998 commit 9191a14

32 files changed

Lines changed: 177 additions & 38 deletions
File renamed without changes.
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,8 @@ describe('generateClassifierCacheKey', () => {
194194

195195
it('should handle empty messages array', () => {
196196
const key = generateClassifierCacheKey('anthropic', 'claude-haiku-4-5', [])
197-
expect(key).toMatch(/^ai\/anthropic\/claude-haiku-4-5\/[a-f0-9]{64}$/)
197+
// Format: ai/<provider>/<model>/<promptSig 8 chars>/<hash 64 chars>
198+
expect(key).toMatch(/^ai\/anthropic\/claude-haiku-4-5\/[a-f0-9]{8}\/[a-f0-9]{64}$/)
198199
})
199200
})
200201

src/cache/key.ts renamed to src/caching/key.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
import { createHash } from 'node:crypto'
8+
import { getPromptSignature } from '../classifier/prompt'
89
import type { CacheKeyComponents } from './types'
910

1011
/**
@@ -65,13 +66,16 @@ export function generateEmbeddingCacheKey(model: string, inputs: readonly string
6566

6667
/**
6768
* Generate cache key for classification requests.
68-
* Path: ai/<provider>/<model>/<hash>.json
69+
* Path: ai/<provider>/<model>/<promptSig>/<hash>.json
70+
*
71+
* Includes prompt signature so cache is invalidated when prompt.ts changes.
6972
*/
7073
export function generateClassifierCacheKey(
7174
provider: string,
7275
model: string,
7376
messages: readonly { readonly content: string; readonly messageId: number }[]
7477
): string {
78+
const promptSig = getPromptSignature()
7579
const hash = generateCacheKey({
7680
service: provider,
7781
model,
@@ -82,7 +86,7 @@ export function generateClassifierCacheKey(
8286
}))
8387
}
8488
})
85-
return `ai/${provider}/${model}/${hash}`
89+
return `ai/${provider}/${model}/${promptSig}/${hash}`
8690
}
8791

8892
/**
File renamed without changes.

src/classifier/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
* and extract activity/location details.
66
*/
77

8-
import { generateClassifierCacheKey } from '../cache/key'
9-
import type { ResponseCache } from '../cache/types'
8+
import { generateClassifierCacheKey } from '../caching/key'
9+
import type { ResponseCache } from '../caching/types'
1010
import {
1111
type ActivityCategory,
1212
type CandidateMessage,

0 commit comments

Comments
 (0)