owlmem 0.9.28 → 0.9.30

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 +140 -18
  2. package/package.json +1 -1
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.28";
47
+ export const VERSION = "0.9.30";
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();
@@ -877,6 +877,8 @@ export function allowCodex(home_ = home()) {
877
877
  return true;
878
878
  }
879
879
  // Antigravity's CLI reads ~/.gemini/antigravity-cli/settings.json: add only the rules for WAKE_TOOLS
880
+ // Is agy (Antigravity's command line) bound, not just the app? Only then are agy's settings touched.
881
+ export function agyCli(cl) { return Array.isArray(cl?.command) && cl.command.length > 0; }
880
882
  export function allowAntigravity(home_ = home()) {
881
883
  const f = join(home_, ".gemini", "antigravity-cli", "settings.json"), need = WAKE_TOOLS.map((n) => "mcp(owlmem/" + n + ")");
882
884
  let j = {};
@@ -1582,13 +1584,31 @@ export async function runTask(task, cfg, o = {}) {
1582
1584
  log("Foreground delivery failed for " + jobLabel(task) + " (" + d.detail + "); starting a headless session.");
1583
1585
  }
1584
1586
  }
1585
- if (!cl || !Array.isArray(cl.command) || !cl.command.length) return { outcome: "error", detail: "no command for " + task.client + " on this computer (wake.json)" };
1586
- const signIn = checkSignIn(task, cl, o);
1587
- if (!signIn.ok) { log("Not starting " + jobLabel(task) + ": " + signIn.detail); return { outcome: "error", detail: signIn.detail }; }
1587
+ const agyApp = task.client === "antigravity" && cl && cl.app !== false; // wake.json "app": false keeps agy -p only
1588
+ if (!agyApp && (!cl || !Array.isArray(cl.command) || !cl.command.length)) return { outcome: "error", detail: "no command for " + task.client + " on this computer (wake.json)" };
1589
+ if (!agyApp) {
1590
+ const signIn = checkSignIn(task, cl, o);
1591
+ if (!signIn.ok) { log("Not starting " + jobLabel(task) + ": " + signIn.detail); return { outcome: "error", detail: signIn.detail }; }
1592
+ }
1588
1593
  let place;
1589
1594
  try { const plan = o.plan || planWorkdir(task, o.home || home(), o.git); place = prepareWorkdir(task, plan, dir, o.git); if (plan.kind === "scratch") place.scratch = true; }
1590
1595
  catch (e) { return { outcome: "error", detail: e.message }; }
1591
1596
  const prompt = wakePrompt(task, place, { machine: cfg.machine, timeout_min: cfg.timeout_min });
1597
+ if (agyApp) { // 11-21: the Antigravity app (or agy hub) that's open here first; agy -p only when none answers
1598
+ const A = o.agyApp || {};
1599
+ const s = await (A.find || agyFind)().catch(() => null);
1600
+ if (s) {
1601
+ const r = await runAgyApp(task, prompt, { call: A.call || agyCall(s), model: cl.model, log, sleep: o.sleep, pollMs: o.pollMs, idlePolls: o.idlePolls,
1602
+ now: o.now, timeoutMs: o.timeoutMs ?? (cfg.timeout_min || WAKE_DEFAULTS.timeout_min) * 60000 });
1603
+ if (r.outcome !== "error" || r.cascade || !(cl.command || []).length) return r;
1604
+ log(jobLabel(task) + ": " + r.detail + "; trying agy instead.");
1605
+ } else if (!(cl.command || []).length) {
1606
+ if ((o.platform || platform()) === "darwin") { try { (A.open || (() => spawnSync("open", ["-a", "Antigravity"], { timeout: 15000 })))(); } catch {} }
1607
+ return { outcome: "error", detail: "Antigravity isn't open on this computer" + ((o.platform || platform()) === "darwin" ? " (opened it; the task will be sent again)" : "") };
1608
+ }
1609
+ const signIn = checkSignIn(task, cl, o);
1610
+ if (!signIn.ok) { log("Not starting " + jobLabel(task) + ": " + signIn.detail); return { outcome: "error", detail: signIn.detail }; }
1611
+ }
1592
1612
  const argv = [...wakeArgv(task.client, cl.command, task.trust, !!task.external), ...(cl.prompt === "arg" ? [prompt] : [])];
1593
1613
  mkdirSync(join(wakeDir(dir), "logs"), { recursive: true });
1594
1614
  const logPath = join(wakeDir(dir), "logs", jobName(task) + ".log");
