@feynmanzhang/open-party 0.1.4 → 0.1.5

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 (27) hide show
  1. package/dist/claude-code/{open-party-0.1.0 → open-party-0.1.5}/.claude-plugin/plugin.json +1 -1
  2. package/dist/claude-code/open-party-0.1.5/BUILD_INFO.json +6 -0
  3. package/dist/claude-code/{open-party-0.1.1 → open-party-0.1.5}/dist/hook-handler.js +113 -46
  4. package/dist/claude-code/{open-party-0.1.1 → open-party-0.1.5}/dist/mcp-server.js +156 -25
  5. package/dist/claude-code/{open-party-0.1.1 → open-party-0.1.5}/dist/party-server.js +549 -64
  6. package/dist/claude-code/{open-party-0.1.1 → open-party-0.1.5}/hooks/hooks.json +1 -1
  7. package/dist/claude-code/{open-party-0.1.1 → open-party-0.1.5}/package.json +1 -1
  8. package/dist/cli/index.js +700 -134
  9. package/dist/cli/index.js.map +1 -1
  10. package/dist/openclaw/open-party-0.1.5/BUILD_INFO.json +6 -0
  11. package/dist/openclaw/open-party-0.1.5/SKILL.md +127 -0
  12. package/dist/openclaw/open-party-0.1.5/dist/index.js +550 -0
  13. package/dist/openclaw/open-party-0.1.5/openclaw.plugin.json +28 -0
  14. package/dist/openclaw/open-party-0.1.5/package.json +12 -0
  15. package/dist/openclaw/open-party-0.1.5/skills/open-party/SKILL.md +90 -0
  16. package/dist/party-server.js +549 -64
  17. package/dist/party-server.js.map +1 -1
  18. package/package.json +35 -4
  19. package/dist/claude-code/open-party-0.1.1/.claude-plugin/plugin.json +0 -5
  20. package/dist/claude-code/open-party-0.1.1/.mcp.json +0 -9
  21. package/dist/claude-code/open-party-0.1.1/BUILD_INFO.json +0 -6
  22. package/dist/hook-handler.js +0 -555
  23. package/dist/hook-handler.js.map +0 -1
  24. package/dist/mcp-server.js +0 -21408
  25. package/dist/mcp-server.js.map +0 -1
  26. /package/dist/claude-code/{open-party-0.1.0 → open-party-0.1.5}/.mcp.json +0 -0
  27. /package/dist/claude-code/{open-party-0.1.1 → open-party-0.1.5}/skills/open-party/SKILL.md +0 -0
package/package.json CHANGED
@@ -1,9 +1,28 @@
1
1
  {
2
2
  "name": "@feynmanzhang/open-party",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "Decentralized Agent communication network for Claude Code",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://gitee.com/jiayuzhang123/open-party.git"
10
+ },
11
+ "homepage": "https://gitee.com/jiayuzhang123/open-party",
12
+ "bugs": {
13
+ "url": "https://gitee.com/jiayuzhang123/open-party/issues"
14
+ },
15
+ "keywords": [
16
+ "claude",
17
+ "claude-code",
18
+ "mcp",
19
+ "plugin",
20
+ "agent-network",
21
+ "p2p"
22
+ ],
23
+ "engines": {
24
+ "node": ">=20.0.0"
25
+ },
7
26
  "bin": {
8
27
  "open-party": "./dist/cli/index.js"
9
28
  },
@@ -11,13 +30,25 @@
11
30
  "dist"
12
31
  ],
