mirror of
https://github.com/wu736139669/hapi.git
synced 2026-11-26 05:27:06 +00:00
feat(cli): add Codex-aware auto peer delivery
Default peer CLI and MCP messages to auto, steering eligible Codex turns and queueing otherwise. Preserve explicit delivery modes and uncertain-send safety, and clarify steer guidance for important time-sensitive findings.
This commit is contained in:
@@ -131,6 +131,10 @@ describe('startHappyServer skill_lookup', () => {
|
||||
|
||||
it.each([
|
||||
[undefined, 'accepted'],
|
||||
[undefined, 'steered'],
|
||||
['auto', 'accepted'],
|
||||
['auto', 'steered'],
|
||||
['auto', 'invoked'],
|
||||
['queue', 'accepted'],
|
||||
['steer', 'steered'],
|
||||
['steer', 'invoked']
|
||||
@@ -143,7 +147,8 @@ describe('startHappyServer skill_lookup', () => {
|
||||
const mcp = await connect(false)
|
||||
const tools = await mcp.listTools()
|
||||
const tool = tools.tools.find((entry) => entry.name === 'ping_peer')
|
||||
expect(tool?.inputSchema.properties?.deliveryMode).toMatchObject({ enum: ['queue', 'steer'] })
|
||||
expect(tool?.inputSchema.properties?.deliveryMode).toMatchObject({ enum: ['auto', 'queue', 'steer'] })
|
||||
expect(tool?.description).toContain('auto (default)')
|
||||
const result = await mcp.callTool({
|
||||
name: 'ping_peer',
|
||||
arguments: { sessionIdPrefix: 'peer-id', message: 'hello', ...(deliveryMode ? { deliveryMode } : {}) }
|
||||
|
||||
@@ -8,7 +8,7 @@ import { createServer, type IncomingMessage } from "node:http";
|
||||
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
|
||||
import { AddressInfo } from "node:net";
|
||||
import { z } from "zod";
|
||||
import { MessageDeliveryModeSchema, type MessageDeliveryMode } from '@hapi/protocol';
|
||||
import { PeerDeliveryModeSchema, type PeerDeliveryMode } from '@/modules/pingPeer/deliveryMode';
|
||||
import { logger } from "@/ui/logger";
|
||||
import { ApiSessionClient } from "@/api/apiSession";
|
||||
import { randomUUID } from "node:crypto";
|
||||
@@ -25,6 +25,7 @@ import { resolveSkill } from "@/modules/common/skills";
|
||||
import { isPeerToolsDisabled } from "@/modules/common/peerTools";
|
||||
import {
|
||||
INSPECT_PEER_TOOL_DESCRIPTION,
|
||||
PEER_DELIVERY_MODE_DESCRIPTION,
|
||||
PING_PEER_TOOL_DESCRIPTION,
|
||||
SESSION_ID_PREFIX_PARAM_DESCRIPTION,
|
||||
} from '@hapi/protocol/sessionCitation'
|
||||
@@ -134,9 +135,7 @@ function createHapiMcpServer(
|
||||
const pingPeerInputSchema: z.ZodTypeAny = z.object({
|
||||
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: MessageDeliveryModeSchema.optional().describe(
|
||||
'queue (default): next turn, resuming if needed. steer: insert into an active Pi, Codex, or Cursor ACP turn; idle/inactive targets are rejected. If steer fails after send, inspect the target before retrying; do not resend automatically.'
|
||||
),
|
||||
deliveryMode: PeerDeliveryModeSchema.optional().describe(PEER_DELIVERY_MODE_DESCRIPTION),
|
||||
});
|
||||
|
||||
const maxInlineMediaBytes = 25 * 1024 * 1024;
|
||||
@@ -327,7 +326,7 @@ function createHapiMcpServer(
|
||||
description: PING_PEER_TOOL_DESCRIPTION,
|
||||
title: 'Ping Peer Session',
|
||||
inputSchema: pingPeerInputSchema,
|
||||
}, async (args: { sessionIdPrefix: string; message: string; deliveryMode?: MessageDeliveryMode }) => {
|
||||
}, async (args: { sessionIdPrefix: string; message: string; deliveryMode?: PeerDeliveryMode }) => {
|
||||
logger.debug('[hapiMCP] ping_peer:', args.sessionIdPrefix);
|
||||
try {
|
||||
const result = await pingPeer({
|
||||
|
||||
@@ -42,6 +42,9 @@ describe('peer-tools citation steer across flavors', () => {
|
||||
|
||||
expect(opencode.OPENCODE_NATIVE_TOOL_INSTRUCTION).toContain('are disabled on this machine')
|
||||
expect(opencode.OPENCODE_NATIVE_TOOL_INSTRUCTION).not.toContain('Call "hapi_inspect_peer"')
|
||||
for (const prompt of [claudePrompt, codex.TITLE_INSTRUCTION, opencode.TITLE_INSTRUCTION, opencode.OPENCODE_NATIVE_TOOL_INSTRUCTION]) {
|
||||
expect(prompt).not.toContain('auto (default)')
|
||||
}
|
||||
} finally {
|
||||
restore()
|
||||
}
|
||||
@@ -54,6 +57,13 @@ describe('peer-tools citation steer across flavors', () => {
|
||||
expect(codex.TITLE_INSTRUCTION).toContain('Call "functions.hapi__inspect_peer"')
|
||||
expect(opencode.TITLE_INSTRUCTION).toContain('Call "hapi_inspect_peer"')
|
||||
expect(opencode.OPENCODE_NATIVE_TOOL_INSTRUCTION).toContain('Call "hapi_inspect_peer"')
|
||||
for (const prompt of [claude.getSystemPrompt(), codex.TITLE_INSTRUCTION, opencode.TITLE_INSTRUCTION, opencode.OPENCODE_NATIVE_TOOL_INSTRUCTION]) {
|
||||
expect(prompt).toContain('auto (default)')
|
||||
expect(prompt).toContain('Prefer auto for routine collaboration')
|
||||
expect(prompt).toContain('steer: use for important, time-sensitive findings the peer needs to know now')
|
||||
expect(prompt).toContain('does not abort the current turn or guarantee an immediate response')
|
||||
expect(prompt).toContain('do not resend automatically')
|
||||
}
|
||||
} finally {
|
||||
restore()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user