claude-friends 0.1.2 → 0.2.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/cli.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import { writeFileSync, existsSync } from "fs";
3
+ import { writeFileSync, existsSync, mkdirSync, copyFileSync, readdirSync } from "fs";
4
4
  import { join } from "path";
5
5
  import { homedir } from "os";
6
6
  import { createInterface } from "readline";
@@ -40,18 +40,32 @@ if (command === "setup") {
40
40
 
41
41
  writeFileSync(CONFIG_PATH, JSON.stringify({ username: username.trim() }, null, 2));
42
42
 
43
+ // Install slash commands to ~/.claude/commands/
44
+ const commandsDir = join(homedir(), ".claude", "commands");
45
+ mkdirSync(commandsDir, { recursive: true });
46
+
47
+ const srcCommands = join(__dirname, "commands");
48
+ if (existsSync(srcCommands)) {
49
+ const files = readdirSync(srcCommands).filter((f) => f.endsWith(".md"));
50
+ for (const file of files) {
51
+ copyFileSync(join(srcCommands, file), join(commandsDir, file));
52
+ }
53
+ console.log(`\nInstalled slash commands: ${files.map((f) => "/" + f.replace(".md", "")).join(", ")}`);
54
+ }
55
+
43
56
  console.log(`
44
57
  Done! You're "${username.trim()}".
45
58
 
46
59
  Now add the MCP server to Claude Code:
47
60
 
48
- claude mcp add claude-friends -- node ${join(__dirname, "mcp-server.js")}
61
+ claude mcp add claude-friends -- claude-friends serve
49
62
 
50
- Then in Claude Code, try:
51
- "who's online?"
52
- "add friend alice"
53
- "set my status to debugging auth"
54
- "nudge bob"
63
+ Then in Claude Code:
64
+ /friend alice Add a friend
65
+ /friends See who's online
66
+ /nudge bob Nudge someone
67
+ /status debugging Set your status
68
+ /unfriend alice Remove a friend
55
69
  `);
56
70
 
57
71
  rl.close();
@@ -0,0 +1 @@
1
+ Use the add-friend MCP tool to add "$ARGUMENTS" as a friend. If no username is provided, ask for one.
@@ -0,0 +1 @@
1
+ Use the friends-online MCP tool to show who's currently online.
@@ -0,0 +1 @@
1
+ Use the nudge MCP tool to nudge "$ARGUMENTS". If the input includes a message after the username, pass it as the message parameter. If no username is provided, ask for one.
@@ -0,0 +1 @@
1
+ Use the set-status MCP tool to set your status to "$ARGUMENTS". If no status is provided, ask what to set it to.
@@ -0,0 +1 @@
1
+ Use the remove-friend MCP tool to remove "$ARGUMENTS" from your friends list. If no username is provided, ask for one.
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.2",
3
+ "version": "0.2.0",
4
4
  "description": "See who's online in Claude Code. Add friends, share status, nudge each other.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -15,7 +15,8 @@
15
15
  "cli.js",
16
16
  "mcp-server.js",
17
17
  "statusline.js",
18
- "client.js"
18
+ "client.js",
19
+ "commands/"
19
20
  ],
20
21
  "dependencies": {
21
22
  "@modelcontextprotocol/sdk": "^1.12.1",