owlmem 0.9.18 → 0.9.20

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/owlmem.mjs +42 -3
  2. package/package.json +1 -1
package/owlmem.mjs CHANGED
@@ -43,7 +43,7 @@ import { join, dirname, basename, relative, isAbsolute } from "node:path";
43
43
  import { fileURLToPath } from "node:url";
44
44
  import { spawn, spawnSync } from "node:child_process";
45
45
 
46
- export const VERSION = "0.9.18";
46
+ export const VERSION = "0.9.20";
47
47
  const BASE = (process.env.OWLMEM_URL || "https://owlmem.com").replace(/\/$/, "");
48
48
  const DIR = process.env.OWLMEM_HOME || join(process.env.XDG_CONFIG_HOME || join(homedir(), ".config"), "owlmem");
49
49
  const enc = new TextEncoder(), dec = new TextDecoder();
@@ -1675,12 +1675,18 @@ async function claudeQuota(fetchImpl = fetch) {
1675
1675
  // Antigravity's quota (0.9.5): its running app answers on 127.0.0.1 with each model's remaining share and reset time, the
1676
1676
  // numbers its own model picker shows. We find the app by its command line (agy --hub-port=… --csrf_token=…); the token
1677
1677
  // only goes to that local port. Models that reset together are one window; OwlMem gets percentages and times, no names.
1678
- export function agyServers(psOut) {
1678
+ // Antigravity 1.5.9 (2026-11-14) stopped putting --csrf_token on the command line: the token is in the app's
1679
+ // daemon file ~/.gemini/antigravity/daemon/hub_<port>.json ("csrfToken") and in its environment. Read the file when
1680
+ // the command line has only the port.
1681
+ export function agyServers(psOut, daemonDir = join(homedir(), ".gemini", "antigravity", "daemon")) {
1679
1682
  const out = [];
1680
1683
  for (const l of String(psOut || "").split("\n")) {
1681
1684
  if (!/(^|\/)agy$/.test(l.trim().split(/\s/)[0] || "")) continue;
1682
1685
  const port = /--hub-port[= ](\d{2,5})\b/.exec(l), tok = /--csrf_token[= ]([\w-]{8,})/.exec(l);
1683
- if (port && tok) out.push({ port: Number(port[1]), token: tok[1] });
1686
+ if (!port) continue;
1687
+ let token = tok?.[1];
1688
+ if (!token) { try { const d = JSON.parse(readFileSync(join(daemonDir, "hub_" + port[1] + ".json"), "utf8")); if (/^[\w-]{8,}$/.test(d?.csrfToken || "")) token = d.csrfToken; } catch {} }
1689
+ if (token && !out.some((s) => s.port === Number(port[1]))) out.push({ port: Number(port[1]), token });
1684
1690
  }
1685
1691
  return out;
1686
1692
  }
@@ -1722,6 +1728,32 @@ async function antigravityQuota(fetchImpl = fetch) {
1722
1728
  }
1723
1729
  return null;
1724
1730
  }
1731
+ // DeepSeek's balance (0.9.20): DSH pays per token, so its quota is the account balance, not a window.
1732
+ // Read it from DeepSeek's balance endpoint with the key DSH itself runs on: DEEPSEEK_API_KEY in this
1733
+ // process's environment (DSH's own documented variable). The key is only sent to api.deepseek.com and
1734
+ // never leaves this computer otherwise; OwlMem gets the amount and currency. No key, no answer, or a
1735
+ // shape we don't recognize: no balance this round, the same as the other quota readers.
1736
+ export function dshBalanceFrom(j) {
1737
+ const infos = Array.isArray(j?.balance_infos) ? j.balance_infos : [];
1738
+ const entries = infos.map((b) => ({ currency: b?.currency, balance: Number(b?.total_balance) }))
1739
+ .filter((e) => typeof e.currency === "string" && e.currency && Number.isFinite(e.balance));
1740
+ if (!entries.length) return null;
1741
+ return entries.find((e) => e.balance > 0) || entries[0];
1742
+ }
1743
+ // The auto-wake service doesn't inherit your shell's environment, so also read DSH's own config file
1744
+ // ~/.dsh/.env (where `dsh` keeps DEEPSEEK_API_KEY). Only that one line is read; the key stays in memory.
1745
+ export function dshKeyFrom(text) {
1746
+ const m = /^\s*(?:export\s+)?DEEPSEEK_API_KEY\s*=\s*["']?([^"'\s#]+)/m.exec(String(text || ""));
1747
+ return m ? m[1] : null;
1748
+ }
1749
+ async function dshBalance(fetchImpl = fetch, home = homedir()) {
1750
+ let key = process.env.DEEPSEEK_API_KEY;
1751
+ if (!key) { try { key = dshKeyFrom(readFileSync(join(home, ".dsh", ".env"), "utf8")); } catch {} }
1752
+ if (!key) return null;
1753
+ const r = await fetchImpl("https://api.deepseek.com/user/balance", { headers: { Authorization: "Bearer " + key, "User-Agent": "owlmem-cli/" + VERSION }, signal: AbortSignal.timeout(15000) });
1754
+ if (!r.ok) return null;
1755
+ return dshBalanceFrom(await r.json());
1756
+ }
1725
1757
  async function usageTick(cfg, api, log, dir = DIR) {
1726
1758
  const file = join(wakeDir(dir), "usage.json");
1727
1759
  let state = {}; try { state = JSON.parse(readFileSync(file, "utf8")); } catch {}
@@ -1734,6 +1766,13 @@ async function usageTick(cfg, api, log, dir = DIR) {
1734
1766
  if (r.status !== 200 && r.status !== 404) log("usage: OwlMem answered " + (r.data?.detail || "HTTP " + r.status));
1735
1767
  }
1736
1768
  }
1769
+ if (cfg.clients?.dsh) { // no transcripts to count here either, only its DeepSeek balance
1770
+ const b = await dshBalance().catch(() => null);
1771
+ if (b) {
1772
+ const r = await api("usage", { days: {}, status: { dsh: { ...b, limit_at: Math.floor(Date.now() / 1000) } } });
1773
+ if (r.status !== 200 && r.status !== 404) log("usage: OwlMem answered " + (r.data?.detail || "HTTP " + r.status));
1774
+ }
1775
+ }
1737
1776
  if (!clients.length) return;
1738
1777
  scanUsage(state, Object.fromEntries(Object.entries(usageRoots()).filter(([c]) => clients.includes(c))));
1739
1778
  try { writeFileSync(file + ".tmp", JSON.stringify(state)); renameSync(file + ".tmp", file); } catch (e) { log("usage: " + e.message); }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "owlmem",
3
- "version": "0.9.18",
3
+ "version": "0.9.20",
4
4
  "description": "OwlMem command line: connect your AI apps to OwlMem in one command (npx -y owlmem install), an end-to-end encrypted vault for your AI agents, and a local MCP server.",
5
5
  "type": "module",
6
6
  "bin": { "owlmem": "owlmem.mjs" },