@@ -1802,7 +1822,7 @@ export function wakeTools(cfg, home_ = home(), env = process.env) {
1802
1822
  let changed = false;
1803
1823
  if (i >= 0 && ours.includes(cmd[i + 1])) { cmd[i + 1] = now; changed = true; }
1804
1824
  if (cfg.clients?.codex) allowCodex(home_);
1805
- if (cfg.clients?.antigravity) allowAntigravity(home_);
1825
+ if (agyCli(cfg.clients?.antigravity)) allowAntigravity(home_); // only agy reads that file; the app alone doesn't (11-21)
1806
1826
  if (cfg.clients?.hermes) allowHermes(home_, env);
1807
1827
  return changed;
1808
1828
  }
@@ -1960,18 +1980,124 @@ async function claudeQuota(fetchImpl = fetch) {
1960
1980
  // Antigravity 1.5.9 (2026-11-14) stopped putting --csrf_token on the command line: the token is in the app's
1961
1981
  // daemon file ~/.gemini/antigravity/daemon/hub_<port>.json ("csrfToken") and in its environment. Read the file when
1962
1982
  // the command line has only the port.
1983
+ // 11-21: also the desktop app's own language server (language_server_macos_arm etc. under Antigravity.app), which carries
1984
+ // --csrf_token and its ports on the command line; that's how a Mac without agy is found (fabric's Cirila.local).
1985
+ // agyFind keeps only the ones that answer.
1963
1986
  export function agyServers(psOut, daemonDir = join(homedir(), ".gemini", "antigravity", "daemon")) {
1964
1987
  const out = [];
1988
+ const add = (port, token) => { port = Number(port); if (port > 0 && /^[\w-]{8,}$/.test(token || "") && !out.some((s) => s.port === port)) out.push({ port, token }); };
1965
1989
  for (const l of String(psOut || "").split("\n")) {
1966
- if (!/(^|\/)agy$/.test(l.trim().split(/\s/)[0] || "")) continue;
1967
- const port = /--hub-port[= ](\d{2,5})\b/.exec(l), tok = /--csrf_token[= ]([\w-]{8,})/.exec(l);
1968
- if (!port) continue;
1969
- let token = tok?.[1];
1970
- 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 {} }
1971
- if (token && !out.some((s) => s.port === Number(port[1]))) out.push({ port: Number(port[1]), token });
1990
+ const exe = l.trim().split(/\s/)[0] || "", tok = /--csrf_token[= ]([\w-]{8,})/.exec(l)?.[1];
1991
+ if (/(^|\/)agy$/.test(exe)) {
1992
+ const port = /--hub-port[= ](\d{2,5})\b/.exec(l);
1993
+ if (!port) continue;
1994
+ let token = tok;
1995
+ if (!token) { try { const d = JSON.parse(readFileSync(join(daemonDir, "hub_" + port[1] + ".json"), "utf8")); token = d?.csrfToken; } catch {} }
1996
+ add(port[1], token);
1997
+ } else if (/(^|\/)language_server[\w.-]*$/.test(exe) && /antigravity/i.test(l) && tok) {
1998
+ const before = out.length;
1999
+ for (const m of l.matchAll(/--(?:server_port|extension_server_port|http_server_port|lsp_port)[= ](\d{2,5})\b/g)) add(m[1], tok);
2000
+ // macOS app 2.33 (Cirila.local 11-21): no http port flag (only --https_server_port 0); the port is in its daemon file,
2001
+ // the one whose csrfToken is this process's token
2002
+ if (out.length === before) {
2003
+ try { for (const f of readdirSync(daemonDir)) if (/^hub_\d+\.json$/.test(f)) { try { const d = JSON.parse(readFileSync(join(daemonDir, f), "utf8")); if (d?.csrfToken === tok) add(d.httpPort, tok); } catch {} } } catch {}
2004
+ }
2005
+ }
1972
2006
  }
1973
2007
  return out;
1974
2008
  }
