claude-code-memory-explorer 1.1.0 → 1.1.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/lib/net-guard.js CHANGED
@@ -37,11 +37,14 @@ const PORT_RE = /^[0-9]{1,5}$/;
37
37
  // port dynamic, so only the host is allowlisted.
38
38
  const validPort = (p) => PORT_RE.test(p) && Number(p) >= 1 && Number(p) <= 65535;
39
39
  const KEEP_ALIVE_MS = 65000;
40
+ // A whole IPv4 literal: a prefix test would let a rebinding name like 127.evil.com through.
41
+ const LOOPBACK_V4_RE = /^127(?:\.(?:25[0-5]|2[0-4]\d|1?\d?\d)){3}$/;
40
42
 
41
43
  function isLoopbackAddress(host) {
42
44
  if (!host) return false;
43
- const h = String(host).toLowerCase();
44
- return LOOPBACK_HOSTS.has(h) || h.startsWith('127.');
45
+ // An Origin or URL host carries an IPv6 literal in brackets.
46
+ const h = String(host).toLowerCase().replace(/^\[(.*)\]$/, '$1');
47
+ return LOOPBACK_HOSTS.has(h) || LOOPBACK_V4_RE.test(h);
45
48
  }
46
49
 
47
50
  // Hand-parsed rather than via new URL(), which is far more permissive than we
@@ -102,7 +105,7 @@ function getFlag(name) {
102
105
  }
103
106
 
104
107
  /**
105
- * @param {{appName?: string}} [config]
108
+ * @param {{appName?: string, selfFramedPaths?: string[]}} [config]
106
109
  */
