owlmem 0.9.26 → 0.9.27

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 +53 -1
  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.26";
47
+ export const VERSION = "0.9.27";
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();
@@ -1519,6 +1519,56 @@ export async function deliverForeground(task, cfg, o = {}) {
1519
1519
  return { ok: false, detail: tried.join("; ") || "no foreground method configured" };
1520
1520
  }
1521
1521
 
1522
+ // ── sign-in check before a headless start (0.9.27, #3928) ──
1523
+ // A woken AI acts through its own OwlMem connection. If that sign-in has lapsed it starts with no kb_* tools, spends its
1524
+ // tokens and quits, and OwlMem can only say it didn't pick the task up. So before starting Claude Code or Codex headless,
1525
+ // ask the client itself. Only a definite "not signed in" / "not set up" stops the start; anything uncertain (the check
1526
+ // failed, timed out, printed something unexpected, or the client has no check) lets it start as before.
1527
+ const INSTALL_FIX = "run `npx -y owlmem install` on this computer";
1528
+ function signInRun(sp = spawnSync) {
1529
+ return (argv) => sp(argv[0], argv.slice(1), { encoding: "utf8", timeout: 20000, windowsHide: true, shell: false, env: { ...process.env, OWLMEM_NO_BROWSER: "1" } });
1530
+ }
1531
+ export function owlmemSignIn(client, command, run, deps = {}) {
1532
+ const bin = Array.isArray(command) && command[0];
1533
+ const say = (name, what) => ({ ok: false, detail: `${name} is not signed in to OwlMem on this computer: ${what}` });
1534
+ if (!bin || (client !== "codex" && client !== "claude-code")) return { ok: true };
1535
+ run = run || signInRun(deps.spawnSync);
1536
+ try {
1537
+ if (client === "codex") {
1538
+ const r = run([bin, "mcp", "list", "--json"]);
1539
+ if (!r || r.error || r.status !== 0) return { ok: true };
1540
+ let list; try { list = JSON.parse(r.stdout || ""); } catch { return { ok: true }; }
1541
+ if (!Array.isArray(list)) return { ok: true };
1542
+ const s = list.find((x) => x && x.name === "owlmem");
1543
+ if (!s) return { ok: false, detail: `Codex has no OwlMem connection on this computer: ${INSTALL_FIX}` };
1544
+ if (s.enabled === false) return { ok: false, detail: "Codex has its OwlMem connection disabled on this computer: enable [mcp_servers.owlmem] in ~/.codex/config.toml" };
1545
+ if (String(s.auth_status || "").toLowerCase() === "not_logged_in") return say("Codex", "run `codex mcp login owlmem`, open the link and choose this AI's name");
1546
+ return { ok: true };
1547
+ }
1548
+ const r = run([bin, "mcp", "get", "owlmem"]);
1549
+ if (!r || r.error) return { ok: true };
1550
+ const out = (r.stdout || "") + "\n" + (r.stderr || "");
1551
+ if (/no mcp server found/i.test(out)) return { ok: false, detail: `Claude Code has no OwlMem connection on this computer: ${INSTALL_FIX}` };
1552
+ if (/^\s*status:.*needs authentication/im.test(out)) return say("Claude Code", "open Claude Code, run /mcp, pick owlmem and sign in with this AI's name");
1553
+ return { ok: true };
1554
+ } catch { return { ok: true }; }
1555
+ }
1556
+ const SIGNIN_OK_MS = 5 * 60 * 1000; // a good answer is reused for a few minutes; a bad one is asked again every time
1557
+ const signInOk = new Map();
1558
+ export function owlmemSignInCacheClear() { signInOk.clear(); }
1559
+ function checkSignIn(task, cl, o) {
1560
+ const check = o.loginCheck || (process.env.OWLMEM_TEST === "1" ? null : owlmemSignIn);
1561
+ if (!check) return { ok: true };
1562
+ const cache = o.loginCheck ? !!o.loginCache : true;
1563
+ const key = task.client + "\0" + cl.command[0];
1564
+ if (cache && (signInOk.get(key) || 0) > Date.now()) return { ok: true };
1565
+ let r;
1566
+ try { r = check(task.client, cl.command) || { ok: true }; } catch { return { ok: true }; }
1567
+ if (r.ok === false) { signInOk.delete(key); return r; }
1568
+ if (cache) signInOk.set(key, Date.now() + SIGNIN_OK_MS);
1569
+ return { ok: true };
1570
+ }
1571
+
1522
1572
  // ── running a task ──
1523
1573
  export async function runTask(task, cfg, o = {}) {
1524
1574
  const dir = o.dir || DIR, cl = (cfg.clients || {})[task.client];
@@ -1533,6 +1583,8 @@ export async function runTask(task, cfg, o = {}) {
1533
1583
  }
1534
1584
  }
1535
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 }; }
1536
1588
  let place;
1537
1589
  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; }
1538
1590
  catch (e) { return { outcome: "error", detail: e.message }; }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "owlmem",
3
- "version": "0.9.26",
3
+ "version": "0.9.27",
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" },