@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
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Keiran Flynn
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# LLMnesia local agent host
|
|
2
|
+
|
|
3
|
+
A tiny local helper that lets the LLMnesia browser extension (1) index your local coding-agent sessions automatically — **Claude Code** and **Codex**, with no folder picking and no hidden-folder navigation — and (2) sync your LLMnesia conversation corpus for the [MCP companion](https://www.npmjs.com/package/@llmnesia/mcp) without the File System Access picker.
|
|
4
|
+
|
|
5
|
+
It reads `.jsonl` session files under `~/.claude/projects` and `~/.codex/sessions`. It writes only inside the corpus root named in its own config (`~/.llmnesia/config.json`) — there is no protocol field that lets a caller choose a different write location. It makes no network calls.
|
|
6
|
+
|
|
7
|
+
> Previously published as `@llmnesia/claude-code-host`. That name still works and installs this same helper; see [the compatibility package](https://www.npmjs.com/package/@llmnesia/claude-code-host).
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
Requires Node 18+.
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
npx -y @llmnesia/local-agent-host@latest [--corpus <dir>] [--codex-home <dir>]
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
For the **Chrome Web Store build, no arguments are needed** — the installer already knows its permanent extension id.
|
|
18
|
+
|
|
19
|
+
Only pass an id if you're running a **dev / unpacked** build (its id is random per machine — find it at `brave://extensions` or `chrome://extensions` with Developer mode on):
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
npx -y @llmnesia/local-agent-host@latest <your-dev-extension-id> [--corpus <dir>]
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Any ids you pass are allowed *in addition to* the Web Store build, so this also covers running both at once. (From a checkout of this repo you can also run it directly: `node cli.mjs [<your-extension-id>] [--corpus <dir>]`.)
|
|
26
|
+
|
|
27
|
+
Then **fully quit and reopen** your browser and open LLMnesia → Settings. The "Local coding sessions" card detects the helper and switches to one-click **Sync now** (and auto-syncs on open).
|
|
28
|
+
|
|
29
|
+
### Where Codex sessions are read from
|
|
30
|
+
|
|
31
|
+
Resolved once at install time, in this order: `--codex-home <dir>`, then the
|
|
32
|
+
`CODEX_HOME` environment variable Codex itself honours, then `~/.codex`. The
|
|
33
|
+
result is written into `~/.llmnesia/config.json`, because native messaging
|
|
34
|
+
launches the host with almost no environment — it can't re-derive `CODEX_HOME`
|
|
35
|
+
at runtime.
|
|
36
|
+
|
|
37
|
+
Works on macOS, Linux, and Windows, with Brave, Chrome, Edge, and Chromium. `allowed_origins` is locked to the extension id(s) you pass, so only LLMnesia can talk to the host.
|
|
38
|
+
|
|
39
|
+
### Choosing the corpus root
|
|
40
|
+
|
|
41
|
+
`--corpus <dir>` sets where the host is allowed to write your synced conversation corpus. If you omit it, the installer resolves the same order the companion does: `$LLMNESIA_CORPUS_DIR`, then the default `~/.llmnesia/corpus`. Point it at the same directory your MCP companion reads from.
|
|
42
|
+
|
|
43
|
+
Re-running the installer is safe: it won't move a corpus that already has a different root written unless you pass `--force`.
|
|
44
|
+
|
|
45
|
+
```sh
|
|
46
|
+
node cli.mjs <your-extension-id> --corpus ~/.llmnesia/corpus --force
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## What it installs
|
|
50
|
+
|
|
51
|
+
The host script goes to `~/.llmnesia/llmnesia-claude-host.mjs` on every platform. How each browser is pointed at it differs:
|
|
52
|
+
|
|
53
|
+
- **macOS / Linux:** a `com.llmnesia.claude_code.json` manifest is written into each browser's `NativeMessagingHosts` folder, and the host script's shebang is pinned to the node that ran the installer (native messaging launches hosts with a bare `PATH`).
|
|
54
|
+
- **Windows:** a `llmnesia-claude-host.bat` launcher and the `com.llmnesia.claude_code.json` manifest go to `~/.llmnesia`, and a registry key `HKCU\Software\<vendor>\NativeMessagingHosts\com.llmnesia.claude_code` (per browser found) is set to the manifest path.
|
|
55
|
+
|
|
56
|
+
Plus, on every platform: `~/.llmnesia/config.json` (mode `0600`) → `{ "corpusRoot": "…" }`, the host-owned write root for corpus sync. The host reads this and only this to decide where corpus deltas land; the browser can never name a write target.
|
|
57
|
+
|
|
58
|
+
## Troubleshooting
|
|
59
|
+
|
|
60
|
+
If the extension's Settings page says the helper isn't answering, run:
|
|
61
|
+
|
|
62
|
+
```sh
|
|
63
|
+
npx -y @llmnesia/local-agent-host@latest doctor
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
It's read-only — checks the host script, each browser's manifest, `config.json`, whether Claude Code / Codex sessions were found, and pings the helper directly — and prints exactly which step is missing instead of a generic failure.
|
|
67
|
+
|
|
68
|
+
## Uninstall
|
|
69
|
+
|
|
70
|
+
```sh
|
|
71
|
+
npx -y @llmnesia/local-agent-host@latest uninstall
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
This removes only the helper script, browser manifests / registry entries, and
|
|
75
|
+
the Windows launcher. It deliberately keeps `~/.llmnesia/config.json` and the
|
|
76
|
+
corpus directory it names, so uninstalling the browser integration cannot erase
|
|
77
|
+
conversation history. Remove those separately only if you intentionally want to
|
|
78
|
+
delete the retained data too.
|
|
79
|
+
|
|
80
|
+
## Protocol
|
|
81
|
+
|
|
82
|
+
Native messaging over stdio (little-endian uint32 length prefix + UTF-8 JSON):
|
|
83
|
+
|
|
84
|
+
- `{ cmd: "ping" }` → `{ type: "pong", version }`
|
|
85
|
+
- `{ cmd: "list" }` → `{ type: "list", sessions: [{ sessionId, mtime, project }] }`
|
|
86
|
+
- `{ cmd: "get", sessionId }` → `{ type: "chunk", sessionId, seq, total, data }` × N, then `{ type: "sessionDone", sessionId }`
|
|
87
|
+
- `{ cmd: "corpusInfo" }` → `{ type: "corpusInfo", present: false }`, or `{ type: "corpusInfo", present: true, root }` if `~/.llmnesia/config.json` names a corpus
|
|
88
|
+
- `{ cmd: "putChunk", filename, seq, total, data }` → `{ type: "chunkAck", seq }`, one call per chunk. Once every chunk `0..total-1` for a `filename` has arrived, the host writes `<corpusRoot>/inbox/<filename>` (via a `.part-<pid>` temp file, `rename()`d into place so a concurrent drain never sees a partial file). `filename` must be a bare basename — anything containing `/`, `\`, or `..` is rejected with `{ type: "error" }` and nothing is written. Transfers are bounded to 256 chunks, 512 KiB characters per chunk, 64 MiB characters across pending data, eight simultaneous filenames, and a five-minute idle lifetime. The corpus root always comes from the host's own config; it cannot be set over the protocol.
|
|
89
|
+
|
|
90
|
+
`putChunk` is how the extension's service worker pushes corpus sync deltas without ever holding a File System Access handle. Deltas are sent as plain uncompressed NDJSON text (each `data` string is written verbatim into a `.jsonl` file the companion drains directly), so there is no base64 or gzip round-trip. The corpus root is written by the installer into `~/.llmnesia/config.json`.
|
|
91
|
+
|
|
92
|
+
## Support
|
|
93
|
+
|
|
94
|
+
If `doctor` does not resolve the problem, email [hello@llmnesia.com](mailto:hello@llmnesia.com) and paste its output.
|
package/cli.mjs
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Standalone CLI for the native messaging host, for people who want only local
|
|
3
|
+
// session indexing (Claude Code and Codex) without the full MCP suite:
|
|
4
|
+
//
|
|
5
|
+
// npx @llmnesia/local-agent-host [extension-id...] [--corpus <dir>]
|
|
6
|
+
// [--codex-home <dir>] [--force]
|
|
7
|
+
//
|
|
8
|
+
// Kept deliberately separate from install.mjs so that file stays a pure,
|
|
9
|
+
// side-effect-free module — @llmnesia/mcp bundles it, and a self-executing
|
|
10
|
+
// entry point inside a bundled module runs on every invocation of the
|
|
11
|
+
// bundling program (see the note at the end of install.mjs).
|
|
12
|
+
|
|
13
|
+
import { installNativeHost, uninstallNativeHost } from "./install.mjs";
|
|
14
|
+
import { runDoctor } from "./doctor.mjs";
|
|
15
|
+
|
|
16
|
+
const HELP = `LLMnesia local agent host
|
|
17
|
+
|
|
18
|
+
Installs a private, on-device helper so the LLMnesia browser extension can
|
|
19
|
+
index local Claude Code and Codex sessions. The helper makes no network calls.
|
|
20
|
+
|
|
21
|
+
Usage:
|
|
22
|
+
npx -y @llmnesia/local-agent-host@latest
|
|
23
|
+
npx -y @llmnesia/local-agent-host@latest doctor
|
|
24
|
+
npx -y @llmnesia/local-agent-host@latest uninstall
|
|
25
|
+
|
|
26
|
+
Options:
|
|
27
|
+
--corpus <dir> Conversation-data folder (default: ~/.llmnesia/corpus)
|
|
28
|
+
--codex-home <dir> Codex data folder (default: $CODEX_HOME or ~/.codex)
|
|
29
|
+
--force Allow changing an existing conversation-data folder
|
|
30
|
+
-h, --help Show this help
|
|
31
|
+
|
|
32
|
+
For an unpacked extension, pass its 32-letter Chromium extension ID after the
|
|
33
|
+
package name. The Chrome Web Store build needs no ID.`;
|
|
34
|
+
|
|
35
|
+
function requireDirectoryValue(flag, value) {
|
|
36
|
+
if (typeof value !== "string" || value.trim() === "" || value.startsWith("--")) {
|
|
37
|
+
const example = flag === "--codex-home" ? "~/.codex" : "~/.llmnesia/corpus";
|
|
38
|
+
throw new Error(`${flag} needs a directory, e.g. ${flag} ${example}`);
|
|
39
|
+
}
|
|
40
|
+
return value;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function cliErrorMessage(error) {
|
|
44
|
+
if (error && typeof error === "object" && (error.code === "EACCES" || error.code === "EPERM")) {
|
|
45
|
+
return `Permission denied while installing the helper. Run the command from your normal user account (not with sudo), check that you own ~/.llmnesia and your browser profile, then retry. Details: ${error.message}`;
|
|
46
|
+
}
|
|
47
|
+
return error instanceof Error ? error.message : String(error);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function parseCliArgs(argv) {
|
|
51
|
+
const ids = [];
|
|
52
|
+
let corpusArg;
|
|
53
|
+
let codexHomeArg;
|
|
54
|
+
let force = false;
|
|
55
|
+
for (let i = 0; i < argv.length; i++) {
|
|
56
|
+
const arg = argv[i];
|
|
57
|
+
if (arg === "--force") {
|
|
58
|
+
force = true;
|
|
59
|
+
} else if (arg === "--corpus") {
|
|
60
|
+
corpusArg = requireDirectoryValue("--corpus", argv[++i]);
|
|
61
|
+
} else if (arg.startsWith("--corpus=")) {
|
|
62
|
+
corpusArg = requireDirectoryValue("--corpus", arg.slice("--corpus=".length));
|
|
63
|
+
} else if (arg === "--codex-home") {
|
|
64
|
+
codexHomeArg = requireDirectoryValue("--codex-home", argv[++i]);
|
|
65
|
+
} else if (arg.startsWith("--codex-home=")) {
|
|
66
|
+
codexHomeArg = requireDirectoryValue("--codex-home", arg.slice("--codex-home=".length));
|
|
67
|
+
} else if (arg.startsWith("-")) {
|
|
68
|
+
throw new Error(`Unknown option ${JSON.stringify(arg)}. Run with --help to see the available options.`);
|
|
69
|
+
} else if (arg) {
|
|
70
|
+
ids.push(arg);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return { ids, corpusArg, codexHomeArg, force };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
async function main() {
|
|
77
|
+
const args = process.argv.slice(2);
|
|
78
|
+
if (args.includes("--help") || args.includes("-h")) {
|
|
79
|
+
console.log(HELP);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
if (args[0] === "doctor") {
|
|
83
|
+
await runDoctor();
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
if (args[0] === "uninstall") {
|
|
87
|
+
const result = await uninstallNativeHost();
|
|
88
|
+
console.log(result.removed.length > 0 ? `Removed: ${result.removed.join(", ")}` : "The browser helper was already absent.");
|
|
89
|
+
console.log("Kept ~/.llmnesia/config.json and all corpus data.");
|
|
90
|
+
if (result.corpusRoot) {
|
|
91
|
+
console.log(`Corpus kept at ${result.corpusRoot}`);
|
|
92
|
+
}
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
if (args[0] === "install") {
|
|
96
|
+
args.shift();
|
|
97
|
+
}
|
|
98
|
+
const { ids, corpusArg, codexHomeArg, force } = parseCliArgs(args);
|
|
99
|
+
console.log("Installing the LLMnesia local-session helper…");
|
|
100
|
+
console.log("Your session data stays on this computer; the helper makes no network calls.\n");
|
|
101
|
+
await installNativeHost({ ids, corpus: corpusArg, codexHome: codexHomeArg, force });
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
main().catch((error) => {
|
|
105
|
+
console.error(cliErrorMessage(error));
|
|
106
|
+
process.exit(1);
|
|
107
|
+
});
|
package/doctor.mjs
ADDED
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// `local-agent-host doctor` — a read-only diagnostic for people whose helper
|
|
3
|
+
// isn't answering. It never installs or changes anything; it just says which
|
|
4
|
+
// of the install steps actually landed, so a support conversation can start
|
|
5
|
+
// from "here's exactly what's missing" instead of "try reinstalling".
|
|
6
|
+
|
|
7
|
+
import { execFile, spawn } from "node:child_process";
|
|
8
|
+
import { readFile } from "node:fs/promises";
|
|
9
|
+
import { homedir, platform } from "node:os";
|
|
10
|
+
import { join } from "node:path";
|
|
11
|
+
import { promisify } from "node:util";
|
|
12
|
+
import {
|
|
13
|
+
CLAUDE_PROJECTS_DIR,
|
|
14
|
+
HOST_NAME,
|
|
15
|
+
STORE_EXTENSION_ID,
|
|
16
|
+
exists,
|
|
17
|
+
posixBrowsers,
|
|
18
|
+
resolveCodexHome,
|
|
19
|
+
windowsBrowsers
|
|
20
|
+
} from "./install.mjs";
|
|
21
|
+
|
|
22
|
+
const home = homedir();
|
|
23
|
+
const osPlatform = process.env.LLMNESIA_FAKE_PLATFORM || platform();
|
|
24
|
+
const execFileAsync = promisify(execFile);
|
|
25
|
+
const platformLabel = osPlatform === "darwin" ? "macOS" : osPlatform === "win32" ? "Windows" : "Linux";
|
|
26
|
+
|
|
27
|
+
// Speaks Chrome's native-messaging framing directly (a little-endian uint32
|
|
28
|
+
// byte-length prefix, then that many bytes of JSON) so this check exercises
|
|
29
|
+
// the exact same path the browser does — not just "does the file exist".
|
|
30
|
+
function pingHost(launchPath, isWindows) {
|
|
31
|
+
return new Promise((resolve) => {
|
|
32
|
+
let child;
|
|
33
|
+
try {
|
|
34
|
+
// Exercise the path Chrome launches: the executable script and its pinned
|
|
35
|
+
// shebang on POSIX, or the installed .bat launcher on Windows.
|
|
36
|
+
child = isWindows
|
|
37
|
+
? spawn(process.env.ComSpec || "cmd.exe", ["/d", "/s", "/c", `""${launchPath}""`], {
|
|
38
|
+
stdio: ["pipe", "pipe", "pipe"]
|
|
39
|
+
})
|
|
40
|
+
: spawn(launchPath, [], { stdio: ["pipe", "pipe", "pipe"] });
|
|
41
|
+
} catch (err) {
|
|
42
|
+
resolve({ ok: false, error: err instanceof Error ? err.message : String(err) });
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
let settled = false;
|
|
47
|
+
const settle = (result) => {
|
|
48
|
+
if (settled) return;
|
|
49
|
+
settled = true;
|
|
50
|
+
clearTimeout(timer);
|
|
51
|
+
try {
|
|
52
|
+
child.kill();
|
|
53
|
+
} catch {
|
|
54
|
+
// Already exited.
|
|
55
|
+
}
|
|
56
|
+
resolve(result);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const timer = setTimeout(() => settle({ ok: false, error: "No response within 3s" }), 3000);
|
|
60
|
+
|
|
61
|
+
let stderr = "";
|
|
62
|
+
child.stderr?.on("data", (chunk) => {
|
|
63
|
+
stderr += chunk.toString("utf8");
|
|
64
|
+
});
|
|
65
|
+
child.on("error", (err) => settle({ ok: false, error: err.message }));
|
|
66
|
+
child.on("exit", (code) => {
|
|
67
|
+
if (!settled) {
|
|
68
|
+
settle({ ok: false, error: stderr.trim() || `Helper exited with code ${code} before responding` });
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
let buffer = Buffer.alloc(0);
|
|
73
|
+
child.stdout?.on("data", (chunk) => {
|
|
74
|
+
buffer = Buffer.concat([buffer, chunk]);
|
|
75
|
+
if (buffer.length < 4) return;
|
|
76
|
+
const len = buffer.readUInt32LE(0);
|
|
77
|
+
if (buffer.length < 4 + len) return;
|
|
78
|
+
try {
|
|
79
|
+
const message = JSON.parse(buffer.subarray(4, 4 + len).toString("utf8"));
|
|
80
|
+
settle({ ok: true, message });
|
|
81
|
+
} catch (err) {
|
|
82
|
+
settle({ ok: false, error: `Malformed response: ${err instanceof Error ? err.message : String(err)}` });
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
const payload = Buffer.from(JSON.stringify({ cmd: "ping" }), "utf8");
|
|
87
|
+
const lenPrefix = Buffer.alloc(4);
|
|
88
|
+
lenPrefix.writeUInt32LE(payload.length, 0);
|
|
89
|
+
child.stdin?.write(Buffer.concat([lenPrefix, payload]));
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async function checkManifest(manifestPath, expectedLaunchPath) {
|
|
94
|
+
let manifest;
|
|
95
|
+
try {
|
|
96
|
+
manifest = JSON.parse(await readFile(manifestPath, "utf8"));
|
|
97
|
+
} catch (err) {
|
|
98
|
+
if (err && typeof err === "object" && err.code === "ENOENT") {
|
|
99
|
+
return { ok: false, error: "file not found — run the installer again" };
|
|
100
|
+
}
|
|
101
|
+
return { ok: false, error: err instanceof Error ? err.message : String(err) };
|
|
102
|
+
}
|
|
103
|
+
if (!manifest || typeof manifest !== "object" || Array.isArray(manifest)) {
|
|
104
|
+
return { ok: false, error: "manifest is not a JSON object" };
|
|
105
|
+
}
|
|
106
|
+
if (manifest.name !== HOST_NAME) {
|
|
107
|
+
return { ok: false, error: `wrong host name ${JSON.stringify(manifest.name)}` };
|
|
108
|
+
}
|
|
109
|
+
if (manifest.type !== "stdio") {
|
|
110
|
+
return { ok: false, error: `wrong type ${JSON.stringify(manifest.type)}` };
|
|
111
|
+
}
|
|
112
|
+
if (manifest.path !== expectedLaunchPath) {
|
|
113
|
+
return { ok: false, error: `points at ${JSON.stringify(manifest.path)}, expected ${JSON.stringify(expectedLaunchPath)}` };
|
|
114
|
+
}
|
|
115
|
+
const storeOrigin = `chrome-extension://${STORE_EXTENSION_ID}/`;
|
|
116
|
+
if (!Array.isArray(manifest.allowed_origins) || !manifest.allowed_origins.includes(storeOrigin)) {
|
|
117
|
+
return { ok: false, error: `does not allow the LLMnesia Web Store origin ${storeOrigin}` };
|
|
118
|
+
}
|
|
119
|
+
return { ok: true };
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
async function checkWindowsRegistry(vendorKey, expectedManifestPath) {
|
|
123
|
+
const key = `HKCU\\${vendorKey}\\NativeMessagingHosts\\${HOST_NAME}`;
|
|
124
|
+
const regExe = join(process.env.SystemRoot || "C:\\Windows", "System32", "reg.exe");
|
|
125
|
+
try {
|
|
126
|
+
const { stdout } = await execFileAsync(regExe, ["query", key, "/ve"]);
|
|
127
|
+
if (!stdout.toLowerCase().includes(expectedManifestPath.toLowerCase())) {
|
|
128
|
+
return { ok: false, key, error: `registry value does not point at ${expectedManifestPath}` };
|
|
129
|
+
}
|
|
130
|
+
return { ok: true, key };
|
|
131
|
+
} catch (err) {
|
|
132
|
+
return { ok: false, key, error: err instanceof Error ? err.message : String(err) };
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Run every check and print a report via `log` (defaults to console.log).
|
|
138
|
+
* Pure aside from its filesystem reads and the one ping subprocess — no writes.
|
|
139
|
+
*/
|
|
140
|
+
export async function runDoctor({ log = console.log } = {}) {
|
|
141
|
+
const isWindows = osPlatform === "win32";
|
|
142
|
+
const installDir = join(home, ".llmnesia");
|
|
143
|
+
const hostScriptPath = join(installDir, "llmnesia-claude-host.mjs");
|
|
144
|
+
const launchPath = isWindows ? join(installDir, "llmnesia-claude-host.bat") : hostScriptPath;
|
|
145
|
+
const configPath = join(installDir, "config.json");
|
|
146
|
+
|
|
147
|
+
log(`Platform: ${platformLabel}`);
|
|
148
|
+
log("");
|
|
149
|
+
|
|
150
|
+
const hostScriptFound = await exists(hostScriptPath);
|
|
151
|
+
log(hostScriptFound ? `✓ Helper script installed → ${hostScriptPath}` : `✗ No helper script at ${hostScriptPath} — run the installer.`);
|
|
152
|
+
|
|
153
|
+
log("");
|
|
154
|
+
log("Browser manifests:");
|
|
155
|
+
let anyManifest = false;
|
|
156
|
+
if (isWindows) {
|
|
157
|
+
const manifestPath = join(installDir, `${HOST_NAME}.json`);
|
|
158
|
+
const manifestCheck = await checkManifest(manifestPath, launchPath);
|
|
159
|
+
anyManifest = manifestCheck.ok;
|
|
160
|
+
log(
|
|
161
|
+
manifestCheck.ok
|
|
162
|
+
? ` ✓ Shared manifest → ${manifestPath}`
|
|
163
|
+
: ` ✗ Shared manifest at ${manifestPath} is missing or invalid: ${manifestCheck.error}`
|
|
164
|
+
);
|
|
165
|
+
for (const [label, userDataDir, vendorKey] of windowsBrowsers()) {
|
|
166
|
+
if (await exists(userDataDir)) {
|
|
167
|
+
const registryCheck = await checkWindowsRegistry(vendorKey, manifestPath);
|
|
168
|
+
log(
|
|
169
|
+
registryCheck.ok
|
|
170
|
+
? ` ✓ ${label} registry → ${manifestPath}`
|
|
171
|
+
: ` ✗ ${label} registry key ${registryCheck.key} is missing or invalid: ${registryCheck.error}`
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
} else {
|
|
176
|
+
for (const [label, browserDir] of posixBrowsers()) {
|
|
177
|
+
if (!(await exists(browserDir))) {
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
const manifestPath = join(browserDir, "NativeMessagingHosts", `${HOST_NAME}.json`);
|
|
181
|
+
const manifestCheck = await checkManifest(manifestPath, launchPath);
|
|
182
|
+
anyManifest = anyManifest || manifestCheck.ok;
|
|
183
|
+
log(
|
|
184
|
+
manifestCheck.ok
|
|
185
|
+
? ` ✓ ${label} → ${manifestPath}`
|
|
186
|
+
: ` ✗ ${label} manifest at ${manifestPath} is missing or invalid: ${manifestCheck.error}`
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
if (!anyManifest) {
|
|
190
|
+
log(" No valid manifest found for a supported browser.");
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
log("");
|
|
195
|
+
let config = null;
|
|
196
|
+
try {
|
|
197
|
+
config = JSON.parse(await readFile(configPath, "utf8"));
|
|
198
|
+
log(`✓ Config → ${configPath}`);
|
|
199
|
+
if (typeof config.corpusRoot === "string") {
|
|
200
|
+
log(` corpus root: ${config.corpusRoot}`);
|
|
201
|
+
}
|
|
202
|
+
} catch (err) {
|
|
203
|
+
if (err && typeof err === "object" && err.code === "ENOENT") {
|
|
204
|
+
log(`✗ Settings file not found at ${configPath} — run the installer again.`);
|
|
205
|
+
} else {
|
|
206
|
+
log(`✗ Config at ${configPath} exists but couldn't be read: ${err instanceof Error ? err.message : String(err)}`);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
const codexHome = resolveCodexHome(config && typeof config.codexHome === "string" ? config.codexHome : undefined);
|
|
211
|
+
log("");
|
|
212
|
+
log("Session sources:");
|
|
213
|
+
log((await exists(CLAUDE_PROJECTS_DIR)) ? ` ✓ Claude Code sessions at ${CLAUDE_PROJECTS_DIR}` : ` - No Claude Code sessions at ${CLAUDE_PROJECTS_DIR} (fine if you don't use it).`);
|
|
214
|
+
log((await exists(join(codexHome, "sessions"))) ? ` ✓ Codex sessions at ${codexHome}` : ` - No Codex sessions at ${codexHome} (fine if you don't use it).`);
|
|
215
|
+
|
|
216
|
+
log("");
|
|
217
|
+
log("Pinging the helper…");
|
|
218
|
+
if (!hostScriptFound) {
|
|
219
|
+
log("✗ Skipped — no helper script to run.");
|
|
220
|
+
} else {
|
|
221
|
+
const result = await pingHost(launchPath, isWindows);
|
|
222
|
+
if (result.ok && result.message?.type === "pong") {
|
|
223
|
+
log(`✓ Helper responded — protocol v${result.message.version}.`);
|
|
224
|
+
} else if (result.ok) {
|
|
225
|
+
log(`✗ Helper responded, but not with a pong: ${JSON.stringify(result.message)}`);
|
|
226
|
+
} else {
|
|
227
|
+
log(`✗ Helper could not start or answer: ${result.error}`);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
log("");
|
|
232
|
+
log("If any check is red, run the install command again. If every check is green, fully quit the browser (not just close its window), reopen it, and try LLMnesia Settings once more.");
|
|
233
|
+
}
|
package/install.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// Hand-authored declarations for install.mjs (plain JS + JSDoc, no build step).
|
|
2
|
+
// Kept in sync manually with the exports in install.mjs.
|
|
3
|
+
|
|
4
|
+
export const HOST_NAME: string;
|
|
5
|
+
export const STORE_EXTENSION_ID: string;
|
|
6
|
+
export const CLAUDE_PROJECTS_DIR: string;
|
|
7
|
+
|
|
8
|
+
export function exists(path: string): Promise<boolean>;
|
|
9
|
+
export function expandHome(p: string): string;
|
|
10
|
+
export function resolveCorpusDir(explicit?: string): string;
|
|
11
|
+
export function resolveCodexHome(explicit?: string): string;
|
|
12
|
+
export function posixBrowsers(
|
|
13
|
+
homeDir?: string,
|
|
14
|
+
forPlatform?: string
|
|
15
|
+
): Array<[label: string, browserDir: string]>;
|
|
16
|
+
export function windowsBrowsers(): Array<[label: string, userDataDir: string, vendorRegistryKey: string]>;
|
|
17
|
+
|
|
18
|
+
export type InstallNativeHostOptions = {
|
|
19
|
+
ids?: string[];
|
|
20
|
+
corpus?: string;
|
|
21
|
+
codexHome?: string;
|
|
22
|
+
force?: boolean;
|
|
23
|
+
quiet?: boolean;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export type InstallNativeHostResult = {
|
|
27
|
+
installedCount: number;
|
|
28
|
+
allowedIds: string[];
|
|
29
|
+
configPath: string;
|
|
30
|
+
corpusRoot: string;
|
|
31
|
+
corpusRootChanged: boolean;
|
|
32
|
+
codexHome: string;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export function installNativeHost(options?: InstallNativeHostOptions): Promise<InstallNativeHostResult>;
|
|
36
|
+
|
|
37
|
+
export type UninstallNativeHostResult = {
|
|
38
|
+
removed: string[];
|
|
39
|
+
corpusRoot: string | null;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export function uninstallNativeHost(): Promise<UninstallNativeHostResult>;
|