@todoforai/edge 0.13.10 → 0.13.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 (2) hide show
  1. package/dist/index.js +68 -12
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -53186,22 +53186,75 @@ class ServerError extends Error {
53186
53186
  }
53187
53187
  }
53188
53188
 
53189
+ // src/update-notifier.ts
53190
+ import fs12 from "node:fs";
53191
+ import path9 from "node:path";
53192
+ import os9 from "node:os";
53193
+ var TTL_MS = 24 * 60 * 60 * 1000;
53194
+ var CACHE_DIR = path9.join(os9.homedir(), ".config", "todoforai");
53195
+ function cmpVer(a, b) {
53196
+ const pa2 = a.split("-")[0].split(".").map((n) => parseInt(n, 10) || 0);
53197
+ const pb2 = b.split("-")[0].split(".").map((n) => parseInt(n, 10) || 0);
53198
+ for (let i10 = 0;i10 < Math.max(pa2.length, pb2.length); i10++) {
53199
+ const d = (pa2[i10] ?? 0) - (pb2[i10] ?? 0);
53200
+ if (d)
53201
+ return d;
53202
+ }
53203
+ return 0;
53204
+ }
53205
+ function checkForUpdates(pkg) {
53206
+ if (!process.stderr.isTTY || process.env.CI || process.env.NO_UPDATE_NOTIFIER)
53207
+ return;
53208
+ const cacheFile = path9.join(CACHE_DIR, `notifier-${encodeURIComponent(pkg.name)}.json`);
53209
+ let cache = {};
53210
+ try {
53211
+ cache = JSON.parse(fs12.readFileSync(cacheFile, "utf8"));
53212
+ } catch {}
53213
+ if (cache.latest && cmpVer(cache.latest, pkg.version) > 0) {
53214
+ process.stderr.write(`
53215
+ \x1B[33m Update available: \x1B[2m${pkg.version}\x1B[22m → \x1B[1m${cache.latest}\x1B[0m
53216
+ ` + `\x1B[33m Run:\x1B[0m npm i -g ${pkg.name}
53217
+
53218
+ `);
53219
+ }
53220
+ if (Date.now() - (cache.ts ?? 0) > TTL_MS) {
53221
+ try {
53222
+ fs12.mkdirSync(CACHE_DIR, { recursive: true });
53223
+ fs12.writeFileSync(cacheFile, JSON.stringify({ ...cache, ts: Date.now() }));
53224
+ } catch {}
53225
+ fetch(`https://registry.npmjs.org/${pkg.name}/latest`, { signal: AbortSignal.timeout(3000) }).then((r) => r.ok ? r.json() : null).then((j) => {
53226
+ if (!j?.version)
53227
+ return;
53228
+ fs12.writeFileSync(cacheFile, JSON.stringify({ ts: Date.now(), latest: j.version }));
53229
+ }).catch(() => {});
53230
+ }
53231
+ }
53232
+
53189
53233
  // src/index.ts
53190
- import fs12 from "fs";
53191
- import path9 from "path";
53192
- import os9 from "os";
53234
+ import { fileURLToPath as fileURLToPath2 } from "url";
53235
+ import fs13 from "fs";
53236
+ import path10 from "path";
53237
+ import os10 from "os";
53193
53238
  import crypto3 from "crypto";
53239
+ function readOwnPackage() {
53240
+ try {
53241
+ const pkgPath = path10.resolve(fileURLToPath2(import.meta.url), "../../package.json");
53242
+ return JSON.parse(fs13.readFileSync(pkgPath, "utf-8"));
53243
+ } catch {
53244
+ return null;
53245
+ }
53246
+ }
53194
53247
  function lockPath(apiUrl, userId) {
53195
- const dir = path9.join(os9.homedir(), ".todoforai");
53196
- fs12.mkdirSync(dir, { recursive: true });
53248
+ const dir = path10.join(os10.homedir(), ".todoforai");
53249
+ fs13.mkdirSync(dir, { recursive: true });
53197
53250
  const hash = crypto3.createHash("sha256").update(`${apiUrl}
53198
53251
  ${userId}`).digest("hex").slice(0, 12);
53199
- return path9.join(dir, `edge-${hash}.lock`);
53252
+ return path10.join(dir, `edge-${hash}.lock`);
53200
53253
  }
53201
53254
  function isEdgeProcess(pid) {
53202
53255
  try {
53203
53256
  process.kill(pid, 0);
53204
- const cmdline = fs12.readFileSync(`/proc/${pid}/cmdline`, "utf-8");
53257
+ const cmdline = fs13.readFileSync(`/proc/${pid}/cmdline`, "utf-8");
53205
53258
  return cmdline.includes("index.ts") || cmdline.includes("todoforai-edge");
53206
53259
  } catch {
53207
53260
  return false;
@@ -53209,7 +53262,7 @@ function isEdgeProcess(pid) {
53209
53262
  }
53210
53263
  function killExistingEdge(lp2) {
53211
53264
  try {
53212
- const pid = parseInt(fs12.readFileSync(lp2, "utf-8").trim(), 10);
53265
+ const pid = parseInt(fs13.readFileSync(lp2, "utf-8").trim(), 10);
53213
53266
  if (!isNaN(pid) && isEdgeProcess(pid)) {
53214
53267
  console.log(`\x1B[33mKilling existing edge process (pid ${pid})...\x1B[0m`);
53215
53268
  process.kill(pid, "SIGTERM");
@@ -53232,7 +53285,7 @@ function killExistingEdge(lp2) {
53232
53285
  }
53233
53286
  function acquireLock(lp2, kill = false) {
53234
53287
  try {
53235
- const pid = parseInt(fs12.readFileSync(lp2, "utf-8").trim(), 10);
53288
+ const pid = parseInt(fs13.readFileSync(lp2, "utf-8").trim(), 10);
53236
53289
  if (!isNaN(pid) && isEdgeProcess(pid)) {
53237
53290
  if (kill) {
53238
53291
  killExistingEdge(lp2);
@@ -53240,16 +53293,19 @@ function acquireLock(lp2, kill = false) {
53240
53293
  return false;
53241
53294
  }
53242
53295
  } catch {}
53243
- fs12.writeFileSync(lp2, String(process.pid));
53296
+ fs13.writeFileSync(lp2, String(process.pid));
53244
53297
  return true;
53245
53298
  }
53246
53299
  function releaseLock(lp2) {
53247
53300
  try {
53248
- if (fs12.readFileSync(lp2, "utf-8").trim() === String(process.pid))
53249
- fs12.unlinkSync(lp2);
53301
+ if (fs13.readFileSync(lp2, "utf-8").trim() === String(process.pid))
53302
+ fs13.unlinkSync(lp2);
53250
53303
  } catch {}
53251
53304
  }
53252
53305
  async function main() {
53306
+ const ownPkg = readOwnPackage();
53307
+ if (ownPkg)
53308
+ checkForUpdates(ownPkg);
53253
53309
  const config = await loadConfig();
53254
53310
  if (config.debug) {
53255
53311
  console.log("[config]", { apiUrl: config.apiUrl, debug: config.debug, addWorkspacePath: config.addWorkspacePath });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@todoforai/edge",
3
- "version": "0.13.10",
3
+ "version": "0.13.11",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "todoforai-edge": "dist/index.js"
@@ -22,8 +22,8 @@
22
22
  "ws": "^8.18.0"
23
23
  },
24
24
  "devDependencies": {
25
- "@types/ws": "^8.5.12",
26
25
  "@types/node": "^22.0.0",
26
+ "@types/ws": "^8.5.12",
27
27
  "typescript": "^5.6.0"
28
28
  }
29
29
  }