@mobius-os/mobius 0.3.51 → 0.3.52

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mobius-os/mobius",
3
- "version": "0.3.51",
3
+ "version": "0.3.52",
4
4
  "type": "module",
5
5
  "description": "Mobius terminal client. Reuses Mobius frontend TypeScript types and jsonl entry shapes.",
6
6
  "bin": {
@@ -157,7 +157,7 @@ export function ChatScreen({ client, ready, webUserId, resumeSessionId, onClear,
157
157
  // the indicator falls back to the normal Working label for every turn.
158
158
  const firstQueryInFlight = !resumeSessionId && !chat.entries.some(isAssistantOutput)
159
159
 
160
- // 用户输入去重 (对齐 web viewer/rounds.ts buildRounds): codex 同一提问的 3 形态
160
+ // 用户输入去重 (对齐 web viewer/display-dedup.ts): codex 同一提问的 3 形态
161
161
  // (type:user / response_item.message[user] / event_msg.user_message) 合并成 1 条,
162
162
  // 避免在累积视图里把同一条提问显示多次.
163
163
  const dedupedEntries = useMemo(() => dedupeUserEntries(chat.entries), [chat.entries])
@@ -679,7 +679,7 @@ export function toolLabel(name: string): string {
679
679
  return TOOL_LABEL[n] ?? n
680
680
  }
681
681
 
682
- // ── 用户输入去重 (对齐 web viewer/rounds.ts buildRounds) ──────────────────────
682
+ // ── 用户输入去重 (对齐 web viewer/display-dedup.ts) ──────────────────────────
683
683
  // codex 一次用户输入在 jsonl 里以 3 种形态出现 (type:user / response_item.message[role=user]
684
684
  // / event_msg.user_message), 文本相同. 若与上一条用户输入文本相同, 且之间还没出现任何
685
685
  // agent 输出, 则视为同一次输入的重复入口 → 丢弃, 避免 TUI 把同一条提问显示多次.
@@ -735,12 +735,51 @@ export function isAssistantOutput(e: AnyEntry): boolean {
735
735
  return false
736
736
  }
737
737
 
738
+ // 开轮 kind 白名单 (与后端 mobius-kinds.ts 同源; TUI 是独立包, 只能各存一份)
739
+ // Round-opening kinds, same rule as the backend's mobius-kinds.ts (the TUI is a separate package)
740
+ const ROUND_OPENING_KINDS = new Set(['user', 'user-sp-command', 'mobius-multiagent', 'mobius-com', 'mobius-extension'])
741
+ // 来源枚举之前的旧 kind, 让改动前入库的老会话仍能认出自己的开轮卡
742
+ // The kinds used before the enum; they keep openers recognisable in sessions stored back then
743
+ const LEGACY_ROUND_OPENING_KINDS = new Set(['user_input', 'compact'])
744
+
745
+ /*
746
+ * True when this card is the user prompt that opened its round. The kind decides: a session prompt
747
+ * (or a slash command in it) and one 小莫 asks itself open a round, every other kind does not.
748
+ */
749
+ export function isRoundOpenerEntry(e: AnyEntry): boolean {
750
+ // 只认 Mobius 自己写的 user 卡,agent 侧的原生副本没有 mobius 块
751
+ // Only Mobius-authored user cards count, the agent's own copies carry no mobius block
752
+ if (e?.type !== 'user') return false
753
+ const kind = e?.mobius?.kind
754
+ if (typeof kind !== 'string') return false
755
+ return ROUND_OPENING_KINDS.has(kind) || LEGACY_ROUND_OPENING_KINDS.has(kind)
756
+ }
757
+
758
+ /*
759
+ * Drops duplicate user-input entries while keeping the round-opener card. One user input reaches
760
+ * the jsonl in several shapes (type:user / response_item.message[user] / event_msg.user_message)
761
+ * with the same text; the opener is the authoritative one, so every other shape steps aside.
762
+ * The older rule is kept as a fallback for backends that emit no opener card at all.
763
+ */
738
764
  export function dedupeUserEntries(entries: AnyEntry[]): AnyEntry[] {
765
+ // 先收集开轮卡文本,用来判断某条输入是否已由开轮卡承载
766
+ // Collect the opener texts first, they mark inputs already carried by an opener card
767
+ const openerTexts = new Set<string>()
768
+ for (const e of entries) {
769
+ if (!isRoundOpenerEntry(e)) continue
770
+ const text = userTextOf(e)
771
+ if (text) openerTexts.add(text)
772
+ }
739
773
  let lastUserText = ''
740
774
  let seenAssistantAfter = false
741
775
  return entries.filter((e) => {
742
776
  const text = userTextOf(e)
743
777
  if (text) {
778
+ // ✨ 核心:同文的非开轮形态一律让位,开轮卡是这条输入的权威载体
779
+ // ✨ Core: any non-opener form with the same text gives way to the opener card
780
+ if (openerTexts.has(text) && !isRoundOpenerEntry(e)) return false
781
+ // 相邻同文且其间没有 agent 输出,视为同一次输入的重复落盘
782
+ // Same text with no agent output in between is one input landing twice
744
783
  if (text === lastUserText && !seenAssistantAfter) return false
745
784
  lastUserText = text
746
785
  seenAssistantAfter = false