@llmnesia/local-agent-host 0.3.6 → 0.3.7

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/install.mjs CHANGED
@@ -226,6 +226,12 @@ async function installWindows(manifestBase, hostPath, installDir, log) {
226
226
  return installed;
227
227
  }
228
228
 
229
+ /** The helper's `const PROTOCOL_VERSION = N`, or null when it has none. */
230
+ function hostProtocolVersion(source) {
231
+ const match = /^const PROTOCOL_VERSION = (\d+);$/m.exec(source);
232
+ return match ? Number(match[1]) : null;
233
+ }
234
+
229
235
  /**
230
236
  * Install (or update) the native-messaging host and its corpus config. Pure
231
237
  * function of its arguments — no process.argv/process.exit — so it can be
@@ -281,11 +287,20 @@ export async function installNativeHost({ ids = [], corpus, codexHome, force = f
281
287
  // Windows the .bat wrapper invokes node explicitly, so the shebang is unused.
282
288
  const hosted = isWindows ? hostSource : hostSource.replace(/^#![^\n]*\n/, `#!${process.execPath}\n`);
283
289
  const hostPath = join(installDir, "llmnesia-claude-host.mjs");
284
- await writeFile(hostPath, hosted, "utf8");
285
- if (!isWindows) {
286
- await chmod(hostPath, 0o755);
290
+ // Two packages install this helper (@llmnesia/local-agent-host and
291
+ // @llmnesia/mcp), each bundling its own copy. Never let the older bundle
292
+ // replace a helper that speaks a newer protocol: the extension relies on it.
293
+ const installedProtocol = hostProtocolVersion(await readFile(hostPath, "utf8").catch(() => ""));
294
+ const bundledProtocol = hostProtocolVersion(hostSource);
295
+ if (installedProtocol !== null && bundledProtocol !== null && installedProtocol > bundledProtocol) {
296
+ log(`✓ Helper already up to date (kept the newer protocol ${installedProtocol} helper)`);
297
+ } else {
298
+ await writeFile(hostPath, hosted, "utf8");
299
+ if (!isWindows) {
300
+ await chmod(hostPath, 0o755);
301
+ }
302
+ log("✓ Helper installed");
287
303
  }
288
- log("✓ Helper installed");
289
304
 
290
305
  const manifestBase = {
291
306
  name: HOST_NAME,
@@ -53,7 +53,8 @@
53
53
  // { cmd: "get", source, sessionId } → one or more { type: "chunk", sessionId, seq, total, data }
54
54
  // then { type: "sessionDone", sessionId }
55
55
  // (or { type: "session", sessionId, notFound: true })
56
- // { cmd: "corpusInfo" } → { type: "corpusInfo", present, root? }
56
+ // { cmd: "corpusInfo" } → { type: "corpusInfo", present, root?,
57
+ // sourceHealthSupported?, sourceHealthSources? }
57
58
  // { cmd: "putChunk", filename,
58
59
  // seq, total, data } → { type: "chunkAck", seq }
59
60
  // (writes <root>/inbox/<filename> once
@@ -1090,11 +1091,18 @@ async function readCorpusMemories(corpusRoot) {
1090
1091
 
1091
1092
  // A separate metadata channel keeps health heartbeats out of the conversation
1092
1093
  // inbox. Older MCP readers ignore this file and keep their true data age.
1094
+ // The sources this host stores health for, advertised on corpusInfo so an
1095
+ // extension newer than the host sends only rows the host understands.
1096
+ const SOURCE_HEALTH_SOURCES = ["claude_code", "codex", "zcode", "vibe"];
1097
+ // Generous on purpose: an extension that adds a source must not get its whole
1098
+ // report rejected by an older host. Unknown sources are skipped, not fatal.
1099
+ const MAX_SOURCE_HEALTH_ROWS = 32;
1100
+
1093
1101
  function sourceHealthRow(value) {
1094
1102
  if (!value || typeof value !== "object") return null;
1095
1103
  const { source, observedAt, connection, state, lastAttemptAt, lastSuccessfulSyncAt, lastCaptureAt, failedSessions } = value;
1096
1104
  const time = (v) => Number.isSafeInteger(v) && v >= 0;
1097
- if (!["claude_code", "codex", "zcode", "vibe"].includes(source) || !["connected", "disconnected"].includes(connection) ||
1105
+ if (!SOURCE_HEALTH_SOURCES.includes(source) || !["connected", "disconnected"].includes(connection) ||
1098
1106
  !["ok", "partial", "missing", "error", "unknown"].includes(state) || !time(observedAt) ||
1099
1107
  observedAt > Date.now() + 300000 || !time(lastAttemptAt) || lastAttemptAt > observedAt ||
1100
1108
  (lastSuccessfulSyncAt !== null && (!time(lastSuccessfulSyncAt) || lastSuccessfulSyncAt > observedAt)) ||
@@ -1104,10 +1112,15 @@ function sourceHealthRow(value) {
1104
1112
 
1105
1113
  async function handleSourceHealth(message) {
1106
1114
  const config = await loadConfig();
1107
- if (!config?.corpusRoot || !Array.isArray(message.rows) || message.rows.length > 4) {
1108
- send({ type: "error", error: "source health: invalid rows or no corpus configured" }); return;
1115
+ if (!config?.corpusRoot) {
1116
+ send({ type: "error", error: "source health: no corpus configured (run the installer)" }); return;
1117
+ }
1118
+ if (!Array.isArray(message.rows) || message.rows.length > MAX_SOURCE_HEALTH_ROWS) {
1119
+ send({ type: "error", error: "source health: rows must be an array of at most " + MAX_SOURCE_HEALTH_ROWS }); return;
1109
1120
  }
1110
- const rows = message.rows.map(sourceHealthRow);
1121
+ // A source this host does not know yet (a newer extension) is skipped so
1122
+ // the rows it does know still land.
1123
+ const rows = message.rows.filter((row) => SOURCE_HEALTH_SOURCES.includes(row?.source)).map(sourceHealthRow);
1111
1124
  if (rows.some((row) => !row)) {
1112
1125
  send({ type: "error", error: "source health: invalid report" }); return;
1113
1126
  }
@@ -1576,7 +1589,7 @@ async function handle(message) {
1576
1589
  send({ type: "corpusInfo", present: false });
1577
1590
  return;
1578
1591
  }
1579
- send({ type: "corpusInfo", present: true, root: config.corpusRoot, sourceHealthSupported: true });
1592
+ send({ type: "corpusInfo", present: true, root: config.corpusRoot, sourceHealthSupported: true, sourceHealthSources: SOURCE_HEALTH_SOURCES });
1580
1593
  return;
1581
1594
  }
1582
1595
  if (message.cmd === "putSourceHealth") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@llmnesia/local-agent-host",
3
- "version": "0.3.6",
3
+ "version": "0.3.7",
4
4
  "description": "LLMnesia native messaging host: lets the browser extension read local coding-agent sessions (Claude Code, Codex, ZCode, Mistral Vibe) automatically.",
5
5
  "keywords": [
6
6
  "llmnesia",