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:
HeavyGee
2026-07-28 08:36:56 +08:00
committed by GitHub
co-authored by Cursor
parent 84cd9aa3b1
commit e2631a553a
20 changed files with 1241 additions and 21 deletions
+2
View File
@@ -15,6 +15,8 @@ export const HAPI_SESSION_ID_ENV = 'HAPI_SESSION_ID';
*
* Prefer the MCP `display_image` tool for inline media when it is available;
* `HAPI_SESSION_ID` is the deterministic fallback for hub REST and shell tooling.
* To message another session, prefer MCP `ping_peer` or `hapi ping-peer` - do not
* reinvent JWT+curl.
*
* For lazy Codex sessions the id must only be exported after the hub row is
* materialized — exporting the provisional id early makes GET /api/sessions/:id
@@ -74,7 +74,7 @@ vi.mock('@/claude/utils/startHappyServer', () => ({
harness.startHappyServerOptions = options
return {
url: 'http://127.0.0.1:1234',
toolNames: ['change_title', 'display_image', 'skill_lookup'],
toolNames: ['change_title', 'display_image', 'ping_peer', 'skill_lookup'],
stop: harness.stopServer
}
})
@@ -167,7 +167,7 @@ describe('runAgentSession', () => {
'--url',
'http://127.0.0.1:1234',
'--tools',
'change_title,display_image,skill_lookup'
'change_title,display_image,ping_peer,skill_lookup'
])
expect(harness.newSessionOptions).toMatchObject({
cwd: '/tmp/project',