diff --git a/ios/Hapi/Features/Chat/Blocks/TextBlockViews.swift b/ios/Hapi/Features/Chat/Blocks/TextBlockViews.swift index d2451432..9a7cbfcd 100644 --- a/ios/Hapi/Features/Chat/Blocks/TextBlockViews.swift +++ b/ios/Hapi/Features/Chat/Blocks/TextBlockViews.swift @@ -18,6 +18,7 @@ struct UserTextBlockView: View { @Environment(\.chatInteractions) private var interactions @Environment(\.hapiTypography) private var typography + @Environment(\.hapiTheme) private var theme @Environment(\.openChatMessage) private var openMessage init(block: UserTextBlock) { @@ -57,7 +58,27 @@ struct UserTextBlockView: View { } .padding(.horizontal, 16) .padding(.vertical, 12) - .background(.tint.opacity(0.16)) + .foregroundStyle(theme.textPrimary) + .background { + UnevenRoundedRectangle( + topLeadingRadius: 16, + bottomLeadingRadius: 16, + bottomTrailingRadius: 4, + topTrailingRadius: 16, + style: .continuous + ) + .fill(theme.surface) + } + .overlay { + UnevenRoundedRectangle( + topLeadingRadius: 16, + bottomLeadingRadius: 16, + bottomTrailingRadius: 4, + topTrailingRadius: 16, + style: .continuous + ) + .stroke(theme.divider, lineWidth: 1) + } .clipShape( .rect( topLeadingRadius: 16, @@ -84,6 +105,12 @@ struct UserTextBlockView: View { .padding(.trailing, 4) } } + ChatMessageActionRow( + timestamp: block.createdAt, + copyText: block.text, + metadata: nil, + alignment: .trailing + ) } } } @@ -96,8 +123,19 @@ struct AgentTextBlockView: View { let block: AgentTextBlock var body: some View { - CachedMarkdownView(markdown: block.text) - .frame(maxWidth: .infinity, alignment: .leading) + VStack(alignment: .leading, spacing: 0) { + CachedMarkdownView(markdown: block.text) + .frame(maxWidth: .infinity, alignment: .leading) + ChatMessageActionRow( + timestamp: block.createdAt, + copyText: block.text, + metadata: ChatMessageMeta( + durationMs: block.durationMs, + model: block.model, + usage: block.usage + ) + ) + } } } @@ -106,6 +144,7 @@ struct AgentTextBlockView: View { struct AgentReasoningBlockView: View { let block: AgentReasoningBlock @ChatStoredState private var expanded: Bool + @Environment(\.hapiTheme) private var theme init(block: AgentReasoningBlock) { self.block = block @@ -130,10 +169,12 @@ struct AgentReasoningBlockView: View { if expanded { CachedMarkdownView(markdown: block.text) .opacity(0.75) - .padding(.leading, 8) + .padding(.leading, 4) } } .frame(maxWidth: .infinity, alignment: .leading) + .padding(10) + .background(theme.surface, in: RoundedRectangle(cornerRadius: 12, style: .continuous)) } } @@ -155,7 +196,9 @@ struct AgentEventBlockView: View { CompactionSummaryCard(id: block.id, presentation: compact, expanded: $expanded) } else { let presentation = eventPresentation(block.event) - Text([presentation.icon, presentation.text].compactMap { $0 }.joined(separator: " ")) + Text([presentation.icon, presentation.text, ChatTimeLabel.text(for: block.createdAt)] + .compactMap { $0 } + .joined(separator: " · ")) .font(.caption) .foregroundStyle(.secondary) .multilineTextAlignment(.center) diff --git a/ios/Hapi/Features/Chat/Blocks/ToolCallBlockView.swift b/ios/Hapi/Features/Chat/Blocks/ToolCallBlockView.swift index c67d40c5..5705ea30 100644 --- a/ios/Hapi/Features/Chat/Blocks/ToolCallBlockView.swift +++ b/ios/Hapi/Features/Chat/Blocks/ToolCallBlockView.swift @@ -68,7 +68,8 @@ struct ToolCallBlockView: View { private func headerRow(_ presentation: ToolCardPresentation) -> some View { ToolSummaryRow( presentation: presentation, state: block.tool.state, - showsStatus: block.tool.state != .pending || block.tool.permission?.status != .pending + showsStatus: block.tool.state != .pending || block.tool.permission?.status != .pending, + timing: ChatToolTiming.text(for: block) ) { openTool?(block) } .accessibilityHint(opensToolProcess(block) ? String(localized: "View agent process") : String(localized: "View tool details")) @@ -82,6 +83,7 @@ struct ToolSummaryRow: View { let presentation: ToolCardPresentation let state: ToolCallState var showsStatus = true + var timing: String? = nil let action: () -> Void @Environment(\.hapiTheme) private var theme @Environment(\.hapiTypography) private var typography @@ -120,6 +122,12 @@ struct ToolSummaryRow: View { } if !stacksStatus { Spacer(minLength: 8) } HStack(spacing: 8) { + if let timing { + Text(timing) + .font(typography.captionFont) + .foregroundStyle(theme.textHint) + .lineLimit(1) + } if showsStatus && state != .completed { ToolStatusIndicator(state: state) } diff --git a/ios/Hapi/Features/Chat/ChatModel.swift b/ios/Hapi/Features/Chat/ChatModel.swift index 45d9674a..b6608a94 100644 --- a/ios/Hapi/Features/Chat/ChatModel.swift +++ b/ios/Hapi/Features/Chat/ChatModel.swift @@ -15,6 +15,9 @@ struct ChatHeaderUI: Equatable { var flavor: String? var active: Bool var thinking: Bool + var project: String? = nil + var model: String? = nil + var effort: String? = nil } /// Presentation state machine for the read-only chat screen (M2f) — the iOS @@ -706,10 +709,17 @@ final class ChatModel { let worktree = (detail?.metadata?.worktree ?? summary?.metadata?.worktree).map { tree in tree.name.trimmingCharacters(in: .whitespaces).isEmpty ? tree.branch : tree.name } + let project = (detail?.metadata?.path ?? summary?.metadata?.path) + .flatMap { $0.split(separator: "/").last.map(String.init) } + let model = detail?.model + let effort = detail?.effort ?? detail?.modelReasoningEffort let parts: [String] = [ flavor.map { flavorLabel(forFlavor: $0) }, + project, machineLabel, worktree, + model, + effort, ].compactMap { $0 } return ChatHeaderUI( @@ -717,7 +727,10 @@ final class ChatModel { subtitle: parts.isEmpty ? nil : parts.joined(separator: " · "), flavor: flavor, active: detail?.active ?? summary?.active ?? false, - thinking: detail?.thinking ?? summary?.thinking ?? false + thinking: detail?.thinking ?? summary?.thinking ?? false, + project: project, + model: model, + effort: effort ) } diff --git a/ios/Hapi/Features/Chat/ChatView.swift b/ios/Hapi/Features/Chat/ChatView.swift index b0814d01..dda69d6d 100644 --- a/ios/Hapi/Features/Chat/ChatView.swift +++ b/ios/Hapi/Features/Chat/ChatView.swift @@ -107,6 +107,9 @@ struct ChatView: View { .safeAreaInset(edge: .bottom, spacing: 0) { VStack(spacing: 0) { QueuedMessagesBarView(interactor: model.interactor) + ChatComposerStatusBar(model: model) { + configOpen = true + } ChatComposerView( interactor: model.interactor, dictation: model.dictation, @@ -392,9 +395,18 @@ struct ChatView: View { private var headerTitle: some View { VStack(alignment: .leading, spacing: 0) { - Text(model.header.title) - .font(.headline) - .lineLimit(1) + HStack(spacing: 5) { + Circle() + .fill(headerStatus.color) + .frame(width: 6, height: 6) + Text(model.header.title) + .font(.headline) + .lineLimit(1) + Text(headerStatus.label) + .font(.caption2.weight(.medium)) + .foregroundStyle(headerStatus.color) + .lineLimit(1) + } if let subtitle = model.header.subtitle { HStack(spacing: 4) { if model.header.flavor != nil { @@ -412,6 +424,14 @@ struct ChatView: View { } } + private var headerStatus: (label: String, color: Color) { + ChatSessionStatus.label( + active: model.header.active, + thinking: model.header.thinking, + reconnecting: model.isReconnecting + ) + } + @ViewBuilder private var warningBanner: some View { if let warning = model.warning { diff --git a/ios/Hapi/Features/Chat/Composer/ChatComposerStatusBar.swift b/ios/Hapi/Features/Chat/Composer/ChatComposerStatusBar.swift new file mode 100644 index 00000000..028379a3 --- /dev/null +++ b/ios/Hapi/Features/Chat/Composer/ChatComposerStatusBar.swift @@ -0,0 +1,89 @@ +import HapiClient +import HapiUI +import SwiftUI + +/// Quiet one-line status above the composer: connection/thinking state plus +/// the active model, effort and permission labels. Tapping any chip opens the +/// existing session config sheet; this is a readout, not a second settings UI. +struct ChatComposerStatusBar: View { + let model: ChatModel + let openSettings: () -> Void + + @Environment(\.hapiTheme) private var theme + @Environment(\.hapiTypography) private var typography + + private var status: (label: String, color: Color) { + ChatSessionStatus.label( + active: model.header.active, + thinking: model.header.thinking, + reconnecting: model.isReconnecting + ) + } + + private var config: SessionConfigState { + model.interactor.config + } + + private var modelLabel: String? { + if let label = config.modelOptions?.first(where: { $0.value == config.model })?.label { + return label + } + return config.model + } + + private var effortLabel: String? { + config.effortOptions?.first { $0.value == config.effort }?.label + } + + private var permissionLabel: String? { + config.permissionModes.first { $0.mode == config.permissionMode }?.label + } + + var body: some View { + HStack(spacing: 8) { + HStack(spacing: 5) { + Circle() + .fill(status.color) + .frame(width: 6, height: 6) + Text(status.label) + .foregroundStyle(status.color) + } + .lineLimit(1) + + Spacer(minLength: 8) + + if let modelLabel { + pill(modelLabel, icon: "cpu") + } + if let effortLabel { + pill(effortLabel, icon: "speedometer") + } + if let permissionLabel { + pill(permissionLabel, icon: "lock.shield") + } + } + .font(typography.captionFont) + .foregroundStyle(theme.textSecondary) + .padding(.horizontal, 4) + .padding(.vertical, 2) + .hapiReadingColumn() + .accessibilityElement(children: .combine) + } + + private func pill(_ label: String, icon: String) -> some View { + Button(action: openSettings) { + HStack(spacing: 3) { + Image(systemName: icon) + .font(.system(size: 9, weight: .medium)) + Text(label) + .lineLimit(1) + } + .padding(.horizontal, 7) + .padding(.vertical, 3) + .background(theme.surface, in: Capsule()) + } + .buttonStyle(.plain) + .foregroundStyle(theme.textSecondary) + .accessibilityHint("Open session settings") + } +} diff --git a/ios/Hapi/Features/Chat/MessageChrome.swift b/ios/Hapi/Features/Chat/MessageChrome.swift new file mode 100644 index 00000000..41b24d1d --- /dev/null +++ b/ios/Hapi/Features/Chat/MessageChrome.swift @@ -0,0 +1,181 @@ +import HapiProtocol +import HapiUI +import SwiftUI +import UIKit + +/// Timestamp formatting for transcript chrome. The web uses a compact +/// same-day clock and a date prefix for older messages; keep the same +/// information density without copying its typography. +enum ChatTimeLabel { + static func text(for epochMs: Int, now: Date = Date()) -> String { + let date = Date(timeIntervalSince1970: Double(epochMs) / 1000) + let calendar = Calendar.current + if calendar.isDate(date, inSameDayAs: now) { + return date.formatted(date: .omitted, time: .shortened) + } + if calendar.component(.year, from: date) == calendar.component(.year, from: now) { + return date.formatted(.dateTime.month(.abbreviated).day().hour().minute()) + } + return date.formatted(.dateTime.year().month(.abbreviated).day().hour().minute()) + } +} + +/// Shared live-state wording for the nav header and composer strip. +enum ChatSessionStatus { + static func label( + active: Bool, + thinking: Bool, + reconnecting: Bool + ) -> (label: String, color: Color) { + if reconnecting { + return (String(localized: "Reconnecting"), .orange) + } + if !active { + return (String(localized: "Inactive"), .secondary) + } + if thinking { + return (String(localized: "Vibing"), .blue) + } + return (String(localized: "Online"), .green) + } +} + +/// Shared duration wording for assistant metadata and tool timing. +enum ChatDurationLabel { + static func text(ms: Int) -> String? { + guard ms > 0 else { return nil } + let seconds = Double(ms) / 1000 + if seconds < 60 { + return String(format: "%.1fs", seconds) + } + let total = Int(seconds.rounded()) + return "\(total / 60)m \(total % 60)s" + } +} + +/// Compact timing for a tool summary: completed duration, or the start clock +/// while running. Kept in the existing trailing area so card height does not +/// grow. +enum ChatToolTiming { + static func text(for block: ToolCallBlock) -> String? { + let start = block.tool.startedAt ?? block.tool.execStartedAt + if let start, let end = block.tool.completedAt ?? block.tool.execCompletedAt { + return ChatDurationLabel.text(ms: max(0, end - start)) + } + if block.tool.state == .running, let start { + return String(localized: "Started \(ChatTimeLabel.text(for: start))") + } + if let duration = block.durationMs { + return ChatDurationLabel.text(ms: duration) + } + return nil + } +} + +/// Data already carried by the chat blocks but previously not shown. Keep the +/// adapter here so transcript rows stay presentation-only. +struct ChatMessageMeta: Equatable { + var durationMs: Int? + var model: String? + var inputTokens: Double? + var outputTokens: Double? + + init( + durationMs: Int? = nil, + model: String? = nil, + usage: UsageData? = nil + ) { + self.durationMs = durationMs + self.model = model + self.inputTokens = usage?.inputTokens + self.outputTokens = usage?.outputTokens + } + + var hasDetails: Bool { + durationMs != nil || model != nil || inputTokens != nil || outputTokens != nil + } + + var durationLabel: String? { + guard let durationMs else { return nil } + return ChatDurationLabel.text(ms: durationMs) + } + + var tokenLabel: String? { + guard inputTokens != nil || outputTokens != nil else { return nil } + let input = Int(inputTokens ?? 0) + let output = Int(outputTokens ?? 0) + return "\(input) / \(output)" + } +} + +/// Compact footer under a message: time, copy, and (for assistant prose) +/// duration/model/token details. Kept visually quiet so the transcript remains +/// the primary surface. +struct ChatMessageActionRow: View { + enum Alignment { + case leading + case trailing + } + + let timestamp: Int? + let copyText: String? + let metadata: ChatMessageMeta? + var alignment: Alignment = .leading + + @Environment(\.hapiTheme) private var theme + @Environment(\.hapiTypography) private var typography + @State private var copied = false + + var body: some View { + HStack(spacing: 8) { + if alignment == .trailing { + Spacer(minLength: 0) + } + if let timestamp, timestamp > 0 { + Text(ChatTimeLabel.text(for: timestamp)) + .monospacedDigit() + } + if let copyText, !copyText.isEmpty { + Button { + UIPasteboard.general.string = copyText + copied = true + Task { + try? await Task.sleep(for: .seconds(1.5)) + copied = false + } + } label: { + Image(systemName: copied ? "checkmark" : "doc.on.doc") + .frame(width: 28, height: 28) + .contentShape(Rectangle()) + } + .buttonStyle(.plain) + .accessibilityLabel(copied ? Text("Copied") : Text("Copy")) + } + if let metadata, metadata.hasDetails { + Menu { + if let duration = metadata.durationLabel { + Text("Duration \(duration)") + } + if let model = metadata.model { + Text("Model \(model)") + } + if let tokens = metadata.tokenLabel { + Text("Tokens \(tokens)") + } + } label: { + Image(systemName: "info.circle") + .frame(width: 28, height: 28) + .contentShape(Rectangle()) + } + .menuStyle(.borderlessButton) + .accessibilityLabel("Info") + } + if alignment == .leading { + Spacer(minLength: 0) + } + } + .font(typography.captionFont) + .foregroundStyle(theme.textSecondary) + .padding(.top, 2) + } +} diff --git a/ios/Hapi/Features/Sessions/SessionListView.swift b/ios/Hapi/Features/Sessions/SessionListView.swift index 3ca3ad26..141da452 100644 --- a/ios/Hapi/Features/Sessions/SessionListView.swift +++ b/ios/Hapi/Features/Sessions/SessionListView.swift @@ -683,13 +683,17 @@ struct SessionRowView: View { /// The agent owns the leading column; a presence badge marks connected /// sessions (pulsing while the agent works) instead of dimming the rest. private var agentIcon: some View { - AgentFlavorIconView(flavor: row.flavor, size: metrics.iconSize * 0.8) - .frame(width: metrics.iconSize, height: metrics.iconSize) - .overlay(alignment: .bottomTrailing) { - if row.summary.active { - presenceBadge - } + ZStack { + RoundedRectangle(cornerRadius: metrics.iconSize * 0.28, style: .continuous) + .fill(theme.surface) + AgentFlavorIconView(flavor: row.flavor, size: metrics.iconSize * 0.72) + } + .frame(width: metrics.iconSize, height: metrics.iconSize) + .overlay(alignment: .bottomTrailing) { + if row.summary.active { + presenceBadge } + } } private var presenceBadge: some View { diff --git a/ios/Hapi/Resources/Localizable.xcstrings b/ios/Hapi/Resources/Localizable.xcstrings index 6649f598..2b85090b 100644 --- a/ios/Hapi/Resources/Localizable.xcstrings +++ b/ios/Hapi/Resources/Localizable.xcstrings @@ -11901,6 +11901,176 @@ } } } + }, + "Info" : { + "extractionState" : "manual", + "localizations" : { + "ru" : { + "stringUnit" : { + "state" : "translated", + "value" : "Информация" + } + }, + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "信息" + } + } + } + }, + "Copied" : { + "extractionState" : "manual", + "localizations" : { + "ru" : { + "stringUnit" : { + "state" : "translated", + "value" : "Скопировано" + } + }, + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "已复制" + } + } + } + }, + "Duration %@" : { + "extractionState" : "manual", + "localizations" : { + "ru" : { + "stringUnit" : { + "state" : "translated", + "value" : "Длительность %@" + } + }, + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "耗时 %@" + } + } + } + }, + "Model %@" : { + "extractionState" : "manual", + "localizations" : { + "ru" : { + "stringUnit" : { + "state" : "translated", + "value" : "Модель %@" + } + }, + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "模型 %@" + } + } + } + }, + "Tokens %@" : { + "extractionState" : "manual", + "localizations" : { + "ru" : { + "stringUnit" : { + "state" : "translated", + "value" : "Токены %@" + } + }, + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "Token 数 %@" + } + } + } + }, + "Online" : { + "extractionState" : "manual", + "localizations" : { + "ru" : { + "stringUnit" : { + "state" : "translated", + "value" : "В сети" + } + }, + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "在线" + } + } + } + }, + "Vibing" : { + "extractionState" : "manual", + "localizations" : { + "ru" : { + "stringUnit" : { + "state" : "translated", + "value" : "Работает" + } + }, + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "思考中" + } + } + } + }, + "Reconnecting" : { + "extractionState" : "manual", + "localizations" : { + "ru" : { + "stringUnit" : { + "state" : "translated", + "value" : "Переподключение" + } + }, + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "重连中" + } + } + } + }, + "Open session settings" : { + "extractionState" : "manual", + "localizations" : { + "ru" : { + "stringUnit" : { + "state" : "translated", + "value" : "Открыть настройки сеанса" + } + }, + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "打开会话设置" + } + } + } + }, + "Started %@" : { + "extractionState" : "manual", + "localizations" : { + "ru" : { + "stringUnit" : { + "state" : "translated", + "value" : "Начато %@" + } + }, + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "开始于 %@" + } + } + } } }, "version" : "1.0" diff --git a/ios/HapiTests/MessageChromeTests.swift b/ios/HapiTests/MessageChromeTests.swift new file mode 100644 index 00000000..5778b0a3 --- /dev/null +++ b/ios/HapiTests/MessageChromeTests.swift @@ -0,0 +1,31 @@ +import HapiProtocol +import XCTest +@testable import Hapi + +final class MessageChromeTests: XCTestCase { + func testDurationLabels() { + XCTAssertEqual(ChatDurationLabel.text(ms: 500), "0.5s") + XCTAssertEqual(ChatDurationLabel.text(ms: 8_500), "8.5s") + XCTAssertEqual(ChatDurationLabel.text(ms: 65_000), "1m 5s") + XCTAssertNil(ChatDurationLabel.text(ms: 0)) + } + + func testMessageMetadataUsesUsage() { + let meta = ChatMessageMeta( + durationMs: 8_500, + model: "claude-sonnet", + usage: UsageData(inputTokens: 120, outputTokens: 45) + ) + + XCTAssertTrue(meta.hasDetails) + XCTAssertEqual(meta.durationLabel, "8.5s") + XCTAssertEqual(meta.model, "claude-sonnet") + XCTAssertEqual(meta.tokenLabel, "120 / 45") + } + + func testEmptyMetadataHidesTheInfoAction() { + XCTAssertFalse(ChatMessageMeta().hasDetails) + XCTAssertNil(ChatMessageMeta().durationLabel) + XCTAssertNil(ChatMessageMeta().tokenLabel) + } +}