mindmeld-mcp 0.3.0 → 0.4.0

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/README.md CHANGED
@@ -13,7 +13,7 @@ The answer comes from a **read-only copy of the Claude session your teammate has
13
13
  ## Setup (each of you, once)
14
14
 
15
15
  ```sh
16
- claude plugin install mindmeld --marketplace dhrupad-sah/claude-share
16
+ claude plugin install mindmeld --marketplace dhrupad-sah/mindmeld
17
17
  ```
18
18
 
19
19
  Restart Claude Code afterwards. The plugin starts its MCP server through `npx`, so the only requirement is Node 20+.
@@ -31,17 +31,22 @@ claude mcp add -s user mindmeld -- mindmeld mcp
31
31
  - **You:** `/mindmeld:invite` (or just say *"invite a teammate to mindmeld"*). Claude gives you a code like `k7q2-9xmd-4tpa` and a message to send. The code works once and expires in 15 minutes.
32
32
  - **Them:** `/mindmeld:join k7q2-9xmd-4tpa`. Connected.
33
33
 
34
- From then on you're online whenever you have a Claude Code session open. There's nothing else to run. `/mindmeld:peers` shows who's around.
34
+ Joining exposes nothing. **Every session is private until you share it:**
35
+
36
+ - **Them, in the session that has the answers:** `/mindmeld:share scraper work`. The group can now see "scraper work" and ask it questions. They see your name, that label and when the session was last active. Never your prompts, files or transcript.
37
+ - `/mindmeld:stop` makes it private again. Closing the session does too.
38
+ - `/mindmeld:peers` lists the sessions people are sharing. `/mindmeld:status` shows whether you're connected, whether this session is shared, who's "always allowed", and every recent question in and out.
35
39
 
36
40
  ## Use
37
41
 
38
- *"Ask Sarim how they set up the auth middleware."*
42
+ *"Ask Sarim how they set up the auth middleware."* Your Claude shows progress as it happens: delivered → approved → writing the answer. If Sarim's session doesn't acknowledge the question within 15 seconds, you're told right away instead of waiting.
39
43
 
40
- On Sarim's side, Claude Code shows a dialog:
44
+ On Sarim's side, in the session they shared, Claude Code shows a dialog:
41
45
 
42
46
  ```
43
47
  MCP server mindmeld requests your input
44
- Dhrupad asks: How did you set up the auth middleware?
48
+ Dhrupad asks your shared session "scraper work":
49
+ How did you set up the auth middleware?
45
50
  Answer with a read-only copy of this session? You'll see the answer before it's sent.
46
51
  (To skip these prompts for Dhrupad, tell Claude "always allow Dhrupad".)
47
52
  Accept Decline
@@ -49,15 +54,17 @@ Answer with a read-only copy of this session? You'll see the answer before it's
49
54
 
50
55
  Sarim presses Enter, a read-only copy of that session writes the answer, and a second dialog shows the draft. Another Enter sends it to your Claude. Telling Claude *"always allow Dhrupad"* skips both dialogs for Dhrupad from then on. *"stop allowing Dhrupad"* turns that off.
51
56
 
52
- If Sarim has several Claude sessions open, the question goes to the one used most recently. `list_peers` shows each session and what it's about.
57
+ If Sarim shares several sessions, the question goes to the one used most recently. Every question, including ones answered automatically, is logged in `/mindmeld:status`.
53
58
 
54
59
  ## Tools Claude gets
55
60
 
56
61
  | tool | what it does |
57
62
  |---|---|
58
63
  | `invite_peer` / `join_peer` | pair with a teammate |
64
+ | `share_session` / `stop_sharing` | make this session visible and askable, or private again |
65
+ | `status` | connection, sharing state, trusted people, recent questions |
59
66
  | `trust_peer` | always allow, or stop allowing, someone's questions |
60
- | `list_peers` | who's online, in which project and session |
67
+ | `list_peers` | sessions teammates are sharing |
61
68
  | `ask_peer` | ask a question; blocks until the answer arrives |
62
69
  | `share_snippet` / `read_inbox` | send or receive code and notes, no reply needed |
63
70
 
@@ -80,7 +87,8 @@ By default, both sides connect to a hosted relay (a Cloudflare Worker, source in
80
87
 
81
88
  - **Pairing via a PAKE handshake.** Invite codes run SPAKE2 over ristretto255. The relay sees only the first 4 characters (a rendezvous id), never the password part. Someone watching, including the relay operator, can't guess the code offline. An attacker gets one live guess, and a wrong guess burns the invite.
82
89
  - **End-to-end encrypted.** Pairing hands each member a random 256-bit group secret. Every message is sealed with AES-256-GCM using a key derived from that secret. The relay only sees a room hash and ciphertext, and stores nothing.
83
- - **Read-only fork.** The answering fork gets only `Read`, `Grep` and `Glob`. There's no Bash, no edits, no web access, no Chrome and **no MCP servers**, so a question can't reach your connectors. Forks are never saved as sessions.
90
+ - **Private by default.** A session is invisible to your group until you run `/mindmeld:share` in it. Sharing reveals only your name, the label you chose and a last-active time. Asking never reveals anything: askers aren't listed at all.
91
+ - **A sandboxed, read-only fork.** Answers come from a copy of the shared session that can only `Read` and `Glob` files **inside that project**. Reads outside it are denied by Claude Code's permission system, and so are `.env*`, keys, `*.pem` and credential files inside it. The fork has no Bash, Grep, edits, web, Chrome or MCP servers. Your own settings are not loaded, so your allow rules can't widen any of this. Forks are never saved as sessions.
84
92
  - **You approve.** By default you see every question and every draft answer before it leaves your machine.
85
93
  - **Replies are fenced.** Answers reach the asking Claude wrapped in `<peer_reply untrusted="true">` with an instruction to treat them as data.
86
94
  - **Rate limited.** At most 10 questions per peer per 10 minutes.
package/dist/answerer.js CHANGED
@@ -1,5 +1,7 @@
1
1
  import { spawn } from "node:child_process";
2
2
  const FORK_TIMEOUT_MS = 5 * 60_000;
3
+ /** Files a fork may never read, even inside the project. */
4
+ export const SECRET_PATTERNS = [".env", ".env.*", "*.pem", "*.key", "*.p12", "id_rsa*", "id_ed25519*", "id_ecdsa*", ".npmrc", ".netrc", "*credentials*", "*secret*", ".git/config"];
3
5
  const PEER_GUARD = `A teammate's Claude Code session is asking you a question through mindmeld.
