lens-engine 0.1.17 → 0.1.18
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/cli.js +1 -1
- package/daemon.js +37 -33
- package/dashboard/assets/{index-Bgjp5TLX.js → index-Dpgp0uUn.js} +16 -16
- package/dashboard/index.html +1 -1
- package/package.json +1 -1
package/cli.js
CHANGED
|
@@ -4639,7 +4639,7 @@ async function logoutCommand() {
|
|
|
4639
4639
|
}
|
|
4640
4640
|
|
|
4641
4641
|
// packages/cli/src/index.ts
|
|
4642
|
-
var program2 = new Command().name("lens").description("LENS \u2014 Local-first repo context engine").version("0.1.
|
|
4642
|
+
var program2 = new Command().name("lens").description("LENS \u2014 Local-first repo context engine").version("0.1.18");
|
|
4643
4643
|
function trackCommand(name) {
|
|
4644
4644
|
if (!isTelemetryEnabled()) return;
|
|
4645
4645
|
const BASE_URL2 = process.env.LENS_HOST ?? "http://127.0.0.1:4111";
|
package/daemon.js
CHANGED
|
@@ -9251,6 +9251,16 @@ function interpretQuery(query, metadata, fileStats2, vocabClusters, indegrees, m
|
|
|
9251
9251
|
const { exact, stemmed, clusterFiles } = expandKeywords(rawWords, vocabClusters ?? null);
|
|
9252
9252
|
const allTerms = [...exact, ...stemmed];
|
|
9253
9253
|
const termWeights = buildTermWeights(allTerms, metadata);
|
|
9254
|
+
const exportTokensMap = /* @__PURE__ */ new Map();
|
|
9255
|
+
for (const f of metadata) {
|
|
9256
|
+
const tokens = /* @__PURE__ */ new Set();
|
|
9257
|
+
for (const exp of f.exports ?? []) {
|
|
9258
|
+
for (const part of exp.replace(/([a-z])([A-Z])/g, "$1 $2").toLowerCase().split(/[\s_-]+/)) {
|
|
9259
|
+
if (part.length >= 3 && !STOPWORDS2.has(part)) tokens.add(part);
|
|
9260
|
+
}
|
|
9261
|
+
}
|
|
9262
|
+
exportTokensMap.set(f.path, tokens);
|
|
9263
|
+
}
|
|
9254
9264
|
const scored = metadata.map((f) => {
|
|
9255
9265
|
let score = 0;
|
|
9256
9266
|
let matchedTerms = 0;
|
|
@@ -9265,12 +9275,14 @@ function interpretQuery(query, metadata, fileStats2, vocabClusters, indegrees, m
|
|
|
9265
9275
|
const fileTokens = fileName.replace(/([a-z])([A-Z])/g, "$1 $2").replace(/[._-]/g, " ").toLowerCase().split(/\s+/).filter((t) => t.length >= 2);
|
|
9266
9276
|
const dirTokens = pathSegments.slice(-4, -1).flatMap((s) => s.replace(/\./g, " ").split(/\s+/)).filter((t) => t.length >= 2);
|
|
9267
9277
|
const pathTokenSet = /* @__PURE__ */ new Set([...fileTokens, ...dirTokens]);
|
|
9278
|
+
const expTokens = exportTokensMap.get(f.path);
|
|
9268
9279
|
for (const w of exact) {
|
|
9269
9280
|
const weight = termWeights.get(w) ?? 1;
|
|
9270
9281
|
let termScore = 0;
|
|
9271
9282
|
if (fileTokens.some((t) => t === w || t.includes(w))) termScore += 4 * weight;
|
|
9272
9283
|
else if (pathTokenSet.has(w)) termScore += 2 * weight;
|
|
9273
|
-
if (
|
|
9284
|
+
if (expTokens?.has(w)) termScore += 2.5 * weight;
|
|
9285
|
+
else if (exportsLower.includes(w)) termScore += 2 * weight;
|
|
9274
9286
|
if (docLower.includes(w) || purposeLower.includes(w)) termScore += 1 * weight;
|
|
9275
9287
|
if (sectionsLower.includes(w)) termScore += 1 * weight;
|
|
9276
9288
|
if (internalsLower.includes(w)) termScore += 1.5 * weight;
|
|
@@ -9294,6 +9306,10 @@ function interpretQuery(query, metadata, fileStats2, vocabClusters, indegrees, m
|
|
|
9294
9306
|
if (score > 0 && isNoisePath(f.path)) {
|
|
9295
9307
|
score *= 0.3;
|
|
9296
9308
|
}
|
|
9309
|
+
const exportCount = (f.exports ?? []).length;
|
|
9310
|
+
if (exportCount > 5 && score > 0) {
|
|
9311
|
+
score *= 1 / (1 + Math.log2(exportCount / 5) * 0.3);
|
|
9312
|
+
}
|
|
9297
9313
|
const stats = fileStats2?.get(f.path);
|
|
9298
9314
|
if (stats && stats.recent_count > 0 && score > 0) {
|
|
9299
9315
|
score += Math.min(stats.recent_count, 5) * 0.5;
|
|
@@ -32396,6 +32412,10 @@ var mcp_exports = {};
|
|
|
32396
32412
|
__export(mcp_exports, {
|
|
32397
32413
|
createMcpServer: () => createMcpServer
|
|
32398
32414
|
});
|
|
32415
|
+
import { randomUUID as randomUUID3 } from "crypto";
|
|
32416
|
+
function logMcp(method, path, status, duration3, reqBody, resSize, resBody, trace) {
|
|
32417
|
+
getRawDb().prepare(LOG_SQL).run(randomUUID3(), method, path, status, duration3, reqBody ?? null, resSize ?? null, resBody ?? null, trace ?? null);
|
|
32418
|
+
}
|
|
32399
32419
|
function text2(s) {
|
|
32400
32420
|
return { content: [{ type: "text", text: s }] };
|
|
32401
32421
|
}
|
|
@@ -32423,15 +32443,16 @@ function createMcpServer(db, caps) {
|
|
|
32423
32443
|
trace.step("findRepo");
|
|
32424
32444
|
const repoId = findOrRegisterRepo(db, repo_path);
|
|
32425
32445
|
trace.end("findRepo");
|
|
32426
|
-
const
|
|
32446
|
+
const repo = repoQueries.getById(db, repoId);
|
|
32447
|
+
const useEmbeddings = repo?.enable_embeddings === 1;
|
|
32427
32448
|
const result = await buildContext(db, repoId, goal, caps, trace, { useEmbeddings });
|
|
32428
32449
|
const duration3 = Math.round(performance.now() - start);
|
|
32429
32450
|
const reqBody = JSON.stringify({ repo_path, goal });
|
|
32430
|
-
|
|
32451
|
+
logMcp("MCP", "/tool/get_context", 200, duration3, reqBody, result.context_pack.length, result.context_pack, trace.serialize());
|
|
32431
32452
|
return text2(result.context_pack);
|
|
32432
32453
|
} catch (e) {
|
|
32433
32454
|
const duration3 = Math.round(performance.now() - start);
|
|
32434
|
-
|
|
32455
|
+
logMcp("MCP", "/tool/get_context", 500, duration3, JSON.stringify({ repo_path, goal }), void 0, e.message, trace.serialize());
|
|
32435
32456
|
return error2(e.message);
|
|
32436
32457
|
}
|
|
32437
32458
|
}
|
|
@@ -32448,11 +32469,11 @@ function createMcpServer(db, caps) {
|
|
|
32448
32469
|
const repos2 = listRepos(db);
|
|
32449
32470
|
const body = JSON.stringify(repos2, null, 2);
|
|
32450
32471
|
const duration3 = Math.round(performance.now() - start);
|
|
32451
|
-
|
|
32472
|
+
logMcp("MCP", "/tool/list_repos", 200, duration3, void 0, body.length, body);
|
|
32452
32473
|
return text2(body);
|
|
32453
32474
|
} catch (e) {
|
|
32454
32475
|
const duration3 = Math.round(performance.now() - start);
|
|
32455
|
-
|
|
32476
|
+
logMcp("MCP", "/tool/list_repos", 500, duration3, void 0, void 0, e.message);
|
|
32456
32477
|
return error2(e.message);
|
|
32457
32478
|
}
|
|
32458
32479
|
}
|
|
@@ -32468,17 +32489,17 @@ function createMcpServer(db, caps) {
|
|
|
32468
32489
|
try {
|
|
32469
32490
|
const repo = repoQueries.getByPath(db, repo_path);
|
|
32470
32491
|
if (!repo) {
|
|
32471
|
-
|
|
32492
|
+
logMcp("MCP", "/tool/get_status", 404, Math.round(performance.now() - start), JSON.stringify({ repo_path }));
|
|
32472
32493
|
return error2("repo not found at " + repo_path);
|
|
32473
32494
|
}
|
|
32474
32495
|
const status = await getRepoStatus(db, repo.id);
|
|
32475
32496
|
const body = JSON.stringify(status, null, 2);
|
|
32476
32497
|
const duration3 = Math.round(performance.now() - start);
|
|
32477
|
-
|
|
32498
|
+
logMcp("MCP", "/tool/get_status", 200, duration3, JSON.stringify({ repo_path }), body.length, body);
|
|
32478
32499
|
return text2(body);
|
|
32479
32500
|
} catch (e) {
|
|
32480
32501
|
const duration3 = Math.round(performance.now() - start);
|
|
32481
|
-
|
|
32502
|
+
logMcp("MCP", "/tool/get_status", 500, duration3, JSON.stringify({ repo_path }), void 0, e.message);
|
|
32482
32503
|
return error2(e.message);
|
|
32483
32504
|
}
|
|
32484
32505
|
}
|
|
@@ -32499,23 +32520,26 @@ function createMcpServer(db, caps) {
|
|
|
32499
32520
|
const result = await runIndex(db, repoId, caps, force ?? false, void 0, trace);
|
|
32500
32521
|
const body = JSON.stringify(result, null, 2);
|
|
32501
32522
|
const duration3 = Math.round(performance.now() - start);
|
|
32502
|
-
|
|
32523
|
+
logMcp("MCP", "/tool/index_repo", 200, duration3, JSON.stringify({ repo_path, force }), body.length, body, trace.serialize());
|
|
32503
32524
|
return text2(body);
|
|
32504
32525
|
} catch (e) {
|
|
32505
32526
|
const duration3 = Math.round(performance.now() - start);
|
|
32506
|
-
|
|
32527
|
+
logMcp("MCP", "/tool/index_repo", 500, duration3, JSON.stringify({ repo_path, force }), void 0, e.message, trace.serialize());
|
|
32507
32528
|
return error2(e.message);
|
|
32508
32529
|
}
|
|
32509
32530
|
}
|
|
32510
32531
|
);
|
|
32511
32532
|
return server;
|
|
32512
32533
|
}
|
|
32534
|
+
var LOG_SQL;
|
|
32513
32535
|
var init_mcp2 = __esm({
|
|
32514
32536
|
"apps/daemon/src/mcp.ts"() {
|
|
32515
32537
|
"use strict";
|
|
32516
32538
|
init_dist();
|
|
32517
32539
|
init_mcp();
|
|
32518
32540
|
init_zod();
|
|
32541
|
+
LOG_SQL = `INSERT INTO request_logs (id, method, path, status, duration_ms, source, request_body, response_size, response_body, trace, created_at)
|
|
32542
|
+
VALUES (?, ?, ?, ?, ?, 'mcp', ?, ?, ?, ?, datetime('now'))`;
|
|
32519
32543
|
}
|
|
32520
32544
|
});
|
|
32521
32545
|
|
|
@@ -35098,7 +35122,8 @@ function createApp(db, dashboardDist, initialCaps, initialPlanData) {
|
|
|
35098
35122
|
try {
|
|
35099
35123
|
const { repo_id, goal } = await c.req.json();
|
|
35100
35124
|
if (!repo_id || !goal) return c.json({ error: "repo_id and goal required" }, 400);
|
|
35101
|
-
const
|
|
35125
|
+
const repo = repoQueries.getById(db, repo_id);
|
|
35126
|
+
const useEmbeddings = repo?.enable_embeddings === 1;
|
|
35102
35127
|
const result = await buildContext(db, repo_id, goal, caps, c.get("trace"), { useEmbeddings });
|
|
35103
35128
|
usageQueries.increment(db, "context_queries");
|
|
35104
35129
|
return c.json(result);
|
|
@@ -35824,27 +35849,6 @@ function createApp(db, dashboardDist, initialCaps, initialPlanData) {
|
|
|
35824
35849
|
return c.json({ error: e.message }, 500);
|
|
35825
35850
|
}
|
|
35826
35851
|
});
|
|
35827
|
-
trackRoute("GET", "/api/dashboard/settings");
|
|
35828
|
-
app.get("/api/dashboard/settings", (c) => {
|
|
35829
|
-
try {
|
|
35830
|
-
const all = settingsQueries.getAll(db);
|
|
35831
|
-
return c.json({ settings: all });
|
|
35832
|
-
} catch (e) {
|
|
35833
|
-
return c.json({ error: e.message }, 500);
|
|
35834
|
-
}
|
|
35835
|
-
});
|
|
35836
|
-
trackRoute("PUT", "/api/dashboard/settings");
|
|
35837
|
-
app.put("/api/dashboard/settings", async (c) => {
|
|
35838
|
-
try {
|
|
35839
|
-
const body = await c.req.json();
|
|
35840
|
-
for (const [key, value] of Object.entries(body)) {
|
|
35841
|
-
settingsQueries.set(db, key, value);
|
|
35842
|
-
}
|
|
35843
|
-
return c.json({ ok: true, settings: settingsQueries.getAll(db) });
|
|
35844
|
-
} catch (e) {
|
|
35845
|
-
return c.json({ error: e.message }, 500);
|
|
35846
|
-
}
|
|
35847
|
-
});
|
|
35848
35852
|
trackRoute("GET", "/api/dashboard/routes");
|
|
35849
35853
|
app.get("/api/dashboard/routes", (c) => {
|
|
35850
35854
|
return c.json({ routes: registeredRoutes });
|