oficina / equipo Public

native: the Mac app, and a live pairing test

EquipoMac: the AppKit transcript and composer (Roster's bylines, raised cards, sub-chat composer) inside a SwiftUI split view with Needs you, Tasks, the task inspector, Settings and quiet Sparkle updates. Pairing accepts plain http only to a loopback address, and the approval page must be on the team's own origin. LiveTests pairs, reads, sends, polls and signs out against a real Equipo when EQUIPO_LIVE_ORIGIN is set.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by claude agent, operated by paul@keymail.dev 09cd7e25576c7de0d67bdd0e90799c5c6532204b parent 733c4b0
14 files changed, +1,296 −10
  • native/.gitignore +1 −0
  • native/apple/Sources/EquipoKit/Pairing/Pairing.swift +12 −4
  • native/apple/Sources/EquipoKit/Resources/Localizable.xcstrings +55 −0
  • native/apple/Sources/EquipoMac/EquipoMacApp.swift +75 −0
  • native/apple/Sources/EquipoMac/LiveTranscript.swift +346 −0
  • native/apple/Sources/EquipoMac/MacComposer.swift +128 −0
  • native/apple/Sources/EquipoMac/MacMainView.swift +91 −0
  • native/apple/Sources/EquipoMac/MacRoster.swift +294 −0
  • native/apple/Sources/EquipoMac/MacStyle.swift +204 −0
  • native/apple/Sources/EquipoMac/main.swift +0 −5
  • native/apple/Tests/EquipoKitTests/LiveTests.swift +67 −0
  • native/apple/Tests/EquipoKitTests/PairingTests.swift +16 −0
  • native/scripts/check-strings.py +2 −1
  • native/scripts/strings.json +5 −0
diff --git a/native/.gitignore b/native/.gitignore
index 12a13114..ba3dba2d 100644
--- a/native/.gitignore
+++ b/native/.gitignore
@@ -4,3 +4,4 @@ DerivedData/
build/
*.xcodeproj/
*.log
+ios/Info.plist
diff --git a/native/apple/Sources/EquipoKit/Pairing/Pairing.swift b/native/apple/Sources/EquipoKit/Pairing/Pairing.swift
index 99436f5d..e0f10528 100644
--- a/native/apple/Sources/EquipoKit/Pairing/Pairing.swift
+++ b/native/apple/Sources/EquipoKit/Pairing/Pairing.swift
@@ -41,15 +41,23 @@ public final class PairingModel {
}
/// Turns what a person types into the team's origin: a host or a URL,
- /// https only, nothing after the host.
+ /// nothing after the host. https only, except plain http to this
+ /// machine's loopback address for a local Equipo (README, "Local startup").
public static func origin(from typed: String) -> URL? {
var text = typed.trimmingCharacters(in: .whitespacesAndNewlines)
guard !text.isEmpty else { return nil }
if !text.contains("://") { text = "https://" + text }
- guard let url = URL(string: text), url.scheme == "https", let host = url.host, !host.isEmpty, url.user == nil else { return nil }
- var c = URLComponents(); c.scheme = "https"; c.host = host.lowercased(); c.port = url.port
+ guard let url = URL(string: text), let scheme = url.scheme?.lowercased(), let host = url.host?.lowercased(), !host.isEmpty, url.user == nil else { return nil }
+ guard scheme == "https" || (scheme == "http" && isLoopback(host)) else { return nil }
+ var c = URLComponents(); c.scheme = scheme; c.host = host; c.port = url.port
return c.url
}
+ static func isLoopback(_ host: String) -> Bool { host == "127.0.0.1" || host == "localhost" || host == "::1" }
+
+ /// The browser page must belong to the team itself.
+ static func verificationIsTrusted(_ url: URL, origin: URL) -> Bool {
+ url.scheme == origin.scheme && url.host?.lowercased() == origin.host?.lowercased() && url.port == origin.port
+ }
public func start(origin: URL, label: String) {
task?.cancel()
@@ -67,7 +75,7 @@ public final class PairingModel {
let client = EquipoClient(transport: makeTransport(origin), token: nil)
let begin = try PendingWrite.json(["public_key": try account.publicKey(), "label": label])
let challenge: DeviceChallenge = try await retrying { try await client.beginDevice(begin) }
- guard let verification = URL(string: challenge.verificationUri), verification.scheme == "https" else {
+ guard let verification = URL(string: challenge.verificationUri), Self.verificationIsTrusted(verification, origin: origin) else {
throw PairingError.badChallenge
}
step = .waiting(code: challenge.userCode, verification: verification, expires: challenge.expiresAt)
diff --git a/native/apple/Sources/EquipoKit/Resources/Localizable.xcstrings b/native/apple/Sources/EquipoKit/Resources/Localizable.xcstrings
index bdc1f7d8..29dced27 100644
--- a/native/apple/Sources/EquipoKit/Resources/Localizable.xcstrings
+++ b/native/apple/Sources/EquipoKit/Resources/Localizable.xcstrings
@@ -156,6 +156,17 @@
}
}
},
+ "app.name": {
+ "extractionState": "manual",
+ "localizations": {
+ "en": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Equipo"
+ }
+ }
+ }
+ },
"byline.asks": {
"extractionState": "manual",
"localizations": {
@@ -343,6 +354,17 @@
}
}
},
+ "needs.count %lld": {
+ "extractionState": "manual",
+ "localizations": {
+ "en": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "%lld waiting for you"
+ }
+ }
+ }
+ },
"needs.count_spoken %lld": {
"extractionState": "manual",
"localizations": {
@@ -695,6 +717,17 @@
}
}
},
+ "settings.not_paired": {
+ "extractionState": "manual",
+ "localizations": {
+ "en": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Pair this Mac with a team to see its settings."
+ }
+ }
+ }
+ },
"specialist.checks": {
"extractionState": "manual",
"localizations": {
@@ -838,6 +871,17 @@
}
}
},
+ "task.inspector": {
+ "extractionState": "manual",
+ "localizations": {
+ "en": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Show or hide the task"
+ }
+ }
+ }
+ },
"task.missing": {
"extractionState": "manual",
"localizations": {
@@ -860,6 +904,17 @@
}
}
},
+ "task.none_selected": {
+ "extractionState": "manual",
+ "localizations": {
+ "en": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Choose a task to see it here."
+ }
+ }
+ }
+ },
"task.not_started": {
"extractionState": "manual",
"localizations": {
diff --git a/native/apple/Sources/EquipoMac/EquipoMacApp.swift b/native/apple/Sources/EquipoMac/EquipoMacApp.swift
new file mode 100644
index 00000000..1a45c8a8
--- /dev/null
+++ b/native/apple/Sources/EquipoMac/EquipoMacApp.swift
@@ -0,0 +1,75 @@
+#if canImport(RastrilloMacUpdates)
+import RastrilloMacUpdates
+#endif
+import AppKit
+import EquipoKit
+import RastrilloApple
+import SwiftUI
+
+/// Equipo for the Mac. One window: pairing until there is a team, then the
+/// conversation, Needs you and Tasks. Settings shows the team and this
+/// device, and signs out.
+@main struct EquipoMacApp: App {
+ @State private var model = EquipoAppModel()
+ #if canImport(RastrilloMacUpdates)
+ // Quiet, as the other Oficina apps: a scheduled check never opens a
+ // window; an update downloads in the background and installs on quit.
+ @State private var updater = NativeUpdater(policy: .quiet)
+ #endif
+
+ var body: some Scene {
+ WindowGroup(EquipoStrings.text("app.name")) {
+ MacRoot(model: model)
+ #if canImport(RastrilloMacUpdates)
+ .safeAreaInset(edge: .bottom) {
+ if updater.canInstallPendingUpdate { NativeUpdateNotice(updater: updater).padding(.bottom, 12) }
+ }
+ #endif
+ }
+ .defaultSize(width: 1180, height: 780)
+ .commands {
+ // First: About, Hide and Quit say "Equipo", not the Finder name.
+ PlainAppNameCommands()
+ #if canImport(RastrilloMacUpdates)
+ NativeUpdateCommands(updater: updater)
+ #endif
+ }
+ Settings { MacSettings(model: model) }
+ }
+}
+
+/// Pairing or the signed-in window, and the app's foreground state.
+struct MacRoot: View {
+ let model: EquipoAppModel
+ var body: some View {
+ Group {
+ if let session = model.session, !model.needsPairing {
+ MacMainView(model: model, session: session)
+ } else {
+ PairingView(model: model).frame(minWidth: 560, minHeight: 520)
+ }
+ }
+ .tint(Color(nsColor: .webAccent))
+ .frame(minWidth: 860, minHeight: 560)
+ .onAppear { model.foreground() }
+ .onReceive(NotificationCenter.default.publisher(for: NSApplication.didBecomeActiveNotification)) { _ in model.foreground() }
+ .onReceive(NotificationCenter.default.publisher(for: NSApplication.didResignActiveNotification)) { _ in model.background() }
+ .onChange(of: model.session?.status) { _, status in if status == .signedOut { model.sessionEnded() } }
+ }
+}
+
+/// Equipo ▸ Settings: the paired team and this device.
+struct MacSettings: View {
+ let model: EquipoAppModel
+ var body: some View {
+ Group {
+ if let session = model.session, !model.needsPairing {
+ AccountScreen(model: model, session: session)
+ } else {
+ Text(EquipoStrings.text("settings.not_paired")).foregroundStyle(.secondary).padding(40)
+ }
+ }
+ .frame(width: 460)
+ .padding(.vertical, 8)
+ }
+}
diff --git a/native/apple/Sources/EquipoMac/LiveTranscript.swift b/native/apple/Sources/EquipoMac/LiveTranscript.swift
new file mode 100644
index 00000000..5f89e355
--- /dev/null
+++ b/native/apple/Sources/EquipoMac/LiveTranscript.swift
@@ -0,0 +1,346 @@
+import AppKit
+import EquipoKit
+import SwiftUI
+
+/// The conversation in AppKit: Roster's bylines and cards over the live feed
+/// (EquipoKit's `Feed.build`), in a centred column with a 48-point author
+/// gutter, and the composer at the bottom. Each update lays the feed out
+/// again at the column width; the view stays pinned to the newest item
+/// unless the person has scrolled up.
+@MainActor
+final class LiveTranscript: NSView {
+ override var isFlipped: Bool { true }
+
+ /// What a question card is doing, kept here across rebuilds.
+ enum AnswerState: Equatable {
+ case sending(String)
+ case answered(String)
+ case changed, offline, failed
+ }
+
+ let session: EquipoSession
+ var openTask: (String) -> Void
+ private(set) var items: [FeedItem] = []
+ private var answers: [String: AnswerState] = [:]
+ private let scroll = NSScrollView()
+ private let document = FlippedView()
+ let composer = MacComposer()
+ private var laidOutWidth: CGFloat = 0
+ private var hasScrolledOnce = false
+
+ init(session: EquipoSession, openTask: @escaping (String) -> Void) {
+ self.session = session
+ self.openTask = openTask
+ super.init(frame: .zero)
+ scroll.documentView = document
+ scroll.hasVerticalScroller = true
+ scroll.drawsBackground = false
+ scroll.automaticallyAdjustsContentInsets = false
+ addSubview(scroll)
+ addSubview(composer)
+ composer.onHeightChange = { [weak self] in self?.needsLayout = true }
+ composer.onSend = { [weak self] text in
+ guard let self else { return }
+ let session = self.session
+ Task { await session.send(text) }
+ }
+ setAccessibilityLabel(EquipoStrings.text("tab.conversation"))
+ }
+ required init?(coder: NSCoder) { fatalError() }
+
+ func update(items: [FeedItem]) {
+ let wasAtBottom = isAtBottom
+ self.items = items
+ rebuild()
+ if wasAtBottom || !hasScrolledOnce { scrollToBottom(); hasScrolledOnce = !items.isEmpty }
+ }
+
+ private var column: (x: CGFloat, width: CGFloat) {
+ let width = min(max(bounds.width - 64, 300), 768)
+ return (floor((bounds.width - width) / 2), width)
+ }
+ private var isAtBottom: Bool {
+ let clip = scroll.contentView.bounds
+ return clip.maxY >= document.frame.height - 24
+ }
+ private func scrollToBottom() {
+ let maxY = max(0, document.frame.height - scroll.contentView.bounds.height)
+ scroll.contentView.scroll(to: NSPoint(x: 0, y: maxY))
+ scroll.reflectScrolledClipView(scroll.contentView)
+ }
+
+ override func layout() {
+ super.layout()
+ let height = composer.desiredHeight
+ let column = self.column
+ composer.frame = NSRect(x: column.x, y: bounds.height - height - 18, width: column.width, height: height)
+ scroll.frame = NSRect(x: 0, y: 0, width: bounds.width, height: composer.frame.minY - 12)
+ if laidOutWidth != bounds.width {
+ let wasAtBottom = isAtBottom
+ laidOutWidth = bounds.width
+ rebuild()
+ if wasAtBottom { scrollToBottom() }
+ }
+ }
+
+ override func draw(_ dirtyRect: NSRect) { NSColor.webBackground.setFill(); bounds.fill() }
+
+ // MARK: Building the feed
+
+ private func rebuild() {
+ document.subviews.forEach { $0.removeFromSuperview() }
+ let column = self.column
+ let x0 = column.x, width = column.width
+ let content = width - MacMetric.gutter
+ var y: CGFloat = 24
+ func place(_ view: NSView, x: CGFloat = 0, gapAfter: CGFloat = 22) {
+ view.frame.origin = NSPoint(x: x0 + x, y: y)
+ document.addSubview(view)
+ y = view.frame.maxY + gapAfter
+ }
+ func placeCard(_ plate: RaisedPlate) {
+ plate.frame.origin = NSPoint(x: x0 + MacMetric.gutter - MacMetric.shadow, y: y - MacMetric.shadow)
+ document.addSubview(plate, positioned: .below, relativeTo: nil)
+ y += plate.content.frame.height + 24
+ }
+ if items.isEmpty && session.status == .ready {
+ place(makeText(EquipoStrings.text("conversation.empty"), MacType.line, .webSecondary, width: width), gapAfter: 0)
+ }
+ for item in items {
+ switch item {
+ case .own(let message):
+ place(ownBubble(message.body, width: width), x: width - ownWidth(message.body, width: width))
+ case .coordinator(let message):
+ place(coordinatorRow(message, width: width))
+ case .outgoing(let outgoing):
+ let bubble = ownBubble(outgoing.text, width: width)
+ bubble.alphaValue = outgoing.state == .sending ? 0.6 : 1
+ place(bubble, x: width - bubble.frame.width, gapAfter: 4)
+ let status = outgoingStatus(outgoing)
+ place(status, x: width - status.frame.width)
+ case .report(_, let byline, let task):
+ place(bylineView(byline, width: width), gapAfter: MacMetric.bylineGap)
+ place(reportLine(task, width: width), gapAfter: 24)
+ case .question(let card, let byline, let question, let taskTitle):
+ place(bylineView(byline, width: width), gapAfter: MacMetric.bylineGap)
+ placeCard(questionCard(card, question, taskTitle: taskTitle, width: content))
+ case .decision(let card, let byline, let taskTitle):
+ place(bylineView(byline, width: width), gapAfter: MacMetric.bylineGap)
+ placeCard(decisionCard(card, taskTitle: taskTitle, width: content))
+ }
+ }
+ // The last item scrolls clear of the composer.
+ document.frame = NSRect(x: 0, y: 0, width: bounds.width, height: max(y + 24, scroll.bounds.height))
+ }
+
+ private func ownWidth(_ text: String, width: CGFloat) -> CGFloat {
+ makeText(text, MacType.line, .webText, width: min(width * 0.7, 520) - 28, lineSpacing: 2).frame.width + 28
+ }
+ private func ownBubble(_ value: String, width: CGFloat) -> NSView {
+ let label = makeText(value, MacType.line, .webText, width: min(width * 0.7, 520) - 28, lineSpacing: 2, selectable: true)
+ let card = PaintView(frame: NSRect(x: 0, y: 0, width: label.frame.width + 28, height: label.frame.height + 20)) { r in
+ let p = NSBezierPath(roundedRect: r.insetBy(dx: 0.5, dy: 0.5), xRadius: 16, yRadius: 16)
+ NSColor.webSoft.setFill(); p.fill(); NSColor.webLightRim.withAlphaComponent(0.7).setStroke(); p.stroke()
+ }
+ label.frame.origin = NSPoint(x: 14, y: 10)
+ card.addSubview(label)
+ card.setAccessibilityElement(true); card.setAccessibilityRole(.group)
+ card.setAccessibilityLabel(EquipoStrings.text("thread.own_spoken \(value)"))
+ return card
+ }
+
+ private func coordinatorRow(_ message: Message, width: CGFloat) -> NSView {
+ let row = FlippedView(frame: NSRect(x: 0, y: 0, width: width, height: 0))
+ let mark = sparkleView(); mark.frame.origin = NSPoint(x: 0, y: 4); row.addSubview(mark)
+ let time = message.createdAt.formatted(date: .omitted, time: .shortened)
+ let timeLabel = makeText(time, MacType.time, .webFaint); centre(timeLabel, x: MacMetric.gutter, row: 0, height: MacMetric.tile); row.addSubview(timeLabel)
+ let body = makeText(message.body, MacType.line, .webText, width: min(width - MacMetric.gutter, 620), lineSpacing: 3, selectable: true)
+ body.frame.origin = NSPoint(x: MacMetric.gutter, y: MacMetric.tile + 2); row.addSubview(body)
+ row.frame.size.height = body.frame.maxY
+ row.setAccessibilityElement(true); row.setAccessibilityRole(.group)
+ row.setAccessibilityLabel("\(Specialist.coordinator.name), \(time). \(message.body)")
+ return row
+ }
+
+ private func outgoingStatus(_ outgoing: EquipoSession.Outgoing) -> NSView {
+ let session = self.session
+ let id = outgoing.id
+ switch outgoing.state {
+ case .sending:
+ return makeText(EquipoStrings.text("message.sending"), MacType.caption, .webFaint)
+ case .waiting:
+ return button(EquipoStrings.text("message.waiting"), .link) { Task { await session.retry(id) } }
+ case .failed:
+ let b = button(EquipoStrings.text("message.failed"), .link) { Task { await session.retry(id) } }
+ b.contentTintColor = .webNegative
+ return b
+ }
+ }
+
+ /// One compact line on the neutral rail: the title, what the task is
+ /// doing, and the Needs you chip. Clicking opens the task.
+ private func reportLine(_ task: EquipoTask, width: CGFloat) -> NSView {
+ let summary = TaskSummary(task)
+ let block = FlippedView(frame: NSRect(x: 0, y: 0, width: width, height: 26))
+ let x = MacMetric.gutter, w = width - MacMetric.gutter
+ let title = makeText(task.description, MacType.compactTitle, .webText, width: w * 0.65, lines: 1)
+ centre(title, x: x, row: 0, height: 22); block.addSubview(title)
+ let label = makeText(summary.label, MacType.eyebrow, summary.tone.nsEyebrow)
+ centre(label, x: title.frame.maxX + 10, row: 0, height: 22); block.addSubview(label)
+ if summary.needsYou {
+ let chip = needsChipView(); centre(chip, x: label.frame.maxX + 10, row: 0, height: 22); block.addSubview(chip)
+ }
+ block.addSubview(PaintView(frame: NSRect(x: MacMetric.tile / 2 - 1, y: -2, width: 2, height: 28)) { r in
+ NSColor.webLine.setFill(); NSBezierPath(roundedRect: r, xRadius: 1, yRadius: 1).fill()
+ }, positioned: .below, relativeTo: nil)
+ let open = ActionButton("", style: .row) { [weak self] in self?.openTask(task.id) }
+ open.frame = NSRect(x: x - 4, y: 0, width: w + 4, height: 26)
+ open.setAccessibilityLabel("\(task.description), \(summary.label)")
+ open.setAccessibilityHelp(EquipoStrings.text("task.open_hint"))
+ block.addSubview(open, positioned: .below, relativeTo: nil)
+ return block
+ }
+
+ // MARK: Cards
+
+ private func finish(_ plate: RaisedPlate, height: CGFloat) -> RaisedPlate {
+ let m = MacMetric.shadow
+ plate.content.frame.size.height = height
+ plate.frame.size = NSSize(width: plate.content.frame.width + 2 * m, height: height + 2 * m)
+ return plate
+ }
+
+ private func questionCard(_ card: Card, _ question: Question?, taskTitle: String?, width: CGFloat) -> RaisedPlate {
+ let state = answers[card.id]
+ let answered: Bool = { if case .answered = state { return true }; return false }()
+ let plate = RaisedPlate(width: width, height: 0, flat: answered)
+ let inner = width - 2 * MacMetric.pad
+ var y = MacMetric.pad
+ func add(_ view: NSView, gap: CGFloat = MacMetric.gap) {
+ view.frame.origin = NSPoint(x: MacMetric.pad, y: y); plate.content.addSubview(view); y = view.frame.maxY + gap
+ }
+ if let taskTitle, !(question?.text.contains(taskTitle) ?? false) {
+ add(makeText(taskTitle, MacType.caption, .webSecondary, width: inner), gap: 4)
+ }
+ add(makeText(question?.text ?? EquipoStrings.text("question.loading"), MacType.line, .webText, width: inner, lineSpacing: 2, selectable: true))
+ guard let question else { return finish(plate, height: y - MacMetric.gap + MacMetric.pad) }
+ if question.kind != "clarification" {
+ add(openOnWeb(card, primary: false))
+ return finish(plate, height: y - MacMetric.gap + MacMetric.pad)
+ }
+ if case .answered(let what) = state {
+ add(outcome(EquipoStrings.text("question.answered \(what)"), width: inner))
+ return finish(plate, height: y - MacMetric.gap + MacMetric.pad)
+ }
+ guard question.isAnswerable() else {
+ add(makeText(EquipoStrings.text("question.closed"), MacType.small, .webSecondary, width: inner))
+ return finish(plate, height: y - MacMetric.gap + MacMetric.pad)
+ }
+ let sending: String? = { if case .sending(let id) = state { return id }; return nil }()
+ let options = question.options ?? []
+ if !options.isEmpty {
+ let gap: CGFloat = 10
+ let w = floor((inner - gap * CGFloat(options.count - 1)) / CGFloat(options.count))
+ for (index, option) in options.enumerated() {
+ let busy = sending == option.id ? EquipoStrings.text("action.sending") : nil
+ let b = button(option.label, busy: busy) { [weak self] in
+ self?.submit(card: card, question: question, answer: .option(option.id), shown: option.label, sendingID: option.id)
+ }
+ if sending != nil && sending != option.id { b.isEnabled = false }
+ b.frame = NSRect(x: MacMetric.pad + CGFloat(index) * (w + gap), y: y, width: w, height: 32)
+ b.setAccessibilityLabel(busy ?? option.label)
+ plate.content.addSubview(b)
+ }
+ y += 32 + MacMetric.gap
+ }
+ if question.allowText {
+ let composer = MiniComposerView(width: inner, placeholder: EquipoStrings.text("question.answer_placeholder"), busy: sending == "text")
+ composer.onSend = { [weak self] text in
+ self?.submit(card: card, question: question, answer: .text(text), shown: text, sendingID: "text")
+ }
+ add(composer)
+ }
+ let feedback: String? = {
+ switch state {
+ case .changed: return EquipoStrings.text("card.changed")
+ case .offline: return EquipoStrings.text("card.offline")
+ case .failed: return EquipoStrings.text("card.failed")
+ default: return nil
+ }
+ }()
+ if let feedback {
+ let line = makeText(feedback, MacType.small, .webNegative, width: inner)
+ line.setAccessibilityRole(.staticText)
+ add(line)
+ NSAccessibility.post(element: line, notification: .announcementRequested, userInfo: [.announcement: feedback])
+ }
+ return finish(plate, height: y - MacMetric.gap + MacMetric.pad)
+ }
+
+ private func submit(card: Card, question: Question, answer: EquipoClient.Answer, shown: String, sendingID: String) {
+ if case .sending = answers[card.id] { return }
+ answers[card.id] = .sending(sendingID)
+ rebuild()
+ let session = self.session
+ Task { [weak self] in
+ let outcome = await session.answer(question, with: answer)
+ guard let self else { return }
+ switch outcome {
+ case .answered: self.answers[card.id] = .answered(shown)
+ case .changed: self.answers[card.id] = .changed
+ case .offline: self.answers[card.id] = .offline
+ case .failed: self.answers[card.id] = .failed
+ }
+ self.rebuild()
+ }
+ }
+
+ private func decisionCard(_ card: Card, taskTitle: String?, width: CGFloat) -> RaisedPlate {
+ let plate = RaisedPlate(width: width, height: 0, flat: false)
+ let inner = width - 2 * MacMetric.pad
+ var y = MacMetric.pad
+ func add(_ view: NSView, gap: CGFloat = MacMetric.gap) {
+ view.frame.origin = NSPoint(x: MacMetric.pad, y: y); plate.content.addSubview(view); y = view.frame.maxY + gap
+ }
+ add(makeText(taskTitle ?? EquipoStrings.text("decision.untitled"), MacType.line, .webText, width: inner, lineSpacing: 2), gap: 4)
+ add(makeText(EquipoStrings.text("decision.on_web"), MacType.small, .webSecondary, width: inner))
+ add(openOnWeb(card, primary: true))
+ return finish(plate, height: y - MacMetric.gap + MacMetric.pad)
+ }
+
+ private func openOnWeb(_ card: Card, primary: Bool) -> ActionButton {
+ let url = Feed.webURL(for: card, origin: session.origin)
+ return button(EquipoStrings.text("card.open_on_web"), primary ? .primary : .choice) { NSWorkspace.shared.open(url) }
+ }
+
+ private func outcome(_ line: String, width: CGFloat) -> NSView {
+ let label = makeText(line, MacType.smallStrong, .webPositive, width: width - 20)
+ let view = FlippedView(frame: NSRect(x: 0, y: 0, width: width, height: label.frame.height))
+ if let check = symbolImage("checkmark", size: 11, weight: .bold, color: .webPositive) {
+ let image = NSImageView(image: check)
+ image.frame = NSRect(x: 0, y: ((label.frame.height - check.size.height) / 2).rounded(), width: check.size.width, height: check.size.height)
+ view.addSubview(image)
+ }
+ label.frame.origin = NSPoint(x: 18, y: 0); view.addSubview(label)
+ view.setAccessibilityElement(true); view.setAccessibilityLabel(line)
+ return view
+ }
+}
+
+/// The AppKit transcript in the SwiftUI window. The feed is built in the
+/// SwiftUI body, so any change to the session it reads updates it here.
+struct TranscriptView: NSViewRepresentable {
+ let items: [FeedItem]
+ let session: EquipoSession
+ var openTask: (String) -> Void
+
+ func makeNSView(context: Context) -> LiveTranscript {
+ let view = LiveTranscript(session: session, openTask: openTask)
+ view.update(items: items)
+ return view
+ }
+ func updateNSView(_ view: LiveTranscript, context: Context) {
+ view.openTask = openTask
+ view.update(items: items)
+ }
+}
diff --git a/native/apple/Sources/EquipoMac/MacComposer.swift b/native/apple/Sources/EquipoMac/MacComposer.swift
new file mode 100644
index 00000000..7ff677ee
--- /dev/null
+++ b/native/apple/Sources/EquipoMac/MacComposer.swift
@@ -0,0 +1,128 @@
+import AppKit
+import EquipoKit
+
+/// The composer's text view: Return sends, Shift-Return starts a new line,
+/// and an input method's marked text is never sent half typed.
+final class ComposerEditor: NSTextView {
+ var onSubmit: (() -> Void)?
+ var placeholder = ""
+ override func draw(_ dirtyRect: NSRect) {
+ super.draw(dirtyRect)
+ if string.isEmpty {
+ var attributes = typingAttributes
+ attributes[.foregroundColor] = NSColor.webPlaceholder
+ (placeholder as NSString).draw(in: NSRect(x: 18, y: 0, width: max(0, bounds.width - 36), height: 24), withAttributes: attributes)
+ }
+ }
+ override func didChangeText() { super.didChangeText(); needsDisplay = true }
+ override func keyDown(with event: NSEvent) {
+ if (event.keyCode == 36 || event.keyCode == 76) && !event.modifierFlags.contains(.shift) && !hasMarkedText() {
+ onSubmit?()
+ } else { super.keyDown(with: event) }
+ }
+}
+
+final class ComposerPill: NSView {
+ override var isFlipped: Bool { true }
+ override func draw(_ dirtyRect: NSRect) {
+ let path = NSBezierPath(roundedRect: bounds.insetBy(dx: 0.5, dy: 0.5), xRadius: 22, yRadius: 22)
+ NSColor.webFace.setFill(); path.fill()
+ let focused = window?.firstResponder is ComposerEditor && window?.isKeyWindow == true
+ (focused ? NSColor.webAccent : NSColor.webBorder).setStroke()
+ path.lineWidth = 1; path.stroke()
+ }
+}
+
+/// The conversation's composer, text only in slice 1: a pill that grows to
+/// six lines, then scrolls, with a 44-point send target centred on its last
+/// line.
+final class MacComposer: NSView, NSTextViewDelegate {
+ override var isFlipped: Bool { true }
+ let editor = ComposerEditor()
+ let send = ActionButton("", style: .send, symbol: "arrow.up") {}
+ let pill = ComposerPill()
+ let textScroll = NSScrollView()
+ var onSend: ((String) -> Void)?
+ var onHeightChange: (() -> Void)?
+ private(set) var desiredHeight: CGFloat = 44
+ private var updating = false
+
+ init() {
+ super.init(frame: .zero)
+ addSubview(pill)
+ pill.addSubview(textScroll); pill.addSubview(send)
+ textScroll.documentView = editor
+ textScroll.drawsBackground = false
+ textScroll.hasVerticalScroller = false
+ textScroll.borderType = .noBorder
+ editor.isRichText = false; editor.drawsBackground = false
+ editor.allowsUndo = true
+ editor.font = .systemFont(ofSize: 14)
+ editor.textColor = .webText
+ editor.insertionPointColor = .webText
+ editor.textContainerInset = NSSize(width: 18, height: 0)
+ editor.textContainer?.lineFragmentPadding = 0
+ editor.isVerticallyResizable = true
+ editor.isHorizontallyResizable = false
+ editor.textContainer?.widthTracksTextView = true
+ editor.delegate = self
+ let paragraph = NSMutableParagraphStyle()
+ paragraph.minimumLineHeight = 24; paragraph.maximumLineHeight = 24
+ editor.defaultParagraphStyle = paragraph
+ editor.typingAttributes = [.font: NSFont.systemFont(ofSize: 14), .paragraphStyle: paragraph, .foregroundColor: NSColor.webText, .baselineOffset: 3]
+ editor.placeholder = EquipoStrings.text("conversation.placeholder")
+ editor.setAccessibilityLabel(EquipoStrings.text("conversation.placeholder"))
+ send.toolTip = EquipoStrings.text("composer.send")
+ send.setAccessibilityLabel(EquipoStrings.text("composer.send"))
+ send.actionBlock = { [weak self] in self?.submit() }
+ editor.onSubmit = { [weak self] in self?.submit() }
+ refresh()
+ }
+ required init?(coder: NSCoder) { fatalError() }
+
+ var text: String { editor.string }
+ private var canSend: Bool { !editor.string.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty }
+
+ func textDidChange(_ notification: Notification) { refresh() }
+ func textDidBeginEditing(_ notification: Notification) { pill.needsDisplay = true }
+ func textDidEndEditing(_ notification: Notification) { pill.needsDisplay = true }
+
+ func setText(_ text: String) { editor.string = text; editor.needsDisplay = true; refresh() }
+
+ func submit() {
+ let value = editor.string.trimmingCharacters(in: .whitespacesAndNewlines)
+ guard !value.isEmpty else { return }
+ editor.string = ""; editor.needsDisplay = true
+ refresh(); onSend?(value)
+ window?.makeFirstResponder(editor)
+ }
+
+ func refresh() {
+ send.isHidden = !canSend
+ needsLayout = true
+ layoutSubtreeIfNeeded()
+ }
+
+ override func layout() {
+ super.layout()
+ guard !updating, bounds.width > 80 else { return }
+ updating = true
+ let pillWidth = bounds.width
+ let editorWidth = pillWidth - 44
+ editor.frame.size.width = editorWidth
+ editor.textContainer?.containerSize = NSSize(width: max(1, editorWidth - 36), height: .greatestFiniteMagnitude)
+ editor.layoutManager?.ensureLayout(for: editor.textContainer!)
+ let used = editor.layoutManager?.usedRect(for: editor.textContainer!).height ?? 24
+ let contentHeight = max(24, ceil(used))
+ let height = min(164, contentHeight + 20)
+ pill.frame = NSRect(x: 0, y: 0, width: pillWidth, height: height)
+ textScroll.frame = NSRect(x: 0, y: 10, width: editorWidth, height: height - 20)
+ editor.frame.size = NSSize(width: editorWidth, height: contentHeight)
+ textScroll.hasVerticalScroller = contentHeight > 144
+ send.frame = NSRect(x: pillWidth - 44, y: height - 44, width: 44, height: 44)
+ let changed = desiredHeight != height
+ desiredHeight = height
+ updating = false
+ if changed { onHeightChange?() }
+ }
+}
diff --git a/native/apple/Sources/EquipoMac/MacMainView.swift b/native/apple/Sources/EquipoMac/MacMainView.swift
new file mode 100644
index 00000000..561be49e
--- /dev/null
+++ b/native/apple/Sources/EquipoMac/MacMainView.swift
@@ -0,0 +1,91 @@
+import EquipoKit
+import RastrilloApple
+import SwiftUI
+
+/// The signed-in window: a sidebar of Conversation, Needs you and Tasks, the
+/// chosen one in the middle, and a task in the inspector.
+struct MacMainView: View {
+ let model: EquipoAppModel
+ let session: EquipoSession
+
+ enum Pane: Hashable { case conversation, needs, tasks }
+ @State private var pane: Pane = .conversation
+ @State private var inspectedTask: String?
+ @State private var showsInspector = false
+
+ var body: some View {
+ NavigationSplitView {
+ List(selection: $pane) {
+ Label(EquipoStrings.text("tab.conversation"), systemImage: "bubble.left.and.bubble.right").tag(Pane.conversation)
+ needsRow.tag(Pane.needs)
+ Label(EquipoStrings.text("tab.tasks"), systemImage: "checklist").tag(Pane.tasks)
+ }
+ .listStyle(.sidebar)
+ .navigationSplitViewColumnWidth(min: 200, ideal: 220, max: 280)
+ } detail: {
+ detail
+ .safeAreaInset(edge: .top, spacing: 0) { NativeOfflineBanner(origin: session.origin) }
+ .navigationTitle(session.teamName)
+ .navigationSubtitle(title(for: pane))
+ }
+ .inspector(isPresented: $showsInspector) {
+ Group {
+ if let id = inspectedTask { TaskScreen(session: session, taskID: id).id(id) }
+ else { Text(EquipoStrings.text("task.none_selected")).foregroundStyle(.secondary) }
+ }
+ .inspectorColumnWidth(min: 300, ideal: 360, max: 480)
+ }
+ .toolbar {
+ ToolbarItem(placement: .primaryAction) { needsPill }
+ ToolbarItem(placement: .primaryAction) {
+ Button { showsInspector.toggle() } label: { Image(systemName: "sidebar.right") }
+ .help(EquipoStrings.text("task.inspector"))
+ .accessibilityLabel(EquipoStrings.text("task.inspector"))
+ }
+ }
+ }
+
+ @ViewBuilder private var detail: some View {
+ switch pane {
+ case .conversation:
+ TranscriptView(items: Feed.build(session), session: session, openTask: open)
+ case .needs:
+ NeedsScreen(session: session, openTask: open)
+ case .tasks:
+ TasksScreen(session: session, openTask: open)
+ }
+ }
+
+ @ViewBuilder private var needsRow: some View {
+ if let count = session.needsYou?.count, count > 0 {
+ Label(EquipoStrings.text("tab.needs"), systemImage: "tray").badge(count)
+ } else {
+ Label(EquipoStrings.text("tab.needs"), systemImage: "tray")
+ }
+ }
+
+ /// The web's Needs you pill: an inbox and its count, only when known.
+ private var needsPill: some View {
+ Button { pane = .needs } label: {
+ HStack(spacing: 6) {
+ Image(systemName: "tray")
+ if let count = session.needsYou?.count { Text(count.formatted()).monospacedDigit() }
+ }
+ }
+ .help(EquipoStrings.text("tab.needs"))
+ .accessibilityLabel(session.needsYou.map { EquipoStrings.text("needs.count \($0.count)") } ?? EquipoStrings.text("tab.needs"))
+ }
+
+ private func title(for pane: Pane) -> String {
+ switch pane {
+ case .conversation: return EquipoStrings.text("tab.conversation")
+ case .needs: return EquipoStrings.text("tab.needs")
+ case .tasks: return EquipoStrings.text("tab.tasks")
+ }
+ }
+
+ private func open(_ taskID: String) {
+ inspectedTask = taskID
+ showsInspector = true
+ }
+}
diff --git a/native/apple/Sources/EquipoMac/MacRoster.swift b/native/apple/Sources/EquipoMac/MacRoster.swift
new file mode 100644
index 00000000..ca4c2323
--- /dev/null
+++ b/native/apple/Sources/EquipoMac/MacRoster.swift
@@ -0,0 +1,294 @@
+import AppKit
+import EquipoKit
+
+enum MacType {
+ static var name: NSFont { NSFont.systemFont(ofSize: 13, weight: .bold) }
+ static var verb: NSFont { NSFont.systemFont(ofSize: 12) }
+ static var time: NSFont { NSFont.monospacedDigitSystemFont(ofSize: 11, weight: .regular) }
+ static var eyebrow: NSFont { NSFont.systemFont(ofSize: 11, weight: .semibold) }
+ static var title: NSFont { NSFont.systemFont(ofSize: 15, weight: .semibold) }
+ static var compactTitle: NSFont { NSFont.systemFont(ofSize: 13, weight: .semibold) }
+ static var small: NSFont { NSFont.systemFont(ofSize: 12) }
+ static var smallStrong: NSFont { NSFont.systemFont(ofSize: 12, weight: .semibold) }
+ static var caption: NSFont { NSFont.systemFont(ofSize: 11) }
+ static var code: NSFont { NSFont.monospacedSystemFont(ofSize: 11, weight: .semibold) }
+ static var line: NSFont { NSFont.systemFont(ofSize: 14) }
+ static var thread: NSFont { NSFont.systemFont(ofSize: 13) }
+ static var chip: NSFont { NSFont.systemFont(ofSize: 10, weight: .bold) }
+}
+enum MacMetric {
+ static let gutter: CGFloat = 48
+ static let tile: CGFloat = 30
+ static let gap: CGFloat = 12
+ static let bylineGap: CGFloat = 8
+ static let pad: CGFloat = 16
+ static let radius: CGFloat = 14
+ /// Room around a raised card for its drawn shadow.
+ static let shadow: CGFloat = 14
+}
+
+/// A flipped view that draws with a closure.
+final class PaintView: NSView {
+ override var isFlipped: Bool { true }
+ var paint: (NSRect) -> Void
+ init(frame: NSRect, paint: @escaping (NSRect) -> Void) { self.paint = paint; super.init(frame: frame) }
+ required init?(coder: NSCoder) { fatalError() }
+ override func draw(_ dirtyRect: NSRect) { paint(bounds) }
+}
+@MainActor func makeText(_ value: String, _ font: NSFont, _ color: NSColor = .webText, width: CGFloat = 10000, lineSpacing: CGFloat = 0, selectable: Bool = false, lines: Int = 0) -> NSTextField {
+ let field = NSTextField(wrappingLabelWithString: value)
+ let paragraph = NSMutableParagraphStyle()
+ paragraph.lineSpacing = lineSpacing
+ if lines == 1 { paragraph.lineBreakMode = .byTruncatingTail }
+ field.attributedStringValue = NSAttributedString(string: value, attributes: [.font: font, .foregroundColor: color, .paragraphStyle: paragraph])
+ field.isSelectable = selectable
+ field.maximumNumberOfLines = lines
+ if lines == 1 { field.cell?.lineBreakMode = .byTruncatingTail; field.cell?.wraps = false; field.cell?.truncatesLastVisibleLine = true }
+ let fitted = field.cell?.cellSize(forBounds: NSRect(x: 0, y: 0, width: width, height: 10000)) ?? NSSize(width: width, height: 16)
+ field.frame.size = NSSize(width: min(width, ceil(fitted.width)), height: ceil(fitted.height))
+ return field
+}
+func textWidth(_ value: String, _ font: NSFont) -> CGFloat {
+ ceil((value as NSString).size(withAttributes: [.font: font]).width)
+}
+/// Centres a view vertically on a row of the given height.
+@MainActor func centre(_ view: NSView, x: CGFloat, row y: CGFloat, height: CGFloat) {
+ view.frame.origin = NSPoint(x: x, y: (y + (height - view.frame.height) / 2).rounded())
+}
+func sparklePath(in rect: NSRect) -> NSBezierPath {
+ let s = min(rect.width, rect.height) / 24
+ let ox = rect.midX - 12 * s, oy = rect.midY - 12 * s
+ func p(_ x: CGFloat, _ y: CGFloat) -> NSPoint { NSPoint(x: ox + x * s, y: oy + y * s) }
+ let path = NSBezierPath()
+ path.move(to: p(12, 3))
+ path.curve(to: p(21, 12), controlPoint1: p(13.1, 8.8), controlPoint2: p(15.2, 10.9))
+ path.curve(to: p(12, 21), controlPoint1: p(15.2, 13.1), controlPoint2: p(13.1, 15.2))
+ path.curve(to: p(3, 12), controlPoint1: p(10.9, 15.2), controlPoint2: p(8.8, 13.1))
+ path.curve(to: p(12, 3), controlPoint1: p(8.8, 10.9), controlPoint2: p(10.9, 8.8))
+ path.close()
+ path.lineWidth = s * 1.6
+ path.lineJoinStyle = .round
+ path.lineCapStyle = .round
+ return path
+}
+/// The coordinator's bare, muted mark. Its name is only for VoiceOver.
+@MainActor func sparkleView(size: CGFloat = 22) -> NSView {
+ let view = PaintView(frame: NSRect(x: 0, y: 0, width: size, height: size)) { rect in
+ NSColor.webSecondary.setStroke(); sparklePath(in: rect.insetBy(dx: 0.5, dy: 0.5)).stroke()
+ }
+ view.setAccessibilityElement(true); view.setAccessibilityRole(.image); view.setAccessibilityLabel(Specialist.coordinator.name)
+ return view
+}
+/// A specialist's icon, centred in its tile by the symbol's own bounds.
+@MainActor func tileView(_ who: Specialist, size: CGFloat = MacMetric.tile) -> NSView {
+ if who == .coordinator {
+ let holder = FlippedView(frame: NSRect(x: 0, y: 0, width: size, height: size))
+ let mark = sparkleView(size: (size * 0.74).rounded())
+ mark.frame.origin = NSPoint(x: 0, y: ((size - mark.frame.height) / 2).rounded())
+ holder.addSubview(mark)
+ return holder
+ }
+ let view = PaintView(frame: NSRect(x: 0, y: 0, width: size, height: size)) { rect in
+ let shape = NSBezierPath(roundedRect: rect.insetBy(dx: 0.5, dy: 1), xRadius: size * 0.3, yRadius: size * 0.3)
+ NSGraphicsContext.saveGraphicsState()
+ let shadow = NSShadow(); shadow.shadowColor = NSColor.webShadow.withAlphaComponent(0.08); shadow.shadowOffset = NSSize(width: 0, height: -1); shadow.shadowBlurRadius = 2
+ shadow.set()
+ NSColor.webSurface.setFill(); shape.fill()
+ NSGraphicsContext.restoreGraphicsState()
+ NSColor.webLine.setStroke(); shape.lineWidth = 1; shape.stroke()
+ if let image = symbolImage(who.symbol, size: size * 0.43, weight: .medium, color: .webText) {
+ let r = NSRect(x: ((rect.width - image.size.width) / 2).rounded(), y: ((rect.height - 1 - image.size.height) / 2).rounded(), width: image.size.width, height: image.size.height)
+ image.draw(in: r, from: .zero, operation: .sourceOver, fraction: 1, respectFlipped: true, hints: nil)
+ }
+ }
+ view.setAccessibilityElement(false)
+ return view
+}
+@MainActor func monogramView(_ name: String, size: CGFloat = 16) -> NSView {
+ PaintView(frame: NSRect(x: 0, y: 0, width: size, height: size)) { rect in
+ NSColor.webNeutralBg.setFill()
+ NSBezierPath(roundedRect: rect, xRadius: size * 0.28, yRadius: size * 0.28).fill()
+ let letter = NSAttributedString(string: String(name.prefix(1)).uppercased(), attributes: [.font: NSFont.systemFont(ofSize: size * 0.62, weight: .bold), .foregroundColor: NSColor.webNeutral])
+ let s = letter.size()
+ letter.draw(at: NSPoint(x: ((rect.width - s.width) / 2).rounded(), y: ((rect.height - s.height) / 2).rounded()))
+ }
+}
+
+/// The byline: the author's tile in the gutter, then name, verb, project and
+/// time. One accessibility element, read as `RosterByline.spoken`.
+@MainActor func bylineView(_ byline: RosterByline, width: CGFloat) -> NSView {
+ let view = FlippedView(frame: NSRect(x: 0, y: 0, width: width, height: MacMetric.tile))
+ let avatar = tileView(byline.who); avatar.frame.origin = .zero; view.addSubview(avatar)
+ var x = MacMetric.gutter
+ func add(_ item: NSView, gap: CGFloat = 6) { centre(item, x: x, row: 0, height: MacMetric.tile); view.addSubview(item); x += item.frame.width + gap }
+ if byline.showsName {
+ add(makeText(byline.who.name, MacType.name))
+ add(makeText(byline.verb, MacType.verb, .webSecondary))
+ }
+ if let project = byline.project {
+ if byline.showsName { add(makeText("·", MacType.verb, .webFaint)) }
+ add(monogramView(project), gap: 4)
+ add(makeText(project, MacType.verb, .webSecondary, lines: 1))
+ }
+ if let time = byline.timeText { add(makeText(time, MacType.time, .webFaint)) }
+ view.setAccessibilityElement(true); view.setAccessibilityRole(.group); view.setAccessibilityLabel(byline.spoken)
+ return view
+}
+
+@MainActor func needsChipView() -> NSView {
+ let label = NSAttributedString(string: EquipoStrings.text("chip.needs_you").uppercased(), attributes: [.font: MacType.chip, .foregroundColor: NSColor.webWarning, .kern: 0.3])
+ let width = ceil(label.size().width) + 16 + 15
+ let view = PaintView(frame: NSRect(x: 0, y: 0, width: width, height: 19)) { rect in
+ NSColor.webWarningBg.setFill(); NSBezierPath(roundedRect: rect, xRadius: rect.height / 2, yRadius: rect.height / 2).fill()
+ if let hand = symbolImage("hand.raised", size: 10, weight: .semibold, color: .webWarning) {
+ hand.draw(in: NSRect(x: 8, y: ((rect.height - hand.size.height) / 2).rounded(), width: hand.size.width, height: hand.size.height), from: .zero, operation: .sourceOver, fraction: 1, respectFlipped: true, hints: nil)
+ }
+ label.draw(at: NSPoint(x: 23, y: ((rect.height - label.size().height) / 2).rounded()))
+ }
+ view.setAccessibilityElement(true); view.setAccessibilityLabel(EquipoStrings.text("chip.needs_you"))
+ return view
+}
+extension StageTone {
+ var ns: NSColor { self == .warning ? .webWarning : self == .negative ? .webNegative : .webPositive }
+ var nsHalo: NSColor { self == .warning ? .webWarningBg : self == .negative ? .webNegativeBg : .webPositiveBg }
+ var nsEyebrow: NSColor { self == .positive ? .webSecondary : ns }
+}
+@MainActor func button(_ title: String, _ style: ActionButton.Style = .choice, symbol: String? = nil, forced: ForcedState? = nil, busy: String? = nil, action: @escaping () -> Void = {}) -> ActionButton {
+ let b = ActionButton(title, style: style, symbol: symbol, action: action)
+ b.forced = forced
+ b.busyLabel = busy
+ let label = busy ?? title
+ let font = NSFont.systemFont(ofSize: 13, weight: style == .link ? .regular : .medium)
+ let extra: CGFloat = (symbol != nil ? 16 : 0) + (busy != nil ? 22 : 0)
+ b.frame.size = NSSize(width: style == .link ? textWidth(label, font) + extra + 4 : max(64, textWidth(label, font) + 32 + extra), height: 32)
+ return b
+}
+
+/// A raised card's plate: the surface, a rim and the web's two-step shadow.
+/// The view is larger than the card by `MacMetric.shadow` on every side.
+final class RaisedPlate: NSView {
+ override var isFlipped: Bool { true }
+ var flat: Bool
+ var dashed = false
+ let content = FlippedView()
+ init(width: CGFloat, height: CGFloat, flat: Bool) {
+ self.flat = flat
+ let m = MacMetric.shadow
+ super.init(frame: NSRect(x: 0, y: 0, width: width + 2 * m, height: height + 2 * m))
+ content.frame = NSRect(x: m, y: m, width: width, height: height)
+ addSubview(content)
+ }
+ required init?(coder: NSCoder) { fatalError() }
+ override func draw(_ dirtyRect: NSRect) {
+ let card = bounds.insetBy(dx: MacMetric.shadow + 0.5, dy: MacMetric.shadow + 0.5)
+ let shape = NSBezierPath(roundedRect: card, xRadius: MacMetric.radius, yRadius: MacMetric.radius)
+ if !flat {
+ for (alpha, blur, y) in [(0.06, 4.0, 2.0), (0.10, 14.0, 6.0)] as [(CGFloat, CGFloat, CGFloat)] {
+ NSGraphicsContext.saveGraphicsState()
+ let shadow = NSShadow()
+ shadow.shadowColor = NSColor.webShadow.withAlphaComponent(NSAppearance.currentDrawing().bestMatch(from: [.aqua, .darkAqua]) == .darkAqua ? alpha * 4 : alpha)
+ shadow.shadowBlurRadius = blur; shadow.shadowOffset = NSSize(width: 0, height: -y)
+ shadow.set()
+ NSColor.webSurface.setFill(); shape.fill()
+ NSGraphicsContext.restoreGraphicsState()
+ }
+ }
+ (flat ? NSColor.webSurface2 : NSColor.webSurface).setFill(); shape.fill()
+ (flat ? NSColor.webLine : NSColor.webLightRim).setStroke(); shape.lineWidth = 1; shape.stroke()
+ }
+}
+/// A sub-chat turn: yours on the right with "Sent", theirs with an avatar.
+@MainActor func threadTurnView(_ turn: ThreadTurn, width: CGFloat) -> NSView {
+ let view = FlippedView(frame: NSRect(x: 0, y: 0, width: width, height: 0))
+ if turn.own {
+ let body = makeText(turn.text, MacType.thread, .webText, width: min(width * 0.8, 440) - 24, selectable: true)
+ let bubble = PaintView(frame: NSRect(x: width - body.frame.width - 24, y: 0, width: body.frame.width + 24, height: body.frame.height + 16)) { r in
+ let p = NSBezierPath(roundedRect: r.insetBy(dx: 0.5, dy: 0.5), xRadius: 12, yRadius: 12)
+ NSColor.webSoft.setFill(); p.fill(); NSColor.webLightRim.setStroke(); p.stroke()
+ }
+ body.frame.origin = NSPoint(x: 12, y: 8); bubble.addSubview(body); view.addSubview(bubble)
+ let sent = makeText(EquipoStrings.text("thread.sent"), MacType.caption, .webFaint); sent.frame.origin = NSPoint(x: width - sent.frame.width, y: bubble.frame.maxY + 4); view.addSubview(sent)
+ view.frame.size.height = sent.frame.maxY
+ view.setAccessibilityElement(true); view.setAccessibilityLabel(EquipoStrings.text("thread.own_spoken \(turn.text)"))
+ } else {
+ let who = turn.who ?? .coordinator
+ let avatar = tileView(who, size: 24); avatar.frame.origin = NSPoint(x: 0, y: 2); view.addSubview(avatar)
+ let maxBody = min(width - 32, 460) - 24
+ let name = makeText(who.name, NSFont.systemFont(ofSize: 11, weight: .semibold), .webSecondary)
+ let time = makeText(turn.timeText, MacType.time, .webFaint)
+ let body = makeText(turn.text, MacType.thread, .webText, width: maxBody, selectable: true)
+ let inner = max(body.frame.width, name.frame.width + 6 + time.frame.width)
+ let bubble = PaintView(frame: NSRect(x: 32, y: 0, width: inner + 24, height: name.frame.height + 3 + body.frame.height + 14)) { r in
+ let p = NSBezierPath(roundedRect: r.insetBy(dx: 0.5, dy: 0.5), xRadius: 12, yRadius: 12)
+ NSColor.webSurface.setFill(); p.fill(); NSColor.webLine.setStroke(); p.stroke()
+ }
+ name.frame.origin = NSPoint(x: 12, y: 6); bubble.addSubview(name)
+ time.frame.origin = NSPoint(x: name.frame.maxX + 6, y: 6); bubble.addSubview(time)
+ body.frame.origin = NSPoint(x: 12, y: name.frame.maxY + 3); bubble.addSubview(body)
+ view.addSubview(bubble)
+ view.frame.size.height = bubble.frame.maxY
+ view.setAccessibilityElement(true); view.setAccessibilityLabel("\(who.name), \(turn.timeText): \(turn.text)")
+ }
+ return view
+}
+@MainActor func readingView(_ who: Specialist) -> NSView {
+ let label = makeText(EquipoStrings.text("thread.reading \(who.name)"), MacType.small, .webSecondary)
+ let view = PaintView(frame: NSRect(x: 0, y: 0, width: label.frame.width + 28, height: max(18, label.frame.height))) { r in
+ NSColor.webSecondary.setFill()
+ for i in 0..<3 { NSBezierPath(ovalIn: NSRect(x: CGFloat(i) * 6, y: r.midY - 2, width: 4, height: 4)).fill() }
+ }
+ label.frame.origin = NSPoint(x: 28, y: 0); view.addSubview(label)
+ view.setAccessibilityElement(true); view.setAccessibilityLabel(label.stringValue)
+ return view
+}
+
+/// The card composer: a 46-point pill with a 44-point send target centred in it.
+final class MiniComposerView: NSView, NSTextFieldDelegate {
+ override var isFlipped: Bool { true }
+ let field = NSTextField()
+ let send: ActionButton
+ var focused: Bool { didSet { needsDisplay = true } }
+ var onSend: ((String) -> Void)?
+ init(width: CGFloat, placeholder: String, text: String = "", focused: Bool = false, busy: Bool = false) {
+ self.focused = focused
+ send = ActionButton(busy ? EquipoStrings.text("action.sending") : "", style: busy ? .primary : .miniSend, symbol: busy ? nil : "arrow.up") {}
+ super.init(frame: NSRect(x: 0, y: 0, width: width, height: 46))
+ field.isBordered = false; field.drawsBackground = false; field.focusRingType = .none
+ field.font = NSFont.systemFont(ofSize: 13); field.textColor = .webText
+ field.placeholderAttributedString = NSAttributedString(string: placeholder, attributes: [.font: NSFont.systemFont(ofSize: 13), .foregroundColor: NSColor.webPlaceholder])
+ field.stringValue = text
+ field.delegate = self
+ field.setAccessibilityLabel(placeholder)
+ let h = ceil(field.intrinsicContentSize.height)
+ field.frame = NSRect(x: 16, y: ((46 - h) / 2).rounded(), width: width - 16 - 50, height: h)
+ addSubview(field)
+ send.hasContent = !text.trimmingCharacters(in: .whitespaces).isEmpty
+ send.setAccessibilityLabel(busy ? EquipoStrings.text("action.sending") : EquipoStrings.text("composer.send"))
+ send.frame = busy ? NSRect(x: width - 96, y: 5, width: 90, height: 36) : NSRect(x: width - 45, y: 1, width: 44, height: 44)
+ send.actionBlock = { [weak self] in self?.submit() }
+ addSubview(send)
+ }
+ required init?(coder: NSCoder) { fatalError() }
+ func controlTextDidChange(_ obj: Notification) {
+ send.hasContent = !field.stringValue.trimmingCharacters(in: .whitespaces).isEmpty
+ focused = true
+ }
+ func controlTextDidEndEditing(_ obj: Notification) { focused = false }
+ /// Return sends; the field is single-line, so there is no newline to keep.
+ func control(_ control: NSControl, textView: NSTextView, doCommandBy selector: Selector) -> Bool {
+ guard selector == #selector(NSResponder.insertNewline(_:)) else { return false }
+ submit(); return true
+ }
+ func submit() {
+ let value = field.stringValue.trimmingCharacters(in: .whitespacesAndNewlines)
+ guard !value.isEmpty else { return }
+ onSend?(value)
+ field.stringValue = ""; send.hasContent = false
+ }
+ override func draw(_ dirtyRect: NSRect) {
+ let shape = NSBezierPath(roundedRect: bounds.insetBy(dx: 0.5, dy: 0.5), xRadius: 22.5, yRadius: 22.5)
+ let on = focused || send.hasContent
+ NSColor.webSurface.setFill(); shape.fill()
+ (on ? NSColor.webAccent : NSColor.webBorder).setStroke(); shape.lineWidth = 1; shape.stroke()
+ }
+}
diff --git a/native/apple/Sources/EquipoMac/MacStyle.swift b/native/apple/Sources/EquipoMac/MacStyle.swift
new file mode 100644
index 00000000..f96e7b8e
--- /dev/null
+++ b/native/apple/Sources/EquipoMac/MacStyle.swift
@@ -0,0 +1,204 @@
+import AppKit
+import EquipoKit
+
+// Ported from the r7 mockups (native-mockups-r4: native/mockups/Mac/
+// RosterAppKit.swift, NativeTranscript.swift, NativeComposer.swift): the
+// web's tokens and controls, drawn in AppKit.
+
+/// Hover, pressed and focus can be forced for a still capture; the live app
+/// draws them from the pointer and the keyboard.
+enum ForcedState { case hover, pressed, focus, disabled }
+
+extension NSColor {
+ static func web(_ light: UInt32, _ dark: UInt32) -> NSColor {
+ NSColor(name: nil) { appearance in
+ let value = appearance.bestMatch(from: [.aqua, .darkAqua]) == .darkAqua ? dark : light
+ return NSColor(srgbRed: Double((value >> 16) & 255) / 255, green: Double((value >> 8) & 255) / 255, blue: Double(value & 255) / 255, alpha: 1)
+ }
+ }
+ static let webText = web(0x18181B, 0xEDEDF0)
+ static let webFace = web(0xFFFFFF, 0x141518)
+ static let webPlaceholder = web(0x6B6B75, 0x8C8C96)
+ static let webPrimary = web(0x2257DF, 0x2F61E8)
+ static let webBorder = web(0xD0D4DC, 0x343843)
+ static let webBackground = web(0xFBFBFC, 0x0C0D0F)
+ static let webSecondary = web(0x52525C, 0xA1A1AA)
+ static let webAccent = web(0x1F56D6, 0x7AA2FF)
+ static let webSoft = web(0xECF1FF, 0x16234A)
+ static let webSoftBorder = web(0xC9D7FA, 0x27397A)
+ static let webLine = web(0xE6E6EA, 0x26282E)
+ static let webSurface2 = web(0xF3F3F5, 0x18191D)
+ static let webFaceHover = web(0xF4F5F8, 0x1B1D22)
+ static let webFacePressed = web(0xE9EBEF, 0x22242B)
+ static let webPrimaryHover = web(0x1D4DC8, 0x2956D0)
+ static let webPrimaryEdge = web(0x153CA0, 0x1F43A6)
+ static let webPositive = web(0x166534, 0x6EE7A8)
+ static let webNegative = web(0xB91C1C, 0xF79AA0)
+}
+
+extension NSColor {
+ static let webFaint = web(0x6B6B75, 0x8C8C96)
+ static let webSurface = web(0xFFFFFF, 0x141518)
+ static let webLightRim = web(0xB8C5E5, 0x5D6986)
+ static let webLineStrong = web(0x868691, 0x71737C)
+ static let webWarning = web(0x854D0E, 0xF0C46A)
+ static let webWarningBg = web(0xFEF3C7, 0x2C2110)
+ static let webPositiveBg = web(0xDCFCE7, 0x10281C)
+ static let webNegativeBg = web(0xFEE2E2, 0x331819)
+ static let webNeutral = web(0x374151, 0xC3C9D1)
+ static let webNeutralBg = web(0xEEF0F2, 0x262C34)
+ static let webShadow = web(0x101828, 0x000000)
+}
+func symbolImage(_ name: String, size: CGFloat, weight: NSFont.Weight = .medium, color: NSColor) -> NSImage? {
+ NSImage(systemSymbolName: name, accessibilityDescription: nil)?
+ .withSymbolConfiguration(NSImage.SymbolConfiguration(pointSize: size, weight: weight).applying(NSImage.SymbolConfiguration(paletteColors: [color])))
+}
+
+/// The web's controls, drawn in AppKit: rest, hover, pressed, focus,
+/// disabled and busy.
+final class ActionButton: NSButton {
+ enum Style { case choice, primary, quiet, round, send, glyph, row, link, miniSend, aside }
+ var style: Style { didSet { needsDisplay = true } }
+ var symbol: String? { didSet { needsDisplay = true } }
+ var forced: ForcedState? { didSet { needsDisplay = true } }
+ /// The web's data-busy-label: shown with a spinner while a request runs.
+ var busyLabel: String? { didSet { updateSpinner() } }
+ /// For the card composer's send button: filled once there is something to send.
+ var hasContent = false { didSet { needsDisplay = true } }
+ var actionBlock: (() -> Void)?
+ private var hovering = false
+ private var tracking: NSTrackingArea?
+ private var spinner: NSProgressIndicator?
+ init(_ title: String, style: Style = .choice, symbol: String? = nil, action: @escaping () -> Void) {
+ self.style = style
+ self.symbol = symbol
+ super.init(frame: .zero)
+ self.title = title
+ actionBlock = action
+ isBordered = false
+ setButtonType(.momentaryPushIn)
+ focusRingType = .exterior
+ target = self
+ self.action = #selector(performAction)
+ if !title.isEmpty { setAccessibilityLabel(title) }
+ }
+ required init?(coder: NSCoder) { fatalError() }
+ override var isFlipped: Bool { true }
+ @objc private func performAction() { actionBlock?() }
+ override var wantsUpdateLayer: Bool { false }
+ override func updateTrackingAreas() {
+ super.updateTrackingAreas()
+ if let tracking { removeTrackingArea(tracking) }
+ let area = NSTrackingArea(rect: .zero, options: [.mouseEnteredAndExited, .activeAlways, .inVisibleRect], owner: self)
+ addTrackingArea(area)
+ tracking = area
+ }
+ override func mouseEntered(with event: NSEvent) { hovering = true; needsDisplay = true }
+ override func mouseExited(with event: NSEvent) { hovering = false; needsDisplay = true }
+ private func updateSpinner() {
+ spinner?.removeFromSuperview(); spinner = nil
+ isEnabled = busyLabel == nil
+ if busyLabel != nil {
+ let s = NSProgressIndicator(frame: NSRect(x: 0, y: 0, width: 14, height: 14))
+ s.style = .spinning; s.controlSize = .small; s.isDisplayedWhenStopped = true
+ if style == .primary { s.appearance = NSAppearance(named: .darkAqua) }
+ addSubview(s); spinner = s
+ setAccessibilityLabel(busyLabel)
+ }
+ needsLayout = true; needsDisplay = true
+ }
+ private var shapePath: NSBezierPath {
+ switch style {
+ case .choice, .primary: return NSBezierPath(roundedRect: bounds.insetBy(dx: 0.5, dy: 0.5), xRadius: 6, yRadius: 6)
+ case .round: return NSBezierPath(ovalIn: bounds.insetBy(dx: 0.5, dy: 0.5))
+ case .send: return NSBezierPath(ovalIn: bounds.insetBy(dx: 6, dy: 6))
+ case .miniSend: return NSBezierPath(ovalIn: bounds.insetBy(dx: 4, dy: 4))
+ case .glyph: return NSBezierPath(ovalIn: bounds.insetBy(dx: 9, dy: 9))
+ case .aside: return NSBezierPath(roundedRect: NSRect(x: (bounds.width - 28) / 2, y: (bounds.height - 28) / 2, width: 28, height: 28), xRadius: 6, yRadius: 6)
+ case .quiet, .row, .link: return NSBezierPath(roundedRect: bounds, xRadius: 6, yRadius: 6)
+ }
+ }
+ override var focusRingMaskBounds: NSRect { bounds }
+ override func drawFocusRingMask() { shapePath.fill() }
+ override func draw(_ dirtyRect: NSRect) {
+ let busy = busyLabel != nil
+ let enabled = (isEnabled || busy) && forced != .disabled
+ let pressed = (isHighlighted || forced == .pressed) && enabled
+ let hover = (hovering || forced == .hover) && enabled && !busy
+ let path = shapePath
+ NSGraphicsContext.current?.cgContext.setAlpha(enabled ? 1 : 0.45)
+ var textColor = NSColor.webText
+ var symbolColor = NSColor.webSecondary
+ switch style {
+ case .choice, .round:
+ (pressed ? NSColor.webFacePressed : hover ? NSColor.webFaceHover : NSColor.webFace).setFill(); path.fill()
+ NSColor.webBorder.setStroke(); path.lineWidth = 1; path.stroke()
+ case .primary, .send:
+ (pressed ? NSColor.webPrimaryEdge : hover ? NSColor.webPrimaryHover : NSColor.webPrimary).setFill(); path.fill()
+ if style == .primary { NSColor.webPrimaryEdge.setStroke(); path.lineWidth = 1; path.stroke() }
+ textColor = .white; symbolColor = .white
+ case .miniSend:
+ if hasContent { (pressed ? NSColor.webPrimaryEdge : hover ? NSColor.webPrimaryHover : NSColor.webPrimary).setFill(); symbolColor = .white }
+ else { NSColor.webSurface2.setFill(); symbolColor = .webFaint }
+ path.fill()
+ case .glyph, .row, .aside:
+ if hover || pressed { (pressed ? NSColor.webFacePressed : NSColor.webFaceHover).setFill(); path.fill() }
+ case .quiet:
+ textColor = .webAccent
+ case .link:
+ textColor = hover ? .webText : .webSecondary; symbolColor = textColor
+ }
+ if forced == .focus {
+ let ring = NSBezierPath(roundedRect: bounds.insetBy(dx: -2, dy: -2), xRadius: 8, yRadius: 8)
+ NSColor.keyboardFocusIndicatorColor.setStroke(); ring.lineWidth = 3; ring.stroke()
+ }
+ let label = busyLabel ?? title
+ var attributes: [NSAttributedString.Key: Any] = [
+ .font: NSFont.systemFont(ofSize: 13, weight: style == .quiet || style == .row || style == .link ? .regular : .medium),
+ .foregroundColor: textColor,
+ ]
+ if (style == .quiet || style == .link) && hover { attributes[.underlineStyle] = NSUnderlineStyle.single.rawValue }
+ let text = NSAttributedString(string: label, attributes: attributes)
+ let textSize = label.isEmpty ? NSSize.zero : text.size()
+ let image = busy ? nil : symbol.flatMap { symbolImage($0, size: style == .send || style == .miniSend ? 13 : style == .glyph || style == .link || style == .aside ? 11 : 15, weight: style == .send || style == .miniSend ? .bold : .semibold, color: symbolColor) }
+ let imageSize = image?.size ?? .zero
+ let spin: CGFloat = busy ? 20 : 0
+ let gap: CGFloat = image != nil && !label.isEmpty ? (style == .link ? 4 : 8) : 0
+ var x: CGFloat
+ switch style {
+ case .quiet, .link: x = 0
+ case .row: x = 10
+ default: x = (bounds.width - textSize.width - imageSize.width - gap - spin) / 2
+ }
+ if let spinner { spinner.frame.origin = NSPoint(x: x.rounded(), y: ((bounds.height - 14) / 2).rounded()); x += spin }
+ let drawImage = { (at: CGFloat) in
+ guard let image else { return }
+ image.draw(in: NSRect(x: at.rounded(), y: ((self.bounds.height - imageSize.height) / 2).rounded(), width: imageSize.width, height: imageSize.height), from: .zero, operation: .sourceOver, fraction: 1, respectFlipped: true, hints: nil)
+ }
+ if style == .link {
+ if !label.isEmpty { text.draw(at: NSPoint(x: x.rounded(), y: ((bounds.height - textSize.height) / 2).rounded())) }
+ drawImage(x + textSize.width + gap)
+ return
+ }
+ if image != nil { drawImage(x); x += imageSize.width + gap }
+ if !label.isEmpty { text.draw(at: NSPoint(x: x.rounded(), y: ((bounds.height - textSize.height) / 2).rounded())) }
+ }
+}
+final class FlippedView: NSView { override var isFlipped: Bool { true } }
+final class CardView: NSView {
+ override var isFlipped: Bool { true }
+ let fill: NSColor
+ let stroke: NSColor?
+ let radius: CGFloat
+ init(fill: NSColor, stroke: NSColor? = nil, radius: CGFloat = 10) {
+ self.fill = fill; self.stroke = stroke; self.radius = radius
+ super.init(frame: .zero)
+ }
+ required init?(coder: NSCoder) { fatalError() }
+ override func draw(_ dirtyRect: NSRect) {
+ let path = NSBezierPath(roundedRect: bounds.insetBy(dx: 0.5, dy: 0.5), xRadius: radius, yRadius: radius)
+ fill.setFill(); path.fill()
+ if let stroke { stroke.setStroke(); path.lineWidth = 1; path.stroke() }
+ }
+}
+
diff --git a/native/apple/Sources/EquipoMac/main.swift b/native/apple/Sources/EquipoMac/main.swift
deleted file mode 100644
index 1984571b..00000000
--- a/native/apple/Sources/EquipoMac/main.swift
+++ /dev/null
@@ -1,5 +0,0 @@
-import EquipoKit
-
-// The Mac app; built out below.
-struct EquipoMacMain { static func main() {} }
-EquipoMacMain.main()
diff --git a/native/apple/Tests/EquipoKitTests/LiveTests.swift b/native/apple/Tests/EquipoKitTests/LiveTests.swift
new file mode 100644
index 00000000..ec536f20
--- /dev/null
+++ b/native/apple/Tests/EquipoKitTests/LiveTests.swift
@@ -0,0 +1,67 @@
+import Foundation
+import Testing
+@testable import EquipoKit
+
+/// End to end against a real Equipo: pair, read, send, poll, sign out.
+/// Off unless EQUIPO_LIVE_ORIGIN is set (a local drive, `tools/drive`).
+/// It writes the code and approval link to EQUIPO_LIVE_HANDOFF and waits up
+/// to ten minutes for a person to approve the device in a browser.
+@MainActor @Suite(.enabled(if: ProcessInfo.processInfo.environment["EQUIPO_LIVE_ORIGIN"] != nil), .timeLimit(.minutes(15)))
+struct LiveTests {
+ @Test func pairReadSendAndSignOut() async throws {
+ let env = ProcessInfo.processInfo.environment
+ let origin = try #require(PairingModel.origin(from: env["EQUIPO_LIVE_ORIGIN"]!))
+ let handoff = URL(fileURLWithPath: env["EQUIPO_LIVE_HANDOFF"] ?? NSTemporaryDirectory() + "equipo-live-handoff.txt")
+ let store = MemorySecretStore()
+ let accounts = DeviceAccounts(store: store)
+ let pairing = PairingModel(accounts: accounts)
+ pairing.start(origin: origin, label: "EquipoKit live test")
+
+ var wrote = false
+ let deadline = Date().addingTimeInterval(600)
+ while Date() < deadline {
+ switch pairing.step {
+ case .waiting(let code, let url, _) where !wrote:
+ try "\(code)\n\(url.absoluteString)\n".write(to: handoff, atomically: true, encoding: .utf8)
+ wrote = true
+ case .approved, .expired, .failed: break
+ default: break
+ }
+ if case .approved = pairing.step { break }
+ if case .expired = pairing.step { break }
+ if case .failed = pairing.step { break }
+ try await Task.sleep(for: .milliseconds(500))
+ }
+ guard case .approved(let team) = pairing.step, let account = pairing.account else {
+ Issue.record("pairing ended as \(pairing.step)"); return
+ }
+ print("LIVE paired with \(team) as device \(account.credential?.id ?? "?")")
+
+ let session = EquipoSession(account: account, accounts: accounts)
+ await session.refresh()
+ #expect(session.status == .ready)
+ #expect(session.me != nil)
+ print("LIVE read \(session.messages.count) messages, \(session.cards.count) cards, \(session.tasks.count) tasks, needs you \(session.needsYou.map { String($0.count) } ?? "unknown")")
+
+ let text = "Native slice 1 live check \(UUID().uuidString.prefix(8))"
+ await session.send(text)
+ #expect(session.outgoing.isEmpty, "the message was not accepted: \(session.outgoing)")
+ #expect(session.messages.contains { $0.isOwn && $0.body == text })
+
+ if let task = session.tasks.first {
+ await session.loadThread(task.id)
+ print("LIVE thread of \(task.id): \(session.threads[task.id]?.count ?? 0) messages")
+ }
+
+ await session.pollOnce()
+ #expect(session.storedSubscription() != nil, "no notification subscription")
+
+ await session.signOut()
+ #expect(accounts.all().isEmpty)
+ // The credential no longer works: the server revoked it.
+ let after = EquipoClient(transport: URLSessionTransport(origin: origin), token: account.credential?.token)
+ do { _ = try await after.me(); Issue.record("a revoked device could still read") }
+ catch let error as EquipoAPIError { #expect(error.endsSession, "expected 401 after revocation, got \(error)") }
+ print("LIVE signed out; the revoked credential is refused")
+ }
+}
diff --git a/native/apple/Tests/EquipoKitTests/PairingTests.swift b/native/apple/Tests/EquipoKitTests/PairingTests.swift
index 644b18a1..1ad28c3c 100644
--- a/native/apple/Tests/EquipoKitTests/PairingTests.swift
+++ b/native/apple/Tests/EquipoKitTests/PairingTests.swift
@@ -61,11 +61,27 @@ final class Sleeps: @unchecked Sendable {
#expect(Set(t.sent("POST /auth/devices").map(\.idempotencyKey)).count == 1)
}
+ @Test func theBrowserPageMustBeTheTeams() async throws {
+ let t = ScriptedTransport()
+ var challenge = try JSONSerialization.jsonObject(with: Fixture.data("device-challenge")) as! [String: Any]
+ challenge["verification_uri"] = "https://elsewhere.example.test/approve"
+ t.on("POST /auth/devices", .success(APIResponse(status: 200, data: try JSONSerialization.data(withJSONObject: challenge))))
+ let model = PairingModel(accounts: DeviceAccounts(store: MemorySecretStore()), makeTransport: { _ in t }, sleep: Sleeps().sleep)
+ await model.run(origin: t.origin, label: "Test")
+ if case .failed = model.step {} else { Issue.record("a foreign approval page was accepted: \(model.step)") }
+ #expect(t.sent("POST /auth/devices/exchange").isEmpty)
+ }
+
@Test func originParsing() {
#expect(PairingModel.origin(from: "paulca.equipo.oficina.works")?.absoluteString == "https://paulca.equipo.oficina.works")
#expect(PairingModel.origin(from: " https://Team.Example.test/some/path?x ")?.absoluteString == "https://team.example.test")
#expect(PairingModel.origin(from: "http://team.example.test") == nil)
#expect(PairingModel.origin(from: "https://user@team.example.test") == nil)
#expect(PairingModel.origin(from: "") == nil)
+ // Plain http only to this machine.
+ #expect(PairingModel.origin(from: "http://127.0.0.1:8824")?.absoluteString == "http://127.0.0.1:8824")
+ #expect(PairingModel.origin(from: "http://localhost:8824/x")?.absoluteString == "http://localhost:8824")
+ #expect(PairingModel.origin(from: "http://127.0.0.1.example.test") == nil)
+ #expect(PairingModel.origin(from: "http://10.0.0.5:8824") == nil)
}
}
diff --git a/native/scripts/check-strings.py b/native/scripts/check-strings.py
index 936d5680..84ee7257 100755
--- a/native/scripts/check-strings.py
+++ b/native/scripts/check-strings.py
@@ -24,7 +24,8 @@ def used_keys():
for m in re.finditer(r'(?:String\(localized:|EquipoStrings\.text\()\s*"((?:[^"\\]|\\.|\\\([^)]*\))*)"', text):
raw = m.group(1)
# Interpolations become format specifiers: Int as %lld, the rest %@.
- raw = re.sub(r'\\\((count|[a-z]+\.count)\)', '%lld', raw)
+ # A count (count, x.count, $0.count) is an Int.
+ raw = re.sub(r'\\\((?:[\w$]+\.)?count\)', '%lld', raw)
raw = re.sub(r'\\\((?:[^()]|\([^()]*\))*\)', '%@', raw)
keys.add(raw)
return keys
diff --git a/native/scripts/strings.json b/native/scripts/strings.json
index 3a25d9b8..679502b0 100644
--- a/native/scripts/strings.json
+++ b/native/scripts/strings.json
@@ -13,6 +13,7 @@
"action.sending": "Sending…",
"action.set_aside": "Set aside",
"action.setting_aside": "Setting aside…",
+ "app.name": "Equipo",
"byline.asks": "asks",
"byline.reports": "reports",
"card.changed": "This item has changed. Check it before trying again.",
@@ -30,6 +31,7 @@
"message.own_spoken %@": "You said: %@",
"message.sending": "Sending…",
"message.waiting": "Waiting for a connection. Try again.",
+ "needs.count %lld": "%lld waiting for you",
"needs.count_spoken %lld": "%lld waiting for you",
"needs.empty": "Questions and decisions for you appear here.",
"needs.empty_title": "Nothing needs you",
@@ -62,6 +64,7 @@
"question.answered %@": "You answered: %@",
"question.closed": "This question is no longer open.",
"question.loading": "Loading the question…",
+ "settings.not_paired": "Pair this Mac with a team to see its settings.",
"specialist.checks": "Checks",
"specialist.coordinator": "Coordinator",
"specialist.copy": "Copy",
@@ -75,8 +78,10 @@
"task.cancelled": "Cancelled",
"task.done": "Done",
"task.hide_talk": "Hide the talk",
+ "task.inspector": "Show or hide the task",
"task.missing": "This task is not available.",
"task.needs_you": "Needs you",
+ "task.none_selected": "Choose a task to see it here.",
"task.not_started": "Not started",
"task.open_hint": "Opens the task",
"task.open_web": "Open on the web",