Skip to content

Commit 8742823

Browse files
committed
fix(minimax-bot): 紧贴中文的点名能点到了,模型写的字段和群里的回复也伪造不了上下文块
1 parent 32f6970 commit 8742823

8 files changed

Lines changed: 307 additions & 19 deletions

File tree

‎plugins/minimax-ai/minimax-bot/.minimax-plugin/plugin.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"schemaVersion": 1,
33
"name": "minimax-bot",
44
"displayName": "MiniMax Bot",
5-
"version": "0.7.12",
5+
"version": "0.7.13",
66
"description": "Turn MiniMax Code into an always-on team of Bots. A Chief Bot helps you build the team; in group chats the admin answers and @mentions hand work to other members. Every Bot has its own octopus avatar and memory, with scheduled tasks and usage stats.",
77
"author": "MiniMax Code",
88
"icon": "icon.png",

‎plugins/minimax-ai/minimax-bot/README.md‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Copy this directory, including the hidden `.minimax-plugin/` directory, into the
1212

1313
- **Long-lived Bots**: every Bot has a name, a role, instructions and its own Agent session. When its setup, the team roster or its memory changes, the next turn automatically carries the latest context.
1414
- **Chief Bot**: created on first launch to help you build your team. Chief can create, edit and delete Bots and groups; other Bots are refused when they try to do so.
15-
- **Group chats**: the group admin answers by default. `@Name` calls on a specific member, and a Bot that `@`-mentions another member in its reply hands the turn over. Members with nothing to add reply `[PASS]` and are skipped. Each member keeps a separate session per group, and groups cannot see private chats. There is no fixed reply cap by default; a group can set one in the group settings. A group can also keep a short note of what it said, which survives clearing the chat. Discussions finish naturally, or wait for more instructions after repeated handoffs without tool progress.
15+
- **Group chats**: the group admin answers by default. `@Name` calls on a specific member, and a Bot that `@`-mentions another member in its reply hands the turn over. The `@` needs no space in front of it, so `请@某人` calls that member. Members with nothing to add reply `[PASS]` and are skipped. Each member keeps a separate session per group, and groups cannot see private chats. There is no fixed reply cap by default; a group can set one in the group settings. A group can also keep a short note of what it said, which survives clearing the chat. Discussions finish naturally, or wait for more instructions after repeated handoffs without tool progress.
1616
- **Hand-offs between Bots**: `message_bot` hands work to another Bot and immediately returns an admission receipt; the completed result returns to the source chat. `post_group` is **private chat only**: it posts to a group and returns immediately while the discussion continues according to the group's reply mode. From a private chat, Chief can post to any group without joining it; other Bots can only post to groups they belong to. During a group turn, `post_group` is disabled for everyone, including Chief and admins, for both same-group and cross-group posts. Use `@Name` in a reply to hand off within the group; start cross-group work from a private chat.
1717
- **Background work**: when an isolated execution context is useful, a Bot calls `start_helper` to run it in the background in a fresh, separate session; the Bot's turn ends at once and you can keep chatting. The Bot simply says something like "let me look into it" without internal jargon or IDs. When the job finishes, its report comes back to the Bot as a new turn, and the Bot reviews it and passes it on in its own words (in groups too, where it can keep handing off with `@`). At most 2 background jobs run at once (one slot is always kept free for chat) and the rest queue; each Bot can have at most 4 queued or running. Running jobs are shown above the chat input and can be stopped at any time; the strip orders them by how far along they are, the ones already working first, then the ones waiting for another job, then the queued ones; when more than three jobs are listed, it keeps the first three in the open and folds the rest into one line that says how many are left, and one button below the rows opens the whole queue; tool approvals from a background job appear in its chat; jobs still running when the Mini App restarts are marked interrupted. Bots can also manage jobs with `list_helpers` / `stop_helper`. "Allow background helpers automatically" is on by default in Bot settings; when off, a Bot only does so when you explicitly ask.
1818
- **Per-Bot model and reasoning effort**: pick a model and reasoning effort in Bot settings (only the levels the model supports are listed, and thinking can be turned off where supported; Bots that follow the default model can still set their own effort). Chief can also set them with the `model` (a model ID, `provider/model` or display name; `default` follows the default) and `effort` (`low`, `high`, `off`, ...) parameters of `create_bot` / `update_bot`. Requires a MiniMax Code version with `agent.models()` / `run({ model })`; older versions prompt you to upgrade.
@@ -47,6 +47,11 @@ Copy this directory, including the hidden `.minimax-plugin/` directory, into the
4747
- A background job is an Agent turn like any other, so the usage panel counts it. Before, the panel showed fewer turns than the model actually ran: the job's own turn never reached the ledger, only the turn that relayed its report back.
4848
- The job's row carries the time it took, the tools it called and the reply it produced, and it says how the job ended: a job that failed is an error, one that was stopped or cut off is aborted.
4949

