ctxloom-pro 1.0.28 → 1.0.31

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.
@@ -145,10 +145,12 @@ function collectFiles(dir, results = []) {
145
145
  }
146
146
  return results;
147
147
  }
148
+ var MIN_MODEL_BYTES;
148
149
  var init_embedder = __esm({
149
150
  "../../packages/core/src/indexer/embedder.ts"() {
150
151
  "use strict";
151
152
  init_logger();
153
+ MIN_MODEL_BYTES = 80 * 1024 * 1024;
152
154
  }
153
155
  });
154
156
 
@@ -33,6 +33,7 @@
33
33
  "@types/supertest": "^6.0.0",
34
34
  "@vitejs/plugin-react": "^4.3.0",
35
35
  "autoprefixer": "^10.4.0",
36
+ "clsx": "^2.1.1",
36
37
  "d3": "^7.9.0",
37
38
  "jsdom": "^24.0.0",
38
39
  "postcss": "^8.4.0",
@@ -0,0 +1,85 @@
1
+ #!/usr/bin/env node
2
+ /* eslint-disable @typescript-eslint/no-var-requires */
3
+ 'use strict';
4
+
5
+ /**
6
+ * ctxloom — CJS bootstrap that bumps the file-descriptor soft limit
7
+ * before loading the ESM entry point.
8
+ *
9
+ * Why this exists
10
+ * ───────────────
11
+ * Node.js does not expose `setrlimit(2)` natively, so we cannot raise
12
+ * RLIMIT_NOFILE from inside the JS runtime. macOS's launchctl default
13
+ * is `maxfiles = 256` (soft) / `unlimited` (hard), and every child
14
+ * process spawned by Claude.app / VS Code inherits that 256 soft cap.
15
+ *
16
+ * During a long-lived MCP session the cap is exhausted within ~20 tool
17
+ * calls — LanceDB keeps SSTable file handles open across queries, the
18
+ * ONNX runtime holds the model.onnx mmap, tree-sitter holds each WASM
19
+ * grammar, and the ~80 source files indexed at boot each leave a
20
+ * residual handle. The result is an EMFILE cascade that breaks every
21
+ * subsequent tool, including plain `fs.readFile`.
22
+ *
23
+ * Strategy
24
+ * ────────
25
+ * Re-exec ourselves through `/bin/sh -c "ulimit -n 65536; exec node …"`,
26
+ * gated by an env var to prevent an exec loop. On the second pass the
27
+ * raised limit is in place and we dynamic-import the real ESM entry.
28
+ *
29
+ * Windows is unaffected (the FD limit is much higher there, and `sh`
30
+ * is unavailable), so we skip the bump and load directly.
31
+ *
32
+ * Safe to call when the limit is already higher than our target — the
33
+ * second `ulimit` invocation is a no-op when the value is already at
34
+ * or above 65536.
35
+ */
36
+
37
+ const path = require('node:path');
38
+
39
+ const FD_LIMIT_TARGET = 65536;
40
+ const SENTINEL_ENV = 'CTXLOOM_FD_BUMPED';
41
+ const ENTRY = path.join(__dirname, '..', 'dist', 'index.js');
42
+
43
+ function shellQuote(arg) {
44
+ // POSIX-safe single-quote escape: a' becomes 'a'\'''.
45
+ return `'${String(arg).replace(/'/g, "'\\''")}'`;
46
+ }
47
+
48
+ function shouldBump() {
49
+ if (process.env[SENTINEL_ENV] === '1') return false;
50
+ if (process.platform === 'win32') return false;
51
+ // Allow opt-out for unusual environments (e.g. setuid wrappers, CI
52
+ // runners that already manage rlimit themselves).
53
+ if (process.env['CTXLOOM_SKIP_FD_BUMP'] === '1') return false;
54
+ return true;
55
+ }
56
+
57
+ if (shouldBump()) {
58
+ const { spawnSync } = require('node:child_process');
59
+ const quotedExec = shellQuote(process.execPath);
60
+ // process.argv[0] is the node path; argv[1] is THIS script; argv[2…] are
61
+ // the user's args. We want to re-exec node against the same script with
62
+ // the same user args, so we keep argv[1…] intact.
63
+ const quotedArgs = process.argv.slice(1).map(shellQuote).join(' ');
64
+ const cmd =
65
+ `ulimit -n ${FD_LIMIT_TARGET} 2>/dev/null; ` +
66
+ `${SENTINEL_ENV}=1 exec ${quotedExec} ${quotedArgs}`;
67
+ const result = spawnSync('/bin/sh', ['-c', cmd], { stdio: 'inherit' });
68
+ // spawnSync sets `status` on normal exit and `signal` on signal exit.
69
+ if (result.signal) {
70
+ process.kill(process.pid, result.signal);
71
+ // Fallback in case the signal is non-terminating in this context.
72
+ process.exit(1);
73
+ }
74
+ process.exit(result.status == null ? 1 : result.status);
75
+ }
76
+
77
+ // On the second pass (or on Windows) load the real ESM entry.
78
+ import(ENTRY).catch((err) => {
79
+ // Surface errors clearly — without this the user sees an unhandled
80
+ // promise rejection with no stack trace pointing back to the wrapper.
81
+ process.stderr.write(
82
+ `ctxloom: failed to load entry ${ENTRY}\n${err && err.stack ? err.stack : err}\n`,
83
+ );
84
+ process.exit(1);
85
+ });
@@ -9,6 +9,7 @@ import path from "path";
9
9
  var EMBEDDING_DIMENSION = 384;
