@takara-ai/miru-code 0.4.4 → 0.4.5
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 +4 -3
- package/src/chunking/structural.ts +35 -1
- package/src/cli.ts +4 -5
- package/src/index/files.ts +4 -1
- package/src/utils.ts +5 -0
package/package.json
CHANGED
package/src/cache.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
2
|
import { rm } from "node:fs/promises";
|
|
3
|
-
import { join
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { computeSourceCacheKey } from "./utils.ts";
|
|
4
5
|
import { resolveEmbeddingDimensions, resolveEmbeddingModel } from "./embeddings/openai.ts";
|
|
5
6
|
import {
|
|
6
7
|
loadBm25,
|
|
@@ -30,8 +31,8 @@ export function resolveCacheFolder(): string {
|
|
|
30
31
|
return base;
|
|
31
32
|
}
|
|
32
33
|
|
|
33
|
-
export function findIndexCachePath(path: string): string {
|
|
34
|
-
const normalized =
|
|
34
|
+
export function findIndexCachePath(path: string, ref?: string | null): string {
|
|
35
|
+
const normalized = computeSourceCacheKey(path, ref);
|
|
35
36
|
const subdir = createHash("sha256").update(normalized, "utf-8").digest("hex");
|
|
36
37
|
return join(resolveCacheFolder(), subdir, "index");
|
|
37
38
|
}
|
|
@@ -5,7 +5,16 @@ import {
|
|
|
5
5
|
splitLinesKeepEnds,
|
|
6
6
|
} from "./lines.ts";
|
|
7
7
|
|
|
8
|
-
const SUPPORTED_STRUCTURAL_LANGUAGES = new Set([
|
|
8
|
+
const SUPPORTED_STRUCTURAL_LANGUAGES = new Set([
|
|
9
|
+
"python",
|
|
10
|
+
"go",
|
|
11
|
+
"typescript",
|
|
12
|
+
"javascript",
|
|
13
|
+
"cpp",
|
|
14
|
+
"c",
|
|
15
|
+
]);
|
|
16
|
+
|
|
17
|
+
const BRACE_FAMILY_LANGUAGES = new Set(["cpp", "c"]);
|
|
9
18
|
|
|
10
19
|
export function chunkStructural(
|
|
11
20
|
source: string,
|
|
@@ -164,9 +173,27 @@ function declPattern(language: string): RegExp {
|
|
|
164
173
|
if (language === "go") {
|
|
165
174
|
return /^\s*(func\b|type\b.*\b(struct|interface)\b)/;
|
|
166
175
|
}
|
|
176
|
+
if (language === "cpp") {
|
|
177
|
+
return /^\s*(?:(?:template\s*<[^>]*>\s*)?(?:class|struct|namespace|enum(?:\s+class)?)\b|(?!(?:if|for|while|switch|catch|return|sizeof|static_assert|else|do)\b)(?:[\w:~<>,*&]+\s+)+\w+\s*\([^;{}]*\)\s*(?:const)?\s*(?:override)?(?:\s*=\s*0)?)/;
|
|
178
|
+
}
|
|
179
|
+
if (language === "c") {
|
|
180
|
+
return /^\s*(?:struct|enum|union|typedef)\b|(?!(?:if|for|while|switch|return|sizeof|else|do)\b)(?:[\w:*\s]+\s+)+\w+\s*\([^;{}]*\)/;
|
|
181
|
+
}
|
|
167
182
|
return /^\s*(export\s+)?(async\s+function\b|function\b|class\b|interface\b|type\b|(?:const|let|var)\s+[A-Za-z_$][\w$]*\s*=\s*(?:async\s*)?(?:\([^)]*\)|[A-Za-z_$][\w$]*)(?:\s*:\s*[^=]+)?\s*=>)/;
|
|
168
183
|
}
|
|
169
184
|
|
|
185
|
+
function isBraceFamilyTypeDecl(text: string, language: string): boolean {
|
|
186
|
+
if (language === "cpp") {
|
|
187
|
+
return /^\s*(?:(?:template\s*<[^>]*>\s*)?(?:class|struct|namespace|enum(?:\s+class)?)\b)/.test(
|
|
188
|
+
text,
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
if (language === "c") {
|
|
192
|
+
return /^\s*(?:struct|enum|union)\b/.test(text);
|
|
193
|
+
}
|
|
194
|
+
return false;
|
|
195
|
+
}
|
|
196
|
+
|
|
170
197
|
function braceUnits(lines: LineGroup[], language: string): ChunkBoundary[] {
|
|
171
198
|
const units: ChunkBoundary[] = [];
|
|
172
199
|
const full = lines.map((l) => l.text).join("");
|
|
@@ -178,6 +205,13 @@ function braceUnits(lines: LineGroup[], language: string): ChunkBoundary[] {
|
|
|
178
205
|
if (!re.test(text)) {
|
|
179
206
|
continue;
|
|
180
207
|
}
|
|
208
|
+
if (
|
|
209
|
+
BRACE_FAMILY_LANGUAGES.has(language) &&
|
|
210
|
+
lineIndent(text) > 0 &&
|
|
211
|
+
!isBraceFamilyTypeDecl(text, language)
|
|
212
|
+
) {
|
|
213
|
+
continue;
|
|
214
|
+
}
|
|
181
215
|
if (firstDeclStart === null) {
|
|
182
216
|
firstDeclStart = lines[i]?.start;
|
|
183
217
|
}
|
package/src/cli.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
|
-
import { resolve } from "node:path";
|
|
3
2
|
import { type AgentId, writeAgentFile } from "./agents.ts";
|
|
4
3
|
import { clearCache } from "./cache.ts";
|
|
5
4
|
import {
|
|
@@ -27,7 +26,7 @@ import { MiruIndex } from "./miru-index.ts";
|
|
|
27
26
|
import { ensureCredentials, runClearCredentials, runSetup } from "./setup.ts";
|
|
28
27
|
import { withSpinner } from "./spinner.ts";
|
|
29
28
|
import type { ContentType, SearchResult } from "./types.ts";
|
|
30
|
-
import { formatResults, resolveChunk, resolveContent } from "./utils.ts";
|
|
29
|
+
import { formatResults, resolveChunk, resolveContent, resolveSearchPath } from "./utils.ts";
|
|
31
30
|
|
|
32
31
|
loadEnvFiles();
|
|
33
32
|
normalizeTakaraApiKeyEnv();
|
|
@@ -283,7 +282,7 @@ async function runCli(argv: string[]): Promise<void> {
|
|
|
283
282
|
}
|
|
284
283
|
|
|
285
284
|
if (command === "clear") {
|
|
286
|
-
const path =
|
|
285
|
+
const path = resolveSearchPath(rest[0] ?? process.cwd());
|
|
287
286
|
await runClear(path);
|
|
288
287
|
return;
|
|
289
288
|
}
|
|
@@ -298,7 +297,7 @@ async function runCli(argv: string[]): Promise<void> {
|
|
|
298
297
|
printCommandHelp("search");
|
|
299
298
|
process.exit(1);
|
|
300
299
|
}
|
|
301
|
-
const path =
|
|
300
|
+
const path = resolveSearchPath(sizedRest[1] ?? process.cwd());
|
|
302
301
|
await runSearch(path, query, topK, content, jsonFlag);
|
|
303
302
|
return;
|
|
304
303
|
}
|
|
@@ -311,7 +310,7 @@ async function runCli(argv: string[]): Promise<void> {
|
|
|
311
310
|
process.exit(1);
|
|
312
311
|
}
|
|
313
312
|
const line = Number(lineRaw);
|
|
314
|
-
const path =
|
|
313
|
+
const path = resolveSearchPath(sizedRest[2] ?? process.cwd());
|
|
315
314
|
try {
|
|
316
315
|
await runFindRelated(path, filePath, line, topK, content, jsonFlag);
|
|
317
316
|
} catch (err) {
|
package/src/index/files.ts
CHANGED
|
@@ -21,11 +21,14 @@ const EXTENSION_TO_LANGUAGE: Record<string, string> = {
|
|
|
21
21
|
".kt": "kotlin",
|
|
22
22
|
".kts": "kotlin",
|
|
23
23
|
".c": "c",
|
|
24
|
-
".h": "
|
|
24
|
+
".h": "cpp",
|
|
25
25
|
".cpp": "cpp",
|
|
26
26
|
".cc": "cpp",
|
|
27
27
|
".cxx": "cpp",
|
|
28
28
|
".hpp": "cpp",
|
|
29
|
+
".hh": "cpp",
|
|
30
|
+
".hxx": "cpp",
|
|
31
|
+
".h++": "cpp",
|
|
29
32
|
".cs": "csharp",
|
|
30
33
|
".rb": "ruby",
|
|
31
34
|
".php": "php",
|
package/src/utils.ts
CHANGED
|
@@ -62,3 +62,8 @@ export function computeSourceCacheKey(source: string, ref?: string | null): stri
|
|
|
62
62
|
}
|
|
63
63
|
return resolve(source);
|
|
64
64
|
}
|
|
65
|
+
|
|
66
|
+
/** Resolve a local search path; leave git URLs unchanged for remote indexing. */
|
|
67
|
+
export function resolveSearchPath(path: string): string {
|
|
68
|
+
return isGitUrl(path) ? path : resolve(path);
|
|
69
|
+
}
|