owlmem 0.9.25 → 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 (3) hide show
  1. package/README.md +1 -2
  2. package/owlmem.mjs +70 -6
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -58,8 +58,7 @@ npx -y owlmem wake disable # also done by npx -y owlmem uninstall
58
58
  Claude Code is only additionally allowed the two OwlMem tools it needs to report back (`kb_task_update`,
59
59
  `kb_inbox`). Anything that needs a person — an approval, a sign-in, a code — it declines, saying what to do.
60
60
  It is told never to put secrets in its result.
61
- - **Turning it off.** Each AI has an auto-wake switch in the console (AI agents → Agents), where you can also remove
62
- the computer. When the computer is removed, the AI is disconnected or the account is gone, the program gets a 401,
61
+ - **Turning it off.** Run `npx -y owlmem wake disable` on that computer, or remove the computer in the console (AI agents → Agents, Paired computers). When the computer is removed, the AI is disconnected or the account is gone, the program gets a 401,
63
62
  removes its own autostart entry and exits. The command for each app is in `~/.config/owlmem/wake/wake.json`;
64
63
  logs and worktrees stay in that folder after uninstalling.
65
64
  - **Plan usage.** The waker also reports each app's plan usage to OwlMem. Cursor:自动报套餐用量。
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.25";
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();
@@ -815,7 +815,7 @@ function nextSteps(items, out) {
815
815
  // needs a person, it declines with what the person has to do. When a task the agent gave out is done or declined, it is
816
816
  // woken too, to read the result (OwlMem sends those only to 0.7.7 and later).
817
817
  // This computer is identified by its device key (device.json); the pairing is approved in the console, where each AI has an
818
- // auto-wake switch and the computer can be removed. If OwlMem answers 401 (computer removed, AI disconnected, account gone)
818
+ // auto-wake is on by default for computer AIs, and the computer can be removed. If OwlMem answers 401 (computer removed, AI disconnected, account gone)
819
819
  // the program removes its own autostart entry and exits.
820
820
  // The OwlMem tools an unattended wake run may call without asking: answer the task, read its inbox, and send (report the
821
821
  // result to its person, hand work on). 0.7.8 added kb_send (站长 10-28).
@@ -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 }; }
@@ -2118,6 +2170,18 @@ export async function wakeNoClients(api, items = null) {
2118
2170
  return r.status === 200;
2119
2171
  }
2120
2172
 
2173
+ // #3936:已配对的电脑再配对,打出真实结果:绑上的列表 + 没对上的应用的补配链接(不再说去控制台拨开关,那个开关 0.82.0 就去掉了)。
2174
+ export function wakeActiveText(data) {
2175
+ const bound = (data.agents || []).map((x) => x.agent + " (" + x.client + ")").join(", ");
2176
+ let out = "Bound here: " + (bound || "nothing yet") + ". Auto-wake is on by default for these AIs; to turn it off, run: npx -y owlmem wake disable.";
2177
+ const un = data.unassigned || [];
2178
+ if (un.length && data.url) {
2179
+ out += "\nThese aren't assigned to an AI yet: " + un.join(", ") + ". Choose which AI each is:\n\n " + data.url +
2180
+ "\n\nCheck that the console shows this code: " + data.code;
2181
+ }
2182
+ return out;
2183
+ }
2184
+
2121
2185
  async function wakeEnable(args = []) {
2122
2186
  const boot = args.includes("--boot"), again = args.includes("--again");
2123
2187
  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; };
@@ -2165,7 +2229,7 @@ async function wakeEnable(args = []) {
2165
2229
  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." +
2166
2230
  "\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.)");
2167
2231
  openBrowser(r.data.url);
2168
- } else say("This computer is already paired (" + r.data.code + "). Turn auto-wake on or off for each AI in the console (AI agents → Agents).");
2232
+ } else say(wakeActiveText(r.data));
2169
2233
  }
2170
2234
 
2171
2235
  function wakeDisable(quiet = false) {
@@ -2196,10 +2260,10 @@ async function wakeStatus() {
2196
2260
  if (r.status === 401) say("OwlMem: this computer isn't paired any more. Pair it again: npx -y owlmem wake enable --again");
2197
2261
  else if (r.status !== 200) say("OwlMem: can't reach it (" + (r.data.detail || "HTTP " + r.status) + ")");
2198
2262
  else if (r.data.status === "pending") say("OwlMem: waiting for approval in the console" + (cfg.pair_url ? ": " + cfg.pair_url : "") + " (code " + r.data.code + ")");
2199
- else say("OwlMem: paired as " + r.data.code + ". " + r.data.agents.map((x) => x.agent + " (" + x.client + (x.wake ? "" : ", switched off") + ")").join(", "));
2263
+ else say("OwlMem: paired as " + r.data.code + ". " + r.data.agents.map((x) => x.agent + " (" + x.client + ")").join(", "));
2200
2264
  }
2201
2265
 
2202
- const WAKE_HELP = `Usage: npx -y owlmem wake <enable|disable|status>
2266
+ export const WAKE_HELP = `Usage: npx -y owlmem wake <enable|disable|status>
2203
2267
 
2204
2268
  Auto-wake starts the AI on this computer when it gets an OwlMem task (Claude Code with \`claude -p\`, Codex with
2205
2269
  \`codex exec\`, Antigravity with \`agy -p\`, Hermes with \`hermes -z\`), without you opening it. It runs in the background from login, for this user only.
@@ -2211,7 +2275,7 @@ Auto-wake starts the AI on this computer when it gets an OwlMem task (Claude Cod
2211
2275
  disable remove it from this computer (also done by npx -y owlmem uninstall)
2212
2276
  status show what's set up and what OwlMem says
2213
2277
 
2214
- Turn it off for one AI with the switch in the console (AI agents → Agents). Settings, including the command for
2278
+ Settings, including the command for
2215
2279
  each app ("claude-code", "codex", or your own under "gemini" / "custom"): ~/.config/owlmem/wake/wake.json`;
2216
2280
 
2217
2281
  async function wakeCmd(sub, args) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "owlmem",
3
- "version": "0.9.25",
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" },