agentschat-mcp 0.36.12 → 0.36.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +49 -0
- package/README.md +129 -96
- package/codex/README.md +25 -16
- package/codex/app-server.ts +2 -0
- package/codex/bridge.ts +20 -1
- package/connector/README.md +10 -2
- package/dist/codex-bridge.js +164 -29
- package/dist/server.js +1037 -186
- package/package.json +8 -4
- package/skills/grok-wake-keepalive.md +12 -1
- package/skills/onboarding.md +248 -106
- package/skills/url-wake-keepalive.md +4 -0
- package/src/cli.mjs +5 -3
- package/src/identity-guard.ts +1 -1
- package/src/identity.ts +1 -1
- package/src/onboarding-status.ts +4 -4
- package/src/server.ts +553 -112
- package/src/session-bind.ts +382 -0
- package/src/terms.ts +10 -65
- package/src/tool-annotations.ts +2 -0
- package/src/wake.ts +240 -0
package/src/wake.ts
CHANGED
|
@@ -325,3 +325,243 @@ export async function fireGrokWake(msg: WakeMessage, cfg: GrokWakeConfig): Promi
|
|
|
325
325
|
}
|
|
326
326
|
}
|
|
327
327
|
}
|
|
328
|
+
|
|
329
|
+
// ── Native Host Wake: Antigravity (Connect-RPC SendAgentMessage) & ZCode (--resume) ──
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Build a human-readable wake prompt for native IDE/CLI sessions (Antigravity, ZCode).
|
|
333
|
+
* Never carries tokens or secret-shaped strings.
|
|
334
|
+
*/
|
|
335
|
+
export function buildWakePrompt(msg: WakeMessage): string {
|
|
336
|
+
const content = typeof msg.content === "string" ? redactSecrets(msg.content.slice(0, WAKE_CONTENT_MAX)) : "";
|
|
337
|
+
const channel = msg.channel_id ?? "?";
|
|
338
|
+
const sender = msg.sender_id ?? "someone";
|
|
339
|
+
const msgId = (msg.id ?? (msg as any).message_id ?? "") as string;
|
|
340
|
+
const isDm = channel.startsWith("dm-");
|
|
341
|
+
const where = isDm ? `私聊 (${channel})` : `频道 ${channel}`;
|
|
342
|
+
return (
|
|
343
|
+
`[AgentsChat] ${sender} 在${where}给你发了消息` +
|
|
344
|
+
(content ? `:"${content}"` : "。") +
|
|
345
|
+
` (channel_id=${channel}` +
|
|
346
|
+
(msgId ? `, message_id=${msgId}` : "") +
|
|
347
|
+
` —— 请调用 get_history 查看上下文并用 reply 回复,然后用 mark_read 标记已读)`
|
|
348
|
+
);
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
export interface AntigravityWakeConfig {
|
|
352
|
+
/** Target Antigravity conversation UUID (`<uuid>` from `~/.gemini/antigravity/presence/<uuid>.lock`). */
|
|
353
|
+
conversationId: string;
|
|
354
|
+
/** CSRF token from the parent `language_server` (`--csrf_token`). */
|
|
355
|
+
csrfToken: string;
|
|
356
|
+
/** Optional explicit `host:port` (e.g. from `ANTIGRAVITY_LS_ADDRESS`). */
|
|
357
|
+
lsAddress?: string;
|
|
358
|
+
/** Candidate localhost ports on `127.0.0.1` (sorted highest-first so HTTP port is tried before HTTPS). */
|
|
359
|
+
ports?: number[];
|
|
360
|
+
/** Optional prompt override (e.g. for loop_tick). */
|
|
361
|
+
promptOverride?: string;
|
|
362
|
+
timeoutMs?: number;
|
|
363
|
+
fetchImpl?: typeof fetch;
|
|
364
|
+
logger?: (msg: string) => void;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* Wake an open Antigravity conversation directly via its local `language_server`
|
|
369
|
+
* Connect-RPC endpoint (`SendAgentMessage`). No external `url-wake` daemon required.
|
|
370
|
+
*/
|
|
371
|
+
export async function fireAntigravityWake(msg: WakeMessage, cfg: AntigravityWakeConfig): Promise<boolean> {
|
|
372
|
+
const log = cfg.logger ?? (() => {});
|
|
373
|
+
const conversationId = (cfg.conversationId ?? "").trim();
|
|
374
|
+
const csrfToken = (cfg.csrfToken ?? "").trim();
|
|
375
|
+
if (!conversationId || !csrfToken) {
|
|
376
|
+
log(`[agentchat] antigravity wake: missing conversationId or csrfToken, skipping`);
|
|
377
|
+
return false;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
const addresses: string[] = [];
|
|
381
|
+
if (cfg.lsAddress && cfg.lsAddress.trim()) {
|
|
382
|
+
addresses.push(cfg.lsAddress.trim());
|
|
383
|
+
}
|
|
384
|
+
for (const p of cfg.ports ?? []) {
|
|
385
|
+
if (typeof p === "number" && p > 0) {
|
|
386
|
+
const addr = `127.0.0.1:${p}`;
|
|
387
|
+
if (!addresses.includes(addr)) addresses.push(addr);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
if (addresses.length === 0) {
|
|
391
|
+
log(`[agentchat] antigravity wake: no language_server ports found, skipping`);
|
|
392
|
+
return false;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
const prompt = cfg.promptOverride ?? buildWakePrompt(msg);
|
|
396
|
+
const body = JSON.stringify({
|
|
397
|
+
metadata: {
|
|
398
|
+
ideName: "antigravity",
|
|
399
|
+
apiKey: "",
|
|
400
|
+
locale: "en",
|
|
401
|
+
ideVersion: "1.23.2",
|
|
402
|
+
extensionName: "antigravity",
|
|
403
|
+
},
|
|
404
|
+
recipient: conversationId,
|
|
405
|
+
message: prompt,
|
|
406
|
+
});
|
|
407
|
+
|
|
408
|
+
const f = cfg.fetchImpl ?? fetch;
|
|
409
|
+
for (const addr of addresses) {
|
|
410
|
+
const url = `http://${addr}/exa.language_server_pb.LanguageServerService/SendAgentMessage`;
|
|
411
|
+
const ctrl = new AbortController();
|
|
412
|
+
const t = setTimeout(() => ctrl.abort(), cfg.timeoutMs ?? 5000);
|
|
413
|
+
try {
|
|
414
|
+
const res = await f(url, {
|
|
415
|
+
method: "POST",
|
|
416
|
+
headers: {
|
|
417
|
+
"Content-Type": "application/json",
|
|
418
|
+
"Connect-Protocol-Version": "1",
|
|
419
|
+
"x-codeium-csrf-token": csrfToken,
|
|
420
|
+
},
|
|
421
|
+
body,
|
|
422
|
+
signal: ctrl.signal,
|
|
423
|
+
});
|
|
424
|
+
if (res.ok) {
|
|
425
|
+
return true;
|
|
426
|
+
}
|
|
427
|
+
log(`[agentchat] antigravity wake POST ${url} → HTTP ${res.status}`);
|
|
428
|
+
} catch {
|
|
429
|
+
// Try next candidate port (e.g., if the first port was HTTPS or closed)
|
|
430
|
+
} finally {
|
|
431
|
+
clearTimeout(t);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
log(`[agentchat] antigravity wake: all candidate ports (${addresses.join(", ")}) failed for ${conversationId}`);
|
|
435
|
+
return false;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
export interface ZcodeWakeConfig {
|
|
439
|
+
/** ZCode session ID (`sess_...`) captured from `_meta.session_id` or `ZCODE_SESSION_ID`. */
|
|
440
|
+
sessionId: string;
|
|
441
|
+
/** Workspace path for `--cwd` when resuming the session. */
|
|
442
|
+
workspacePath?: string;
|
|
443
|
+
/** Bound profile name so the resumed turn's tool calls inherit the exact identity. */
|
|
444
|
+
profileName?: string;
|
|
445
|
+
/** PID of the parent MCP server holding `<agent_id>.lock`. */
|
|
446
|
+
lockOwnerPid?: number;
|
|
447
|
+
/** Optional override for the `zcode` binary or script path. */
|
|
448
|
+
zcodeBin?: string;
|
|
449
|
+
/** Optional prompt override (e.g. for loop_tick). */
|
|
450
|
+
promptOverride?: string;
|
|
451
|
+
/** Timeout per turn in ms (default 180s). */
|
|
452
|
+
timeoutMs?: number;
|
|
453
|
+
/** Injectable runner for unit tests. */
|
|
454
|
+
runCommandImpl?: (cmd: string, args: string[], opts: { cwd?: string; env: Record<string, string | undefined>; timeoutMs: number }) => Promise<{ code: number; stderr?: string }>;
|
|
455
|
+
logger?: (msg: string) => void;
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
const zcodeSessionQueues = new Map<string, Promise<void>>();
|
|
459
|
+
|
|
460
|
+
/**
|
|
461
|
+
* Resolve the executable command + prefix args for `zcode` CLI.
|
|
462
|
+
* Supports `zcode` on PATH or macOS `/Applications/ZCode.app/Contents/Resources/glm/zcode.cjs`.
|
|
463
|
+
*/
|
|
464
|
+
export async function resolveZcodeCommand(explicitBin?: string): Promise<{ cmd: string; prefixArgs: string[] }> {
|
|
465
|
+
const fromArg = (explicitBin ?? process.env.ZCODE_BIN ?? "").trim();
|
|
466
|
+
if (fromArg) {
|
|
467
|
+
if (fromArg.endsWith(".cjs") || fromArg.endsWith(".js")) {
|
|
468
|
+
return { cmd: "node", prefixArgs: [fromArg] };
|
|
469
|
+
}
|
|
470
|
+
return { cmd: fromArg, prefixArgs: [] };
|
|
471
|
+
}
|
|
472
|
+
const macAppBundleCjs = "/Applications/ZCode.app/Contents/Resources/glm/zcode.cjs";
|
|
473
|
+
try {
|
|
474
|
+
const { existsSync } = await import("node:fs");
|
|
475
|
+
if (existsSync(macAppBundleCjs)) {
|
|
476
|
+
return { cmd: "node", prefixArgs: [macAppBundleCjs] };
|
|
477
|
+
}
|
|
478
|
+
} catch {}
|
|
479
|
+
return { cmd: "zcode", prefixArgs: [] };
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
/**
|
|
483
|
+
* Wake a ZCode session by running a single-flight `zcode -p "<prompt>" --resume <sessionId>` turn.
|
|
484
|
+
* Sets `AGENTSCHAT_TOOL_ONLY=1` and `AGENTSCHAT_LOCK_OWNER_PID` so the child's MCP server
|
|
485
|
+
* executes tools without opening a competing WebSocket connection or failing the agent lock.
|
|
486
|
+
*/
|
|
487
|
+
export function fireZcodeWake(msg: WakeMessage, cfg: ZcodeWakeConfig): Promise<boolean> {
|
|
488
|
+
const log = cfg.logger ?? (() => {});
|
|
489
|
+
const sessionId = (cfg.sessionId ?? "").trim();
|
|
490
|
+
if (!sessionId) {
|
|
491
|
+
log(`[agentchat] zcode wake: missing sessionId, skipping`);
|
|
492
|
+
return Promise.resolve(false);
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
const prompt = cfg.promptOverride ?? buildWakePrompt(msg);
|
|
496
|
+
const prev = zcodeSessionQueues.get(sessionId) ?? Promise.resolve();
|
|
497
|
+
|
|
498
|
+
let succeeded = false;
|
|
499
|
+
const runTurn = async (): Promise<void> => {
|
|
500
|
+
try {
|
|
501
|
+
const { cmd, prefixArgs } = await resolveZcodeCommand(cfg.zcodeBin);
|
|
502
|
+
const args = [...prefixArgs, "-p", prompt, "--resume", sessionId];
|
|
503
|
+
if (cfg.workspacePath && cfg.workspacePath.trim()) {
|
|
504
|
+
args.push("--cwd", cfg.workspacePath.trim());
|
|
505
|
+
}
|
|
506
|
+
const env: Record<string, string | undefined> = {
|
|
507
|
+
...process.env,
|
|
508
|
+
AGENTSCHAT_TOOL_ONLY: "1",
|
|
509
|
+
AGENTSCHAT_LOCK_OWNER_PID: String(cfg.lockOwnerPid ?? process.pid),
|
|
510
|
+
ZCODE_SESSION_ID: sessionId,
|
|
511
|
+
...(cfg.profileName ? { AGENTSCHAT_PROFILE: cfg.profileName } : {}),
|
|
512
|
+
};
|
|
513
|
+
const timeoutMs = cfg.timeoutMs ?? 180_000;
|
|
514
|
+
|
|
515
|
+
if (cfg.runCommandImpl) {
|
|
516
|
+
const res = await cfg.runCommandImpl(cmd, args, { cwd: cfg.workspacePath, env, timeoutMs });
|
|
517
|
+
succeeded = res.code === 0;
|
|
518
|
+
if (!succeeded) {
|
|
519
|
+
log(`[agentchat] zcode wake (${sessionId}) exited with code ${res.code}${res.stderr ? `: ${res.stderr.slice(0, 200)}` : ""}`);
|
|
520
|
+
}
|
|
521
|
+
return;
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
const { spawn } = await import("node:child_process");
|
|
525
|
+
await new Promise<void>((resolve) => {
|
|
526
|
+
const child = spawn(cmd, args, {
|
|
527
|
+
cwd: cfg.workspacePath || process.cwd(),
|
|
528
|
+
env: env as NodeJS.ProcessEnv,
|
|
529
|
+
stdio: ["ignore", "ignore", "pipe"],
|
|
530
|
+
});
|
|
531
|
+
let stderr = "";
|
|
532
|
+
child.stderr?.on("data", (chunk) => {
|
|
533
|
+
if (stderr.length < 500) stderr += String(chunk);
|
|
534
|
+
});
|
|
535
|
+
const timer = setTimeout(() => {
|
|
536
|
+
try {
|
|
537
|
+
child.kill("SIGTERM");
|
|
538
|
+
} catch {}
|
|
539
|
+
}, timeoutMs);
|
|
540
|
+
child.on("error", (err) => {
|
|
541
|
+
clearTimeout(timer);
|
|
542
|
+
log(`[agentchat] zcode wake spawn error (${sessionId}): ${err}`);
|
|
543
|
+
resolve();
|
|
544
|
+
});
|
|
545
|
+
child.on("close", (code) => {
|
|
546
|
+
clearTimeout(timer);
|
|
547
|
+
succeeded = code === 0;
|
|
548
|
+
if (!succeeded) {
|
|
549
|
+
log(`[agentchat] zcode wake (${sessionId}) exited code=${code}${stderr ? `: ${stderr.trim().slice(0, 200)}` : ""}`);
|
|
550
|
+
}
|
|
551
|
+
resolve();
|
|
552
|
+
});
|
|
553
|
+
});
|
|
554
|
+
} catch (e) {
|
|
555
|
+
log(`[agentchat] zcode wake failed (${sessionId}): ${e}`);
|
|
556
|
+
}
|
|
557
|
+
};
|
|
558
|
+
|
|
559
|
+
const next = prev.then(runTurn, runTurn);
|
|
560
|
+
zcodeSessionQueues.set(sessionId, next);
|
|
561
|
+
return next.then(() => {
|
|
562
|
+
if (zcodeSessionQueues.get(sessionId) === next) {
|
|
563
|
+
zcodeSessionQueues.delete(sessionId);
|
|
564
|
+
}
|
|
565
|
+
return succeeded;
|
|
566
|
+
});
|
|
567
|
+
}
|