fix(cli): stop peer pings from waking or broadcasting to unrelated sessions

ping_peer resumed any inactive target by default, and list_peers returned
the whole namespace (including offline sessions) with no machine or cwd, so
agents re-woke finished collaborators and broadcast exclusive-work notices
to every listed peer.

- ping_peer refuses inactive targets unless wake=true (CLI --wake, exit 5);
  spawn_peer keeps waking its own fresh child.
- list_peers lists active sessions only (hub GET /api/sessions?active=true)
  unless includeInactive (CLI --list --all); rows show busy/idle, machine,
  cwd, and same-machine/same-cwd marks relative to the caller.
- inspect_peer reports the peer's machine.
- Prompts and tool descriptions: message only task-related peers, inspect
  unfamiliar peers first, never broadcast, never wake for FYI/status.
This commit is contained in:
weishu
2026-11-05 11:28:40 +08:00
parent 7688a4f13a
commit 5a5731f938
14 changed files with 387 additions and 57 deletions
+6 -1
View File
@@ -20,7 +20,10 @@ import { PeerDeliveryModeSchema } from '@/modules/pingPeer/deliveryMode';
import { DISPLAY_IMAGE_PROMPT_CURSOR, DISPLAY_MEDIA_PROMPT_CURSOR, DISPLAY_VIDEO_PROMPT_CURSOR } from '@/modules/common/displayImagePrompt';
import {
INSPECT_PEER_TOOL_DESCRIPTION,
LIST_PEERS_INCLUDE_INACTIVE_PARAM_DESCRIPTION,
LIST_PEERS_TOOL_DESCRIPTION,
PEER_DELIVERY_MODE_DESCRIPTION,
PEER_WAKE_PARAM_DESCRIPTION,
PING_PEER_TOOL_DESCRIPTION,
SESSION_ID_PREFIX_PARAM_DESCRIPTION,
SPAWN_PEER_TOOL_DESCRIPTION,
@@ -219,6 +222,7 @@ export async function runHappyMcpStdioBridge(argv: string[]): Promise<void> {
sessionIdPrefix: z.string().trim().min(1).describe(SESSION_ID_PREFIX_PARAM_DESCRIPTION),
message: z.string().min(1).describe('Message text to deliver to the target session'),
deliveryMode: PeerDeliveryModeSchema.optional().describe(PEER_DELIVERY_MODE_DESCRIPTION),
wake: z.boolean().optional().describe(PEER_WAKE_PARAM_DESCRIPTION),
});
if (toolNames.has('ping_peer')) {
@@ -332,13 +336,14 @@ export async function runHappyMcpStdioBridge(argv: string[]): Promise<void> {
limit: z.number().int().min(1).max(100).optional().describe(
'Max sessions to return (default 30, max 100). Newest updatedAt first.'
),
includeInactive: z.boolean().optional().describe(LIST_PEERS_INCLUDE_INACTIVE_PARAM_DESCRIPTION),
});
if (toolNames.has('list_peers')) {
server.registerTool<any, any>(
'list_peers',
{
description: 'List peer HAPI sessions on the same hub/namespace (id prefix, active, flavor, name). Uses this session\'s hub credentials - works from runner-spawned agents without being on the hub host. Prefer this over shelling `hapi ping-peer --list`. Then call inspect_peer / ping_peer with a listed id, or spawn_peer to create a new peer with a remit.',
description: LIST_PEERS_TOOL_DESCRIPTION,
title: 'List Peer Sessions',
inputSchema: listPeersInputSchema,
},