owlmem 0.9.35 → 0.9.37
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 +107 -8
- 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.37";
|
|
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();
|
|
@@ -524,18 +524,27 @@ export const SESSION_START_CONTEXT = "Before reading any code or files, search O
|
|
|
524
524
|
// `owlmem hook context-meter` shows the measured context length after each reply, so the
|
|
525
525
|
// AI quotes a number instead of guessing one. It reads the hook JSON on stdin
|
|
526
526
|
// (hook_event_name, transcript_path) and takes the length from the last non-sidechain
|
|
527
|
-
// assistant usage in the transcript (input + cache read + cache creation).
|
|
528
|
-
//
|
|
529
|
-
//
|
|
527
|
+
// assistant usage in the transcript (input + cache read + cache creation). A Codex rollout
|
|
528
|
+
// works too: the last token_count event's last_token_usage.input_tokens, with the window
|
|
529
|
+
// from that event (200k when it names none). Stop prints {"systemMessage": line};
|
|
530
|
+
// UserPromptSubmit prints additionalContext. Anything else prints nothing. Always
|
|
531
|
+
// offline, nothing on stderr, exit 0.
|
|
530
532
|
function contextMeterLine(payload) {
|
|
531
533
|
const p = payload?.transcript_path;
|
|
532
534
|
if (typeof p !== "string" || !p) return null;
|
|
533
535
|
let text;
|
|
534
536
|
try { text = readFileSync(p, "utf8"); } catch { return null; }
|
|
535
|
-
let tokens = null, over200k = false;
|
|
537
|
+
let tokens = null, over200k = false, codex = null;
|
|
536
538
|
for (const line of text.split("\n")) {
|
|
537
539
|
let e;
|
|
538
540
|
try { e = JSON.parse(line); } catch { continue; } // junk lines are skipped
|
|
541
|
+
if (e?.type === "event_msg" && e?.payload?.type === "token_count") {
|
|
542
|
+
// A Codex rollout line: the context length is the last turn's input tokens (cached input
|
|
543
|
+
// is already inside input_tokens; output tokens don't count). Null info / zero: not a reading.
|
|
544
|
+
const info = e?.payload?.info, n = info?.last_token_usage?.input_tokens;
|
|
545
|
+
if (info && typeof n === "number" && n > 0) codex = { tokens: n, window: info.model_context_window || 200000 };
|
|
546
|
+
continue;
|
|
547
|
+
}
|
|
539
548
|
if (e?.type !== "assistant" || e?.isSidechain) continue; // subagents don't count
|
|
540
549
|
const u = e?.message?.usage;
|
|
541
550
|
if (!u) continue;
|
|
@@ -544,8 +553,12 @@ function contextMeterLine(payload) {
|
|
|
544
553
|
if (sum > 200000) over200k = true;
|
|
545
554
|
tokens = sum; // keep the last one
|
|
546
555
|
}
|
|
547
|
-
|
|
548
|
-
|
|
556
|
+
let window;
|
|
557
|
+
if (codex) { tokens = codex.tokens; window = codex.window; } // a transcript is one app or the other
|
|
558
|
+
else {
|
|
559
|
+
if (tokens === null) return null;
|
|
560
|
+
window = over200k ? 1000000 : 200000;
|
|
561
|
+
}
|
|
549
562
|
const n = Math.round(tokens / 1000), pct = Math.round(tokens * 100 / window);
|
|
550
563
|
const icon = tokens < 80000 ? "🟢" : tokens < 150000 ? "🔵" : tokens < 180000 ? "🟡" : "🔴";
|
|
551
564
|
const advice = tokens < 80000 ? "Keep going." : tokens < 150000 ? "You may clear at the next task boundary." : tokens < 180000 ? "Consider clearing, even mid-task." : "Hand off and clear now.";
|
|
@@ -805,6 +818,53 @@ export function planSessionStartHook(uninstall) {
|
|
|
805
818
|
return { file, text: JSON.stringify(next, null, 2) + "\n" };
|
|
806
819
|
}
|
|
807
820
|
|
|
821
|
+
// Codex hooks: $CODEX_HOME/hooks.json (default ~/.codex/hooks.json) has the same shape as
|
|
822
|
+
// Claude Code's settings.json "hooks". Codex gets only the context meter (Stop +
|
|
823
|
+
// UserPromptSubmit) — it has no SessionStart search-first hook. A hook written by a
|
|
824
|
+
// program does not run until the person trusts it in Codex with /hooks, so install says
|
|
825
|
+
// so; install never writes trust state (no trusted_hash / hooks.state in config.toml).
|
|
826
|
+
function codexHooksFile() {
|
|
827
|
+
return join(process.env.CODEX_HOME || join(home(), ".codex"), "hooks.json");
|
|
828
|
+
}
|
|
829
|
+
export function planCodexHooks(uninstall) {
|
|
830
|
+
const file = codexHooksFile();
|
|
831
|
+
const text = readText(file);
|
|
832
|
+
let obj = {};
|
|
833
|
+
if (text !== null && text.trim()) {
|
|
834
|
+
try { obj = JSON.parse(text); } catch { return null; } // bad JSON: leave alone
|
|
835
|
+
if (!obj || typeof obj !== "object" || Array.isArray(obj)) return null;
|
|
836
|
+
}
|
|
837
|
+
if (obj.hooks !== undefined && (typeof obj.hooks !== "object" || Array.isArray(obj.hooks) || obj.hooks === null)) return null;
|
|
838
|
+
const hooks = obj.hooks || {};
|
|
839
|
+
const events = [
|
|
840
|
+
{ event: "Stop", ours: isContextMeterOurs, command: contextMeterCommand() },
|
|
841
|
+
{ event: "UserPromptSubmit", ours: isContextMeterOurs, command: contextMeterCommand() },
|
|
842
|
+
];
|
|
843
|
+
for (const { event } of events) {
|
|
844
|
+
if (hooks[event] !== undefined && !Array.isArray(hooks[event])) return null;
|
|
845
|
+
}
|
|
846
|
+
if (uninstall) {
|
|
847
|
+
if (!events.some(({ event, ours }) => (hooks[event] || []).some(ours))) return null;
|
|
848
|
+
const next = { ...obj, hooks: { ...hooks } };
|
|
849
|
+
for (const { event, ours } of events) {
|
|
850
|
+
if (hooks[event]) next.hooks[event] = hooks[event].filter((e) => !ours(e));
|
|
851
|
+
}
|
|
852
|
+
return { file, text: JSON.stringify(next, null, 2) + "\n" };
|
|
853
|
+
}
|
|
854
|
+
const next = { ...obj, hooks: { ...hooks } };
|
|
855
|
+
let changed = false;
|
|
856
|
+
for (const { event, ours, command } of events) {
|
|
857
|
+
const list = hooks[event] || [];
|
|
858
|
+
if (!list.some(ours)) {
|
|
859
|
+
next.hooks[event] = [...list, { hooks: [{ type: "command", command }] }];
|
|
860
|
+
changed = true;
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
if (!changed) return null; // already installed
|
|
864
|
+
return { file, text: JSON.stringify(next, null, 2) + "\n" };
|
|
865
|
+
}
|
|
866
|
+
const codexHooksPresent = () => (readText(codexHooksFile()) || "").includes("hook context-meter");
|
|
867
|
+
|
|
808
868
|
export function plan(opts = {}) {
|
|
809
869
|
const only = opts.only ? new Set(opts.only) : null;
|
|
810
870
|
const out = [];
|
|
@@ -825,6 +885,14 @@ export function plan(opts = {}) {
|
|
|
825
885
|
r.ops.push({ type: "write", file: hop.file, text: hop.text, hook: true });
|
|
826
886
|
}
|
|
827
887
|
}
|
|
888
|
+
if (c.id === "codex" && !opts.noRules && r.state !== "fail") {
|
|
889
|
+
const hop = planCodexHooks(opts.uninstall);
|
|
890
|
+
if (hop) {
|
|
891
|
+
if (!opts.uninstall) r.ops.unshift({ type: "copy", file: join(wakeDir(), "owlmem.mjs") });
|
|
892
|
+
r.ops.push({ type: "write", file: hop.file, text: hop.text, hook: true, codex: true });
|
|
893
|
+
}
|
|
894
|
+
if (!opts.uninstall) r.codexHooks = !!hop || codexHooksPresent();
|
|
895
|
+
}
|
|
828
896
|
out.push(r);
|
|
829
897
|
}
|
|
830
898
|
return out;
|
|
@@ -873,7 +941,8 @@ function describe(r, done, uninstall) {
|
|
|
873
941
|
for (const op of r.ops) {
|
|
874
942
|
if (op.type === "run" && !done) lines.push(" run: " + op.argv.join(" "));
|
|
875
943
|
if (op.rules) lines.push(` ${done ? "" : "will "}${uninstall ? (done ? "removed" : "remove") : (done ? "wrote" : "write")} the OwlMem rules block in ${tilde(op.file)}`);
|
|
876
|
-
if (op.hook) lines.push(` ${done ? "" : "will "}${uninstall ? (done ? "removed" : "remove") : (done ? "added" : "add")} the
|
|
944
|
+
if (op.hook && op.codex) lines.push(` ${done ? "" : "will "}${uninstall ? (done ? "removed" : "remove") : (done ? "added" : "add")} the context-meter hooks in ${tilde(op.file)} (Codex runs them only once you trust them with /hooks)`);
|
|
945
|
+
else if (op.hook) lines.push(` ${done ? "" : "will "}${uninstall ? (done ? "removed" : "remove") : (done ? "added" : "add")} the SessionStart and context-meter hooks in ${tilde(op.file)}`);
|
|
877
946
|
}
|
|
878
947
|
if (done && r.backups?.length) lines.push(" backup: " + r.backups.join(", "));
|
|
879
948
|
return lines.join("\n");
|
|
@@ -965,6 +1034,8 @@ function nextSteps(items, out) {
|
|
|
965
1034
|
out("Next: sign in once in each app. The first time an app uses OwlMem it opens the owlmem.com sign-in page —");
|
|
966
1035
|
out("sign in with your email (new accounts get a free space) and click \"Allow\". An AI can't click it for you.");
|
|
967
1036
|
for (const r of live) out(" • " + LOGIN[r.id]);
|
|
1037
|
+
if (live.some((r) => r.id === "codex" && r.codexHooks))
|
|
1038
|
+
out("Codex: the context-meter hooks in ~/.codex/hooks.json don't run until you trust them — open /hooks in Codex and trust the OwlMem entries.");
|
|
968
1039
|
if (live.some((r) => ["cursor", "vscode", "vscode-insiders", "windsurf"].includes(r.id)))
|
|
969
1040
|
out("Cursor, VS Code and Windsurf have no global rules file: add the rules from https://owlmem.com/docs#instructions to your project rules.");
|
|
970
1041
|
if (live.some((r) => r.id === "claude-desktop")) out("Claude Desktop: restart it to load OwlMem. (Or add https://mcp.owlmem.com/mcp under Settings → Connectors instead.)");
|
|
@@ -1398,9 +1469,37 @@ export function foregroundFirst(task) {
|
|
|
1398
1469
|
`;
|
|
1399
1470
|
}
|
|
1400
1471
|
|
|
1472
|
+
// A task handed out again after a clean exit while still "doing": the previous session probably started
|
|
1473
|
+
// background tests and its turn ended while waiting. Check whether the work is finished and mark it done,
|
|
1474
|
+
// or finish it — and run tests in the foreground, not the background, because nobody is watching.
|
|
1475
|
+
export function resumePrompt(task, place, o = {}) {
|
|
1476
|
+
const id = task.id, mins = o.timeout_min || WAKE_DEFAULTS.timeout_min;
|
|
1477
|
+
const where = place.worktree
|
|
1478
|
+
? `Work in ${place.cwd}. It is a separate git worktree of ${place.repo} on the branch ${place.branch}, made for this task so it doesn't collide with other work. Commit your changes on this branch only. Don't merge, rebase or push other branches, and don't touch ${place.repo} itself. Put the branch name in your result so a person can review and merge it.`
|
|
1479
|
+
: place.scratch ? `There is no project directory for this task: you are in an empty folder (${place.cwd}). Use the OwlMem tools.`
|
|
1480
|
+
: `Work in ${place.cwd}. Other tasks wait until you finish here.`;
|
|
1481
|
+
return `${limitedNote(task)}OwlMem auto-wake started you on ${o.machine || "this computer"} to resume a task that is already in doing. A previous session left it in doing and ended cleanly, so check first whether the work is already finished.
|
|
1482
|
+
|
|
1483
|
+
Task #${id}, for ${task.agent}${task.broadcast ? " (sent to every agent; it is yours once you take it)" : ""}, from ${task.from}:
|
|
1484
|
+
Title: ${task.title}
|
|
1485
|
+
|
|
1486
|
+
${task.body || "(no details)"}
|
|
1487
|
+
|
|
1488
|
+
Rules:
|
|
1489
|
+
1. The task is already in doing — don't take it again with kb_task_update. First check whether the work is finished: look for the pull request, the branch, and the task thread. If it is finished, call kb_task_update with id=${id}, status="done" and note = the result, then end.
|
|
1490
|
+
2. If it isn't finished, finish it: ${where}
|
|
1491
|
+
3. Run tests in the foreground, not in the background: nobody is watching this session, and a background test run ends your turn while the work is still unfinished. Wait for the tests to finish before you end.
|
|
1492
|
+
4. When you're finished, call kb_task_update with id=${id}, status="done" and note = the result (what you did, where it is).
|
|
1493
|
+
5. If you can't do it — including anything that needs a person to approve, sign in, enter a code or confirm — call kb_task_update with id=${id}, status="declined" and note = what a person needs to do. Don't try to get around a permission you don't have.
|
|
1494
|
+
6. Never put passwords, tokens, keys or other secrets in the note or in any message.
|
|
1495
|
+
7. You have ${mins} minutes. After that this session is stopped and the task is handed to a person.
|
|
1496
|
+
`;
|
|
1497
|
+
}
|
|
1498
|
+
|
|
1401
1499
|
export function wakePrompt(task, place, o = {}) {
|
|
1402
1500
|
if (isReply(task)) return limitedNote(task) + foregroundFirst(task) + replyPrompt(task, o);
|
|
1403
1501
|
if (isNote(task)) return limitedNote(task) + foregroundFirst(task) + notePrompt(task, place, o);
|
|
1502
|
+
if (task.resume) return resumePrompt(task, place, o);
|
|
1404
1503
|
const id = task.id, mins = o.timeout_min || WAKE_DEFAULTS.timeout_min;
|
|
1405
1504
|
const where = place.worktree
|
|
1406
1505
|
? `Work in ${place.cwd}. It is a separate git worktree of ${place.repo} on the branch ${place.branch}, made for this task so it doesn't collide with other work. Commit your changes on this branch only. Don't merge, rebase or push other branches, and don't touch ${place.repo} itself. Put the branch name in your result so a person can review and merge it.`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "owlmem",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.37",
|
|
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" },
|