ei-tui 1.6.0 → 1.6.2

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/README.md CHANGED
@@ -1,12 +1,12 @@
1
1
  # Ei
2
2
 
3
- A local-first AI companion system with persistent personas and coding tool integrations (OpenCode, Claude Code, Cursor).
3
+ A local-first AI companion system with persistent personas and coding tool integrations (OpenCode, Claude Code, Cursor, Codex).
4
4
 
5
5
  You can access the Web version at [ei.flare576.com](https://ei.flare576.com).
6
6
 
7
7
  You can run the local version via `bunx ei-tui` — no install needed, always current (see [### TUI](#tui) for details).
8
8
 
9
- If you're here to give your coding tools (OpenCode, Claude Code, Cursor) persistent memory, jump over to [TUI README.md](./tui/README.md) to learn how to get information _into_ Ei, and [CLI README.md](./src/cli/README.md) to wire up automatic context injection so your agents receive relevant memory before every message — no tool calls required.
9
+ If you're here to give your coding tools (OpenCode, Claude Code, Cursor, Codex) persistent memory, jump over to [TUI README.md](./tui/README.md) to learn how to get information _into_ Ei, and [CLI README.md](./src/cli/README.md) to wire up MCP/context injection so your agents can read relevant memory when they need it.
10
10
 
11
11
  ## What Does "Local First" Mean?
12
12
 
@@ -83,7 +83,7 @@ Ei can operate with three types of input, and three types of output.
83
83
  ^
84
84
  Sessions
85
85
  |
86
- [OpenCode / Claude Code / Cursor]
86
+ [OpenCode / Claude Code / Cursor / Codex]
87
87
  ```
88
88
 
89
89
  ```
@@ -91,7 +91,7 @@ Ei can operate with three types of input, and three types of output.
91
91
  |
92
92
  CLI Data
93
93
  v
94
- [OpenCode]
94
+ [OpenCode / Claude Code / Cursor / Codex]
95
95
  ```
96
96
 
97
97
  Optionally, users can opt into a server-side data sync. This is ideal for users who want to use multiple devices or switch between TUI and Web throughout the day. All data is encrypted _before_ being sent to the server, using a key that only the user can generate (your `username` and `passphrase` never leave your device - I couldn't decrypt your data if I wanted to).
@@ -129,7 +129,7 @@ More information (including commands) can be found in the [TUI Readme](tui/READM
129
129
 
130
130
  Ei can import sessions from your coding tools and extract what you've been working on — pulling out facts, topics, and context that persist across sessions. Enable any combination; they work independently and feed into the same knowledge base.
131
131
 
132
- All three integrations are enabled via `/settings` in the TUI.
132
+ All four integrations are enabled via `/settings` in the TUI.
133
133
 
134
134
  #### OpenCode
135
135
 
@@ -165,6 +165,21 @@ Reads from Cursor's SQLite databases:
165
165
 
166
166
  All sessions map to a single "Cursor" persona.
167
167
 
168
+ #### Codex
169
+
170
+ ```yaml
171
+ codex:
172
+ integration: true
173
+ ```
174
+
175
+ Reads from Codex's local state database and rollout JSONL files:
176
+ - `~/.codex/state_*.sqlite`
177
+ - `~/.codex/sessions/`
178
+
179
+ All sessions map to a single "Codex" persona. Codex may store thread-level agent metadata for custom agents, but rollout messages do not reliably expose per-message sub-agent speaker identity yet. Tool calls, prompt scaffolding, and token-count events are stripped — only visible user/agent messages are imported.
180
+
181
+ Codex can also read Ei's knowledge back out. Run `ei --install` to register the Ei MCP server and install a Codex `UserPromptSubmit` hook that injects relevant memory before each message, using your current prompt plus recent Codex transcript context when available.
182
+
168
183
  ---
169
184
 
170
185
  Sessions are processed oldest-first, one per queue cycle, so Ei won't overwhelm your LLM provider on first run. See [TUI Readme](tui/README.md)
@@ -233,7 +248,7 @@ Personas can use tools. Not just read-from-memory tools — *actual* tools. Web
233
248
  |------|-------------|
234
249
  | `find_memory` | Semantic search of your personal memory — facts, traits, topics, people, quotes. Personas call this automatically when the conversation touches something they might know about you. Supports the `persona` filter to scope results to what a specific persona has learned. |
235
250
  | `fetch_memory` | Full-record lookup for a specific human entity (Fact, Topic, Person, or Quote) by ID. Use after `find_memory` to retrieve complete details. |
236
- | `fetch_message` | Retrieve a specific message by ID with optional surrounding context. Searches persona conversations and room messages. |
251
+ | `fetch_message` | Retrieve a specific message by fully-qualified ID with optional surrounding context. Searches Ei conversations and supported external coding-session stores. |
237
252
  | `file_read` | Read a file from your local filesystem *(TUI only)* |
238
253
  | `list_directory` | Explore folder structure *(TUI only)* |
239
254
  | `directory_tree` | Recursive directory tree *(TUI only)* |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ei-tui",
3
- "version": "1.6.0",
3
+ "version": "1.6.2",
4
4
  "author": "Flare576",
5
5
  "repository": {
6
6
  "type": "git",
package/src/cli/README.md CHANGED
@@ -15,8 +15,8 @@ ei --recent # Most recently mentioned items (no query
15
15
  ei --persona "Beta" --recent # Most recently mentioned items Beta has learned
16
16
  ei --id <id> # Look up entity by ID — or fetch a message by FQ ID
17
17
  echo <id> | ei --id # Look up entity by ID from stdin
18
- ei --install # Wire Ei into Claude Code, Cursor, and OpenCode (MCP + hooks + persona plugin)
19
- ei mcp # Start the Ei MCP stdio server (for Cursor/Claude Desktop)
18
+ ei --install # Wire Ei into Claude Code, Cursor, Codex, and OpenCode (MCP + hooks + persona plugin)
19
+ ei mcp # Start the Ei MCP stdio server (for Claude Code/Cursor/Codex)
20
20
  ```
21
21
 
22
22
  Type aliases: `fact`, `person`, `topic`, `quote`, `persona` all work (singular or plural).
@@ -35,6 +35,7 @@ It also resolves fully-qualified message IDs from any supported integration, ret
35
35
  ei --id "opencode:jeremys-macbook-pro:ses_38a7...:msg_c75b..."
36
36
  ei --id "claudecode:my-machine:session-uuid:message-uuid"
37
37
  ei --id "cursor:my-machine:composer-uuid:bubble-uuid"
38
+ ei --id "codex:my-machine:thread-uuid:evt_42"
38
39
  ```
39
40
 
40
41
  Quotes surfaced by `ei_search` include a `message_id` field in this format — pipe it to `ei --id` to read the original conversation.
@@ -47,15 +48,16 @@ Quotes surfaced by `ei_search` include a `message_id` field in this format — p
47
48
  ei --install
48
49
  ```
49
50
 
50
- This registers Ei with Claude Code, Cursor, and OpenCode — MCP server config, context injection hooks, and (for OpenCode) a persona identity plugin so agents know who they are before the first message:
51
+ This registers Ei with Claude Code, Cursor, Codex, and OpenCode — MCP server config, context injection hooks where supported, and (for OpenCode) a persona identity plugin so agents know who they are before the first message:
51
52
 
52
53
  | Tool | MCP | Context Hook | Persona Plugin |
53
54
  |------|-----|-------------|----------------|
54
55
  | **Claude Code** | `~/.claude.json` | `~/.claude/settings.json` (`UserPromptSubmit`) + `~/.claude/hooks/ei-inject.ts` | — |
55
56
  | **Cursor** | `~/.cursor/mcp.json` | `~/.cursor/hooks.json` (`beforeSubmitPrompt`) + `~/.cursor/hooks/ei-inject.sh` | — |
57
+ | **Codex** | `~/.codex/config.toml` via `codex mcp add ei` | `~/.codex/hooks.json` (`UserPromptSubmit`) + `~/.codex/hooks/ei-inject.ts` | Local Codex agent plugin if installed separately |
56
58
  | **OpenCode** | manual (see below) | Via Oh My OpenCode compatibility layer (reads `~/.claude/settings.json`) | `~/.config/opencode/plugins/ei-persona.ts` |
57
59
 
58
- **Context hook**: fires before every message, searches Ei for topics relevant to what you just asked, injects them silently. No tool call required.
60
+ **Context hook**: fires before every message, searches Ei for relevant memory, and injects it silently. No tool call required.
59
61
 
60
62
  **Persona plugin** (OpenCode + [Oh My OpenCode](https://github.com/code-yeongyu/oh-my-opencode) only): injects the agent's Ei relationship record directly into the system prompt at session start — traits, working style, shared context. The agent knows who it is *to you* before it reads a word of your message.
61
63
 
@@ -80,7 +82,7 @@ Restart your agent tool after changes to activate.
80
82
 
81
83
  ### MCP Server
82
84
 
83
- Claude Code and Cursor call `ei mcp` to start the MCP stdio server. You can run it directly to test:
85
+ Claude Code, Cursor, and Codex call `ei mcp` to start the MCP stdio server. You can run it directly to test:
84
86
 
85
87
  ```sh
86
88
  ei mcp
@@ -97,7 +99,7 @@ The `ei_search`, `ei_lookup`, and `ei_fetch_message` MCP tools are still availab
97
99
 
98
100
  ## MCP Tools Reference
99
101
 
100
- The MCP server exposes these tools to Claude Code, Cursor, and OpenCode:
102
+ The MCP server exposes these tools to Claude Code, Cursor, Codex, and OpenCode:
101
103
 
102
104
  | Tool | Description |
103
105
  |------|-------------|
@@ -112,7 +114,7 @@ The MCP server exposes these tools to Claude Code, Cursor, and OpenCode:
112
114
  | `query` | string (optional) | Search text. Omit to browse by recency. |
113
115
  | `type` | enum (optional) | `facts` \| `people` \| `topics` \| `quotes` \| `personas` — omit for balanced results across all types |
114
116
  | `persona` | string (optional) | Persona display_name to scope results to what that persona has learned |
115
- | `source` | string (optional) | Prefix match against source identifiers (e.g. `opencode`, `cursor:my-machine`) |
117
+ | `source` | string (optional) | Prefix match against source identifiers (e.g. `opencode`, `cursor:my-machine`, `codex:my-machine`) |
116
118
  | `limit` | number (optional) | Max results, default 10 |
117
119
  | `recent` | boolean (optional) | Sort by most recently mentioned instead of relevance |
118
120
 
package/src/cli/mcp.ts CHANGED
@@ -37,7 +37,7 @@ export function createMcpServer(): McpServer {
37
37
  .string()
38
38
  .optional()
39
39
  .describe(
40
- "Filter to entities from a specific source. Prefix match against namespaced source identifiers (e.g. 'cursor', 'opencode', 'opencode:my-machine', 'opencode:my-machine:ses_abc123')."
40
+ "Filter to entities from a specific source. Prefix match against namespaced source identifiers (e.g. 'cursor', 'codex', 'opencode', 'opencode:my-machine', 'codex:my-machine:thread-id')."
41
41
  ),
42
42
  limit: z
43
43
  .number()
@@ -106,7 +106,7 @@ export function createMcpServer(): McpServer {
106
106
  .string()
107
107
  .optional()
108
108
  .describe(
109
- "Filter to entities from a specific source. Prefix match against namespaced source identifiers (e.g. 'cursor', 'opencode', 'opencode:my-machine', 'opencode:my-machine:ses_abc123'). If the entity does not match, returns not found."
109
+ "Filter to entities from a specific source. Prefix match against namespaced source identifiers (e.g. 'cursor', 'codex', 'opencode', 'opencode:my-machine', 'codex:my-machine:thread-id'). If the entity does not match, returns not found."
110
110
  ),
111
111
  },
112
112
  },
@@ -134,7 +134,7 @@ export function createMcpServer(): McpServer {
134
134
  "ei_fetch_message",
135
135
  {
136
136
  description:
137
- "Retrieve a specific message by its fully-qualified ID, with optional surrounding conversation context. Use when ei_search returns a quote with a message_id and you want to read the original exchange. The 'before' and 'after' parameters expand the context window in either direction (default 0). Accepts IDs from any integrated source: 'ei:uuid' searches Ei state, 'opencode:machine:session:id' queries OpenCode SQLite, 'claudecode:...' scans Claude Code JSONL files, 'cursor:...' reads the Cursor DB.",
137
+ "Retrieve a specific message by its fully-qualified ID, with optional surrounding conversation context. Use when ei_search returns a quote with a message_id and you want to read the original exchange. The 'before' and 'after' parameters expand the context window in either direction (default 0). Accepts IDs from any integrated source: 'ei:uuid' searches Ei state, 'opencode:machine:session:id' queries OpenCode SQLite, 'claudecode:...' scans Claude Code JSONL files, 'cursor:...' reads the Cursor DB, and 'codex:...' reads Codex rollout history.",
138
138
  inputSchema: {
139
139
  id: z.string().describe("The ID of the message to retrieve"),
140
140
  before: z
@@ -499,6 +499,28 @@ export async function resolveExternalMessage(
499
499
  }
500
500
  }
501
501
 
502
+ case "codex": {
503
+ if (parsed.machine !== getMachineId()) {
504
+ return { error: `Message is from machine '${parsed.machine}', not available on this machine (${getMachineId()})` };
505
+ }
506
+ try {
507
+ const { CodexReader } = await import("../integrations/codex/reader.js");
508
+ const reader = new CodexReader();
509
+ const win = await reader.getMessageById(parsed.session!, parsed.nativeId, before, after);
510
+ if (!win) return null;
511
+ return {
512
+ type: "opencode_message",
513
+ message: { id: win.message.id, role: win.message.role, content: win.message.content, timestamp: win.message.timestamp },
514
+ before: win.before.map(m => ({ id: m.id, role: m.role, content: m.content, timestamp: m.timestamp })),
515
+ after: win.after.map(m => ({ id: m.id, role: m.role, content: m.content, timestamp: m.timestamp })),
516
+ session: { id: win.session.id, title: win.session.title, directory: win.session.cwd },
517
+ source: "codex",
518
+ };
519
+ } catch {
520
+ return null;
521
+ }
522
+ }
523
+
502
524
  case "unknown":
503
525
  default: {
504
526
  // Backward compat: bare msg_xxx → treat as opencode (no machine qualifier)
package/src/cli.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env bun
2
2
  /**
3
- * EI CLI - Memory retrieval interface for OpenCode integration
3
+ * EI CLI - Memory retrieval interface for coding tool integrations
4
4
  *
5
5
  * Usage:
6
6
  * ei "search text" Search all data types
@@ -53,7 +53,7 @@ Usage:
53
53
  ei --persona "Name" "query" Filter results to what a persona has learned
54
54
  ei --id <id> Look up a specific entity by ID
55
55
  echo <id> | ei --id Look up entity by ID from stdin
56
- ei mcp Start the Ei MCP stdio server (for Cursor/Claude Desktop)
56
+ ei mcp Start the Ei MCP stdio server (for Claude Code/Cursor/Codex)
57
57
 
58
58
  Types:
59
59
  quote / quotes Quotes from conversation history
@@ -66,11 +66,11 @@ Options:
66
66
  --number, -n Maximum number of results (default: 10)
67
67
  --recent, -r Sort by last_mentioned date (most recent first)
68
68
  --persona, -p Filter to entities a specific persona has learned about
69
- --source, -s Filter to entities from a specific source (prefix match, e.g. "cursor", "opencode:my-machine", "opencode:my-machine:ses_abc123")
69
+ --source, -s Filter to entities from a specific source (prefix match, e.g. "cursor", "codex:my-machine", "opencode:my-machine:ses_abc123")
70
70
  --id Look up entity by ID (accepts value or stdin)
71
- --install Register Ei with Claude Code, Cursor, and OpenCode (MCP + context hooks)
71
+ --install Register Ei with Claude Code, Cursor, Codex, and OpenCode (MCP + context hooks where supported)
72
72
  --session <id> Session ID to enrich the query with recent context (use with --hook-source)
73
- --hook-source <src> Source of the hook: "opencode-plugin" (OpenCode SQLite) or "cursor"
73
+ --hook-source <src> Source of the hook: "opencode-plugin" (OpenCode SQLite), "cursor", or "codex"
74
74
  --transcript <path> Path to a Claude Code JSONL transcript file for context enrichment
75
75
  --help, -h Show this help message
76
76
 
@@ -93,6 +93,12 @@ async function installMcpClients(): Promise<void> {
93
93
 
94
94
  const home = process.env.HOME || "~";
95
95
 
96
+ if (await commandExists("codex")) {
97
+ await installCodex();
98
+ } else {
99
+ console.log(`ℹ️ Codex CLI not detected — skipping Codex MCP install.`);
100
+ }
101
+
96
102
  const cursorDataDirs = [
97
103
  join(home, "Library", "Application Support", "Cursor"),
98
104
  join(home, ".config", "Cursor"),
@@ -117,6 +123,169 @@ async function installMcpClients(): Promise<void> {
117
123
  }
118
124
  }
119
125
 
126
+ async function commandExists(command: string): Promise<boolean> {
127
+ try {
128
+ const proc = Bun.spawn([command, "--version"], {
129
+ stdout: "ignore",
130
+ stderr: "ignore",
131
+ });
132
+ await proc.exited;
133
+ return proc.exitCode === 0;
134
+ } catch {
135
+ return false;
136
+ }
137
+ }
138
+
139
+ function hookEntryHasCommand(entry: unknown, command: string): boolean {
140
+ if (typeof entry !== "object" || entry === null || !("hooks" in entry)) return false;
141
+ const hooks = (entry as { hooks?: unknown }).hooks;
142
+ if (!Array.isArray(hooks)) return false;
143
+
144
+ return hooks.some((hook) => {
145
+ if (typeof hook !== "object" || hook === null) return false;
146
+ const candidate = hook as { type?: unknown; command?: unknown };
147
+ return candidate.type === "command" && candidate.command === command;
148
+ });
149
+ }
150
+
151
+ async function installCodex(): Promise<void> {
152
+ const dataPath = process.env.EI_DATA_PATH ?? join(process.env.HOME || "~", ".local", "share", "ei");
153
+ const proc = Bun.spawn(
154
+ ["codex", "mcp", "add", "ei", "--env", `EI_DATA_PATH=${dataPath}`, "--", "bunx", "ei-tui", "mcp"],
155
+ {
156
+ stdout: "pipe",
157
+ stderr: "pipe",
158
+ }
159
+ );
160
+
161
+ const [stdout, stderr, exitCode] = await Promise.all([
162
+ new Response(proc.stdout).text(),
163
+ new Response(proc.stderr).text(),
164
+ proc.exited,
165
+ ]);
166
+
167
+ if (exitCode !== 0) {
168
+ console.warn(`⚠️ Codex MCP install failed.`);
169
+ const detail = (stderr || stdout).trim();
170
+ if (detail) console.warn(` ${detail}`);
171
+ } else {
172
+ console.log(`✓ Installed Ei MCP server to Codex config (~/.codex/config.toml)`);
173
+ console.log(` Restart Codex to activate MCP.`);
174
+ }
175
+
176
+ await installCodexHooks();
177
+ }
178
+
179
+ async function installCodexHooks(): Promise<void> {
180
+ const home = process.env.HOME || "~";
181
+ const hooksDir = join(home, ".codex", "hooks");
182
+ const scriptPath = join(hooksDir, "ei-inject.ts");
183
+ const hooksJsonPath = join(home, ".codex", "hooks.json");
184
+
185
+ await Bun.$`mkdir -p ${hooksDir}`;
186
+
187
+ try {
188
+ await Bun.$`test -w ${hooksDir}`.quiet();
189
+ } catch {
190
+ console.warn(`⚠️ Cannot write to ${hooksDir} (permission denied).`);
191
+ console.warn(` Fix with: sudo chown ${process.env.USER ?? "$(whoami)"} ${hooksDir}`);
192
+ console.warn(` Then re-run: ei --install`);
193
+ return;
194
+ }
195
+
196
+ const scriptContent = `#!/usr/bin/env bun
197
+ import { $ } from "bun";
198
+
199
+ const input = await new Response(Bun.stdin.stream()).json().catch(() => ({}));
200
+ const raw = (input.prompt ?? "").replace(/<[^>]*>/g, "").trim();
201
+ const searchArgs = ["-n", "8"];
202
+
203
+ const sessionArgs = [];
204
+ if (input.transcript_path) {
205
+ sessionArgs.push("--transcript", input.transcript_path);
206
+ }
207
+ if (input.session_id) {
208
+ sessionArgs.push("--session", input.session_id, "--hook-source", "codex");
209
+ }
210
+
211
+ const args = raw ? [...searchArgs, ...sessionArgs, raw] : ["--recent", ...searchArgs];
212
+
213
+ async function runEi(commandArgs) {
214
+ const direct = await $\`ei \${commandArgs}\`.quiet().text().catch(() => "");
215
+ if (direct.trim()) return direct;
216
+ return await $\`bunx ei-tui@latest \${commandArgs}\`.quiet().text().catch(() => "");
217
+ }
218
+
219
+ const output = await runEi(args);
220
+ if (output.trim()) {
221
+ const heading = [
222
+ "## Ei Memory Context",
223
+ "*(The user cannot see this block. It is injected automatically before their message.)*",
224
+ "*(If you reference anything from it, briefly explain where it came from — e.g. \\"Ei shows you've been working on X\\" — so the user isn't confused by knowledge that appeared from nowhere.)*",
225
+ "",
226
+ "Ei is a personal knowledge base built from the user's coding sessions, Slack, documents, and conversations.",
227
+ "The following memories MAY be relevant to your current task — use \`ei_search\` or \`ei_lookup\` for targeted queries.",
228
+ ].join("\\n");
229
+
230
+ process.stdout.write(JSON.stringify({
231
+ hookSpecificOutput: {
232
+ hookEventName: "UserPromptSubmit",
233
+ additionalContext: \`\\n\${heading}\\n\${output.trim()}\\n\`,
234
+ },
235
+ }));
236
+ }
237
+ `;
238
+
239
+ await Bun.write(scriptPath, scriptContent);
240
+ await Bun.$`chmod +x ${scriptPath}`;
241
+
242
+ type CodexUserPromptHook = {
243
+ hooks: Array<{ type: string; command: string; statusMessage?: string; timeout?: number }>;
244
+ };
245
+
246
+ interface CodexHooksConfig {
247
+ hooks: {
248
+ UserPromptSubmit?: CodexUserPromptHook[];
249
+ [key: string]: unknown;
250
+ };
251
+ }
252
+
253
+ let hooksConfig: CodexHooksConfig = { hooks: {} };
254
+ try {
255
+ const text = await Bun.file(hooksJsonPath).text();
256
+ hooksConfig = JSON.parse(text) as CodexHooksConfig;
257
+ if (!hooksConfig.hooks || typeof hooksConfig.hooks !== "object") {
258
+ hooksConfig.hooks = {};
259
+ }
260
+ } catch {
261
+ // File doesn't exist or isn't valid JSON — start fresh
262
+ }
263
+
264
+ const userPromptSubmit = (hooksConfig.hooks.UserPromptSubmit ?? []) as CodexUserPromptHook[];
265
+ const hookEntry = {
266
+ hooks: [{
267
+ type: "command",
268
+ command: scriptPath,
269
+ statusMessage: "Loading Ei memory context",
270
+ timeout: 30,
271
+ }],
272
+ };
273
+ const alreadyInstalled = userPromptSubmit.some((entry) => hookEntryHasCommand(entry, scriptPath));
274
+ if (!alreadyInstalled) {
275
+ userPromptSubmit.push(hookEntry);
276
+ }
277
+
278
+ hooksConfig.hooks.UserPromptSubmit = userPromptSubmit;
279
+
280
+ const tmpPath = `${hooksJsonPath}.ei-install.tmp`;
281
+ await Bun.write(tmpPath, JSON.stringify(hooksConfig, null, 2) + "\n");
282
+ const { rename } = await import(/* @vite-ignore */ "fs/promises");
283
+ await rename(tmpPath, hooksJsonPath);
284
+
285
+ console.log(`✓ Installed Ei Codex context hook to ~/.codex/hooks/ei-inject.ts`);
286
+ console.log(` Use /hooks in Codex to review/trust the hook if prompted.`);
287
+ }
288
+
120
289
  async function installClaudeCode(): Promise<void> {
121
290
  const home = process.env.HOME || "~";
122
291
  const claudeJsonPath = join(home, ".claude.json");
@@ -217,9 +386,7 @@ if (output.trim()) process.stdout.write(\`\\n\${heading}\\n\${output.trim()}\\n\
217
386
  const userPromptSubmit = (hooks.UserPromptSubmit ?? []) as unknown[];
218
387
 
219
388
  const hookEntry = { hooks: [{ type: "command", command: "~/.claude/hooks/ei-inject.ts" }] };
220
- const alreadyInstalled = userPromptSubmit.some(
221
- (entry) => JSON.stringify(entry) === JSON.stringify(hookEntry)
222
- );
389
+ const alreadyInstalled = userPromptSubmit.some((entry) => hookEntryHasCommand(entry, "~/.claude/hooks/ei-inject.ts"));
223
390
  if (!alreadyInstalled) {
224
391
  userPromptSubmit.push(hookEntry);
225
392
  }
@@ -410,6 +577,7 @@ function buildEiRelationshipBlock(persona: PersonaResult): string {
410
577
  .map((t) => \`**\${t.name}**: \${t.perspective} — \${t.approach}\`)
411
578
  .join("\\n")
412
579
  return [
580
+ "<!-- ei-relationship-injected -->",
413
581
  "<ei-relationship>",
414
582
  "## Ei: Relationship Context",
415
583
  "",
@@ -438,7 +606,7 @@ export default async function EiPersonaPlugin() {
438
606
 
439
607
  if (sessionCache.has(cacheKey)) {
440
608
  const cached = sessionCache.get(cacheKey) ?? null
441
- if (cached !== null && !output.system[0].includes("<ei-relationship>"))
609
+ if (cached !== null && !output.system[0].includes("<!-- ei-relationship-injected -->"))
442
610
  output.system[0] = output.system[0] + "\\n\\n" + cached
443
611
  return
444
612
  }
@@ -454,7 +622,7 @@ export default async function EiPersonaPlugin() {
454
622
 
455
623
  const block = await sessionFetch.get(cacheKey)!
456
624
  sessionCache.set(cacheKey, block)
457
- if (block !== null && !output.system[0].includes("<ei-relationship>"))
625
+ if (block !== null && !output.system[0].includes("<!-- ei-relationship-injected -->"))
458
626
  output.system[0] = output.system[0] + "\\n\\n" + block
459
627
  },
460
628
  }
@@ -496,6 +664,15 @@ async function getRecentSessionMessages(
496
664
  if (transcriptPath) {
497
665
  try {
498
666
  const text = await Bun.file(transcriptPath).text();
667
+
668
+ const { parseCodexRolloutMessages } = await import(
669
+ /* @vite-ignore */ "./integrations/codex/reader.js"
670
+ );
671
+ const codexMessages = parseCodexRolloutMessages(text, sessionId ?? "transcript");
672
+ if (codexMessages.length > 0) {
673
+ return codexMessages.slice(-5).map((m) => `${m.role}: ${m.content}`);
674
+ }
675
+
499
676
  const messages: Array<{ content: string }> = [];
500
677
 
501
678
  for (const line of text.split("\n")) {
@@ -528,7 +705,7 @@ async function getRecentSessionMessages(
528
705
  }
529
706
  }
530
707
 
531
- return messages.slice(-4).map((m) => m.content);
708
+ return messages.slice(-5).map((m) => m.content);
532
709
  } catch {
533
710
  return [];
534
711
  }
@@ -543,7 +720,7 @@ async function getRecentSessionMessages(
543
720
  );
544
721
  const reader = await createOpenCodeReader();
545
722
  const messages = await reader.getMessagesForSession(sessionId);
546
- return messages.slice(-4).map((m) => m.content);
723
+ return messages.slice(-5).map((m) => `${m.role}: ${m.content}`);
547
724
  }
548
725
 
549
726
  if (hookSource === "cursor") {
@@ -555,7 +732,20 @@ async function getRecentSessionMessages(
555
732
  const session =
556
733
  sessions.find((s) => s.id === sessionId) ?? sessions[sessions.length - 1];
557
734
  if (session) {
558
- return session.messages.slice(-4).map((m) => m.text);
735
+ return session.messages.slice(-5).map((m) => `${m.type === 1 ? "user" : "assistant"}: ${m.text}`);
736
+ }
737
+ }
738
+
739
+ if (hookSource === "codex") {
740
+ const { CodexReader } = await import(
741
+ /* @vite-ignore */ "./integrations/codex/reader.js"
742
+ );
743
+ const reader = new CodexReader();
744
+ const sessions = await reader.getSessions();
745
+ const session =
746
+ sessions.find((s) => s.id === sessionId) ?? sessions[sessions.length - 1];
747
+ if (session) {
748
+ return session.messages.slice(-5).map((m) => `${m.role}: ${m.content}`);
559
749
  }
560
750
  }
561
751
  } catch {
@@ -588,6 +778,16 @@ async function main(): Promise<void> {
588
778
  if (args[0] === "--install") {
589
779
  await installMcpClients();
590
780
  console.log(`
781
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
782
+ Codex
783
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
784
+
785
+ If Codex was detected, Ei MCP was registered via:
786
+
787
+ codex mcp add ei --env EI_DATA_PATH="${process.env.EI_DATA_PATH ?? "~/.local/share/ei"}" -- bunx ei-tui mcp
788
+
789
+ Restart Codex to activate.
790
+
591
791
  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
592
792
  OpenCode: add to ~/.config/opencode/opencode.jsonc
593
793
  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
@@ -18,7 +18,6 @@ export function filterMessagesForContext(
18
18
 
19
19
  return messages.filter((msg) => {
20
20
  if (msg.external === true) return false;
21
- if (msg.context_status === ContextStatusEnum.Always) return true;
22
21
  if (msg.context_status === ContextStatusEnum.Never) return false;
23
22
 
24
23
  const msgMs = new Date(msg.timestamp).getTime();