Skip to content

Commit 9d2d5cd

Browse files
committed
fix(minimax-bot): 群纪要的三处收尾,与后台任务也计入用量台账
1 parent 799b772 commit 9d2d5cd

13 files changed

Lines changed: 408 additions & 46 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.11",
5+
"version": "0.7.12",
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: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ Copy this directory, including the hidden `.minimax-plugin/` directory, into the
3939
- The note is off unless you switch it on in the group settings, and a group without a note gets exactly the prompt it got before. Only you can set it: a Bot cannot switch it on, and the record itself is written by the plugin — a Bot cannot write into it.
4040
- The note holds the most recent rounds and stays within a small size limit. The group settings show what was recorded, and you can clear it there. Switching the note off stops the recording and stops handing the record to the Bots, but what was already recorded stays until you clear it.
4141

42+
## 0.7.12 The group note, again, and background jobs that count
43+
44+
- A recorded line keeps its Chinese text. Cutting a line to its closing part used to trim up to the first space, and Chinese has no spaces, so a Chinese entry could lose almost all of itself. The trim now only drops a half Latin word, and never more than 20 characters.
45+
- The protocol marks are matched in any spelling: a tag with spaces, with an attribute, in another case, or with a dash that looks like a hyphen is removed as well. The text around it is left alone, and Chinese punctuation is not rewritten.
46+
- The group settings state the limits the plugin actually uses. The panel reads them from the server instead of writing down numbers of its own.
47+
- 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.
48+
- 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.
49+
4250
## 0.7.11 The group note, cleaned up
4351

4452
- 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.
@@ -119,8 +127,8 @@ Avatars are stored in the Mini App's `dataDir/avatars/`. `GET /api/avatars` list
119127

120128
## Data & access
121129

122-
- **Agent turns**: every Bot reply, scheduled task and background job is an Agent turn run through `context.agent`, with the Agent's full capabilities (files, shell, Skills and MCP, including this plugin's own MCP tools). A tool call that needs approval is shown in the page or in the session's sidebar tab; it runs only after you choose **Allow once**. Nothing is approved automatically. A group with a relay limit spends one more Agent turn on the round that reaches the limit: the wrap-up, which replaces the blocked hand-off. A group note spends no turn at all: it is written from the replies the round already produced.
123-
- **Files written**: only inside the Mini App's `dataDir`: `state.json`, `messages/`, `usage.jsonl`, `memory/` (including its journal, archive and backups), `uploads/` (your attachments) and `avatars/`. A group's note is part of that group's record in `state.json`, so it is removed with the group.
130+
- **Agent turns**: every Bot reply, scheduled task and background job is an Agent turn run through `context.agent`, with the Agent's full capabilities (files, shell, Skills and MCP, including this plugin's own MCP tools). A tool call that needs approval is shown in the page or in the session's sidebar tab; it runs only after you choose **Allow once**. Nothing is approved automatically. A group with a relay limit spends one more Agent turn on the round that reaches the limit: the wrap-up, which replaces the blocked hand-off. A group note spends no turn at all: it is written from the replies the round already produced. Every turn is counted once in the usage panel, background jobs included.
131+
- **Files written**: only inside the Mini App's `dataDir`: `state.json`, `messages/`, `usage.jsonl` (one row per Agent turn), `memory/` (including its journal, archive and backups), `uploads/` (your attachments) and `avatars/`. A group's note is part of that group's record in `state.json`, so it is removed with the group.
124132
- **Files read outside `dataDir`**:
125133
- `/api/media` serves a local file (up to 1 GiB) only when its absolute path appears in a Bot message of that same chat.
126134
- An avatar given as a local image path (by you or by Chief through `update_bot`) is read once and copied into `avatars/`.

