oficina / base Public

Native apps name a person's files under their words (Task 10)

Human

Prompt

Build Base's half of files in Ask, slice 1, task by task from the approved plan, tests first.

From this commit's own message. The prompt ledger has no entries for it — which is what a squashed, rebased or amended commit looks like, and what every commit looks like in a repo without a ledger.

Summary

BaseKit decodes a message's attachments (an unknown kind is a file, one without an id dropped); a person's bubble shows their words, then one plain line of the files' names with a paperclip, so a files-only message is never empty; VoiceOver reads ask.files_line_a11y (Attached: {names}). Slice 2 draws files properly.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev e5da47100885f7ab5adbef0f96b8f71268366aeb parent 667433d
4 files changed, +120 −11
  • native/apple/Sources/BaseKit/API/Models.swift +31 −3
  • native/apple/Sources/BaseKit/Ask/Thread.swift +44 −8
  • native/apple/Sources/BaseKit/Resources/Localizable.xcstrings +12 −0
  • native/apple/Tests/BaseKitTests/AskViewTests.swift +33 −0
diff --git a/native/apple/Sources/BaseKit/API/Models.swift b/native/apple/Sources/BaseKit/API/Models.swift
index ce7cb20..66c549a 100644
--- a/native/apple/Sources/BaseKit/API/Models.swift
+++ b/native/apple/Sources/BaseKit/API/Models.swift
@@ -164,15 +164,43 @@ public struct AskMessage: Decodable, Sendable, Equatable, Identifiable {
public var text: String
public var turnID: String
public var createdAt: Date?
+ /// The files the person sent with it, in order (none for most).
+ public var attachments: [AskAttachment]
public var isPerson: Bool { role == "person" }
- public init(id: String, role: String, text: String, turnID: String = "", createdAt: Date? = nil) {
- self.id = id; self.role = role; self.text = text; self.turnID = turnID; self.createdAt = createdAt
+ public init(id: String, role: String, text: String, turnID: String = "", createdAt: Date? = nil, attachments: [AskAttachment] = []) {
+ self.id = id; self.role = role; self.text = text; self.turnID = turnID; self.createdAt = createdAt; self.attachments = attachments
}
- enum CodingKeys: String, CodingKey { case id, role, text, turnID = "turn_id", createdAt = "created_at" }
+ enum CodingKeys: String, CodingKey { case id, role, text, turnID = "turn_id", createdAt = "created_at", attachments }
public init(from decoder: Decoder) throws {
let c = try decoder.container(keyedBy: CodingKeys.self)
id = c.value(.id, ""); role = c.value(.role, ""); text = c.value(.text, "")
turnID = c.value(.turnID, ""); createdAt = c.date(.createdAt)
+ attachments = c.value(.attachments, [AskAttachment]()).filter { !$0.id.isEmpty }
+ }
+}
+
+/// One of a message's files (docs/api/base-native-v1.md, Attachment).
+/// Until the app draws files (slice 2), only its name shows. A kind the
+/// app doesn't know is a file.
+public struct AskAttachment: Decodable, Sendable, Equatable {
+ public var id: String
+ public var kind: String
+ public var name: String
+ public var mediaType: String
+ public var size: Int64
+ public var width: Int
+ public var height: Int
+ public var isImage: Bool { kind == "image" }
+ public init(id: String, kind: String = "file", name: String, mediaType: String = "", size: Int64 = 0, width: Int = 0, height: Int = 0) {
+ self.id = id; self.kind = kind; self.name = name; self.mediaType = mediaType; self.size = size; self.width = width; self.height = height
+ }
+ enum CodingKeys: String, CodingKey { case id, kind, name, mediaType = "media_type", size, width, height }
+ public init(from decoder: Decoder) throws {
+ let c = try decoder.container(keyedBy: CodingKeys.self)
+ id = c.value(.id, ""); name = c.value(.name, ""); mediaType = c.value(.mediaType, "")
+ let k: String = c.value(.kind, "file")
+ kind = k == "image" ? "image" : "file"
+ size = c.value(.size, Int64(0)); width = c.value(.width, 0); height = c.value(.height, 0)
}
}
diff --git a/native/apple/Sources/BaseKit/Ask/Thread.swift b/native/apple/Sources/BaseKit/Ask/Thread.swift
index 4d8d9d1..3e6f62d 100644
--- a/native/apple/Sources/BaseKit/Ask/Thread.swift
+++ b/native/apple/Sources/BaseKit/Ask/Thread.swift
@@ -87,14 +87,22 @@ struct AskThread: View {
switch entry {
case .message(let m):
Bubble(person: m.isPerson, maxWidth: bubbleWidth) {
- // The person's own words take the web's little Markdown
- // (PersonMarkdown); with none, they are exactly as written.
- if m.isPerson, case let nodes = PersonMarkdown.parse(m.text), !PersonMarkdown.isPlain(nodes) {
- BaseMarkdownView(person: nodes, id: m.id, transcript: transcript)
- } else if m.isPerson {
- Text(verbatim: m.text).font(BaseFont.body(15)).fixedSize(horizontal: false, vertical: true)
- } else {
- BaseMarkdownView(m.text, draft: false, id: m.id, transcript: transcript)
+ let parts = PersonBubble.parts(m)
+ VStack(alignment: .leading, spacing: 4) {
+ // The person's own words take the web's little Markdown
+ // (PersonMarkdown); with none, they are exactly as written.
+ if !parts.showsText {
+ EmptyView()
+ } else if m.isPerson, case let nodes = PersonMarkdown.parse(m.text), !PersonMarkdown.isPlain(nodes) {
+ BaseMarkdownView(person: nodes, id: m.id, transcript: transcript)
+ } else if m.isPerson {
+ Text(verbatim: m.text).font(BaseFont.body(15)).fixedSize(horizontal: false, vertical: true)
+ } else {
+ BaseMarkdownView(m.text, draft: false, id: m.id, transcript: transcript)
+ }
+ if let names = parts.names {
+ FilesLine(names: names)
+ }
}
}
case .draft(let d):
@@ -124,6 +132,34 @@ struct AskThread: View {
}
}
+/// What a person's bubble shows until the app draws files (slice 2, plan
+/// P9): their words, then one plain line of their files' names, so a
+/// message of files alone is never an empty bubble.
+enum PersonBubble {
+ struct Parts: Equatable { var showsText: Bool; var names: String? }
+ static func parts(_ m: AskMessage) -> Parts {
+ let names = m.attachments.map(\.name).filter { !$0.isEmpty }
+ let hasText = !m.text.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty
+ return Parts(showsText: hasText || names.isEmpty, names: names.isEmpty ? nil : names.joined(separator: ", "))
+ }
+}
+
+/// The names line: a paperclip and the files' names, in the secondary
+/// ink; VoiceOver reads "Attached: …".
+struct FilesLine: View {
+ let names: String
+ @Environment(\.colorScheme) private var scheme
+ var body: some View {
+ HStack(alignment: .firstTextBaseline, spacing: 5) {
+ Image(systemName: "paperclip").font(BaseFont.body(12, relativeTo: .footnote)).accessibilityHidden(true)
+ Text(verbatim: names).font(BaseFont.body(13, relativeTo: .footnote)).fixedSize(horizontal: false, vertical: true)
+ }
+ .foregroundStyle(Palette(scheme)[.haze])
+ .accessibilityElement(children: .ignore)
+ .accessibilityLabel(Text(BaseText.format("ask.files_line_a11y", ["names": names])))
+ }
+}
+
/// A line of the conversation: the person's on the right in teal, the
/// Assistant's on the left, each with one tucked corner (app.css `.msg`).
struct Bubble<Content: View>: View {
diff --git a/native/apple/Sources/BaseKit/Resources/Localizable.xcstrings b/native/apple/Sources/BaseKit/Resources/Localizable.xcstrings
index 1292fa6..3af3278 100644
--- a/native/apple/Sources/BaseKit/Resources/Localizable.xcstrings
+++ b/native/apple/Sources/BaseKit/Resources/Localizable.xcstrings
@@ -109,6 +109,18 @@
}
}
},
+ "ask.files_line_a11y": {
+ "comment": "Copy review 13 (pending). VoiceOver's reading of the line of a person's files' names under their words, until the app draws files (slice 2). {names} is the names, comma-separated.",
+ "extractionState": "manual",
+ "localizations": {
+ "en": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Attached: {names}"
+ }
+ }
+ }
+ },
"ask.jump": {
"comment": "Base on the web's approved copy. Floats at the conversation's foot when the person has scrolled up and something new arrives (chat.html).",
"extractionState": "manual",
diff --git a/native/apple/Tests/BaseKitTests/AskViewTests.swift b/native/apple/Tests/BaseKitTests/AskViewTests.swift
index b061b0b..17cd0a2 100644
--- a/native/apple/Tests/BaseKitTests/AskViewTests.swift
+++ b/native/apple/Tests/BaseKitTests/AskViewTests.swift
@@ -124,3 +124,36 @@ extension AskViewTests {
XCTAssertEqual(MarkdownPresentation.rows(ChatMarkdown.parse("3. Third\n4. Fourth", draft: false)).map(\.marker), ["3.", "4."])
}
}
+
+extension AskViewTests {
+ /// A message's files decode (an unknown kind is a file, one without an
+ /// id is dropped), and a message without them has none.
+ func testMessageFilesDecode() throws {
+ let raw = """
+ {"id":"m_1","role":"person","text":"","turn_id":"t_1","created_at":"2026-11-26T10:00:00Z",
+ "attachments":[{"id":"at_abcdefgh12","kind":"image","name":"shot.png","media_type":"image/png","size":2048,"width":640,"height":480},
+ {"id":"at_zzzzzzzz99","kind":"video","name":"notes.md","media_type":"text/markdown","size":12,"width":0,"height":0},
+ {"kind":"file","name":"nameless"}]}
+ """
+ let m = try JSONDecoder().decode(AskMessage.self, from: Data(raw.utf8))
+ XCTAssertEqual(m.attachments.map(\.name), ["shot.png", "notes.md"])
+ XCTAssertEqual(m.attachments.map(\.kind), ["image", "file"])
+ XCTAssertEqual(m.attachments[0].width, 640)
+ XCTAssertEqual(m.attachments[1].mediaType, "text/markdown")
+ let plain = try JSONDecoder().decode(AskMessage.self, from: Data(#"{"id":"m_2","role":"person","text":"hi"}"#.utf8))
+ XCTAssertEqual(plain.attachments, [])
+ }
+
+ /// A person's bubble with files and words shows the words, then the
+ /// names line; with files alone, only the names; with words alone, no
+ /// line (plan P9).
+ func testThePersonsBubbleNamesItsFiles() {
+ let files = [AskAttachment(id: "at_abcdefgh12", kind: "image", name: "shot.png"), AskAttachment(id: "at_abcdefgh13", name: "q3.csv")]
+ XCTAssertEqual(PersonBubble.parts(AskMessage(id: "m", role: "person", text: "Look", attachments: files)),
+ .init(showsText: true, names: "shot.png, q3.csv"))
+ XCTAssertEqual(PersonBubble.parts(AskMessage(id: "m", role: "person", text: " ", attachments: files)),
+ .init(showsText: false, names: "shot.png, q3.csv"))
+ XCTAssertEqual(PersonBubble.parts(AskMessage(id: "m", role: "person", text: "Look")), .init(showsText: true, names: nil))
+ XCTAssertEqual(BaseText.format("ask.files_line_a11y", ["names": "shot.png, q3.csv"]), "Attached: shot.png, q3.csv")
+ }
+}