Skip to content

Commit 5ee75bd

Browse files
author
Antigravity Assistant
committed
feat: Add MCP room tools and secure /wake endpoint
- Added `room_list_new`, `room_ack`, and `room_post` MCP tools for subsecond room I/O. - Implemented authenticated `/wake` HTTP endpoint in `webhook-server.mjs`. - Changed `gemini_gui_nudge.sh` to use `open -a` instead of `activate` with increased retry loops. - Fixed missing `--session` forwarding in CLI and `room-poller.mjs`.
1 parent 1703c73 commit 5ee75bd

6 files changed

Lines changed: 112 additions & 10 deletions

File tree

‎bin/cli.mjs‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,8 @@ async function main() {
451451
apiKey: pollerApiKey,
452452
handle: pollerHandle,
453453
interval: opts.interval ? parseInt(opts.interval) : undefined,
454-
config
454+
config,
455+
sessionOpt: opts.session
455456
});
456457
return;
457458
}
@@ -474,7 +475,8 @@ async function main() {
474475
apiKey: opts['api-key'],
475476
handle: opts.handle,
476477
interval: opts.interval ? parseInt(opts.interval) : undefined,
477-
config
478+
config,
479+
sessionOpt: opts.session
478480
});
479481
return;
480482
}

‎src/mcp-server.mjs‎

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,28 @@ export async function runMcpServer({ configPath } = {}) {
301301
}
302302

