mirror of
https://github.com/wu736139669/hapi.git
synced 2026-11-24 04:47:03 +00:00
feat(cli): ping-peer CLI + MCP ping_peer for peer messaging (#1195)
* feat(cli): add ping-peer CLI and MCP ping_peer for peer messaging Promote resume-if-inactive + wait-active + POST message into a first-class CLI command and session MCP tool so agents stop reinventing JWT+curl. Fixes #1194 Co-authored-by: Cursor <cursoragent@cursor.com> * fix(cli): do not auto-approve MCP ping_peer Cross-session messaging can resume a peer and inject a prompt, so keep permission-mode gating (Codex PR review Major on #1195). Co-authored-by: Cursor <cursoragent@cursor.com> * fix(cli): require approval for ping_peer in read-only mode Read-only auto-approve treated non-write names as safe; ping_peer can still resume a peer and inject prompts, so gate it like a write tool. Co-authored-by: Cursor <cursoragent@cursor.com> * fix(cli): keep ping_peer out of Claude --allowedTools toolNames still registers the MCP tool, but Claude auto-allow must not pre-approve cross-session resume+inject without a permission prompt. Co-authored-by: Cursor <cursoragent@cursor.com> * fix(cli): re-check session active before ping-peer send List/get can race; POST /messages still 409s if the target flips inactive before send. Resume+wait again (and re-gate pi) immediately before POST. Co-authored-by: Cursor <cursoragent@cursor.com> --------- Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -36,3 +36,28 @@ describe('resolveToolAutoApprovalDecision skill_lookup', () => {
|
||||
)).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
describe('resolveToolAutoApprovalDecision ping_peer', () => {
|
||||
it.each([
|
||||
'ping_peer',
|
||||
'mcp__hapi__ping_peer',
|
||||
'hapi_ping_peer',
|
||||
'Ping Peer Session'
|
||||
])('does not auto-approve %s in default mode', (toolName) => {
|
||||
expect(resolveToolAutoApprovalDecision('default', toolName, 'call-1')).toBeNull()
|
||||
})
|
||||
|
||||
it.each([
|
||||
'ping_peer',
|
||||
'mcp__hapi__ping_peer',
|
||||
'hapi_ping_peer',
|
||||
'Ping Peer Session'
|
||||
])('does not auto-approve %s in read-only mode', (toolName) => {
|
||||
expect(resolveToolAutoApprovalDecision('read-only', toolName, 'call-1')).toBeNull()
|
||||
})
|
||||
|
||||
it('still auto-approves unrelated read tools in read-only mode', () => {
|
||||
expect(resolveToolAutoApprovalDecision('read-only', 'Read', 'call-1')).toBe('approved')
|
||||
expect(resolveToolAutoApprovalDecision('read-only', 'grep', 'call-2')).toBe('approved')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -32,8 +32,21 @@ const AUTO_APPROVE_EXACT_TOOL_NAMES = new Set([
|
||||
'happy__skill_lookup',
|
||||
'mcp__hapi__skill_lookup'
|
||||
]);
|
||||
// ping_peer intentionally omitted from always-approve: it can resume another
|
||||
// session and inject a prompt into a peer, so permission modes must still gate
|
||||
// it (Codex PR #1195). Treat it as write-like in read-only so ACP titles such as
|
||||
// "Ping Peer Session" also require approval.
|
||||
const AUTO_APPROVE_TOOL_ID_HINTS = ['change_title', 'save_memory'];
|
||||
const AUTO_APPROVE_WRITE_TOOL_HINTS = ['write', 'edit', 'create', 'delete', 'patch', 'fs-edit'];
|
||||
const SENSITIVE_TOOL_NAME_HINTS = ['ping_peer', 'ping peer'];
|
||||
const AUTO_APPROVE_WRITE_TOOL_HINTS = [
|
||||
'write',
|
||||
'edit',
|
||||
'create',
|
||||
'delete',
|
||||
'patch',
|
||||
'fs-edit',
|
||||
...SENSITIVE_TOOL_NAME_HINTS
|
||||
];
|
||||
|
||||
export function resolveToolAutoApprovalDecision(
|
||||
mode: PermissionMode | undefined,
|
||||
|
||||
Reference in New Issue
Block a user