wechat-clawbot 0.9.7 → 0.9.9
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 +113 -3
- package/README.zh.md +98 -3
- package/lib/bridge.d.ts +22 -0
- package/lib/bridge.d.ts.map +1 -1
- package/lib/bridge.js +91 -4
- package/lib/bridge.js.map +1 -1
- package/lib/client.js +37 -5
- package/lib/codex-peer.d.ts +70 -0
- package/lib/codex-peer.d.ts.map +1 -0
- package/lib/codex-peer.js +324 -0
- package/lib/codex-peer.js.map +1 -0
- package/lib/codex-progress.d.ts +18 -0
- package/lib/codex-progress.d.ts.map +1 -0
- package/lib/codex-progress.js +25 -0
- package/lib/codex-progress.js.map +1 -0
- package/lib/codex-rpc.d.ts +49 -0
- package/lib/codex-rpc.d.ts.map +1 -0
- package/lib/codex-rpc.js +262 -0
- package/lib/codex-rpc.js.map +1 -0
- package/lib/config.d.ts +45 -0
- package/lib/config.d.ts.map +1 -1
- package/lib/config.js +32 -1
- package/lib/config.js.map +1 -1
- package/lib/idle-compact.d.ts +47 -0
- package/lib/idle-compact.d.ts.map +1 -0
- package/lib/idle-compact.js +129 -0
- package/lib/idle-compact.js.map +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +14 -1
- package/lib/index.js.map +1 -1
- package/lib/mcp-cli.d.ts +3 -0
- package/lib/mcp-cli.d.ts.map +1 -0
- package/lib/mcp-cli.js +29 -0
- package/lib/mcp-cli.js.map +1 -0
- package/lib/mcp-route.d.ts +4 -1
- package/lib/mcp-route.d.ts.map +1 -1
- package/lib/mcp-route.js +33 -9
- package/lib/mcp-route.js.map +1 -1
- package/lib/mcp-server.d.ts +13 -0
- package/lib/mcp-server.d.ts.map +1 -0
- package/lib/mcp-server.js +117 -0
- package/lib/mcp-server.js.map +1 -0
- package/lib/pending.d.ts +2 -0
- package/lib/pending.d.ts.map +1 -1
- package/lib/pending.js +4 -0
- package/lib/pending.js.map +1 -1
- package/lib/prompt.js +1 -1
- package/lib/workspace-instructions.d.ts +59 -0
- package/lib/workspace-instructions.d.ts.map +1 -0
- package/lib/workspace-instructions.js +67 -0
- package/lib/workspace-instructions.js.map +1 -0
- package/package.json +9 -3
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/** Standard stdio MCP facade over the plugin's authenticated, local HTTP routes. */
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
import { CODEX_PROGRESS_STATES } from "./codex-progress.js";
|
|
7
|
+
import { resolveStateDir } from "./ilink/storage/state-dir.js";
|
|
8
|
+
export class ClawbotMcpClient {
|
|
9
|
+
base;
|
|
10
|
+
tokenFile;
|
|
11
|
+
constructor(options = {}) {
|
|
12
|
+
this.base = new URL(options.url ?? process.env.CLAWBOT_DSH_URL ?? "http://127.0.0.1:3080");
|
|
13
|
+
if (!['http:', 'https:'].includes(this.base.protocol)
|
|
14
|
+
|| !["127.0.0.1", "localhost", "[::1]"].includes(this.base.hostname)
|
|
15
|
+
|| this.base.username || this.base.password || this.base.search || this.base.hash || this.base.pathname !== "/") {
|
|
16
|
+
throw new Error("CLAWBOT_DSH_URL must be a loopback HTTP(S) origin without credentials, a path, or a query");
|
|
17
|
+
}
|
|
18
|
+
this.tokenFile = options.tokenFile ?? process.env.CLAWBOT_MCP_TOKEN_FILE ?? path.join(resolveStateDir(), "mcp-token");
|
|
19
|
+
}
|
|
20
|
+
async request(route, body, query) {
|
|
21
|
+
let token;
|
|
22
|
+
try {
|
|
23
|
+
token = (await readFile(this.tokenFile, "utf8")).trim();
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
throw new Error("Cannot read the MCP bridge token. Start DSH or configure CLAWBOT_MCP_TOKEN_FILE.");
|
|
27
|
+
}
|
|
28
|
+
if (!token)
|
|
29
|
+
throw new Error("MCP bridge token is empty; start DSH first");
|
|
30
|
+
const url = new URL(`/plugins/clawbot/mcp/${route}`, this.base);
|
|
31
|
+
if (query)
|
|
32
|
+
url.search = query.toString();
|
|
33
|
+
const waitMs = typeof body?.waitMs === "number" ? body.waitMs : 120_000;
|
|
34
|
+
const response = await fetch(url, {
|
|
35
|
+
method: body === undefined ? "GET" : "POST",
|
|
36
|
+
headers: { authorization: `Bearer ${token}`, ...(body === undefined ? {} : { "content-type": "application/json" }) },
|
|
37
|
+
...(body === undefined ? {} : { body: JSON.stringify(body) }),
|
|
38
|
+
// Never forward the local secret to a redirected endpoint.
|
|
39
|
+
redirect: "error",
|
|
40
|
+
signal: AbortSignal.timeout(body?.waitForReply === true ? Math.min(600_000, waitMs) + 5_000 : 30_000),
|
|
41
|
+
});
|
|
42
|
+
const result = await response.json();
|
|
43
|
+
if (!response.ok || result.ok !== true) {
|
|
44
|
+
throw new Error(`DSH bridge HTTP ${response.status}: ${typeof result.message === "string" ? result.message : "request failed"}`);
|
|
45
|
+
}
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
async wechatSession() {
|
|
49
|
+
const sessions = await this.request("sessions");
|
|
50
|
+
if (typeof sessions.wechatSessionId !== "string")
|
|
51
|
+
throw new Error("DSH plugin needs the Codex bridge update");
|
|
52
|
+
const history = await this.request("read", { sessionId: sessions.wechatSessionId, limit: 20 });
|
|
53
|
+
return { sessionId: sessions.wechatSessionId, messages: history.messages };
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
export function createClawbotMcpServer(client = new ClawbotMcpClient()) {
|
|
57
|
+
const server = new McpServer({ name: "wechat-clawbot", version: "1.0.0" });
|
|
58
|
+
const text = z.string().trim().min(1).max(32_000);
|
|
59
|
+
const sessionId = z.string().trim().min(1).max(256);
|
|
60
|
+
const readOnly = { readOnlyHint: true, destructiveHint: false, openWorldHint: false };
|
|
61
|
+
// Honest hints matter here: Codex decides from them whether to ask before a
|
|
62
|
+
// call. Driving a DSH agent can run commands outside Codex's sandbox, and a
|
|
63
|
+
// notification leaves the machine, so both must prompt. Only the progress
|
|
64
|
+
// report is a local, additive write.
|
|
65
|
+
const drives = { readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: true };
|
|
66
|
+
const messages = { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: true };
|
|
67
|
+
const records = { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false };
|
|
68
|
+
const call = async (operation) => {
|
|
69
|
+
try {
|
|
70
|
+
const result = await operation();
|
|
71
|
+
return { content: [{ type: "text", text: JSON.stringify(result) }], structuredContent: result };
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
return { isError: true, content: [{ type: "text", text: error instanceof Error ? error.message : "DSH bridge request failed" }] };
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
server.registerTool("dsh_list_sessions", {
|
|
78
|
+
description: "List DSH conversations and their live states. wechatSessionId identifies the conversation used by WeChat Clawbot.",
|
|
79
|
+
inputSchema: {}, annotations: readOnly,
|
|
80
|
+
}, () => call(() => client.request("sessions")));
|
|
81
|
+
server.registerTool("dsh_get_wechat_session", {
|
|
82
|
+
description: "Read the configured DSH WeChat conversation and recent text. Use it to understand messages received by Clawbot.",
|
|
83
|
+
inputSchema: {}, annotations: readOnly,
|
|
84
|
+
}, () => call(async () => ({ ok: true, ...await client.wechatSession() })));
|
|
85
|
+
server.registerTool("dsh_read_session", {
|
|
86
|
+
description: "Read recent text from a selected DSH conversation without starting any work.",
|
|
87
|
+
inputSchema: { sessionId, limit: z.number().int().min(1).max(200).optional() }, annotations: readOnly,
|
|
88
|
+
}, (args) => call(() => client.request("read", args)));
|
|
89
|
+
server.registerTool("dsh_send_to_session", {
|
|
90
|
+
description: "Send a user-authorized message to a selected live DSH conversation. This drives that conversation; it does not send a WeChat notification. List sessions first.",
|
|
91
|
+
inputSchema: {
|
|
92
|
+
sessionId, text, waitForReply: z.boolean().optional(), waitMs: z.number().int().min(1_000).max(600_000).optional(),
|
|
93
|
+
}, annotations: drives,
|
|
94
|
+
}, (args) => call(() => client.request("send", args)));
|
|
95
|
+
server.registerTool("dsh_notify_wechat", {
|
|
96
|
+
description: "Send one user-authorized text notification to the QR-linked WeChat owner. The recipient is fixed. A Codex-labelled copy is recorded in the DSH WeChat conversation.",
|
|
97
|
+
inputSchema: { text }, annotations: messages,
|
|
98
|
+
}, (args) => call(() => client.request("notify", { ...args, source: "Codex" })));
|
|
99
|
+
server.registerTool("dsh_report_codex_progress", {
|
|
100
|
+
description: "Publish current Codex task progress for DSH/Clawbot to query. Call at meaningful milestones and completion; use the selected Codex thread id. This stores a timestamped report and does not notify WeChat by itself.",
|
|
101
|
+
inputSchema: {
|
|
102
|
+
threadId: sessionId, state: z.enum(CODEX_PROGRESS_STATES), summary: z.string().trim().min(1).max(4_000),
|
|
103
|
+
cwd: z.string().min(1).max(4_096).optional(), turnId: sessionId.optional(),
|
|
104
|
+
}, annotations: records,
|
|
105
|
+
}, (args) => call(() => client.request("codex/report", args)));
|
|
106
|
+
server.registerTool("dsh_read_codex_progress", {
|
|
107
|
+
description: "Read the latest timestamped Codex progress reports held by Clawbot. Reports are cached observations; check updatedAt before calling a task currently running.",
|
|
108
|
+
inputSchema: { threadId: sessionId.optional() }, annotations: readOnly,
|
|
109
|
+
}, (args) => call(() => client.request("codex/progress", undefined, args.threadId ? new URLSearchParams({ threadId: args.threadId }) : undefined)));
|
|
110
|
+
server.registerResource("wechat-session", "clawbot://wechat-session", {
|
|
111
|
+
description: "The DSH conversation used by WeChat Clawbot and its recent messages", mimeType: "application/json",
|
|
112
|
+
}, async (uri) => ({
|
|
113
|
+
contents: [{ uri: uri.href, mimeType: "application/json", text: JSON.stringify(await client.wechatSession()) }],
|
|
114
|
+
}));
|
|
115
|
+
return server;
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=mcp-server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-server.js","sourceRoot":"","sources":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AAC,YAAY,CAAC,yBAAyB,EAAE;QAC7C,WAAW,EAAE,+JAA+J;QAC5K,WAAW,EAAE,EAAE,QAAQ,EAAE,SAAS,CAAC,QAAQ,EAAE,EAAE,EAAE,WAAW,EAAE,QAAQ;KACvE,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,gBAAgB,EAAE,SAAS,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,eAAe,CAAC,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;IACpJ,MAAM,CAAC,gBAAgB,CAAC,gBAAgB,EAAE,0BAA0B,EAAE;QACpE,WAAW,EAAE,qEAAqE,EAAE,QAAQ,EAAE,kBAAkB;KACjH,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC;QACjB,QAAQ,EAAE,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,IAAI,EAAE,QAAQ,EAAE,kBAAkB,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,MAAM,CAAC,aAAa,EAAE,CAAC,EAAE,CAAC;KAChH,CAAC,CAAC,CAAC;IACJ,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/lib/pending.d.ts
CHANGED
|
@@ -15,6 +15,8 @@ export declare class PendingRegistry {
|
|
|
15
15
|
push(answer: PendingAnswer): void;
|
|
16
16
|
/** Whether the bot is waiting for this sender to answer something. */
|
|
17
17
|
hasFor(sender: string): boolean;
|
|
18
|
+
/** How many interactions are waiting for an answer from anyone. */
|
|
19
|
+
get size(): number;
|
|
18
20
|
/** Pop the oldest pending interaction for a sender, if any. */
|
|
19
21
|
popFor(sender: string): PendingAnswer | undefined;
|
|
20
22
|
/**
|
package/lib/pending.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pending.d.ts","sourceRoot":"","sources":["../src/pending.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,aAAa;IAC5B,+EAA+E;IAC/E,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,6CAA6C;IAC7C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB;;;OAGG;IACH,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAC;CACzC;AAED,qBAAa,eAAe;IAC1B,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAuB;IAE7C,sCAAsC;IACtC,IAAI,CAAC,MAAM,EAAE,aAAa,GAAG,IAAI;IAIjC,sEAAsE;IACtE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;IAI/B,+DAA+D;IAC/D,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS;IAOjD;;;;OAIG;IACH,MAAM,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO;IAOtC,gFAAgF;IAChF,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAS9B,wDAAwD;IACxD,QAAQ,IAAI,IAAI;CAKjB"}
|
|
1
|
+
{"version":3,"file":"pending.d.ts","sourceRoot":"","sources":["../src/pending.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,aAAa;IAC5B,+EAA+E;IAC/E,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,6CAA6C;IAC7C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB;;;OAGG;IACH,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAC;CACzC;AAED,qBAAa,eAAe;IAC1B,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAuB;IAE7C,sCAAsC;IACtC,IAAI,CAAC,MAAM,EAAE,aAAa,GAAG,IAAI;IAIjC,sEAAsE;IACtE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;IAI/B,mEAAmE;IACnE,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,+DAA+D;IAC/D,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS;IAOjD;;;;OAIG;IACH,MAAM,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO;IAOtC,gFAAgF;IAChF,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAS9B,wDAAwD;IACxD,QAAQ,IAAI,IAAI;CAKjB"}
|
package/lib/pending.js
CHANGED
|
@@ -14,6 +14,10 @@ export class PendingRegistry {
|
|
|
14
14
|
hasFor(sender) {
|
|
15
15
|
return this.queue.some((a) => a.sender === sender);
|
|
16
16
|
}
|
|
17
|
+
/** How many interactions are waiting for an answer from anyone. */
|
|
18
|
+
get size() {
|
|
19
|
+
return this.queue.length;
|
|
20
|
+
}
|
|
17
21
|
/** Pop the oldest pending interaction for a sender, if any. */
|
|
18
22
|
popFor(sender) {
|
|
19
23
|
const index = this.queue.findIndex((a) => a.sender === sender);
|
package/lib/pending.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pending.js","sourceRoot":"","sources":["../src/pending.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAchD,MAAM,OAAO,eAAe;IACT,KAAK,GAAoB,EAAE,CAAC;IAE7C,sCAAsC;IACtC,IAAI,CAAC,MAAqB;QACxB,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC1B,CAAC;IAED,sEAAsE;IACtE,MAAM,CAAC,MAAc;QACnB,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,MAAM,CAAC,CAAC;IACrD,CAAC;IAED,+DAA+D;IAC/D,MAAM,CAAC,MAAc;QACnB,MAAM,KAAK,GAAG,IAAI,CA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AAC,CAAC,CAAC;QAC5B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,gFAAgF;IAChF,QAAQ,CAAC,MAAc;QACrB,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;YACnD,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,KAAK,MAAM,EAAE,CAAC;gBACpC,MAAM,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;gBACzC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YACvB,CAAC;QACH,CAAC;IACH,CAAC;IAED,wDAAwD;IACxD,QAAQ;QACN,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QACjC,KAAK,MAAM,MAAM,IAAI,GAAG;YAAE,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAC/C,MAAM,CAAC,IAAI,CAAC,4BAA4B,GAAG,CAAC,MAAM,uBAAuB,CAAC,CAAC;IAC7E,CAAC;CACF"}
|
package/lib/prompt.js
CHANGED
|
@@ -219,7 +219,7 @@ G12 — 引用消息(用户引用之前的某条消息):
|
|
|
219
219
|
用户引用旧消息时,消息里会带"[引用: …]"前缀,内容是用户引用的旧消息。把它当作"用户针对那条旧消息提问"来处理:先理解被引用的内容,再回答当前问题。回复不要包含"[引用]"前缀本身。
|
|
220
220
|
|
|
221
221
|
G13 — 别的 agent 已经发给用户的消息:
|
|
222
|
-
对话里可能出现带"[Claude 发给用户的] …"
|
|
222
|
+
对话里可能出现带"[Claude 发给用户的] …"或"[Codex 发给用户的] …"前缀的条目。那是对应 agent 通过桥直接发到用户微信的消息,**用户已经收到了**。它只是给你补上下文,不是用户在跟你说话:
|
|
223
223
|
· **不要回复它**,也不要复述、总结或确认它。
|
|
224
224
|
· 不要重复发一遍它的内容 —— 用户看两遍会以为出了 bug。
|
|
225
225
|
· 但要记住它说了什么。用户接着说"那怎么办""按你说的做",指的很可能就是那条。
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Optionally keep DSH's workspace instruction files (AGENTS.md / CLAUDE.md)
|
|
3
|
+
* out of the WeChat session.
|
|
4
|
+
*
|
|
5
|
+
* The host's agent-instructions plugin splices a directory's instruction file
|
|
6
|
+
* into the conversation the first time a tool touches a file there — and the
|
|
7
|
+
* WHOLE file again every time it changes afterwards. A long developer notebook
|
|
8
|
+
* kept for a coding agent (30–40k characters) is the bad case: the bot runs one
|
|
9
|
+
* script in that project, then every later edit of the notebook — none of them
|
|
10
|
+
* the bot's business — adds another full copy, and in a long-lived chat
|
|
11
|
+
* ~140k characters end up riding along on every request.
|
|
12
|
+
*
|
|
13
|
+
* Off by config (`workspaceInstructions: false`), this session gets none of it;
|
|
14
|
+
* the owner keeps the knowledge on demand instead (e.g. a memory.md line telling
|
|
15
|
+
* the bot to read the relevant section before working there). On by default,
|
|
16
|
+
* because for someone else an AGENTS.md in the bot's working directory may be
|
|
17
|
+
* exactly how they instruct their bot. Other sessions (web, subagents) are
|
|
18
|
+
* never touched.
|
|
19
|
+
*
|
|
20
|
+
* Mechanism: an outermost `agent/pre-step` listener (`prepend`) runs after the
|
|
21
|
+
* agent-instructions listener and drops its messages — the ones it spliced into
|
|
22
|
+
* this step and the ones it parked in the next-step inbox. Best effort: any
|
|
23
|
+
* surprise leaves the host's decision exactly as it was.
|
|
24
|
+
*/
|
|
25
|
+
import type { Context } from "@deepseek-ai/cordis";
|
|
26
|
+
type SourceCarrier = {
|
|
27
|
+
id?: unknown;
|
|
28
|
+
source?: {
|
|
29
|
+
kind?: unknown;
|
|
30
|
+
changes?: unknown;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
/** A message the host's agent-instructions plugin produced. */
|
|
34
|
+
export declare function isWorkspaceInstructions(message: unknown): boolean;
|
|
35
|
+
type Inbox = {
|
|
36
|
+
nextStep?: readonly SourceCarrier[];
|
|
37
|
+
remove?: (id: unknown) => unknown;
|
|
38
|
+
};
|
|
39
|
+
type Decision = {
|
|
40
|
+
kind?: unknown;
|
|
41
|
+
messages?: unknown;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Remove workspace-instruction messages from one pre-step decision and from the
|
|
45
|
+
* agent's next-step inbox. Returns the decision to use and what was dropped.
|
|
46
|
+
*/
|
|
47
|
+
export declare function stripWorkspaceInstructions(agent: {
|
|
48
|
+
inbox?: Inbox;
|
|
49
|
+
}, decision: Decision): {
|
|
50
|
+
decision: Decision;
|
|
51
|
+
dropped: string[];
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Install the filter. `shouldStrip(agentId)` decides per step, so the config
|
|
55
|
+
* switch takes effect on the next step without a restart.
|
|
56
|
+
*/
|
|
57
|
+
export declare function registerWorkspaceInstructionsFilter(ctx: Context, shouldStrip: (agentId: string) => boolean): void;
|
|
58
|
+
export {};
|
|
59
|
+
//# sourceMappingURL=workspace-instructions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workspace-instructions.d.ts","sourceRoot":"","sources":["../src/workspace-instructions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAGnD,KAAK,aAAa,GAAG;IAAE,EAAE,CAAC,EAAE,OAAO,CAAC;IAAC,MAAM,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,OAAO,CAAC;QAAC,OAAO,CAAC,EAAE,OAAO,CAAA;KAAE,CAAA;CAAE,CAAC;AAEtF,+DAA+D;AAC/D,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAEjE;AAUD,KAAK,KAAK,GAAG;IAAE,QAAQ,CAAC,EAAE,SAAS,aAAa,EAAE,CAAC;IAAC,MAAM,CAAC,EAAE,CAAC,EAAE,EAAE,OAAO,KAAK,OAAO,CAAA;CAAE,CAAC;AACxF,KAAK,QAAQ,GAAG;IAAE,IAAI,CAAC,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAEvD;;;GAGG;AACH,wBAAgB,0BAA0B,CACxC,KAAK,EAAE;IAAE,KAAK,CAAC,EAAE,KAAK,CAAA;CAAE,EACxB,QAAQ,EAAE,QAAQ,GACjB;IAAE,QAAQ,EAAE,QAAQ,CAAC;IAAC,OAAO,EAAE,MAAM,EAAE,CAAA;CAAE,CAiB3C;AAID;;;GAGG;AACH,wBAAgB,mCAAmC,CACjD,GAAG,EAAE,OAAO,EACZ,WAAW,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,GACxC,IAAI,CA0BN"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { logger } from "./ilink/util/logger.js";
|
|
2
|
+
/** A message the host's agent-instructions plugin produced. */
|
|
3
|
+
export function isWorkspaceInstructions(message) {
|
|
4
|
+
return message?.source?.kind === "agent-instructions";
|
|
5
|
+
}
|
|
6
|
+
/** The instruction files a message carries, for the log line (no content). */
|
|
7
|
+
function scopesOf(message) {
|
|
8
|
+
const changes = Array.isArray(message.source?.changes) ? message.source.changes : [];
|
|
9
|
+
return changes
|
|
10
|
+
.map((c) => (typeof c.scope === "string" ? c.scope.replace(/\u0000/g, "/") : ""))
|
|
11
|
+
.filter((s) => s.length > 0);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Remove workspace-instruction messages from one pre-step decision and from the
|
|
15
|
+
* agent's next-step inbox. Returns the decision to use and what was dropped.
|
|
16
|
+
*/
|
|
17
|
+
export function stripWorkspaceInstructions(agent, decision) {
|
|
18
|
+
const dropped = [];
|
|
19
|
+
const inbox = agent.inbox;
|
|
20
|
+
if (inbox?.nextStep !== undefined && typeof inbox.remove === "function") {
|
|
21
|
+
for (const message of inbox.nextStep.filter(isWorkspaceInstructions)) {
|
|
22
|
+
inbox.remove(message.id);
|
|
23
|
+
dropped.push(...scopesOf(message));
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (decision.kind === "reject" || !Array.isArray(decision.messages))
|
|
27
|
+
return { decision, dropped };
|
|
28
|
+
const kept = decision.messages.filter((m) => {
|
|
29
|
+
if (!isWorkspaceInstructions(m))
|
|
30
|
+
return true;
|
|
31
|
+
dropped.push(...scopesOf(m));
|
|
32
|
+
return false;
|
|
33
|
+
});
|
|
34
|
+
if (kept.length === decision.messages.length)
|
|
35
|
+
return { decision, dropped };
|
|
36
|
+
return { decision: { ...decision, messages: kept }, dropped };
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Install the filter. `shouldStrip(agentId)` decides per step, so the config
|
|
40
|
+
* switch takes effect on the next step without a restart.
|
|
41
|
+
*/
|
|
42
|
+
export function registerWorkspaceInstructionsFilter(ctx, shouldStrip) {
|
|
43
|
+
const on = ctx.on;
|
|
44
|
+
let lastLogged = "";
|
|
45
|
+
on.call(ctx, "agent/pre-step", async (args, next) => {
|
|
46
|
+
const decision = await next();
|
|
47
|
+
try {
|
|
48
|
+
const agent = args?.agent;
|
|
49
|
+
if (agent === undefined || typeof agent.id !== "string" || !shouldStrip(agent.id))
|
|
50
|
+
return decision;
|
|
51
|
+
const result = stripWorkspaceInstructions(agent, decision);
|
|
52
|
+
if (result.dropped.length > 0) {
|
|
53
|
+
const files = [...new Set(result.dropped)].join(", ") || "(unnamed)";
|
|
54
|
+
if (files !== lastLogged) {
|
|
55
|
+
lastLogged = files;
|
|
56
|
+
logger.info(`workspace-instructions: kept ${files} out of the WeChat session (workspaceInstructions: false)`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return result.decision;
|
|
60
|
+
}
|
|
61
|
+
catch (err) {
|
|
62
|
+
logger.warn(`workspace-instructions: filter skipped: ${String(err)}`);
|
|
63
|
+
return decision;
|
|
64
|
+
}
|
|
65
|
+
}, { prepend: true });
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=workspace-instructions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workspace-instructions.js","sourceRoot":"","sources":["../src/workspace-instructions.ts"],"names":[],"mappings":"AAyBA,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAIhD,+DAA+D;AAC/D,MAAM,UAAU,uBAAuB,CAAC,OAAgB;IACtD,OAAQ,OAAgC,EAAE,MAAM,EAAE,IAAI,KAAK,oBAAoB,CAAC;AAClF,CAAC;AAED,8EAA8E;AAC9E,SAAS,QAAQ,CAAC,OAAsB;IACtC,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;IACrF,OAAO,OAAO;SACX,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,OAAQ,CAAyB,CAAC,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAE,CAAuB,CAAC,KAAK,CAAC,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;SAChI,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AACjC,CAAC;AAKD;;;GAGG;AACH,MAAM,UAAU,0BAA0B,CACxC,KAAwB,EACxB,QAAkB;IAElB,MAAM,OAAO,GAAa,EAAE,CAAC;IAC7B,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;IAC1B,IAAI,KAAK,EAAE,QAAQ,KAAK,SAAS,IAAI,OAAO,KAAK,CAAC,MAAM,KAAK,UAAU,EAAE,CAAC;QACxE,KAAK,MAAM,OAAO,IAAI,KA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EAAE,KAAK,CAAC;YAC1B,IAAI,KAAK,KAAK,SAAS,IAAI,OAAO,KAAK,CAAC,EAAE,KAAK,QAAQ,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE,CAAC;gBAAE,OAAO,QAAQ,CAAC;YACnG,MAAM,MAAM,GAAG,0BAA0B,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;YAC3D,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBAC9B,MAAM,KAAK,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,WAAW,CAAC;gBACrE,IAAI,KAAK,KAAK,UAAU,EAAE,CAAC;oBACzB,UAAU,GAAG,KAAK,CAAC;oBACnB,MAAM,CAAC,IAAI,CAAC,gCAAgC,KAAK,2DAA2D,CAAC,CAAC;gBAChH,CAAC;YACH,CAAC;YACD,OAAO,MAAM,CAAC,QAAQ,CAAC;QACzB,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,CAAC,IAAI,CAAC,2CAA2C,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;YACtE,OAAO,QAAQ,CAAC;QAClB,CAAC;IACH,CAAC,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;AACxB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wechat-clawbot",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.9",
|
|
4
4
|
"description": "Connect DeepSeek Harness to WeChat via the official WeChat ClawBot (Tencent iLink) bridge — a DSH plugin bundle.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"deepseek-harness",
|
|
@@ -37,7 +37,8 @@
|
|
|
37
37
|
"./client": "./lib/client.js"
|
|
38
38
|
},
|
|
39
39
|
"bin": {
|
|
40
|
-
"clawbot": "lib/cli.js"
|
|
40
|
+
"clawbot": "lib/cli.js",
|
|
41
|
+
"clawbot-mcp": "lib/mcp-cli.js"
|
|
41
42
|
},
|
|
42
43
|
"files": [
|
|
43
44
|
"lib",
|
|
@@ -54,6 +55,7 @@
|
|
|
54
55
|
"scripts": {
|
|
55
56
|
"build": "tsc -p tsconfig.json && cp -f src/client.js lib/client.js",
|
|
56
57
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
58
|
+
"test:codex": "npm run build && node --test test/codex-bridge.mjs",
|
|
57
59
|
"clean": "rm -rf lib",
|
|
58
60
|
"test:memory": "npm run build && node test/memory-eval-run.mjs"
|
|
59
61
|
},
|
|
@@ -71,7 +73,10 @@
|
|
|
71
73
|
},
|
|
72
74
|
"ilink_appid": "bot",
|
|
73
75
|
"dependencies": {
|
|
74
|
-
"
|
|
76
|
+
"@modelcontextprotocol/sdk": "^1.32.1",
|
|
77
|
+
"qrcode-terminal": "^0.12.0",
|
|
78
|
+
"ws": "^8.22.0",
|
|
79
|
+
"zod": "^4.4.3"
|
|
75
80
|
},
|
|
76
81
|
"peerDependencies": {
|
|
77
82
|
"@deepseek-ai/cordis": "^4.0.4",
|
|
@@ -94,6 +99,7 @@
|
|
|
94
99
|
"@deepseek-ai/dsh-user-questions": "0.2.0-rc.2",
|
|
95
100
|
"@deepseek-ai/schemastery": "3.18.4",
|
|
96
101
|
"@types/node": "^24.0.0",
|
|
102
|
+
"@types/ws": "^8.18.2",
|
|
97
103
|
"typescript": "^5.8.0"
|
|
98
104
|
}
|
|
99
105
|
}
|