Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
c221c6a
完善原生对话入场与工具活动记录
taekchef Sep 17, 2026
7139cd7
让原生对话真正连续呈现并修复完成时跳字
taekchef Sep 17, 2026
d91e86f
fix: surface provider search activity in conversation
taekchef Sep 17, 2026
dfe1bd2
fix: show searchable detail in compact tool activity
taekchef Sep 17, 2026
e13f891
feat: complete local tool activity details and outcomes
taekchef Sep 17, 2026
b3b15ed
fix: inline tool activity groups in conversation flow
taekchef Sep 17, 2026
64c5728
fix: retain animated feedback throughout tool execution
taekchef Sep 17, 2026
18e2e2d
fix: size inline activities to content and retain streaming footer state
taekchef Sep 17, 2026
73843c6
fix: keep activity titles stable and omit unsolicited execution plans
taekchef Sep 17, 2026
38ef30b
fix: share Chinese emphasis rules with Catalyst conversation rendering
taekchef Sep 17, 2026
5840656
fix: preserve emphasis before Chinese closing punctuation
taekchef Sep 17, 2026
cfb3e1e
Polish tool activity choreography and streaming Markdown display
taekchef Sep 17, 2026
f3df964
Distinguish web reads from searches in tool activity
taekchef Sep 17, 2026
e041bef
Keep appended text fading across rendered paragraph terminators
taekchef Sep 17, 2026
0faf179
Keep incoming emphasis markers pending until text arrives
taekchef Sep 17, 2026
df7029d
Show live search context and preserve current answer intent
taekchef Sep 17, 2026
edb6a3e
Preserve existing contextual answer instructions
taekchef Sep 17, 2026
02038dd
Remove shortest-answer directive while retaining context
taekchef Sep 17, 2026
a2229d1
Keep conversation presentation merge independent of prompt changes
taekchef Sep 17, 2026
5e81a23
Merge remote-tracking branch 'origin/main' into codex/conversation-flow
taekchef Sep 17, 2026
3d93db1
Preserve native Markdown spacing after main integration
taekchef Sep 17, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 70 additions & 2 deletions App/Sources/BlockView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ final class BlockView: UIView, UITextViewDelegate {
private let selectionOverlay = CAShapeLayer()
private var lastWidth: CGFloat = 0
private var lastHeight: CGFloat = 0
private var displayedText = ""
private var displayedWidth: CGFloat = 0
private let revealMask = CALayer()
private let settledTextMask = CAShapeLayer()
private var revealingText: [(range: NSRange, layer: CAShapeLayer, until: CFTimeInterval)] = []
private var revealCleanup: DispatchWorkItem?

override init(frame: CGRect) {
super.init(frame: frame)
Expand Down Expand Up @@ -132,6 +138,66 @@ final class BlockView: UIView, UITextViewDelegate {
accessibilityIdentifier = block.id
}

/// Fade only newly appended glyphs. Settled text is never redrawn with a lower opacity.
func revealAppendedText(animated: Bool) {
// Paragraph terminators belong to the renderer, not the growing text.
// Keeping them in the prefix makes every append look like a replacement.
let current = label.attributedText.string.replacingOccurrences(of: "[\\r\\n]+$", with: "", options: .regularExpression)
let previous = displayedText
defer { displayedText = current; displayedWidth = bounds.width }
guard animated, !preparedLabel.isHidden else { finishTextReveal(); return }
guard current != previous else { return }
guard current.hasPrefix(previous), displayedWidth == 0 || displayedWidth == bounds.width else {
finishTextReveal(); return
}
let range = NSRange(location: previous.utf16.count, length: current.utf16.count - previous.utf16.count)
guard range.length > 0 else { return }
let now = CACurrentMediaTime()
revealingText.removeAll { $0.until <= now }
let layer = CAShapeLayer()
layer.fillColor = UIColor.black.cgColor
revealingText.append((range, layer, now + 0.32))
let settled = CGMutablePath()
settled.addRect(preparedLabel.bounds)
CATransaction.begin()
CATransaction.setDisableActions(true)
revealMask.frame = preparedLabel.bounds
settledTextMask.frame = preparedLabel.bounds
settledTextMask.fillColor = UIColor.black.cgColor
settledTextMask.fillRule = .evenOdd
for item in revealingText {
let path = CGMutablePath()
for rect in textGeometry().rects(for: item.range) {
let glyphs = CGRect(x: rect.minX, y: bounds.height - rect.maxY, width: rect.width, height: rect.height)
path.addRect(glyphs)
settled.addRect(glyphs)
}
item.layer.frame = preparedLabel.bounds
item.layer.path = path
}
settledTextMask.path = settled
revealMask.sublayers = [settledTextMask] + revealingText.map(\.layer)
preparedLabel.layer.mask = revealMask
CATransaction.commit()
let fade = CABasicAnimation(keyPath: "opacity")
fade.fromValue = 0
fade.toValue = 1
fade.duration = 0.32
fade.timingFunction = CAMediaTimingFunction(name: .easeOut)
layer.add(fade, forKey: "stream-reveal")
revealCleanup?.cancel()
let cleanup = DispatchWorkItem { [weak self] in self?.finishTextReveal() }
revealCleanup = cleanup
DispatchQueue.main.asyncAfter(deadline: .now() + 0.32, execute: cleanup)
}

private func finishTextReveal() {
revealCleanup?.cancel(); revealCleanup = nil
revealingText.removeAll()
preparedLabel.layer.mask = nil
revealMask.sublayers = nil
}

func measure(width: CGFloat) -> CGFloat {
guard let record else { return 1 }
if lastWidth != width { geometry = nil }
Expand All @@ -158,7 +224,7 @@ final class BlockView: UIView, UITextViewDelegate {
markdown.frame = CGRect(x: 0, y: 0, width: width, height: lastHeight)
markdown.layoutIfNeeded()
case .workspaceAttachment:
lastHeight = max(120, record.height)
lastHeight = max(1, record.height)
case .card:
lastHeight = record.collapsed ? 48 : 204
draft.isHidden = record.collapsed; save.isHidden = record.collapsed
Expand All @@ -175,6 +241,7 @@ final class BlockView: UIView, UITextViewDelegate {
super.layoutSubviews()
guard let record else { return }
if bounds.width != lastWidth { geometry = nil; lastWidth = bounds.width }
if displayedWidth != 0, displayedWidth != bounds.width { finishTextReveal() }
switch record.kind {
case .markdown:
if preparedLabel.isHidden { markdown.frame = bounds }
Expand Down Expand Up @@ -267,6 +334,7 @@ final class BlockView: UIView, UITextViewDelegate {
func displaySelection(_ range: NSRange?) {
let path = CGMutablePath()
if let range, range.length > 0 {
finishTextReveal()
for rect in textGeometry().rects(for: range) {
path.addRect(CGRect(x: rect.minX, y: bounds.height - rect.maxY, width: rect.width, height: rect.height))
}
Expand All @@ -287,7 +355,7 @@ final class BlockView: UIView, UITextViewDelegate {
return text
case let .card(source): return record.draft.isEmpty ? source : record.draft
case let .diagram(source): return source
case .workspaceAttachment: return "[互动内容]"
case let .workspaceAttachment(identifier): return identifier.hasPrefix("activity/") ? "" : "[互动内容]"
}
}
}
15 changes: 10 additions & 5 deletions App/Sources/CatalystConversationView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ struct CatalystConversationView: View {
displayedMessages: displayedMessages, floatingThreadID: floatingThreadID, onContentHeight: onContentHeight,
onFocusComposer: onFocusComposer, onReadingMessage: onReadingMessage).contentShape(Rectangle()) }
private struct Bridge: UIViewControllerRepresentable {
@Environment(\.weibeiReduceMotion) private var reduceMotion
@ObservedObject var workspace: WorkspaceStore
@ObservedObject var streaming: AgentStreamingState
var wideTypography: Bool
Expand All @@ -39,6 +40,8 @@ struct CatalystConversationView: View {
return controller
}
func updateUIViewController(_ controller: ConversationController, context: Context) {
controller.reduceMotion = reduceMotion
controller.reservesReplySpace = floatingThreadID == nil
controller.workspaceBodyWidth = bodyWidth
controller.readingMessageChanged = onReadingMessage
controller.contentHeightChanged = onContentHeight
Expand Down Expand Up @@ -82,8 +85,8 @@ struct CatalystConversationView: View {
session.messages = displayedMessages ?? workspace.messages
if let id = streaming.displayingMessageID,
streaming.displayingChatID == targetID,
let index = session.messages.firstIndex(where: { $0.id == id && $0.completionState == .generating }) {
session.messages[index].text = streaming.text
let index = session.messages.firstIndex(where: { $0.id == id }) {
session.messages[index] = streaming.applyingDisplayText(to: session.messages[index])
}
coordinator.enqueue(session, into: controller, refreshAppearance: appearanceChanged)
}
Expand Down Expand Up @@ -185,7 +188,9 @@ struct CatalystConversationView: View {
pending = nil
if displayedSessionID != session.id {
auxiliaryHosts.removeAll()
await controller.showSession(session)
let firstTurn = displayedSessionID != nil && previous.isEmpty
&& session.messages.contains { $0.completionState == .generating }
await controller.showSession(session, animateFirstTurn: firstTurn)
displayedSessionID = session.id
} else {
controller.updateSavedHistory(session.messages)
Expand Down Expand Up @@ -234,14 +239,14 @@ private struct CatalystMessageFooter: View {
@ObservedObject var streaming: AgentStreamingState
let wideTypography: Bool
let onHeight: (CGFloat) -> Void
private var message: AgentMessage { store.messages.first { $0.id == initial.id } ?? initial }
private var message: AgentMessage { streaming.applyingDisplayText(to: store.messages.first { $0.id == initial.id } ?? initial) }
var body: some View {
let text = streaming.isDisplaying(message.id) ? streaming.text : message.text
VStack(alignment: .leading, spacing: 8) {
if message.role == .user {
AgentBubble(message: message, isChatWideTypography: wideTypography)
} else {
if message.completionState == .generating && text.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty {
if message.completionState == .generating && !message.toolActivities.contains(where: { $0.state == .running }) && text.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty {
AgentThinkingIndicator(activityText: streaming.activityText, chatWideTypography: wideTypography)
}
AgentBubble(message: message, isChatWideTypography: wideTypography, showsBody: false)
Expand Down
92 changes: 89 additions & 3 deletions App/Sources/ConversationController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import QuartzCore
final class ConversationController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate, UITextViewDelegate {
let fixtureMode: Bool
var usesWorkspaceChrome = false
var reduceMotion = false
var reservesReplySpace = false
var auxiliaryView: ((LabMessage) -> UIView)?
var messageLink: ((URL, AgentMessage) -> Void)?
var interfaceLanguage: WeiBeiInterfaceLanguage = .chinese {
Expand Down Expand Up @@ -80,6 +82,10 @@ final class ConversationController: UIViewController, UICollectionViewDataSource
collection.keyboardDismissMode = .none
collection.accessibilityLabel = "会话消息列表"
flow.itemHeight = { [weak self] path in self?.itemHeight(at: path) ?? 0 }
flow.replyStartSection = { [weak self] in
guard let self, reservesReplySpace else { return nil }
return messages.lastIndex { $0.original?.role == .user }
}
for child in [toolbar, status, collection, input, send, latest] { view.addSubview(child) }
toolbar.spacing = 16; toolbar.alignment = .center
toolbar.addArrangedSubview(button("阅读区", symbol: "sidebar.left", action: { [weak self] in self?.toggleWorkspace?() }))
Expand Down Expand Up @@ -348,6 +354,7 @@ final class ConversationController: UIViewController, UICollectionViewDataSource
let block = message.blocks[path.item - 1]
let stale = block.width != bodyWidth
cell.show(body: store.view(for: block, width: bodyWidth))
cell.body?.revealAppendedText(animated: !reduceMotion && message.state == .streaming && followsLatest)
selection.paint(cell.body!)
// A paragraph scrolled in before the width converged was sized from its
// previous width; the frame in the layout catches up on the next turn.
Expand Down Expand Up @@ -484,7 +491,7 @@ final class ConversationController: UIViewController, UICollectionViewDataSource
if submitQuestion?(input.text) == true { input.text = "" }
}

func showSession(_ session: StudySession) async {
func showSession(_ session: StudySession, animateFirstTurn: Bool = false) async {
loadViewIfNeeded()
scenarioGeneration += 1
preparation?.cancel(); preparation = nil
Expand All @@ -502,6 +509,7 @@ final class ConversationController: UIViewController, UICollectionViewDataSource
messages.append(message)
}
collection.reloadData(); collection.layoutIfNeeded(); scrollToLatest()
if animateFirstTurn { for section in messages.indices { animateInsertion(in: section) } }
status.text = session.title
}

Expand All @@ -518,7 +526,7 @@ final class ConversationController: UIViewController, UICollectionViewDataSource
private func formattedMarkdown(_ value: AgentMessage, memo: AgentMessageMarkdownMemo) -> String {
// The original right-aligned user chip is hosted by the auxiliary row.
guard value.role == .assistant else { return usesWorkspaceChrome ? "" : value.text }
let text = AgentNativeMessageContent.markdown(text: value.text, blocks: value.contentBlocks)
let text = AgentNativeMessageContent.markdown(text: value.text, blocks: value.contentBlocks, activities: value.toolActivities)
return memo.outputs(text: text, sources: value.sources, language: interfaceLanguage).finalized
}

Expand Down Expand Up @@ -549,6 +557,23 @@ final class ConversationController: UIViewController, UICollectionViewDataSource
UIView.performWithoutAnimation { collection.insertSections(IndexSet(integer: messages.count - 1)) }
collection.layoutIfNeeded()
if followsLatest || value.role == .user { scrollToLatest() }
animateInsertion(in: messages.count - 1)
}
}

private func animateInsertion(in section: Int) {
guard !reduceMotion else { return }
for path in collection.indexPathsForVisibleItems where path.section == section {
guard let cell = collection.cellForItem(at: path) else { continue }
let isQuestion = messages[section].original?.role == .user
let travel = isQuestion ? max(8, collection.bounds.maxY - cell.frame.maxY - 16) : 8
cell.contentView.alpha = 0
cell.contentView.transform = CGAffineTransform(translationX: 0, y: travel)
UIView.animate(withDuration: isQuestion ? 0.42 : 0.24, delay: 0,
options: [.beginFromCurrentState, .curveEaseOut, .allowUserInteraction]) {
cell.contentView.alpha = 1
cell.contentView.transform = .identity
}
}
}

Expand Down Expand Up @@ -687,6 +712,10 @@ final class ConversationController: UIViewController, UICollectionViewDataSource
}
guard generation == scenarioGeneration else { return }
if answer.state != .stopped { answer.state = Task.isCancelled ? .stopped : .complete }
let previous = answer.blocks
_ = await store.prepare(answer, width: bodyWidth)
guard generation == scenarioGeneration else { return }
applyBlocks(answer, previous: previous)
refreshFooter(answer)
send.setImage(UIImage(systemName: "arrow.up.circle.fill"), for: .normal)
send.accessibilityLabel = "发送并重放固定回答"
Expand Down Expand Up @@ -1049,11 +1078,68 @@ final class ConversationController: UIViewController, UICollectionViewDataSource
let message = LabMessage(author: "检查样本", markdown: "第一段:中文与 emoji 👩🏽‍💻。\n\n第二段尚在增长")
_ = await store.prepare(message, width: bodyWidth)
let first = message.blocks[0]
let beforeAppend = store.view(for: message.blocks.last!, width: bodyWidth)
beforeAppend.revealAppendedText(animated: false)
let oldLength = beforeAppend.copyText().trimmingCharacters(in: .newlines).utf16.count
message.append(",尾字已经收到。")
_ = await store.prepare(message, width: bodyWidth)
try expect(message.blocks[0] === first, "流式更新替换了未改变的段落")
let rendered = store.view(for: message.blocks.last!, width: bodyWidth).copyText()
let growing = store.view(for: message.blocks.last!, width: bodyWidth)
growing.revealAppendedText(animated: true)
let rendered = growing.copyText()
try expect(rendered.contains("尾字已经收到。"), "流式尾字没有显示")
try expect(growing === beforeAppend, "新增文字替换了原生段落视图")
guard let mask = growing.label.layer.mask,
let settled = (mask.sublayers?.first as? CAShapeLayer)?.path,
let oldGlyph = growing.rect(for: 0), let newGlyph = growing.rect(for: oldLength) else {
throw Failure(message: "流式正文没有进入逐字淡入路径")
}
try expect(settled.contains(CGPoint(x: oldGlyph.midX, y: oldGlyph.midY), using: .evenOdd)
&& !settled.contains(CGPoint(x: newGlyph.midX, y: newGlyph.midY), using: .evenOdd),
"淡入遮罩重播了旧文字,或未覆盖新增文字")
try expect(mask.sublayers?.last?.animation(forKey: "stream-reveal") != nil, "新增文字没有淡入动画")
growing.revealAppendedText(animated: false)
try expect(growing.label.layer.mask == nil, "减少动态效果后仍保留文字动画")

let unfinished = LabMessage(author: "显示格式检查", markdown: "**尚未闭合")
unfinished.state = .streaming
_ = await store.prepare(unfinished, width: bodyWidth)
let live = store.view(for: unfinished.blocks[0], width: bodyWidth)
try expect(live.copyText().trimmingCharacters(in: .newlines) == "尚未闭合", "流式粗体仍显示原始星号")
try expect(unfinished.copyableMarkdown == "**尚未闭合", "显示修补污染了复制原文")
unfinished.state = .stopped
_ = await store.prepare(unfinished, width: bodyWidth)
try expect(store.view(for: unfinished.blocks[0], width: bodyWidth).copyText().trimmingCharacters(in: .newlines) == "**尚未闭合",
"停止后没有恢复真实原文排版")
let pending = LabMessage(author: "链接检查", markdown: "[来源](https://example.")
pending.state = .streaming
_ = await store.prepare(pending, width: bodyWidth)
let pendingView = store.view(for: pending.blocks[0], width: bodyWidth)
let previousOpenLink = store.openLink
var openedPendingLink = false
store.openLink = { _, _ in openedPendingLink = true }
pendingView.onLink?(URL(string: MarkdownStreamingDisplay.pendingLink)!)
store.openLink = previousOpenLink
try expect(!openedPendingLink, "尚未传完的链接可被打开")

let anchored = ConversationController(fixtureMode: false)
anchored.usesWorkspaceChrome = true
anchored.reservesReplySpace = true
anchored.reduceMotion = true
anchored.loadViewIfNeeded()
anchored.view.frame = CGRect(x: 0, y: 0, width: 720, height: 640)
anchored.view.setNeedsLayout(); anchored.view.layoutIfNeeded()
var turn = StudySession(id: UUID(), title: "发送位置检查")
turn.messages = [AgentMessage(role: .user, text: "之前的问题", source: nil),
AgentMessage(role: .assistant, text: String(repeating: "之前的一段回答。\n\n", count: 24), source: nil),
AgentMessage(role: .user, text: "新的问题", source: nil)]
await anchored.showSession(turn)
let questionTop = anchored.collection.layoutAttributesForItem(at: IndexPath(item: 0, section: 2))!.frame.minY
- anchored.flow.sectionInset.top
try expect(abs(anchored.collection.contentOffset.y - questionTop) < 1, "发送问题后没有留出回答空间")
let reply = AgentMessage(role: .assistant, text: "短回答保持原位。", source: nil, completionState: .generating)
await anchored.display(reply, streaming: true)
try expect(abs(anchored.collection.contentOffset.y - questionTop) < 1, "短回答把问题顶出了原位")
message.state = .stopped
try expect(message.blocks[0] === first, "停止时重建了正文")
metrics.checks["stream_keeps_unchanged_blocks_and_tail"] = "passed"
Expand Down
Loading
Loading