@edihasaj/recall 0.9.6 → 0.9.7

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/dist/cli.js CHANGED
@@ -2228,17 +2228,50 @@ import { join as join10 } from "path";
2228
2228
  import Database from "better-sqlite3";
2229
2229
 
2230
2230
  // src/daemon/launchd.ts
2231
- import { existsSync as existsSync7, mkdirSync as mkdirSync5, rmSync as rmSync2, writeFileSync as writeFileSync5 } from "fs";
2231
+ import { chmodSync, existsSync as existsSync7, mkdirSync as mkdirSync5, rmSync as rmSync2, writeFileSync as writeFileSync5 } from "fs";
2232
2232
  import { homedir as homedir2 } from "os";
2233
2233
  import { dirname as dirname6, join as join8, resolve as resolve5 } from "path";
2234
2234
  import { execFileSync as execFileSync4 } from "child_process";
2235
+
2236
+ // src/daemon/provider-env.ts
2237
+ var DAEMON_PROVIDER_ENV_KEYS = [
2238
+ "OPENAI_API_KEY",
2239
+ "ANTHROPIC_API_KEY",
2240
+ "AZURE_OPENAI_ENDPOINT",
2241
+ "AZURE_OPENAI_DEPLOYMENT",
2242
+ "AZURE_OPENAI_API_VERSION",
2243
+ "AZURE_OPENAI_API_KEY"
2244
+ ];
2245
+ function resolveDaemonProviderEnvironment(current, installed = {}) {
2246
+ const resolved = {};
2247
+ for (const key of DAEMON_PROVIDER_ENV_KEYS) {
2248
+ const value = current[key] ?? installed[key];
2249
+ if (value && value.trim().length > 0) {
2250
+ resolved[key] = value;
2251
+ }
2252
+ }
2253
+ return resolved;
2254
+ }
2255
+ function readDaemonProviderEnvironment(environment) {
2256
+ const installed = {};
2257
+ for (const key of DAEMON_PROVIDER_ENV_KEYS) {
2258
+ const value = environment[key];
2259
+ if (typeof value === "string" && value.trim().length > 0) {
2260
+ installed[key] = value;
2261
+ }
2262
+ }
2263
+ return installed;
2264
+ }
2265
+
2266
+ // src/daemon/launchd.ts
2235
2267
  var DEFAULT_LABEL = "com.recall.daemon";