107
110
  function createNetGuard(config = {}) {
108
111
  const appName = config.appName || 'This app';
@@ -216,9 +219,18 @@ function createNetGuard(config = {}) {
216
219
  CSP = "frame-ancestors 'none'";
217
220
  }
218
221
 
219
- function frameGuard(_req, res, next) {
222
+ // Alone, these pages may be framed by this app's own port under its loopback names, for a page
223
+ // that frames itself from its other name to get its own renderer process.
224
+ const selfFramed = new Set(config.selfFramedPaths || []);
225
+
226
+ function frameGuard(req, res, next) {
220
227
  res.setHeader('X-Content-Type-Options', 'nosniff');
221
228
  res.setHeader('Referrer-Policy', 'no-referrer');
229
+ if (!hubOrigin && selfFramed.has(req.path)) {
230
+ const port = req.socket.localPort;
231
+ res.setHeader('Content-Security-Policy', `frame-ancestors 'self' http://localhost:${port} http://127.0.0.1:${port}`);
232
+ return next();
233
+ }
222
234
  res.setHeader('Content-Security-Policy', CSP);
223
235
  if (!hubOrigin) res.setHeader('X-Frame-Options', 'DENY');
224
236
  next();
@@ -232,7 +244,10 @@ function createNetGuard(config = {}) {
232
244
  * the OS resolver orders A/AAAA records - binding only 127.0.0.1 breaks hosts
233
245
  * where `localhost` resolves to ::1, and vice versa. Doing it on the *resolved*
234
246
  * port means every existing URL, startup banner and postMessage origin is
235
- * unchanged. Failures are swallowed: it is an optimization, not a requirement.
247
+ * unchanged. A family the host does not have is skipped. A port that another
248
+ * process holds on the other family is treated as busy: the primary closes and
249
+ * emits EADDRINUSE (port 0 picks another random port instead), because that process would answer `localhost:<port>` (and a
250
+ * cross-site frame on it) in our name. onReady waits for the second bind.
236
251
  *
237
252
  * Returns the primary server, so callers keep attaching their own 'error'
238
253
  * handler for the EADDRINUSE fallback.
@@ -259,18 +274,30 @@ function createNetGuard(config = {}) {
259
274
  };
260
275
  const server = makeServer(app);
261
276
  let secondary = null;
277
+ let randomTries = 0;
262
278
 
263
279
  server.on('listening', () => {
264
- actualPort = server.address().port;
265
- if (!EXPOSED) {
266
- const otherFamily = BIND_HOST.includes(':') ? '127.0.0.1' : '::1';
267
- try {
268
- secondary = makeServer(app);
269
- secondary.on('error', () => {}); // that family may not exist on this host
270
- secondary.listen({ host: otherFamily, port: actualPort, ipv6Only: otherFamily === '::1' });
271
- } catch { /* best effort */ }
280
+ const boundPort = server.address().port;
281
+ actualPort = boundPort;
282
+ // Not actualPort: the hub listens several servers through one guard, and another one can bind
283
+ // while this one waits for its second family.
284
+ const ready = () => { if (onReady) onReady(boundPort); };
285
+ if (EXPOSED) return ready();
286
+ const otherFamily = BIND_HOST.includes(':') ? '127.0.0.1' : '::1';
287
+ try {
288
+ secondary = makeServer(app);
289
+ secondary.once('listening', ready);
290
+ secondary.on('error', (err) => {
291
+ if (err.code !== 'EADDRINUSE') return ready();
292
+ // A caller asking for port 0 has no fallback of its own, so it gets another random port here.
293
+ if (port === 0 && ++randomTries < 5) return server.close(() => server.listen(0, BIND_HOST));
294
+ server.close();
295
+ server.emit('error', err);
296
+ });
297
+ secondary.listen({ host: otherFamily, port: boundPort, ipv6Only: otherFamily === '::1' });
298
+ } catch {
299
+ ready();
272
300
  }
273
- if (onReady) onReady(actualPort);
274
301
  });
275
302
  server.on('close', () => { try { if (secondary) secondary.close(); } catch { /* already gone */ } });
276
303
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-code-memory-explorer",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "Memory explorer dashboard for Claude Code",
5
5
  "main": "server.js",
6
6
  "type": "commonjs",
@@ -1,9 +1,18 @@
1
- // claude-hub-sdk 1.1.0 (sha256 0fed14faa670). Copied by npm run sdk:sync in claude-code-hub. Do not edit.
1
+ // claude-hub-sdk 1.2.0 (sha256 62c7d9f477b2). Copied by npm run sdk:sync in claude-code-hub. Do not edit.
2
2
  // Claude Code Hub SDK stub: what an app serves when no hub runs it. Under a hub, the hub hands the
3
3
  // app its real SDK (client.js) in place of this file. The API must match client.js; a test checks it.
4
4
  ((root) => {
5
5
  'use strict';
6
6
 
7
+ // A copy of client.js comboOf(); a test checks they match.
8
+ function comboOf(e) {
9
+ const lower = typeof e.key === 'string' ? e.key.toLowerCase() : '';
10
+ const m = /^(?:Key|Digit)([A-Z1-9])$/.exec(e.code || '');
11
+ const key = /^[a-z1-9]$/.test(lower) ? lower : m ? m[1].toLowerCase() : e.key;
12
+ const mods = [e.ctrlKey && 'ctrl', e.altKey && 'alt', e.shiftKey && 'shift', e.metaKey && 'meta'];
13
+ return [...mods, key].filter(Boolean).join('+');
14
+ }
15
+
7
16
  function createClaudeHub(win) {
8
17
  let hub = null;
9
18
  const off = () => {};
@@ -33,6 +42,7 @@
33
42
  },
34
43
  can: (action) => !!standaloneFn(action),
35
44
  forwards: () => false,
45
+ forwardCombos: () => [],
36
46
  closeGuard() {},
37
47
  openExternal(url) {
38
48
  win.open(url, '_blank', 'noopener');
@@ -42,9 +52,9 @@
42
52
  return hub;
43
53
  }
44
54
 
45
- return { connect };
55
+ return { connect, comboOf };
46
56
  }
47
57
 
48
- if (typeof module === 'object' && module.exports) module.exports = { createClaudeHub };
58
+ if (typeof module === 'object' && module.exports) module.exports = { createClaudeHub, comboOf };
49
59
  else root.ClaudeHub = createClaudeHub(root);
50
60
  })(typeof window !== 'undefined' ? window : globalThis);