brain-cache 0.3.4 → 0.3.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.
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
|
-
assembleContext
|
|
3
|
+
assembleContext,
|
|
4
|
+
countChunkTokens
|
|
4
5
|
} from "./chunk-5FXXZBZV.js";
|
|
5
6
|
import {
|
|
6
7
|
RETRIEVAL_STRATEGIES,
|
|
@@ -26,6 +27,7 @@ import {
|
|
|
26
27
|
} from "./chunk-3SFDFUEX.js";
|
|
27
28
|
|
|
28
29
|
// src/workflows/buildContext.ts
|
|
30
|
+
import { readFile } from "fs/promises";
|
|
29
31
|
import { resolve } from "path";
|
|
30
32
|
async function runBuildContext(query, opts) {
|
|
31
33
|
const profile = await readProfile();
|
|
@@ -62,8 +64,20 @@ async function runBuildContext(query, opts) {
|
|
|
62
64
|
const results = await searchChunks(table, queryVector, strategy);
|
|
63
65
|
const deduped = deduplicateChunks(results);
|
|
64
66
|
const assembled = assembleContext(deduped, { maxTokens });
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
+
const uniqueFiles = [...new Set(assembled.chunks.map((c) => c.filePath))];
|
|
68
|
+
let estimatedWithoutBraincache = 0;
|
|
69
|
+
for (const filePath of uniqueFiles) {
|
|
70
|
+
try {
|
|
71
|
+
const fileContent = await readFile(filePath, "utf-8");
|
|
72
|
+
estimatedWithoutBraincache += countChunkTokens(fileContent);
|
|
73
|
+
} catch {
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
const rawChunkTokens = assembled.chunks.reduce(
|
|
77
|
+
(sum, c) => sum + countChunkTokens(c.content),
|
|
78
|
+
0
|
|
79
|
+
);
|
|
80
|
+
const reductionPct = estimatedWithoutBraincache > 0 ? Math.round((1 - rawChunkTokens / estimatedWithoutBraincache) * 100) : 0;
|
|
67
81
|
const result = {
|
|
68
82
|
content: assembled.content,
|
|
69
83
|
chunks: assembled.chunks,
|
package/dist/cli.js
CHANGED
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
|
|
6
6
|
// src/cli/index.ts
|
|
7
7
|
import { Command } from "commander";
|
|
8
|
-
var version = "0.3.
|
|
8
|
+
var version = "0.3.5";
|
|
9
9
|
var program = new Command();
|
|
10
10
|
program.name("brain-cache").description("Local AI runtime \u2014 GPU cache layer for Claude").version(version);
|
|
11
11
|
program.command("init").description("Detect hardware, pull embedding model, create config directory").action(async () => {
|
|
@@ -35,7 +35,7 @@ program.command("status").description(
|
|
|
35
35
|
});
|
|
36
36
|
program.command("context").description("Build token-budgeted context from codebase for a query").argument("<query>", "Natural language query string").option("-n, --limit <n>", "Maximum number of search results", "10").option("-b, --budget <tokens>", "Token budget for assembled context", "4096").option("-p, --path <path>", "Project root directory").option("--raw", "Output raw JSON (MCP transport compatible)").action(
|
|
37
37
|
async (query, opts) => {
|
|
38
|
-
const { runBuildContext } = await import("./buildContext-
|
|
38
|
+
const { runBuildContext } = await import("./buildContext-IND6F67G.js");
|
|
39
39
|
const result = await runBuildContext(query, {
|
|
40
40
|
limit: parseInt(opts.limit, 10),
|
|
41
41
|
maxTokens: parseInt(opts.budget, 10),
|
|
@@ -61,7 +61,7 @@ ${formatTokenSavings({ tokensSent: result.metadata.tokensSent, estimatedWithout,
|
|
|
61
61
|
program.command("ask").description(
|
|
62
62
|
"Ask a natural language question about the codebase \u2014 retrieves context locally, reasons via Claude"
|
|
63
63
|
).argument("<question>", "Natural language question about the codebase").option("-b, --budget <tokens>", "Token budget for context retrieval", "4096").option("-p, --path <path>", "Project root directory").action(async (question, opts) => {
|
|
64
|
-
const { runAskCodebase } = await import("./askCodebase-
|
|
64
|
+
const { runAskCodebase } = await import("./askCodebase-NYPWHDEZ.js");
|
|
65
65
|
const result = await runAskCodebase(question, {
|
|
66
66
|
path: opts.path,
|
|
67
67
|
maxContextTokens: parseInt(opts.budget, 10)
|
package/dist/mcp.js
CHANGED
|
@@ -1087,6 +1087,7 @@ async function runSearch(query, opts) {
|
|
|
1087
1087
|
}
|
|
1088
1088
|
|
|
1089
1089
|
// src/workflows/buildContext.ts
|
|
1090
|
+
import { readFile as readFile5 } from "fs/promises";
|
|
1090
1091
|
import { resolve as resolve3 } from "path";
|
|
1091
1092
|
async function runBuildContext(query, opts) {
|
|
1092
1093
|
const profile = await readProfile();
|
|
@@ -1123,8 +1124,20 @@ async function runBuildContext(query, opts) {
|
|
|
1123
1124
|
const results = await searchChunks(table, queryVector, strategy);
|
|
1124
1125
|
const deduped = deduplicateChunks(results);
|
|
1125
1126
|
const assembled = assembleContext(deduped, { maxTokens });
|
|
1126
|
-
const
|
|
1127
|
-
|
|
1127
|
+
const uniqueFiles = [...new Set(assembled.chunks.map((c) => c.filePath))];
|
|
1128
|
+
let estimatedWithoutBraincache = 0;
|
|
1129
|
+
for (const filePath of uniqueFiles) {
|
|
1130
|
+
try {
|
|
1131
|
+
const fileContent = await readFile5(filePath, "utf-8");
|
|
1132
|
+
estimatedWithoutBraincache += countChunkTokens(fileContent);
|
|
1133
|
+
} catch {
|
|
1134
|
+
}
|
|
1135
|
+
}
|
|
1136
|
+
const rawChunkTokens = assembled.chunks.reduce(
|
|
1137
|
+
(sum, c) => sum + countChunkTokens(c.content),
|
|
1138
|
+
0
|
|
1139
|
+
);
|
|
1140
|
+
const reductionPct = estimatedWithoutBraincache > 0 ? Math.round((1 - rawChunkTokens / estimatedWithoutBraincache) * 100) : 0;
|
|
1128
1141
|
const result = {
|
|
1129
1142
|
content: assembled.content,
|
|
1130
1143
|
chunks: assembled.chunks,
|
|
@@ -1144,7 +1157,7 @@ async function runBuildContext(query, opts) {
|
|
|
1144
1157
|
}
|
|
1145
1158
|
|
|
1146
1159
|
// src/mcp/index.ts
|
|
1147
|
-
var version = "0.3.
|
|
1160
|
+
var version = "0.3.5";
|
|
1148
1161
|
var log9 = childLogger("mcp");
|
|
1149
1162
|
var server = new McpServer({ name: "brain-cache", version });
|
|
1150
1163
|
server.registerTool(
|
package/package.json
CHANGED