2009
+
2010
+ // ── Antigravity app without agy (11-21, owner: "有通用的方案…你自己做") ──
2011
+ // The task runs in the app (or agy hub) already open on this computer, through its local language server: the same calls
2012
+ // its chat panel makes. Found and tested on ori 11-21 (a woken conversation answered OwlMem note #4114 in 26 s by itself).
2013
+ export function agyAppInstalled(o = {}) {
2014
+ const plat = o.platform || platform(), h = o.home || home(), exists = o.exists || existsSync;
2015
+ if (plat !== "darwin") return false;
2016
+ return ["/Applications/Antigravity.app", join(h, "Applications", "Antigravity.app")].some((p) => exists(p));
2017
+ }
2018
+ // The apps auto-wake can start here, added to what wake.json already has (existing entries are left as they are).
2019
+ export function wakeClients(old = {}, o = {}) {
2020
+ const clients = { ...old }, h = o.home || home(), exists = o.exists || existsSync, path = o.path || onPath;
2021
+ for (const [id, c] of Object.entries(WAKE_CLIENTS)) {
2022
+ if (clients[id] || c.quotaOnly) continue;
2023
+ const bin = wakeBin(c, h, exists, path);
2024
+ if (id === "antigravity") {
2025
+ if (bin) clients[id] = { app: true, command: [bin, ...c.command.slice(1)], prompt: c.prompt };
2026
+ else if (agyAppInstalled({ platform: o.platform, home: h, exists })) clients[id] = { app: true, command: [], prompt: c.prompt };
2027
+ continue;
2028
+ }
2029
+ if (bin) clients[id] = { command: [bin, ...c.command.slice(1)], prompt: c.prompt };
2030
+ }
2031
+ return clients;
2032
+ }
2033
+ // Which model the woken conversation uses: wake.json clients.antigravity.model if the app offers it, else the first with
2034
+ // quota left, else the first.
2035
+ export function agyModel(userStatus, preferred) {
2036
+ const ms = userStatus?.userStatus?.cascadeModelConfigData?.clientModelConfigs || [];
2037
+ const id = (m) => m?.modelOrAlias?.model;
2038
+ if (preferred && ms.some((m) => id(m) === preferred)) return preferred;
2039
+ const left = ms.find((m) => id(m) && (m.quotaInfo?.remainingFraction ?? 1) > 0);
2040
+ return id(left) || id(ms.find((m) => id(m))) || null;
2041
+ }
2042
+ export function agyCall(s, fetchImpl = fetch) {
2043
+ return async (method, body = {}) => {
2044
+ const r = await fetchImpl("http://127.0.0.1:" + s.port + "/exa.language_server_pb.LanguageServerService/" + method, {
2045
+ method: "POST", headers: { "Content-Type": "application/json", "Connect-Protocol-Version": "1", "X-Codeium-Csrf-Token": s.token },
2046
+ body: JSON.stringify({ metadata: { ideName: "antigravity" }, ...body }), signal: AbortSignal.timeout(15000) });
2047
+ const j = await r.json().catch(() => null);
2048
+ if (!r.ok) throw new Error(method + ": " + (j?.message || "HTTP " + r.status));
2049
+ return j || {};
2050
+ };
2051
+ }
2052
+ // The first running app / agy hub that answers.
2053
+ export async function agyFind(fetchImpl = fetch) {
2054
+ if (process.platform === "win32") return null;
2055
+ const ps = spawnSync("ps", ["-axww", "-o", "args="], { encoding: "utf8", timeout: 10000 });
2056
+ for (const s of agyServers(ps.stdout)) { try { if ((await agyCall(s, fetchImpl)("GetUserStatus"))?.userStatus) return s; } catch {} }
2057
+ return null;
2058
+ }
2059
+ const AGY_IDLE = "CASCADE_RUN_STATUS_IDLE";
2060
+ // Run one task in the app. The run goes idle for a moment between steps, so it counts as finished only after idlePolls idle
2061
+ // answers in a row. Outcomes match runTask's: exit 0 (done), exit 1 (ended on an error step), timeout (cancelled), error.
2062
+ export async function runAgyApp(task, prompt, o = {}) {
2063
+ const call = o.call, sleep = o.sleep || ((ms) => new Promise((r) => setTimeout(r, ms))), now = o.now || Date.now;
2064
+ const pollMs = o.pollMs ?? 5000, idlePolls = o.idlePolls ?? 3, log = o.log || (() => {});
2065
+ const timeoutMs = o.timeoutMs ?? WAKE_DEFAULTS.timeout_min * 60000, waitApprovalMs = o.waitApprovalMs ?? 10 * 60000;
2066
+ let id;
2067
+ try {
2068
+ const model = agyModel(await call("GetUserStatus").catch(() => ({})), o.model);
2069
+ id = (await call("StartCascade", { source: "CORTEX_TRAJECTORY_SOURCE_CASCADE_CLIENT" }))?.cascadeId;
2070
+ if (!id) throw new Error("StartCascade: no conversation id");
2071
+ await call("SendUserCascadeMessage", { cascadeId: id, items: [{ text: prompt }],
2072
+ ...(model ? { cascadeConfig: { plannerConfig: { planModel: model, requestedModel: { model } } } } : {}) });
2073
+ log("Antigravity conversation " + id + (model ? " (" + model + ")" : "") + " started for " + jobLabel(task) + ".");
2074
+ } catch (e) { return { outcome: "error", detail: "Antigravity app: " + (e?.message || String(e)) }; }
2075
+ const t0 = now();
2076
+ let idle = 0, waitingSince = null;
2077
+ for (;;) {
2078
+ await sleep(pollMs);
2079
+ let st, steps = null;
2080
+ try { st = (await call("GetAllCascadeTrajectories"))?.trajectorySummaries?.[id]?.status; } catch { st = null; }
2081
+ const last = async () => { if (!steps) { try { steps = (await call("GetCascadeTrajectory", { cascadeId: id }))?.trajectory?.steps || []; } catch { steps = []; } } return steps[steps.length - 1]; };
2082
+ if (st === AGY_IDLE) {
2083
+ if (++idle >= idlePolls) {
2084
+ const s = await last();
2085
+ if (s?.type === "CORTEX_STEP_TYPE_ERROR_MESSAGE") return { outcome: "exit", code: 1, cascade: id, detail: "Antigravity: " + (s.errorMessage?.error?.shortError || s.errorMessage?.error?.userErrorMessage || "error") };
2086
+ return { outcome: "exit", code: 0, cascade: id };
2087
+ }
2088
+ continue;
2089
+ }
2090
+ idle = 0;
2091
+ if ((await last())?.status === "CORTEX_STEP_STATUS_WAITING") {
2092
+ waitingSince ??= now();
2093
+ if (now() - waitingSince >= waitApprovalMs) return { outcome: "error", cascade: id, detail: "Antigravity is waiting for someone to approve a step in conversation " + id };
2094
+ } else waitingSince = null;
2095
+ if (now() - t0 >= timeoutMs) {
2096
+ await call("CancelCascadeInvocation", { cascadeId: id }).catch(() => {});
2097
+ return { outcome: "timeout", cascade: id };
2098
+ }
2099
+ }
2100
+ }
1975
2101
  export function agyWindows(j) {
1976
2102
  const groups = {};
1977
2103
  for (const m of j?.userStatus?.cascadeModelConfigData?.clientModelConfigs || []) {
@@ -2189,19 +2315,15 @@ async function wakeEnable(args = []) {
2189
2315
  const num = (name, lo, hi) => { const i = args.indexOf(name); if (i < 0) return undefined; const n = Number(args[i + 1]); if (!Number.isInteger(n) || n < lo || n > hi) throw new Fail(`${name} takes a whole number from ${lo} to ${hi}.`); return n; };
2190
2316
  const max = num("--max", 1, 16), timeout = num("--timeout", 1, 240);
2191
2317
  const old = loadWake() || {};
2192
- const clients = { ...(old.clients || {}) };
2193
- for (const [id, c] of Object.entries(WAKE_CLIENTS)) {
2194
- const bin = !clients[id] && wakeBin(c);
2195
- if (bin) clients[id] = { command: [bin, ...c.command.slice(1)], prompt: c.prompt };
2196
- }
2318
+ const clients = wakeClients(old.clients || {});
2197
2319
  if (!clients.cursor && existsSync(cursorStateDb())) clients.cursor = {}; // Cursor: quota-only — no command to run, only its plan usage is reported
2198
2320
  if (!Object.keys(clients).length) {
2199
2321
  const told = await wakeNoClients(wakeApi()).catch(() => false);
2200
- 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\"." +
2322
+ throw new Fail("No AI command line found on this computer that auto-wake can start (Claude Code: claude, Codex: codex, Antigravity: agy or the Antigravity app on macOS, Hermes: hermes, DeepSeek Harness: dsh). Install one, or add its command to " + wakeFile() + " under \"clients\"." +
2201
2323
  (told ? "\nOwlMem support has been told; you'll hear from us once your AI app is supported." : ""));
2202
2324
  }
2203
2325
  if (clients.codex && allowCodex()) say("Let Codex report back to OwlMem when nobody is watching (tool approvals in ~/.codex/config.toml).");
2204
- if (clients.antigravity && allowAntigravity()) say("Let Antigravity's command line report back to OwlMem when nobody is watching (rules in ~/.gemini/antigravity-cli/settings.json).");
2326
+ if (agyCli(clients.antigravity) && allowAntigravity()) say("Let Antigravity's command line report back to OwlMem when nobody is watching (rules in ~/.gemini/antigravity-cli/settings.json).");
2205
2327
  if (clients.dsh) {
2206
2328
  const d = allowDsh();
2207
2329
  if (d === "init") say("DeepSeek Harness: run `dsh --profile headless --help` once to create its headless profile, then run this again.");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "owlmem",
3
- "version": "0.9.28",
3
+ "version": "0.9.30",
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" },