@insitue/claude-plugin 0.5.0 → 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,62 @@
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
+
28
+ ## 0.5.1
29
+
30
+ - **Docs:** the operating instructions (`commands/connect.md`) now document
31
+ the cloud-issue workflow — `list_cloud_issues`, `claim_cloud_issue`,
32
+ `resolve_cloud_issue`, and `release_cloud_issue`. Previously these tools
33
+ were registered in the MCP server but not mentioned in the instructions
34
+ surfaced via `/insitue:connect`, `start_session`, or the `connect` prompt,
35
+ so Claude had no way to know the workflow existed. The new section covers
36
+ the claim→fix→PR→resolve loop, prerequisites (`insitue login` +
37
+ `insitue link`), the paid-plan requirement, and how to handle
38
+ `not_logged_in` / `not_linked` / `not_paid` error codes.
39
+
40
+ ## 0.5.0
41
+
42
+ - **Feature:** four new MCP tools for working the InSitue Cloud issue queue
43
+ from a local Claude session:
44
+ - `list_cloud_issues` — list open bug reports for the linked project.
45
+ - `claim_cloud_issue(id)` — claim an issue; returns the full repro: note,
46
+ source `file:line`, page URL, and top console errors.
47
+ - `resolve_cloud_issue(id, prUrl, branch?)` — mark resolved and attach the
48
+ GitHub PR URL; `branch` is optional.
49
+ - `release_cloud_issue(id)` — return a claimed issue to the open queue.
50
+ - **Docs:** added "Fix cloud issues from Claude" section to the README
51
+ covering prerequisites (`insitue login` + `insitue link`), the
52
+ claim→fix→resolve loop, and a typical Claude session transcript.
53
+ - **Docs:** added the four cloud-issue tools to the MCP tools reference
54
+ table in the Architecture section.
55
+
56
+ Requires a paid InSitue Cloud plan. Uses the project link written by
57
+ `insitue link <projectId>` (the `@insitue/companion` CLI) and the auth
58
+ token from `insitue login`.
59
+
3
60
  ## 0.4.6
4
61
 
5
62
  - **Fix (Windows):** `isInsideProject` now uses `path.sep` instead of a
package/README.md CHANGED
@@ -233,6 +233,65 @@ extensively to stderr; claude surfaces them in the transcript.
233
233
 
234
234
  ---
235
235
 
236
+ ## Fix cloud issues from Claude
237
+
238
+ > Requires a **paid InSitue Cloud plan** and the `@insitue/companion` CLI.
239
+
240
+ If your project uses InSitue Cloud, bug reports captured in production land in your Cloud issue queue. The four `cloud_issue_*` MCP tools let Claude list those issues, claim one, read the full repro, fix it locally, and mark it resolved — all without leaving the terminal.
241
+
242
+ ### Prerequisites
243
+
244
+ 1. **Authenticate:** run `insitue login` (from the `@insitue/companion` CLI). This stores a token at `~/.insitue/auth.json`. Get the token at <https://app.insitue.com/app/settings/developer>.
245
+ 2. **Link your project:** run `insitue link <projectId>` in your project root. The tools read the linked project from `.insitue/project.json`.
246
+
247
+ ### The loop
248
+
249
+ ```
250
+ list_cloud_issues ← what's open?
251
+
252
+ claim_cloud_issue(id) ← lock the issue; receive full repro
253
+
254
+ (Claude reads source file, applies fix, opens a PR)
255
+
256
+ resolve_cloud_issue(id, prUrl, branch?) ← attach the PR; close the issue
257
+ ```
258
+
259
+ If you claim an issue and decide not to fix it, call `release_cloud_issue(id)` to return it to the queue so someone else can pick it up.
260
+
261
+ ### MCP tools
262
+
263
+ | Tool | Arguments | What it does |
264
+ |---|---|---|
265
+ | `list_cloud_issues` | — | Lists open bug reports for the linked project. |
266
+ | `claim_cloud_issue` | `id` | Claims the issue and returns the full repro: description (note), source `file:line`, page URL, and top console errors. |
267
+ | `resolve_cloud_issue` | `id`, `prUrl`, `branch?` | Marks the issue resolved and attaches the GitHub PR URL. `branch` is optional — include it when the fix isn't on the default branch yet. |
268
+ | `release_cloud_issue` | `id` | Returns a claimed issue to the open queue without resolving it. |
269
+
270
+ ### Typical Claude session
271
+
272
+ ```
273
+ > /insitue:connect
274
+ # (pick-and-edit loop starts as normal)
275
+
276
+ # Switch to cloud issues:
277
+ > list open cloud issues
278
+ # Claude calls list_cloud_issues, picks one.
279
+
280
+ > claim issue <id>
281
+ # Claude calls claim_cloud_issue — gets note, file:line, page URL, console errors.
282
+ # Claude opens the source file at the reported line, reads context, writes a fix.
283
+ # Claude opens a PR via gh or the normal git flow.
284
+
285
+ > resolve issue <id> with PR https://github.com/…/pull/42
286
+ # Claude calls resolve_cloud_issue(id, "https://github.com/…/pull/42").
287
+ ```
288
+
289
+ The cloud-issue tools compose naturally with the pick→edit loop — you can interleave browser picks and issue fixes in the same session.
290
+
291
+ See [Fix cloud issues locally](../../docs/fix-cloud-issues-locally.md) for a full walkthrough.
292
+
293
+ ---
294
+
236
295
  ## Architecture (skip unless curious)
