claude-friends 0.1.3 → 0.2.1
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 +54 -7
- package/commands/friend.md +1 -0
- package/commands/friends.md +1 -0
- package/commands/nudge.md +1 -0
- package/commands/status.md +1 -0
- package/commands/unfriend.md +1 -0
- package/hooks/update-tokens.js +79 -0
- package/package.json +4 -2
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, readFileSync, 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,65 @@ 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
|
+
|
|
56
|
+
// Install token-sharing hook to ~/.claude/settings.json
|
|
57
|
+
const settingsPath = join(homedir(), ".claude", "settings.json");
|
|
58
|
+
const hookCommand = `node ${join(__dirname, "hooks", "update-tokens.js")}`;
|
|
59
|
+
try {
|
|
60
|
+
let settings = {};
|
|
61
|
+
if (existsSync(settingsPath)) {
|
|
62
|
+
settings = JSON.parse(readFileSync(settingsPath, "utf-8"));
|
|
63
|
+
}
|
|
64
|
+
if (!settings.hooks) settings.hooks = {};
|
|
65
|
+
if (!settings.hooks.Stop) settings.hooks.Stop = [];
|
|
66
|
+
|
|
67
|
+
// Check if hook already installed
|
|
68
|
+
const alreadyInstalled = settings.hooks.Stop.some((h) =>
|
|
69
|
+
h.hooks?.some((hk) => hk.command?.includes("update-tokens"))
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
if (!alreadyInstalled) {
|
|
73
|
+
settings.hooks.Stop.push({
|
|
74
|
+
hooks: [{
|
|
75
|
+
type: "command",
|
|
76
|
+
command: hookCommand,
|
|
77
|
+
async: true,
|
|
78
|
+
}],
|
|
79
|
+
});
|
|
80
|
+
writeFileSync(settingsPath, JSON.stringify(settings, null, 2));
|
|
81
|
+
console.log("Installed auto token-sharing hook.");
|
|
82
|
+
}
|
|
83
|
+
} catch (err) {
|
|
84
|
+
console.log("Could not install token hook (non-critical):", err.message);
|
|
85
|
+
}
|
|
86
|
+
|
|
43
87
|
console.log(`
|
|
44
88
|
Done! You're "${username.trim()}".
|
|
45
89
|
|
|
46
90
|
Now add the MCP server to Claude Code:
|
|
47
91
|
|
|
48
|
-
claude mcp add claude-friends --
|
|
92
|
+
claude mcp add claude-friends -- claude-friends serve
|
|
93
|
+
|
|
94
|
+
Then in Claude Code:
|
|
95
|
+
/friend alice Add a friend
|
|
96
|
+
/friends See who's online
|
|
97
|
+
/nudge bob Nudge someone
|
|
98
|
+
/status debugging Set your status
|
|
99
|
+
/unfriend alice Remove a friend
|
|
49
100
|
|
|
50
|
-
|
|
51
|
-
"who's online?"
|
|
52
|
-
"add friend alice"
|
|
53
|
-
"set my status to debugging auth"
|
|
54
|
-
"nudge bob"
|
|
101
|
+
Token usage is shared automatically with friends.
|
|
55
102
|
`);
|
|
56
103
|
|
|
57
104
|
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.
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// Hook script: reads token estimate from session, pushes to PartyKit
|
|
4
|
+
// Called by Claude Code's Stop hook after each response
|
|
5
|
+
|
|
6
|
+
import { readFileSync, writeFileSync, existsSync } from "fs";
|
|
7
|
+
import { join } from "path";
|
|
8
|
+
import { homedir } from "os";
|
|
9
|
+
|
|
10
|
+
const CONFIG_PATH = join(homedir(), ".claude-friends.json");
|
|
11
|
+
const TOKENS_PATH = join(homedir(), ".claude-friends-tokens.json");
|
|
12
|
+
const PARTY_HOST = "claude-friends-app.nandinitalwar.partykit.dev";
|
|
13
|
+
|
|
14
|
+
// Read config
|
|
15
|
+
let config;
|
|
16
|
+
try {
|
|
17
|
+
config = JSON.parse(readFileSync(CONFIG_PATH, "utf-8"));
|
|
18
|
+
} catch {
|
|
19
|
+
process.exit(0); // silently exit if not set up
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Read hook input from stdin
|
|
23
|
+
let input = "";
|
|
24
|
+
try {
|
|
25
|
+
input = readFileSync("/dev/stdin", "utf-8");
|
|
26
|
+
} catch {}
|
|
27
|
+
|
|
28
|
+
// Parse the stop event to estimate tokens
|
|
29
|
+
let tokensThisCall = 0;
|
|
30
|
+
try {
|
|
31
|
+
const event = JSON.parse(input);
|
|
32
|
+
// Estimate based on content length — rough but functional
|
|
33
|
+
const content = JSON.stringify(event);
|
|
34
|
+
tokensThisCall = Math.ceil(content.length / 4); // ~4 chars per token
|
|
35
|
+
} catch {
|
|
36
|
+
tokensThisCall = 500; // default estimate per response
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Accumulate session tokens
|
|
40
|
+
let sessionTokens = 0;
|
|
41
|
+
try {
|
|
42
|
+
if (existsSync(TOKENS_PATH)) {
|
|
43
|
+
const data = JSON.parse(readFileSync(TOKENS_PATH, "utf-8"));
|
|
44
|
+
// Reset if older than 4 hours (new session)
|
|
45
|
+
if (Date.now() - data.lastUpdate < 4 * 60 * 60 * 1000) {
|
|
46
|
+
sessionTokens = data.tokens || 0;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
} catch {}
|
|
50
|
+
|
|
51
|
+
sessionTokens += tokensThisCall;
|
|
52
|
+
|
|
53
|
+
writeFileSync(TOKENS_PATH, JSON.stringify({
|
|
54
|
+
tokens: sessionTokens,
|
|
55
|
+
lastUpdate: Date.now(),
|
|
56
|
+
}));
|
|
57
|
+
|
|
58
|
+
// Push to PartyKit via HTTP (faster than WebSocket for one-shot)
|
|
59
|
+
// Use the WebSocket approach since PartyKit is WS-only
|
|
60
|
+
try {
|
|
61
|
+
const { default: PartySocket } = await import("partysocket");
|
|
62
|
+
const ws = new PartySocket({
|
|
63
|
+
host: PARTY_HOST,
|
|
64
|
+
room: "lobby",
|
|
65
|
+
query: { username: config.username },
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
ws.addEventListener("open", () => {
|
|
69
|
+
ws.send(JSON.stringify({ type: "share-tokens", tokens: sessionTokens }));
|
|
70
|
+
setTimeout(() => { ws.close(); process.exit(0); }, 500);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
ws.addEventListener("error", () => process.exit(0));
|
|
74
|
+
|
|
75
|
+
// Don't hang
|
|
76
|
+
setTimeout(() => process.exit(0), 3000);
|
|
77
|
+
} catch {
|
|
78
|
+
process.exit(0);
|
|
79
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "claude-friends",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
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,9 @@
|
|
|
15
15
|
"cli.js",
|
|
16
16
|
"mcp-server.js",
|
|
17
17
|
"statusline.js",
|
|
18
|
-
"client.js"
|
|
18
|
+
"client.js",
|
|
19
|
+
"commands/",
|
|
20
|
+
"hooks/"
|
|
19
21
|
],
|
|
20
22
|
"dependencies": {
|
|
21
23
|
"@modelcontextprotocol/sdk": "^1.12.1",
|