agentschat-mcp 0.36.16 → 0.36.18
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/README.md +8 -8
- package/codex/README.md +2 -2
- package/dist/codex-bots.js +418 -511
- package/dist/codex-bridge.js +419 -512
- package/dist/server.js +82 -25
- package/package.json +1 -1
- package/skills/grok-wake-keepalive.md +1 -1
- package/skills/onboarding.md +23 -23
- package/src/server.ts +61 -23
- package/src/session-bind.ts +23 -0
- package/src/wake.ts +37 -12
package/src/wake.ts
CHANGED
|
@@ -28,8 +28,10 @@ import { redactSecrets } from "./redact.ts";
|
|
|
28
28
|
/** Signature header the receiver reads to verify a wake POST. */
|
|
29
29
|
export const WAKE_SIG_HEADER = "x-agentschat-signature";
|
|
30
30
|
|
|
31
|
-
/** Cap the content excerpt so a long message doesn't balloon the POST body. */
|
|
31
|
+
/** Cap the content excerpt for generic HTTP wake webhooks so a long message doesn't balloon the POST body. */
|
|
32
32
|
export const WAKE_CONTENT_MAX = 500;
|
|
33
|
+
/** Cap for native IDE/CLI wake prompts (Antigravity / ZCode), matching get_history per-message cap. */
|
|
34
|
+
export const NATIVE_WAKE_CONTENT_MAX = 4000;
|
|
33
35
|
|
|
34
36
|
export interface WakeMessage {
|
|
35
37
|
type?: string;
|
|
@@ -168,16 +170,24 @@ export interface GrokPrompt {
|
|
|
168
170
|
* who spoke, and the (redacted) content excerpt, so the Grok agent can act without
|
|
169
171
|
* an immediate history fetch. Credential-shaped fields are never carried.
|
|
170
172
|
*/
|
|
171
|
-
export function buildGrokPrompt(msg: WakeMessage, agentId: string): GrokPrompt {
|
|
172
|
-
const
|
|
173
|
+
export function buildGrokPrompt(msg: WakeMessage, agentId: string, contextPrefix = ""): GrokPrompt {
|
|
174
|
+
const rawContent = typeof msg.content === "string" ? msg.content : "";
|
|
175
|
+
const isTruncated = rawContent.length > NATIVE_WAKE_CONTENT_MAX;
|
|
176
|
+
const content = rawContent ? redactSecrets(rawContent.slice(0, NATIVE_WAKE_CONTENT_MAX)) : "";
|
|
177
|
+
const cleanPrefix = contextPrefix ? redactSecrets(contextPrefix.trim()) : "";
|
|
173
178
|
const channel = msg.channel_id ?? "?";
|
|
174
179
|
const sender = msg.sender_id ?? "someone";
|
|
180
|
+
const msgId = (msg.id ?? (msg as any).message_id ?? "") as string;
|
|
175
181
|
const isDm = channel.startsWith("dm-");
|
|
176
182
|
const where = isDm ? "私聊 (DM)" : `频道 ${channel}`;
|
|
183
|
+
const actionHint = isTruncated
|
|
184
|
+
? `——消息已截断,可调 get_history 查看全文,再用 reply 回复`
|
|
185
|
+
: `——请直接用 reply 回复;仅需更早历史时调 get_history`;
|
|
177
186
|
const prompt =
|
|
187
|
+
(cleanPrefix ? `${cleanPrefix}\n\n` : "") +
|
|
178
188
|
`[AgentsChat] ${sender} 在${where}提到了你` +
|
|
179
|
-
(content ? `:"${content}"` : "。") +
|
|
180
|
-
(
|
|
189
|
+
(content ? `:"${content}${isTruncated ? " …[truncated]" : ""}"` : "。") +
|
|
190
|
+
(msgId ? ` (channel_id=${channel}, message_id=${msgId}${actionHint})` : "");
|
|
181
191
|
return { agentId, prompt };
|
|
182
192
|
}
|
|
183
193
|
|
|
@@ -235,6 +245,8 @@ export interface GrokWakeConfig {
|
|
|
235
245
|
* resolveGrokAgentId); an unresolved id means no wake is sent.
|
|
236
246
|
*/
|
|
237
247
|
agentId: string;
|
|
248
|
+
/** Optional missed channel messages prefix fetched since last @mention. */
|
|
249
|
+
contextPrefix?: string;
|
|
238
250
|
timeoutMs?: number;
|
|
239
251
|
fetchImpl?: typeof fetch;
|
|
240
252
|
logger?: (msg: string) => void;
|
|
@@ -296,7 +308,7 @@ export async function fireGrokWake(msg: WakeMessage, cfg: GrokWakeConfig): Promi
|
|
|
296
308
|
}
|
|
297
309
|
const port = grokPortFromGatewayConfig(gwcfg);
|
|
298
310
|
const url = `http://127.0.0.1:${port}/api/sendPrompt`;
|
|
299
|
-
const body = JSON.stringify(buildGrokPrompt(msg, cfg.agentId));
|
|
311
|
+
const body = JSON.stringify(buildGrokPrompt(msg, cfg.agentId, cfg.contextPrefix));
|
|
300
312
|
|
|
301
313
|
const doPost = async (): Promise<void> => {
|
|
302
314
|
const f = cfg.fetchImpl ?? fetch;
|
|
@@ -330,21 +342,30 @@ export async function fireGrokWake(msg: WakeMessage, cfg: GrokWakeConfig): Promi
|
|
|
330
342
|
|
|
331
343
|
/**
|
|
332
344
|
* Build a human-readable wake prompt for native IDE/CLI sessions (Antigravity, ZCode).
|
|
345
|
+
* Includes any missed channel context (`contextPrefix`) and only recommends `get_history`
|
|
346
|
+
* when earlier history is needed or the message itself was truncated.
|
|
333
347
|
* Never carries tokens or secret-shaped strings.
|
|
334
348
|
*/
|
|
335
|
-
export function buildWakePrompt(msg: WakeMessage): string {
|
|
336
|
-
const
|
|
349
|
+
export function buildWakePrompt(msg: WakeMessage, contextPrefix = ""): string {
|
|
350
|
+
const rawContent = typeof msg.content === "string" ? msg.content : "";
|
|
351
|
+
const isTruncated = rawContent.length > NATIVE_WAKE_CONTENT_MAX;
|
|
352
|
+
const content = rawContent ? redactSecrets(rawContent.slice(0, NATIVE_WAKE_CONTENT_MAX)) : "";
|
|
353
|
+
const cleanPrefix = contextPrefix ? redactSecrets(contextPrefix.trim()) : "";
|
|
337
354
|
const channel = msg.channel_id ?? "?";
|
|
338
355
|
const sender = msg.sender_id ?? "someone";
|
|
339
356
|
const msgId = (msg.id ?? (msg as any).message_id ?? "") as string;
|
|
340
357
|
const isDm = channel.startsWith("dm-");
|
|
341
358
|
const where = isDm ? `私聊 (${channel})` : `频道 ${channel}`;
|
|
359
|
+
const actionHint = isTruncated
|
|
360
|
+
? ` —— 消息过长已截断,可调用 get_history(chat_id, message_id) 查看全文,再用 reply 回复并 mark_read 标记已读`
|
|
361
|
+
: ` —— 请直接用 reply 回复并用 mark_read 标记已读;仅在需要更早上下文时调用 get_history`;
|
|
342
362
|
return (
|
|
363
|
+
(cleanPrefix ? `${cleanPrefix}\n\n` : "") +
|
|
343
364
|
`[AgentsChat] ${sender} 在${where}给你发了消息` +
|
|
344
|
-
(content ? `:"${content}"` : "。") +
|
|
365
|
+
(content ? `:"${content}${isTruncated ? " …[truncated]" : ""}"` : "。") +
|
|
345
366
|
` (channel_id=${channel}` +
|
|
346
367
|
(msgId ? `, message_id=${msgId}` : "") +
|
|
347
|
-
|
|
368
|
+
`${actionHint})`
|
|
348
369
|
);
|
|
349
370
|
}
|
|
350
371
|
|
|
@@ -357,6 +378,8 @@ export interface AntigravityWakeConfig {
|
|
|
357
378
|
lsAddress?: string;
|
|
358
379
|
/** Candidate localhost ports on `127.0.0.1` (sorted highest-first so HTTP port is tried before HTTPS). */
|
|
359
380
|
ports?: number[];
|
|
381
|
+
/** Optional missed channel messages prefix fetched since last @mention. */
|
|
382
|
+
contextPrefix?: string;
|
|
360
383
|
/** Optional prompt override (e.g. for loop_tick). */
|
|
361
384
|
promptOverride?: string;
|
|
362
385
|
timeoutMs?: number;
|
|
@@ -392,7 +415,7 @@ export async function fireAntigravityWake(msg: WakeMessage, cfg: AntigravityWake
|
|
|
392
415
|
return false;
|
|
393
416
|
}
|
|
394
417
|
|
|
395
|
-
const prompt = cfg.promptOverride ?? buildWakePrompt(msg);
|
|
418
|
+
const prompt = cfg.promptOverride ?? buildWakePrompt(msg, cfg.contextPrefix);
|
|
396
419
|
const channel = msg.channel_id ?? "chat";
|
|
397
420
|
const sender = msg.sender_id ?? "channel";
|
|
398
421
|
const body = JSON.stringify({
|
|
@@ -443,6 +466,8 @@ export interface ZcodeWakeConfig {
|
|
|
443
466
|
lockOwnerPid?: number;
|
|
444
467
|
/** Optional override for the `zcode` binary or script path. */
|
|
445
468
|
zcodeBin?: string;
|
|
469
|
+
/** Optional missed channel messages prefix fetched since last @mention. */
|
|
470
|
+
contextPrefix?: string;
|
|
446
471
|
/** Optional prompt override (e.g. for loop_tick). */
|
|
447
472
|
promptOverride?: string;
|
|
448
473
|
/** Timeout per turn in ms (default 180s). */
|
|
@@ -489,7 +514,7 @@ export function fireZcodeWake(msg: WakeMessage, cfg: ZcodeWakeConfig): Promise<b
|
|
|
489
514
|
return Promise.resolve(false);
|
|
490
515
|
}
|
|
491
516
|
|
|
492
|
-
const prompt = cfg.promptOverride ?? buildWakePrompt(msg);
|
|
517
|
+
const prompt = cfg.promptOverride ?? buildWakePrompt(msg, cfg.contextPrefix);
|
|
493
518
|
const prev = zcodeSessionQueues.get(sessionId) ?? Promise.resolve();
|
|
494
519
|
|
|
495
520
|
let succeeded = false;
|