50+
## 0.7.13 A mention that reads like Chinese, and marks that stay out
51+
52+
- A mention works right after a Chinese word. The character in front of the `@` used to end the mention whenever it was a letter of any script, and Chinese has no spaces between words, so `请@某人` and `好的@某人` reached nobody. Only an ASCII letter, digit or underscore in front of the `@` ends it now, which is what the local part of an email address is made of. An address is still not a mention, a name that runs into more words (`@Alicex`) still is not one either, and English is unchanged: `mail@alice.com` and `ok@alice` reach nobody, while `@alice`, `@alice.` and `@Alice Smith` do.
53+
- A name, a role, a notice, an instruction or a memory entry cannot close a block of the plugin's own. Those travel into the standing brief of every Bot of the group and into the memory block, and a protocol mark in one of them used to close the block early and let the text after it read as if the plugin had written it. A reply in a group travels into the next Bot's prompt the same way, so a mark in it cannot open a block of its own there either. The marks go the way they go in a reply: out of the text, the words around them untouched.
54+
5055
## 0.7.11 The group note, cleaned up
5156

5257
- Switching the note off no longer hides what was recorded. The group settings keep showing the record and its **Clear** button while the record exists, and say that the switch is off. The record itself is kept until you clear it, so switching the note back on hands the same record to the Bots again.

‎plugins/minimax-ai/minimax-bot/miniapp/node/engine.mjs‎

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { selectMemoryContext } from './memory-context.mjs';
99
import { UserInbox } from './user-inbox.mjs';
1010
import { TaskDispatcher } from './task-dispatcher.mjs';
1111
import { modelKey, newId, withEffort } from './store.mjs';
12-
import { CONVERGE_MARK, CONTEXT_BLOCK_END, CONTEXT_BLOCK_MARK, handoverRequested, handoverSummary, hopLimit, renderHandover } from './relay-guard.mjs';
12+
import { CONVERGE_MARK, CONTEXT_BLOCK_END, CONTEXT_BLOCK_MARK, handoverRequested, handoverSummary, hopLimit, neutralizeMarks, renderHandover } from './relay-guard.mjs';
1313
import { appendNote, notesEnabled, renderNote } from './group-note.mjs';
1414

1515
/** @typedef {import('./miniapp-api.js').MiniAppAgentClient} MiniAppAgentClient */
@@ -18,6 +18,17 @@ import { appendNote, notesEnabled, renderNote } from './group-note.mjs';
1818
/** @typedef {import('./store.mjs').Store} Store */
1919
/** @typedef {import('./memory.mjs').MemoryStore} MemoryStore */
2020

