import SessionCore import SwiftUI /// Copy + wire pairing for one gate button — the SINGLE label source for both /// gate surfaces (`GateBanner`, `PlanGateSheet`). Labels mirror /// public/tabs.ts:334-350 byte-for-byte; the affordance→ClientMessage mapping /// itself is frozen in SessionCore (`GateState.Affordance.clientMessage`). struct GateChoiceSpec: Equatable { let label: String let affordance: GateState.Affordance /// Ordered button set for `gate` (tool → two, plan → three), driven by the /// frozen `GateState.affordances` list. static func specs(for gate: GateState) -> [GateChoiceSpec] { gate.affordances.map { GateChoiceSpec(label: label(for: $0), affordance: $0) } } static func label(for affordance: GateState.Affordance) -> String { switch affordance { case .approveAuto: return "✓ Approve + Auto" case .approveReview: return "✓ Approve + Review" case .keepPlanning: return "✎ Keep Planning" case .approve: return "✓ Approve" case .reject: return "✗ Reject" } } } /// T-iOS-14 · Two-button banner for an ordinary TOOL gate (plan gates get the /// three-way `PlanGateSheet`). Render-only: state lives in `GateViewModel`. /// Every tap reports the affordance PLUS the epoch of the gate THIS banner /// rendered — the VM drops stale taps (first-line guard); wiring into /// TerminalScreen is T-iOS-15. struct GateBanner: View { let gate: GateState let onDecide: (GateState.Affordance, Int) -> Void private enum Metrics { static let spacing: CGFloat = 8 static let horizontalPadding: CGFloat = 14 static let verticalPadding: CGFloat = 10 static let cornerRadius: CGFloat = 12 static let messageLineLimit = 2 } /// Banner headline, mirror of public/tabs.ts:329: /// `Claude wants to use ${pendingTool ?? 'a tool'}`. `detail` is /// server-supplied display text (untrusted) — rendered as plain Text only. static func message(for gate: GateState) -> String { "Claude wants to use \(gate.detail ?? "a tool")" } var body: some View { VStack(alignment: .leading, spacing: Metrics.spacing) { Text(Self.message(for: gate)) .font(.footnote.weight(.semibold)) .lineLimit(Metrics.messageLineLimit) HStack(spacing: Metrics.spacing) { ForEach(GateChoiceSpec.specs(for: gate), id: \.affordance) { spec in decisionButton(spec) } } } .padding(.horizontal, Metrics.horizontalPadding) .padding(.vertical, Metrics.verticalPadding) .background(.thinMaterial, in: RoundedRectangle(cornerRadius: Metrics.cornerRadius)) .accessibilityElement(children: .contain) } private func decisionButton(_ spec: GateChoiceSpec) -> some View { Button(spec.label) { onDecide(spec.affordance, gate.epoch) // epoch of the RENDERED gate } .accessibilityIdentifier("gate.decision.\(spec.affordance)") .buttonStyle(.borderedProminent) .controlSize(.small) .tint(tint(for: spec.affordance)) } private func tint(for affordance: GateState.Affordance) -> Color { switch affordance { case .approve, .approveAuto, .approveReview: return .green case .reject: return .red case .keepPlanning: return .indigo } } }