@takara-ai/miru-code 0.7.0 → 0.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/package.json +1 -1
- package/src/cache.ts +11 -0
- package/src/miru-index.ts +2 -0
- package/src/version.ts +15 -0
package/package.json
CHANGED
package/src/cache.ts
CHANGED
|
@@ -13,8 +13,13 @@ import { resolveSemanticStorage, semanticStorageFromMetadata } from "./index/vec
|
|
|
13
13
|
import type { Chunk, ContentType } from "./types.ts";
|
|
14
14
|
import { chunkFromDict } from "./types.ts";
|
|
15
15
|
import { computeSourceCacheKey } from "./utils.ts";
|
|
16
|
+
import { indexCacheEpoch } from "./version.ts";
|
|
16
17
|
|
|
17
18
|
export function resolveCacheFolder(): string {
|
|
19
|
+
const override = process.env.MIRU_CACHE_HOME?.trim();
|
|
20
|
+
if (override) {
|
|
21
|
+
return override;
|
|
22
|
+
}
|
|
18
23
|
const name = "miru";
|
|
19
24
|
const home = process.env.HOME ?? process.env.USERPROFILE ?? "";
|
|
20
25
|
let base: string;
|
|
@@ -43,6 +48,9 @@ function metadataMatches(
|
|
|
43
48
|
content: ContentType[],
|
|
44
49
|
): boolean {
|
|
45
50
|
try {
|
|
51
|
+
if (metadata.index_epoch !== indexCacheEpoch()) {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
46
54
|
const stored = metadata.content_type as ContentType[];
|
|
47
55
|
const model = metadata.embedding_model as string;
|
|
48
56
|
if (model !== embeddingModel) {
|
|
@@ -87,6 +95,9 @@ export async function getValidatedCache(
|
|
|
87
95
|
const model = embeddingModel ?? resolveEmbeddingModel();
|
|
88
96
|
const metadata = JSON.parse(await Bun.file(paths.metadata).text()) as Record<string, unknown>;
|
|
89
97
|
if (!metadataMatches(metadata, model, content)) {
|
|
98
|
+
if (metadata.index_epoch !== indexCacheEpoch()) {
|
|
99
|
+
await rm(indexPath, { recursive: true, force: true });
|
|
100
|
+
}
|
|
90
101
|
return null;
|
|
91
102
|
}
|
|
92
103
|
|
package/src/miru-index.ts
CHANGED
|
@@ -17,6 +17,7 @@ import { hybridSearch, searchSemanticOnly } from "./search.ts";
|
|
|
17
17
|
import type { Chunk, ContentType, SearchResult } from "./types.ts";
|
|
18
18
|
import { chunkKey, chunkToDict } from "./types.ts";
|
|
19
19
|
import { computeSourceCacheKey, isGitUrl } from "./utils.ts";
|
|
20
|
+
import { indexCacheEpoch } from "./version.ts";
|
|
20
21
|
|
|
21
22
|
export class MiruIndex {
|
|
22
23
|
readonly embeddings: EmbeddingBackend;
|
|
@@ -204,6 +205,7 @@ export class MiruIndex {
|
|
|
204
205
|
semantic: this.semanticIndex,
|
|
205
206
|
chunks: this.chunks.map(chunkToDict),
|
|
206
207
|
metadata: {
|
|
208
|
+
index_epoch: indexCacheEpoch(),
|
|
207
209
|
root_path: this.root,
|
|
208
210
|
time: Date.now() / 1000,
|
|
209
211
|
embedding_model: this.embeddingModel,
|
package/src/version.ts
CHANGED
|
@@ -19,6 +19,21 @@ export function miruVersion(): string {
|
|
|
19
19
|
return packageJson.version;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
/**
|
|
23
|
+
* Index cache epoch — zero-copy from package.json semver.
|
|
24
|
+
* - 0.x releases: `0.{minor}` (chunking may break on minor bumps pre-1.0).
|
|
25
|
+
* - 1.x+: major version only.
|
|
26
|
+
*/
|
|
27
|
+
export function indexCacheEpoch(): string {
|
|
28
|
+
const parts = packageJson.version.split(".");
|
|
29
|
+
const major = parts[0] ?? "0";
|
|
30
|
+
const minor = parts[1] ?? "0";
|
|
31
|
+
if (major === "0") {
|
|
32
|
+
return `0.${minor}`;
|
|
33
|
+
}
|
|
34
|
+
return major;
|
|
35
|
+
}
|
|
36
|
+
|
|
22
37
|
export function isVersionNewer(latest: string, current: string): boolean {
|
|
23
38
|
const parse = (v: string): [number, number, number] | null => {
|
|
24
39
|
const match = v.trim().match(/^(\d+)\.(\d+)\.(\d+)/);
|