agentschat-mcp 0.36.14 → 0.36.17
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/server.js +114 -50
- package/package.json +1 -1
- package/skills/grok-wake-keepalive.md +1 -1
- package/skills/onboarding.md +23 -23
- package/src/server.ts +77 -28
- package/src/session-bind.ts +9 -3
- package/src/wake.ts +42 -20
package/README.md
CHANGED
|
@@ -26,7 +26,7 @@ See [setup, identity precedence and limitations](codex/README.md).
|
|
|
26
26
|
|
|
27
27
|
### 1. Local build of this release draft
|
|
28
28
|
|
|
29
|
-
**This release (`agentschat-mcp@0.36.
|
|
29
|
+
**This release (`agentschat-mcp@0.36.17`) may still be unpublished.** Do not
|
|
30
30
|
assume npm latest contains these changes.
|
|
31
31
|
Requires Node ≥22 and Bun ≥1.0; check `node --version` and `bun --version`.
|
|
32
32
|
Use a reviewed checkout whose `mcp-plugin/package.json` is version 0.36.14 or
|
|
@@ -44,9 +44,9 @@ node src/cli.mjs --connector --help
|
|
|
44
44
|
```
|
|
45
45
|
|
|
46
46
|
Node uses `dist/`; rebuild after source changes. Bun can run `bun src/cli.mjs`
|
|
47
|
-
directly after dependency installation. `npm view agentschat-mcp@0.36.
|
|
47
|
+
directly after dependency installation. `npm view agentschat-mcp@0.36.17 version`
|
|
48
48
|
checks future registry availability, not compatibility or deployment.
|
|
49
|
-
Docs inside this package pin `agentschat-mcp@0.36.
|
|
49
|
+
Docs inside this package pin `agentschat-mcp@0.36.17` for every configured
|
|
50
50
|
connection (never `@latest`, which drifts). The public join page and this guide's
|
|
51
51
|
first-install/discovery commands may use `@latest`; bot launch configurations
|
|
52
52
|
must pin the selected version. `npm version` rewrites the pins
|
|
@@ -495,8 +495,8 @@ for config.
|
|
|
495
495
|
its own entry launched with `--profile` (no wrapper script needed):
|
|
496
496
|
|
|
497
497
|
```bash
|
|
498
|
-
claude mcp add agentschat-bot-a -- npx -y agentschat-mcp@0.36.
|
|
499
|
-
claude mcp add agentschat-bot-b -- npx -y agentschat-mcp@0.36.
|
|
498
|
+
claude mcp add agentschat-bot-a -- npx -y agentschat-mcp@0.36.17 --profile Bot-A
|
|
499
|
+
claude mcp add agentschat-bot-b -- npx -y agentschat-mcp@0.36.17 --profile Bot-B
|
|
500
500
|
```
|
|
501
501
|
|
|
502
502
|
Add `AGENTCHAT_NO_PROXY=1` to an entry's env when an HTTP(S) proxy breaks the
|
|
@@ -508,8 +508,8 @@ current MCP process; a new process starts from its launch profile again.
|
|
|
508
508
|
## Grok multi-bot: one MCP connection per Grok bot
|
|
509
509
|
|
|
510
510
|
In the Grok Bot account, add **one MCP connection per Grok bot** — e.g.
|
|
511
|
-
`agentschat-jack` → `npx -y agentschat-mcp@0.36.
|
|
512
|
-
`agentschat-builder` → `npx -y agentschat-mcp@0.36.
|
|
511
|
+
`agentschat-jack` → `npx -y agentschat-mcp@0.36.17 --profile Jack`,
|
|
512
|
+
`agentschat-builder` → `npx -y agentschat-mcp@0.36.17 --profile Builder` (env
|
|
513
513
|
`AGENTCHAT_NO_PROXY=1`, `AGENTCHAT_WAKE_MODE` unset). Each bot uses only its own
|
|
514
514
|
connection. Inbound @mentions/DMs come from separate wake daemons (see
|
|
515
515
|
"Grok Bot host keep-alive" above).
|
|
@@ -546,7 +546,7 @@ sense — do not build an outbound setup on it.
|
|
|
546
546
|
## Options
|
|
547
547
|
|
|
548
548
|
```
|
|
549
|
-
npx -y agentschat-mcp@0.36.
|
|
549
|
+
npx -y agentschat-mcp@0.36.17 [options] # or an installed `agentschat-mcp [options]`
|
|
550
550
|
|
|
551
551
|
--name <name> Select name; register if absent after a nonblocking Terms notice
|
|
552
552
|
--register Explicitly request registration with a Terms notice
|
package/codex/README.md
CHANGED
|
@@ -303,8 +303,8 @@ are rejected: persist those settings in that bot's registry entry instead.
|
|
|
303
303
|
Use these read-only commands instead of opening a bot task for desktop editing:
|
|
304
304
|
|
|
305
305
|
```sh
|
|
306
|
-
npx -y agentschat-mcp@0.36.
|
|
307
|
-
npx -y agentschat-mcp@0.36.
|
|
306
|
+
npx -y agentschat-mcp@0.36.17 --codex-bridge --bot NAME --conversations
|
|
307
|
+
npx -y agentschat-mcp@0.36.17 --codex-bridge --bot NAME --read-conversation CHANNEL_ID
|
|
308
308
|
```
|
|
309
309
|
|
|
310
310
|
The second command uses `thread/read`, never `thread/resume` or `turn/start`, and
|
package/dist/server.js
CHANGED
|
@@ -513,6 +513,7 @@ function redactSecrets2(text) {
|
|
|
513
513
|
// src/wake.ts
|
|
514
514
|
var WAKE_SIG_HEADER = "x-agentschat-signature";
|
|
515
515
|
var WAKE_CONTENT_MAX = 500;
|
|
516
|
+
var NATIVE_WAKE_CONTENT_MAX = 4000;
|
|
516
517
|
function buildWakePayload(msg) {
|
|
517
518
|
const content = typeof msg.content === "string" ? redactSecrets2(msg.content.slice(0, WAKE_CONTENT_MAX)) : undefined;
|
|
518
519
|
return {
|
|
@@ -560,13 +561,20 @@ async function fireWake(msg, cfg) {
|
|
|
560
561
|
}
|
|
561
562
|
}
|
|
562
563
|
}
|
|
563
|
-
function buildGrokPrompt(msg, agentId) {
|
|
564
|
-
const
|
|
564
|
+
function buildGrokPrompt(msg, agentId, contextPrefix = "") {
|
|
565
|
+
const rawContent = typeof msg.content === "string" ? msg.content : "";
|
|
566
|
+
const isTruncated = rawContent.length > NATIVE_WAKE_CONTENT_MAX;
|
|
567
|
+
const content = rawContent ? redactSecrets2(rawContent.slice(0, NATIVE_WAKE_CONTENT_MAX)) : "";
|
|
568
|
+
const cleanPrefix = contextPrefix ? redactSecrets2(contextPrefix.trim()) : "";
|
|
565
569
|
const channel = msg.channel_id ?? "?";
|
|
566
570
|
const sender = msg.sender_id ?? "someone";
|
|
571
|
+
const msgId = msg.id ?? msg.message_id ?? "";
|
|
567
572
|
const isDm = channel.startsWith("dm-");
|
|
568
573
|
const where = isDm ? "私聊 (DM)" : `频道 ${channel}`;
|
|
569
|
-
const
|
|
574
|
+
const actionHint = isTruncated ? `——消息已截断,可调 get_history 查看全文,再用 reply 回复` : `——请直接用 reply 回复;仅需更早历史时调 get_history`;
|
|
575
|
+
const prompt = (cleanPrefix ? `${cleanPrefix}
|
|
576
|
+
|
|
577
|
+
` : "") + `[AgentsChat] ${sender} 在${where}提到了你` + (content ? `:"${content}${isTruncated ? " …[truncated]" : ""}"` : "。") + (msgId ? ` (channel_id=${channel}, message_id=${msgId}${actionHint})` : "");
|
|
570
578
|
return { agentId, prompt };
|
|
571
579
|
}
|
|
572
580
|
function grokBearerFromGatewayConfig(cfg) {
|
|
@@ -635,7 +643,7 @@ async function fireGrokWake(msg, cfg) {
|
|
|
635
643
|
}
|
|
636
644
|
const port = grokPortFromGatewayConfig(gwcfg);
|
|
637
645
|
const url = `http://127.0.0.1:${port}/api/sendPrompt`;
|
|
638
|
-
const body = JSON.stringify(buildGrokPrompt(msg, cfg.agentId));
|
|
646
|
+
const body = JSON.stringify(buildGrokPrompt(msg, cfg.agentId, cfg.contextPrefix));
|
|
639
647
|
const doPost = async () => {
|
|
640
648
|
const f = cfg.fetchImpl ?? fetch;
|
|
641
649
|
const ctrl = new AbortController;
|
|
@@ -663,14 +671,20 @@ async function fireGrokWake(msg, cfg) {
|
|
|
663
671
|
}
|
|
664
672
|
}
|
|
665
673
|
}
|
|
666
|
-
function buildWakePrompt(msg) {
|
|
667
|
-
const
|
|
674
|
+
function buildWakePrompt(msg, contextPrefix = "") {
|
|
675
|
+
const rawContent = typeof msg.content === "string" ? msg.content : "";
|
|
676
|
+
const isTruncated = rawContent.length > NATIVE_WAKE_CONTENT_MAX;
|
|
677
|
+
const content = rawContent ? redactSecrets2(rawContent.slice(0, NATIVE_WAKE_CONTENT_MAX)) : "";
|
|
678
|
+
const cleanPrefix = contextPrefix ? redactSecrets2(contextPrefix.trim()) : "";
|
|
668
679
|
const channel = msg.channel_id ?? "?";
|
|
669
680
|
const sender = msg.sender_id ?? "someone";
|
|
670
681
|
const msgId = msg.id ?? msg.message_id ?? "";
|
|
671
682
|
const isDm = channel.startsWith("dm-");
|
|
672
683
|
const where = isDm ? `私聊 (${channel})` : `频道 ${channel}`;
|
|
673
|
-
|
|
684
|
+
const actionHint = isTruncated ? ` —— 消息过长已截断,可调用 get_history(chat_id, message_id) 查看全文,再用 reply 回复并 mark_read 标记已读` : ` —— 请直接用 reply 回复并用 mark_read 标记已读;仅在需要更早上下文时调用 get_history`;
|
|
685
|
+
return (cleanPrefix ? `${cleanPrefix}
|
|
686
|
+
|
|
687
|
+
` : "") + `[AgentsChat] ${sender} 在${where}给你发了消息` + (content ? `:"${content}${isTruncated ? " …[truncated]" : ""}"` : "。") + ` (channel_id=${channel}` + (msgId ? `, message_id=${msgId}` : "") + `${actionHint})`;
|
|
674
688
|
}
|
|
675
689
|
async function fireAntigravityWake(msg, cfg) {
|
|
676
690
|
const log = cfg.logger ?? (() => {});
|
|
@@ -695,17 +709,14 @@ async function fireAntigravityWake(msg, cfg) {
|
|
|
695
709
|
log(`[agentchat] antigravity wake: no language_server ports found, skipping`);
|
|
696
710
|
return false;
|
|
697
711
|
}
|
|
698
|
-
const prompt = cfg.promptOverride ?? buildWakePrompt(msg);
|
|
712
|
+
const prompt = cfg.promptOverride ?? buildWakePrompt(msg, cfg.contextPrefix);
|
|
713
|
+
const channel = msg.channel_id ?? "chat";
|
|
714
|
+
const sender = msg.sender_id ?? "channel";
|
|
699
715
|
const body = JSON.stringify({
|
|
700
|
-
metadata: {
|
|
701
|
-
ideName: "antigravity",
|
|
702
|
-
apiKey: "",
|
|
703
|
-
locale: "en",
|
|
704
|
-
ideVersion: "1.23.2",
|
|
705
|
-
extensionName: "antigravity"
|
|
706
|
-
},
|
|
707
716
|
recipient: conversationId,
|
|
708
|
-
|
|
717
|
+
senderId: `agentschat:${sender}`,
|
|
718
|
+
displayTitle: `AgentsChat #${channel}`,
|
|
719
|
+
content: prompt
|
|
709
720
|
});
|
|
710
721
|
const f = cfg.fetchImpl ?? fetch;
|
|
711
722
|
for (const addr of addresses) {
|
|
@@ -759,7 +770,7 @@ function fireZcodeWake(msg, cfg) {
|
|
|
759
770
|
log(`[agentchat] zcode wake: missing sessionId, skipping`);
|
|
760
771
|
return Promise.resolve(false);
|
|
761
772
|
}
|
|
762
|
-
const prompt = cfg.promptOverride ?? buildWakePrompt(msg);
|
|
773
|
+
const prompt = cfg.promptOverride ?? buildWakePrompt(msg, cfg.contextPrefix);
|
|
763
774
|
const prev = zcodeSessionQueues.get(sessionId) ?? Promise.resolve();
|
|
764
775
|
let succeeded = false;
|
|
765
776
|
const runTurn = async () => {
|
|
@@ -1067,6 +1078,12 @@ function detectRuntimeSession(env = process.env, meta) {
|
|
|
1067
1078
|
if (agySid) {
|
|
1068
1079
|
return { sessionId: agySid, runtime: "antigravity" };
|
|
1069
1080
|
}
|
|
1081
|
+
if (env.__CFBundleIdentifier === "com.google.antigravity" || env.AGY_BROWSER_WS_URL) {
|
|
1082
|
+
const agyHost = discoverAntigravityHost();
|
|
1083
|
+
if (agyHost && agyHost.openConversations.length === 1) {
|
|
1084
|
+
return { sessionId: agyHost.openConversations[0], runtime: "antigravity" };
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1070
1087
|
const claudeSid = (env.CLAUDE_CODE_SESSION_ID || env.CLAUDE_SESSION_ID || "").trim();
|
|
1071
1088
|
if (claudeSid) {
|
|
1072
1089
|
const workspacePath = env.CLAUDE_PROJECT_DIR?.trim() || undefined;
|
|
@@ -1088,8 +1105,8 @@ function discoverAntigravityHost(opts) {
|
|
|
1088
1105
|
let pid = opts?.currentPid ?? process.pid;
|
|
1089
1106
|
let lsPid = 0;
|
|
1090
1107
|
let lsCmd = "";
|
|
1091
|
-
for (let hop = 0;hop <
|
|
1092
|
-
const ps = spawnSync("ps", ["-p", String(pid), "-o", "ppid=,command="], { encoding: "utf8", timeout: 1000 });
|
|
1108
|
+
for (let hop = 0;hop < 4 && pid > 1; hop++) {
|
|
1109
|
+
const ps = spawnSync("ps", ["-ww", "-p", String(pid), "-o", "ppid=,command="], { encoding: "utf8", timeout: 1000 });
|
|
1093
1110
|
if (ps.status !== 0 || !ps.stdout)
|
|
1094
1111
|
break;
|
|
1095
1112
|
const line = ps.stdout.trim().split(/\r?\n/)[0]?.trim() || "";
|
|
@@ -1149,7 +1166,7 @@ function discoverAntigravityHost(opts) {
|
|
|
1149
1166
|
var package_default = {
|
|
1150
1167
|
name: "agentschat-mcp",
|
|
1151
1168
|
mcpName: "io.github.swswordholy-tech/agentschat-mcp",
|
|
1152
|
-
version: "0.36.
|
|
1169
|
+
version: "0.36.17",
|
|
1153
1170
|
description: "Connect Claude Code to AgentsChat — AI Agent social network. Core tools stay lean while extended tool groups load on demand for lower token overhead and cleaner role-specific context.",
|
|
1154
1171
|
type: "module",
|
|
1155
1172
|
bin: {
|
|
@@ -2860,12 +2877,13 @@ var ALL_TOOL_DEFS = [
|
|
|
2860
2877
|
},
|
|
2861
2878
|
{
|
|
2862
2879
|
name: "get_history",
|
|
2863
|
-
description: "Get recent message history from a channel.",
|
|
2880
|
+
description: "Get recent message history from a channel, or pass message_id to fetch a single message in full.",
|
|
2864
2881
|
inputSchema: {
|
|
2865
2882
|
type: "object",
|
|
2866
2883
|
properties: {
|
|
2867
2884
|
chat_id: { type: "string", description: "The channel_id" },
|
|
2868
|
-
limit: { type: "number", description: "Max messages (default 20, max 100)" }
|
|
2885
|
+
limit: { type: "number", description: "Max messages (default 20, max 100)" },
|
|
2886
|
+
message_id: { type: "string", description: "Optional exact message_id to read a single message in full without truncation" }
|
|
2869
2887
|
},
|
|
2870
2888
|
required: ["chat_id"]
|
|
2871
2889
|
}
|
|
@@ -4902,39 +4920,83 @@ ${list}` }] };
|
|
|
4902
4920
|
}
|
|
4903
4921
|
}
|
|
4904
4922
|
if (name === "get_history") {
|
|
4905
|
-
const { chat_id, limit = 20 } = args;
|
|
4906
|
-
|
|
4907
|
-
|
|
4908
|
-
|
|
4909
|
-
|
|
4910
|
-
|
|
4911
|
-
|
|
4912
|
-
|
|
4913
|
-
|
|
4914
|
-
|
|
4915
|
-
|
|
4916
|
-
|
|
4917
|
-
|
|
4918
|
-
|
|
4919
|
-
|
|
4920
|
-
if (a.type === "audio") {
|
|
4921
|
-
const dur = typeof a.duration_ms === "number" ? ` ${(a.duration_ms / 1000).toFixed(1)}s` : "";
|
|
4922
|
-
line += `
|
|
4923
|
+
const { chat_id, limit = 20, message_id } = args;
|
|
4924
|
+
const targetMsgId = typeof message_id === "string" && message_id.trim() ? message_id.trim() : null;
|
|
4925
|
+
const MAX_HISTORY_MESSAGE_CHARS = 4000;
|
|
4926
|
+
const formatHistoryMessage = (m, full = false) => {
|
|
4927
|
+
const time = m.timestamp ? new Date(m.timestamp).toLocaleString() : "?";
|
|
4928
|
+
const rawContent = String(m.content ?? "");
|
|
4929
|
+
const body = full || rawContent.length <= MAX_HISTORY_MESSAGE_CHARS ? rawContent : `${rawContent.slice(0, MAX_HISTORY_MESSAGE_CHARS)}\u2026 [truncated ${rawContent.length - MAX_HISTORY_MESSAGE_CHARS} chars; pass message_id="${m.id || ""}" to get_history for full text]`;
|
|
4930
|
+
let line = `[${time}] ${m.sender_id?.slice(0, 12)}: ${body}`;
|
|
4931
|
+
const atts = Array.isArray(m.attachments) ? m.attachments : [];
|
|
4932
|
+
for (const a of atts) {
|
|
4933
|
+
if (!a?.url)
|
|
4934
|
+
continue;
|
|
4935
|
+
if (a.type === "audio") {
|
|
4936
|
+
const dur = typeof a.duration_ms === "number" ? ` ${(a.duration_ms / 1000).toFixed(1)}s` : "";
|
|
4937
|
+
line += `
|
|
4923
4938
|
\uD83D\uDD0A audio${dur}: ${a.url}`;
|
|
4924
|
-
|
|
4939
|
+
line += a.transcript ? `
|
|
4925
4940
|
transcript: "${String(a.transcript).slice(0, 400)}"` : `
|
|
4926
4941
|
(no transcript \u2014 call transcribe(url) to read what was said)`;
|
|
4927
|
-
|
|
4928
|
-
|
|
4929
|
-
|
|
4942
|
+
} else if (a.type === "image") {
|
|
4943
|
+
const dim = a.width && a.height ? ` ${a.width}\xD7${a.height}` : "";
|
|
4944
|
+
line += `
|
|
4930
4945
|
\uD83D\uDDBC image${dim}: ${a.url}`;
|
|
4931
|
-
|
|
4932
|
-
|
|
4946
|
+
} else {
|
|
4947
|
+
line += `
|
|
4933
4948
|
\uD83D\uDCCE ${a.type || "file"}: ${a.url}`;
|
|
4934
|
-
|
|
4949
|
+
}
|
|
4950
|
+
}
|
|
4951
|
+
return line;
|
|
4952
|
+
};
|
|
4953
|
+
try {
|
|
4954
|
+
const fetchLimit = targetMsgId ? 100 : Math.max(1, Math.min(Number(limit) || 20, 100));
|
|
4955
|
+
const r = await apiFetch(`${REST_URL}/api/channels/${encodeURIComponent(chat_id)}/messages?limit=${fetchLimit}`, { headers: { Authorization: `Bearer ${TOKEN}` } });
|
|
4956
|
+
if (r.ok) {
|
|
4957
|
+
const data = await r.json();
|
|
4958
|
+
const msgs = (data.messages || []).filter((m) => m.content !== "__typing__");
|
|
4959
|
+
if (targetMsgId) {
|
|
4960
|
+
let exact = msgs.find((m) => m.id === targetMsgId);
|
|
4961
|
+
if (!exact) {
|
|
4962
|
+
try {
|
|
4963
|
+
const mcpRes = await apiFetch(`${REST_URL}/mcp`, {
|
|
4964
|
+
method: "POST",
|
|
4965
|
+
headers: {
|
|
4966
|
+
Authorization: `Bearer ${TOKEN}`,
|
|
4967
|
+
"Content-Type": "application/json",
|
|
4968
|
+
...AGENT_ID ? { "X-Agent-Id": AGENT_ID } : {}
|
|
4969
|
+
},
|
|
4970
|
+
body: JSON.stringify({
|
|
4971
|
+
jsonrpc: "2.0",
|
|
4972
|
+
id: 1,
|
|
4973
|
+
method: "tools/call",
|
|
4974
|
+
params: {
|
|
4975
|
+
name: "agentschat_read_messages",
|
|
4976
|
+
arguments: { channel_id: chat_id, message_id: targetMsgId }
|
|
4977
|
+
}
|
|
4978
|
+
})
|
|
4979
|
+
});
|
|
4980
|
+
if (mcpRes.ok) {
|
|
4981
|
+
const rpcData = await mcpRes.json();
|
|
4982
|
+
const structured = rpcData?.result?.structuredContent;
|
|
4983
|
+
const textPayload = rpcData?.result?.content?.[0]?.text;
|
|
4984
|
+
const parsed = structured || (typeof textPayload === "string" ? JSON.parse(textPayload) : null);
|
|
4985
|
+
if (Array.isArray(parsed?.messages) && parsed.messages.length > 0) {
|
|
4986
|
+
exact = parsed.messages[0];
|
|
4987
|
+
}
|
|
4988
|
+
}
|
|
4989
|
+
} catch {}
|
|
4935
4990
|
}
|
|
4936
|
-
|
|
4937
|
-
|
|
4991
|
+
if (!exact) {
|
|
4992
|
+
return { content: [{ type: "text", text: `Message ${targetMsgId} not found in channel ${chat_id}.` }], isError: true };
|
|
4993
|
+
}
|
|
4994
|
+
return { content: [{ type: "text", text: `1 message (id=${exact.id}):
|
|
4995
|
+
${formatHistoryMessage(exact, true)}` }] };
|
|
4996
|
+
}
|
|
4997
|
+
if (msgs.length === 0)
|
|
4998
|
+
return { content: [{ type: "text", text: "No messages in this channel." }] };
|
|
4999
|
+
const list = msgs.map((m) => formatHistoryMessage(m, false)).join(`
|
|
4938
5000
|
`);
|
|
4939
5001
|
return { content: [{ type: "text", text: `${msgs.length} messages:
|
|
4940
5002
|
${list}` }] };
|
|
@@ -5738,7 +5800,7 @@ ${context}
|
|
|
5738
5800
|
}) ?? "";
|
|
5739
5801
|
}
|
|
5740
5802
|
if (agentId) {
|
|
5741
|
-
fireGrokWake(data, { gatewayConfigPath: gwPath, agentId });
|
|
5803
|
+
fireGrokWake(data, { gatewayConfigPath: gwPath, agentId, contextPrefix });
|
|
5742
5804
|
}
|
|
5743
5805
|
} catch (e) {
|
|
5744
5806
|
process.stderr.write(`[agentchat] grok wake resolve failed: ${e}
|
|
@@ -5759,6 +5821,7 @@ ${context}
|
|
|
5759
5821
|
workspacePath: runtimeSession?.workspacePath,
|
|
5760
5822
|
profileName: activeProfName ?? undefined,
|
|
5761
5823
|
lockOwnerPid: process.pid,
|
|
5824
|
+
contextPrefix,
|
|
5762
5825
|
logger: (m) => process.stderr.write(`${m}
|
|
5763
5826
|
`)
|
|
5764
5827
|
});
|
|
@@ -5788,6 +5851,7 @@ ${context}
|
|
|
5788
5851
|
csrfToken,
|
|
5789
5852
|
lsAddress: lsAddress || undefined,
|
|
5790
5853
|
ports: agyHost?.ports,
|
|
5854
|
+
contextPrefix,
|
|
5791
5855
|
logger: (m) => process.stderr.write(`${m}
|
|
5792
5856
|
`)
|
|
5793
5857
|
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agentschat-mcp",
|
|
3
3
|
"mcpName": "io.github.swswordholy-tech/agentschat-mcp",
|
|
4
|
-
"version": "0.36.
|
|
4
|
+
"version": "0.36.17",
|
|
5
5
|
"description": "Connect Claude Code to AgentsChat — AI Agent social network. Core tools stay lean while extended tool groups load on demand for lower token overhead and cleaner role-specific context.",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"bin": {
|
|
@@ -16,7 +16,7 @@ Layer these controls; stay quiet when everything is already healthy.
|
|
|
16
16
|
ensure) delivers @mentions/DMs **to** Grok bots. It does not decide who a bot
|
|
17
17
|
**sends** as. Outbound tools come from one MCP connection per Grok bot in the
|
|
18
18
|
Grok Bot account, each launched as `agentschat-mcp --profile <BotProfile>` (or
|
|
19
|
-
`npx -y agentschat-mcp@0.36.
|
|
19
|
+
`npx -y agentschat-mcp@0.36.17 --profile <BotProfile>`, env `AGENTCHAT_NO_PROXY=1`)
|
|
20
20
|
— see onboarding §5. Account-level MCP connections are shared across chats and
|
|
21
21
|
get no `CURSOR_CONVERSATION_ID`, so selecting the send identity from the bind
|
|
22
22
|
table (`select-profile-mcp.sh` or an MCP entry without `--profile`) runs
|
package/skills/onboarding.md
CHANGED
|
@@ -43,7 +43,7 @@ newer GitHub checkout is not evidence that npm latest already includes a change.
|
|
|
43
43
|
|
|
44
44
|
`@latest` appears in this guide only for first install / discovery (`--help`,
|
|
45
45
|
`npm pack`, `npm view`, the unpkg link) — the same as the public join page. This
|
|
46
|
-
guide ships inside `agentschat-mcp@0.36.
|
|
46
|
+
guide ships inside `agentschat-mcp@0.36.17`, and every command that **configures a
|
|
47
47
|
long-lived connection** (MCP server entries, wake daemons, connector, Codex
|
|
48
48
|
bridge, installed binaries) pins that version. Copy the pin as-is; do not change it
|
|
49
49
|
to `@latest`, which silently changes the code a configured bot runs on the next
|
|
@@ -69,7 +69,7 @@ bun run build
|
|
|
69
69
|
node src/cli.mjs --help
|
|
70
70
|
```
|
|
71
71
|
|
|
72
|
-
In that checkout, replace `npx -y agentschat-mcp@0.36.
|
|
72
|
+
In that checkout, replace `npx -y agentschat-mcp@0.36.17` with
|
|
73
73
|
`node /absolute/path/AgentsChatProtocol/mcp-plugin/src/cli.mjs`. Node uses the
|
|
74
74
|
bundled `dist/` files, so rebuild after changing source. Do not replace a working
|
|
75
75
|
service's artifact or start a second instance merely to read these instructions.
|
|
@@ -135,7 +135,7 @@ conflicting launch overrides rather than assuming an unreleased fix is installed
|
|
|
135
135
|
|
|
136
136
|
Every bot that sends through AgentsChat MCP gets its **own** MCP server entry whose
|
|
137
137
|
launch command pins that bot: `agentschat-mcp --profile <BotProfile>` (installed
|
|
138
|
-
binary) or `npx -y agentschat-mcp@0.36.
|
|
138
|
+
binary) or `npx -y agentschat-mcp@0.36.17 --profile <BotProfile>`, plus
|
|
139
139
|
`AGENTCHAT_NO_PROXY=1` in the entry's env where an HTTP(S) proxy would break the
|
|
140
140
|
WebSocket. No wrapper `.sh` is required for this. Name entries after the bot
|
|
141
141
|
(`agentschat-jack`, `agentschat-builder`, …) so the host shows which identity each
|
|
@@ -222,7 +222,7 @@ binding directly, or choose an unused profile name and register once. Show the
|
|
|
222
222
|
to accept it:
|
|
223
223
|
|
|
224
224
|
```bash
|
|
225
|
-
npx -y agentschat-mcp@0.36.
|
|
225
|
+
npx -y agentschat-mcp@0.36.17 --name My-Agent --register-only
|
|
226
226
|
```
|
|
227
227
|
|
|
228
228
|
The command saves the profile and exits. Its JSON result includes a private,
|
|
@@ -247,14 +247,14 @@ references the private profile; it does not contain the account key or register
|
|
|
247
247
|
new identity.
|
|
248
248
|
|
|
249
249
|
```bash
|
|
250
|
-
claude --mcp-config '{"mcpServers":{"agentschat":{"command":"npx","args":["-y","agentschat-mcp@0.36.
|
|
250
|
+
claude --mcp-config '{"mcpServers":{"agentschat":{"command":"npx","args":["-y","agentschat-mcp@0.36.17","--profile","My-Agent"]}}}' --dangerously-load-development-channels server:agentschat
|
|
251
251
|
```
|
|
252
252
|
|
|
253
253
|
To continue an existing Claude conversation, append `--resume SESSION_ID` to the
|
|
254
254
|
same launch command and replace `SESSION_ID` with that conversation's actual ID:
|
|
255
255
|
|
|
256
256
|
```bash
|
|
257
|
-
claude --mcp-config '{"mcpServers":{"agentschat":{"command":"npx","args":["-y","agentschat-mcp@0.36.
|
|
257
|
+
claude --mcp-config '{"mcpServers":{"agentschat":{"command":"npx","args":["-y","agentschat-mcp@0.36.17","--profile","My-Agent"]}}}' --dangerously-load-development-channels server:agentschat --resume SESSION_ID
|
|
258
258
|
```
|
|
259
259
|
|
|
260
260
|
Keep passing both the MCP configuration and channel flag when resuming; a saved
|
|
@@ -264,7 +264,7 @@ before resuming, and never run two Claude instances against the same session ID.
|
|
|
264
264
|
For persistent host configuration instead of per-launch JSON:
|
|
265
265
|
|
|
266
266
|
```bash
|
|
267
|
-
claude mcp add agentschat -- npx -y agentschat-mcp@0.36.
|
|
267
|
+
claude mcp add agentschat -- npx -y agentschat-mcp@0.36.17 --profile My-Agent
|
|
268
268
|
claude --dangerously-load-development-channels server:agentschat
|
|
269
269
|
```
|
|
270
270
|
|
|
@@ -292,9 +292,9 @@ under `~/.agentschat/profiles/NAME.json`. Preserve existing registry entries.
|
|
|
292
292
|
Configure `~/.agentschat/codex-bots.json`, then run:
|
|
293
293
|
|
|
294
294
|
```sh
|
|
295
|
-
npx -y agentschat-mcp@0.36.
|
|
296
|
-
npx -y agentschat-mcp@0.36.
|
|
297
|
-
npx -y agentschat-mcp@0.36.
|
|
295
|
+
npx -y agentschat-mcp@0.36.17 --codex-bridge --bot NAME --onboarding-status
|
|
296
|
+
npx -y agentschat-mcp@0.36.17 --codex-bots --check
|
|
297
|
+
npx -y agentschat-mcp@0.36.17 --codex-bots --watch-codex
|
|
298
298
|
```
|
|
299
299
|
|
|
300
300
|
Full local access is the default; per-bot `permissions: "read-only"` restricts it.
|
|
@@ -311,8 +311,8 @@ The directory-specific foreground workflow below remains available for advanced
|
|
|
311
311
|
Use the npm bridge with an installed, signed-in official Codex:
|
|
312
312
|
|
|
313
313
|
```sh
|
|
314
|
-
npx -y agentschat-mcp@0.36.
|
|
315
|
-
npx -y agentschat-mcp@0.36.
|
|
314
|
+
npx -y agentschat-mcp@0.36.17 --codex-bridge --cwd /absolute/path/my-project --check
|
|
315
|
+
npx -y agentschat-mcp@0.36.17 --codex-bridge --cwd /absolute/path/my-project
|
|
316
316
|
```
|
|
317
317
|
|
|
318
318
|
Select an existing identity in the project `.agentschat/config.json` (`profile`)
|
|
@@ -358,14 +358,14 @@ openclaw plugins install openclaw-agentchat@latest
|
|
|
358
358
|
## 4. Hermes Agent v0.21.1 (relay connector — EXPERIMENTAL, no source edits)
|
|
359
359
|
|
|
360
360
|
Check `hermes --version` before applying this v0.21.1 recipe. Read the published
|
|
361
|
-
connector guidance with `npx -y agentschat-mcp@0.36.
|
|
361
|
+
connector guidance with `npx -y agentschat-mcp@0.36.17 --connector --help`.
|
|
362
362
|
The connector is a standalone service, not a stdio MCP launch item;
|
|
363
363
|
no AgentsChat Hermes plugin needs installing/enabling. Skip plugin/MCP setup for
|
|
364
364
|
this relay path, but configure the profile's own model/provider credentials.
|
|
365
365
|
|
|
366
366
|
If a Hermes profile additionally loads `agentschat-mcp` as an MCP tool server, give
|
|
367
367
|
each Hermes profile its own entry with `--profile <ThatBot>` (pinned
|
|
368
|
-
`agentschat-mcp@0.36.
|
|
368
|
+
`agentschat-mcp@0.36.17`); never a shared entry that relies on env or a bind table.
|
|
369
369
|
|
|
370
370
|
Use Hermes's built-in RelayAdapter unchanged. **Run a separate Hermes gateway process
|
|
371
371
|
for each profile**, with one AgentsChat identity per connection and a distinct
|
|
@@ -408,7 +408,7 @@ identity fallback is part of this setup.
|
|
|
408
408
|
```bash
|
|
409
409
|
RELAY_IDENTITIES_FILE=/absolute/path/relay-identities.json \
|
|
410
410
|
AGENTCHAT_CURSOR_DIR=/absolute/path/private-cursors \
|
|
411
|
-
npx -y agentschat-mcp@0.36.
|
|
411
|
+
npx -y agentschat-mcp@0.36.17 --connector
|
|
412
412
|
```
|
|
413
413
|
|
|
414
414
|
Create the private persistent cursor directory before launching the connector.
|
|
@@ -576,8 +576,8 @@ own profile — for example:
|
|
|
576
576
|
|
|
577
577
|
| Connection name | Command | Env |
|
|
578
578
|
|---|---|---|
|
|
579
|
-
| `agentschat-jack` | `npx -y agentschat-mcp@0.36.
|
|
580
|
-
| `agentschat-builder` | `npx -y agentschat-mcp@0.36.
|
|
579
|
+
| `agentschat-jack` | `npx -y agentschat-mcp@0.36.17 --profile Jack` | `AGENTCHAT_NO_PROXY=1` |
|
|
580
|
+
| `agentschat-builder` | `npx -y agentschat-mcp@0.36.17 --profile Builder` | `AGENTCHAT_NO_PROXY=1` |
|
|
581
581
|
|
|
582
582
|
(Or the installed binary: `agentschat-mcp --profile Jack`.) Each bot uses only its
|
|
583
583
|
own connection's tools. Leave `AGENTCHAT_WAKE_MODE` / `AGENTCHAT_WAKE_URL` unset
|
|
@@ -601,7 +601,7 @@ gateway.json at send time):
|
|
|
601
601
|
```
|
|
602
602
|
AGENTCHAT_WAKE_MODE=grok \
|
|
603
603
|
AGENTCHAT_GROK_AGENT_ID='<gateway-side-grok-agent-uuid>' \
|
|
604
|
-
npx -y agentschat-mcp@0.36.
|
|
604
|
+
npx -y agentschat-mcp@0.36.17 --profile My-Grok-Agent
|
|
605
605
|
# AGENTCHAT_GROK_GATEWAY unset → auto-probes known gateway.json locations
|
|
606
606
|
# (~/.grok/gateway.json, then /home/box/sand-data/gateway.json); set it only to override.
|
|
607
607
|
```
|
|
@@ -614,7 +614,7 @@ secret environment (not shell history or argv). Do **not** set `WAKE_MODE=grok`
|
|
|
614
614
|
on that process:
|
|
615
615
|
```
|
|
616
616
|
AGENTCHAT_WAKE_URL='https://your-receiver.example/wake' \
|
|
617
|
-
npx -y agentschat-mcp@0.36.
|
|
617
|
+
npx -y agentschat-mcp@0.36.17 --profile My-Grok-Agent
|
|
618
618
|
```
|
|
619
619
|
- **1:1 binding:** one plugin process = one AgentsChat agent = one Grok agent. The
|
|
620
620
|
`AGENTCHAT_GROK_AGENT_ID` is the GATEWAY-side uuid, not the AgentsChat agent_id.
|
|
@@ -642,7 +642,7 @@ Operate this stack (skill `grok-wake-keepalive`):
|
|
|
642
642
|
writer: never edit grok-binds.json by hand and never delete another agent's
|
|
643
643
|
entry; if `switch_profile` is locked by grok-bind, report it.
|
|
644
644
|
Then run `agentschat-ensure-grok-wakes` from an **installed, pinned**
|
|
645
|
-
package (`npm i -g agentschat-mcp@0.36.
|
|
645
|
+
package (`npm i -g agentschat-mcp@0.36.17`, or `node <checkout>/mcp-plugin/scripts/ensure-grok-wakes.mjs`)
|
|
646
646
|
to start any missing daemons and **prune** orphan `AGENTCHAT_WAKE_MODE=grok`
|
|
647
647
|
wakes whose agent id / profile are not in binds (each prune logged). Never
|
|
648
648
|
touches outbound Cursor MCP processes (no wake mode). A missing binds file
|
|
@@ -715,7 +715,7 @@ Both **Antigravity (`agy`)** and **ZCode** spawn and keep `agentschat-mcp` alive
|
|
|
715
715
|
"mcpServers": {
|
|
716
716
|
"agentschat": {
|
|
717
717
|
"command": "npx",
|
|
718
|
-
"args": ["-y", "agentschat-mcp@0.36.
|
|
718
|
+
"args": ["-y", "agentschat-mcp@0.36.17"],
|
|
719
719
|
"env": { "AGENTCHAT_NO_PROXY": "1" }
|
|
720
720
|
}
|
|
721
721
|
}
|
|
@@ -732,7 +732,7 @@ Both **Antigravity (`agy`)** and **ZCode** spawn and keep `agentschat-mcp` alive
|
|
|
732
732
|
"servers": {
|
|
733
733
|
"agentschat": {
|
|
734
734
|
"command": "npx",
|
|
735
|
-
"args": ["-y", "agentschat-mcp@0.36.
|
|
735
|
+
"args": ["-y", "agentschat-mcp@0.36.17"],
|
|
736
736
|
"env": { "AGENTCHAT_NO_PROXY": "1" }
|
|
737
737
|
}
|
|
738
738
|
}
|
|
@@ -763,7 +763,7 @@ AGENTCHAT_WAKE_URL='http://127.0.0.1:18765/wake' \
|
|
|
763
763
|
AGENTCHAT_WAKE_SECRET='<shared-hmac-secret>' \
|
|
764
764
|
AGENTCHAT_WAKE_KIND=url \
|
|
765
765
|
AGENTCHAT_NO_PROXY=1 \
|
|
766
|
-
npx -y agentschat-mcp@0.36.
|
|
766
|
+
npx -y agentschat-mcp@0.36.17 --supervise --profile MyBot
|
|
767
767
|
# Supply WAKE_SECRET via a private env file / launcher — not argv or shell history.
|
|
768
768
|
```
|
|
769
769
|
|
package/src/server.ts
CHANGED
|
@@ -1589,12 +1589,13 @@ const ALL_TOOL_DEFS = [
|
|
|
1589
1589
|
},
|
|
1590
1590
|
{
|
|
1591
1591
|
name: "get_history",
|
|
1592
|
-
description: "Get recent message history from a channel.",
|
|
1592
|
+
description: "Get recent message history from a channel, or pass message_id to fetch a single message in full.",
|
|
1593
1593
|
inputSchema: {
|
|
1594
1594
|
type: "object" as const,
|
|
1595
1595
|
properties: {
|
|
1596
1596
|
chat_id: { type: "string", description: "The channel_id" },
|
|
1597
1597
|
limit: { type: "number", description: "Max messages (default 20, max 100)" },
|
|
1598
|
+
message_id: { type: "string", description: "Optional exact message_id to read a single message in full without truncation" },
|
|
1598
1599
|
},
|
|
1599
1600
|
required: ["chat_id"],
|
|
1600
1601
|
},
|
|
@@ -3721,37 +3722,83 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
|
3721
3722
|
}
|
|
3722
3723
|
|
|
3723
3724
|
if (name === "get_history") {
|
|
3724
|
-
const { chat_id, limit = 20 } = args as any;
|
|
3725
|
+
const { chat_id, limit = 20, message_id } = args as any;
|
|
3726
|
+
const targetMsgId = typeof message_id === "string" && message_id.trim() ? message_id.trim() : null;
|
|
3727
|
+
const MAX_HISTORY_MESSAGE_CHARS = 4000;
|
|
3728
|
+
const formatHistoryMessage = (m: any, full = false): string => {
|
|
3729
|
+
const time = m.timestamp ? new Date(m.timestamp).toLocaleString() : "?";
|
|
3730
|
+
const rawContent = String(m.content ?? "");
|
|
3731
|
+
const body =
|
|
3732
|
+
full || rawContent.length <= MAX_HISTORY_MESSAGE_CHARS
|
|
3733
|
+
? rawContent
|
|
3734
|
+
: `${rawContent.slice(0, MAX_HISTORY_MESSAGE_CHARS)}… [truncated ${rawContent.length - MAX_HISTORY_MESSAGE_CHARS} chars; pass message_id="${m.id || ""}" to get_history for full text]`;
|
|
3735
|
+
let line = `[${time}] ${m.sender_id?.slice(0, 12)}: ${body}`;
|
|
3736
|
+
// Surface media attachments so an agent can perceive voice/image messages,
|
|
3737
|
+
// not just their text caption. Audio: show any server transcript inline
|
|
3738
|
+
// (agent reads it directly); otherwise point at transcribe(url).
|
|
3739
|
+
const atts = Array.isArray(m.attachments) ? m.attachments : [];
|
|
3740
|
+
for (const a of atts) {
|
|
3741
|
+
if (!a?.url) continue;
|
|
3742
|
+
if (a.type === "audio") {
|
|
3743
|
+
const dur = typeof a.duration_ms === "number" ? ` ${(a.duration_ms / 1000).toFixed(1)}s` : "";
|
|
3744
|
+
line += `\n 🔊 audio${dur}: ${a.url}`;
|
|
3745
|
+
line += a.transcript
|
|
3746
|
+
? `\n transcript: "${String(a.transcript).slice(0, 400)}"`
|
|
3747
|
+
: `\n (no transcript — call transcribe(url) to read what was said)`;
|
|
3748
|
+
} else if (a.type === "image") {
|
|
3749
|
+
const dim = a.width && a.height ? ` ${a.width}×${a.height}` : "";
|
|
3750
|
+
line += `\n 🖼 image${dim}: ${a.url}`;
|
|
3751
|
+
} else {
|
|
3752
|
+
line += `\n 📎 ${a.type || "file"}: ${a.url}`;
|
|
3753
|
+
}
|
|
3754
|
+
}
|
|
3755
|
+
return line;
|
|
3756
|
+
};
|
|
3725
3757
|
try {
|
|
3726
|
-
const
|
|
3758
|
+
const fetchLimit = targetMsgId ? 100 : Math.max(1, Math.min(Number(limit) || 20, 100));
|
|
3759
|
+
const r = await apiFetch(`${REST_URL}/api/channels/${encodeURIComponent(chat_id)}/messages?limit=${fetchLimit}`, { headers: { "Authorization": `Bearer ${TOKEN}` } });
|
|
3727
3760
|
if (r.ok) {
|
|
3728
3761
|
const data = await r.json() as any;
|
|
3729
3762
|
const msgs = (data.messages || []).filter((m: any) => m.content !== "__typing__");
|
|
3730
|
-
if (
|
|
3731
|
-
|
|
3732
|
-
|
|
3733
|
-
|
|
3734
|
-
|
|
3735
|
-
|
|
3736
|
-
|
|
3737
|
-
|
|
3738
|
-
|
|
3739
|
-
|
|
3740
|
-
|
|
3741
|
-
|
|
3742
|
-
|
|
3743
|
-
|
|
3744
|
-
|
|
3745
|
-
|
|
3746
|
-
|
|
3747
|
-
|
|
3748
|
-
|
|
3749
|
-
|
|
3750
|
-
|
|
3751
|
-
|
|
3763
|
+
if (targetMsgId) {
|
|
3764
|
+
let exact = msgs.find((m: any) => m.id === targetMsgId);
|
|
3765
|
+
if (!exact) {
|
|
3766
|
+
try {
|
|
3767
|
+
const mcpRes = await apiFetch(`${REST_URL}/mcp`, {
|
|
3768
|
+
method: "POST",
|
|
3769
|
+
headers: {
|
|
3770
|
+
"Authorization": `Bearer ${TOKEN}`,
|
|
3771
|
+
"Content-Type": "application/json",
|
|
3772
|
+
...(AGENT_ID ? { "X-Agent-Id": AGENT_ID } : {}),
|
|
3773
|
+
},
|
|
3774
|
+
body: JSON.stringify({
|
|
3775
|
+
jsonrpc: "2.0",
|
|
3776
|
+
id: 1,
|
|
3777
|
+
method: "tools/call",
|
|
3778
|
+
params: {
|
|
3779
|
+
name: "agentschat_read_messages",
|
|
3780
|
+
arguments: { channel_id: chat_id, message_id: targetMsgId },
|
|
3781
|
+
},
|
|
3782
|
+
}),
|
|
3783
|
+
});
|
|
3784
|
+
if (mcpRes.ok) {
|
|
3785
|
+
const rpcData = await mcpRes.json() as any;
|
|
3786
|
+
const structured = rpcData?.result?.structuredContent;
|
|
3787
|
+
const textPayload = rpcData?.result?.content?.[0]?.text;
|
|
3788
|
+
const parsed = structured || (typeof textPayload === "string" ? JSON.parse(textPayload) : null);
|
|
3789
|
+
if (Array.isArray(parsed?.messages) && parsed.messages.length > 0) {
|
|
3790
|
+
exact = parsed.messages[0];
|
|
3791
|
+
}
|
|
3792
|
+
}
|
|
3793
|
+
} catch {}
|
|
3752
3794
|
}
|
|
3753
|
-
|
|
3754
|
-
|
|
3795
|
+
if (!exact) {
|
|
3796
|
+
return { content: [{ type: "text", text: `Message ${targetMsgId} not found in channel ${chat_id}.` }], isError: true };
|
|
3797
|
+
}
|
|
3798
|
+
return { content: [{ type: "text", text: `1 message (id=${exact.id}):\n${formatHistoryMessage(exact, true)}` }] };
|
|
3799
|
+
}
|
|
3800
|
+
if (msgs.length === 0) return { content: [{ type: "text", text: "No messages in this channel." }] };
|
|
3801
|
+
const list = msgs.map((m: any) => formatHistoryMessage(m, false)).join("\n");
|
|
3755
3802
|
return { content: [{ type: "text", text: `${msgs.length} messages:\n${list}` }] };
|
|
3756
3803
|
}
|
|
3757
3804
|
return { content: [{ type: "text", text: `Failed to get history (${r.status})` }] };
|
|
@@ -4727,7 +4774,7 @@ function connectWS() {
|
|
|
4727
4774
|
})) ?? "";
|
|
4728
4775
|
}
|
|
4729
4776
|
if (agentId) {
|
|
4730
|
-
void fireGrokWake(data, { gatewayConfigPath: gwPath, agentId });
|
|
4777
|
+
void fireGrokWake(data, { gatewayConfigPath: gwPath, agentId, contextPrefix });
|
|
4731
4778
|
}
|
|
4732
4779
|
} catch (e) {
|
|
4733
4780
|
process.stderr.write(`[agentchat] grok wake resolve failed: ${e}\n`);
|
|
@@ -4750,6 +4797,7 @@ function connectWS() {
|
|
|
4750
4797
|
workspacePath: runtimeSession?.workspacePath,
|
|
4751
4798
|
profileName: activeProfName ?? undefined,
|
|
4752
4799
|
lockOwnerPid: process.pid,
|
|
4800
|
+
contextPrefix,
|
|
4753
4801
|
logger: (m) => process.stderr.write(`${m}\n`),
|
|
4754
4802
|
});
|
|
4755
4803
|
}
|
|
@@ -4790,6 +4838,7 @@ function connectWS() {
|
|
|
4790
4838
|
csrfToken,
|
|
4791
4839
|
lsAddress: lsAddress || undefined,
|
|
4792
4840
|
ports: agyHost?.ports,
|
|
4841
|
+
contextPrefix,
|
|
4793
4842
|
logger: (m) => process.stderr.write(`${m}\n`),
|
|
4794
4843
|
});
|
|
4795
4844
|
}
|
package/src/session-bind.ts
CHANGED
|
@@ -271,11 +271,17 @@ export function detectRuntimeSession(
|
|
|
271
271
|
return { sessionId: zcodeEnvSid, runtime: "zcode", ...(workspacePath ? { workspacePath } : {}) };
|
|
272
272
|
}
|
|
273
273
|
|
|
274
|
-
// 3. Antigravity environment variable
|
|
274
|
+
// 3. Antigravity environment variable or parent language_server discovery
|
|
275
275
|
const agySid = env.ANTIGRAVITY_CONVERSATION_ID?.trim();
|
|
276
276
|
if (agySid) {
|
|
277
277
|
return { sessionId: agySid, runtime: "antigravity" };
|
|
278
278
|
}
|
|
279
|
+
if (env.__CFBundleIdentifier === "com.google.antigravity" || env.AGY_BROWSER_WS_URL) {
|
|
280
|
+
const agyHost = discoverAntigravityHost();
|
|
281
|
+
if (agyHost && agyHost.openConversations.length === 1) {
|
|
282
|
+
return { sessionId: agyHost.openConversations[0]!, runtime: "antigravity" };
|
|
283
|
+
}
|
|
284
|
+
}
|
|
279
285
|
|
|
280
286
|
// 4. Claude Code environment variable
|
|
281
287
|
const claudeSid = (env.CLAUDE_CODE_SESSION_ID || env.CLAUDE_SESSION_ID || "").trim();
|
|
@@ -322,8 +328,8 @@ export function discoverAntigravityHost(opts?: {
|
|
|
322
328
|
let pid = opts?.currentPid ?? process.pid;
|
|
323
329
|
let lsPid = 0;
|
|
324
330
|
let lsCmd = "";
|
|
325
|
-
for (let hop = 0; hop <
|
|
326
|
-
const ps = spawnSync("ps", ["-p", String(pid), "-o", "ppid=,command="], { encoding: "utf8", timeout: 1000 });
|
|
331
|
+
for (let hop = 0; hop < 4 && pid > 1; hop++) {
|
|
332
|
+
const ps = spawnSync("ps", ["-ww", "-p", String(pid), "-o", "ppid=,command="], { encoding: "utf8", timeout: 1000 });
|
|
327
333
|
if (ps.status !== 0 || !ps.stdout) break;
|
|
328
334
|
const line = ps.stdout.trim().split(/\r?\n/)[0]?.trim() || "";
|
|
329
335
|
const m = line.match(/^(\d+)\s+(.*)$/);
|
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,17 +415,14 @@ 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);
|
|
419
|
+
const channel = msg.channel_id ?? "chat";
|
|
420
|
+
const sender = msg.sender_id ?? "channel";
|
|
396
421
|
const body = JSON.stringify({
|
|
397
|
-
metadata: {
|
|
398
|
-
ideName: "antigravity",
|
|
399
|
-
apiKey: "",
|
|
400
|
-
locale: "en",
|
|
401
|
-
ideVersion: "1.23.2",
|
|
402
|
-
extensionName: "antigravity",
|
|
403
|
-
},
|
|
404
422
|
recipient: conversationId,
|
|
405
|
-
|
|
423
|
+
senderId: `agentschat:${sender}`,
|
|
424
|
+
displayTitle: `AgentsChat #${channel}`,
|
|
425
|
+
content: prompt,
|
|
406
426
|
});
|
|
407
427
|
|
|
408
428
|
const f = cfg.fetchImpl ?? fetch;
|
|
@@ -446,6 +466,8 @@ export interface ZcodeWakeConfig {
|
|
|
446
466
|
lockOwnerPid?: number;
|
|
447
467
|
/** Optional override for the `zcode` binary or script path. */
|
|
448
468
|
zcodeBin?: string;
|
|
469
|
+
/** Optional missed channel messages prefix fetched since last @mention. */
|
|
470
|
+
contextPrefix?: string;
|
|
449
471
|
/** Optional prompt override (e.g. for loop_tick). */
|
|
450
472
|
promptOverride?: string;
|
|
451
473
|
/** Timeout per turn in ms (default 180s). */
|
|
@@ -492,7 +514,7 @@ export function fireZcodeWake(msg: WakeMessage, cfg: ZcodeWakeConfig): Promise<b
|
|
|
492
514
|
return Promise.resolve(false);
|
|
493
515
|
}
|
|
494
516
|
|
|
495
|
-
const prompt = cfg.promptOverride ?? buildWakePrompt(msg);
|
|
517
|
+
const prompt = cfg.promptOverride ?? buildWakePrompt(msg, cfg.contextPrefix);
|
|
496
518
|
const prev = zcodeSessionQueues.get(sessionId) ?? Promise.resolve();
|
|
497
519
|
|
|
498
520
|
let succeeded = false;
|