@llmnesia/local-agent-host 0.2.0-beta.1
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/LICENSE +21 -0
- package/README.md +94 -0
- package/cli.mjs +107 -0
- package/doctor.mjs +233 -0
- package/install.d.ts +42 -0
- package/install.mjs +441 -0
- package/llmnesia-claude-host.mjs +441 -0
- package/package.json +44 -0
|
@@ -0,0 +1,441 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// LLMnesia native messaging host — reads local coding-agent sessions (Claude
|
|
3
|
+
// Code from ~/.claude/projects, Codex from the configured Codex home) and
|
|
4
|
+
// streams them to the LLMnesia browser extension, and writes corpus sync deltas
|
|
5
|
+
// the extension sends back into the LLMnesia corpus's inbox/ directory (see
|
|
6
|
+
// packages/../companion/src/paths.ts).
|
|
7
|
+
//
|
|
8
|
+
// It reads .jsonl session files under those two roots, and writes only inside
|
|
9
|
+
// the corpus root named in its own config (~/.llmnesia/config.json) — never a
|
|
10
|
+
// path the caller supplies. It makes no network calls. The browser launches it
|
|
11
|
+
// on demand (see the installed com.llmnesia.claude_code.json manifest) and
|
|
12
|
+
// talks to it over stdio using Chrome's native-messaging framing: a
|
|
13
|
+
// little-endian uint32 byte-length prefix followed by that many bytes of UTF-8
|
|
14
|
+
// JSON, in both directions.
|
|
15
|
+
//
|
|
16
|
+
// The write path only ever activates for a user who has explicitly run the
|
|
17
|
+
// installer with --corpus (see install.mjs) to opt into the MCP companion;
|
|
18
|
+
// without ~/.llmnesia/config.json this host is exactly as read-only as it
|
|
19
|
+
// has always been for plain session indexing.
|
|
20
|
+
//
|
|
21
|
+
// Protocol v2 (extension → host). v1 was Claude-Code-only: `list` carried no
|
|
22
|
+
// `source` and `get` took a bare sessionId. Both remain accepted, so an
|
|
23
|
+
// extension older than this host keeps working; an extension NEWER than the
|
|
24
|
+
// host detects v1 from the pong and syncs Claude Code only.
|
|
25
|
+
// { cmd: "ping" } → { type: "pong", version: 2 }
|
|
26
|
+
// { cmd: "list" } → { type: "list", sessions:
|
|
27
|
+
// [{source, sessionId, mtime, project?, title?}] }
|
|
28
|
+
// { cmd: "get", source, sessionId } → one or more { type: "chunk", sessionId, seq, total, data }
|
|
29
|
+
// then { type: "sessionDone", sessionId }
|
|
30
|
+
// (or { type: "session", sessionId, notFound: true })
|
|
31
|
+
// { cmd: "corpusInfo" } → { type: "corpusInfo", present, root? }
|
|
32
|
+
// { cmd: "putChunk", filename,
|
|
33
|
+
// seq, total, data } → { type: "chunkAck", seq }
|
|
34
|
+
// (writes <root>/inbox/<filename> once
|
|
35
|
+
// every chunk 0..total-1 has arrived)
|
|
36
|
+
//
|
|
37
|
+
// The extension never names a path in either direction: it asks for a
|
|
38
|
+
// (source, sessionId) pair and the host resolves it against its own roots. That
|
|
39
|
+
// is what keeps a compromised or buggy caller from reading arbitrary files.
|
|
40
|
+
|
|
41
|
+
import { chmod, mkdir, readdir, readFile, rename, stat, writeFile } from "node:fs/promises";
|
|
42
|
+
import { homedir } from "node:os";
|
|
43
|
+
import { join } from "node:path";
|
|
44
|
+
|
|
45
|
+
const PROTOCOL_VERSION = 2;
|
|
46
|
+
const PROJECTS_DIR = join(homedir(), ".claude", "projects");
|
|
47
|
+
const CONFIG_FILE = join(homedir(), ".llmnesia", "config.json");
|
|
48
|
+
// Codex's home, resolved at install time (--codex-home > CODEX_HOME > ~/.codex)
|
|
49
|
+
// and persisted into config.json. The env var is read here too so a host
|
|
50
|
+
// installed before Codex support still honours a non-default CODEX_HOME.
|
|
51
|
+
const DEFAULT_CODEX_HOME = process.env.CODEX_HOME || join(homedir(), ".codex");
|
|
52
|
+
// Codex nests rollouts as sessions/<year>/<month>/<day>/*.jsonl. Bounded so a
|
|
53
|
+
// misconfigured codexHome can't turn into an unbounded filesystem walk.
|
|
54
|
+
const CODEX_MAX_DEPTH = 3;
|
|
55
|
+
// Conservative chunk size (chars). After JSON-escaping + any multibyte chars the
|
|
56
|
+
// on-wire message stays well under native messaging's 1 MB per-message ceiling.
|
|
57
|
+
const CHUNK_CHARS = 256 * 1024;
|
|
58
|
+
// Matches companion/src/corpus.ts DIR_MODE/FILE_MODE — the corpus holds
|
|
59
|
+
// plaintext conversation history, so writes here should be no more readable
|
|
60
|
+
// than the browser profile it was copied out of.
|
|
61
|
+
const DIR_MODE = 0o700;
|
|
62
|
+
const FILE_MODE = 0o600;
|
|
63
|
+
// Defend the host process from malformed or compromised callers. The extension
|
|
64
|
+
// currently sends 256 KiB chunks and waits for each ack, so these limits leave
|
|
65
|
+
// ample headroom without permitting unbounded arrays or abandoned transfers.
|
|
66
|
+
const MAX_PUT_CHUNK_CHARS = 512 * 1024;
|
|
67
|
+
const MAX_PUT_CHUNKS = 256;
|
|
68
|
+
const MAX_PUT_TRANSFER_CHARS = 64 * 1024 * 1024;
|
|
69
|
+
const MAX_PENDING_WRITE_CHARS = 64 * 1024 * 1024;
|
|
70
|
+
const MAX_PENDING_WRITES = 8;
|
|
71
|
+
const PENDING_WRITE_TTL_MS = 5 * 60 * 1000;
|
|
72
|
+
|
|
73
|
+
function send(message) {
|
|
74
|
+
const body = Buffer.from(JSON.stringify(message), "utf8");
|
|
75
|
+
const header = Buffer.alloc(4);
|
|
76
|
+
header.writeUInt32LE(body.length, 0);
|
|
77
|
+
process.stdout.write(header);
|
|
78
|
+
process.stdout.write(body);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// --- session discovery ----------------------------------------------------
|
|
82
|
+
// One entry per session: { source, sessionId, mtime, project?, title?, path }.
|
|
83
|
+
// `path` is stripped before anything goes on the wire.
|
|
84
|
+
|
|
85
|
+
async function listClaudeCodeSessions() {
|
|
86
|
+
const sessions = [];
|
|
87
|
+
let projectDirs;
|
|
88
|
+
try {
|
|
89
|
+
projectDirs = await readdir(PROJECTS_DIR, { withFileTypes: true });
|
|
90
|
+
} catch {
|
|
91
|
+
return sessions; // no ~/.claude/projects yet
|
|
92
|
+
}
|
|
93
|
+
for (const entry of projectDirs) {
|
|
94
|
+
if (!entry.isDirectory()) {
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
const dir = join(PROJECTS_DIR, entry.name);
|
|
98
|
+
let files;
|
|
99
|
+
try {
|
|
100
|
+
files = await readdir(dir);
|
|
101
|
+
} catch {
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
for (const file of files) {
|
|
105
|
+
if (!file.endsWith(".jsonl")) {
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
const path = join(dir, file);
|
|
109
|
+
try {
|
|
110
|
+
const info = await stat(path);
|
|
111
|
+
sessions.push({
|
|
112
|
+
source: "claude_code",
|
|
113
|
+
sessionId: file.replace(/\.jsonl$/, ""),
|
|
114
|
+
mtime: Math.floor(info.mtimeMs),
|
|
115
|
+
project: entry.name,
|
|
116
|
+
path
|
|
117
|
+
});
|
|
118
|
+
} catch {
|
|
119
|
+
// Skip unreadable files.
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return sessions;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// Codex names rollouts `rollout-<ISO timestamp>-<uuid>.jsonl`; the trailing
|
|
127
|
+
// UUID is the thread id (it matches session_meta.payload.id). Mirrors
|
|
128
|
+
// codexSessionIdFromFilename in the extension.
|
|
129
|
+
const CODEX_UUID_RE = /([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})$/i;
|
|
130
|
+
|
|
131
|
+
function codexSessionId(filename) {
|
|
132
|
+
const base = filename.replace(/\.jsonl$/i, "");
|
|
133
|
+
const match = CODEX_UUID_RE.exec(base);
|
|
134
|
+
return match ? match[1].toLowerCase() : base;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
async function walkCodexDir(dir, depth, out) {
|
|
138
|
+
let entries;
|
|
139
|
+
try {
|
|
140
|
+
entries = await readdir(dir, { withFileTypes: true });
|
|
141
|
+
} catch {
|
|
142
|
+
return out; // missing or unreadable — nothing to add
|
|
143
|
+
}
|
|
144
|
+
for (const entry of entries) {
|
|
145
|
+
const path = join(dir, entry.name);
|
|
146
|
+
if (entry.isDirectory()) {
|
|
147
|
+
if (depth > 0) {
|
|
148
|
+
await walkCodexDir(path, depth - 1, out);
|
|
149
|
+
}
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
if (!entry.name.endsWith(".jsonl")) {
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
try {
|
|
156
|
+
const info = await stat(path);
|
|
157
|
+
out.push({
|
|
158
|
+
source: "codex",
|
|
159
|
+
sessionId: codexSessionId(entry.name),
|
|
160
|
+
mtime: Math.floor(info.mtimeMs),
|
|
161
|
+
path
|
|
162
|
+
});
|
|
163
|
+
} catch {
|
|
164
|
+
// Skip unreadable files.
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return out;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// Codex's user-facing thread names, so search results read as the titles the
|
|
171
|
+
// user sees in the app rather than a derived "<project> · <first prompt>".
|
|
172
|
+
async function readCodexThreadNames(codexHome) {
|
|
173
|
+
const titles = new Map();
|
|
174
|
+
let raw;
|
|
175
|
+
try {
|
|
176
|
+
raw = await readFile(join(codexHome, "session_index.jsonl"), "utf8");
|
|
177
|
+
} catch {
|
|
178
|
+
return titles; // absent is normal — the extension falls back to a derived title
|
|
179
|
+
}
|
|
180
|
+
for (const line of raw.split("\n")) {
|
|
181
|
+
const trimmed = line.trim();
|
|
182
|
+
if (!trimmed) {
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
try {
|
|
186
|
+
const row = JSON.parse(trimmed);
|
|
187
|
+
if (row && typeof row.id === "string" && typeof row.thread_name === "string") {
|
|
188
|
+
const name = row.thread_name.trim();
|
|
189
|
+
if (name) {
|
|
190
|
+
titles.set(row.id.toLowerCase(), name);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
} catch {
|
|
194
|
+
// Skip malformed lines (including a truncated final one).
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
return titles;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
async function listCodexSessions(codexHome) {
|
|
201
|
+
const sessions = await walkCodexDir(join(codexHome, "sessions"), CODEX_MAX_DEPTH, []);
|
|
202
|
+
if (sessions.length === 0) {
|
|
203
|
+
return sessions;
|
|
204
|
+
}
|
|
205
|
+
const titles = await readCodexThreadNames(codexHome);
|
|
206
|
+
for (const session of sessions) {
|
|
207
|
+
const title = titles.get(session.sessionId);
|
|
208
|
+
if (title) {
|
|
209
|
+
session.title = title;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
return sessions;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Every session across every source. Sources are listed independently and
|
|
217
|
+
* failures are contained per source (each helper swallows its own errors), so
|
|
218
|
+
* an absent or unreadable Codex home can never stop Claude Code from syncing,
|
|
219
|
+
* or vice versa.
|
|
220
|
+
*/
|
|
221
|
+
async function listSessions() {
|
|
222
|
+
const config = await loadConfig();
|
|
223
|
+
const codexHome = config?.codexHome || DEFAULT_CODEX_HOME;
|
|
224
|
+
const [claude, codex] = await Promise.all([
|
|
225
|
+
listClaudeCodeSessions().catch(() => []),
|
|
226
|
+
listCodexSessions(codexHome).catch(() => [])
|
|
227
|
+
]);
|
|
228
|
+
return [...claude, ...codex];
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
async function loadConfig() {
|
|
232
|
+
try {
|
|
233
|
+
const raw = await readFile(CONFIG_FILE, "utf8");
|
|
234
|
+
const parsed = JSON.parse(raw);
|
|
235
|
+
if (!parsed || typeof parsed !== "object") {
|
|
236
|
+
return null;
|
|
237
|
+
}
|
|
238
|
+
const corpusRoot =
|
|
239
|
+
typeof parsed.corpusRoot === "string" && parsed.corpusRoot.length > 0 ? parsed.corpusRoot : null;
|
|
240
|
+
const codexHome =
|
|
241
|
+
typeof parsed.codexHome === "string" && parsed.codexHome.length > 0 ? parsed.codexHome : null;
|
|
242
|
+
// A config that names only codexHome is still useful for listing, but the
|
|
243
|
+
// corpus write path requires corpusRoot — callers check that field.
|
|
244
|
+
if (!corpusRoot && !codexHome) {
|
|
245
|
+
return null;
|
|
246
|
+
}
|
|
247
|
+
return { corpusRoot, codexHome };
|
|
248
|
+
} catch {
|
|
249
|
+
return null; // no config yet, or unreadable/invalid — treat as "not installed"
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// A filename must be a bare basename: no separators, no "..", nothing that
|
|
254
|
+
// could walk outside the corpus's inbox/ directory. The host is the trust
|
|
255
|
+
// boundary here — the extension is not trusted to name a write target.
|
|
256
|
+
function sanitizeFilename(name) {
|
|
257
|
+
if (typeof name !== "string" || name.length === 0) {
|
|
258
|
+
return null;
|
|
259
|
+
}
|
|
260
|
+
if (name === "." || name === "..") {
|
|
261
|
+
return null;
|
|
262
|
+
}
|
|
263
|
+
if (name.includes("/") || name.includes("\\") || name.includes("..")) {
|
|
264
|
+
return null;
|
|
265
|
+
}
|
|
266
|
+
return name;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
// filename → { chunks: Map<number, string>, total, receivedChars, updatedAt }
|
|
270
|
+
// while a multi-chunk putChunk transfer is in flight. A Map avoids allocating
|
|
271
|
+
// from caller-controlled `total`, and lets duplicate chunks replace their old
|
|
272
|
+
// contribution without inflating the byte/character budget.
|
|
273
|
+
const pendingWrites = new Map();
|
|
274
|
+
|
|
275
|
+
function prunePendingWrites(now) {
|
|
276
|
+
for (const [filename, entry] of pendingWrites) {
|
|
277
|
+
if (now - entry.updatedAt > PENDING_WRITE_TTL_MS) {
|
|
278
|
+
pendingWrites.delete(filename);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
setInterval(() => prunePendingWrites(Date.now()), 60 * 1000).unref();
|
|
284
|
+
|
|
285
|
+
async function handlePutChunk(message) {
|
|
286
|
+
const { filename, seq, total, data } = message;
|
|
287
|
+
const safeName = sanitizeFilename(filename);
|
|
288
|
+
if (!safeName) {
|
|
289
|
+
send({ type: "error", error: `putChunk: rejected filename ${JSON.stringify(filename)}` });
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
if (
|
|
293
|
+
!Number.isInteger(seq) ||
|
|
294
|
+
!Number.isInteger(total) ||
|
|
295
|
+
seq < 0 ||
|
|
296
|
+
total < 1 ||
|
|
297
|
+
total > MAX_PUT_CHUNKS ||
|
|
298
|
+
seq >= total
|
|
299
|
+
) {
|
|
300
|
+
send({ type: "error", error: `putChunk: invalid seq/total for ${safeName}` });
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
if (typeof data !== "string" || data.length > MAX_PUT_CHUNK_CHARS) {
|
|
304
|
+
send({ type: "error", error: `putChunk: invalid or oversized data for ${safeName}` });
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
const config = await loadConfig();
|
|
308
|
+
if (!config?.corpusRoot) {
|
|
309
|
+
send({ type: "error", error: "putChunk: no corpus configured (run the installer)" });
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
const now = Date.now();
|
|
314
|
+
prunePendingWrites(now);
|
|
315
|
+
let entry = pendingWrites.get(safeName);
|
|
316
|
+
if (!entry || entry.total !== total) {
|
|
317
|
+
if (!entry && pendingWrites.size >= MAX_PENDING_WRITES) {
|
|
318
|
+
send({ type: "error", error: "putChunk: too many transfers in progress" });
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
entry = { chunks: new Map(), total, receivedChars: 0, updatedAt: now };
|
|
322
|
+
pendingWrites.set(safeName, entry);
|
|
323
|
+
}
|
|
324
|
+
const previous = entry.chunks.get(seq);
|
|
325
|
+
const nextReceivedChars = entry.receivedChars - (previous?.length ?? 0) + data.length;
|
|
326
|
+
if (nextReceivedChars > MAX_PUT_TRANSFER_CHARS) {
|
|
327
|
+
pendingWrites.delete(safeName);
|
|
328
|
+
send({ type: "error", error: `putChunk: transfer too large for ${safeName}` });
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
const pendingChars = [...pendingWrites.values()].reduce((sum, pending) => sum + pending.receivedChars, 0);
|
|
332
|
+
if (pendingChars - (previous?.length ?? 0) + data.length > MAX_PENDING_WRITE_CHARS) {
|
|
333
|
+
pendingWrites.delete(safeName);
|
|
334
|
+
send({ type: "error", error: "putChunk: pending transfer budget exceeded" });
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
entry.chunks.set(seq, data);
|
|
338
|
+
entry.receivedChars = nextReceivedChars;
|
|
339
|
+
entry.updatedAt = now;
|
|
340
|
+
|
|
341
|
+
if (entry.chunks.size < total) {
|
|
342
|
+
send({ type: "chunkAck", seq });
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
pendingWrites.delete(safeName);
|
|
347
|
+
const inboxDir = join(config.corpusRoot, "inbox");
|
|
348
|
+
await mkdir(inboxDir, { recursive: true, mode: DIR_MODE });
|
|
349
|
+
await chmod(inboxDir, DIR_MODE).catch(() => {}); // mkdir's mode is masked by umask
|
|
350
|
+
const tmpPath = join(inboxDir, `${safeName}.part-${process.pid}`);
|
|
351
|
+
const finalPath = join(inboxDir, safeName);
|
|
352
|
+
const text = Array.from({ length: total }, (_, index) => entry.chunks.get(index) ?? "").join("");
|
|
353
|
+
await writeFile(tmpPath, text, { encoding: "utf8", mode: FILE_MODE });
|
|
354
|
+
await rename(tmpPath, finalPath);
|
|
355
|
+
send({ type: "chunkAck", seq });
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
async function handle(message) {
|
|
359
|
+
if (!message || typeof message !== "object") {
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
if (message.cmd === "ping") {
|
|
363
|
+
send({ type: "pong", version: PROTOCOL_VERSION });
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
if (message.cmd === "corpusInfo") {
|
|
367
|
+
const config = await loadConfig();
|
|
368
|
+
if (!config?.corpusRoot) {
|
|
369
|
+
send({ type: "corpusInfo", present: false });
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
send({ type: "corpusInfo", present: true, root: config.corpusRoot });
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
if (message.cmd === "putChunk") {
|
|
376
|
+
await handlePutChunk(message);
|
|
377
|
+
return;
|
|
378
|
+
}
|
|
379
|
+
if (message.cmd === "list") {
|
|
380
|
+
const sessions = await listSessions();
|
|
381
|
+
send({ type: "list", sessions: sessions.map(({ path, ...rest }) => rest) });
|
|
382
|
+
return;
|
|
383
|
+
}
|
|
384
|
+
if (message.cmd === "get") {
|
|
385
|
+
const sessions = await listSessions();
|
|
386
|
+
// Session ids are only unique WITHIN a source, so a v2 caller names both.
|
|
387
|
+
// A v1 caller sends no source; everything it knows about is Claude Code, so
|
|
388
|
+
// that's what an absent source resolves to — never a bare id match that
|
|
389
|
+
// could hand back the wrong source's file.
|
|
390
|
+
const wantSource = typeof message.source === "string" ? message.source : "claude_code";
|
|
391
|
+
const match = sessions.find((s) => s.source === wantSource && s.sessionId === message.sessionId);
|
|
392
|
+
if (!match) {
|
|
393
|
+
send({ type: "session", sessionId: message.sessionId, notFound: true });
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
396
|
+
const text = await readFile(match.path, "utf8");
|
|
397
|
+
const total = Math.max(1, Math.ceil(text.length / CHUNK_CHARS));
|
|
398
|
+
for (let i = 0, seq = 0; seq < total; i += CHUNK_CHARS, seq++) {
|
|
399
|
+
send({
|
|
400
|
+
type: "chunk",
|
|
401
|
+
sessionId: message.sessionId,
|
|
402
|
+
seq,
|
|
403
|
+
total,
|
|
404
|
+
data: text.slice(i, i + CHUNK_CHARS)
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
send({ type: "sessionDone", sessionId: message.sessionId });
|
|
408
|
+
return;
|
|
409
|
+
}
|
|
410
|
+
send({ type: "error", error: `unknown command: ${String(message.cmd)}` });
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
// --- native-messaging stdin framing --------------------------------------
|
|
414
|
+
let inbox = Buffer.alloc(0);
|
|
415
|
+
let processing = Promise.resolve();
|
|
416
|
+
|
|
417
|
+
process.stdin.on("data", (data) => {
|
|
418
|
+
inbox = Buffer.concat([inbox, data]);
|
|
419
|
+
while (inbox.length >= 4) {
|
|
420
|
+
const length = inbox.readUInt32LE(0);
|
|
421
|
+
if (inbox.length < 4 + length) {
|
|
422
|
+
break;
|
|
423
|
+
}
|
|
424
|
+
const payload = inbox.subarray(4, 4 + length).toString("utf8");
|
|
425
|
+
inbox = inbox.subarray(4 + length);
|
|
426
|
+
let message;
|
|
427
|
+
try {
|
|
428
|
+
message = JSON.parse(payload);
|
|
429
|
+
} catch {
|
|
430
|
+
continue;
|
|
431
|
+
}
|
|
432
|
+
// Serialize handling so chunk ordering per session is preserved.
|
|
433
|
+
processing = processing
|
|
434
|
+
.then(() => handle(message))
|
|
435
|
+
.catch((error) => send({ type: "error", error: String((error && error.message) || error) }));
|
|
436
|
+
}
|
|
437
|
+
});
|
|
438
|
+
|
|
439
|
+
process.stdin.on("end", () => {
|
|
440
|
+
processing.finally(() => process.exit(0));
|
|
441
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@llmnesia/local-agent-host",
|
|
3
|
+
"version": "0.2.0-beta.1",
|
|
4
|
+
"description": "LLMnesia native messaging host — lets the browser extension read local coding-agent sessions (Claude Code, Codex) automatically.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"llmnesia",
|
|
7
|
+
"claude-code",
|
|
8
|
+
"codex",
|
|
9
|
+
"native-messaging",
|
|
10
|
+
"browser-extension",
|
|
11
|
+
"chat-history",
|
|
12
|
+
"local-first"
|
|
13
|
+
],
|
|
14
|
+
"homepage": "https://llmnesia.com",
|
|
15
|
+
"bugs": {
|
|
16
|
+
"email": "hello@llmnesia.com"
|
|
17
|
+
},
|
|
18
|
+
"author": "Keiran Flynn <hello@llmnesia.com>",
|
|
19
|
+
"type": "module",
|
|
20
|
+
"main": "./install.mjs",
|
|
21
|
+
"types": "./install.d.ts",
|
|
22
|
+
"bin": {
|
|
23
|
+
"local-agent-host": "cli.mjs"
|
|
24
|
+
},
|
|
25
|
+
"scripts": {
|
|
26
|
+
"install-host": "node cli.mjs"
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"llmnesia-claude-host.mjs",
|
|
30
|
+
"cli.mjs",
|
|
31
|
+
"install.mjs",
|
|
32
|
+
"install.d.ts",
|
|
33
|
+
"doctor.mjs",
|
|
34
|
+
"README.md",
|
|
35
|
+
"LICENSE"
|
|
36
|
+
],
|
|
37
|
+
"license": "MIT",
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public"
|
|
40
|
+
},
|
|
41
|
+
"engines": {
|
|
42
|
+
"node": ">=18"
|
|
43
|
+
}
|
|
44
|
+
}
|