@insitue/claude-plugin 0.5.1 → 0.5.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/CHANGELOG.md CHANGED
@@ -1,5 +1,30 @@
1
1
  # @insitue/claude-plugin
2
2
 
3
+ ## 0.5.2
4
+
5
+ - **Fix (hardcoded protocol version):** `mcp-server.ts` was sending
6
+ `protocolVersion: 5` as a literal in the WS hello handshake — the
7
+ same class of bug fixed in `@insitue/companion` 0.4.4 for the CLI
8
+ subscriber path. The literal would silently mismatch the next time
9
+ `@insitue/capture-core` bumps `PROTOCOL_VERSION`. The value is now
10
+ imported from `@insitue/capture-core` (added as a real dependency)
11
+ so there is a single source of truth. `@insitue/capture-core` is
12
+ bundled by tsup (not external) — no new runtime dep in the published
13
+ package.
14
+ - **Fix (subscriber attach race — `start_session` / `list_recent_picks`
15
+ says "connected" before it is):** `connectToCompanion` previously
16
+ returned `void` and was not awaited in `ensureSubscriberAttached`.
17
+ This meant `list_recent_picks` (and therefore the `/insitue:connect`
18
+ slash command) could return "No picks buffered yet" before the
19
+ companion had added this MCP server to its `subscribers` set — so
20
+ the browser launcher badge stayed dark for a moment after claude
21
+ claimed to be listening. `connectToCompanion` now returns a
22
+ `Promise<boolean>` that resolves `true` when `subscribe-ok` arrives
23
+ (subscriber set joined, badge lit), or `false` on pre-subscribe
24
+ close. `ensureSubscriberAttached` awaits it and resets `attached` on
25
+ failure so the next explicit call retries cleanly.
26
+ - Bumped 0.5.1 → 0.5.2.
27
+
3
28
  ## 0.5.1
4
29
 
5
30
  - **Docs:** the operating instructions (`commands/connect.md`) now document
@@ -29,6 +29,7 @@ import { dirname as dirname3, join as join3 } from "path";
29
29
  import { fileURLToPath as fileURLToPath2 } from "url";
30
30
  import WebSocket from "ws";
31
31
  import { z } from "zod";
32
+ import { PROTOCOL_VERSION } from "@insitue/capture-core";
32
33
 
33
34
  // src/file-tools.ts
