omo-memory 0.1.10 → 0.1.12

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/dist/hooks.js DELETED
@@ -1,198 +0,0 @@
1
- import { spawnSync } from "node:child_process";
2
- import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
3
- import { homedir } from "node:os";
4
- import { dirname, join } from "node:path";
5
- import { CODEX_AGENTS_BLOCK, CODEX_HOOKS_JSON, CODEX_MARKETPLACE, CODEX_PLUGIN, CODEX_PLUGIN_JSON, CODEX_SKILL, GROK_AGENTS_BLOCK, GROK_HOOK_SCRIPT, GROK_HOOKS_JSON, GROK_MCP_JSON, GROK_PLUGIN_JSON, GROK_SKILL, SESSION_BOOTSTRAP_SCRIPT, } from "./hookTemplates.js";
6
- const BLOCK_START = "<!-- omo-memory:start -->";
7
- const BLOCK_END = "<!-- omo-memory:end -->";
8
- export function installHooks(input) {
9
- const home = process.env["OMO_MEMORY_INSTALL_HOME"] ?? homedir();
10
- return { home, installed: targetsFor(input.host).map((target) => installTarget(target, home)) };
11
- }
12
- function targetsFor(host) {
13
- if (host === "all")
14
- return ["codex", "grok"];
15
- return [host];
16
- }
17
- function installTarget(host, home) {
18
- if (host === "codex")
19
- return installCodex(home);
20
- return installGrok(home);
21
- }
22
- function installCodex(home) {
23
- const skillPath = join(home, ".codex", "skills", "omo-memory", "SKILL.md");
24
- const agentsPath = join(home, ".codex", "AGENTS.md");
25
- const marketplacePath = join(home, ".codex", "local-marketplaces", CODEX_MARKETPLACE);
26
- const marketplaceJsonPath = join(marketplacePath, "marketplace.json");
27
- const agentsMarketplaceJsonPath = join(marketplacePath, ".agents", "plugins", "marketplace.json");
28
- const pluginRoot = join(marketplacePath, "plugins", CODEX_PLUGIN);
29
- const pluginJsonPath = join(pluginRoot, ".codex-plugin", "plugin.json");
30
- const pluginSkillPath = join(pluginRoot, "skills", "omo-memory", "SKILL.md");
31
- const hookJsonPath = join(pluginRoot, "hooks", "hooks.json");
32
- const hookScriptPath = join(pluginRoot, "scripts", "omo-memory-session.mjs");
33
- const configPath = join(home, ".codex", "config.toml");
34
- writeText(skillPath, CODEX_SKILL);
35
- upsertAgentsBlock(agentsPath, CODEX_AGENTS_BLOCK);
36
- writeText(pluginJsonPath, CODEX_PLUGIN_JSON);
37
- writeText(pluginSkillPath, CODEX_SKILL);
38
- writeText(hookJsonPath, CODEX_HOOKS_JSON);
39
- writeText(hookScriptPath, SESSION_BOOTSTRAP_SCRIPT);
40
- chmodSync(hookScriptPath, 0o755);
41
- upsertMarketplace(marketplaceJsonPath, { withInterface: false });
42
- upsertMarketplace(agentsMarketplaceJsonPath, { withInterface: true });
43
- upsertCodexConfig(configPath, marketplacePath);
44
- const pluginAddNote = maybeInstallCodexPlugin(home);
45
- return {
46
- host: "codex",
47
- files: [skillPath, agentsPath, pluginJsonPath, pluginSkillPath, hookJsonPath, hookScriptPath, marketplaceJsonPath, agentsMarketplaceJsonPath, configPath],
48
- notes: [
49
- "Codex MCP still needs `codex mcp add omo-memory -- npx -y omo-memory mcp` if it is not already present.",
50
- "Codex plugin hooks are installed through the local islee23520 marketplace and enabled in ~/.codex/config.toml.",
51
- pluginAddNote,
52
- "Codex may ask to trust the new hook command on first execution unless hook trust has already been granted.",
53
- ],
54
- };
55
- }
56
- function installGrok(home) {
57
- const skillPath = join(home, ".grok", "skills", "omo-memory", "SKILL.md");
58
- const agentsPath = join(home, ".grok", "AGENTS.md");
59
- const hookScriptPath = join(home, ".grok", "hooks", "omo-memory-session.mjs");
60
- const hookJsonPath = join(home, ".grok", "hooks", "omo-memory-hooks.json");
61
- const pluginRoot = join(home, ".grok", "plugins", "omo-memory");
62
- const pluginJsonPath = join(pluginRoot, "plugin.json");
63
- const pluginSkillPath = join(pluginRoot, "skills", "omo-memory", "SKILL.md");
64
- const pluginHookJsonPath = join(pluginRoot, "hooks", "hooks.json");
65
- const pluginHookScriptPath = join(pluginRoot, "scripts", "omo-memory-session.mjs");
66
- const pluginMcpPath = join(pluginRoot, ".mcp.json");
67
- writeText(skillPath, GROK_SKILL);
68
- upsertAgentsBlock(agentsPath, GROK_AGENTS_BLOCK);
69
- writeText(hookScriptPath, GROK_HOOK_SCRIPT);
70
- chmodSync(hookScriptPath, 0o755);
71
- writeText(hookJsonPath, GROK_HOOKS_JSON.replace("{{HOME}}", home));
72
- writeText(pluginJsonPath, GROK_PLUGIN_JSON);
73
- writeText(pluginSkillPath, GROK_SKILL);
74
- writeText(pluginHookJsonPath, GROK_HOOKS_JSON.replace(`node \\"{{HOME}}/.grok/hooks/omo-memory-session.mjs\\"`, `node \\"${pluginHookScriptPath}\\"`));
75
- writeText(pluginHookScriptPath, GROK_HOOK_SCRIPT);
76
- chmodSync(pluginHookScriptPath, 0o755);
77
- writeText(pluginMcpPath, GROK_MCP_JSON);
78
- const pluginInstallNote = maybeInstallGrokPlugin(home, pluginRoot);
79
- return {
80
- host: "grok",
81
- files: [skillPath, agentsPath, hookScriptPath, hookJsonPath, pluginJsonPath, pluginSkillPath, pluginHookJsonPath, pluginHookScriptPath, pluginMcpPath],
82
- notes: ["Grok plugin bundle installed at ~/.grok/plugins/omo-memory.", pluginInstallNote],
83
- };
84
- }
85
- function writeText(path, text) {
86
- mkdirSync(dirname(path), { recursive: true });
87
- writeFileSync(path, text, "utf8");
88
- }
89
- function upsertMarketplace(path, input) {
90
- const marketplace = readMarketplace(path, input.withInterface);
91
- const plugins = marketplace.plugins.filter((plugin) => plugin.name !== CODEX_PLUGIN);
92
- const omoMemory = marketplacePlugin(input.withInterface);
93
- const next = { ...marketplace, plugins: [...plugins, omoMemory] };
94
- writeText(path, `${JSON.stringify(next, null, 2)}\n`);
95
- }
96
- function readMarketplace(path, withInterface) {
97
- if (!existsSync(path))
98
- return defaultMarketplace(withInterface);
99
- const parsed = JSON.parse(readFileSync(path, "utf8"));
100
- if (!isMarketplace(parsed))
101
- return defaultMarketplace(withInterface);
102
- return parsed;
103
- }
104
- function defaultMarketplace(withInterface) {
105
- return {
106
- name: CODEX_MARKETPLACE,
107
- ...(withInterface ? { interface: { displayName: CODEX_MARKETPLACE } } : {}),
108
- plugins: [],
109
- };
110
- }
111
- function marketplacePlugin(withPolicy) {
112
- return {
113
- name: CODEX_PLUGIN,
114
- source: { source: "local", path: "./plugins/omo-memory" },
115
- ...(withPolicy ? { policy: { installation: "AVAILABLE", authentication: "ON_INSTALL" }, category: "Developer Tools" } : {}),
116
- };
117
- }
118
- function isMarketplace(value) {
119
- if (!isRecord(value) || value["name"] !== CODEX_MARKETPLACE || !Array.isArray(value["plugins"]))
120
- return false;
121
- return value["plugins"].every(isMarketplacePlugin);
122
- }
123
- function isMarketplacePlugin(value) {
124
- if (!isRecord(value) || typeof value["name"] !== "string" || !isRecord(value["source"]))
125
- return false;
126
- const source = value["source"];
127
- return source["source"] === "local" && typeof source["path"] === "string";
128
- }
129
- function isRecord(value) {
130
- return typeof value === "object" && value !== null;
131
- }
132
- function upsertCodexConfig(path, marketplacePath) {
133
- const existing = existsSync(path) ? readFileSync(path, "utf8") : "";
134
- const withHooks = ensureTomlKey(existing, "[features]", "plugin_hooks = true");
135
- const withMarketplace = ensureTomlTable(withHooks, `[marketplaces.${CODEX_MARKETPLACE}]`, `source_type = "local"\nsource = "${escapeTomlString(marketplacePath)}"`);
136
- writeText(path, ensureTomlTable(withMarketplace, `[plugins."${CODEX_PLUGIN}@${CODEX_MARKETPLACE}"]`, "enabled = true"));
137
- }
138
- function maybeInstallCodexPlugin(home) {
139
- if (home !== homedir())
140
- return "Skipped `codex plugin add` because OMO_MEMORY_INSTALL_HOME points at a test/alternate home.";
141
- const result = spawnSync("codex", ["plugin", "add", `${CODEX_PLUGIN}@${CODEX_MARKETPLACE}`, "--json"], {
142
- encoding: "utf8",
143
- stdio: ["ignore", "pipe", "pipe"],
144
- timeout: 15000,
145
- });
146
- if (result.status === 0)
147
- return "`codex plugin add omo-memory@islee23520 --json` completed successfully.";
148
- const detail = result.error instanceof Error ? result.error.message : result.stderr.trim();
149
- return `Could not run \`codex plugin add omo-memory@islee23520 --json\`: ${detail || "unknown error"}. Run it manually if Codex still reports the plugin as not installed.`;
150
- }
151
- function maybeInstallGrokPlugin(home, pluginRoot) {
152
- if (home !== homedir())
153
- return "Skipped `grok plugin install` because OMO_MEMORY_INSTALL_HOME points at a test/alternate home.";
154
- const result = spawnSync("grok", ["plugin", "install", pluginRoot, "--trust"], {
155
- encoding: "utf8",
156
- stdio: ["ignore", "pipe", "pipe"],
157
- timeout: 15000,
158
- });
159
- if (result.status === 0)
160
- return "`grok plugin install ~/.grok/plugins/omo-memory --trust` completed successfully.";
161
- const detail = result.error instanceof Error ? result.error.message : result.stderr.trim();
162
- return `Could not run \`grok plugin install ~/.grok/plugins/omo-memory --trust\`: ${detail || "unknown error"}. Run it manually if Grok still reports the plugin as not installed.`;
163
- }
164
- function ensureTomlKey(text, table, keyValue) {
165
- if (text.includes(keyValue))
166
- return text;
167
- if (!text.includes(table))
168
- return appendTomlTable(text, table, keyValue);
169
- const start = text.indexOf(table);
170
- const nextTable = text.indexOf("\n[", start + table.length);
171
- const insertAt = nextTable === -1 ? text.length : nextTable;
172
- return `${text.slice(0, insertAt).trimEnd()}\n${keyValue}\n${text.slice(insertAt).trimStart()}`;
173
- }
174
- function ensureTomlTable(text, table, body) {
175
- if (text.includes(table))
176
- return text;
177
- return appendTomlTable(text, table, body);
178
- }
179
- function appendTomlTable(text, table, body) {
180
- const prefix = text.trimEnd();
181
- const separator = prefix.length === 0 ? "" : "\n\n";
182
- return `${prefix}${separator}${table}\n${body}\n`;
183
- }
184
- function escapeTomlString(value) {
185
- return value.replaceAll("\\", "\\\\").replaceAll('"', '\\"');
186
- }
187
- function upsertAgentsBlock(path, block) {
188
- const existing = existsSync(path) ? readFileSync(path, "utf8") : "";
189
- const wrapped = `${BLOCK_START}\n${block}\n${BLOCK_END}`;
190
- const start = existing.indexOf(BLOCK_START);
191
- const end = existing.indexOf(BLOCK_END);
192
- if (start !== -1 && end > start) {
193
- writeText(path, `${existing.slice(0, start)}${wrapped}${existing.slice(end + BLOCK_END.length)}`);
194
- return;
195
- }
196
- const separator = existing.trim().length === 0 ? "" : "\n\n";
197
- writeText(path, `${existing.trimEnd()}${separator}${wrapped}\n`);
198
- }