From bd3150afa190f1f941d89a3d103de283aec92ca4 Mon Sep 17 00:00:00 2001 From: Evander Date: Fri, 27 Nov 2026 04:41:10 -0500 Subject: [PATCH 1/2] =?UTF-8?q?fix(minimax-bot):=20=E5=AF=B9=E6=96=B9?= =?UTF-8?q?=E5=BF=99=E7=9A=84=E6=97=B6=E5=80=99=E5=85=88=E6=9F=A5=E5=9C=A8?= =?UTF-8?q?=E5=BF=99=E4=BB=80=E4=B9=88=EF=BC=8C=E5=86=8D=E5=91=8A=E8=AF=89?= =?UTF-8?q?=E7=94=A8=E6=88=B7=EF=BC=8C=E5=88=AB=E5=8F=AA=E5=9B=9E=E4=B8=80?= =?UTF-8?q?=E5=8F=A5=E5=B7=B2=E6=8E=92=E9=98=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../minimax-bot/.minimax-plugin/plugin.json | 2 +- plugins/minimax-ai/minimax-bot/README.md | 9 ++++ .../minimax-bot/miniapp/node/mcp.mjs | 2 +- .../minimax-bot/miniapp/node/strings.mjs | 16 +++---- plugins/minimax-ai/minimax-bot/package.json | 2 +- .../tests/brief-busy-tools.test.mjs | 47 +++++++++++++++++++ 6 files changed, 67 insertions(+), 11 deletions(-) create mode 100644 plugins/minimax-ai/minimax-bot/tests/brief-busy-tools.test.mjs diff --git a/plugins/minimax-ai/minimax-bot/.minimax-plugin/plugin.json b/plugins/minimax-ai/minimax-bot/.minimax-plugin/plugin.json index 915018bd..5f3402c7 100644 --- a/plugins/minimax-ai/minimax-bot/.minimax-plugin/plugin.json +++ b/plugins/minimax-ai/minimax-bot/.minimax-plugin/plugin.json @@ -2,7 +2,7 @@ "schemaVersion": 1, "name": "minimax-bot", "displayName": "MiniMax Bot", - "version": "0.7.39", + "version": "0.7.42", "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.", "author": "MiniMax Code", "icon": "icon.png", diff --git a/plugins/minimax-ai/minimax-bot/README.md b/plugins/minimax-ai/minimax-bot/README.md index c022ed8c..614eba64 100644 --- a/plugins/minimax-ai/minimax-bot/README.md +++ b/plugins/minimax-ai/minimax-bot/README.md @@ -145,6 +145,15 @@ The hand-over between two Bots of a group carried the tail of the previous reply - The stored name now replaces a run of dots, and a long name is cut on a whole character so an emoji is never left half-written. - The extension is kept apart from the rest of the name and survives that cleaning, because it decides how the file is served: `photo..png` was stored as `photo_png`, so it went out as `application/octet-stream` and the Bot received a plain file instead of an image. It is stored as `photo.png` now and stays a PNG end to end. +## 0.7.42 A Bot that is busy says what it is doing, not just that it is busy + +- When another Bot is occupied, the work queues behind it. The brief said so and stopped there, so the answer a user got was a restatement of that line — 「这个 Bot 正在忙别的任务,已排队,轮到后自动发送」 — which does not say what the other Bot is doing, cannot be acted on, and is not what the plugin said: the plugin had no such string. +- The tools to answer it were there the whole time. `get_tasks` reports the title and status of the queued work, `cancel_tasks` stops it, and the tasks page in the sidebar lists every one of them with a stop button. Nothing told the Bot to look before answering. +- `brief.tool.tasks` and `brief.tool.message` now say what to do when the other Bot is busy: look it up with `get_tasks`, tell the user in one sentence what it is busy with, and use `cancel_tasks` if the user wants it stopped. The rule that the task ids are not read out to the user stays, with the part that was missing: the ids are for the tools, and what the query finds is told to the user. +- `mcp.t.message_bot` carries the same instruction, because that is the description the model reads when it decides to hand work over. +- `brief.tool.schedule` now answers the other half of the same question. A user who asks whether something is running on a timer, or why their usage keeps going, gets an answer from `list_schedules`, and `delete_schedule` stops it. The line also states the limit: only this team's scheduled tasks are in that list. A schedule the Host runs elsewhere is not in it and is not under the Bot's control — a cron attached to a session from the host side showed as zero rows in the Bot's own list while it kept spending the session's quota. +- Only the wording changed. No tool, no state and no limit moved: the same calls with the same arguments do the same things. + ## 0.7.38 The page tells the user when a chat is stuck and when a job was stopped - A turn whose outcome cannot be confirmed — the process stopped while it was running, or the Host took it and never said — leaves the request marked as unknown. Every later message of that chat waits for it, on purpose: a correction must not act on a state nobody can vouch for. diff --git a/plugins/minimax-ai/minimax-bot/miniapp/node/mcp.mjs b/plugins/minimax-ai/minimax-bot/miniapp/node/mcp.mjs index 5e0c520a..63e7bd6d 100644 --- a/plugins/minimax-ai/minimax-bot/miniapp/node/mcp.mjs +++ b/plugins/minimax-ai/minimax-bot/miniapp/node/mcp.mjs @@ -662,7 +662,7 @@ export function createMcpHandler({ team, engine }) { result = { protocolVersion: PROTOCOL_VERSIONS.includes(requested) ? requested : PROTOCOL_VERSIONS[0], capabilities: { tools: { listChanged: false } }, - serverInfo: { name: 'minimax-bot', version: '0.7.39' }, + serverInfo: { name: 'minimax-bot', version: '0.7.42' }, instructions: t('mcp.instructions'), }; break; diff --git a/plugins/minimax-ai/minimax-bot/miniapp/node/strings.mjs b/plugins/minimax-ai/minimax-bot/miniapp/node/strings.mjs index 577a6352..b95bb3cb 100644 --- a/plugins/minimax-ai/minimax-bot/miniapp/node/strings.mjs +++ b/plugins/minimax-ai/minimax-bot/miniapp/node/strings.mjs @@ -35,7 +35,7 @@ export default { 'notice.groupCreated': '群聊已创建。管理员 {admin} 默认接话;用 @名字 可以直接点名某个 Bot。', "notice.noProgress": "检测到重复交接且没有新的工具进展,讨论已暂停。可以补充要求后继续;独立任务仍会运行。", "notice.hopLimit": "已达接力上限({max} 跳),本轮讨论在此收口。", - 'brief.tool.tasks': "- dispatch_tasks:一次交给多个 Bot,用于需要多人协作的同一请求。和 message_bot 一样持久受理,完成后结果回到发起聊天;不需要预先指定结果群或汇总人。get_tasks 可查看进展,cancel_tasks 明确停止。不要向用户暴露任务编号或要求用户选择执行模式。外部主会话没有回调能力,须主动查询结果。", + 'brief.tool.tasks': "- dispatch_tasks:一次交给多个 Bot,用于需要多人协作的同一请求。和 message_bot 一样持久受理,完成后结果回到发起聊天;不需要预先指定结果群或汇总人。get_tasks 可查看进展,cancel_tasks 明确停止。不要向用户暴露任务编号或要求用户选择执行模式。外部主会话没有回调能力,须主动查询结果。对方忙起来时不要只说「已排队」:先 get_tasks 查清楚他在忙什么、忙了多久,再用一句话告诉用户;用户想停就用 cancel_tasks 停,停下来以后告诉他怎么停的。编号是给工具用的,不要念给用户,但查到的东西要讲给用户听。", 'mcp.t.dispatch_tasks': "持久化派发一批任务并立即返回 batch_id/task_id,不按任务长短区分路径。不同 Bot 可并行,同一私聊串行,共用 Host 并发额度。request_id 必填,相同内容重试返回原任务;不同内容报冲突。结果自动回到发起聊天,由发起 Bot 验收,只回传本次产出。外部主会话没有回调能力,应 get_tasks 查询。", "mcp.t.get_tasks": "用 batch_id 或 task_id 查询任务(只填一个),wait_ms 最多 20000,只短等状态变化,不取消任务。状态包括 queued/running/waiting_for_tasks/waiting_for_user/paused/done/failed/cancelled/unknown;unknown 不代表失败,不要自动重派;unknown 的任务不会重放,但批次仍会收口并给出结果未知的说明。单任务结果按 result_offset/next_result_offset 分片读取;聊天记录已不在时只返回开头一段并带上 result_truncated。已结算的批次只有最近 30 个保留完整记录,更早的批次只留一条不含回复的记录(最多 1000 条):它们的 batch_id 仍能查到,回复从聊天记录里读;比这更老的 request_id 已经不被认识,同样的活会被当成新的再跑一遍。", "task.unknownOutcome": "结果未知:这次执行的结果无法确认(可能已经完成,也可能没有)。不会自动重跑;仍需要结果时请重新发起一次请求。", @@ -258,12 +258,12 @@ export default { 'brief.toolsWhere': '这些工具来自 MCP 服务 minimax-bot。如果工具列表里没有直接看到,先用 tool_search 搜索 "minimax-bot" 再调用。', 'brief.callerId': '每次调用都把 caller_bot_id 设为 {id}。', 'brief.tool.list': '- list_team:查看团队里的 Bot 和群聊', - 'brief.tool.message': "- message_bot:把事情交给另一个 Bot,不用判断长短;收到回执后可以结束本轮。Bot 会独立完成,结果回到这里。重试复用 request_id;回执仅代表受理。", + 'brief.tool.message': "- message_bot:把事情交给另一个 Bot,不用判断长短;收到回执后可以结束本轮。Bot 会独立完成,结果回到这里。重试复用 request_id;回执仅代表受理。对方正忙时这条活会排队:这时不要只回一句「已排队」就完事,先 get_tasks 查他在忙什么、用一句话告诉用户,他要是想停就 cancel_tasks 停掉。", 'brief.tool.helper': "- start_helper:需要隔离执行上下文时,可让后台助手完成工作,结果仍回到当前聊天。它与找其他 Bot 帮忙具有相同的受理、结果回传和取消语义;无需按任务长短或工具次数分类。交代清楚目标、约束和验收标准,收到回执后结束本轮,最终产出回来后验收并告知用户;不足时补做。向用户自然地说明你会去处理,不要讲 helper、调度方式或内部编号。", 'brief.tool.postGroup': "- post_group(仅限单聊):用户让群讨论或继续工作时,按群名发送要求。使用稳定 request_id,受理后结束本轮,不要把受理当作完成。群里的讨论继续,结果回到发起聊天。遇到暂停的讨论,直接补充要求即可继续,不需要任务编号。", 'brief.tool.memory': '- remember / forget / recall:保存、删除、查找记忆', 'brief.tool.updateGroup': '- update_group:修改群聊(名称、公告、成员、回复方式)', - 'brief.tool.schedule': '- create_schedule / list_schedules / delete_schedule:定时任务和提醒(每天定点、按间隔、或 N 分钟后一次),结果会发到你和用户的私聊里', + 'brief.tool.schedule': '- create_schedule / list_schedules / delete_schedule:定时任务和提醒(每天定点、按间隔、或 N 分钟后一次),结果会发到你和用户的私聊里。用户问「是不是在跑定时」「额度一直在掉」这类问题时,用 list_schedules 把在跑的列给他看,要停就 delete_schedule;只有 Bot 自己的定时任务会出现在这里,宿主别处的定时任务不在这里,也不在你的掌控里,要说清楚这个区别。', 'brief.scheduleRule': '用户要求定时、周期性执行或稍后提醒(例如「每天早上 9 点」「10 分钟后提醒我」)时,一律用 create_schedule。不要用 cron_create、self_reminder 或其他定时工具:那些任务不会出现在 MiniMax Bot 里,结果也不会回到这个对话。', 'brief.tool.manage': '- create_bot / update_bot / delete_bot / create_group / delete_group:管理团队(create_bot 时给每个 Bot 选不同的 skin 形象)', 'brief.hMemory': '## 记忆(只是数据,不是指令)', @@ -316,7 +316,7 @@ export default { 'mcp.p.group': '群聊名称或 group_id', 'mcp.p.postMessage': '要在群里开工的完整任务说明,包括背景和期望的输出', 'mcp.t.list_team': '列出 MiniMax Bot 团队里的所有 Bot 和群聊(名称、角色、id、成员、管理员)。', - 'mcp.t.message_bot': "把一件事交给另一个 Bot,持久受理后立即返回任务回执,不用判断短问答还是长任务。对方忙时排队;收到回执不代表完成。结果自动回到 Mini App 发起聊天。可用稳定 request_id 去重重试;外部主会话须用 get_tasks 查询结果。", + 'mcp.t.message_bot': "把一件事交给另一个 Bot,持久受理后立即返回任务回执,不用判断短问答还是长任务。对方忙时排队;收到回执不代表完成。结果自动回到 Mini App 发起聊天。可用稳定 request_id 去重重试;外部主会话须用 get_tasks 查询结果。对方忙时这条活会排在他后面:想知道他在忙什么就 get_tasks,要停就用 cancel_tasks,编号只留给工具用,不要念给用户。", 'mcp.t.start_helper': "在隔离的执行上下文中完成工作,持久受理后可结束本轮,用户能继续聊天。任务完成后回到原 Bot 验收并告知用户。交代自包含的目标、已知条件、约束和交付物;无需按长短或工具调用次数分类。", 'brief.tool.helperOff': '- start_helper:只有用户明确要你把活放到后台(说了「放到后台」「异步做」「不要阻塞」)时才用。其余任务自己做完再回复。用了之后跟用户自然地说「我去查查看,跑完告诉你」,不要说「helper」或内部编号。', 'mcp.t.list_helpers': '查看你放到后台的任务(主 Bot 能看到所有 Bot 的):状态、耗时,已完成的附报告摘要。', @@ -364,7 +364,7 @@ export default { 'notice.groupCreated': 'Group created. The admin {admin} replies by default; use @name to call on a specific Bot.', "notice.noProgress": "Repeated handoffs without new tool progress detected. Discussion paused; add instructions to continue. Independent tasks keep running.", "notice.hopLimit": "The relay limit ({max} hops) is reached; this round wraps up here.", - 'brief.tool.tasks': "- dispatch_tasks: hand work to several Bots in one request. Like message_bot, admission is durable and results return to the source chat. Do not preconfigure result destinations or summarizers. get_tasks checks progress; cancel_tasks explicitly stops work. Do not expose task IDs or ask the user to select execution modes. External host chats have no callback and must query results.", + 'brief.tool.tasks': "- dispatch_tasks: hand work to several Bots in one request. Like message_bot, admission is durable and results return to the source chat. Do not preconfigure result destinations or summarizers. get_tasks checks progress; cancel_tasks explicitly stops work. Do not expose task IDs or ask the user to select execution modes. External host chats have no callback and must query results. When the other Bot is busy, do not just say the work is queued: get_tasks first to find out what it is busy with and for how long, then tell the user in one sentence. If the user wants it stopped, use cancel_tasks and say how it was stopped. The ids are for the tools: do not read them out, but do tell the user what the query found.", 'mcp.t.dispatch_tasks': "Persist a batch of tasks and immediately return batch_id/task_id, without classifying work as short or long. Different Bots can run in parallel; each private chat is serial and shares Host capacity. Required request_id deduplicates identical retries; changed content conflicts. Task outputs return to the source chat for verification by the caller Bot. External host chats must query get_tasks; no callback is available.", "mcp.t.get_tasks": "Query exactly one of batch_id or task_id. wait_ms is bounded to 20000 and only waits for a state change; it never cancels work. States: queued/running/waiting_for_tasks/waiting_for_user/paused/done/failed/cancelled/unknown. Unknown is not a confirmed failure: do not automatically redispatch. An unknown task is never replayed, but its batch still closes and states that the outcome is unknown. Read full single-task outputs with result_offset/next_result_offset; when the chat record is gone only the first part comes back, flagged with result_truncated. Only the 30 most recent settled batches are kept in full; older ones leave a record without the reply (at most 1,000 records), so their batch_id still answers and the reply is read from the chat record; a request_id older than that is no longer known, and the same work would start again.", "task.unknownOutcome": "Outcome unknown: this run's result could not be confirmed (it may have finished, or may not have). It is not retried automatically; send a fresh request if you still need the result.", @@ -580,12 +580,12 @@ export default { 'brief.toolsWhere': 'These tools come from the MCP server minimax-bot. If you do not see them in your tool list, search for "minimax-bot" with tool_search first.', 'brief.callerId': 'Always set caller_bot_id to {id}.', 'brief.tool.list': '- list_team: see the Bots and groups on the team', - 'brief.tool.message': "- message_bot: hand work to another Bot without classifying it as short or long. End your turn after admission; the Bot works independently and returns the result here. Reuse request_id on retry. Admission does not mean completion.", + 'brief.tool.message': "- message_bot: hand work to another Bot without classifying it as short or long. End your turn after admission; the Bot works independently and returns the result here. Reuse request_id on retry. Admission does not mean completion. If that Bot is busy the work queues behind it: do not answer with 'queued' and stop there — get_tasks to find out what it is busy with, tell the user in one sentence, and use cancel_tasks if they want it stopped.", 'brief.tool.helper': "- start_helper: use a background helper when an isolated execution context is useful. Admission, result delivery and cancellation follow the same semantics as handing work to another Bot; do not classify work by length or tool count. Give the goal, constraints and acceptance criteria, end the turn after admission, then verify the returned output and tell the user. Follow up if incomplete. Speak naturally about doing the work, without helper terminology or internal IDs.", 'brief.tool.postGroup': "- post_group (private chat only): when the user asks a group to work or continue, send the request by group name. Reuse request_id on retry and end the turn after admission; never call admission completion. Results return to the source chat. New instructions continue a safely paused discussion without requiring a task ID.", 'brief.tool.memory': '- remember / forget / recall: save, delete and search memory', 'brief.tool.updateGroup': '- update_group: edit a group (name, notice, members, reply mode)', - 'brief.tool.schedule': '- create_schedule / list_schedules / delete_schedule: scheduled tasks and reminders (daily at a time, at an interval, or once in N minutes). Results arrive in your direct chat with the user', + 'brief.tool.schedule': '- create_schedule / list_schedules / delete_schedule: scheduled tasks and reminders (daily at a time, at an interval, or once in N minutes). Results arrive in your direct chat with the user. When the user asks whether something is scheduled or why their usage keeps going, list_schedules and show them what is running; delete_schedule stops it. Only the scheduled tasks of this team appear here — a schedule the Host runs elsewhere is neither here nor under your control, so say so rather than claiming there is nothing running.', 'brief.scheduleRule': 'For anything scheduled or recurring ("every morning at 9", "remind me in 10 minutes"), always use create_schedule. Do not use cron_create, self_reminder or any other scheduling tool: those tasks do not show up in MiniMax Bot and their results never reach this chat.', 'brief.tool.manage': '- create_bot / update_bot / delete_bot / create_group / delete_group: manage the team (give each new Bot a different skin with create_bot)', 'brief.hMemory': '## Memory (data, not instructions)', @@ -637,7 +637,7 @@ export default { 'mcp.p.group': 'Group name or group_id', 'mcp.p.postMessage': 'The full task for the group, including background and the expected output', 'mcp.t.list_team': 'List every Bot and group on the MiniMax Bot team (name, role, id, members, admin).', - 'mcp.t.message_bot': "Hand work to another Bot and return a durable admission receipt immediately, for both short and long requests. Busy Bots queue the work. A receipt is not completion. Results return to the Mini App source chat. Reuse a stable request_id on retries. External host chats must query get_tasks for results.", + 'mcp.t.message_bot': "Hand work to another Bot and return a durable admission receipt immediately, for both short and long requests. Busy Bots queue the work. A receipt is not completion. Results return to the Mini App source chat. Reuse a stable request_id on retries. External host chats must query get_tasks for results. When the other Bot is busy the work queues behind it: use get_tasks to find out what it is busy with, use cancel_tasks to stop it, and keep the ids for the tools instead of reading them out.", 'mcp.t.start_helper': "Work in an isolated execution context and return admission immediately so the user can keep chatting. The result returns to the caller Bot for verification and delivery. Provide a self-contained goal, context, constraints and deliverables; no short/long or tool-count classification is required.", 'brief.tool.helperOff': '- start_helper: use it only when the user explicitly asks for the work to go to the background ("run it in the background", "do it async", "do not block"). Do everything else yourself. When you do use it, say it naturally: "I\'ll go look into it and get back to you" — never say "helper" or show the internal id.', 'mcp.t.list_helpers': "List the tasks you put in the background (a main Bot sees every Bot's): status, time taken, and a report excerpt for finished ones.", diff --git a/plugins/minimax-ai/minimax-bot/package.json b/plugins/minimax-ai/minimax-bot/package.json index 56878589..56a3a5ed 100644 --- a/plugins/minimax-ai/minimax-bot/package.json +++ b/plugins/minimax-ai/minimax-bot/package.json @@ -1,6 +1,6 @@ { "name": "minimax-bot", - "version": "0.7.39", + "version": "0.7.42", "private": true, "type": "module", "mcode": { diff --git a/plugins/minimax-ai/minimax-bot/tests/brief-busy-tools.test.mjs b/plugins/minimax-ai/minimax-bot/tests/brief-busy-tools.test.mjs new file mode 100644 index 00000000..5308c62b --- /dev/null +++ b/plugins/minimax-ai/minimax-bot/tests/brief-busy-tools.test.mjs @@ -0,0 +1,47 @@ +import assert from 'node:assert/strict'; +import { test } from 'node:test'; +import strings from '../miniapp/node/strings.mjs'; + +// A Bot that is told "busy Bots queue the work" and nothing else answers the way it answered +// in MiniMax开放平台用户交流群: 「这个 Bot 正在忙别的任务,已排队,轮到后自动发送」 — it cannot +// say what the other Bot is doing, and the user has no way to stop it. The tools were always +// there (get_tasks / cancel_tasks / list_schedules / delete_schedule); the brief never said to +// use them when something is busy, and it forbade reading the ids out without saying they are +// still for the tools. + +for (const lang of ['zh', 'en']) { + test(`the brief tells a Bot to look before it says "queued" (${lang})`, () => { + const tasks = strings[lang]['brief.tool.tasks']; + const message = strings[lang]['brief.tool.message']; + for (const text of [tasks, message]) { + assert.match(text, /get_tasks/u, 'the Bot is told to look the busy Bot up'); + } + assert.match(tasks, /cancel_tasks/u, 'the Bot is told how to stop it'); + assert.match(message, /cancel_tasks/u, 'the Bot is told how to stop it from message_bot too'); + }); + + test(`the ids stay for the tools, and what they find is told to the user (${lang})`, () => { + const tasks = strings[lang]['brief.tool.tasks']; + // The ids are still not read out to the user... + assert.match(tasks, lang === 'zh' ? /不要向用户暴露任务编号/u : /Do not expose task IDs/u); + // ...but the answer has to say that the ids are for the tools and that the findings are not. + assert.match(tasks, lang === 'zh' ? /编号是给工具用的/u : /The ids are for the tools/u); + assert.match(tasks, lang === 'zh' ? /查到的东西要讲给用户听/u : /do tell the user what the query found/u); + }); + + test(`a question about a schedule is answered from list_schedules (${lang})`, () => { + const schedule = strings[lang]['brief.tool.schedule']; + assert.match(schedule, /list_schedules/u); + assert.match(schedule, /delete_schedule/u); + // And the limit of that list is stated: something the Host runs elsewhere is not in it. + assert.match(schedule, lang === 'zh' ? /宿主别处的定时任务不在这里/u : /a schedule the Host runs elsewhere is neither here/u); + }); + + test(`both languages say the same thing about a busy Bot (${lang})`, () => { + for (const key of ['brief.tool.tasks', 'brief.tool.message', 'mcp.t.message_bot', 'brief.tool.schedule']) { + assert.equal(typeof strings[lang][key], 'string', `${key} missing in ${lang}`); + assert.ok(strings[lang][key].length > 0, `${key} empty in ${lang}`); + assert.ok(!strings[lang][key].includes('undefined'), `${key} has an empty placeholder in ${lang}`); + } + }); +} From 4922501cb3103c49a493c4ce150d53d0c1caaadd Mon Sep 17 00:00:00 2001 From: Evander Date: Sun, 29 Nov 2026 21:33:41 -0500 Subject: [PATCH 2/2] =?UTF-8?q?fix(minimax-bot):=20=E6=96=87=E6=A1=88?= =?UTF-8?q?=E6=8C=89=E5=B7=A5=E5=85=B7=E5=A5=91=E7=BA=A6=E6=94=B9=EF=BC=8C?= =?UTF-8?q?=E5=8F=AA=E8=AF=B4=E5=9B=9E=E6=89=A7=E8=83=BD=E8=AF=81=E6=98=8E?= =?UTF-8?q?=E7=9A=84=E4=BA=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/minimax-ai/minimax-bot/README.md | 19 +- .../minimax-bot/miniapp/node/strings.mjs | 12 +- .../tests/brief-busy-tools.test.mjs | 167 ++++++++++++++++-- 3 files changed, 164 insertions(+), 34 deletions(-) diff --git a/plugins/minimax-ai/minimax-bot/README.md b/plugins/minimax-ai/minimax-bot/README.md index 614eba64..0eb7f6ad 100644 --- a/plugins/minimax-ai/minimax-bot/README.md +++ b/plugins/minimax-ai/minimax-bot/README.md @@ -145,15 +145,6 @@ The hand-over between two Bots of a group carried the tail of the previous reply - The stored name now replaces a run of dots, and a long name is cut on a whole character so an emoji is never left half-written. - The extension is kept apart from the rest of the name and survives that cleaning, because it decides how the file is served: `photo..png` was stored as `photo_png`, so it went out as `application/octet-stream` and the Bot received a plain file instead of an image. It is stored as `photo.png` now and stays a PNG end to end. -## 0.7.42 A Bot that is busy says what it is doing, not just that it is busy - -- When another Bot is occupied, the work queues behind it. The brief said so and stopped there, so the answer a user got was a restatement of that line — 「这个 Bot 正在忙别的任务,已排队,轮到后自动发送」 — which does not say what the other Bot is doing, cannot be acted on, and is not what the plugin said: the plugin had no such string. -- The tools to answer it were there the whole time. `get_tasks` reports the title and status of the queued work, `cancel_tasks` stops it, and the tasks page in the sidebar lists every one of them with a stop button. Nothing told the Bot to look before answering. -- `brief.tool.tasks` and `brief.tool.message` now say what to do when the other Bot is busy: look it up with `get_tasks`, tell the user in one sentence what it is busy with, and use `cancel_tasks` if the user wants it stopped. The rule that the task ids are not read out to the user stays, with the part that was missing: the ids are for the tools, and what the query finds is told to the user. -- `mcp.t.message_bot` carries the same instruction, because that is the description the model reads when it decides to hand work over. -- `brief.tool.schedule` now answers the other half of the same question. A user who asks whether something is running on a timer, or why their usage keeps going, gets an answer from `list_schedules`, and `delete_schedule` stops it. The line also states the limit: only this team's scheduled tasks are in that list. A schedule the Host runs elsewhere is not in it and is not under the Bot's control — a cron attached to a session from the host side showed as zero rows in the Bot's own list while it kept spending the session's quota. -- Only the wording changed. No tool, no state and no limit moved: the same calls with the same arguments do the same things. - ## 0.7.38 The page tells the user when a chat is stuck and when a job was stopped - A turn whose outcome cannot be confirmed — the process stopped while it was running, or the Host took it and never said — leaves the request marked as unknown. Every later message of that chat waits for it, on purpose: a correction must not act on a state nobody can vouch for. @@ -170,6 +161,16 @@ The hand-over between two Bots of a group carried the tail of the previous reply - `` reached the next Bot whole: the closing tag of the block the plugin writes around the context. The words around it were kept, as they are for every other spelling. - The text is now walked by code point, so a character outside the Basic Multilingual Plane is read as the one character it is. The tag characters are named as well, because some of the slots in that block are not assigned in every Unicode version and are therefore not caught by the general categories. +## 0.7.42 A Bot that is busy says what it is doing, not just that it is busy + +- When another Bot is occupied, the work queues behind it. The brief said so and stopped there, so the answer a user got was a restatement of that line — 「这个 Bot 正在忙别的任务,已排队,轮到后自动发送」 — which says nothing that can be acted on, and is not what the plugin said: the plugin had no such string. +- What the brief may ask for is bounded by what the tools can do. `get_tasks` takes exactly one of `task_id` or `batch_id` and reports the work in the caller's own hands. Nothing lists the work the other Bot is busy with — `list_helpers` covers background helpers, not delegated work. A brief that says "look up what he is busy with" asks for a call that does not exist, and the model answers with the one thing it can see: the piece of work it just handed over, still queued. +- `brief.tool.tasks` and `brief.tool.message` now point at what the receipt carries: `bot_id` is the Bot that took the work and `status` is the state of that piece of work. The Bot tells the user it is queued behind that Bot, and stops it with `cancel_tasks` when asked. The line says plainly that `get_tasks` reports the work in its own hands and that the other Bot's batch cannot be queried, so the answer is not dressed up as more than it is. +- The rule that the task ids are not read out to the user stays, with the part that was missing: the ids are for the tools, and the state that was found is told to the user. +- `mcp.t.message_bot` carries the same instruction in both languages — the receipt names the Bot that took the work and the state of that work, report that, and stop this work if the user asks. +- `brief.tool.schedule` answers the other half of the same question. A user who asks whether something is running on a timer, or why their usage keeps going, gets an answer from `list_schedules`, and `delete_schedule` stops it. The line also states the limit: only this team's scheduled tasks are in that list. A schedule the Host runs elsewhere is not in it and is not under the Bot's control — a cron attached to a session from the host side showed as zero rows in the Bot's own list while it kept spending the session's quota. +- Only the wording changed. No tool, no state and no limit moved: the same calls with the same arguments do the same things. + ## 0.7.10 Optional group notes - A group can keep a note of what it said. After every round the group records the closing lines of the replies, and every Bot of the group gets that record in its standing brief. diff --git a/plugins/minimax-ai/minimax-bot/miniapp/node/strings.mjs b/plugins/minimax-ai/minimax-bot/miniapp/node/strings.mjs index b95bb3cb..e6adb714 100644 --- a/plugins/minimax-ai/minimax-bot/miniapp/node/strings.mjs +++ b/plugins/minimax-ai/minimax-bot/miniapp/node/strings.mjs @@ -35,7 +35,7 @@ export default { 'notice.groupCreated': '群聊已创建。管理员 {admin} 默认接话;用 @名字 可以直接点名某个 Bot。', "notice.noProgress": "检测到重复交接且没有新的工具进展,讨论已暂停。可以补充要求后继续;独立任务仍会运行。", "notice.hopLimit": "已达接力上限({max} 跳),本轮讨论在此收口。", - 'brief.tool.tasks': "- dispatch_tasks:一次交给多个 Bot,用于需要多人协作的同一请求。和 message_bot 一样持久受理,完成后结果回到发起聊天;不需要预先指定结果群或汇总人。get_tasks 可查看进展,cancel_tasks 明确停止。不要向用户暴露任务编号或要求用户选择执行模式。外部主会话没有回调能力,须主动查询结果。对方忙起来时不要只说「已排队」:先 get_tasks 查清楚他在忙什么、忙了多久,再用一句话告诉用户;用户想停就用 cancel_tasks 停,停下来以后告诉他怎么停的。编号是给工具用的,不要念给用户,但查到的东西要讲给用户听。", + 'brief.tool.tasks': "- dispatch_tasks:一次交给多个 Bot,用于需要多人协作的同一请求。和 message_bot 一样持久受理,完成后结果回到发起聊天;不需要预先指定结果群或汇总人。get_tasks 可查看进展,cancel_tasks 明确停止。不要向用户暴露任务编号或要求用户选择执行模式。外部主会话没有回调能力,须主动查询结果。对方忙起来时不要只回一句「已排队」:回执里写着这条排在谁后面(bot_id 是接手方)和它自己的状态,用这一句告诉用户「排在 Worker 后面」,用户想停就 cancel_tasks 停这条活。要说明白的是,get_tasks 查的是你手上这一条,不是对方在忙的那批活 —— 对方的活查不到,别把它说成查到了。编号是给工具用的,不要念给用户,但查到的状态要讲给用户听。", 'mcp.t.dispatch_tasks': "持久化派发一批任务并立即返回 batch_id/task_id,不按任务长短区分路径。不同 Bot 可并行,同一私聊串行,共用 Host 并发额度。request_id 必填,相同内容重试返回原任务;不同内容报冲突。结果自动回到发起聊天,由发起 Bot 验收,只回传本次产出。外部主会话没有回调能力,应 get_tasks 查询。", "mcp.t.get_tasks": "用 batch_id 或 task_id 查询任务(只填一个),wait_ms 最多 20000,只短等状态变化,不取消任务。状态包括 queued/running/waiting_for_tasks/waiting_for_user/paused/done/failed/cancelled/unknown;unknown 不代表失败,不要自动重派;unknown 的任务不会重放,但批次仍会收口并给出结果未知的说明。单任务结果按 result_offset/next_result_offset 分片读取;聊天记录已不在时只返回开头一段并带上 result_truncated。已结算的批次只有最近 30 个保留完整记录,更早的批次只留一条不含回复的记录(最多 1000 条):它们的 batch_id 仍能查到,回复从聊天记录里读;比这更老的 request_id 已经不被认识,同样的活会被当成新的再跑一遍。", "task.unknownOutcome": "结果未知:这次执行的结果无法确认(可能已经完成,也可能没有)。不会自动重跑;仍需要结果时请重新发起一次请求。", @@ -258,7 +258,7 @@ export default { 'brief.toolsWhere': '这些工具来自 MCP 服务 minimax-bot。如果工具列表里没有直接看到,先用 tool_search 搜索 "minimax-bot" 再调用。', 'brief.callerId': '每次调用都把 caller_bot_id 设为 {id}。', 'brief.tool.list': '- list_team:查看团队里的 Bot 和群聊', - 'brief.tool.message': "- message_bot:把事情交给另一个 Bot,不用判断长短;收到回执后可以结束本轮。Bot 会独立完成,结果回到这里。重试复用 request_id;回执仅代表受理。对方正忙时这条活会排队:这时不要只回一句「已排队」就完事,先 get_tasks 查他在忙什么、用一句话告诉用户,他要是想停就 cancel_tasks 停掉。", + 'brief.tool.message': "- message_bot:把事情交给另一个 Bot,不用判断长短;收到回执后可以结束本轮。Bot 会独立完成,结果回到这里。重试复用 request_id;回执仅代表受理。对方正忙时这条活会排队,这时不要只回一句「已排队」就完事:回执里有接手方(bot_id)和这条活的状态,用一句话告诉用户「排在 Worker 后面」,他要是想停就 cancel_tasks 停这条活。", 'brief.tool.helper': "- start_helper:需要隔离执行上下文时,可让后台助手完成工作,结果仍回到当前聊天。它与找其他 Bot 帮忙具有相同的受理、结果回传和取消语义;无需按任务长短或工具次数分类。交代清楚目标、约束和验收标准,收到回执后结束本轮,最终产出回来后验收并告知用户;不足时补做。向用户自然地说明你会去处理,不要讲 helper、调度方式或内部编号。", 'brief.tool.postGroup': "- post_group(仅限单聊):用户让群讨论或继续工作时,按群名发送要求。使用稳定 request_id,受理后结束本轮,不要把受理当作完成。群里的讨论继续,结果回到发起聊天。遇到暂停的讨论,直接补充要求即可继续,不需要任务编号。", 'brief.tool.memory': '- remember / forget / recall:保存、删除、查找记忆', @@ -316,7 +316,7 @@ export default { 'mcp.p.group': '群聊名称或 group_id', 'mcp.p.postMessage': '要在群里开工的完整任务说明,包括背景和期望的输出', 'mcp.t.list_team': '列出 MiniMax Bot 团队里的所有 Bot 和群聊(名称、角色、id、成员、管理员)。', - 'mcp.t.message_bot': "把一件事交给另一个 Bot,持久受理后立即返回任务回执,不用判断短问答还是长任务。对方忙时排队;收到回执不代表完成。结果自动回到 Mini App 发起聊天。可用稳定 request_id 去重重试;外部主会话须用 get_tasks 查询结果。对方忙时这条活会排在他后面:想知道他在忙什么就 get_tasks,要停就用 cancel_tasks,编号只留给工具用,不要念给用户。", + 'mcp.t.message_bot': "把一件事交给另一个 Bot,持久受理后立即返回任务回执,不用判断短问答还是长任务。对方忙时排队;收到回执不代表完成。结果自动回到 Mini App 发起聊天。可用稳定 request_id 去重重试;外部主会话须用 get_tasks 查询结果。对方忙时这条活会排在他后面:回执里的 bot_id 是接手方、status 是这条活自己的状态,把这个讲给用户;用户想停就用 cancel_tasks 停这条活,编号只留给工具用,不要念给用户。", 'mcp.t.start_helper': "在隔离的执行上下文中完成工作,持久受理后可结束本轮,用户能继续聊天。任务完成后回到原 Bot 验收并告知用户。交代自包含的目标、已知条件、约束和交付物;无需按长短或工具调用次数分类。", 'brief.tool.helperOff': '- start_helper:只有用户明确要你把活放到后台(说了「放到后台」「异步做」「不要阻塞」)时才用。其余任务自己做完再回复。用了之后跟用户自然地说「我去查查看,跑完告诉你」,不要说「helper」或内部编号。', 'mcp.t.list_helpers': '查看你放到后台的任务(主 Bot 能看到所有 Bot 的):状态、耗时,已完成的附报告摘要。', @@ -364,7 +364,7 @@ export default { 'notice.groupCreated': 'Group created. The admin {admin} replies by default; use @name to call on a specific Bot.', "notice.noProgress": "Repeated handoffs without new tool progress detected. Discussion paused; add instructions to continue. Independent tasks keep running.", "notice.hopLimit": "The relay limit ({max} hops) is reached; this round wraps up here.", - 'brief.tool.tasks': "- dispatch_tasks: hand work to several Bots in one request. Like message_bot, admission is durable and results return to the source chat. Do not preconfigure result destinations or summarizers. get_tasks checks progress; cancel_tasks explicitly stops work. Do not expose task IDs or ask the user to select execution modes. External host chats have no callback and must query results. When the other Bot is busy, do not just say the work is queued: get_tasks first to find out what it is busy with and for how long, then tell the user in one sentence. If the user wants it stopped, use cancel_tasks and say how it was stopped. The ids are for the tools: do not read them out, but do tell the user what the query found.", + 'brief.tool.tasks': "- dispatch_tasks: hand work to several Bots in one request. Like message_bot, admission is durable and results return to the source chat. Do not preconfigure result destinations or summarizers. get_tasks checks progress; cancel_tasks explicitly stops work. Do not expose task IDs or ask the user to select execution modes. External host chats have no callback and must query results. When the other Bot is busy, do not answer with 'queued' and stop there: the receipt names who the work is queued behind (bot_id is the Bot that took it) and the state of this piece of work, so tell the user it is queued behind Worker. If the user wants it stopped, use cancel_tasks on this work. Say plainly that get_tasks reports the work in your own hands, not the batch the other Bot is busy with — that one cannot be queried, and do not present it as if it had been. The ids are for the tools: do not read them out, but do tell the user the state you found.", 'mcp.t.dispatch_tasks': "Persist a batch of tasks and immediately return batch_id/task_id, without classifying work as short or long. Different Bots can run in parallel; each private chat is serial and shares Host capacity. Required request_id deduplicates identical retries; changed content conflicts. Task outputs return to the source chat for verification by the caller Bot. External host chats must query get_tasks; no callback is available.", "mcp.t.get_tasks": "Query exactly one of batch_id or task_id. wait_ms is bounded to 20000 and only waits for a state change; it never cancels work. States: queued/running/waiting_for_tasks/waiting_for_user/paused/done/failed/cancelled/unknown. Unknown is not a confirmed failure: do not automatically redispatch. An unknown task is never replayed, but its batch still closes and states that the outcome is unknown. Read full single-task outputs with result_offset/next_result_offset; when the chat record is gone only the first part comes back, flagged with result_truncated. Only the 30 most recent settled batches are kept in full; older ones leave a record without the reply (at most 1,000 records), so their batch_id still answers and the reply is read from the chat record; a request_id older than that is no longer known, and the same work would start again.", "task.unknownOutcome": "Outcome unknown: this run's result could not be confirmed (it may have finished, or may not have). It is not retried automatically; send a fresh request if you still need the result.", @@ -580,7 +580,7 @@ export default { 'brief.toolsWhere': 'These tools come from the MCP server minimax-bot. If you do not see them in your tool list, search for "minimax-bot" with tool_search first.', 'brief.callerId': 'Always set caller_bot_id to {id}.', 'brief.tool.list': '- list_team: see the Bots and groups on the team', - 'brief.tool.message': "- message_bot: hand work to another Bot without classifying it as short or long. End your turn after admission; the Bot works independently and returns the result here. Reuse request_id on retry. Admission does not mean completion. If that Bot is busy the work queues behind it: do not answer with 'queued' and stop there — get_tasks to find out what it is busy with, tell the user in one sentence, and use cancel_tasks if they want it stopped.", + 'brief.tool.message': "- message_bot: hand work to another Bot without classifying it as short or long. End your turn after admission; the Bot works independently and returns the result here. Reuse request_id on retry. Admission does not mean completion. If that Bot is busy the work queues behind it, and then do not answer with 'queued' and stop there: the receipt names the Bot that took it (bot_id) and the state of this piece of work, so tell the user it is queued behind that Bot, and use cancel_tasks on this work if they want it stopped.", 'brief.tool.helper': "- start_helper: use a background helper when an isolated execution context is useful. Admission, result delivery and cancellation follow the same semantics as handing work to another Bot; do not classify work by length or tool count. Give the goal, constraints and acceptance criteria, end the turn after admission, then verify the returned output and tell the user. Follow up if incomplete. Speak naturally about doing the work, without helper terminology or internal IDs.", 'brief.tool.postGroup': "- post_group (private chat only): when the user asks a group to work or continue, send the request by group name. Reuse request_id on retry and end the turn after admission; never call admission completion. Results return to the source chat. New instructions continue a safely paused discussion without requiring a task ID.", 'brief.tool.memory': '- remember / forget / recall: save, delete and search memory', @@ -637,7 +637,7 @@ export default { 'mcp.p.group': 'Group name or group_id', 'mcp.p.postMessage': 'The full task for the group, including background and the expected output', 'mcp.t.list_team': 'List every Bot and group on the MiniMax Bot team (name, role, id, members, admin).', - 'mcp.t.message_bot': "Hand work to another Bot and return a durable admission receipt immediately, for both short and long requests. Busy Bots queue the work. A receipt is not completion. Results return to the Mini App source chat. Reuse a stable request_id on retries. External host chats must query get_tasks for results. When the other Bot is busy the work queues behind it: use get_tasks to find out what it is busy with, use cancel_tasks to stop it, and keep the ids for the tools instead of reading them out.", + 'mcp.t.message_bot': "Hand work to another Bot and return a durable admission receipt immediately, for both short and long requests. Busy Bots queue the work. A receipt is not completion. Results return to the Mini App source chat. Reuse a stable request_id on retries. External host chats must query get_tasks for results. When the other Bot is busy the work queues behind it: the receipt names the Bot that took it (bot_id) and the state of this piece of work (status) — report that to the user, and use cancel_tasks to stop this work if they ask. Keep the ids for the tools instead of reading them out.", 'mcp.t.start_helper': "Work in an isolated execution context and return admission immediately so the user can keep chatting. The result returns to the caller Bot for verification and delivery. Provide a self-contained goal, context, constraints and deliverables; no short/long or tool-count classification is required.", 'brief.tool.helperOff': '- start_helper: use it only when the user explicitly asks for the work to go to the background ("run it in the background", "do it async", "do not block"). Do everything else yourself. When you do use it, say it naturally: "I\'ll go look into it and get back to you" — never say "helper" or show the internal id.', 'mcp.t.list_helpers': "List the tasks you put in the background (a main Bot sees every Bot's): status, time taken, and a report excerpt for finished ones.", diff --git a/plugins/minimax-ai/minimax-bot/tests/brief-busy-tools.test.mjs b/plugins/minimax-ai/minimax-bot/tests/brief-busy-tools.test.mjs index 5308c62b..c7eee7ba 100644 --- a/plugins/minimax-ai/minimax-bot/tests/brief-busy-tools.test.mjs +++ b/plugins/minimax-ai/minimax-bot/tests/brief-busy-tools.test.mjs @@ -1,47 +1,176 @@ +// @ts-check +// What a Bot says when the Bot it handed work to is busy. +// +// The reply the plugin produced was a restatement of the tool description: 「这个 Bot 正在忙别的 +// 任务,已排队,轮到后自动发送」. That sentence is in no string file of this plugin — the model +// wrote it because the brief said "busy Bots queue the work" and nothing else. +// +// The tools to answer the question were there the whole time, but what the brief asks for has to +// match what the tools can actually do. get_tasks takes exactly one of task_id or batch_id and +// reports the work in the caller's own hands. There is no call that lists what the other Bot is +// busy with — list_helpers covers background helpers, not delegated work. So a brief that says +// "look up what he is busy with" asks for a call that does not exist, and the model answers with +// the one thing it can see: the piece of work it just handed over, still queued. +// +// These tests hold the wording to the contract: what the brief tells the Bot to do has to be +// doable with the tools as they are, and the state it points at has to be the state that exists. + import assert from 'node:assert/strict'; import { test } from 'node:test'; +import { mkdtemp, rm } from 'node:fs/promises'; +import { tmpdir } from 'node:os'; +import { join } from 'node:path'; + +import { Store } from '../miniapp/node/store.mjs'; +import { MemoryStore } from '../miniapp/node/memory.mjs'; +import { Engine } from '../miniapp/node/engine.mjs'; +import { Team } from '../miniapp/node/team.mjs'; +import { createMcpHandler } from '../miniapp/node/mcp.mjs'; +import { setLocale } from '../miniapp/node/i18n.mjs'; import strings from '../miniapp/node/strings.mjs'; -// A Bot that is told "busy Bots queue the work" and nothing else answers the way it answered -// in MiniMax开放平台用户交流群: 「这个 Bot 正在忙别的任务,已排队,轮到后自动发送」 — it cannot -// say what the other Bot is doing, and the user has no way to stop it. The tools were always -// there (get_tasks / cancel_tasks / list_schedules / delete_schedule); the brief never said to -// use them when something is busy, and it forbade reading the ids out without saying they are -// still for the tools. +const TOOL_NAMES = [ + 'list_team', 'message_bot', 'dispatch_tasks', 'get_tasks', 'cancel_tasks', 'post_group', + 'start_helper', 'list_helpers', 'stop_helper', +]; +// The wording has to say what to do, and it has to stay inside what the tools can do. for (const lang of ['zh', 'en']) { - test(`the brief tells a Bot to look before it says "queued" (${lang})`, () => { + test(`the brief says what to do when the other Bot is busy (${lang})`, () => { const tasks = strings[lang]['brief.tool.tasks']; const message = strings[lang]['brief.tool.message']; for (const text of [tasks, message]) { - assert.match(text, /get_tasks/u, 'the Bot is told to look the busy Bot up'); + assert.match(text, /cancel_tasks/u, 'the Bot is told how to stop the work'); + assert.match(text, /bot_id/u, 'the receipt is named as the source of who took the work'); } - assert.match(tasks, /cancel_tasks/u, 'the Bot is told how to stop it'); - assert.match(message, /cancel_tasks/u, 'the Bot is told how to stop it from message_bot too'); + // The receipt is where the answer comes from, not a query about the other Bot. + assert.match(tasks, lang === 'zh' ? /回执/u : /receipt/u); }); - test(`the ids stay for the tools, and what they find is told to the user (${lang})`, () => { + test(`the brief does not ask for a call that does not exist (${lang})`, () => { + const tasks = strings[lang]['brief.tool.tasks']; + const message = strings[lang]['brief.tool.message']; + // "what he is busy with" and "how long he has been busy" need a listing that is not there: + // get_tasks reports one known id, and nothing lists the other Bot's work. + const forbidden = lang === 'zh' + ? [/他在忙什么/u, /忙了多久/u] + : [/what it is busy with/u, /for how long/u]; + for (const text of [tasks, message]) { + for (const pattern of forbidden) { + // The brief may name the limit — it may not promise the lookup. + assert.doesNotMatch(text, pattern, `the brief must not promise a lookup that does not exist: ${pattern}`); + } + } + }); + + test(`the ids stay for the tools, and the state is told to the user (${lang})`, () => { const tasks = strings[lang]['brief.tool.tasks']; - // The ids are still not read out to the user... assert.match(tasks, lang === 'zh' ? /不要向用户暴露任务编号/u : /Do not expose task IDs/u); - // ...but the answer has to say that the ids are for the tools and that the findings are not. assert.match(tasks, lang === 'zh' ? /编号是给工具用的/u : /The ids are for the tools/u); - assert.match(tasks, lang === 'zh' ? /查到的东西要讲给用户听/u : /do tell the user what the query found/u); }); test(`a question about a schedule is answered from list_schedules (${lang})`, () => { const schedule = strings[lang]['brief.tool.schedule']; assert.match(schedule, /list_schedules/u); assert.match(schedule, /delete_schedule/u); - // And the limit of that list is stated: something the Host runs elsewhere is not in it. assert.match(schedule, lang === 'zh' ? /宿主别处的定时任务不在这里/u : /a schedule the Host runs elsewhere is neither here/u); }); - test(`both languages say the same thing about a busy Bot (${lang})`, () => { + test(`both languages name the same tools (${lang})`, () => { for (const key of ['brief.tool.tasks', 'brief.tool.message', 'mcp.t.message_bot', 'brief.tool.schedule']) { - assert.equal(typeof strings[lang][key], 'string', `${key} missing in ${lang}`); - assert.ok(strings[lang][key].length > 0, `${key} empty in ${lang}`); - assert.ok(!strings[lang][key].includes('undefined'), `${key} has an empty placeholder in ${lang}`); + const text = strings[lang][key]; + assert.equal(typeof text, 'string', `${key} missing in ${lang}`); + assert.ok(text.length > 0, `${key} empty in ${lang}`); + assert.ok(!text.includes('undefined'), `${key} has an empty placeholder in ${lang}`); } }); } + +// The tools the brief points at have to exist and be reachable. +test('the tools the brief points at are on the surface', async () => { + const dir = await mkdtemp(join(tmpdir(), 'bot-brief-tools-')); + const store = new Store(dir); + const memory = new MemoryStore(dir); + await store.init(); + await memory.init(); + setLocale('en'); + const engine = new Engine({ store, memory, logger: { warn() {} }, broadcast: () => {}, retryDelaysMs: [] }); + const team = new Team({ store, memory, engine, broadcast() {} }); + const handle = createMcpHandler({ team, engine }); + const listed = await new Promise((resolve) => { + let body = ''; + handle({ method: 'POST' }, { writeHead() { return this; }, end(chunk) { body = chunk; } }, + { jsonrpc: '2.0', id: 1, method: 'tools/list' }); + setTimeout(() => resolve(JSON.parse(body)), 100); + }); + const names = (listed.result?.tools ?? []).map((tool) => tool.name); + for (const name of TOOL_NAMES) { + assert.ok(names.includes(name), `the tool ${name} is not on the surface`); + } + await engine.dispose?.(); + await memory.dispose?.(); + await rm(dir, { recursive: true, force: true }); +}); + +// The state the brief points at has to be the state that exists: the receipt names the Bot that +// took the work, and the status of that piece of work — not the state of the other Bot's work. +test('the receipt names the Bot that took the work and the state of that work', async () => { + const dir = await mkdtemp(join(tmpdir(), 'bot-brief-receipt-')); + const store = new Store(dir); + const memory = new MemoryStore(dir); + await store.init(); + await memory.init(); + setLocale('en'); + const engine = new Engine({ store, memory, logger: { warn() {} }, broadcast: () => {}, retryDelaysMs: [] }); + const team = new Team({ store, memory, engine, broadcast() {} }); + const handle = createMcpHandler({ team, engine }); + const rpc = async (name, args) => { + let response; + await handle({ method: 'POST' }, { writeHead() { return this; }, end(body) { response = JSON.parse(body); } }, + { jsonrpc: '2.0', id: 1, method: 'tools/call', params: { name, arguments: args } }); + const text = response.result?.content?.find((c) => c.type === 'text')?.text; + return JSON.parse(text); + }; + + const chief = store.state.bots[0]; + const worker = { id: 'bot_worker', name: 'Worker', role: 'Coder', instructions: 'w', main: false }; + store.state.bots.push(worker); + await store.save(); + + // The worker is occupied, so the hand-off queues behind it. + let release; + const held = new Promise((done) => { release = done; }); + engine.agent = { + async run(input, options) { + options.onEvent?.({ type: 'turn.started', sessionId: 's', turnId: 't' }); + if (String(input.text).includes('OCCUPY')) { await held; return { status: 'finished', text: 'done' }; } + return { status: 'finished', text: 'ok', sessionId: 's', turnId: 't' }; + }, + }; + engine.runBotTurn({ bot: worker, chatId: `bot:${worker.id}`, text: 'OCCUPY', kind: 'private' }); + await new Promise((done) => setTimeout(done, 120)); + + const receipt = await rpc('message_bot', { to: 'Worker', message: 'do this thing', request_id: 'req_1' }); + const task = receipt.tasks?.[0]; + assert.ok(task, 'the receipt carries the work'); + // What the brief says the model can read off the receipt: + assert.equal(task.bot_id, worker.id, 'the receipt names the Bot that took the work'); + assert.equal(task.status, 'queued', 'the receipt carries the state of this piece of work'); + // And what it must not claim: the state of the other Bot's work is not in there. + assert.equal(task.started_at, undefined, 'the receipt carries no start time of the other work'); + + // get_tasks reports the work in the caller's hands, by the id from the receipt. + const queried = await rpc('get_tasks', { task_id: task.task_id }); + assert.equal(queried.tasks?.[0]?.status, 'queued'); + assert.equal(queried.tasks?.[0]?.bot_id, worker.id); + + // list_helpers does not list delegated work — so the brief may not promise that lookup. + const helpers = await rpc('list_helpers', {}); + assert.deepEqual(helpers, [], 'delegated work is not in list_helpers'); + + release(); + await new Promise((done) => setTimeout(done, 150)); + await engine.dispose?.(); + await memory.dispose?.(); + await rm(dir, { recursive: true, force: true }); +});