@seamnet/client 0.3.5 → 0.3.7
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/lib/guardian.js +9 -1
- package/lib/mcp-server.cjs +2 -2
- package/lib/plugins/im.cjs +9 -5
- package/package.json +1 -1
package/lib/guardian.js
CHANGED
|
@@ -33,11 +33,17 @@ export async function guardianStart() {
|
|
|
33
33
|
// Ensure logs dir
|
|
34
34
|
if (!existsSync(LOGS_DIR)) mkdirSync(LOGS_DIR, { recursive: true });
|
|
35
35
|
|
|
36
|
+
// Detect CC's tmux session for message injection
|
|
37
|
+
let ccSession = '';
|
|
38
|
+
try {
|
|
39
|
+
ccSession = execSync("tmux display-message -p '#S'", { encoding: 'utf8' }).trim();
|
|
40
|
+
} catch {}
|
|
41
|
+
|
|
36
42
|
// Start guardian in tmux — use local node_modules path
|
|
37
43
|
const cwd = process.cwd();
|
|
38
44
|
const localCli = join(cwd, 'node_modules', '@seamnet', 'client', 'bin', 'cli.js');
|
|
39
45
|
execSync(
|
|
40
|
-
`tmux new-session -d -s ${sessionName} 'cd ${cwd} && node ${localCli} guardian run 2>&1 | tee -a ${join(LOGS_DIR, 'guardian.log')}'`,
|
|
46
|
+
`tmux new-session -d -s ${sessionName} 'cd ${cwd} && SEAM_CC_SESSION=${ccSession} node ${localCli} guardian run 2>&1 | tee -a ${join(LOGS_DIR, 'guardian.log')}'`,
|
|
41
47
|
{ stdio: 'inherit' }
|
|
42
48
|
);
|
|
43
49
|
|
|
@@ -60,10 +66,12 @@ export async function guardianRun() {
|
|
|
60
66
|
const { createRequire } = await import('node:module');
|
|
61
67
|
const require = createRequire(import.meta.url);
|
|
62
68
|
const { createImPlugin } = require('./plugins/im.cjs');
|
|
69
|
+
const ccSession = process.env.SEAM_CC_SESSION || '';
|
|
63
70
|
const imPlugin = await createImPlugin({
|
|
64
71
|
credentials: creds,
|
|
65
72
|
socketPath: SOCKET_PATH,
|
|
66
73
|
seamDir: SEAM_DIR,
|
|
74
|
+
ccSession,
|
|
67
75
|
});
|
|
68
76
|
|
|
69
77
|
console.log(`[guardian] Running. Socket: ${SOCKET_PATH}`);
|
package/lib/mcp-server.cjs
CHANGED
|
@@ -51,7 +51,7 @@ const rl = readline.createInterface({ input: process.stdin });
|
|
|
51
51
|
const tools = [
|
|
52
52
|
{
|
|
53
53
|
name: 'msg_send_im',
|
|
54
|
-
description: '
|
|
54
|
+
description: '发送 Seam 私聊消息。当终端出现 💬 [Seam] 开头的消息时,用此工具回复。终端里直接跟你对话的人不走 Seam,直接回复即可。',
|
|
55
55
|
inputSchema: {
|
|
56
56
|
type: 'object',
|
|
57
57
|
properties: {
|
|
@@ -63,7 +63,7 @@ const tools = [
|
|
|
63
63
|
},
|
|
64
64
|
{
|
|
65
65
|
name: 'msg_send_group',
|
|
66
|
-
description: '
|
|
66
|
+
description: '发送 Seam 群消息。当终端出现 💬 [Seam群] 开头的消息时,用此工具回复。',
|
|
67
67
|
inputSchema: {
|
|
68
68
|
type: 'object',
|
|
69
69
|
properties: {
|
package/lib/plugins/im.cjs
CHANGED
|
@@ -52,7 +52,7 @@ if (!Module.prototype._imPatched) {
|
|
|
52
52
|
};
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
function createImPlugin({ credentials, socketPath, seamDir }) {
|
|
55
|
+
function createImPlugin({ credentials, socketPath, seamDir, ccSession }) {
|
|
56
56
|
return new Promise((resolve) => {
|
|
57
57
|
const SDK_APP_ID = Number(credentials.sdkAppId);
|
|
58
58
|
const USER_ID = credentials.userId;
|
|
@@ -108,8 +108,8 @@ function createImPlugin({ credentials, socketPath, seamDir }) {
|
|
|
108
108
|
if (!text) continue;
|
|
109
109
|
|
|
110
110
|
const isGroup = msg.conversationType === TencentCloudChat.TYPES.CONV_GROUP;
|
|
111
|
-
const prefix = isGroup ? '💬
|
|
112
|
-
const line = `${prefix}
|
|
111
|
+
const prefix = isGroup ? '💬 [Seam群]' : '💬 [Seam]';
|
|
112
|
+
const line = `${prefix} ${msg.from}: ${text}`;
|
|
113
113
|
|
|
114
114
|
console.log(`[im-plugin] ${line}`);
|
|
115
115
|
injectToTerminal(line);
|
|
@@ -117,11 +117,15 @@ function createImPlugin({ credentials, socketPath, seamDir }) {
|
|
|
117
117
|
});
|
|
118
118
|
|
|
119
119
|
function injectToTerminal(text) {
|
|
120
|
+
if (!ccSession) {
|
|
121
|
+
console.error('[im-plugin] inject skipped: no CC session configured');
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
120
124
|
try {
|
|
121
125
|
const { execFileSync } = require('child_process');
|
|
122
|
-
// Use execFileSync to avoid shell injection — text is passed as argument, not shell-interpolated
|
|
123
126
|
const sanitized = text.replace(/[\x00-\x1f]/g, ' ').slice(0, 2000);
|
|
124
|
-
execFileSync('tmux', ['send-keys',
|
|
127
|
+
execFileSync('tmux', ['send-keys', '-t', ccSession, sanitized], { stdio: 'ignore', timeout: 5000 });
|
|
128
|
+
execFileSync('tmux', ['send-keys', '-t', ccSession, 'Enter'], { stdio: 'ignore', timeout: 5000 });
|
|
125
129
|
} catch (e) {
|
|
126
130
|
console.error(`[im-plugin] inject failed: ${e.message}`);
|
|
127
131
|
}
|