context-compress 1.0.0 → 2026.3.3
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/README.md +27 -1
- package/dist/executor.d.ts +1 -0
- package/dist/executor.d.ts.map +1 -1
- package/dist/executor.js +25 -11
- package/dist/executor.js.map +1 -1
- package/dist/server.bundle.mjs +77 -38
- package/dist/server.bundle.mjs.map +3 -3
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +57 -3
- package/dist/server.js.map +1 -1
- package/dist/snippet.d.ts.map +1 -1
- package/dist/snippet.js +1 -8
- package/dist/snippet.js.map +1 -1
- package/dist/stats.d.ts.map +1 -1
- package/dist/stats.js +1 -7
- package/dist/stats.js.map +1 -1
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +3 -12
- package/dist/store.js.map +1 -1
- package/docs/token-reduction-report.md +459 -0
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
|
|
12
12
|
A context-aware **MCP server** for [Claude Code](https://claude.ai/claude-code) that compresses tool output by processing it in isolated subprocesses. Raw data stays in the sandbox — only concise summaries enter your context window.
|
|
13
13
|
|
|
14
|
-
[Quickstart for Agents](#quickstart-for-agents) · [Getting Started](#getting-started) · [How It Works](#how-it-works) · [Configuration](#configuration) · [CLI](#cli) · [Changelog](CHANGELOG.md)
|
|
14
|
+
[Quickstart for Agents](#quickstart-for-agents) · [Getting Started](#getting-started) · [How It Works](#how-it-works) · [Token Reduction](#token-reduction) · [Configuration](#configuration) · [CLI](#cli) · [Changelog](CHANGELOG.md)
|
|
15
15
|
|
|
16
16
|
</div>
|
|
17
17
|
|
|
@@ -125,6 +125,32 @@ context-compress doctor
|
|
|
125
125
|
|
|
126
126
|
---
|
|
127
127
|
|
|
128
|
+
## Token Reduction
|
|
129
|
+
|
|
130
|
+
context-compress achieves **99.2% token reduction** across a typical 12-operation coding session.
|
|
131
|
+
|
|
132
|
+
| Operation | Before | After | Reduction |
|
|
133
|
+
|:--|--:|--:|--:|
|
|
134
|
+
| Read bundled file (776KB) | 194,076 tok | 105 tok | 99.9% |
|
|
135
|
+
| Playwright snapshot (56KB) | 14,000 tok | 75 tok | 99.5% |
|
|
136
|
+
| Read CSV/JSON data (100KB) | 25,000 tok | 125 tok | 99.5% |
|
|
137
|
+
| Read source file (21KB) | 5,250 tok | 88 tok | 98.3% |
|
|
138
|
+
| npm install log (15KB) | 3,750 tok | 50 tok | 98.7% |
|
|
139
|
+
| curl API response (12KB) | 3,000 tok | 88 tok | 97.1% |
|
|
140
|
+
| npm test (42 tests) | 935 tok | 45 tok | 95.2% |
|
|
141
|
+
| batch_execute (5 cmds) | 6,250 tok | 375 tok | 94.0% |
|
|
142
|
+
| fetch_and_index (45KB page) | 11,250 tok | 750 tok | 93.3% |
|
|
143
|
+
| grep (small output) | 361 tok | 361 tok | 0% |
|
|
144
|
+
| **Session Total** | **267,121 tok** | **2,223 tok** | **99.2%** |
|
|
145
|
+
|
|
146
|
+
Without context-compress, 12 operations consume **133% of the 200K context window** — overflowing it entirely. With context-compress, the same operations use **1.1%**, leaving 98.9% free for actual conversation.
|
|
147
|
+
|
|
148
|
+
> Data isn't deleted — it's indexed in FTS5 and searchable on demand. Small outputs (<5KB) pass through uncompressed.
|
|
149
|
+
|
|
150
|
+
**[Read the full Token Reduction Report](docs/token-reduction-report.md)** — includes cost analysis, architecture deep-dive, and FAQ on context loss trade-offs.
|
|
151
|
+
|
|
152
|
+
---
|
|
153
|
+
|
|
128
154
|
## What Changed from context-mode
|
|
129
155
|
|
|
130
156
|
| | context-mode | context-compress |
|
package/dist/executor.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Config } from "./config.js";
|
|
2
2
|
import type { RuntimeMap } from "./runtime/index.js";
|
|
3
3
|
import type { ExecFileOptions, ExecOptions, ExecResult } from "./types.js";
|
|
4
|
+
export declare function formatBytes(bytes: number): string;
|
|
4
5
|
export declare class SubprocessExecutor {
|
|
5
6
|
private runtimes;
|
|
6
7
|
private config;
|
package/dist/executor.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../src/executor.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAErD,OAAO,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,UAAU,EAAY,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../src/executor.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAErD,OAAO,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,UAAU,EAAY,MAAM,YAAY,CAAC;AAqHrF,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAIjD;AAED,qBAAa,kBAAkB;IAC9B,OAAO,CAAC,QAAQ,CAAa;IAC7B,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,GAAG,CAAyB;gBAExB,QAAQ,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM;IAMhD;;OAEG;IACG,OAAO,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC;IAyErD;;OAEG;IACG,WAAW,CAAC,IAAI,EAAE,eAAe,GAAG,OAAO,CAAC,UAAU,CAAC;IAsB7D,OAAO,CAAC,eAAe;IA8FvB,OAAO,CAAC,aAAa;IAMrB,OAAO,CAAC,cAAc;CAOtB"}
|
package/dist/executor.js
CHANGED
|
@@ -2,7 +2,7 @@ import { execFileSync, spawn } from "node:child_process";
|
|
|
2
2
|
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { tmpdir } from "node:os";
|
|
4
4
|
import { join } from "node:path";
|
|
5
|
-
import { debug
|
|
5
|
+
import { debug } from "./logger.js";
|
|
6
6
|
const DEFAULT_TIMEOUT = 30_000;
|
|
7
7
|
const DEFAULT_MAX_OUTPUT = 102_400;
|
|
8
8
|
const DEFAULT_HARD_CAP = 100 * 1024 * 1024;
|
|
@@ -106,10 +106,10 @@ function smartTruncate(output, maxBytes) {
|
|
|
106
106
|
const tailLines = lines.slice(tailStart);
|
|
107
107
|
const truncatedLines = lines.length - headEnd - (lines.length - tailStart);
|
|
108
108
|
const truncatedBytes = Buffer.byteLength(output) - headBytes - tailBytes;
|
|
109
|
-
const separator = `\n... [${truncatedLines} lines / ${
|
|
109
|
+
const separator = `\n... [${truncatedLines} lines / ${formatBytes(truncatedBytes)} truncated — showing first ${headEnd} + last ${lines.length - tailStart} lines] ...\n`;
|
|
110
110
|
return headLines.join("\n") + separator + tailLines.join("\n");
|
|
111
111
|
}
|
|
112
|
-
function
|
|
112
|
+
export function formatBytes(bytes) {
|
|
113
113
|
if (bytes < 1024)
|
|
114
114
|
return `${bytes}B`;
|
|
115
115
|
if (bytes < 1024 * 1024)
|
|
@@ -212,11 +212,12 @@ export class SubprocessExecutor {
|
|
|
212
212
|
spawnAndCapture(cmd, args, cwd, timeout, maxOutput, useShell) {
|
|
213
213
|
return new Promise((resolve) => {
|
|
214
214
|
const hardCap = this.config.hardCapBytes;
|
|
215
|
-
|
|
216
|
-
|
|
215
|
+
const stdoutChunks = [];
|
|
216
|
+
const stderrChunks = [];
|
|
217
217
|
let totalBytes = 0;
|
|
218
218
|
let killed = false;
|
|
219
219
|
let networkBytes;
|
|
220
|
+
let resolved = false;
|
|
220
221
|
const proc = spawn(cmd, args, {
|
|
221
222
|
cwd,
|
|
222
223
|
env: { ...this.env, TMPDIR: cwd },
|
|
@@ -233,7 +234,7 @@ export class SubprocessExecutor {
|
|
|
233
234
|
killProcessTree(proc.pid);
|
|
234
235
|
return;
|
|
235
236
|
}
|
|
236
|
-
|
|
237
|
+
stdoutChunks.push(chunk);
|
|
237
238
|
});
|
|
238
239
|
proc.stderr?.on("data", (chunk) => {
|
|
239
240
|
totalBytes += chunk.length;
|
|
@@ -243,14 +244,27 @@ export class SubprocessExecutor {
|
|
|
243
244
|
killProcessTree(proc.pid);
|
|
244
245
|
return;
|
|
245
246
|
}
|
|
246
|
-
|
|
247
|
+
stderrChunks.push(chunk);
|
|
247
248
|
});
|
|
248
249
|
proc.on("error", (err) => {
|
|
249
250
|
debug("Process error:", err.message);
|
|
251
|
+
if (!resolved) {
|
|
252
|
+
resolved = true;
|
|
253
|
+
resolve({
|
|
254
|
+
stdout: "",
|
|
255
|
+
stderr: err.message,
|
|
256
|
+
exitCode: 1,
|
|
257
|
+
truncated: false,
|
|
258
|
+
killed: false,
|
|
259
|
+
});
|
|
260
|
+
}
|
|
250
261
|
});
|
|
251
262
|
proc.on("close", (code) => {
|
|
252
|
-
|
|
253
|
-
|
|
263
|
+
if (resolved)
|
|
264
|
+
return;
|
|
265
|
+
resolved = true;
|
|
266
|
+
let stdout = Buffer.concat(stdoutChunks).toString("utf-8");
|
|
267
|
+
let stderr = Buffer.concat(stderrChunks).toString("utf-8");
|
|
254
268
|
// Extract network bytes from JS/TS stderr marker
|
|
255
269
|
const netMatch = stderr.match(/__CM_NET__:(\d+)/);
|
|
256
270
|
if (netMatch) {
|
|
@@ -258,7 +272,7 @@ export class SubprocessExecutor {
|
|
|
258
272
|
stderr = stderr.replace(/__CM_NET__:\d+\n?/, "");
|
|
259
273
|
}
|
|
260
274
|
if (killed) {
|
|
261
|
-
stdout += `\n[output capped at ${
|
|
275
|
+
stdout += `\n[output capped at ${formatBytes(hardCap)} — process killed]`;
|
|
262
276
|
}
|
|
263
277
|
const truncated = Buffer.byteLength(stdout) > maxOutput;
|
|
264
278
|
if (truncated) {
|
|
@@ -293,7 +307,7 @@ export class SubprocessExecutor {
|
|
|
293
307
|
* Wrap JS/TS code with fetch interceptor for network tracking.
|
|
294
308
|
*/
|
|
295
309
|
function wrapWithNetworkTracking(code) {
|
|
296
|
-
const preamble = "let __cm_net=0;const __cm_f=globalThis.fetch;if(__cm_f){globalThis.fetch=async(...a)=>{const r=await __cm_f(...a);try{const cl=r.
|
|
310
|
+
const preamble = "let __cm_net=0;const __cm_f=globalThis.fetch;if(__cm_f){globalThis.fetch=async(...a)=>{const r=await __cm_f(...a);try{const cl=r.headers.get('content-length');if(cl){__cm_net+=parseInt(cl,10)}else{const b=await r.clone().arrayBuffer();__cm_net+=b.byteLength}}catch{}return r};}";
|
|
297
311
|
const epilogue = `\nprocess.stderr.write('__CM_NET__:'+__cm_net+'\\n');`;
|
|
298
312
|
// Wrap in async IIFE
|
|
299
313
|
return `${preamble}\nasync function __cm_main(){${code}}\n__cm_main().then(()=>{${epilogue}}).catch(e=>{console.error(e);${epilogue}process.exit(1)});`;
|
package/dist/executor.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"executor.js","sourceRoot":"","sources":["../src/executor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxE,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"executor.js","sourceRoot":"","sources":["../src/executor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxE,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,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AAM,QAAQ,GAAG,uDAAuD,CAAC;IAEzE,qBAAqB;IACrB,OAAO,GAAG,QAAQ,gCAAgC,IAAI,4BAA4B,QAAQ,iCAAiC,QAAQ,oBAAoB,CAAC;AACzJ,CAAC"}
|
package/dist/server.bundle.mjs
CHANGED
|
@@ -6818,9 +6818,9 @@ var DEFAULTS = {
|
|
|
6818
6818
|
searchReduceAfter: 3,
|
|
6819
6819
|
searchBlockAfter: 8
|
|
6820
6820
|
};
|
|
6821
|
-
function loadFileConfig(
|
|
6821
|
+
function loadFileConfig(projectDir2) {
|
|
6822
6822
|
const paths = [
|
|
6823
|
-
|
|
6823
|
+
projectDir2 && join(projectDir2, ".context-compress.json"),
|
|
6824
6824
|
join(process.env.HOME ?? "~", ".context-compress.json")
|
|
6825
6825
|
].filter(Boolean);
|
|
6826
6826
|
for (const p of paths) {
|
|
@@ -6855,9 +6855,9 @@ function loadEnvConfig() {
|
|
|
6855
6855
|
return partial2;
|
|
6856
6856
|
}
|
|
6857
6857
|
var _config = null;
|
|
6858
|
-
function loadConfig(
|
|
6858
|
+
function loadConfig(projectDir2) {
|
|
6859
6859
|
if (_config) return _config;
|
|
6860
|
-
const fileConfig = loadFileConfig(
|
|
6860
|
+
const fileConfig = loadFileConfig(projectDir2);
|
|
6861
6861
|
const envConfig = loadEnvConfig();
|
|
6862
6862
|
_config = { ...DEFAULTS, ...fileConfig, ...envConfig };
|
|
6863
6863
|
return _config;
|
|
@@ -21153,11 +21153,11 @@ function smartTruncate(output, maxBytes) {
|
|
|
21153
21153
|
const truncatedLines = lines.length - headEnd - (lines.length - tailStart);
|
|
21154
21154
|
const truncatedBytes = Buffer.byteLength(output) - headBytes - tailBytes;
|
|
21155
21155
|
const separator = `
|
|
21156
|
-
... [${truncatedLines} lines / ${
|
|
21156
|
+
... [${truncatedLines} lines / ${formatBytes(truncatedBytes)} truncated \u2014 showing first ${headEnd} + last ${lines.length - tailStart} lines] ...
|
|
21157
21157
|
`;
|
|
21158
21158
|
return headLines.join("\n") + separator + tailLines.join("\n");
|
|
21159
21159
|
}
|
|
21160
|
-
function
|
|
21160
|
+
function formatBytes(bytes) {
|
|
21161
21161
|
if (bytes < 1024) return `${bytes}B`;
|
|
21162
21162
|
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)}KB`;
|
|
21163
21163
|
return `${(bytes / (1024 * 1024)).toFixed(1)}MB`;
|
|
@@ -21258,11 +21258,12 @@ var SubprocessExecutor = class {
|
|
|
21258
21258
|
spawnAndCapture(cmd, args, cwd, timeout, maxOutput, useShell) {
|
|
21259
21259
|
return new Promise((resolve2) => {
|
|
21260
21260
|
const hardCap = this.config.hardCapBytes;
|
|
21261
|
-
|
|
21262
|
-
|
|
21261
|
+
const stdoutChunks = [];
|
|
21262
|
+
const stderrChunks = [];
|
|
21263
21263
|
let totalBytes = 0;
|
|
21264
21264
|
let killed = false;
|
|
21265
21265
|
let networkBytes;
|
|
21266
|
+
let resolved = false;
|
|
21266
21267
|
const proc = spawn(cmd, args, {
|
|
21267
21268
|
cwd,
|
|
21268
21269
|
env: { ...this.env, TMPDIR: cwd },
|
|
@@ -21278,7 +21279,7 @@ var SubprocessExecutor = class {
|
|
|
21278
21279
|
if (proc.pid) killProcessTree(proc.pid);
|
|
21279
21280
|
return;
|
|
21280
21281
|
}
|
|
21281
|
-
|
|
21282
|
+
stdoutChunks.push(chunk);
|
|
21282
21283
|
});
|
|
21283
21284
|
proc.stderr?.on("data", (chunk) => {
|
|
21284
21285
|
totalBytes += chunk.length;
|
|
@@ -21287,14 +21288,26 @@ var SubprocessExecutor = class {
|
|
|
21287
21288
|
if (proc.pid) killProcessTree(proc.pid);
|
|
21288
21289
|
return;
|
|
21289
21290
|
}
|
|
21290
|
-
|
|
21291
|
+
stderrChunks.push(chunk);
|
|
21291
21292
|
});
|
|
21292
21293
|
proc.on("error", (err) => {
|
|
21293
21294
|
debug("Process error:", err.message);
|
|
21295
|
+
if (!resolved) {
|
|
21296
|
+
resolved = true;
|
|
21297
|
+
resolve2({
|
|
21298
|
+
stdout: "",
|
|
21299
|
+
stderr: err.message,
|
|
21300
|
+
exitCode: 1,
|
|
21301
|
+
truncated: false,
|
|
21302
|
+
killed: false
|
|
21303
|
+
});
|
|
21304
|
+
}
|
|
21294
21305
|
});
|
|
21295
21306
|
proc.on("close", (code) => {
|
|
21296
|
-
|
|
21297
|
-
|
|
21307
|
+
if (resolved) return;
|
|
21308
|
+
resolved = true;
|
|
21309
|
+
let stdout = Buffer.concat(stdoutChunks).toString("utf-8");
|
|
21310
|
+
let stderr = Buffer.concat(stderrChunks).toString("utf-8");
|
|
21298
21311
|
const netMatch = stderr.match(/__CM_NET__:(\d+)/);
|
|
21299
21312
|
if (netMatch) {
|
|
21300
21313
|
networkBytes = Number.parseInt(netMatch[1], 10);
|
|
@@ -21302,7 +21315,7 @@ var SubprocessExecutor = class {
|
|
|
21302
21315
|
}
|
|
21303
21316
|
if (killed) {
|
|
21304
21317
|
stdout += `
|
|
21305
|
-
[output capped at ${
|
|
21318
|
+
[output capped at ${formatBytes(hardCap)} \u2014 process killed]`;
|
|
21306
21319
|
}
|
|
21307
21320
|
const truncated = Buffer.byteLength(stdout) > maxOutput;
|
|
21308
21321
|
if (truncated) {
|
|
@@ -21333,7 +21346,7 @@ var SubprocessExecutor = class {
|
|
|
21333
21346
|
}
|
|
21334
21347
|
};
|
|
21335
21348
|
function wrapWithNetworkTracking(code) {
|
|
21336
|
-
const preamble = "let __cm_net=0;const __cm_f=globalThis.fetch;if(__cm_f){globalThis.fetch=async(...a)=>{const r=await __cm_f(...a);try{const cl=r.
|
|
21349
|
+
const preamble = "let __cm_net=0;const __cm_f=globalThis.fetch;if(__cm_f){globalThis.fetch=async(...a)=>{const r=await __cm_f(...a);try{const cl=r.headers.get('content-length');if(cl){__cm_net+=parseInt(cl,10)}else{const b=await r.clone().arrayBuffer();__cm_net+=b.byteLength}}catch{}return r};}";
|
|
21337
21350
|
const epilogue = `
|
|
21338
21351
|
process.stderr.write('__CM_NET__:'+__cm_net+'\\n');`;
|
|
21339
21352
|
return `${preamble}
|
|
@@ -21719,11 +21732,6 @@ Context-compress kept ${formatBytes(keptOut)} out of context (${reductionPct}% s
|
|
|
21719
21732
|
return lines.join("\n");
|
|
21720
21733
|
}
|
|
21721
21734
|
};
|
|
21722
|
-
function formatBytes(bytes) {
|
|
21723
|
-
if (bytes < 1024) return `${bytes}B`;
|
|
21724
|
-
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)}KB`;
|
|
21725
|
-
return `${(bytes / (1024 * 1024)).toFixed(1)}MB`;
|
|
21726
|
-
}
|
|
21727
21735
|
|
|
21728
21736
|
// src/store.ts
|
|
21729
21737
|
import { readdirSync, unlinkSync } from "node:fs";
|
|
@@ -21754,14 +21762,7 @@ function positionsFromHighlight(highlighted) {
|
|
|
21754
21762
|
return positions;
|
|
21755
21763
|
}
|
|
21756
21764
|
function stripMarkers(text) {
|
|
21757
|
-
|
|
21758
|
-
for (let i = 0; i < text.length; i++) {
|
|
21759
|
-
const ch = text[i];
|
|
21760
|
-
if (ch !== STX && ch !== ETX) {
|
|
21761
|
-
result += ch;
|
|
21762
|
-
}
|
|
21763
|
-
}
|
|
21764
|
-
return result;
|
|
21765
|
+
return text.replaceAll(STX, "").replaceAll(ETX, "");
|
|
21765
21766
|
}
|
|
21766
21767
|
function extractSnippet(highlighted, maxLen = DEFAULT_MAX_LEN) {
|
|
21767
21768
|
const positions = positionsFromHighlight(highlighted);
|
|
@@ -21979,16 +21980,9 @@ var ContentStore = class {
|
|
|
21979
21980
|
tokenize='trigram'
|
|
21980
21981
|
);
|
|
21981
21982
|
`);
|
|
21982
|
-
|
|
21983
|
-
|
|
21984
|
-
"INSERT INTO chunks_trigram (title, content, source_id, content_type) VALUES (?, ?, ?, ?)"
|
|
21983
|
+
this.db.exec(
|
|
21984
|
+
"INSERT INTO chunks_trigram (title, content, source_id, content_type) SELECT title, content, source_id, content_type FROM chunks"
|
|
21985
21985
|
);
|
|
21986
|
-
const tx = this.db.transaction(() => {
|
|
21987
|
-
for (const row of rows) {
|
|
21988
|
-
insert.run(row.title, row.content, row.source_id, row.content_type);
|
|
21989
|
-
}
|
|
21990
|
-
});
|
|
21991
|
-
tx();
|
|
21992
21986
|
this.hasTrigramTable = true;
|
|
21993
21987
|
}
|
|
21994
21988
|
/**
|
|
@@ -22333,6 +22327,11 @@ var LANGUAGES = [
|
|
|
22333
22327
|
"r",
|
|
22334
22328
|
"elixir"
|
|
22335
22329
|
];
|
|
22330
|
+
var projectDir = process.env.CLAUDE_PROJECT_DIR ?? process.cwd();
|
|
22331
|
+
function isWithinProject(absPath) {
|
|
22332
|
+
const normalized = resolve(absPath);
|
|
22333
|
+
return normalized === projectDir || normalized.startsWith(`${projectDir}/`);
|
|
22334
|
+
}
|
|
22336
22335
|
function getVersion() {
|
|
22337
22336
|
try {
|
|
22338
22337
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
@@ -22425,7 +22424,17 @@ Searchable terms: ${terms.join(", ")}
|
|
|
22425
22424
|
timeout: external_exports.number().default(3e4).describe("Max execution time in ms")
|
|
22426
22425
|
},
|
|
22427
22426
|
async ({ path: filePath, language, code, intent, timeout }) => {
|
|
22428
|
-
const absPath = resolve(
|
|
22427
|
+
const absPath = resolve(projectDir, filePath);
|
|
22428
|
+
if (!isWithinProject(absPath)) {
|
|
22429
|
+
return {
|
|
22430
|
+
content: [
|
|
22431
|
+
{
|
|
22432
|
+
type: "text",
|
|
22433
|
+
text: `Error: path "${filePath}" is outside the project directory`
|
|
22434
|
+
}
|
|
22435
|
+
]
|
|
22436
|
+
};
|
|
22437
|
+
}
|
|
22429
22438
|
const result = await executor.executeFile({
|
|
22430
22439
|
language,
|
|
22431
22440
|
code,
|
|
@@ -22478,7 +22487,17 @@ Searchable terms: ${terms.join(", ")}
|
|
|
22478
22487
|
let text;
|
|
22479
22488
|
let label = source ?? "indexed content";
|
|
22480
22489
|
if (filePath) {
|
|
22481
|
-
const absPath = resolve(
|
|
22490
|
+
const absPath = resolve(projectDir, filePath);
|
|
22491
|
+
if (!isWithinProject(absPath)) {
|
|
22492
|
+
return {
|
|
22493
|
+
content: [
|
|
22494
|
+
{
|
|
22495
|
+
type: "text",
|
|
22496
|
+
text: `Error: path "${filePath}" is outside the project directory`
|
|
22497
|
+
}
|
|
22498
|
+
]
|
|
22499
|
+
};
|
|
22500
|
+
}
|
|
22482
22501
|
text = readFileSync2(absPath, "utf-8");
|
|
22483
22502
|
label = source ?? filePath;
|
|
22484
22503
|
} else if (content) {
|
|
@@ -22561,6 +22580,26 @@ ${hit.snippet}
|
|
|
22561
22580
|
source: external_exports.string().optional().describe("Label for the indexed content")
|
|
22562
22581
|
},
|
|
22563
22582
|
async ({ url, source }) => {
|
|
22583
|
+
try {
|
|
22584
|
+
const parsed = new URL(url);
|
|
22585
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
|
|
22586
|
+
return {
|
|
22587
|
+
content: [{ type: "text", text: "Error: only http/https URLs are allowed" }]
|
|
22588
|
+
};
|
|
22589
|
+
}
|
|
22590
|
+
const hostname2 = parsed.hostname;
|
|
22591
|
+
if (hostname2 === "localhost" || hostname2 === "127.0.0.1" || hostname2 === "::1" || hostname2 === "0.0.0.0" || hostname2.startsWith("10.") || hostname2.startsWith("172.16.") || hostname2.startsWith("192.168.") || hostname2.startsWith("169.254.")) {
|
|
22592
|
+
return {
|
|
22593
|
+
content: [
|
|
22594
|
+
{ type: "text", text: "Error: internal/private URLs are not allowed" }
|
|
22595
|
+
]
|
|
22596
|
+
};
|
|
22597
|
+
}
|
|
22598
|
+
} catch {
|
|
22599
|
+
return {
|
|
22600
|
+
content: [{ type: "text", text: `Error: invalid URL "${url}"` }]
|
|
22601
|
+
};
|
|
22602
|
+
}
|
|
22564
22603
|
const label = source ?? url;
|
|
22565
22604
|
const fetchCode = buildFetchCode(url);
|
|
22566
22605
|
const result = await executor.execute({
|