303303
const tools = [
304+
{
305+
name: 'room_list_new',
306+
description: 'List new messages from the notification file.',
307+
inputSchema: { type: 'object', properties: {} },
308+
},
309+
{
310+
name: 'room_ack',
311+
description: 'Clear the notification file, acknowledging that messages have been read.',
312+
inputSchema: { type: 'object', properties: {} },
313+
},
314+
{
315+
name: 'room_post',
316+
description: 'Post a message to a GroupMind room. Much faster than shelling python+urllib.',
317+
inputSchema: {
318+
type: 'object',
319+
properties: {
320+
room: { type: 'string', description: 'Room slug to post to. Defaults to config.mcp.confirmations.room.' },
321+
message: { type: 'string', description: 'The message to post.' },
322+
},
323+
required: ['message'],
324+
},
325+
},
304326
{
305327
name: 'wake_ide',
306328
description:
@@ -482,6 +504,47 @@ export async function runMcpServer({ configPath } = {}) {
482504
const args = req.params.arguments || {};
483505
try {
484506
switch (name) {
507+
case 'room_list_new': {
508+
const notifyFile = config?.poller?.notification_file || '/tmp/iak-new-messages.txt';
509+
try {
510+
const content = readFileSync(notifyFile, 'utf8').trim();
511+
if (!content) return ok('No new messages.');
512+
return ok(content);
513+
} catch {
514+
return ok('No new messages.');
515+
}
516+
}
517+
case 'room_ack': {
518+
const notifyFile = config?.poller?.notification_file || '/tmp/iak-new-messages.txt';
519+
try {
520+
const { writeFileSync } = await import('node:fs');
521+
writeFileSync(notifyFile, '');
522+
return ok('Acknowledged new messages.');
523+
} catch (e) {
524+
return err('Failed to ack: ' + e.message);
525+
}
526+
}
527+
case 'room_post': {
528+
const room = args.room || config?.mcp?.confirmations?.room;
529+
if (!room) return err('room_post: room is required');
530+
const apiKey = config?.poller?.api_key || config?.poller?.apiKey || process.env.ANTIGRAVITY_API_KEY;
531+
if (!apiKey) return err('room_post: config.poller.api_key is required');
532+
try {
533+
const res = await fetch(`https://groupmind.one/api/v1/rooms/${room}/messages`, {
534+
method: 'POST',
535+
headers: {
536+
'Content-Type': 'application/json',
537+
'Authorization': `Bearer ${apiKey}`
538+
},
539+
body: JSON.stringify({ body: args.message })
540+
});
541+
const text = await res.text();
542+
if (res.ok) return ok(`Posted to ${room}`);
543+
return err(`Failed to post to ${room}: ${res.status} ${text}`);
544+
} catch (e) {
545+
return err(`Failed to post: ${e.message}`);
546+
}
547+
}
485548
case 'wake_ide': {
486549
if (!args.session) return err('wake_ide: session is required');
487550
const text = typeof args.text === 'string' ? args.text : 'check rooms';

‎src/room-poller.mjs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ export function checkRoomMessages(config) {
6060
}
6161
}
6262

63-
export async function startRoomPoller({ rooms, apiKey, handle, interval, config }) {
63+
export async function startRoomPoller({ rooms, apiKey, handle, interval, config, sessionOpt }) {
6464
const seenFile = config?.poller?.seen_file || SEEN_FILE_DEFAULT;
6565
const notifyFile = config?.poller?.notification_file || NOTIFY_FILE_DEFAULT;
6666
const queuePath = config?.queue?.path || './ide-agent-queue.jsonl';
67-
const session = config?.tmux?.ide_session || config?.tmux?.default_session || 'claude';
67+
const session = sessionOpt || config?.tmux?.ide_session || config?.tmux?.default_session || 'claude';
6868
const nudgeText = config?.tmux?.nudge_text || 'check rooms';
6969
const nudgeMode = config?.poller?.nudge_mode || 'tmux';
7070
const nudgeCommandText = config?.poller?.nudge_command || '';

‎src/team-relay/room-poller.mjs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,11 @@ export function checkRoomMessages(config) {
144144
}
145145
}
146146

147-
export async function startRoomPoller({ rooms, apiKey, handle, interval, config }) {
147+
export async function startRoomPoller({ rooms, apiKey, handle, interval, config, sessionOpt }) {
148148
const seenFile = config?.poller?.seen_file || SEEN_FILE_DEFAULT;
149149
const notifyFile = config?.poller?.notification_file || NOTIFY_FILE_DEFAULT;
150150
const queuePath = config?.queue?.path || './ide-agent-queue.jsonl';
151-
const session = config?.tmux?.ide_session || config?.tmux?.default_session || 'claude';
151+
const session = sessionOpt || config?.tmux?.ide_session || config?.tmux?.default_session || 'claude';
152152
const nudgeText = config?.tmux?.nudge_text || 'check rooms';
153153
const nudgeMode = config?.poller?.nudge_mode || 'tmux';
154154
const nudgeCommandText = config?.poller?.nudge_command || '';

‎src/team-relay/webhook-server.mjs‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,42 @@ export function startWebhookServer(config, onEvent) {
323323
return;
324324
}
325325

326+
// Wake endpoint for MCP remote waking
327+
if (req.method === 'POST' && req.url === '/wake') {
328+
const chunks = [];
329+
for await (const chunk of req) chunks.push(chunk);
330+
let body = {};
331+
if (chunks.length > 0) {
332+
try { body = JSON.parse(Buffer.concat(chunks).toString()); } catch {}
333+
}
334+
335+
const expectedToken = process.env.IAK_WAKE_TOKEN || config.wake_token;
336+
const providedToken = body.token || req.headers['x-wake-token'];
337+
338+
if (expectedToken && providedToken !== expectedToken) {
339+
res.writeHead(401, { 'Content-Type': 'application/json' });
340+
res.end(JSON.stringify({ error: 'Unauthorized: Invalid or missing wake token' }));
341+
return;
342+
}
343+
344+
const wakeCmd = config.poller?.nudge_command || config.poller?.wake_script;
345+
if (wakeCmd) {
346+
try {
347+
execSync(wakeCmd);
348+
res.writeHead(200, { 'Content-Type': 'application/json' });
349+
res.end(JSON.stringify({ status: 'woken', method: 'command' }));
350+
} catch (e) {
351+
res.writeHead(500, { 'Content-Type': 'application/json' });
352+
res.end(JSON.stringify({ error: e.message }));
353+
}
354+
} else {
355+
nudgeTmux(config.tmux?.ide_session || config.tmux?.default_session || 'claude');
356+
res.writeHead(200, { 'Content-Type': 'application/json' });
357+
res.end(JSON.stringify({ status: 'woken', method: 'tmux' }));
358+
}
359+
return;
360+
}
361+
326362
if (req.method !== 'POST' || req.url !== '/webhook') {
327363
res.writeHead(404);
328364
res.end('Not found');
@@ -381,6 +417,7 @@ export function startWebhookServer(config, onEvent) {
381417

382418
server.listen(port, host, () => {
383419
console.log(`IDE Agent Kit webhook server listening on ${host}:${port}`);
420+
console.log(` POST /wake — Remote wake endpoint`);
384421
console.log(` POST /webhook — GitHub webhook endpoint`);
385422
console.log(` POST /groupmind — GroupMind webhook endpoint`);
386423
console.log(` POST /discord — Discord message webhook endpoint`);

‎tools/gemini_gui_nudge.sh‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,20 +61,20 @@ on run argv
6161
-- gone to the wrong app. petrus saw silent wake drops because of
6262
-- this. New: ACTIVATE → SET FRONTMOST → VERIFY → keystroke. Bail
6363
-- without typing if we can't make target frontmost in 5 tries.
64-
tell application appName to activate
64+
do shell script "open -a " & quoted form of appName
6565
delay 0.3
6666
6767
set focusOk to false
6868
set focusAttempts to 0
69-
repeat while focusAttempts < 5
69+
repeat while focusAttempts < 15
7070
try
7171
tell application "System Events"
7272
tell process appName
7373
set frontmost to true
7474
end tell
7575
end tell
7676
end try
77-
delay 0.2
77+
delay 0.5
7878
try
7979
tell application "System Events"
8080
set checkFront to name of first application process whose frontmost is true
@@ -88,7 +88,7 @@ on run argv
8888
end repeat
8989
9090
if not focusOk then
91-
log "gui_nudge: ABORT — could not bring " & appName & " to front after 5 attempts"
91+
log "gui_nudge: ABORT — could not bring " & appName & " to front after 15 attempts"
9292
return
9393
end if
9494

0 commit comments

Comments
 (0)