lens-engine 0.1.9 → 0.1.11

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.
Files changed (3) hide show
  1. package/cli.js +1 -1
  2. package/daemon.js +47 -15
  3. package/package.json +1 -1
package/cli.js CHANGED
@@ -4368,7 +4368,7 @@ async function logoutCommand() {
4368
4368
  }
4369
4369
 
4370
4370
  // packages/cli/src/index.ts
4371
- var program2 = new Command().name("lens").description("LENS \u2014 Local-first repo context engine").version("0.1.9");
4371
+ var program2 = new Command().name("lens").description("LENS \u2014 Local-first repo context engine").version("0.1.11");
4372
4372
  function trackCommand(name) {
4373
4373
  if (!isTelemetryEnabled()) return;
4374
4374
  const BASE_URL2 = process.env.LENS_HOST ?? "http://127.0.0.1:4111";
package/daemon.js CHANGED
@@ -6627,9 +6627,9 @@ var init_handler = __esm({
6627
6627
  if (this.fsw.closed) {
6628
6628
  return;
6629
6629
  }
6630
- const dirname4 = sysPath.dirname(file);
6630
+ const dirname5 = sysPath.dirname(file);
6631
6631
  const basename4 = sysPath.basename(file);
6632
- const parent = this.fsw._getWatchedDir(dirname4);
6632
+ const parent = this.fsw._getWatchedDir(dirname5);
6633
6633
  let prevStats = stats;
6634
6634
  if (parent.has(basename4))
6635
6635
  return;
@@ -6656,7 +6656,7 @@ var init_handler = __esm({
6656
6656
  prevStats = newStats2;
6657
6657
  }
6658
6658
  } catch (error3) {
6659
- this.fsw._remove(dirname4, basename4);
6659
+ this.fsw._remove(dirname5, basename4);
6660
6660
  }
6661
6661
  } else if (parent.has(basename4)) {
6662
6662
  const at = newStats.atimeMs;
@@ -34497,7 +34497,7 @@ function quotaRemaining(key) {
34497
34497
  function createApp(db, dashboardDist, initialCaps, initialPlanData) {
34498
34498
  let caps = initialCaps;
34499
34499
  if (initialPlanData) {
34500
- quotaCache = { ...initialPlanData, fetchedAt: Date.now() };
34500
+ quotaCache = { ...initialPlanData, subscription: null, fetchedAt: Date.now() };
34501
34501
  }
34502
34502
  const app = new Hono2();
34503
34503
  const telemetryEnabled = isTelemetryEnabled();
@@ -34959,10 +34959,10 @@ function createApp(db, dashboardDist, initialCaps, initialPlanData) {
34959
34959
  async () => cloudProxy("GET", "/api/usage/current")
34960
34960
  );
34961
34961
  trackRoute("GET", "/api/cloud/subscription");
34962
- app.get(
34963
- "/api/cloud/subscription",
34964
- async () => cloudProxy("GET", "/api/subscription")
34965
- );
34962
+ app.get("/api/cloud/subscription", (c) => {
34963
+ const sub = quotaCache?.subscription ?? { plan: "free", status: "active" };
34964
+ return c.json({ subscription: sub });
34965
+ });
34966
34966
  trackRoute("POST", "/api/cloud/billing/checkout");
34967
34967
  app.post("/api/cloud/billing/checkout", async (c) => {
34968
34968
  const body = await c.req.json().catch(() => ({}));
@@ -35239,13 +35239,18 @@ function createApp(db, dashboardDist, initialCaps, initialPlanData) {
35239
35239
  }
35240
35240
  async function refreshQuotaCache() {
35241
35241
  try {
35242
- const res = await cloudProxy("GET", "/api/usage/current");
35242
+ const [res, subRes] = await Promise.all([
35243
+ cloudProxy("GET", "/api/usage/current"),
35244
+ cloudProxy("GET", "/api/subscription")
35245
+ ]);
35243
35246
  if (res.ok) {
35244
35247
  const data = await res.json();
35248
+ const subData = subRes.ok ? (await subRes.json()).subscription ?? null : null;
35245
35249
  quotaCache = {
35246
35250
  plan: data.plan ?? "free",
35247
35251
  usage: data.usage ?? {},
35248
35252
  quota: data.quota ?? {},
35253
+ subscription: subData,
35249
35254
  fetchedAt: Date.now()
35250
35255
  };
35251
35256
  if (caps && data.plan !== "pro") {
@@ -35280,10 +35285,10 @@ function createApp(db, dashboardDist, initialCaps, initialPlanData) {
35280
35285
  console.error("[LENS] API key re-provisioned after 401");
35281
35286
  return refreshQuotaCache();
35282
35287
  }
35283
- quotaCache = { plan: "free", usage: {}, quota: {}, fetchedAt: Date.now() };
35288
+ quotaCache = { plan: "free", usage: {}, quota: {}, subscription: null, fetchedAt: Date.now() };
35284
35289
  caps = void 0;
35285
35290
  } else {
35286
- quotaCache = { plan: "free", usage: {}, quota: {}, fetchedAt: Date.now() };
35291
+ quotaCache = { plan: "free", usage: {}, quota: {}, subscription: null, fetchedAt: Date.now() };
35287
35292
  caps = void 0;
35288
35293
  }
35289
35294
  } catch {
@@ -35930,10 +35935,13 @@ var init_dist3 = __esm({
35930
35935
  // apps/daemon/src/index.ts
35931
35936
  init_dist();
35932
35937
  init_config();
35933
- import { writeFileSync as writeFileSync3, unlinkSync, readFileSync as readFileSync3 } from "fs";
35938
+ import { writeFileSync as writeFileSync3, unlinkSync, readFileSync as readFileSync3, statSync as statSync2, watchFile as watchFile2, openSync } from "fs";
35934
35939
  import { join as join6 } from "path";
35935
35940
  import { homedir as homedir4 } from "os";
35936
- var PID_FILE = join6(homedir4(), ".lens", "daemon.pid");
35941
+ import { spawn } from "child_process";
35942
+ var LENS_DIR = join6(homedir4(), ".lens");
35943
+ var PID_FILE = join6(LENS_DIR, "daemon.pid");
35944
+ var LOG_FILE = join6(LENS_DIR, "daemon.log");
35937
35945
  function writePid() {
35938
35946
  writeFileSync3(PID_FILE, String(process.pid));
35939
35947
  }
@@ -36044,11 +36052,11 @@ async function main() {
36044
36052
  var shutdown = shutdown2;
36045
36053
  const { createApp: createApp2 } = await Promise.resolve().then(() => (init_server3(), server_exports));
36046
36054
  const { serve: serve2 } = await Promise.resolve().then(() => (init_dist3(), dist_exports2));
36047
- const { resolve: resolve4, dirname: dirname4 } = await import("path");
36055
+ const { resolve: resolve4, dirname: dirname5 } = await import("path");
36048
36056
  const { existsSync: existsSync3 } = await import("fs");
36049
36057
  const { fileURLToPath } = await import("url");
36050
36058
  const port = Number(process.env.LENS_PORT) || 4111;
36051
- const selfDir = dirname4(fileURLToPath(import.meta.url));
36059
+ const selfDir = dirname5(fileURLToPath(import.meta.url));
36052
36060
  const candidates = [
36053
36061
  resolve4(selfDir, "../../dashboard/dist"),
36054
36062
  // monorepo dev
@@ -36065,6 +36073,30 @@ async function main() {
36065
36073
  writePid();
36066
36074
  process.on("SIGTERM", shutdown2);
36067
36075
  process.on("SIGINT", shutdown2);
36076
+ const scriptPath = process.argv[1];
36077
+ if (scriptPath) {
36078
+ try {
36079
+ const startMtime = statSync2(scriptPath).mtimeMs;
36080
+ watchFile2(scriptPath, { interval: 3e4 }, (curr) => {
36081
+ if (curr.mtimeMs !== startMtime) {
36082
+ console.error("[LENS] Binary updated, restarting...");
36083
+ app.stopTelemetrySync?.();
36084
+ server.close();
36085
+ closeDb();
36086
+ removePid();
36087
+ const logFd = openSync(LOG_FILE, "a");
36088
+ const child = spawn(process.execPath, [scriptPath], {
36089
+ detached: true,
36090
+ stdio: ["ignore", logFd, logFd],
36091
+ env: { ...process.env, LENS_DAEMON: "1" }
36092
+ });
36093
+ child.unref();
36094
+ process.exit(0);
36095
+ }
36096
+ });
36097
+ } catch {
36098
+ }
36099
+ }
36068
36100
  }
36069
36101
  }
36070
36102
  main().catch((e) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lens-engine",
3
- "version": "0.1.9",
3
+ "version": "0.1.11",
4
4
  "description": "LENS — Local-first repo context engine for AI agents",
5
5
  "type": "module",
6
6
  "bin": {