237
296
 
238
297
  The plugin is a stdio MCP server that:
@@ -267,6 +326,10 @@ The plugin is a stdio MCP server that:
267
326
  | `read_file` | Project-scoped file read. Desktop fallback (Code has native Read). |
268
327
  | `apply_edit` | Project-scoped string-replacement edit. Desktop fallback (Code has native Edit). |
269
328
  | `write_file` | Project-scoped full-file write. Desktop fallback. |
329
+ | `list_cloud_issues` | List open InSitue Cloud bug reports for the linked project. Paid plan + `insitue link` required. |
330
+ | `claim_cloud_issue` | Claim an issue by `id`; returns note, source `file:line`, page URL, and top console errors. |
331
+ | `resolve_cloud_issue` | Mark an issue resolved; attach `prUrl` and optional `branch`. |
332
+ | `release_cloud_issue` | Return a claimed issue to the open queue. |
270
333
 
271
334
  All file tools resolve paths against the project dir and refuse
272
335
  anything that resolves outside it (realpath-checked, so `..` games
@@ -115,6 +115,56 @@ Either path is fine; pick whichever your runtime has.
115
115
  first and ask "want me to do X too?" rather than bundling
116
116
  silently.
117
117
 
118
+ ## Cloud-issue loop (paid plan, signed-in users)
119
+
120
+ In addition to browser picks, you can pull and fix pre-captured bug
121
+ reports from the InSitue dashboard. This is a separate workflow —
122
+ both can be used in the same session.
123
+
124
+ **Tools:**
125
+
126
+ - `mcp__insitue__list_cloud_issues` — show the open issue queue for
127
+ the linked project. Each entry has an `id`, a short `description`,
128
+ and a `source file:line` where known. Call this when the user says
129
+ "show me issues", "what's in the queue", or similar.
130
+ - `mcp__insitue__claim_cloud_issue <id>` — claim an issue (marks it
131
+ "fixing locally" in the dashboard) and return its repro context:
132
+ `note` (the reporter's description), `source.file:line`, `url`
133
+ (the page where it was captured), and `consoleErrors`. On a
134
+ successful claim: read the source file around the reported line,
135
+ reproduce from the note, make the fix, open a PR, then call
136
+ `resolve_cloud_issue`.
137
+ - `mcp__insitue__resolve_cloud_issue <id> <prUrl>` — mark the issue
138
+ resolved and attach the GitHub PR URL. Call this after the PR is
139
+ open, not before.
140
+ - `mcp__insitue__release_cloud_issue <id>` — abandon the claim and
141
+ return the issue to the open queue (use when you decide not to fix
142
+ it locally).
143
+
144
+ **Prerequisites.** These tools require:
145
+ - `insitue login` (creates `~/.insitue/auth.json` — generate a
146
+ token at https://app.insitue.com/app/settings/developer)
147
+ - `insitue link <projectId>` run in this repo (writes
148
+ `.insitue/project.json` — find the id in your project settings)
149
+ - A paid InSitue Cloud plan
150
+
151
+ If any tool returns `error: "not_logged_in"`, `"not_linked"`, or
152
+ `"not_paid"`, relay the `message` field verbatim to the user and
153
+ stop — do not retry. The message contains the exact corrective
154
+ action.
155
+
156
+ **Typical loop:**
157
+
158
+ 1. `list_cloud_issues` → pick an issue with the user.
159
+ 2. `claim_cloud_issue <id>` → read `source.file` around `source.line`,
160
+ understand the repro from `note` + `consoleErrors`, make the fix.
161
+ 3. Open a PR.
162
+ 4. `resolve_cloud_issue <id> <prUrl>`.
163
+
164
+ The cloud-issue workflow follows the same guardrails as browser picks:
165
+ never auto-apply writes, always wait for explicit user approval before
166
+ editing files.
167
+
118
168
  ## Failure modes to handle gracefully
119
169
 
120
170
  - **`source.file` doesn't exist**: tell the user the path the
@@ -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.0",
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",