2236
2268
  function installLaunchAgent(opts = {}) {
2237
2269
  assertDarwin();
2238
2270
  const cfg = resolveConfig(opts);
2239
2271
  mkdirSync5(dirname6(cfg.plistPath), { recursive: true });
2240
2272
  mkdirSync5(dirname6(cfg.stdoutPath), { recursive: true });
2241
- writeFileSync5(cfg.plistPath, renderPlist(cfg));
2273
+ writeFileSync5(cfg.plistPath, renderPlist(cfg), { mode: 384 });
2274
+ chmodSync(cfg.plistPath, 384);
2242
2275
  tryRun2("launchctl", ["bootout", domainTarget(), cfg.plistPath]);
2243
2276
  execFileSync4("launchctl", ["bootstrap", domainTarget(), cfg.plistPath], stdioOpts2());
2244
2277
  execFileSync4("launchctl", ["enable", `${domainTarget()}/${cfg.label}`], stdioOpts2());
@@ -2334,6 +2367,7 @@ function resolveConfig(opts) {
2334
2367
  );
2335
2368
  const plistPath = join8(home, "Library", "LaunchAgents", `${label}.plist`);
2336
2369
  const logDir = join8(dataDir, "logs");
2370
+ const installed = readInstalledConfig(plistPath);
2337
2371
  return {
2338
2372
  label,
2339
2373
  port,
@@ -2347,7 +2381,11 @@ function resolveConfig(opts) {
2347
2381
  repoRoots: opts.repoRoots ?? process.env.RECALL_REPO_ROOTS,
2348
2382
  embeddingProvider: opts.embeddingProvider ?? process.env.RECALL_EMBEDDING_PROVIDER,
2349
2383
  embeddingDims: opts.embeddingDims ?? process.env.RECALL_EMBEDDING_DIMS,
2350
- embeddingsDisabled: opts.embeddingsDisabled ?? process.env.RECALL_EMBEDDINGS_DISABLED
2384
+ embeddingsDisabled: opts.embeddingsDisabled ?? process.env.RECALL_EMBEDDINGS_DISABLED,
2385
+ providerEnvironment: resolveDaemonProviderEnvironment(
2386
+ process.env,
2387
+ installed?.providerEnvironment
2388
+ )
2351
2389
  };
2352
2390
  }
2353
2391
  function renderPlist(cfg) {
@@ -2359,8 +2397,11 @@ function renderPlist(cfg) {
2359
2397
  ...cfg.repoRoots ? { RECALL_REPO_ROOTS: cfg.repoRoots } : {},
2360
2398
  ...cfg.embeddingProvider ? { RECALL_EMBEDDING_PROVIDER: cfg.embeddingProvider } : {},
2361
2399
  ...cfg.embeddingDims ? { RECALL_EMBEDDING_DIMS: cfg.embeddingDims } : {},
2362
- ...cfg.embeddingsDisabled ? { RECALL_EMBEDDINGS_DISABLED: cfg.embeddingsDisabled } : {}
2400
+ ...cfg.embeddingsDisabled ? { RECALL_EMBEDDINGS_DISABLED: cfg.embeddingsDisabled } : {},
2401
+ ...cfg.providerEnvironment
2363
2402
  };
2403
+ const environmentXml = Object.entries(env).map(([key, value]) => ` <key>${escapeXml(key)}</key>
2404
+ <string>${escapeXml(value)}</string>`).join("\n");
2364
2405
  return `<?xml version="1.0" encoding="UTF-8"?>
2365
2406
  <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
2366
2407
  <plist version="1.0">
@@ -2374,23 +2415,8 @@ function renderPlist(cfg) {
2374
2415
  </array>
2375
2416
  <key>EnvironmentVariables</key>
2376
2417
  <dict>
2377
- <key>PATH</key>
2378
- <string>${escapeXml(env.PATH)}</string>
2379
- <key>RECALL_PORT</key>
2380
- <string>${escapeXml(env.RECALL_PORT)}</string>
2381
- <key>RECALL_MAINTENANCE_INTERVAL_SECONDS</key>
2382
- <string>${escapeXml(env.RECALL_MAINTENANCE_INTERVAL_SECONDS)}</string>
2383
- <key>RECALL_DATA_DIR</key>
2384
- <string>${escapeXml(env.RECALL_DATA_DIR)}</string>
2385
- ${env.RECALL_REPO_ROOTS ? ` <key>RECALL_REPO_ROOTS</key>
2386
- <string>${escapeXml(env.RECALL_REPO_ROOTS)}</string>
2387
- ` : ""}${env.RECALL_EMBEDDING_PROVIDER ? ` <key>RECALL_EMBEDDING_PROVIDER</key>
2388
- <string>${escapeXml(env.RECALL_EMBEDDING_PROVIDER)}</string>
2389
- ` : ""}${env.RECALL_EMBEDDING_DIMS ? ` <key>RECALL_EMBEDDING_DIMS</key>
2390
- <string>${escapeXml(env.RECALL_EMBEDDING_DIMS)}</string>
2391
- ` : ""}${env.RECALL_EMBEDDINGS_DISABLED ? ` <key>RECALL_EMBEDDINGS_DISABLED</key>
2392
- <string>${escapeXml(env.RECALL_EMBEDDINGS_DISABLED)}</string>
2393
- ` : ""} </dict>
2418
+ ${environmentXml}
2419
+ </dict>
2394
2420
  <key>RunAtLoad</key>
2395
2421
  <true/>
2396
2422
  <key>KeepAlive</key>
@@ -2456,6 +2482,9 @@ function readInstalledConfig(plistPath) {
2456
2482
  embeddingProvider: parsed?.EnvironmentVariables?.RECALL_EMBEDDING_PROVIDER,
2457
2483
  embeddingDims: parsed?.EnvironmentVariables?.RECALL_EMBEDDING_DIMS,
2458
2484
  embeddingsDisabled: parsed?.EnvironmentVariables?.RECALL_EMBEDDINGS_DISABLED,
2485
+ providerEnvironment: readDaemonProviderEnvironment(
2486
+ parsed?.EnvironmentVariables ?? {}
2487
+ ),
2459
2488
  stdoutPath: parsed?.StandardOutPath,
2460
2489
  stderrPath: parsed?.StandardErrorPath
2461
2490
  };
@@ -2481,7 +2510,7 @@ function assertDarwin() {
2481
2510
  }
2482
2511
 
2483
2512
  // src/daemon/systemd.ts
2484
- import { existsSync as existsSync8, mkdirSync as mkdirSync6, readFileSync as readFileSync5, rmSync as rmSync3, writeFileSync as writeFileSync6 } from "fs";
2513
+ import { chmodSync as chmodSync2, existsSync as existsSync8, mkdirSync as mkdirSync6, readFileSync as readFileSync5, rmSync as rmSync3, writeFileSync as writeFileSync6 } from "fs";
2485
2514
  import { homedir as homedir3 } from "os";
2486
2515
  import { dirname as dirname7, join as join9, resolve as resolve6 } from "path";
2487
2516
  import { fileURLToPath as fileURLToPath4 } from "url";
@@ -2492,7 +2521,8 @@ function installSystemdUnit(opts = {}) {
2492
2521
  const cfg = resolveConfig2(opts);
2493
2522
  mkdirSync6(dirname7(cfg.unitPath), { recursive: true });
2494
2523
  mkdirSync6(cfg.logDir, { recursive: true });
2495
- writeFileSync6(cfg.unitPath, renderUnit(cfg));
2524
+ writeFileSync6(cfg.unitPath, renderUnit(cfg), { mode: 384 });
2525
+ chmodSync2(cfg.unitPath, 384);
2496
2526
  systemctl(["--user", "daemon-reload"]);
2497
2527
  systemctl(["--user", "enable", "--now", `${cfg.label}.service`]);
2498
2528
  return getSystemdStatus(cfg.label);
@@ -2584,6 +2614,7 @@ function resolveConfig2(opts) {
2584
2614
  const configHome = process.env.XDG_CONFIG_HOME ?? join9(home, ".config");
2585
2615
  const unitPath = join9(configHome, "systemd", "user", `${label}.service`);
2586
2616
  const logDir = join9(dataDir, "logs");
2617
+ const installed = readInstalledConfig2(unitPath);
2587
2618
  return {
2588
2619
  label,
2589
2620
  port,
@@ -2596,7 +2627,11 @@ function resolveConfig2(opts) {
2596
2627
  repoRoots: opts.repoRoots ?? process.env.RECALL_REPO_ROOTS,
2597
2628
  embeddingProvider: opts.embeddingProvider ?? process.env.RECALL_EMBEDDING_PROVIDER,
2598
2629
  embeddingDims: opts.embeddingDims ?? process.env.RECALL_EMBEDDING_DIMS,
2599
- embeddingsDisabled: opts.embeddingsDisabled ?? process.env.RECALL_EMBEDDINGS_DISABLED
2630
+ embeddingsDisabled: opts.embeddingsDisabled ?? process.env.RECALL_EMBEDDINGS_DISABLED,
2631
+ providerEnvironment: resolveDaemonProviderEnvironment(
2632
+ process.env,
2633
+ installed?.providerEnvironment
2634
+ )
2600
2635
  };
2601
2636
  }
2602
2637
  function defaultDaemonScript() {
@@ -2614,6 +2649,9 @@ function renderUnit(cfg) {
2614
2649
  if (cfg.embeddingProvider) envLines.push(`Environment=RECALL_EMBEDDING_PROVIDER=${cfg.embeddingProvider}`);
2615
2650
  if (cfg.embeddingDims) envLines.push(`Environment=RECALL_EMBEDDING_DIMS=${cfg.embeddingDims}`);
2616
2651
  if (cfg.embeddingsDisabled) envLines.push(`Environment=RECALL_EMBEDDINGS_DISABLED=${cfg.embeddingsDisabled}`);
2652
+ for (const [key, value] of Object.entries(cfg.providerEnvironment)) {
2653
+ envLines.push(`Environment="${key}=${escapeSystemdValue(value)}"`);
2654
+ }
2617
2655
  return `[Unit]
2618
2656
  Description=Recall local daemon
2619
2657
  After=network.target
@@ -2634,10 +2672,7 @@ function readInstalledConfig2(unitPath) {
2634
2672
  try {
2635
2673
  const raw = readFileSync5(unitPath, "utf8");
2636
2674
  const exec = raw.match(/^ExecStart=(.+)$/m)?.[1]?.trim().split(/\s+/);
2637
- const env = {};
2638
- for (const m of raw.matchAll(/^Environment=([^=]+)=(.+)$/gm)) {
2639
- defineOwn(env, m[1], m[2]);
2640
- }
2675
+ const env = parseSystemdEnvironment(raw);
2641
2676
  return {
2642
2677
  nodePath: exec?.[0],
2643
2678
  daemonScript: exec?.[1],
@@ -2647,12 +2682,30 @@ function readInstalledConfig2(unitPath) {
2647
2682
  repoRoots: env.RECALL_REPO_ROOTS,
2648
2683
  embeddingProvider: env.RECALL_EMBEDDING_PROVIDER,
2649
2684
  embeddingDims: env.RECALL_EMBEDDING_DIMS,
2650
- embeddingsDisabled: env.RECALL_EMBEDDINGS_DISABLED
2685
+ embeddingsDisabled: env.RECALL_EMBEDDINGS_DISABLED,
2686
+ providerEnvironment: readDaemonProviderEnvironment(env)
2651
2687
  };
2652
2688
  } catch {
2653
2689
  return null;
2654
2690
  }
2655
2691
  }
2692
+ function parseSystemdEnvironment(raw) {
2693
+ const environment = {};
2694
+ for (const match of raw.matchAll(/^Environment=(?:"([^=]+)=(.*)"|([^=]+)=(.*))$/gm)) {
2695
+ const key = match[1] ?? match[3];
2696
+ const value = match[2] != null ? unescapeSystemdValue(match[2]) : match[4];
2697
+ if (key && value != null) {
2698
+ defineOwn(environment, key, value);
2699
+ }
2700
+ }
2701
+ return environment;
2702
+ }
2703
+ function escapeSystemdValue(value) {
2704
+ return value.replaceAll("\\", "\\\\").replaceAll('"', '\\"').replaceAll("%", "%%");
2705
+ }
2706
+ function unescapeSystemdValue(value) {
2707
+ return value.replaceAll("%%", "%").replaceAll('\\"', '"').replaceAll("\\\\", "\\");
2708
+ }
2656
2709
  function systemctl(args) {
2657
2710
  execFileSync5("systemctl", args, { stdio: "pipe" });
2658
2711
  }