4
6
  Answer it from what you know in this session: what was built, how problems were solved, and why.
5
7
  Rules:
@@ -24,17 +26,26 @@ export function answerWithFork(opts) {
24
26
  "--no-chrome",
25
27
  "--output-format",
26
28
  "text",
29
+ // Sandbox: files inside the project only, never secrets, and nothing else. dontAsk denies
30
+ // anything not allowed here; ignoring setting sources stops the user's own allow rules
31
+ // (or hooks) from widening it. No Grep: a search could surface text from secret files.
32
+ "--permission-mode",
33
+ "dontAsk",
34
+ "--setting-sources",
35
+ "",
27
36
  "--allowedTools",
28
- "Read",
29
- "Grep",
30
- "Glob",
37
+ "Read(./**)",
38
+ "Glob(./**)",
31
39
  "--disallowedTools",
40
+ ...SECRET_PATTERNS.map((p) => `Read(./**/${p})`),
32
41
  "Bash",
42
+ "Grep",
33
43
  "Edit",
34
44
  "Write",
35
45
  "NotebookEdit",
36
46
  "WebFetch",
37
47
  "WebSearch",
48
+ "Task",
38
49
  // No MCP servers in the fork: a peer's question must not reach the answerer's connectors.
39
50
  "--strict-mcp-config",
40
51
  "--mcp-config",
package/dist/cli.js CHANGED
@@ -22,7 +22,7 @@ const USAGE = `mindmeld — let teammates' Claude Code sessions ask each other q
22
22
  mindmeld relay [--port 8787] self-host a relay (optional; a hosted one is the default)
23
23
 
24
24
  Easiest: install the Claude Code plugin and do everything from Claude:
25
- claude plugin install mindmeld --marketplace dhrupad-sah/claude-share`;
25
+ claude plugin install mindmeld --marketplace dhrupad-sah/mindmeld`;
26
26
  const dim = (s) => `\x1b[2m${s}\x1b[0m`;
27
27
  const bold = (s) => `\x1b[1m${s}\x1b[0m`;
28
28
  const cyan = (s) => `\x1b[36m${s}\x1b[0m`;
@@ -62,7 +62,7 @@ async function main() {
62
62
  console.log(`Send your friend: mindmeld join ${code}${relayHint}\n`);
63
63
  console.log(dim("waiting for them to join… (keep this running)"));
64
64
  const { peerName } = await runInviter({ relay: config.relay, code, secret: config.secret, name: config.name });
65
- console.log(`${cyan("✓")} paired with ${bold(peerName)}. Next: ${bold("mindmeld up")} in your project directory.`);
65
+ console.log(`${cyan("✓")} paired with ${bold(peerName)}. In Claude Code, run ${bold("/mindmeld:share")} in a session to let them ask it.`);
66
66
  return;
67
67
  }
68
68
  case "join": {
@@ -75,7 +75,7 @@ async function main() {
75
75
  const { secret, inviterName } = await runJoiner({ relay, code, name });
76
76
  saveConfig({ secret, relay, name });
77
77
  console.log(`${cyan("✓")} joined ${bold(inviterName)}'s group as ${bold(name)}.`);
78
- console.log(`Next: run ${bold("mindmeld up")} in your project directory.`);
78
+ console.log(`Next: in Claude Code, run ${bold("/mindmeld:share")} in a session to let them ask it (sessions are private by default).`);
79
79
  return;
80
80
  }
81
81
  case "sessions": {
package/dist/daemon.js CHANGED
@@ -2,7 +2,7 @@ import { randomUUID } from "node:crypto";
2
2
  import { EventEmitter } from "node:events";
3
3
  import WebSocket from "ws";
4
4
  import { keyFor, open, roomIdFor, seal } from "./crypto.js";
5
- import { Frame, HELLO_INTERVAL_MS, PEER_TIMEOUT_MS, Payload } from "./protocol.js";
5
+ import { Frame, HELLO_INTERVAL_MS, PEER_TIMEOUT_MS, Payload, PROTOCOL_VERSION } from "./protocol.js";
6
6
  export class Daemon extends EventEmitter {
7
7
  opts;
8
8
  peerId = randomUUID();
@@ -15,9 +15,11 @@ export class Daemon extends EventEmitter {
15
15
  pending = new Map();
16
16
  inbox = [];
17
17
  askLog = new Map();
18
+ share;
18
19
  constructor(opts) {
19
20
  super();
20
21
  this.opts = opts;
22
+ this.share = opts.share === undefined ? { label: opts.project } : opts.share;
21
23
  this.key = keyFor(opts.secret);
22
24
  this.roomUrl = `${opts.relay.replace(/\/$/, "")}/room/${roomIdFor(opts.secret)}`;
23
25
  }
@@ -61,7 +63,24 @@ export class Daemon extends EventEmitter {
61
63
  const frame = { t: "msg", d: seal(this.key, JSON.stringify(p)) };
62
64
  this.ws.send(JSON.stringify(frame));
63
65
  }
66
+ get connected() {
67
+ return this.ws?.readyState === WebSocket.OPEN;
68
+ }
69
+ get sharing() {
70
+ return this.share;
71
+ }
72
+ /** Start or stop sharing this session with the group. */
73
+ setShare(share) {
74
+ const was = this.share;
75
+ this.share = share;
76
+ if (share)
77
+ this.sendHello();
78
+ else if (was)
79
+ this.send({ type: "bye", peer: this.peerId });
80
+ }
64
81
  sendHello() {
82
+ if (!this.share)
83
+ return; // unshared sessions never announce themselves
65
84
  let info = {};
66
85
  try {
67
86
  info = this.opts.sessionInfo?.() ?? {};
@@ -73,9 +92,9 @@ export class Daemon extends EventEmitter {
73
92
  type: "hello",
74
93
  peer: this.peerId,
75
94
  name: this.opts.name,
76
- project: this.opts.project,
77
- session: info.label,
95
+ project: this.share.label,
78
96
  activeAt: info.activeAt,
97
+ v: PROTOCOL_VERSION,
79
98
  });
80
99
  }
81
100
  handleFrame(raw) {
@@ -102,6 +121,7 @@ export class Daemon extends EventEmitter {
102
121
  project: p.project,
103
122
  session: p.session,
104
123
  activeAt: p.activeAt,
124
+ v: p.v,
105
125
  lastSeen: Date.now(),
106
126
  });
107
127
  if (isNew) {
@@ -118,9 +138,18 @@ export class Daemon extends EventEmitter {
118
138
  break;
119
139
  }
120
140
  case "ask":
121
- if (!p.to || p.to === this.opts.name || p.to === this.peerId)
141
+ // Only a shared session answers, and only questions addressed to it (or legacy broadcasts).
142
+ if (this.share && (!p.to || p.to === this.opts.name || p.to === this.peerId))
122
143
  void this.handleAsk(p);
123
144
  break;
145
+ case "status": {
146
+ const pending = this.pending.get(p.id);
147
+ if (pending) {
148
+ pending.acked = true;
149
+ pending.onStatus?.(p.state);
150
+ }
151
+ break;
152
+ }
124
153
  case "answer": {
125
154
  const pending = this.pending.get(p.id);
126
155
  if (pending) {
@@ -148,8 +177,8 @@ export class Daemon extends EventEmitter {
148
177
  break;
149
178
  }
150
179
  }
151
- nameOf(peerId) {
152
- return this.peers.get(peerId)?.name ?? peerId.slice(0, 8);
180
+ nameOf(peerId, fallback) {
181
+ return this.peers.get(peerId)?.name ?? fallback ?? peerId.slice(0, 8);
153
182
  }
154
183
  rateLimited(from) {
155
184
  const { max, windowMs } = this.opts.rateLimit ?? { max: 10, windowMs: 10 * 60_000 };
@@ -159,16 +188,26 @@ export class Daemon extends EventEmitter {
159
188
  this.askLog.set(from, recent);
160
189
  return recent.length > max;
161
190
  }
191
+ seenAsks = new Set();
162
192
  async handleAsk(ask) {
193
+ if (this.seenAsks.has(ask.id))
194
+ return; // a resend of a question already being handled
195
+ this.seenAsks.add(ask.id);
163
196
  const reply = (d) => d.action === "send"
164
197
  ? this.send({ type: "answer", id: ask.id, from: this.peerId, text: d.text })
165
198
  : this.send({ type: "decline", id: ask.id, from: this.peerId, reason: d.reason });
199
+ const report = (state) => this.send({ type: "status", id: ask.id, from: this.peerId, state });
200
+ report("received");
166
201
  if (this.rateLimited(ask.from)) {
167
202
  reply({ action: "decline", reason: "rate limited — too many questions, try again later" });
168
203
  return;
169
204
  }
205
+ const from = this.nameOf(ask.from, ask.fromName);
206
+ this.emit("question", { from, question: ask.question });
170
207
  try {
171
- reply(await this.opts.decide({ ...ask, from: this.nameOf(ask.from) }));
208
+ const d = await this.opts.decide({ ...ask, from }, report);
209
+ this.emit("handled", { from, question: ask.question, action: d.action });
210
+ reply(d);
172
211
  }
173
212
  catch (e) {
174
213
  reply({ action: "decline", reason: `failed to answer: ${e.message}` });
@@ -202,25 +241,36 @@ export class Daemon extends EventEmitter {
202
241
  return matches.reduce((best, p) => ((p.activeAt ?? 0) > (best.activeAt ?? 0) ? p : best));
203
242
  }
204
243
  ask(question, opts = {}) {
244
+ if (!this.connected)
245
+ return Promise.resolve({ error: "not connected to the relay right now; try again in a moment" });
205
246
  const target = this.route(opts.peer);
206
247
  if ("error" in target)
207
248
  return Promise.resolve(target);
208
249
  const id = randomUUID();
209
250
  const timeoutSec = opts.timeoutSec ?? 600;
210
251
  return new Promise((resolve) => {
211
- const timer = setTimeout(() => {
252
+ const timers = [];
253
+ const finish = (r) => {
254
+ timers.forEach(clearTimeout);
212
255
  this.pending.delete(id);
213
- resolve({ error: `no answer within ${timeoutSec}s` });
214
- }, timeoutSec * 1000);
215
- this.pending.set(id, {
216
- expected: 1,
217
- declines: [],
218
- resolve: (r) => {
219
- clearTimeout(timer);
220
- resolve(r);
221
- },
222
- });
223
- this.send({ type: "ask", id, from: this.peerId, to: target.peer, question, context: opts.context });
256
+ resolve(r);
257
+ };
258
+ timers.push(setTimeout(() => finish({ error: `no answer within ${timeoutSec}s` }), timeoutSec * 1000));
259
+ // Peers from 0.4 on acknowledge at once; older ones don't, so only hold newer ones to it.
260
+ const payload = { type: "ask", id, from: this.peerId, fromName: this.opts.name, to: target.peer, question, context: opts.context };
261
+ if ((target.v ?? 0) >= 2) {
262
+ // Not acknowledged halfway through the window: resend once (a frame can be lost while
263
+ // the socket reconnects). The answering side ignores duplicate ids.
264
+ const ackMs = this.opts.ackTimeoutMs ?? 15_000;
265
+ timers.push(setTimeout(() => !this.pending.get(id)?.acked && this.send(payload), ackMs / 2));
266
+ timers.push(setTimeout(() => {
267
+ if (!this.pending.get(id)?.acked) {
268
+ finish({ error: `${target.name}'s session didn't acknowledge the question. It may have just closed or stopped sharing.` });
269
+ }
270
+ }, ackMs));
271
+ }
272
+ this.pending.set(id, { resolve: finish, onStatus: opts.onStatus, acked: false, expected: 1, declines: [] });
273
+ this.send(payload);
224
274
  });
225
275
  }
226
276
  snippet(title, text, peer) {
package/dist/mcp.js CHANGED
@@ -1,9 +1,10 @@
1
- import { basename } from "node:path";
1
+ import { appendFileSync, mkdirSync, readFileSync } from "node:fs";
2
+ import { basename, join } from "node:path";
2
3
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
3
4
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
4
5
  import { z } from "zod";
5
6
  import { answerWithFork } from "./answerer.js";
6
- import { DEFAULT_RELAY, defaultName, loadConfig, saveConfig } from "./config.js";
7
+ import { DEFAULT_RELAY, defaultName, homeDir, loadConfig, saveConfig } from "./config.js";
7
8
  import { generateGroupSecret, generateInviteCode } from "./crypto.js";
8
9
  import { Daemon } from "./daemon.js";
9
10
  import { runInviter, runJoiner } from "./pairing.js";
@@ -11,6 +12,30 @@ import { fenceUntrusted } from "./protocol.js";
11
12
  import { listSessions } from "./sessions.js";
12
13
  const APPROVAL_TIMEOUT_MS = 10 * 60_000;
13
14
  const NOT_PAIRED = "Not connected to anyone yet. Use invite_peer to get a code to send a teammate, or join_peer with a code they sent you.";
15
+ const NOT_SHARED_HINT = "This session is private. Run /mindmeld:share in it to let your group ask it questions.";
16
+ const activityFile = () => join(homeDir(), "activity.jsonl");
17
+ function logActivity(a) {
18
+ try {
19
+ mkdirSync(homeDir(), { recursive: true, mode: 0o700 });
20
+ appendFileSync(activityFile(), JSON.stringify(a) + "\n", { mode: 0o600 });
21
+ }
22
+ catch {
23
+ // best-effort
24
+ }
25
+ }
26
+ function recentActivity(n) {
27
+ try {
28
+ return readFileSync(activityFile(), "utf8").trim().split("\n").slice(-n).map((l) => JSON.parse(l));
29
+ }
30
+ catch {
31
+ return [];
32
+ }
33
+ }
34
+ const STATE_TEXT = {
35
+ received: "delivered; waiting for them to approve",
36
+ approved: "approved; their session is writing the answer",
37
+ drafting: "answer drafted; waiting for them to approve sending it",
38
+ };
14
39
  const text = (t, isError = false) => ({ content: [{ type: "text", text: t }], isError });
15
40
  function loadConfigOrNull() {
16
41
  try {
@@ -36,10 +61,12 @@ function ago(ms) {
36
61
  * dialogs in that session and answered by a read-only fork of it.
37
62
  */
38
63
  export async function runMcpServer() {
39
- const server = new McpServer({ name: "mindmeld", version: "0.3.0" });
64
+ const server = new McpServer({ name: "mindmeld", version: "0.4.0" });
40
65
  const cwd = process.env.CLAUDE_PROJECT_DIR ?? process.cwd();
41
66
  const mySessionId = process.env.CLAUDE_CODE_SESSION_ID;
42
67
  let daemon = null;
68
+ // Private until the user explicitly shares this session; never persisted across sessions.
69
+ let share = null;
43
70
  /** This session's transcript; after /clear the id may be stale, so fall back to the newest. */
44
71
  const mySession = () => {
45
72
  const sessions = listSessions(cwd);
@@ -57,19 +84,25 @@ export async function runMcpServer() {
57
84
  const elicit = (message, requestedSchema) => server.server.elicitInput({ message, requestedSchema }, { timeout: APPROVAL_TIMEOUT_MS });
58
85
  // One question at a time, so approval dialogs never stack up.
59
86
  let queue = Promise.resolve();
60
- const decide = (ask) => {
61
- const run = queue.then(() => answer(ask));
87
+ const decide = (ask, report) => {
88
+ const run = queue.then(() => answer(ask, report));
62
89
  queue = run.catch(() => { });
63
90
  return run;
64
91
  };
65
- async function answer(ask) {
92
+ async function answer(ask, report) {
93
+ const d = await answerInner(ask, report);
94
+ logActivity({ at: Date.now(), dir: "in", peer: ask.from, question: ask.question.slice(0, 200), session: share?.label,
95
+ outcome: d.action === "send" ? (isTrusted(ask.from) ? "answered automatically (always allowed)" : "answered") : `declined: ${d.reason}` });
96
+ return d;
97
+ }
98
+ async function answerInner(ask, report) {
66
99
  const trusted = isTrusted(ask.from);
67
100
  if (!trusted) {
68
101
  if (!server.server.getClientCapabilities()?.elicitation) {
69
102
  return { action: "decline", reason: "they can't approve questions right now (no interactive Claude session)" };
70
103
  }
71
104
  const asked = [
72
- `${ask.from} asks:`,
105
+ `${ask.from} asks your shared session "${share?.label ?? basename(cwd)}":`,
73
106
  "",
74
107
  ask.question.slice(0, 2000),
75
108
  ask.context ? `\nTheir context: ${ask.context.slice(0, 1000)}` : "",
@@ -82,6 +115,7 @@ export async function runMcpServer() {
82
115
  if (r.action !== "accept")
83
116
  return { action: "decline", reason: "declined" };
84
117
  }
118
+ report("approved");
85
119
  const draft = await answerWithFork({
86
120
  cwd,
87
121
  from: ask.from,
@@ -91,6 +125,7 @@ export async function runMcpServer() {
91
125
  });
92
126
  if (trusted)
93
127
  return { action: "send", text: draft };
128
+ report("drafting");
94
129
  const r = await elicit(`Send this answer to ${ask.from}?\n\n${draft.slice(0, 8000)}`, {
95
130
  type: "object",
96
131
  properties: {},
@@ -102,10 +137,12 @@ export async function runMcpServer() {
102
137
  daemon = new Daemon({
103
138
  ...config,
104
139
  project: basename(cwd),
140
+ share,
105
141
  decide,
142
+ // Only a timestamp, for routing: never the transcript or its first prompt.
106
143
  sessionInfo: () => {
107
144
  const s = mySession();
108
- return s ? { label: s.firstPrompt.slice(0, 80), activeAt: s.modified.getTime() } : {};
145
+ return s ? { activeAt: s.modified.getTime() } : {};
109
146
  },
110
147
  });
111
148
  daemon.start();
@@ -115,33 +152,41 @@ export async function runMcpServer() {
115
152
  connect(existing);
116
153
  server.registerTool("list_peers", {
117
154
  title: "List peers",
118
- description: "List teammates connected through mindmeld right now, one line per open Claude session.",
155
+ description: "List the sessions teammates are sharing through mindmeld right now (only shared sessions are visible).",
119
156
  inputSchema: {},
120
157
  }, async () => {
121
158
  if (!daemon)
122
159
  return text(NOT_PAIRED);
123
160
  const peers = daemon.onlinePeers();
124
161
  if (peers.length === 0)
125
- return text("Nobody is online right now. They're online whenever they have a Claude Code session open.");
126
- return text(peers
127
- .map((p) => `- ${p.name}: ${p.project}${p.session ? ` · "${p.session}"` : ""}${p.activeAt ? ` · active ${ago(p.activeAt)}` : ""}`)
128
- .join("\n"));
162
+ return text("Nobody is sharing a session right now. Teammates appear here after they run /mindmeld:share.");
163
+ return text(peers.map((p) => `- ${p.name}: "${p.project}"${p.activeAt ? ` · active ${ago(p.activeAt)}` : ""}`).join("\n"));
129
164
  });
130
165
  server.registerTool("ask_peer", {
131
166
  title: "Ask a teammate's Claude",
132
167
  description: "Ask a teammate's Claude Code session a question, e.g. how they solved something or how part of their work functions. " +
133
- "It goes to their most recently active session; they approve it in their Claude, and a read-only copy of that session answers. " +
134
- "Blocks until the answer arrives (can take a few minutes). Make the question self-contained.",
168
+ "It goes to their most recently active shared session; they approve it in their Claude, and a read-only copy of that session answers. " +
169
+ "Reports progress while waiting (delivered, approved, drafting). Can take a few minutes. Make the question self-contained.",
135
170
  inputSchema: {
136
171
  question: z.string().describe("The question, self-contained"),
137
172
  peer: z.string().optional().describe("Who to ask (name or first name). Optional if only one person is online"),
138
173
  context: z.string().optional().describe("Optional extra context: what you're trying to do, errors, etc."),
139
174
  timeout_sec: z.number().int().min(10).max(3600).optional().describe("Default 600"),
140
175
  },
141
- }, async ({ question, peer, context, timeout_sec }) => {
176
+ }, async ({ question, peer, context, timeout_sec }, extra) => {
142
177
  if (!daemon)
143
178
  return text(NOT_PAIRED, true);
144
- const r = await daemon.ask(question, { peer, context, timeoutSec: timeout_sec });
179
+ const token = extra._meta?.progressToken;
180
+ let step = 0;
181
+ const progress = (message) => {
182
+ step++;
183
+ if (token !== undefined) {
184
+ void extra.sendNotification({ method: "notifications/progress", params: { progressToken: token, progress: step, total: 4, message } });
185
+ }
186
+ };
187
+ progress("sending");
188
+ const r = await daemon.ask(question, { peer, context, timeoutSec: timeout_sec, onStatus: (s) => progress(STATE_TEXT[s]) });
189
+ logActivity({ at: Date.now(), dir: "out", peer: "error" in r ? (peer ?? "?") : r.from, question: question.slice(0, 200), outcome: "error" in r ? r.error : "answered" });
145
190
  if ("error" in r)
146
191
  return text(`No answer: ${r.error}`, true);
147
192
  return text(fenceUntrusted(r.from, r.text));
@@ -172,6 +217,59 @@ export async function runMcpServer() {
172
217
  return text("Inbox is empty.");
173
218
  return text(items.map((i) => fenceUntrusted(i.from, `# ${i.title}\n${i.text}`)).join("\n\n"));
174
219
  });
220
+ server.registerTool("share_session", {
221
+ title: "Share this session",
222
+ description: "Let the user's mindmeld group see this Claude session and ask it questions (each question still needs the user's approval " +
223
+ "unless they've 'always allowed' someone). Only call this when the user asks to share. Sessions are private by default.",
224
+ inputSchema: {
225
+ label: z.string().max(60).optional().describe("What teammates will see this session as. Defaults to the project folder name"),
226
+ },
227
+ }, async ({ label }) => {
228
+ if (!daemon)
229
+ return text(NOT_PAIRED, true);
230
+ share = { label: (label ?? basename(cwd)).trim() || basename(cwd) };
231
+ daemon.setShare(share);
232
+ return text([
233
+ `This session is now shared with your mindmeld group as "${share.label}".`,
234
+ `They can see: your name ("${loadConfigOrNull()?.name}"), the label "${share.label}", and when the session was last active. Nothing else: not your prompts, files or transcript.`,
235
+ "Each question shows an Accept/Decline dialog here, and answers come from a read-only copy of this session that can only read files inside this project (never .env or key files).",
236
+ "Run /mindmeld:stop to stop sharing. Closing this session stops it too.",
237
+ ].join("\n"));
238
+ });
239
+ server.registerTool("stop_sharing", {
240
+ title: "Stop sharing this session",
241
+ description: "Make this session private again: teammates can no longer see it or ask it questions.",
242
+ inputSchema: {},
243
+ }, async () => {
244
+ if (!daemon || !share)
245
+ return text("This session isn't shared.");
246
+ share = null;
247
+ daemon.setShare(null);
248
+ return text("This session is private again. Teammates can no longer see it or ask it questions.");
249
+ });
250
+ server.registerTool("status", {
251
+ title: "mindmeld status",
252
+ description: "Show the user's mindmeld status: connection, whether this session is shared, who's sharing, trusted people, and recent questions.",
253
+ inputSchema: {},
254
+ }, async () => {
255
+ const c = loadConfigOrNull();
256
+ if (!c || !daemon)
257
+ return text(NOT_PAIRED);
258
+ const peers = daemon.onlinePeers();
259
+ const lines = [
260
+ `Connection: ${daemon.connected ? "connected" : "NOT connected (reconnecting to the relay)"}`,
261
+ `You appear as: ${c.name}`,
262
+ `This session: ${share ? `shared as "${share.label}"` : "private (not visible to anyone). Run /mindmeld:share to share it."}`,
263
+ `Sharing now: ${peers.length ? peers.map((p) => `${p.name} ("${p.project}")`).join(", ") : "nobody"}`,
264
+ `Always allowed (answered without dialogs): ${c.trusted?.length ? c.trusted.join(", ") : "nobody"}`,
265
+ "",
266
+ "Recent questions on this machine:",
267
+ ...(recentActivity(10).reverse().map((a) => `- ${new Date(a.at).toLocaleString()} ${a.dir === "in" ? `${a.peer} asked${a.session ? ` "${a.session}"` : ""}` : `you asked ${a.peer}`}: "${a.question}" → ${a.outcome}`) || []),
268
+ ];
269
+ if (lines[lines.length - 1] === "Recent questions on this machine:")
270
+ lines.push("- none yet");
271
+ return text(lines.join("\n"));
272
+ });
175
273
  server.registerTool("trust_peer", {
176
274
  title: "Always allow (or stop allowing) a teammate",
177
275
  description: "When the user says to always allow someone, their questions get answered without approval dialogs. " +
@@ -214,10 +312,12 @@ export async function runMcpServer() {
214
312
  `Invite code: ${code}`,
215
313
  "",
216
314
  "Tell the user to send their teammate this message:",
217
- ` 1. Install (once): claude plugin install mindmeld --marketplace dhrupad-sah/claude-share`,
315
+ ` 1. Install (once): claude plugin install mindmeld --marketplace dhrupad-sah/mindmeld`,
218
316
  ` 2. In Claude Code: /mindmeld:join ${code}`,
219
317
  "",
220
318
  `The code works once and expires in 15 minutes. Keep this session open until they've joined. You'll appear to them as "${config.name}".`,
319
+ "",
320
+ "Joining doesn't expose any of your sessions: each session stays private until you run /mindmeld:share in it.",
221
321
  ].join("\n"));
222
322
  });
223
323
  server.registerTool("join_peer", {
@@ -237,7 +337,8 @@ export async function runMcpServer() {
237
337
  saveConfig(config);
238
338
  connect(config);
239
339
  return text(`Connected to ${inviterName}'s group as "${name}". ` +
240
- `Ask them anything with ask_peer, e.g. "ask ${inviterName.split(/\s+/)[0]} how they built X".` +
340
+ `You can ask any session they share, e.g. "ask ${inviterName.split(/\s+/)[0]} how they built X". ` +
341
+ "Your own sessions stay private until you run /mindmeld:share in one." +
241
342
  (prev && prev.secret !== secret ? " (This replaced the group this machine was in before.)" : ""));
242
343
  }
243
344
  catch (e) {
package/dist/pairing.js CHANGED
@@ -2,17 +2,30 @@ import WebSocket from "ws";
2
2
  import { open, parseInviteCode, seal } from "./crypto.js";
3
3
  import { passwordScalar, Spake2 } from "./spake2.js";
4
4
  const WRONG_CODE = "pairing failed: wrong code (or someone else tried to use it). Create a new invite.";
5
- function connect(relay, rendezvous) {
5
+ function connectOnce(relay, rendezvous) {
6
6
  return new Promise((resolve, reject) => {
7
7
  const ws = new WebSocket(`${relay.replace(/\/$/, "")}/pair/${rendezvous}`);
8
8
  const early = [];
9
9
  const buffer = (data) => early.push(data.toString());
10
10
  ws.on("message", buffer);
11
11
  ws.once("open", () => resolve({ ws, early }));
12
- ws.once("unexpected-response", (_req, res) => reject(new Error(res.statusCode === 409 ? "this invite is already in use" : `relay rejected pairing (${res.statusCode})`)));
13
- ws.once("error", (e) => reject(new Error(`can't reach relay ${relay}: ${e.message || e.code || "connection failed"}`)));
12
+ ws.once("unexpected-response", (_req, res) => reject(Object.assign(new Error(res.statusCode === 409 ? "this invite is already in use" : `relay rejected pairing (${res.statusCode})`), { retryable: (res.statusCode ?? 0) >= 500 })));
13
+ ws.once("error", (e) => reject(Object.assign(new Error(`can't reach relay ${relay}: ${e.message || e.code || "connection failed"}`), { retryable: true })));
14
14
  });
15
15
  }
16
+ /** Flaky networks and transient relay errors shouldn't kill a one-time invite: retry a few times. */
17
+ async function connect(relay, rendezvous) {
18
+ for (let attempt = 1;; attempt++) {
19
+ try {
20
+ return await connectOnce(relay, rendezvous);
21
+ }
22
+ catch (e) {
23
+ if (!e.retryable || attempt >= 4)
24
+ throw e;
25
+ await new Promise((r) => setTimeout(r, 500 * 2 ** attempt));
26
+ }
27
+ }
28
+ }
16
29
  function run({ ws, early }, timeoutMs, onMsg) {
17
30
  return new Promise((resolve, reject) => {
18
31
  let settled = false;
package/dist/protocol.js CHANGED
@@ -6,10 +6,12 @@ export const Payload = z.discriminatedUnion("type", [
6
6
  peer: z.string(),
7
7
  name: z.string(),
8
8
  project: z.string(),
9
- /** Label for the Claude session behind this peer (its first prompt), if known. */
9
+ /** Label for the shared session, chosen by its owner. */
10
10
  session: z.string().optional(),
11
11
  /** When that session was last active (ms since epoch); used to route questions. */
12
12
  activeAt: z.number().optional(),
13
+ /** Protocol version (absent before 0.4). */
14
+ v: z.number().optional(),
13
15
  }),
14
16
  z.object({ type: z.literal("bye"), peer: z.string() }),
15
17
  z.object({
@@ -17,9 +19,17 @@ export const Payload = z.discriminatedUnion("type", [
17
19
  id: z.string(),
18
20
  from: z.string(),
19
21
  to: z.string().optional(),
22
+ /** Asker's display name; askers don't announce themselves, so it travels with the question. */
23
+ fromName: z.string().optional(),
20
24
  question: z.string(),
21
25
  context: z.string().optional(),
22
26
  }),
27
+ z.object({
28
+ type: z.literal("status"),
29
+ id: z.string(),
30
+ from: z.string(),
31
+ state: z.enum(["received", "approved", "drafting"]),
32
+ }),
23
33
  z.object({ type: z.literal("answer"), id: z.string(), from: z.string(), text: z.string() }),
24
34
  z.object({ type: z.literal("decline"), id: z.string(), from: z.string(), reason: z.string() }),
25
35
  z.object({
@@ -33,6 +43,7 @@ export const Payload = z.discriminatedUnion("type", [
33
43
  ]);
34
44
  /** Relay envelope: opaque sealed data. */
35
45
  export const Frame = z.object({ t: z.literal("msg"), d: z.string() });
46
+ export const PROTOCOL_VERSION = 2;
36
47
  export const HELLO_INTERVAL_MS = 20_000;
37
48
  export const PEER_TIMEOUT_MS = 60_000;
38
49
  /** Fence peer-originated text so the asking Claude treats it as data, not instructions. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mindmeld-mcp",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "mindmeld: let your Claude Code session ask a teammate's Claude Code session questions. E2E encrypted, read-only answers, approved in Claude.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -46,10 +46,10 @@
46
46
  "author": "Dhrupad Sah",
47
47
  "repository": {
48
48
  "type": "git",
49
- "url": "git+https://github.com/dhrupad-sah/claude-share.git"
49
+ "url": "git+https://github.com/dhrupad-sah/mindmeld.git"
50
50
  },
51
- "homepage": "https://github.com/dhrupad-sah/claude-share#readme",
51
+ "homepage": "https://github.com/dhrupad-sah/mindmeld#readme",
52
52
  "bugs": {
53
- "url": "https://github.com/dhrupad-sah/claude-share/issues"
53
+ "url": "https://github.com/dhrupad-sah/mindmeld/issues"
54
54
  }
55
55
  }