owlmem 0.9.31 → 0.9.32
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/owlmem.mjs +68 -11
- 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.
|
|
47
|
+
export const VERSION = "0.9.32";
|
|
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();
|
|
@@ -1421,18 +1421,29 @@ export function foregroundMethods(client, cfg = {}) {
|
|
|
1421
1421
|
return [];
|
|
1422
1422
|
}
|
|
1423
1423
|
|
|
1424
|
+
// The project directory a job routes by (0.9.32, #4596): a task or a note names it in its own text
|
|
1425
|
+
// (full trust only — outside work never picks a terminal); a reply routes by the task it answers,
|
|
1426
|
+
// never by its own text. Null means "any terminal, as before".
|
|
1427
|
+
export function foregroundDir(task, h = home()) {
|
|
1428
|
+
if (task.trust !== TRUST_FULL) return null;
|
|
1429
|
+
if (isReply(task)) return task.task_cwd ? taskDir("cwd: " + task.task_cwd, h) : null;
|
|
1430
|
+
return taskDir(task.body, h);
|
|
1431
|
+
}
|
|
1432
|
+
|
|
1424
1433
|
// Short wake note for a foreground session: what arrived, and to read it with kb_inbox (that marks it
|
|
1425
1434
|
// read). Not the full payload — the session reads the rest itself.
|
|
1426
1435
|
export function foregroundNote(task, o = {}) {
|
|
1427
1436
|
const mins = o.timeout_min || WAKE_DEFAULTS.timeout_min;
|
|
1428
1437
|
if (isReply(task)) {
|
|
1429
1438
|
const done = task.result === "done";
|
|
1430
|
-
|
|
1431
|
-
|
|
1439
|
+
// 0.9.32 (#4596): name the one item (kb_inbox id=N), so the session reads and marks only that one —
|
|
1440
|
+
// a plain kb_inbox would read and mark another project's mail.
|
|
1441
|
+
if (task.zh) return `奥麦自动唤醒:回信 #${task.id}——你派的任务 #${task.task_id}「${task.task_title || ""}」有了结果:${shortName(task.by)}${done ? "完成" : "拒绝"}了。用 kb_inbox id=${task.id} 看这封回信(会标成已读);需要接着做(换人派、把结果告诉站长、自己补做)就做,没有要做的就结束,不要发消息。`;
|
|
1442
|
+
return `OwlMem auto-wake: reply #${task.id} — the task you gave out, #${task.task_id} "${task.task_title || ""}", was ${done ? "finished" : "declined"} by ${shortName(task.by)}. Read it with kb_inbox id=${task.id} (that marks it read); if something needs doing next, do it, otherwise just end and don't send any message.`;
|
|
1432
1443
|
}
|
|
1433
1444
|
if (isNote(task)) {
|
|
1434
|
-
if (task.zh) return `奥麦自动唤醒:留言 #${task.id}——${shortName(task.from)}:${task.title}。用 kb_inbox 看这条留言(会标成已读);要你做事就做完、用 kb_send 回结果,不用做就结束,不要发消息。`;
|
|
1435
|
-
return `OwlMem auto-wake: note #${task.id} from ${shortName(task.from)}: ${task.title}. Read it with kb_inbox (that marks it read); if it asks you to do something, do it and report back with kb_send, otherwise just end and don't send a message.`;
|
|
1445
|
+
if (task.zh) return `奥麦自动唤醒:留言 #${task.id}——${shortName(task.from)}:${task.title}。用 kb_inbox id=${task.id} 看这条留言(会标成已读);要你做事就做完、用 kb_send 回结果,不用做就结束,不要发消息。`;
|
|
1446
|
+
return `OwlMem auto-wake: note #${task.id} from ${shortName(task.from)}: ${task.title}. Read it with kb_inbox id=${task.id} (that marks it read); if it asks you to do something, do it and report back with kb_send, otherwise just end and don't send a message.`;
|
|
1436
1447
|
}
|
|
1437
1448
|
if (task.zh) return `奥麦自动唤醒:任务 #${task.id}「${task.title}」等你处理(${shortName(task.from)}派来)。用 kb_task_update 接(doing),做完标 done、做不了标 declined,结果写进 note。你有 ${mins} 分钟。`;
|
|
1438
1449
|
return `OwlMem auto-wake: task #${task.id} "${task.title}" is waiting for you (from ${shortName(task.from)}). Take it with kb_task_update (doing), mark it done when finished or declined if you can't, with the result in the note. You have ${mins} minutes.`;
|
|
@@ -1473,7 +1484,12 @@ export function listClaudeSessions(o = {}) {
|
|
|
1473
1484
|
if (!pid || !alivePid(pid, o)) continue;
|
|
1474
1485
|
let mtime = 0;
|
|
1475
1486
|
try { mtime = statSync(sock).mtimeMs; } catch {}
|
|
1476
|
-
|
|
1487
|
+
// 0.9.32 (#4596): the session's working directory (realpath, "" when the record has none) and its
|
|
1488
|
+
// busy/idle status, so a woken job can be routed to the terminal working in its project.
|
|
1489
|
+
let cwd = "";
|
|
1490
|
+
if (typeof rec.cwd === "string" && rec.cwd) { try { cwd = realpathSync(rec.cwd); } catch {} }
|
|
1491
|
+
out.push({ pid, sock, name: typeof rec.name === "string" ? rec.name : "", updatedAt: Number(rec.updatedAt) || 0, mtime,
|
|
1492
|
+
cwd, status: typeof rec.status === "string" ? rec.status : "" });
|
|
1477
1493
|
}
|
|
1478
1494
|
out.sort((a, b) => (b.updatedAt - a.updatedAt) || (b.mtime - a.mtime) || (b.pid - a.pid));
|
|
1479
1495
|
return out;
|
|
@@ -1531,12 +1547,47 @@ export async function sendClaudeSocket(sock, text, o = {}) {
|
|
|
1531
1547
|
});
|
|
1532
1548
|
}
|
|
1533
1549
|
|
|
1534
|
-
//
|
|
1550
|
+
// A directory's git repository, by its common git dir (0.9.32, #4596): the same repository from any
|
|
1551
|
+
// subfolder and from any of its worktrees resolves to the same realpath. Null when the directory is
|
|
1552
|
+
// not in a git repository (or doesn't exist). `git rev-parse --git-common-dir` prints a path relative
|
|
1553
|
+
// to the directory it ran in (".git", "../.git") or absolute (a worktree), so resolve it against `dir`.
|
|
1554
|
+
function gitCommonDir(dir, git = gitRun) {
|
|
1555
|
+
let st = null; try { st = statSync(dir); } catch {}
|
|
1556
|
+
if (!st || !st.isDirectory()) return null;
|
|
1557
|
+
const r = git(["-C", dir, "rev-parse", "--git-common-dir"]);
|
|
1558
|
+
if (!r.ok || !r.out) return null;
|
|
1559
|
+
const common = r.out.split("\n")[0].trim();
|
|
1560
|
+
if (!common) return null;
|
|
1561
|
+
const abs = isAbsolute(common) ? common : join(dir, common);
|
|
1562
|
+
try { return realpathSync(abs); } catch { return null; }
|
|
1563
|
+
}
|
|
1564
|
+
|
|
1565
|
+
// Is a session's working directory inside the job's project? A git repository counts as one project
|
|
1566
|
+
// across its subfolders and all its worktrees (same git-common-dir); a plain folder means that folder
|
|
1567
|
+
// or below it, matched on a path-segment boundary, so a sibling that only starts the same ("elsewhere"
|
|
1568
|
+
// vs "else") is not inside.
|
|
1569
|
+
function inProject(sessionCwd, dir, git = gitRun) {
|
|
1570
|
+
const dirGit = gitCommonDir(dir, git);
|
|
1571
|
+
if (dirGit) return gitCommonDir(sessionCwd, git) === dirGit;
|
|
1572
|
+
return sessionCwd === dir || sessionCwd.startsWith(dir + "/");
|
|
1573
|
+
}
|
|
1574
|
+
|
|
1575
|
+
// claude-socket: idle sessions before busy ones, then most recently active; the next if a socket won't
|
|
1576
|
+
// take it. With o.dir, only sessions working in that project; no session there fails and sends nothing
|
|
1577
|
+
// anywhere, so a job never lands in another project's terminal (#4596).
|
|
1535
1578
|
export async function deliverClaudeSocket(note, o = {}) {
|
|
1536
1579
|
const sessions = listClaudeSessions(o);
|
|
1537
|
-
|
|
1580
|
+
let dir = null;
|
|
1581
|
+
if (o.dir) { try { dir = realpathSync(o.dir); } catch { dir = o.dir; } }
|
|
1582
|
+
let pool = sessions;
|
|
1583
|
+
if (dir) {
|
|
1584
|
+
pool = sessions.filter((s) => s.cwd && inProject(s.cwd, dir));
|
|
1585
|
+
if (!pool.length) return { ok: false, detail: "no Claude Code session in " + dir };
|
|
1586
|
+
}
|
|
1587
|
+
if (!pool.length) return { ok: false, detail: "no live Claude Code session on this computer" };
|
|
1588
|
+
pool.sort((a, b) => ((a.status === "idle" ? 0 : 1) - (b.status === "idle" ? 0 : 1)) || (b.updatedAt - a.updatedAt) || (b.mtime - a.mtime) || (b.pid - a.pid));
|
|
1538
1589
|
const tried = [];
|
|
1539
|
-
for (const s of
|
|
1590
|
+
for (const s of pool) {
|
|
1540
1591
|
const r = await sendClaudeSocket(s.sock, note, o);
|
|
1541
1592
|
if (r.ok) return { ok: true, detail: "Claude Code session " + (s.name || s.pid) };
|
|
1542
1593
|
tried.push((s.name || s.pid) + ": " + r.detail);
|
|
@@ -1569,11 +1620,15 @@ export async function runForegroundCommand(method, text, o = {}) {
|
|
|
1569
1620
|
}
|
|
1570
1621
|
|
|
1571
1622
|
// Try the configured foreground methods in order; the first success counts as delivered.
|
|
1623
|
+
// The job's project directory (foregroundDir, or o.projectDir when the caller already worked it out)
|
|
1624
|
+
// is passed to the socket method, so it only goes to a session in that project (#4596); without one,
|
|
1625
|
+
// any session, as before. o.dir here is the wake directory, not the project — never pass it through.
|
|
1572
1626
|
export async function deliverForeground(task, cfg, o = {}) {
|
|
1573
1627
|
const note = o.note ?? foregroundNote(task, { timeout_min: cfg.timeout_min });
|
|
1628
|
+
const dir = o.projectDir !== undefined ? o.projectDir : foregroundDir(task, o.home);
|
|
1574
1629
|
const tried = [];
|
|
1575
1630
|
for (const m of foregroundMethods(task.client, cfg)) {
|
|
1576
|
-
const r = m.type === "claude-socket" ? await deliverClaudeSocket(note, o) : await runForegroundCommand(m, note, o);
|
|
1631
|
+
const r = m.type === "claude-socket" ? await deliverClaudeSocket(note, { ...o, dir }) : await runForegroundCommand(m, note, o);
|
|
1577
1632
|
if (r.ok) return { ok: true, method: m.type, detail: r.detail || "" };
|
|
1578
1633
|
tried.push(m.type + ": " + (r.detail || "failed"));
|
|
1579
1634
|
}
|
|
@@ -1638,7 +1693,9 @@ export async function runTask(task, cfg, o = {}) {
|
|
|
1638
1693
|
const methods = foregroundMethods(task.client, cfg);
|
|
1639
1694
|
if (task.foreground_tried) log("Foreground delivery was already tried for " + jobLabel(task) + "; starting a headless session."); // #1870:前台送过一次没接,这次直接无头
|
|
1640
1695
|
else if (methods.length) {
|
|
1641
|
-
|
|
1696
|
+
// #4596: the job's project directory rides along, so it only goes to a session in that project;
|
|
1697
|
+
// no session there fails the foreground step and the job starts headless, as before (one log line).
|
|
1698
|
+
const d = await deliverForeground(task, cfg, { ...o, projectDir: foregroundDir(task, o.home || home()) });
|
|
1642
1699
|
if (d.ok) return { outcome: "foreground", detail: "delivered to the foreground (" + d.method + (d.detail ? ": " + d.detail : "") + ")" };
|
|
1643
1700
|
log("Foreground delivery failed for " + jobLabel(task) + " (" + d.detail + "); starting a headless session.");
|
|
1644
1701
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "owlmem",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.32",
|
|
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" },
|