13
32
  "scripts": {
14
- "build": "tsup",
33
+ "build": "tsup && node scripts/copy-runtime-dist.mjs",
15
34
  "typecheck": "tsc --noEmit",
16
35
  "test": "vitest run",
17
36
  "test:watch": "vitest",
18
- "prepublishOnly": "npm run build && npm run build:plugin",
37
+ "prepublishOnly": "npm run build && npm run build:plugin && npm run build:openclaw",
19
38
  "build:plugin": "node scripts/build-plugin.mjs",
20
- "build:plugin:zip": "node scripts/build-plugin.mjs --zip"
39
+ "build:plugin:zip": "node scripts/build-plugin.mjs --zip",
40
+ "build:openclaw": "node scripts/build-openclaw.mjs",
41
+ "build:openclaw:zip": "node scripts/build-openclaw.mjs --zip",
42
+ "release": "node scripts/release.mjs",
43
+ "release:patch": "node scripts/release.mjs --patch",
44
+ "release:minor": "node scripts/release.mjs --minor",
45
+ "release:major": "node scripts/release.mjs --major",
46
+ "sync-marketplace": "node scripts/sync-marketplace.mjs",
47
+ "sync-marketplace:force": "node scripts/sync-marketplace.mjs --force",
48
+ "lint:errors": "node scripts/lint-error-patterns.mjs",
49
+ "changelog": "node scripts/generate-changelog.mjs",
50
+ "changelog:dry": "node scripts/generate-changelog.mjs --dry-run",
51
+ "dev": "npm run build:plugin && npm run sync-marketplace"
21
52
  },