‎plugins/minimax-ai/minimax-bot/miniapp/client/panels.js‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,9 @@ function groupOverview(group) {
339339
h('span', null, t('panels.group.notes')),
340340
),
341341
h('p', { class: 'hint', style: { marginTop: '8px' } }, t('panels.group.notesHint')),
342+
// The limits come from the server, so the panel cannot state numbers the plugin does
343+
// not use.
344+
...(state.noteLimits ? [h('p', { class: 'hint' }, t('panels.group.notesLimit', state.noteLimits))] : []),
342345
// The record stays visible while it exists, even with the switch off: what was recorded
343346
// has to be readable and clearable, otherwise turning the switch off would hide it.
344347
...(Array.isArray(group.noteEntries) && group.noteEntries.length

‎plugins/minimax-ai/minimax-bot/miniapp/client/strings-panels.js‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,8 @@ export default {
182182
'panels.group.handoverHint': '下一位的提示词里会带上上一位回复的结论(就是它的尾部),省得下一位再翻一遍工具。上一位的原话本来就在「新消息」里,这里是再强调一遍结论。只多一段提示词,不多花回合。',
183183
'panels.group.notesHeading': '群纪要',
184184
'panels.group.notes': '把本群说过的话记下来',
185-
'panels.group.notesHint': '每轮结束后,群会把各 Bot 回复的结尾记成一份纪要,写在群资料里:清空聊天记录(新建对话)之后纪要还在,新加入的 Bot 也能看到。纪要只留最近几轮(最多 6 条 / 1200 字),更早的会掉出去;关掉开关只是不再记、也不再给 Bot 看,记下的内容会保留到你清空为止。纪要只是记录,不代表群里已经达成共识。只多一段提示词,不多花回合。',
185+
'panels.group.notesHint': '每轮结束后,群会把各 Bot 回复的结尾记成一份纪要,写在群资料里:清空聊天记录(新建对话)之后纪要还在,新加入的 Bot 也能看到。关掉开关只是不再记、也不再给 Bot 看,记下的内容会保留到你清空为止。纪要只是记录,不代表群里已经达成共识。只多一段提示词,不多花回合。',
186+
'panels.group.notesLimit': '纪要只留最近几轮(最多 {entries} 条 / {chars} 字),更早的会掉出去。',
186187
'panels.group.notesList': '已记录的纪要:',
187188
'panels.group.notesKept': '开关关着,这份纪要保留着,但不再记录、也不再给 Bot 看。',
188189
'panels.group.notesClear': '清空纪要',
@@ -544,7 +545,8 @@ export default {
544545
'panels.group.handoverHint': "The next Bot's prompt carries the conclusion of the previous reply (its tail), so the next Bot does not have to dig the same ground out of the tools again. The previous reply is in the new messages anyway — this repeats the conclusion on purpose. It is prompt text only — no extra turn.",
545546
'panels.group.notesHeading': 'Group notes',
546547
'panels.group.notes': 'Keep a record of what this group said',
547-
'panels.group.notesHint': 'After every round the group records the closing lines of the replies as a note, kept with the group settings: the note is still there after the chat was cleared (Start new chat), and a Bot that joins later sees it too. Only the last rounds are kept (6 entries and 1200 characters at most); older ones drop off. Switching the note off stops the recording and stops handing it to the Bots, but what was recorded stays until you clear it. A note is a record, not an agreement the group reached. It is prompt text only — no extra turn.',
548+
'panels.group.notesHint': 'After every round the group records the closing lines of the replies as a note, kept with the group settings: the note is still there after the chat was cleared (Start new chat), and a Bot that joins later sees it too. Switching the note off stops the recording and stops handing it to the Bots, but what was recorded stays until you clear it. A note is a record, not an agreement the group reached. It is prompt text only — no extra turn.',
549+
'panels.group.notesLimit': 'Only the last rounds are kept ({entries} entries and {chars} characters at most); older ones drop off.',
548550
'panels.group.notesList': 'Recorded so far:',
549551
'panels.group.notesKept': 'The switch is off, so this record is kept but neither added to nor read by the Bots.',
550552
'panels.group.notesClear': 'Clear the note',

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,17 @@ function errorText(error) {
132132
return String(error);
133133
}
134134

135+
/**
136+
* The usage ledger speaks the Bot's vocabulary: a turn is done, error or aborted. A background
137+
* job that failed is an error; one that was cut off (a stop, a restart) is aborted, not a fault.
138+
* @param {string} status
139+
*/
140+
function helperTurnStatus(status) {
141+
if (status === 'failed') return 'error';
142+
if (status === 'interrupted' || status === 'stopped') return 'aborted';
143+
return 'done';
144+
}
145+
135146
export class Engine {
136147
/**
137148
* @param {{
@@ -1696,6 +1707,12 @@ export class Engine {
16961707
let result;
16971708
let failure = '';
16981709
let aborted = false;
1710+
// What this background job spent: its own turn, its tools and what it answered.
1711+
let turnStartedAt = 0;
1712+
let turnMs = 0;
1713+
let turnTools = 0;
1714+
let turnText = '';
1715+
let turnBotName = '';
16991716
try {
17001717
holdsHelper = await this.acquireHelper(controller.signal);
17011718
if (!holdsHelper || controller.signal.aborted) throw Object.assign(new Error('stopped'), { code: 'REQUEST_CANCELLED' });
@@ -1715,6 +1732,10 @@ export class Engine {
17151732
if (event.type === 'turn.started' && !helper.sessionId) {
17161733
helper.sessionId = event.sessionId;
17171734
this.broadcastHelpers();
1735+
} else if (event.type === 'tool.started') {
1736+
// A background job calls the same tools a Bot's own turn does. Count them, or the
1737+
// turn it spends looks like it cost nothing.
1738+
turnTools += 1;
17181739
} else if (event.type === 'permission.requested') {
17191740
// The user approves a helper's tool call in its Bot's chat, like the Bot's own.
17201741
const approval = {
@@ -1736,13 +1757,18 @@ export class Engine {
17361757
}
17371758
};
17381759
const text = t('helper.brief', { bot: bot?.name ?? 'Bot', role: bot?.role || '-', task: helper.task });
1760+
turnStartedAt = Date.now();
1761+
turnBotName = bot?.name ?? '';
17391762
try {
17401763
result = await /** @type {any} */ (this.agent).run({ text, ...(model ? { model } : {}) }, { signal: controller.signal, onEvent });
17411764
} catch (error) {
17421765
if (model && errorCode(error) === 'INVALID_ARGUMENTS') {
17431766
throw Object.assign(new Error(errorText(error)), { code: 'MODEL_UNAVAILABLE' });
17441767
}
17451768
throw error;
1769+
} finally {
1770+
turnMs = Date.now() - turnStartedAt;
1771+
turnText = result?.text ?? '';
17461772
}
17471773
} finally {
17481774
this.releaseSlot();
@@ -1781,6 +1807,22 @@ export class Engine {
17811807
helper.error = result?.error?.message ?? t('agentError.unknown');
17821808
}
17831809
if (report) helper.report = report;
1810+
if (turnStartedAt) {
1811+
// A background job is an Agent turn like any other: meter it here, or the usage panel
1812+
// counts fewer turns than the model actually ran.
1813+
await this.store.recordUsage({
1814+
ts: Date.now(),
1815+
botId: helper.botId,
1816+
botName: turnBotName,
1817+
chatId: helper.chatId,
1818+
kind: 'helper-run',
1819+
status: helperTurnStatus(helper.status),
1820+
durationMs: turnMs,
1821+
chars: turnText.length,
1822+
tools: turnTools,
1823+
});
1824+
this.broadcast({ type: 'usage.changed' });
1825+
}
17841826
if (this.disposed) return;
17851827
this.trimHelpers();
17861828
await this.store.save();

‎plugins/minimax-ai/minimax-bot/miniapp/node/group-note.mjs‎

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,22 @@ function cleanEntry(entry) {
7171
return { speaker: speaker.slice(0, NOTE_SPEAKER_MAX), text: tailOf(text, NOTE_ENTRY_MAX) };
7272
}
7373

74+
/**
75+
* A word character in the Latin sense: a letter or a digit that a cut can land inside.
76+
*
77+
* A CJK ideograph is its own unit, so a cut between two of them already lands on a boundary.
78+
*/
79+
const LATIN_WORD = /[A-Za-z0-9_]/;
80+
81+
/** How much of a broken word may be dropped to reach the next boundary. */
82+
const WORD_PREFIX_MAX = 20;
83+
7484
/**
7585
* The closing part of a text, cut on a word boundary.
7686
*
7787
* A plain cut can land inside a word — or inside the half of a tag the neutralising left
78-
* behind — and the entry would start mid-word. When the cut lands inside a word, the partial
79-
* word is dropped, so the entry starts where a word starts.
88+
* behind — and the entry would start mid-word. Only a Latin word can be cut in half: Chinese
89+
* has no spaces, so trimming up to the first whitespace there would drop the whole entry.
8090
*
8191
* @param {string} text
8292
* @param {number} [max]
@@ -87,10 +97,13 @@ export function tailOf(text, max = NOTE_ENTRY_MAX) {
8797
if (value.length <= max) return value;
8898
const cut = value.length - max;
8999
const tail = value.slice(cut);
90-
// The character before the cut tells whether the cut landed inside a word.
91-
if (!/\S/.test(value[cut - 1] ?? '')) return tail;
92-
const trimmed = tail.replace(/^\S*\s+/, '');
93-
return trimmed || tail;
100+
// The characters around the cut tell whether it landed inside a Latin word.
101+
if (!LATIN_WORD.test(value[cut - 1] ?? '') || !LATIN_WORD.test(tail[0] ?? '')) return tail;
102+
// Drop the rest of that word and the space after it. A word longer than this is left alone:
103+
// dropping half of a long token would cost more than the fragment is worth.
104+
const fragment = /^[A-Za-z0-9_]+/.exec(tail)?.[0] ?? '';
105+
if (!fragment || fragment.length > WORD_PREFIX_MAX) return tail;
106+
return tail.slice(fragment.length).replace(/^\s+/, '') || tail;
94107
}
95108

96109
/**

‎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.11' },
589+
serverInfo: { name: 'minimax-bot', version: '0.7.12' },
590590
instructions: t('mcp.instructions'),
591591
};
592592
break;

‎plugins/minimax-ai/minimax-bot/miniapp/node/relay-guard.mjs‎

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,18 @@ export const HANDOVER_TAIL = 400;
4646
/**
4747
* Protocol marks a reply must never be able to forge: a Bot that writes them into its answer
4848
* would otherwise be able to open a block of its own in the next Bot's prompt.
49+
*
50+
* The pattern matches any `minimax-bot-…` tag rather than a fixed list, so a mark that is
51+
* spelled differently — with spaces, with an attribute, in another case — is caught as well.
52+
* The attribute part is bounded, so a stray `<` cannot swallow the text behind it.
4953
*/
50-
const FORGED_MARKS = [
51-
HANDOVER_BLOCK_MARK,
52-
HANDOVER_BLOCK_END,
53-
CONVERGE_MARK,
54-
CONTEXT_BLOCK_MARK,
55-
CONTEXT_BLOCK_END,
56-
'<minimax-bot-group-summary>',
57-
'</minimax-bot-group-summary>',
58-
'<minimax-bot-group-summary-task>',
59-
];
54+
const MARK_PATTERN = /<\s*\/?\s*minimax-bot-[a-z0-9-]+(?:\s[^>]{0,40})?>/gi;
55+
56+
/** A dash that looks like the hyphen of a protocol mark. */
57+
const LOOKALIKE_DASH = /[‐-―]/g;
58+
59+
/** A full-width ASCII character, which a Host that folds them would read as ASCII. */
60+
const FULLWIDTH_ASCII = /[!-~]/g;
6061

6162
/** The largest hop limit a group can hold. The panel offers the same range. */
6263
export const HOP_LIMIT_MAX = 20;
@@ -94,30 +95,36 @@ export function handoverRequested(group) {
9495
}
9596

9697
/**
97-
* A protocol mark is a literal, so the pattern has to escape whatever it contains.
98+
* A copy of the text with the characters that can stand in for a hyphen or an ASCII letter
99+
* folded to their ASCII form.
100+
*
101+
* Every fold replaces one character with one character, so a mark found in the folded text
102+
* points at the same characters in the original and the text itself stays untouched.
98103
* @param {string} text
99104
* @returns {string}
100105
*/
101-
function escapeRegExp(text) {
102-
return text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
106+
function foldMarks(text) {
107+
return text
108+
.replace(LOOKALIKE_DASH, '-')
109+
.replace(FULLWIDTH_ASCII, (char) => String.fromCharCode(char.charCodeAt(0) - 0xfee0));
103110
}
104111

105-
/**
106-
* The marks are matched case-insensitively: a tag in another case is still a tag, and a Host
107-
* that reads the marks case-insensitively must not be handed one.
108-
*/
109-
const FORGED_PATTERNS = FORGED_MARKS.map((mark) => new RegExp(escapeRegExp(mark), 'gi'));
110-
111112
/**
112113
* Removes the protocol marks from a text, so a reply can never pretend to open or close a
113114
* block of its own.
114115
* @param {string} text
115116
* @returns {string}
116117
*/
117118
export function neutralizeMarks(text) {
118-
let out = String(text ?? '');
119-
for (const pattern of FORGED_PATTERNS) out = out.replace(pattern, ' ');
120-
return out;
119+
const value = String(text ?? '');
120+
const folded = foldMarks(value);
121+
let out = '';
122+
let last = 0;
123+
for (const match of folded.matchAll(MARK_PATTERN)) {
124+
out += value.slice(last, match.index) + ' ';
125+
last = match.index + match[0].length;
126+
}
127+
return out + value.slice(last);
121128
}
122129

123130
/**

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { extname, isAbsolute, join } from 'node:path';
88

99
import { createHash } from 'node:crypto';
1010
import { Engine, EngineError, UPLOAD_NAME_RE } from './engine.mjs';
11-
import { noteEntries } from './group-note.mjs';
11+
import { NOTE_MAX_CHARS, NOTE_MAX_ENTRIES, noteEntries } from './group-note.mjs';
1212
import { createMcpHandler } from './mcp.mjs';
1313
import { LANGUAGE_PREFS, locale, matchLocale, t } from './i18n.mjs';
1414
import { memoryBudget, MemoryError, MemoryStore } from './memory.mjs';
@@ -144,6 +144,9 @@ export async function start(context) {
144144
groups: store.state.groups.map((group) => (
145145
Array.isArray(group.noteEntries) ? { ...group, noteEntries: noteEntries(group) } : group
146146
)),
147+
// The limits of a group note, so the panel can state them instead of writing down numbers
148+
// that would drift away from the ones the plugin uses.
149+
noteLimits: { entries: NOTE_MAX_ENTRIES, chars: NOTE_MAX_CHARS },
147150
schedules: store.state.schedules,
148151
helpers: engine.helpersList(),
149152
tasks: engine.tasks.uiList(),

‎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.11",
3+
"version": "0.7.12",
44
"private": true,
55
"type": "module",
66
"mcode": {

0 commit comments

Comments
 (0)