10
10
  var MODEL_ID = "sentence-transformers/all-MiniLM-L6-v2";
11
11
  var CHUNK_SIZE = 4096;
12
+ var MIN_MODEL_BYTES = 80 * 1024 * 1024;
12
13
  var embedder = null;
13
14
  var embedderInitInFlight = null;
14
15
  async function loadEmbedder() {
@@ -16,6 +17,29 @@ async function loadEmbedder() {
16
17
  dtype: "fp32"
17
18
  });
18
19
  }
20
+ function extractModelPathFromProtobufError(message) {
21
+ const match = /Load model from (.+) failed:Protobuf parsing failed/i.exec(message);
22
+ return match ? match[1] : null;
23
+ }
24
+ function tryRemoveTruncatedModel(modelPath) {
25
+ try {
26
+ const stat = fs.statSync(modelPath);
27
+ if (stat.size >= MIN_MODEL_BYTES) return false;
28
+ fs.unlinkSync(modelPath);
29
+ logger.warn("Removed truncated embedding model; next attempt will re-download", {
30
+ path: modelPath,
31
+ sizeBytes: stat.size,
32
+ minBytes: MIN_MODEL_BYTES
33
+ });
34
+ return true;
35
+ } catch (err) {
36
+ logger.warn("Could not inspect/remove suspected truncated model", {
37
+ path: modelPath,
38
+ detail: err instanceof Error ? err.message : String(err)
39
+ });
40
+ return false;
41
+ }
42
+ }
19
43
  async function getEmbedder() {
20
44
  if (embedder) return embedder;
21
45
  if (embedderInitInFlight) return embedderInitInFlight;
@@ -32,6 +56,13 @@ async function getEmbedder() {
32
56
  const msg = err instanceof Error ? err.message : String(err);
33
57
  const isProtobufRace = /protobuf parsing failed/i.test(msg);
34
58
  if (!isProtobufRace || attempt === MAX_ATTEMPTS) break;
59
+ const modelPath = extractModelPathFromProtobufError(msg);
60
+ if (modelPath && tryRemoveTruncatedModel(modelPath)) {
61
+ logger.warn("Retrying embedding model load after truncated-cache removal", {
62
+ attempt
63
+ });
64
+ continue;
65
+ }
35
66
  const delay = attempt * 1e3;
36
67
  logger.warn("Embedding model load failed; retrying after FS settle", {
37
68
  attempt,
@@ -180,4 +211,4 @@ export {
180
211
  collectFiles,
181
212
  indexDirectory
182
213
  };
183
- //# sourceMappingURL=chunk-NYBVAPM3.js.map
214
+ //# sourceMappingURL=chunk-VR6PNQYH.js.map
@@ -4,7 +4,7 @@ import {
4
4
  import {
5
5
  collectFiles,
6
6
  generateEmbedding
7
- } from "./chunk-NYBVAPM3.js";
7
+ } from "./chunk-VR6PNQYH.js";
8
8
  import {
9
9
  logger
10
10
  } from "./chunk-TYDMSHV7.js";
@@ -6637,7 +6637,7 @@ function registerFullTextSearchTool(registry, ctx) {
6637
6637
  const { query, mode, case_sensitive, limit, context_lines } = Schema22.parse(args);
6638
6638
  if (mode === "semantic") {
6639
6639
  try {
6640
- const { generateEmbedding: generateEmbedding2 } = await import("./embedder-ZGEKFHHK.js");
6640
+ const { generateEmbedding: generateEmbedding2 } = await import("./embedder-MPDEA6P7.js");
6641
6641
  const store = await ctx.getStore();
6642
6642
  const embedding = await generateEmbedding2(query);
6643
6643
  const results = await store.search(embedding, limit);
@@ -6674,7 +6674,7 @@ function registerFullTextSearchTool(registry, ctx) {
6674
6674
  let merged = keywordResults.slice(0, limit);
6675
6675
  if (mode === "hybrid") {
6676
6676
  try {
6677
- const { generateEmbedding: generateEmbedding2 } = await import("./embedder-ZGEKFHHK.js");
6677
+ const { generateEmbedding: generateEmbedding2 } = await import("./embedder-MPDEA6P7.js");
6678
6678
  const store = await ctx.getStore();
6679
6679
  const embedding = await generateEmbedding2(query);
6680
6680
  const vectorResults = await store.search(embedding, Math.ceil(limit / 2));
@@ -8795,4 +8795,4 @@ export {
8795
8795
  track,
8796
8796
  captureError
8797
8797
  };
8798
- //# sourceMappingURL=chunk-3AF7Z7DD.js.map
8798
+ //# sourceMappingURL=chunk-WQMLQTFY.js.map
@@ -3,7 +3,7 @@ import {
3
3
  collectFiles,
4
4
  generateEmbedding,
5
5
  indexDirectory
6
- } from "./chunk-NYBVAPM3.js";
6
+ } from "./chunk-VR6PNQYH.js";
7
7
  import "./chunk-TYDMSHV7.js";
8
8
  export {
9
9
  EMBEDDING_DIMENSION,
@@ -11,4 +11,4 @@ export {
11
11
  generateEmbedding,
12
12
  indexDirectory
13
13
  };
14
- //# sourceMappingURL=embedder-ZGEKFHHK.js.map
14
+ //# sourceMappingURL=embedder-MPDEA6P7.js.map
package/dist/index.js CHANGED
@@ -34,14 +34,14 @@ import {
34
34
  startTrial,
35
35
  track,
36
36
  writeCODEOWNERS
37
- } from "./chunk-3AF7Z7DD.js";
37
+ } from "./chunk-WQMLQTFY.js";
38
38
  import {
39
39
  VectorStore
40
40
  } from "./chunk-NEHYSE2Y.js";
41
41
  import {
42
42
  generateEmbedding,
43
43
  indexDirectory
44
- } from "./chunk-NYBVAPM3.js";
44
+ } from "./chunk-VR6PNQYH.js";
45
45
  import {
46
46
  logger
47
47
  } from "./chunk-TYDMSHV7.js";
@@ -160,6 +160,22 @@ async function startServer(opts = {}) {
160
160
  await server.connect(transport);
161
161
  logger.info("MCP Server started on Stdio transport");
162
162
  logger.info("Project root", { root: PROJECT_ROOT });
163
+ try {
164
+ const { execSync: execSync2 } = await import("child_process");
165
+ const nofileSoft = Number(execSync2("ulimit -n", { shell: "/bin/sh" }).toString().trim());
166
+ if (Number.isFinite(nofileSoft)) {
167
+ const FD_WARN_THRESHOLD = 4096;
168
+ if (nofileSoft < FD_WARN_THRESHOLD) {
169
+ logger.warn(
170
+ "Low file-descriptor soft limit \u2014 EMFILE likely after ~20 tool calls. Run via `bin/ctxloom.cjs` (default bin) which bumps to 65536, or set `ulimit -n 65536` in your shell before launching.",
171
+ { nofileSoft, threshold: FD_WARN_THRESHOLD }
172
+ );
173
+ } else {
174
+ logger.info("FD soft limit", { nofileSoft });
175
+ }
176
+ }
177
+ } catch {
178
+ }
163
179
  Promise.all([ctx.getGraph(), generateEmbedding("warmup")]).then(async ([graph]) => {
164
180
  logger.info("Ready", { edges: graph.edgeCount() });
165
181
  if (withGit2) {
@@ -616,7 +632,7 @@ try {
616
632
  } catch {
617
633
  }
618
634
  var args = process.argv.slice(2);
619
- var ctxloomVersion = "1.0.28".length > 0 ? "1.0.28" : "dev";
635
+ var ctxloomVersion = "1.0.31".length > 0 ? "1.0.31" : "dev";
620
636
  if (args.includes("--version") || args.includes("-v")) {
621
637
  process.stdout.write(`ctxloom ${ctxloomVersion}
622
638
  `);
@@ -689,7 +705,7 @@ async function checkLicense() {
689
705
  if (command !== void 0 && LICENSE_GATE_BYPASS_COMMANDS.has(command)) return;
690
706
  const ciKey = process.env["CTXLOOM_LICENSE_KEY"];
691
707
  if (ciKey) {
692
- const { ApiClient } = await import("./src-DZ5Z7KVU.js");
708
+ const { ApiClient } = await import("./src-YPSOSNW5.js");
693
709
  const client = new ApiClient(process.env["CTXLOOM_API_BASE"]);
694
710
  try {
695
711
  const result = await client.validate(ciKey, "ci-ephemeral");
@@ -1251,7 +1267,7 @@ Suggested reviewers for ${files.length} file(s):`);
1251
1267
  process.stderr.write("[ctxloom] --limit must be a non-negative integer (0 for unlimited)\n");
1252
1268
  process.exit(2);
1253
1269
  }
1254
- const { loadRulesConfig, RulesChecker, formatText, formatJson, RulesConfigError } = await import("./src-DZ5Z7KVU.js");
1270
+ const { loadRulesConfig, RulesChecker, formatText, formatJson, RulesConfigError } = await import("./src-YPSOSNW5.js");
1255
1271
  let config;
1256
1272
  try {
1257
1273
  config = await loadRulesConfig(root);
@@ -1275,7 +1291,7 @@ Suggested reviewers for ${files.length} file(s):`);
1275
1291
  }
1276
1292
  let graph;
1277
1293
  if (useSnapshot) {
1278
- const { DependencyGraph: DG } = await import("./src-DZ5Z7KVU.js");
1294
+ const { DependencyGraph: DG } = await import("./src-YPSOSNW5.js");
1279
1295
  graph = new DG();
1280
1296
  const loaded = await graph.loadSnapshotOnly(root);
1281
1297
  if (!loaded) {
@@ -1284,7 +1300,7 @@ Suggested reviewers for ${files.length} file(s):`);
1284
1300
  }
1285
1301
  } else {
1286
1302
  process.stderr.write("[ctxloom] Building dependency graph...\n");
1287
- const { ASTParser: ASTParser2, DependencyGraph: DependencyGraph2 } = await import("./src-DZ5Z7KVU.js");
1303
+ const { ASTParser: ASTParser2, DependencyGraph: DependencyGraph2 } = await import("./src-YPSOSNW5.js");
1288
1304
  let parser;
1289
1305
  try {
1290
1306
  parser = new ASTParser2();
@@ -80,7 +80,7 @@ import {
80
80
  startTrial,
81
81
  track,
82
82
  writeCODEOWNERS
83
- } from "./chunk-3AF7Z7DD.js";
83
+ } from "./chunk-WQMLQTFY.js";
84
84
  import {
85
85
  VectorStore
86
86
  } from "./chunk-NEHYSE2Y.js";
@@ -89,7 +89,7 @@ import {
89
89
  collectFiles,
90
90
  generateEmbedding,
91
91
  indexDirectory
92
- } from "./chunk-NYBVAPM3.js";
92
+ } from "./chunk-VR6PNQYH.js";
93
93
  import {
94
94
  logger
95
95
  } from "./chunk-TYDMSHV7.js";
@@ -182,4 +182,4 @@ export {
182
182
  track,
183
183
  writeCODEOWNERS
184
184
  };
185
- //# sourceMappingURL=src-DZ5Z7KVU.js.map
185
+ //# sourceMappingURL=src-YPSOSNW5.js.map
@@ -3,7 +3,7 @@ import {
3
3
  } from "../chunk-NEHYSE2Y.js";
4
4
  import {
5
5
  generateEmbedding
6
- } from "../chunk-NYBVAPM3.js";
6
+ } from "../chunk-VR6PNQYH.js";
7
7
  import "../chunk-TYDMSHV7.js";
8
8
 
9
9
  // packages/core/src/workers/indexerWorker.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ctxloom-pro",
3
- "version": "1.0.28",
3
+ "version": "1.0.31",
4
4
  "description": "ctxloom — The Universal Code Context Engine. A local-first MCP server providing intelligent code context via hybrid Vector + AST + Graph search with Skeletonization (92% token reduction).",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -16,9 +16,10 @@
16
16
  "access": "public"
17
17
  },
18
18
  "bin": {
19
- "ctxloom": "dist/index.js"
19
+ "ctxloom": "bin/ctxloom.cjs"
20
20
  },
21
21
  "files": [
22
+ "bin/ctxloom.cjs",
22
23
  "dist/**/*",
23
24
  "!dist/**/*.map",
24
25
  "apps/dashboard/dist/**/*",