owlmem 0.9.23 → 0.9.24
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/README.md +1 -0
- package/owlmem.mjs +75 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -60,6 +60,7 @@ npx -y owlmem wake disable # also done by npx -y owlmem uninstall
|
|
|
60
60
|
the computer. When the computer is removed, the AI is disconnected or the account is gone, the program gets a 401,
|
|
61
61
|
removes its own autostart entry and exits. The command for each app is in `~/.config/owlmem/wake/wake.json`;
|
|
62
62
|
logs and worktrees stay in that folder after uninstalling.
|
|
63
|
+
- **Plan usage.** The waker also reports each app's plan usage to OwlMem. Cursor:自动报套餐用量。
|
|
63
64
|
|
|
64
65
|
## Vault
|
|
65
66
|
|
package/owlmem.mjs
CHANGED
|
@@ -44,7 +44,7 @@ import { fileURLToPath } from "node:url";
|
|
|
44
44
|
import { spawn, spawnSync } from "node:child_process";
|
|
45
45
|
import { createConnection } from "node:net";
|
|
46
46
|
|
|
47
|
-
export const VERSION = "0.9.
|
|
47
|
+
export const VERSION = "0.9.24";
|
|
48
48
|
const BASE = (process.env.OWLMEM_URL || "https://owlmem.com").replace(/\/$/, "");
|
|
49
49
|
const DIR = process.env.OWLMEM_HOME || join(process.env.XDG_CONFIG_HOME || join(homedir(), ".config"), "owlmem");
|
|
50
50
|
const enc = new TextEncoder(), dec = new TextDecoder();
|
|
@@ -846,8 +846,12 @@ export const WAKE_CLIENTS = {
|
|
|
846
846
|
// closes stdin. Full: --auto; limited: file edits, shell and web fetches denied through OPENCODE_CONFIG_CONTENT (wakeEnv).
|
|
847
847
|
// Tested 11-03 against a local OwlMem with opencode 1.19.5: full did the task; limited refused a shell command and declined.
|
|
848
848
|
opencode: { name: "opencode", bin: "opencode", command: ["opencode", "run"], prompt: "arg", home: [[".opencode", "bin", "opencode"]] },
|
|
849
|
+
// Cursor: quota-only (0.9.24) — no headless command to run a task, only its plan usage is reported. The waker
|
|
850
|
+
// never starts it; the server never sends it a task (hub/wake.py QUOTA_ONLY). `wake enable` offers it when
|
|
851
|
+
// Cursor's own state database exists on this computer.
|
|
852
|
+
cursor: { name: "Cursor", quotaOnly: true },
|
|
849
853
|
};
|
|
850
|
-
export const WAKE_APP_IDS = ["claude-code", "codex", "antigravity", "hermes", "dsh", "opencode", "gemini", "custom"];
|
|
854
|
+
export const WAKE_APP_IDS = ["claude-code", "codex", "antigravity", "hermes", "dsh", "opencode", "gemini", "custom", "cursor"];
|
|
851
855
|
// Where an app's command is: on PATH, or the first of its default install places that exists (path parts under your home
|
|
852
856
|
// folder, or an absolute path), used by full path
|
|
853
857
|
export function wakeBin(c, home_ = home(), exists = existsSync, path = onPath) {
|
|
@@ -1976,6 +1980,67 @@ async function dshBalance(fetchImpl = fetch, home = homedir()) {
|
|
|
1976
1980
|
if (!r.ok) return null;
|
|
1977
1981
|
return dshBalanceFrom(await r.json());
|
|
1978
1982
|
}
|
|
1983
|
+
// Cursor's plan usage (0.9.24, owner 11-17): Cursor's own dashboard (cursor.com) has a usage summary;
|
|
1984
|
+
// the sign-in lives in Cursor's own state database (state.vscdb, ItemTable key cursorAuth/accessToken).
|
|
1985
|
+
// The token is only sent to cursor.com and never leaves this computer otherwise; OwlMem gets the
|
|
1986
|
+
// percentages and reset times. No database / no sqlite / expired sign-in: no quota this round.
|
|
1987
|
+
export function cursorStateDb(home_ = home(), platform_ = process.platform, env = process.env) {
|
|
1988
|
+
if (platform_ === "darwin") return join(home_, "Library", "Application Support", "Cursor", "User", "globalStorage", "state.vscdb");
|
|
1989
|
+
if (platform_ === "win32") return join(env.APPDATA || join(home_, "AppData", "Roaming"), "Cursor", "User", "globalStorage", "state.vscdb");
|
|
1990
|
+
return join(home_, ".config", "Cursor", "User", "globalStorage", "state.vscdb");
|
|
1991
|
+
}
|
|
1992
|
+
export function cursorSession(jwt) {
|
|
1993
|
+
// the cookie value cursor.com's own dashboard sends: "<user id>%3A%3A<jwt>", user id = the part of
|
|
1994
|
+
// the token's "sub" claim after the last "|". Anything that isn't a JWT with a sub: null.
|
|
1995
|
+
if (typeof jwt !== "string") return null;
|
|
1996
|
+
const parts = jwt.split(".");
|
|
1997
|
+
if (parts.length !== 3) return null;
|
|
1998
|
+
let payload;
|
|
1999
|
+
try { payload = JSON.parse(Buffer.from(parts[1], "base64url").toString("utf8")); } catch { return null; }
|
|
2000
|
+
const sub = payload?.sub;
|
|
2001
|
+
if (typeof sub !== "string" || !sub) return null;
|
|
2002
|
+
return sub.split("|").pop() + "%3A%3A" + jwt;
|
|
2003
|
+
}
|
|
2004
|
+
export function cursorWindows(j) {
|
|
2005
|
+
if (j?.isUnlimited) return [];
|
|
2006
|
+
const start = Date.parse(j?.billingCycleStart), end = Date.parse(j?.billingCycleEnd);
|
|
2007
|
+
const used = j?.individualUsage?.plan?.totalPercentUsed;
|
|
2008
|
+
if (isNaN(start) || isNaN(end) || end <= start || typeof used !== "number") return [];
|
|
2009
|
+
return [{ minutes: Math.round((end - start) / 60000), used_percent: used, resets_at: Math.floor(end / 1000) }];
|
|
2010
|
+
}
|
|
2011
|
+
// The stored value is the token itself, or JSON holding it ({"accessToken": ...}); VS Code-style
|
|
2012
|
+
// databases sometimes double-encode it. Anything else: not a token.
|
|
2013
|
+
export function cursorTokenFromValue(v) {
|
|
2014
|
+
let x = v;
|
|
2015
|
+
for (let i = 0; i < 2 && typeof x === "string"; i++) { try { x = JSON.parse(x); } catch { break; } }
|
|
2016
|
+
if (typeof x === "string") return x || null;
|
|
2017
|
+
if (x && typeof x.accessToken === "string" && x.accessToken) return x.accessToken;
|
|
2018
|
+
return null;
|
|
2019
|
+
}
|
|
2020
|
+
async function cursorToken(db = cursorStateDb()) {
|
|
2021
|
+
if (!existsSync(db)) return null; // never create the file: the sqlite3 CLI would make an empty one
|
|
2022
|
+
let raw = null;
|
|
2023
|
+
try {
|
|
2024
|
+
const { DatabaseSync } = await import("node:sqlite");
|
|
2025
|
+
const d = new DatabaseSync(db, { readOnly: true });
|
|
2026
|
+
try { raw = d.prepare("SELECT value FROM ItemTable WHERE key = ?").get("cursorAuth/accessToken")?.value ?? null; }
|
|
2027
|
+
finally { d.close(); }
|
|
2028
|
+
} catch {}
|
|
2029
|
+
if (raw == null) {
|
|
2030
|
+
const r = spawnSync("sqlite3", [db, "SELECT value FROM ItemTable WHERE key='cursorAuth/accessToken';"], { encoding: "utf8", timeout: 10000 });
|
|
2031
|
+
if (r.status === 0 && r.stdout.trim()) raw = r.stdout.replace(/\n$/, "");
|
|
2032
|
+
}
|
|
2033
|
+
return cursorTokenFromValue(raw);
|
|
2034
|
+
}
|
|
2035
|
+
async function cursorQuota(fetchImpl = fetch) {
|
|
2036
|
+
const tok = await cursorToken().catch(() => null);
|
|
2037
|
+
const session = tok ? cursorSession(tok) : null;
|
|
2038
|
+
if (!session) return null;
|
|
2039
|
+
const r = await fetchImpl("https://cursor.com/api/usage-summary", { headers: { Cookie: "WorkosCursorSessionToken=" + session, "User-Agent": "owlmem-cli/" + VERSION }, signal: AbortSignal.timeout(15000) });
|
|
2040
|
+
if (!r.ok) return null;
|
|
2041
|
+
const w = cursorWindows(await r.json());
|
|
2042
|
+
return w.length ? w : null;
|
|
2043
|
+
}
|
|
1979
2044
|
async function usageTick(cfg, api, log, dir = DIR) {
|
|
1980
2045
|
const file = join(wakeDir(dir), "usage.json");
|
|
1981
2046
|
let state = {}; try { state = JSON.parse(readFileSync(file, "utf8")); } catch {}
|
|
@@ -1995,6 +2060,13 @@ async function usageTick(cfg, api, log, dir = DIR) {
|
|
|
1995
2060
|
if (r.status !== 200 && r.status !== 404) log("usage: OwlMem answered " + (r.data?.detail || "HTTP " + r.status));
|
|
1996
2061
|
}
|
|
1997
2062
|
}
|
|
2063
|
+
if (cfg.clients?.cursor) { // no transcripts to count here either, only its plan usage
|
|
2064
|
+
const w = await cursorQuota().catch(() => null);
|
|
2065
|
+
if (w) {
|
|
2066
|
+
const r = await api("usage", { days: {}, status: { cursor: { windows: w, limit_at: Math.floor(Date.now() / 1000) } } });
|
|
2067
|
+
if (r.status !== 200 && r.status !== 404) log("usage: OwlMem answered " + (r.data?.detail || "HTTP " + r.status));
|
|
2068
|
+
}
|
|
2069
|
+
}
|
|
1998
2070
|
if (!clients.length) return;
|
|
1999
2071
|
scanUsage(state, Object.fromEntries(Object.entries(usageRoots()).filter(([c]) => clients.includes(c))));
|
|
2000
2072
|
try { writeFileSync(file + ".tmp", JSON.stringify(state)); renameSync(file + ".tmp", file); } catch (e) { log("usage: " + e.message); }
|
|
@@ -2054,6 +2126,7 @@ async function wakeEnable(args = []) {
|
|
|
2054
2126
|
const bin = !clients[id] && wakeBin(c);
|
|
2055
2127
|
if (bin) clients[id] = { command: [bin, ...c.command.slice(1)], prompt: c.prompt };
|
|
2056
2128
|
}
|
|
2129
|
+
if (!clients.cursor && existsSync(cursorStateDb())) clients.cursor = {}; // Cursor: quota-only — no command to run, only its plan usage is reported
|
|
2057
2130
|
if (!Object.keys(clients).length) {
|
|
2058
2131
|
const told = await wakeNoClients(wakeApi()).catch(() => false);
|
|
2059
2132
|
throw new Fail("No AI command line found on this computer that auto-wake can start (Claude Code: claude, Codex: codex, Antigravity: agy, Hermes: hermes, DeepSeek Harness: dsh). Install one, or add its command to " + wakeFile() + " under \"clients\"." +
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "owlmem",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.24",
|
|
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" },
|