22
53
  "dependencies": {
23
54
  "@hono/node-server": "^1.14.0",
@@ -1,5 +0,0 @@
1
- {
2
- "name": "open-party",
3
- "version": "0.1.1",
4
- "description": "Decentralized Agent communication network for Claude Code"
5
- }
@@ -1,9 +0,0 @@
1
- {
2
- "mcpServers": {
3
- "open-party": {
4
- "type": "stdio",
5
- "command": "node",
6
- "args": ["${CLAUDE_PLUGIN_ROOT}/dist/mcp-server.js"]
7
- }
8
- }
9
- }
@@ -1,6 +0,0 @@
1
- {
2
- "version": "0.1.1",
3
- "git_commit": "5c78847",
4
- "build_timestamp": "2026-05-30T12:58:23.755Z",
5
- "source_path": "src/client/claude-code/"
6
- }
@@ -1,555 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
-
4
- // src/client/claude-code/src/hook-handler.ts
5
- import { randomUUID as randomUUID2 } from "crypto";
6
-
7
- // src/client/claude-code/src/client.ts
8
- var PartyServerClient = class {
9
- baseUrl;
10
- timeout;
11
- constructor(baseUrl = "http://127.0.0.1:8000", timeout = 5e3) {
12
- this.baseUrl = baseUrl.replace(/\/$/, "");
13
- this.timeout = timeout;
14
- }
15
- async request(path, options = {}) {
16
- const controller = new AbortController();
17
- const timer = setTimeout(() => controller.abort(), this.timeout);
18
- try {
19
- const resp = await fetch(`${this.baseUrl}${path}`, {
20
- ...options,
21
- signal: controller.signal,
22
- headers: {
23
- "Content-Type": "application/json",
24
- ...options.headers
25
- }
26
- });
27
- if (!resp.ok) throw new Error(`HTTP ${resp.status}: ${resp.statusText}`);
28
- return resp.json();
29
- } finally {
30
- clearTimeout(timer);
31
- }
32
- }
33
- // -- Agent lifecycle --
34
- async register(agentId, displayName, metadata) {
35
- return this.request("/agent/register", {
36
- method: "POST",
37
- body: JSON.stringify({ agent_id: agentId, display_name: displayName, metadata: metadata ?? {} })
38
- });
39
- }
40
- async remove(agentId) {
41
- const result = await this.request("/agent/remove", {
42
- method: "POST",
43
- body: JSON.stringify({ agent_id: agentId })
44
- });
45
- return result.status === "removed";
46
- }
47
- async heartbeat(agentId) {
48
- return this.request("/agent/heartbeat", {
49
- method: "POST",
50
- body: JSON.stringify({ agent_id: agentId })
51
- });
52
- }
53
- async listAgents() {
54
- const result = await this.request("/agent/list");
55
- return result.agents ?? [];
56
- }
57
- // -- Messaging --
58
- async sendMessage(senderId, recipientId, content, summary) {
59
- return this.request("/agent/send", {
60
- method: "POST",
61
- body: JSON.stringify({ sender_id: senderId, recipient_id: recipientId, content, summary })
62
- });
63
- }
64
- async checkMessages(agentId) {
65
- const result = await this.request(`/agent/messages/${agentId}`);
66
- return result.messages ?? [];
67
- }
68
- /** Get message history for an agent. */
69
- async getMessageHistory(agentId, limit = 20) {
70
- const result = await this.request(`/agent/history/${agentId}?limit=${limit}`);
71
- return result.history ?? [];
72
- }
73
- // -- Proxy --
74
- async health() {
75
- return this.request("/proxy/health");
76
- }
77
- };
78
-
79
- // src/client/claude-code/src/session.ts
80
- import { existsSync, mkdirSync, readFileSync, unlinkSync, writeFileSync } from "fs";
81
- import { join } from "path";
82
- import { homedir } from "os";
83
- import { randomUUID } from "crypto";
84
- var SESSION_DIR = join(homedir(), ".open-party");
85
- var SESSIONS_DIR = join(SESSION_DIR, "sessions");
86
- var AGENTS_DIR = join(SESSION_DIR, "agents");
87
- function ensureDir(dir) {
88
- if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
89
- }
90
- function writeSession(sessionId, agentId, displayName, serverUrl) {
91
- ensureDir(SESSIONS_DIR);
92
- ensureDir(AGENTS_DIR);
93
- const sessionData = { agent_id: agentId, display_name: displayName, server_url: serverUrl, session_id: sessionId };
94
- writeFileSync(join(SESSIONS_DIR, `${sessionId}.json`), JSON.stringify(sessionData));
95
- writeFileSync(join(AGENTS_DIR, `${agentId}.json`), JSON.stringify({ session_id: sessionId }));
96
- }
97
- function readSession(sessionId) {
98
- const path = join(SESSIONS_DIR, `${sessionId}.json`);
99
- if (!existsSync(path)) return void 0;
100
- return JSON.parse(readFileSync(path, "utf-8"));
101
- }
102
- function generateAgentId() {
103
- return `agent-${randomUUID().slice(0, 12)}`;
104
- }
105
- function generateDisplayName() {
106
- const adjectives = [
107
- "swift",
108
- "calm",
109
- "bold",
110
- "keen",
111
- "warm",
112
- "bright",
113
- "clever",
114
- "noble",
115
- "agile",
116
- "brave"
117
- ];
118
- const nouns = [
119
- "falcon",
120
- "river",
121
- "storm",
122
- "raven",
123
- "tiger",
124
- "canyon",
125
- "spark",
126
- "cedar",
127
- "fox",
128
- "wolf"
129
- ];
130
- const adj = adjectives[Math.floor(Math.random() * adjectives.length)];
131
- const noun = nouns[Math.floor(Math.random() * nouns.length)];
132
- const num = Math.floor(Math.random() * 100);
133
- return `${adj}-${noun}-${num}`;
134
- }
135
-
136
- // src/client/claude-code/src/stdin-reader.ts
137
- var SAFETY_TIMEOUT_MS = 3e4;
138
- var PARSE_DELAY_MS = 50;
139
- function isStdinAvailable() {
140
- try {
141
- const stdin = process.stdin;
142
- if (stdin.isTTY) return false;
143
- stdin.readable;
144
- return true;
145
- } catch {
146
- return false;
147
- }
148
- }
149
- function tryParseJson(input) {
150
- const trimmed = input.trim();
151
- if (!trimmed) return { success: false };
152
- try {
153
- return { success: true, value: JSON.parse(trimmed) };
154
- } catch {
155
- return { success: false };
156
- }
157
- }
158
- async function readJsonFromStdin() {
159
- if (!isStdinAvailable()) return void 0;
160
- return new Promise((resolve2) => {
161
- let input = "";
162
- let resolved = false;
163
- let parseDelayId = null;
164
- const cleanup = () => {
165
- try {
166
- process.stdin.removeAllListeners("data");
167
- process.stdin.removeAllListeners("end");
168
- process.stdin.removeAllListeners("error");
169
- } catch {
170
- }
171
- };
172
- const resolveWith = (value) => {
173
- if (resolved) return;
174
- resolved = true;
175
- if (parseDelayId) clearTimeout(parseDelayId);
176
- clearTimeout(safetyTimeoutId);
177
- cleanup();
178
- resolve2(value);
179
- };
180
- const tryResolveWithJson = () => {
181
- const result = tryParseJson(input);
182
- if (result.success) {
183
- resolveWith(result.value);
184
- return true;
185
- }
186
- return false;
187
- };
188
- const safetyTimeoutId = setTimeout(() => {
189
- if (!resolved) {
190
- if (!tryResolveWithJson()) {
191
- resolveWith(input.trim() ? void 0 : void 0);
192
- }
193
- }
194
- }, SAFETY_TIMEOUT_MS);
195
- try {
196
- process.stdin.on("data", (chunk) => {
197
- input += chunk.toString();
198
- if (parseDelayId) {
199
- clearTimeout(parseDelayId);
200
- parseDelayId = null;
201
- }
202
- if (tryResolveWithJson()) return;
203
- parseDelayId = setTimeout(() => tryResolveWithJson(), PARSE_DELAY_MS);
204
- });
205
- process.stdin.on("end", () => {
206
- if (!resolved) tryResolveWithJson();
207
- });
208
- process.stdin.on("error", () => {
209
- if (!resolved) resolveWith(void 0);
210
- });
211
- } catch {
212
- resolved = true;
213
- clearTimeout(safetyTimeoutId);
214
- cleanup();
215
- resolve2(void 0);
216
- }
217
- });
218
- }
219
-
220
- // src/client/claude-code/src/server-manager.ts
221
- import { spawn, execSync } from "child_process";
222
- import { existsSync as existsSync2, readFileSync as readFileSync2, writeFileSync as writeFileSync2, unlinkSync as unlinkSync2, mkdirSync as mkdirSync2, openSync } from "fs";
223
- import { join as join2, resolve, dirname } from "path";
224
- import { homedir as homedir2 } from "os";
225
- import { fileURLToPath } from "url";
226
- var __dirname = dirname(fileURLToPath(import.meta.url));
227
- var DEFAULT_PORT = parseInt(process.env.PARTY_PORT || "8000", 10);
228
- var HEALTH_URL = `http://127.0.0.1:${DEFAULT_PORT}/proxy/health`;
229
- var STARTUP_TIMEOUT = 1e4;
230
- function pidFile() {
231
- const pluginData = process.env.CLAUDE_PLUGIN_DATA || "";
232
- if (pluginData) return join2(pluginData, "server.pid");
233
- return join2(homedir2(), ".open-party", "server.pid");
234
- }
235
- function logFile() {
236
- const pluginData = process.env.CLAUDE_PLUGIN_DATA || "";
237
- if (pluginData) return join2(pluginData, "server.log");
238
- return join2(homedir2(), ".open-party", "server.log");
239
- }
240
- function pluginRoot() {
241
- if (process.env.CLAUDE_PLUGIN_ROOT) return process.env.CLAUDE_PLUGIN_ROOT;
242
- const fromHere = resolve(__dirname, "..");
243
- if (existsSync2(join2(fromHere, "dist", "party-server.js"))) {
244
- return fromHere;
245
- }
246
- if (existsSync2(join2(fromHere, "party-server.js"))) {
247
- return fromHere;
248
- }
249
- return resolve(__dirname, "..");
250
- }
251
- async function isRunning() {
252
- try {
253
- const controller = new AbortController();
254
- const timer = setTimeout(() => controller.abort(), 2e3);
255
- const resp = await fetch(HEALTH_URL, { signal: controller.signal });
256
- clearTimeout(timer);
257
- return resp.status === 200;
258
- } catch {
259
- return false;
260
- }
261
- }
262
- function writePid(pid) {
263
- const path = pidFile();
264
- const dir = dirname(path);
265
- if (!existsSync2(dir)) mkdirSync2(dir, { recursive: true });
266
- writeFileSync2(path, String(pid));
267
- }
268
- async function sleep(ms) {
269
- return new Promise((resolve2) => setTimeout(resolve2, ms));
270
- }
271
- async function ensureServerRunning() {
272
- if (await isRunning()) return;
273
- const serverScript = join2(pluginRoot(), "dist", "party-server.js");
274
- if (!existsSync2(serverScript)) {
275
- console.error(`[Open Party] Server script not found: ${serverScript}`);
276
- return;
277
- }
278
- const logPath = logFile();
279
- mkdirSync2(dirname(logPath), { recursive: true });
280
- const logFd = openSync(logPath, "a");
281
- const proc = spawn(process.execPath, [serverScript], {
282
- stdio: ["ignore", logFd, logFd],
283
- detached: true,
284
- windowsHide: true
285
- });
286
- proc.unref();
287
- writePid(proc.pid);
288
- proc.on("error", (err) => {
289
- console.error(`[Open Party] Failed to start server: ${err.message}`);
290
- });
291
- const deadline = Date.now() + STARTUP_TIMEOUT;
292
- while (Date.now() < deadline) {
293
- if (await isRunning()) return;
294
- await sleep(500);
295
- }
296
- try {
297
- process.kill(proc.pid, 0);
298
- } catch {
299
- console.error(`[Open Party] Server crashed during startup. Check log: ${logPath}`);
300
- }
301
- }
302
-
303
- // src/client/claude-code/src/hook-handler.ts
304
- var PARTY_SERVER_URL = process.env.PARTY_SERVER_URL || "http://127.0.0.1:8000";
305
- async function handleSessionStart(sessionId, source) {
306
- await ensureServerRunning();
307
- const client = new PartyServerClient(PARTY_SERVER_URL);
308
- const existing = readSession(sessionId);
309
- if (existing && (source === "clear" || source === "compact" || source === "resume")) {
310
- const agentId2 = existing.agent_id;
311
- const displayName2 = existing.display_name || agentId2;
312
- if (source === "clear") {
313
- try {
314
- await client.register(agentId2, displayName2, { type: "claude-code" });
315
- console.error(`[Open Party] Re-registered as ${agentId2} (${displayName2})`);
316
- } catch (e) {
317
- console.error(`[Open Party] Re-registration failed: ${e.message}`);
318
- }
319
- writeSession(sessionId, agentId2, displayName2, PARTY_SERVER_URL);
320
- }
321
- let agents2 = [];
322
- let pendingMessages = [];
323
- try {
324
- agents2 = await client.listAgents();
325
- if (source === "resume") {
326
- pendingMessages = await client.checkMessages(agentId2);
327
- }
328
- } catch {
329
- }
330
- outputContext(agentId2, displayName2, agents2, pendingMessages);
331
- return;
332
- }
333
- const agentId = generateAgentId();
334
- const displayName = generateDisplayName();
335
- try {
336
- await client.register(agentId, displayName, { type: "claude-code" });
337
- console.error(`[Open Party] Registered as ${agentId} (${displayName})`);
338
- } catch (e) {
339
- console.error(`[Open Party] Registration failed: ${e.message}`);
340
- writeSession(sessionId, agentId, displayName, PARTY_SERVER_URL);
341
- outputContext(agentId, displayName, [], []);
342
- return;
343
- }
344
- writeSession(sessionId, agentId, displayName, PARTY_SERVER_URL);
345
- let agents = [];
346
- try {
347
- agents = await client.listAgents();
348
- } catch {
349
- }
350
- outputContext(agentId, displayName, agents, []);
351
- }
352
- async function handleSessionEnd(sessionId) {
353
- const session = readSession(sessionId);
354
- if (!session) return;
355
- const agentId = session.agent_id;
356
- const serverUrl = session.server_url;
357
- const client = new PartyServerClient(serverUrl);
358
- try {
359
- await client.remove(agentId);
360
- console.error(`[Open Party] Unregistered ${agentId}`);
361
- } catch (e) {
362
- console.error(`[Open Party] Unregister failed: ${e.message}`);
363
- }
364
- }
365
- async function handleUserPromptSubmit(sessionId) {
366
- const session = readSession(sessionId);
367
- if (!session) return;
368
- const agentId = session.agent_id;
369
- const serverUrl = session.server_url;
370
- const client = new PartyServerClient(serverUrl);
371
- let messages;
372
- try {
373
- messages = await client.checkMessages(agentId);
374
- } catch {
375
- return;
376
- }
377
- if (!messages.length) return;
378
- const lines = ["## \u{1F4EC} New message(s) from other agents", ""];
379
- for (const msg of messages) {
380
- const sender = msg.sender_id ?? "unknown";
381
- const content = msg.content ?? "";
382
- lines.push("---", "", `**From:** \`${sender}\``, "", `> ${content}`, "");
383
- }
384
- lines.push("---", "", "\u{1F4A1} Respond with `send_message` if needed.");
385
- const output = {
386
- hookSpecificOutput: {
387
- hookEventName: "UserPromptSubmit",
388
- additionalContext: lines.join("\n")
389
- }
390
- };
391
- console.log(JSON.stringify(output));
392
- }
393
- async function handlePostToolUse() {
394
- let toolName;
395
- let toolInput;
396
- let toolResult;
397
- try {
398
- const data = await readJsonFromStdin();
399
- toolName = data?.tool_name;
400
- toolInput = data?.tool_input;
401
- toolResult = data?.tool_result;
402
- } catch {
403
- }
404
- if (!toolName) return;
405
- let message = "";
406
- if (toolName.includes("send_message")) {
407
- const recipient = toolInput?.recipient_id ?? "unknown";
408
- const summary = toolInput?.summary ?? "(no summary)";
409
- message = `\u2709\uFE0F \u2192 ${recipient}: ${summary}`;
410
- } else if (toolName.includes("check_messages")) {
411
- if (toolResult?.includes("No new messages")) {
412
- message = `\u{1F4EC} No new messages`;
413
- } else {
414
- const summaries = [];
415
- const msgBlocks = toolResult?.split("---").filter((s) => s.includes("From:")) ?? [];
416
- for (const block of msgBlocks) {
417
- const fromMatch = block.match(/\*\*From:\*\* `([^`]+)`/);
418
- const summaryMatch = block.match(/\*\*Summary:\*\* (.+)/);
419
- const from = fromMatch ? fromMatch[1] : "unknown";
420
- const text = summaryMatch ? summaryMatch[1] : block.slice(0, 50).replace(/\n/g, " ");
421
- summaries.push(` ${from}: ${text}`);
422
- }
423
- if (summaries.length) {
424
- message = `\u{1F4EC} ${summaries.length} message(s):
425
- ` + summaries.join("\n");
426
- } else {
427
- message = `\u{1F4EC} Messages received`;
428
- }
429
- }
430
- } else if (toolName.includes("list_agents")) {
431
- const match = toolResult?.match(/Online Agents \((\d+)\)/);
432
- const count = match ? match[1] : "?";
433
- message = `\u{1F310} ${count} agent(s) online`;
434
- } else if (toolName.includes("message_history")) {
435
- const match = toolResult?.match(/Message History \(last (\d+)\)/);
436
- const count = match ? match[1] : "?";
437
- message = `\u{1F4DC} Last ${count} messages from history`;
438
- }
439
- if (!message) return;
440
- const output = {
441
- hookSpecificOutput: {
442
- hookEventName: "PostToolUse",
443
- systemMessage: message
444
- }
445
- };
446
- console.log(JSON.stringify(output));
447
- }
448
- var BOLD = "\x1B[1m";
449
- var CYAN = "\x1B[36m";
450
- var GREEN = "\x1B[32m";
451
- var YELLOW = "\x1B[33m";
452
- var DIM = "\x1B[2m";
453
- var RESET = "\x1B[0m";
454
- function formatBanner(displayName, others, pendingCount) {
455
- const lines = [];
456
- lines.push(`${BOLD}${CYAN}[Open Party]${RESET} ${BOLD}${displayName}${RESET}`);
457
- if (others.length === 0) {
458
- lines.push(` ${DIM}No other agents online${RESET}`);
459
- } else {
460
- lines.push(` ${GREEN}${others.length} agent(s) online:${RESET}`);
461
- for (let i = 0; i < others.length; i++) {
462
- const a = others[i];
463
- const name = a.display_name || a.agent_id;
464
- const prefix = i < others.length - 1 ? " \u251C\u2500" : " \u2514\u2500";
465
- lines.push(`${prefix} ${name}`);
466
- }
467
- }
468
- if (pendingCount > 0) {
469
- lines.push(` ${YELLOW}\u{1F4EC} ${pendingCount} unread message(s)${RESET}`);
470
- }
471
- return lines.join("\n");
472
- }
473
- function outputContext(agentId, displayName, agents, pendingMessages = []) {
474
- const others = agents.filter((a) => a.agent_id !== agentId);
475
- const lines = [
476
- "## Open Party Agent Identity",
477
- "",
478
- `Your Agent ID: **${agentId}**`,
479
- `Your Display Name: **${displayName}**`,
480
- "",
481
- "You are connected to the Open Party network as an autonomous agent. Other agents in the network communicate with you directly \u2014 they send messages to you, not to the person you're working with. When you receive messages from peers, treat them as messages to you as a collaborator: read, evaluate, and respond on your own judgment.",
482
- "",
483
- "Always use your Agent ID when calling Open Party MCP tools."
484
- ];
485
- if (others.length > 0) {
486
- lines.push("");
487
- lines.push(`**${others.length}** other agent(s) online:`);
488
- for (const a of others) {
489
- const name = a.display_name || a.agent_id;
490
- lines.push(`- **${name}** \`${a.agent_id}\``);
491
- }
492
- lines.push("");
493
- lines.push("Available tools: `send_message` \xB7 `check_messages` \xB7 `list_agents` \xB7 `message_history`");
494
- } else {
495
- lines.push("");
496
- lines.push("No other agents online right now. Use `list_agents()` to check later.");
497
- }
498
- if (pendingMessages.length > 0) {
499
- lines.push("");
500
- lines.push(`## \u{1F4EC} Unread Messages (${pendingMessages.length})`);
501
- lines.push("You have unread messages from your previous session:");
502
- for (const msg of pendingMessages) {
503
- const sender = msg.sender_id ?? "unknown";
504
- const content = msg.content ?? "";
505
- lines.push(`- **From \`${sender}\`:** ${content}`);
506
- }
507
- lines.push("Respond with `send_message` if needed.");
508
- }
509
- lines.push("");
510
- lines.push(
511
- '**Display note:** When you call Open Party tools, summarize the interaction naturally in your response rather than quoting raw tool output. For example, say "I sent a message to agent-x" rather than showing the tool response.'
512
- );
513
- const output = {
514
- hookSpecificOutput: {
515
- hookEventName: "SessionStart",
516
- additionalContext: lines.join("\n")
517
- },
518
- systemMessage: formatBanner(displayName, others, pendingMessages.length)
519
- };
520
- console.log(JSON.stringify(output));
521
- }
522
- async function main() {
523
- if (process.argv.length < 2) {
524
- console.error("Usage: hook-handler.js <session_start|session_end|user_prompt_submit>");
525
- process.exit(1);
526
- }
527
- const event = process.argv[2];
528
- let sessionId;
529
- let source;
530
- try {
531
- const data = await readJsonFromStdin();
532
- sessionId = data?.session_id;
533
- source = data?.source;
534
- } catch {
535
- }
536
- if (!sessionId) sessionId = randomUUID2().slice(0, 12);
537
- if (event === "session_start") {
538
- await handleSessionStart(sessionId, source || "startup");
539
- } else if (event === "session_end") {
540
- await handleSessionEnd(sessionId);
541
- } else if (event === "user_prompt_submit") {
542
- await handleUserPromptSubmit(sessionId);
543
- } else if (event === "post_tool_use") {
544
- await handlePostToolUse();
545
- } else {
546
- console.error(`[Open Party] Unknown event: ${event}`);
547
- process.exit(1);
548
- }
549
- process.exit(0);
550
- }
551
- main().catch((e) => {
552
- console.error(`[Open Party] Fatal: ${e.message}`);
553
- process.exit(1);
554
- });
555
- //# sourceMappingURL=hook-handler.js.map