34
35
  import {
@@ -388,68 +389,81 @@ var activeWs = null;
388
389
  var reconnectTimer = null;
389
390
  var disconnecting = false;
390
391
  function connectToCompanion(s) {
391
- const url = `ws://127.0.0.1:${s.port}/insitue/cli`;
392
- const ws = new WebSocket(url, {
393
- headers: { "user-agent": "insitue-claude-plugin" }
394
- });
395
- activeWs = ws;
396
- ws.on("open", () => {
397
- ws.send(
398
- JSON.stringify({
399
- t: "hello",
400
- // Pin to the companion's pinned protocol version. Bump
401
- // when the wire format breaks.
402
- protocolVersion: 5,
403
- token: s.token
404
- })
405
- );
406
- });
407
- ws.on("message", (data) => {
408
- let m;
409
- try {
410
- m = JSON.parse(String(data));
411
- } catch {
412
- return;
413
- }
414
- if (m && typeof m === "object") {
415
- const tag = m.t;
416
- if (tag === "hello-ok") {
417
- ws.send(JSON.stringify({ t: "subscribe" }));
392
+ return new Promise((subscribeResolve) => {
393
+ let subscribed = false;
394
+ const url = `ws://127.0.0.1:${s.port}/insitue/cli`;
395
+ const ws = new WebSocket(url, {
396
+ headers: { "user-agent": "insitue-claude-plugin" }
397
+ });
398
+ activeWs = ws;
399
+ ws.on("open", () => {
400
+ ws.send(
401
+ JSON.stringify({
402
+ t: "hello",
403
+ // Imported from @insitue/capture-core — the single source of
404
+ // truth for the wire protocol version. A hardcoded literal here
405
+ // would silently drift the moment the capture-core version is
406
+ // bumped (same class of bug fixed in companion 0.4.4).
407
+ protocolVersion: PROTOCOL_VERSION,
408
+ token: s.token
409
+ })
410
+ );
411
+ });
412
+ ws.on("message", (data) => {
413
+ let m;
414
+ try {
415
+ m = JSON.parse(String(data));
416
+ } catch {
418
417
  return;
419
418
  }
420
- if (tag === "broadcast-capture") {
421
- try {
422
- const summary = summariseBundle(
423
- m
424
- );
425
- buffer.push(summary);
426
- const note = summary.userNote ? summary.userNote.length > 60 ? `${summary.userNote.slice(0, 57)}\u2026` : summary.userNote : "(no description)";
427
- const where = summary.source ? `${summary.source.file}:${summary.source.line}` : summary.target;
428
- process.stderr.write(
429
- `[insitue] \u{1F4E5} pick received \u2014 "${note}" @ ${where}
419
+ if (m && typeof m === "object") {
420
+ const tag = m.t;
421
+ if (tag === "hello-ok") {
422
+ ws.send(JSON.stringify({ t: "subscribe" }));
423
+ return;
424
+ }
425
+ if (tag === "subscribe-ok") {
426
+ if (!subscribed) {
427
+ subscribed = true;
428
+ subscribeResolve(true);
429
+ }
430
+ return;
431
+ }
432
+ if (tag === "broadcast-capture") {
433
+ try {
434
+ const summary = summariseBundle(
435
+ m
436
+ );
437
+ buffer.push(summary);
438
+ const note = summary.userNote ? summary.userNote.length > 60 ? `${summary.userNote.slice(0, 57)}\u2026` : summary.userNote : "(no description)";
439
+ const where = summary.source ? `${summary.source.file}:${summary.source.line}` : summary.target;
440
+ process.stderr.write(
441
+ `[insitue] \u{1F4E5} pick received \u2014 "${note}" @ ${where}
430
442
  `
431
- );
432
- } catch (err) {
433
- process.stderr.write(
434
- `[insitue-mcp] dropped malformed pick: ${err.message}
443
+ );
444
+ } catch (err) {
445
+ process.stderr.write(
446
+ `[insitue-mcp] dropped malformed pick: ${err.message}
435
447
  `
436
- );
448
+ );
449
+ }
450
+ return;
437
451
  }
438
- return;
452
+ if (tag === "broadcast-ask") return;
439
453
  }
440
- if (tag === "broadcast-ask") return;
441
- }
442
- });
443
- ws.on("close", () => {
444
- if (activeWs === ws) activeWs = null;
445
- buffer.dropWaiters();
446
- if (disconnecting) return;
447
- process.stderr.write(
448
- "[insitue-mcp] companion link dropped \u2014 reconnecting in 2s\n"
449
- );
450
- reconnectTimer = setTimeout(() => connectToCompanion(s), 2e3);
451
- });
452
- ws.on("error", () => {
454
+ });
455
+ ws.on("close", () => {
456
+ if (!subscribed) subscribeResolve(false);
457
+ if (activeWs === ws) activeWs = null;
458
+ buffer.dropWaiters();
459
+ if (disconnecting) return;
460
+ process.stderr.write(
461
+ "[insitue-mcp] companion link dropped \u2014 reconnecting in 2s\n"
462
+ );
463
+ reconnectTimer = setTimeout(() => void connectToCompanion(s), 2e3);
464
+ });
465
+ ws.on("error", () => {
466
+ });
453
467
  });
454
468
  }
455
469
  var projectDir = resolveProjectDir();
@@ -473,7 +487,13 @@ async function ensureSubscriberAttached(opts = {}) {
473
487
  if (!session) return;
474
488
  }
475
489
  attached = true;
476
- connectToCompanion(session);
490
+ const ok = await connectToCompanion(session);
491
+ if (!ok) {
492
+ attached = false;
493
+ process.stderr.write(
494
+ "[insitue-mcp] subscriber attach failed \u2014 companion handshake did not complete\n"
495
+ );
496
+ }
477
497
  }
478
498
  function endSession() {
479
499
  disconnecting = true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@insitue/claude-plugin",
3
- "version": "0.5.1",
3
+ "version": "0.5.2",
4
4
  "description": "Drive Claude (Code AND Desktop) from the InSitue browser overlay — pick an element in your app, claude reads the file and proposes the edit.",
5
5
  "keywords": [
6
6
  "insitue",
@@ -38,7 +38,8 @@
38
38
  "dependencies": {
39
39
  "@modelcontextprotocol/sdk": "^1.29.0",
40
40
  "ws": "^8.18.0",
41
- "zod": "^3.23.8"
41
+ "zod": "^3.23.8",
42
+ "@insitue/capture-core": "0.4.1"
42
43
  },
43
44
  "devDependencies": {
44
45
  "@types/ws": "^8.5.13",