claude-friends 0.1.1 → 0.1.3

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.
Files changed (2) hide show
  1. package/mcp-server.js +15 -1
  2. package/package.json +1 -1
package/mcp-server.js CHANGED
@@ -13,14 +13,25 @@ const username = config.username;
13
13
 
14
14
  // Persistent WebSocket connection — stays open while Claude Code is running
15
15
  const ws = createConnection(username);
16
+ let connected = false;
16
17
 
17
18
  // Local cache of state, updated via WebSocket messages
18
19
  let friendsList = [];
19
20
  let pendingNudges = [];
20
21
  let lastError = null;
21
22
 
23
+ // Wait for connection to be ready
24
+ function waitForConnection(timeout = 10000) {
25
+ return new Promise((resolve, reject) => {
26
+ if (connected && ws.readyState === 1) return resolve();
27
+ const timer = setTimeout(() => reject(new Error("connection timeout")), timeout);
28
+ ws.addEventListener("open", () => { connected = true; clearTimeout(timer); resolve(); }, { once: true });
29
+ });
30
+ }
31
+
22
32
  // Promise-based request/response helper
23
- function request(msg, responseType, timeout = 5000) {
33
+ async function request(msg, responseType, timeout = 5000) {
34
+ await waitForConnection();
24
35
  return new Promise((resolve, reject) => {
25
36
  const timer = setTimeout(() => reject(new Error("timeout")), timeout);
26
37
  const handler = (event) => {
@@ -138,6 +149,7 @@ server.tool(
138
149
  "Set your status so friends can see what you're working on.",
139
150
  { status: z.string().describe("Your status, e.g. 'debugging auth flow'") },
140
151
  async ({ status }) => {
152
+ await waitForConnection();
141
153
  ws.send(JSON.stringify({ type: "set-status", status }));
142
154
  return { content: [{ type: "text", text: `Status set: "${status}"` }] };
143
155
  }
@@ -148,6 +160,7 @@ server.tool(
148
160
  "Share your token usage with friends.",
149
161
  { tokens: z.number().describe("Tokens used this session") },
150
162
  async ({ tokens }) => {
163
+ await waitForConnection();
151
164
  ws.send(JSON.stringify({ type: "share-tokens", tokens }));
152
165
  return { content: [{ type: "text", text: `Sharing: ${tokens.toLocaleString()} tokens` }] };
153
166
  }
@@ -158,6 +171,7 @@ server.tool(
158
171
  "Stop sharing token usage.",
159
172
  {},
160
173
  async () => {
174
+ await waitForConnection();
161
175
  ws.send(JSON.stringify({ type: "hide-tokens" }));
162
176
  return { content: [{ type: "text", text: "Token usage hidden." }] };
163
177
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-friends",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "See who's online in Claude Code. Add friends, share status, nudge each other.",
5
5
  "type": "module",
6
6
  "bin": {