botmux 2.36.1 → 2.36.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -33,6 +33,7 @@ import { logger } from './utils/logger.js';
33
33
  import { invalidWorkingDirs } from './utils/working-dir.js';
34
34
  import { firstPositional } from './cli/arg-utils.js';
35
35
  import { formatBotInfoEntriesForCli, formatChatBotsForCli, } from './cli/bots-list-output.js';
36
+ import { buildFooterAddressing, hasKnownBotMention, knownBotOpenIdsFromCrossRef, } from './utils/bot-routing.js';
36
37
  import { isLocale, setDefaultLocale, SUPPORTED_LOCALES } from './i18n/index.js';
37
38
  import { readGlobalConfig, setGlobalLocale, globalConfigPath } from './global-config.js';
38
39
  // Resolve the CLI's UI locale once from the global config file, so subsequent
@@ -2456,20 +2457,6 @@ function argValues(args, ...flags) {
2456
2457
  // daemon's bridge fallback path can produce identical cards. cmdSend
2457
2458
  // keeps using `buildCardBodyElements` and `hasMarkdown` from there.
2458
2459
  import { buildCardBodyElements, hasMarkdown } from './im/lark/md-card.js';
2459
- /**
2460
- * Decide who the reply card should @ in its footer.
2461
- *
2462
- * Non-oncall chats: `发送给: @<owner>`.
2463
- * Oncall chats: `发送给: @<last caller>` (falls back to owner if unknown) —
2464
- * permission is governed by allowedUsers, so there's no per-chat list to cc.
2465
- */
2466
- function buildFooterAddressing(s, oncall) {
2467
- const owner = s.ownerOpenId;
2468
- const caller = s.lastCallerOpenId ?? owner;
2469
- if (!oncall)
2470
- return { sendTo: owner, cc: [] };
2471
- return { sendTo: caller, cc: [] };
2472
- }
2473
2460
  async function cmdSend(rest) {
2474
2461
  // Safety gate: a CLI agent running inside a workflow subagent (Slice F)
2475
2462
  // must not chat-post directly — chat-facing side effects are reserved
@@ -2616,12 +2603,14 @@ async function cmdSend(rest) {
2616
2603
  // "获取群组中其他机器人和用户@当前机器人的消息"权限),不再走任何本地
2617
2604
  // 转发——botmux 历史上为绕过 Lark 不投递跨 bot 事件搞过 signal-file,
2618
2605
  // 那套已经在该权限上线后整体下线。
2606
+ let botEntries = [];
2607
+ let crossRef = {};
2619
2608
  try {
2620
2609
  const dataDir = resolveDataDir();
2621
2610
  const botInfoPath = join(dataDir, 'bots-info.json');
2622
- const botEntries = existsSync(botInfoPath) ? JSON.parse(readFileSync(botInfoPath, 'utf-8')) : [];
2611
+ botEntries = existsSync(botInfoPath) ? JSON.parse(readFileSync(botInfoPath, 'utf-8')) : [];
2623
2612
  const crossRefPath = join(dataDir, `bot-openids-${appId}.json`);
2624
- const crossRef = existsSync(crossRefPath)
2613
+ crossRef = existsSync(crossRefPath)
2625
2614
  ? JSON.parse(readFileSync(crossRefPath, 'utf-8'))
2626
2615
  : {};
2627
2616
  const alreadyMentioned = new Set(mentions.map(m => m.open_id));
@@ -2629,10 +2618,16 @@ async function cmdSend(rest) {
2629
2618
  // prefix ("Claude") when both could match — break-on-first-hit otherwise
2630
2619
  // routes "@Claude分身" to Claude.
2631
2620
  const sortedEntries = [...botEntries].sort((a, b) => (b.botName?.length ?? 0) - (a.botName?.length ?? 0));
2621
+ const selfAliases = new Set(botEntries
2622
+ .filter(entry => entry.larkAppId === appId)
2623
+ .flatMap(entry => [entry.botName, entry.cliId])
2624
+ .filter((name) => !!name)
2625
+ .map(name => name.toLowerCase()));
2632
2626
  for (const entry of sortedEntries) {
2633
2627
  if (!entry.botName || entry.larkAppId === appId)
2634
2628
  continue;
2635
- const names = [entry.botName, entry.cliId].filter(Boolean);
2629
+ const names = [entry.botName, entry.cliId]
2630
+ .filter((name) => !!name && !selfAliases.has(name.toLowerCase()));
2636
2631
  for (const name of names) {
2637
2632
  const escName = name.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
2638
2633
  // Boundary: lookbehind blocks only ASCII word chars (so `user@Claude`
@@ -2661,6 +2656,15 @@ async function cmdSend(rest) {
2661
2656
  }
2662
2657
  }
2663
2658
  catch { /* best-effort */ }
2659
+ const explicitKnownBotMention = hasKnownBotMention(text, mentions, botEntries, crossRef, appId);
2660
+ const knownBotOpenIds = knownBotOpenIdsFromCrossRef(crossRef, botEntries, appId);
2661
+ const footerAddressing = sendTopLevel
2662
+ ? { sendTo: undefined, cc: [] }
2663
+ : buildFooterAddressing(s, {
2664
+ isOncall: !!oncallEntry,
2665
+ hasExplicitBotMention: explicitKnownBotMention,
2666
+ knownBotOpenIds,
2667
+ });
2664
2668
  // Decide: interactive card (renders markdown) vs. post (plain text).
2665
2669
  // Explicit --card / --text wins; otherwise auto-detect markdown syntax.
2666
2670
  const useCard = forceCard || (!forceText && hasMarkdown(text));
@@ -2724,14 +2728,13 @@ async function cmdSend(rest) {
2724
2728
  const elements = mdWithImages ? buildCardBodyElements(mdWithImages) : [];
2725
2729
  // Footer: de-emphasized markdown (v2 dropped the `note` tag). Use small
2726
2730
  // text size + grey font tag so it reads like a footnote below the hr.
2727
- // Oncall groups: `发送给` targets whoever triggered this turn (may not
2728
- // be the session owner). Non-oncall: keep owner-only behaviour.
2731
+ // Oncall groups usually address whoever triggered this turn (may not be
2732
+ // the session owner). Bot recipients are filtered out so footer chrome
2733
+ // cannot accidentally wake a sibling bot.
2729
2734
  const footerParts = ['[botmux](https://github.com/deepcoldy/botmux)'];
2730
2735
  // Top-level publish has no specific recipient — drop "发送给/cc" addressing
2731
2736
  // so the message doesn't @ the session owner who isn't even in the target chat.
2732
- const addressing = sendTopLevel
2733
- ? { sendTo: undefined, cc: [] }
2734
- : buildFooterAddressing(s, oncallEntry);
2737
+ const addressing = footerAddressing;
2735
2738
  if (addressing.sendTo)
2736
2739
  footerParts.push(`发送给:<at id=${addressing.sendTo}></at>`);
2737
2740
  if (addressing.cc.length > 0) {
@@ -2787,11 +2790,9 @@ async function cmdSend(rest) {
2787
2790
  }
2788
2791
  }
2789
2792
  // Footer: mirror the card layout — a blank paragraph separates the body
2790
- // from the addressing line(s). `发送给: @<caller>` always. Top-level
2791
- // publish has no specific recipient skip addressing entirely.
2792
- const addressing = sendTopLevel
2793
- ? { sendTo: undefined, cc: [] }
2794
- : buildFooterAddressing(s, oncallEntry);
2793
+ // from the addressing line(s). Top-level publish has no specific
2794
+ // recipient; bot recipients are filtered out by footerAddressing.
2795
+ const addressing = footerAddressing;
2795
2796
  if (addressing.sendTo || addressing.cc.length > 0) {
2796
2797
  if (postContent.length > 0)
2797
2798
  postContent.push([{ tag: 'text', text: '' }]);