21+
/**
22+
* A field a Bot (or the user) wrote: names, roles, notices and instructions travel into the
23+
* standing brief of every Bot of the group. A protocol mark in one of them would close the
24+
* brief's block early and let the rest of the text read as if the plugin had said it, so the
25+
* marks go the same way as in a reply: out of the text, the words around them untouched.
26+
* @param {unknown} value
27+
*/
28+
function clean(value) {
29+
return neutralizeMarks(String(value ?? ''));
30+
}
31+
2132
const TOP_LEVEL_SLOTS = 3; // Leave Host capacity while all chat and task turns share these slots.
2233
const GROUP_CONTEXT_MESSAGES = 30;
2334
const MESSAGE_CLIP = 4000;
@@ -252,15 +263,15 @@ export class Engine {
252263
roster() {
253264
const { bots, groups } = this.store.state;
254265
const botLines = bots.map((bot) =>
255-
t('brief.botLine', { name: bot.name, id: bot.id, main: bot.isMain ? t('brief.mainTag') : '', role: bot.role || t('brief.noRole') }),
266+
t('brief.botLine', { name: clean(bot.name), id: bot.id, main: bot.isMain ? t('brief.mainTag') : '', role: clean(bot.role) || t('brief.noRole') }),
256267
);
257268
const groupLines = groups.map((group) => {
258-
const admin = this.store.getBot(group.adminId)?.name ?? t('brief.none');
269+
const admin = clean(this.store.getBot(group.adminId)?.name) || t('brief.none');
259270
const members = group.memberIds
260-
.map((id) => this.store.getBot(id)?.name)
271+
.map((id) => clean(this.store.getBot(id)?.name))
261272
.filter(Boolean)
262273
.join(t('list.sep'));
263-
return t('brief.groupLine', { name: group.name, id: group.id, admin, members });
274+
return t('brief.groupLine', { name: clean(group.name), id: group.id, admin, members });
264275
});
265276
return { botLines, groupLines };
266277
}
@@ -316,7 +327,7 @@ export class Engine {
316327
// This build keeps no group notes, so the hand-over carries the tail of the reply.
317328
const text = handoverSummary({ note: '', reply: last.text });
318329
if (!text) return undefined;
319-
return { from: last.name, text };
330+
return { from: clean(last.name), text };
320331
}
321332

322333

@@ -405,17 +416,17 @@ export class Engine {
405416
const note = group ? renderNote(group) : '';
406417
const lines = [
407418
CONTEXT_BLOCK_MARK,
408-
t('brief.intro', { name: bot.name, id: bot.id }),
409-
bot.role ? t('brief.role', { role: bot.role }) : '',
419+
t('brief.intro', { name: clean(bot.name), id: bot.id }),
420+
bot.role ? t('brief.role', { role: clean(bot.role) }) : '',
410421
bot.isMain ? t('brief.mainPower') : '',
411422
'',
412423
t('brief.hInstructions'),
413-
bot.instructions?.trim() || t('brief.noInstructions'),
424+
clean(bot.instructions?.trim()) || t('brief.noInstructions'),
414425
'',
415426
t('brief.hChat'),
416427
group
417428
? [
418-
t('brief.inGroup', { name: group.name, notice: group.notice || t('brief.none') }),
429+
t('brief.inGroup', { name: clean(group.name), notice: clean(group.notice) || t('brief.none') }),
419430
isAdmin ? t('brief.groupAdmin') : t('brief.groupMember'),
420431
t('brief.groupPass'),
421432
t('brief.groupNoPost'),
@@ -1165,10 +1176,15 @@ export class Engine {
11651176
const members = group.memberIds.map((id) => this.store.getBot(id)).filter(Boolean)
11661177
.map((bot) => ({ id: bot.id, name: bot.name.toLowerCase() }))
11671178
.sort((a, b) => b.name.length - a.name.length);
1179+
// A word character of any script: it ends a name, so "Alicex" is not "Alice".
11681180
const isWord = (value) => Boolean(value && /[\p{L}\p{N}\p{M}_]/u.test(value));
1181+
// An ASCII word character is what makes an '@' part of a handle: the local part of an
1182+
// email address. Chinese has no spaces between words, so a character before the '@' is a
1183+
// word of its own there ("请@某人"), and it must not swallow the mention.
1184+
const isAsciiWord = (value) => Boolean(value && /[A-Za-z0-9_]/.test(value));
11691185
const found = [];
11701186
for (let index = lower.indexOf('@'); index >= 0; index = lower.indexOf('@', index + 1)) {
1171-
if (isWord(lower[index - 1])) continue;
1187+
if (isAsciiWord(lower[index - 1])) continue;
11721188
const member = members.find(({ name }) => lower.startsWith(name, index + 1) && !isWord(lower[index + 1 + name.length]));
11731189
if (!member) continue;
11741190
if (member.id !== excludeId && !found.includes(member.id)) found.push(member.id);
@@ -1330,14 +1346,17 @@ export class Engine {
13301346
: m.role === 'relay'
13311347
? m.fromName ?? t('bot.deleted')
13321348
: this.store.getBot(m.botId)?.name ?? t('bot.deleted');
1333-
return `[${who}] ${clip(m.role === 'user' ? agentTextOf(m.text, m.attachments) : m.text)}`;
1349+
// The text of a message in the group is text that rides along into the next Bot's
1350+
// prompt, and it comes from a reply or from a user. A protocol mark in it would let
1351+
// the text after it read as if the plugin had written it.
1352+
return `[${clean(who)}] ${clip(clean(m.role === 'user' ? agentTextOf(m.text, m.attachments) : m.text))}`;
13341353
});
13351354
const text = [
13361355
...head,
1337-
t('group.newMessages', { name: group.name }),
1356+
t('group.newMessages', { name: clean(group.name) }),
13381357
...(lines.length ? lines : [t('group.noNew')]),
13391358
'',
1340-
t('group.yourTurn', { name: bot.name }),
1359+
t('group.yourTurn', { name: clean(bot.name) }),
13411360
].join('\n');
13421361
const lastIncluded = recent.at(-1)?.seq ?? lastSeenSeq;
13431362
// Another member's streaming reply is not readable yet. Do not advance past that hole:

‎plugins/minimax-ai/minimax-bot/miniapp/node/mcp.mjs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ export function createMcpHandler({ team, engine }) {
586586
result = {
587587
protocolVersion: PROTOCOL_VERSIONS.includes(requested) ? requested : PROTOCOL_VERSIONS[0],
588588
capabilities: { tools: { listChanged: false } },
589-
serverInfo: { name: 'minimax-bot', version: '0.7.12' },
589+
serverInfo: { name: 'minimax-bot', version: '0.7.13' },
590590
instructions: t('mcp.instructions'),
591591
};
592592
break;

‎plugins/minimax-ai/minimax-bot/miniapp/node/memory-context.mjs‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// @ts-check
22
// Selection affects one prompt only. Storage and the caller's entries remain untouched.
3+
import { neutralizeMarks } from './relay-guard.mjs';
4+
35
export const MEMORY_CONTEXT_MAX = 6000;
46

57
function queryTerms(query) {
@@ -24,7 +26,11 @@ function relevance(entry, terms) {
2426
function serializeEntry(entry) {
2527
return JSON.stringify({
2628
scope: entry.scope, id: entry.id, key: entry.key ?? '', revision: entry.revision ?? '',
27-
pinned: Boolean(entry.pinned), text: entry.text,
29+
pinned: Boolean(entry.pinned),
30+
// A memory entry is written by a Bot (or by the user) and travels into the memory block of
31+
// every Bot that reads it. A protocol mark in it would close that block early, so the marks
32+
// go the way they go in a reply: out of the text, the words around them untouched.
33+
text: neutralizeMarks(String(entry.text ?? '')),
2834
});
2935
}
3036

‎plugins/minimax-ai/minimax-bot/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "minimax-bot",
3-
"version": "0.7.12",
3+
"version": "0.7.13",
44
"private": true,
55
"type": "module",
66
"mcode": {
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
// @ts-check
2+
// The "@" of a mention, read the way Chinese and English write it.
3+
//
4+
// A mention is "@" plus a member's name. Chinese has no spaces between words, so the character
5+
// in front of the "@" is a word of its own ("请@某人") and must not swallow the mention the way
6+
// it does in "mail@alice.com". What makes an "@" part of a handle is an ASCII word character in
7+
// front of it, so that is what the guard looks at. English keeps the old rule: an ASCII letter,
8+
// digit or underscore in front of the "@" still ends the mention, and the address, the longer
9+
// name and the name that runs into more words are all as they were.
10+
11+
import assert from 'node:assert/strict';
12+
import { test } from 'node:test';
13+
import { mkdtemp, rm } from 'node:fs/promises';
14+
import { tmpdir } from 'node:os';
15+
import { join } from 'node:path';
16+
17+
import { Store } from '../miniapp/node/store.mjs';
18+
import { MemoryStore } from '../miniapp/node/memory.mjs';
19+
import { Engine } from '../miniapp/node/engine.mjs';
20+
21+
async function fixture(t) {
22+
const dir = await mkdtemp(join(tmpdir(), 'bot-mention-'));
23+
const store = new Store(dir);
24+
const memory = new MemoryStore(dir);
25+
await store.init();
26+
await memory.init();
27+
const engine = new Engine({
28+
store, memory, logger: { warn() {} }, broadcast: () => {}, retryDelaysMs: [],
29+
});
30+
t.after(async () => {
31+
engine.dispose();
32+
await rm(dir, { recursive: true, force: true });
33+
});
34+
store.state.bots = [
35+
{ id: 'designer', name: '设计师' },
36+
{ id: 'alice', name: 'Alice' },
37+
{ id: 'alice_smith', name: 'Alice Smith' },
38+
{ id: 'bob', name: 'Bob' },
39+
];
40+
return { store, engine, group: { memberIds: ['designer', 'alice', 'alice_smith', 'bob'] } };
41+
}
42+
43+
test('a mention works right after a Chinese word, the way Chinese is written', async (t) => {
44+
const { engine, group } = await fixture(t);
45+
assert.deepEqual(engine.mentionsIn('@设计师,请回答。', group), ['designer']);
46+
assert.deepEqual(engine.mentionsIn('请@设计师,请回答。', group), ['designer']);
47+
assert.deepEqual(engine.mentionsIn('好的@设计师', group), ['designer']);
48+
assert.deepEqual(engine.mentionsIn('麻烦@设计师 看一下', group), ['designer']);
49+
assert.deepEqual(engine.mentionsIn('请 @设计师', group), ['designer']);
50+
// The same rule in the other scripts that write without spaces.
51+
assert.deepEqual(engine.mentionsIn('日本語@alice', group), ['alice']);
52+
assert.deepEqual(engine.mentionsIn('한국어@alice', group), ['alice']);
53+
});
54+
55+
test('a mention in English stays the way it was', async (t) => {
56+
const { engine, group } = await fixture(t);
57+
assert.deepEqual(engine.mentionsIn('@alice', group), ['alice']);
58+
assert.deepEqual(engine.mentionsIn('hi @alice', group), ['alice']);
59+
assert.deepEqual(engine.mentionsIn('@alice please review the plan', group), ['alice']);
60+
assert.deepEqual(engine.mentionsIn('(@alice)', group), ['alice']);
61+
assert.deepEqual(engine.mentionsIn('@alice.', group), ['alice']);
62+
assert.deepEqual(engine.mentionsIn('@alice!', group), ['alice']);
63+
assert.deepEqual(engine.mentionsIn('@alice @bob', group), ['alice', 'bob']);
64+
assert.deepEqual(engine.mentionsIn('@alice,@bob', group), ['alice', 'bob']);
65+
assert.deepEqual(engine.mentionsIn('@alice @alice', group), ['alice']);
66+
assert.deepEqual(engine.mentionsIn('@ALICE SMITH!', group), ['alice_smith']);
67+
// The longest name wins, and a name that runs into more words is not a mention.
68+
assert.deepEqual(engine.mentionsIn('@alice smith', group), ['alice_smith']);
69+
assert.deepEqual(engine.mentionsIn('@Alicex', group), []);
70+
assert.deepEqual(engine.mentionsIn('@alice_x', group), []);
71+
});
72+
73+
test('an English address is still not a mention', async (t) => {
74+
const { engine, group } = await fixture(t);
75+
// The local part of an address is ASCII, so it ends the mention the way it always did.
76+
assert.deepEqual(engine.mentionsIn('mail@alice.com', group), []);
77+
assert.deepEqual(engine.mentionsIn('user.name@alice.com', group), []);
78+
assert.deepEqual(engine.mentionsIn('mail@设计师', group), []);
79+
assert.deepEqual(engine.mentionsIn('ok@alice ok', group), []);
80+
assert.deepEqual(engine.mentionsIn('2@alice', group), []);
81+
assert.deepEqual(engine.mentionsIn('mail@alice.com @ALICE SMITH! @Alice', group), ['alice_smith', 'alice']);
82+
});
83+
84+
test('a name that runs into more words is still not a mention', async (t) => {
85+
const { engine, group } = await fixture(t);
86+
// "Alicex" is another word, not Alice.
87+
assert.deepEqual(engine.mentionsIn('@Alicex', group), []);
88+
// A full stop in Chinese prose ends a sentence; it is not a domain.
89+
assert.deepEqual(engine.mentionsIn('@Alice。然后呢', group), ['alice']);
90+
assert.deepEqual(engine.mentionsIn('@设计师傅', group), []);
91+
});
92+
93+
test('the Bot that sent the message does not call itself', async (t) => {
94+
const { engine, group } = await fixture(t);
95+
assert.deepEqual(engine.mentionsIn('@alice @bob', group, 'alice'), ['bob']);
96+
assert.deepEqual(engine.mentionsIn('@alice @bob', group, 'bob'), ['alice']);
97+
});

0 commit comments

Comments
 (0)