owlmem 0.9.23 → 0.9.25
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 +3 -0
- package/owlmem.mjs +94 -11
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -43,6 +43,8 @@ npx -y owlmem wake disable # also done by npx -y owlmem uninstall
|
|
|
43
43
|
|
|
44
44
|
- **Pairing.** `wake enable` prints a link: open it, check the code matches, and pick which AI each app on this
|
|
45
45
|
computer is. Until then nothing starts. The computer is identified by its device key (next to `config.json`).
|
|
46
|
+
已登录时配对自动批准:if this computer is already logged in (`owlmem login`), pairing is approved automatically
|
|
47
|
+
and the apps are matched to your AIs by their app names — no console step.
|
|
46
48
|
- **Runs as you.** A systemd user service (Linux), a LaunchAgent (macOS) or a logon task (Windows) — this user
|
|
47
49
|
only, no admin rights. `--boot` (Linux) turns on lingering so it runs from boot, not just from login.
|
|
48
50
|
- **One program per computer** for every paired AI. One task at a time per AI, at most 2 at once (`--max`),
|
|
@@ -60,6 +62,7 @@ npx -y owlmem wake disable # also done by npx -y owlmem uninstall
|
|
|
60
62
|
the computer. When the computer is removed, the AI is disconnected or the account is gone, the program gets a 401,
|
|
61
63
|
removes its own autostart entry and exits. The command for each app is in `~/.config/owlmem/wake/wake.json`;
|
|
62
64
|
logs and worktrees stay in that folder after uninstalling.
|
|
65
|
+
- **Plan usage.** The waker also reports each app's plan usage to OwlMem. Cursor:自动报套餐用量。
|
|
63
66
|
|
|
64
67
|
## Vault
|
|
65
68
|
|
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.25";
|
|
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();
|
|
@@ -180,6 +180,8 @@ function token() {
|
|
|
180
180
|
if (!t) throw new Fail("No token. Create one for this agent in the console (AI agents & tokens), then run: owlmem login");
|
|
181
181
|
return t;
|
|
182
182
|
}
|
|
183
|
+
// wake enable 用的 AI 令牌:环境变量没有就读 config.json(owlmem login 存的),都没有回 null,不抛错。
|
|
184
|
+
export function wakeAiToken() { return process.env.OWLMEM_TOKEN || cfg().token || null; }
|
|
183
185
|
function spaceKey(space) {
|
|
184
186
|
const p = join(DIR, "keys", space + ".key");
|
|
185
187
|
if (!existsSync(p)) throw new Fail("This machine doesn't have the space key yet. Run: owlmem vault unlock");
|
|
@@ -846,8 +848,12 @@ export const WAKE_CLIENTS = {
|
|
|
846
848
|
// closes stdin. Full: --auto; limited: file edits, shell and web fetches denied through OPENCODE_CONFIG_CONTENT (wakeEnv).
|
|
847
849
|
// Tested 11-03 against a local OwlMem with opencode 1.19.5: full did the task; limited refused a shell command and declined.
|
|
848
850
|
opencode: { name: "opencode", bin: "opencode", command: ["opencode", "run"], prompt: "arg", home: [[".opencode", "bin", "opencode"]] },
|
|
851
|
+
// Cursor: quota-only (0.9.24) — no headless command to run a task, only its plan usage is reported. The waker
|
|
852
|
+
// never starts it; the server never sends it a task (hub/wake.py QUOTA_ONLY). `wake enable` offers it when
|
|
853
|
+
// Cursor's own state database exists on this computer.
|
|
854
|
+
cursor: { name: "Cursor", quotaOnly: true },
|
|
849
855
|
};
|
|
850
|
-
export const WAKE_APP_IDS = ["claude-code", "codex", "antigravity", "hermes", "dsh", "opencode", "gemini", "custom"];
|
|
856
|
+
export const WAKE_APP_IDS = ["claude-code", "codex", "antigravity", "hermes", "dsh", "opencode", "gemini", "custom", "cursor"];
|
|
851
857
|
// Where an app's command is: on PATH, or the first of its default install places that exists (path parts under your home
|
|
852
858
|
// folder, or an absolute path), used by full path
|
|
853
859
|
export function wakeBin(c, home_ = home(), exists = existsSync, path = onPath) {
|
|
@@ -1710,12 +1716,12 @@ export function wakeRestart(o = {}) {
|
|
|
1710
1716
|
}
|
|
1711
1717
|
|
|
1712
1718
|
function wakeApi() {
|
|
1713
|
-
return async (sub, body) => {
|
|
1719
|
+
return async (sub, body, extra) => {
|
|
1714
1720
|
const url = BASE + "/v1/wake/" + sub;
|
|
1715
1721
|
let r;
|
|
1716
1722
|
try {
|
|
1717
1723
|
const sh = await signHeaders("POST", url, "other");
|
|
1718
|
-
r = await fetch(url, { method: "POST", headers: { "Content-Type": "application/json", "User-Agent": "owlmem-cli/" + VERSION, ...sh },
|
|
1724
|
+
r = await fetch(url, { method: "POST", headers: { "Content-Type": "application/json", "User-Agent": "owlmem-cli/" + VERSION, ...sh, ...(extra || {}) },
|
|
1719
1725
|
body: JSON.stringify(body || {}), signal: AbortSignal.timeout(90000) });
|
|
1720
1726
|
} catch (e) { return { status: 0, data: { detail: e.message } }; }
|
|
1721
1727
|
return { status: r.status, data: await r.json().catch(() => ({})) };
|
|
@@ -1976,6 +1982,67 @@ async function dshBalance(fetchImpl = fetch, home = homedir()) {
|
|
|
1976
1982
|
if (!r.ok) return null;
|
|
1977
1983
|
return dshBalanceFrom(await r.json());
|
|
1978
1984
|
}
|
|
1985
|
+
// Cursor's plan usage (0.9.24, owner 11-17): Cursor's own dashboard (cursor.com) has a usage summary;
|
|
1986
|
+
// the sign-in lives in Cursor's own state database (state.vscdb, ItemTable key cursorAuth/accessToken).
|
|
1987
|
+
// The token is only sent to cursor.com and never leaves this computer otherwise; OwlMem gets the
|
|
1988
|
+
// percentages and reset times. No database / no sqlite / expired sign-in: no quota this round.
|
|
1989
|
+
export function cursorStateDb(home_ = home(), platform_ = process.platform, env = process.env) {
|
|
1990
|
+
if (platform_ === "darwin") return join(home_, "Library", "Application Support", "Cursor", "User", "globalStorage", "state.vscdb");
|
|
1991
|
+
if (platform_ === "win32") return join(env.APPDATA || join(home_, "AppData", "Roaming"), "Cursor", "User", "globalStorage", "state.vscdb");
|
|
1992
|
+
return join(home_, ".config", "Cursor", "User", "globalStorage", "state.vscdb");
|
|
1993
|
+
}
|
|
1994
|
+
export function cursorSession(jwt) {
|
|
1995
|
+
// the cookie value cursor.com's own dashboard sends: "<user id>%3A%3A<jwt>", user id = the part of
|
|
1996
|
+
// the token's "sub" claim after the last "|". Anything that isn't a JWT with a sub: null.
|
|
1997
|
+
if (typeof jwt !== "string") return null;
|
|
1998
|
+
const parts = jwt.split(".");
|
|
1999
|
+
if (parts.length !== 3) return null;
|
|
2000
|
+
let payload;
|
|
2001
|
+
try { payload = JSON.parse(Buffer.from(parts[1], "base64url").toString("utf8")); } catch { return null; }
|
|
2002
|
+
const sub = payload?.sub;
|
|
2003
|
+
if (typeof sub !== "string" || !sub) return null;
|
|
2004
|
+
return sub.split("|").pop() + "%3A%3A" + jwt;
|
|
2005
|
+
}
|
|
2006
|
+
export function cursorWindows(j) {
|
|
2007
|
+
if (j?.isUnlimited) return [];
|
|
2008
|
+
const start = Date.parse(j?.billingCycleStart), end = Date.parse(j?.billingCycleEnd);
|
|
2009
|
+
const used = j?.individualUsage?.plan?.totalPercentUsed;
|
|
2010
|
+
if (isNaN(start) || isNaN(end) || end <= start || typeof used !== "number") return [];
|
|
2011
|
+
return [{ minutes: Math.round((end - start) / 60000), used_percent: used, resets_at: Math.floor(end / 1000) }];
|
|
2012
|
+
}
|
|
2013
|
+
// The stored value is the token itself, or JSON holding it ({"accessToken": ...}); VS Code-style
|
|
2014
|
+
// databases sometimes double-encode it. Anything else: not a token.
|
|
2015
|
+
export function cursorTokenFromValue(v) {
|
|
2016
|
+
let x = v;
|
|
2017
|
+
for (let i = 0; i < 2 && typeof x === "string"; i++) { try { x = JSON.parse(x); } catch { break; } }
|
|
2018
|
+
if (typeof x === "string") return x || null;
|
|
2019
|
+
if (x && typeof x.accessToken === "string" && x.accessToken) return x.accessToken;
|
|
2020
|
+
return null;
|
|
2021
|
+
}
|
|
2022
|
+
async function cursorToken(db = cursorStateDb()) {
|
|
2023
|
+
if (!existsSync(db)) return null; // never create the file: the sqlite3 CLI would make an empty one
|
|
2024
|
+
let raw = null;
|
|
2025
|
+
try {
|
|
2026
|
+
const { DatabaseSync } = await import("node:sqlite");
|
|
2027
|
+
const d = new DatabaseSync(db, { readOnly: true });
|
|
2028
|
+
try { raw = d.prepare("SELECT value FROM ItemTable WHERE key = ?").get("cursorAuth/accessToken")?.value ?? null; }
|
|
2029
|
+
finally { d.close(); }
|
|
2030
|
+
} catch {}
|
|
2031
|
+
if (raw == null) {
|
|
2032
|
+
const r = spawnSync("sqlite3", [db, "SELECT value FROM ItemTable WHERE key='cursorAuth/accessToken';"], { encoding: "utf8", timeout: 10000 });
|
|
2033
|
+
if (r.status === 0 && r.stdout.trim()) raw = r.stdout.replace(/\n$/, "");
|
|
2034
|
+
}
|
|
2035
|
+
return cursorTokenFromValue(raw);
|
|
2036
|
+
}
|
|
2037
|
+
async function cursorQuota(fetchImpl = fetch) {
|
|
2038
|
+
const tok = await cursorToken().catch(() => null);
|
|
2039
|
+
const session = tok ? cursorSession(tok) : null;
|
|
2040
|
+
if (!session) return null;
|
|
2041
|
+
const r = await fetchImpl("https://cursor.com/api/usage-summary", { headers: { Cookie: "WorkosCursorSessionToken=" + session, "User-Agent": "owlmem-cli/" + VERSION }, signal: AbortSignal.timeout(15000) });
|
|
2042
|
+
if (!r.ok) return null;
|
|
2043
|
+
const w = cursorWindows(await r.json());
|
|
2044
|
+
return w.length ? w : null;
|
|
2045
|
+
}
|
|
1979
2046
|
async function usageTick(cfg, api, log, dir = DIR) {
|
|
1980
2047
|
const file = join(wakeDir(dir), "usage.json");
|
|
1981
2048
|
let state = {}; try { state = JSON.parse(readFileSync(file, "utf8")); } catch {}
|
|
@@ -1995,6 +2062,13 @@ async function usageTick(cfg, api, log, dir = DIR) {
|
|
|
1995
2062
|
if (r.status !== 200 && r.status !== 404) log("usage: OwlMem answered " + (r.data?.detail || "HTTP " + r.status));
|
|
1996
2063
|
}
|
|
1997
2064
|
}
|
|
2065
|
+
if (cfg.clients?.cursor) { // no transcripts to count here either, only its plan usage
|
|
2066
|
+
const w = await cursorQuota().catch(() => null);
|
|
2067
|
+
if (w) {
|
|
2068
|
+
const r = await api("usage", { days: {}, status: { cursor: { windows: w, limit_at: Math.floor(Date.now() / 1000) } } });
|
|
2069
|
+
if (r.status !== 200 && r.status !== 404) log("usage: OwlMem answered " + (r.data?.detail || "HTTP " + r.status));
|
|
2070
|
+
}
|
|
2071
|
+
}
|
|
1998
2072
|
if (!clients.length) return;
|
|
1999
2073
|
scanUsage(state, Object.fromEntries(Object.entries(usageRoots()).filter(([c]) => clients.includes(c))));
|
|
2000
2074
|
try { writeFileSync(file + ".tmp", JSON.stringify(state)); renameSync(file + ".tmp", file); } catch (e) { log("usage: " + e.message); }
|
|
@@ -2054,6 +2128,7 @@ async function wakeEnable(args = []) {
|
|
|
2054
2128
|
const bin = !clients[id] && wakeBin(c);
|
|
2055
2129
|
if (bin) clients[id] = { command: [bin, ...c.command.slice(1)], prompt: c.prompt };
|
|
2056
2130
|
}
|
|
2131
|
+
if (!clients.cursor && existsSync(cursorStateDb())) clients.cursor = {}; // Cursor: quota-only — no command to run, only its plan usage is reported
|
|
2057
2132
|
if (!Object.keys(clients).length) {
|
|
2058
2133
|
const told = await wakeNoClients(wakeApi()).catch(() => false);
|
|
2059
2134
|
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\"." +
|
|
@@ -2072,17 +2147,20 @@ async function wakeEnable(args = []) {
|
|
|
2072
2147
|
if (h === true) say("Let Hermes report back to OwlMem when nobody is watching (entries under command_allowlist in ~/.hermes/config.yaml).");
|
|
2073
2148
|
else if (h === "manual") say("Hermes treats OwlMem as untrusted: add mcp:<server>/kb_task_update, mcp:<server>/kb_inbox and mcp:<server>/kb_send to command_allowlist in ~/.hermes/config.yaml, or it can't report back when nobody is watching.");
|
|
2074
2149
|
}
|
|
2075
|
-
const
|
|
2150
|
+
const wakeCfg = { v: 1, ...WAKE_DEFAULTS, ...old, machine: process.env.OWLMEM_DEVICE_NAME || hostname(), clients, ...(max ? { max_parallel: max } : {}), ...(timeout ? { timeout_min: timeout } : {}), boot: boot || !!old.boot };
|
|
2076
2151
|
// OwlMem knows these app names; a command you add yourself to wake.json goes under "gemini" or "custom"
|
|
2077
|
-
|
|
2152
|
+
// 本机已登录(owlmem login 存了 AI 令牌)就带上:服务端自动批准配对,不用去控制台(令牌只放 Authorization 头,不写日志)
|
|
2153
|
+
const aiToken = wakeAiToken();
|
|
2154
|
+
const r = await wakeApi()("pair", { clients: Object.keys(clients).filter((c) => WAKE_APP_IDS.includes(c)), force: again },
|
|
2155
|
+
aiToken ? { Authorization: "Bearer " + aiToken } : undefined);
|
|
2078
2156
|
if (r.status !== 200) throw new Fail("OwlMem didn't accept the pairing: " + (r.data.detail || r.data.error || "HTTP " + r.status));
|
|
2079
2157
|
mkdirSync(wakeDir(), { recursive: true });
|
|
2080
2158
|
copyFileSync(fileURLToPath(import.meta.url), join(wakeDir(), "owlmem.mjs")); // the service runs this copy (npx's cache can be cleaned out)
|
|
2081
|
-
if (r.data.status === "pending")
|
|
2082
|
-
saveWake(DIR,
|
|
2083
|
-
const a = installAutostart(autostartOpts(DIR, { boot:
|
|
2159
|
+
if (r.data.status === "pending") wakeCfg.pair_url = r.data.url; else delete wakeCfg.pair_url;
|
|
2160
|
+
saveWake(DIR, wakeCfg);
|
|
2161
|
+
const a = installAutostart(autostartOpts(DIR, { boot: wakeCfg.boot }));
|
|
2084
2162
|
say("Auto-wake is installed (" + a.kind + ": " + tilde(a.file) + ").");
|
|
2085
|
-
say("Apps it can start here: " + Object.keys(clients).map((c) => WAKE_CLIENTS[c]?.name || c).join(", ") + ". At most " +
|
|
2163
|
+
say("Apps it can start here: " + Object.keys(clients).map((c) => WAKE_CLIENTS[c]?.name || c).join(", ") + ". At most " + wakeCfg.max_parallel + " at once, " + wakeCfg.timeout_min + " minutes per task.");
|
|
2086
2164
|
if (r.data.status === "pending") {
|
|
2087
2165
|
say("\nApprove this computer in the OwlMem console and pick which AI each app is:\n\n " + r.data.url + "\n\nCheck that the console shows this code: " + r.data.code + "\nUntil then auto-wake waits and starts nothing." +
|
|
2088
2166
|
"\n(If you're an AI agent running this: send the link and the code to the person who turned auto-wake on, with kb_send.)");
|
|
@@ -2103,11 +2181,16 @@ function wakeDisable(quiet = false) {
|
|
|
2103
2181
|
});
|
|
2104
2182
|
}
|
|
2105
2183
|
|
|
2184
|
+
// wake status 的「Apps:」那行(0.9.25):只报额度的应用没有 command,写「usage only」,不碰 command。
|
|
2185
|
+
export function wakeAppsLine(clients) {
|
|
2186
|
+
return Object.entries(clients || {}).map(([k, v]) => k + " → " + ((v?.quotaOnly || WAKE_CLIENTS[k]?.quotaOnly) ? "usage only" : (v?.command || []).join(" "))).join("; ");
|
|
2187
|
+
}
|
|
2188
|
+
|
|
2106
2189
|
async function wakeStatus() {
|
|
2107
2190
|
const cfg = loadWake(), a = autostart(autostartOpts());
|
|
2108
2191
|
if (!cfg) { say("Auto-wake isn't set up on this computer. Turn it on: npx -y owlmem wake enable"); return; }
|
|
2109
2192
|
say("Autostart: " + (existsSync(a.file) ? a.kind + " (" + tilde(a.file) + ")" : "missing"));
|
|
2110
|
-
say("Apps: " +
|
|
2193
|
+
say("Apps: " + wakeAppsLine(cfg.clients || {}));
|
|
2111
2194
|
say("At most " + cfg.max_parallel + " at once, " + cfg.timeout_min + " minutes per task. Log: " + tilde(join(wakeDir(), "wake.log")));
|
|
2112
2195
|
const r = await wakeApi()("poll", { wait: 0, slots: 0 });
|
|
2113
2196
|
if (r.status === 401) say("OwlMem: this computer isn't paired any more. Pair it again: npx -y owlmem wake enable --again");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "owlmem",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.25",
|
|
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" },
|