Cotton code
59 lines · 3.4 KB · SwiftRaw
// What the input box does with words it did not act on (Spec 7, Cotton note// 708fe4fa): they are KEPT AS A THOUGHT, and the thought remembers where it// was said — the tool's table, and the record when it was said on a record's// page. A thought said on a todo stands on that todo's page (the core finds// it there, `definitions.contributors`), and whoever files it later knows// what "this" meant.//// A store that keeps thoughts says so here; one that does not (the fixtures,// Settings' own tables) leaves the box doing only what its table takes.import CottonKitimport Foundationpublic protocol ThoughtKeepingRecords: Sendable {    /// Whether a thought can be kept from a list or a page of `table`.    nonisolated func keepsThoughts(table: String) -> Bool    /// Keeps `words` as a thought said in `table`, on `recordId` when the    /// words were said on that record's page, carrying what the box's "+"    /// attached; a nil `table` is a thought said where no table stands (the    /// board). The add's own change: its receipt, and the Undo that takes    /// the thought back.    func keepThought(        _ words: String, table: String?, recordId: String?, attachments: [CaptureAttachment]    ) async throws -> ChangeRecord    /// Copies a file into a store as its own photo, video or document record.    /// `forThought`: the picture rides a thought kept here, so it is kept    /// where the thought is (Personal); otherwise it is kept in THIS store's    /// database — a Photos list's file, the record whose strip it is added to.    func captureMedia(        file: URL, mime: String, kind: CaptureMediaKind, filename: String?, forThought: Bool    ) async throws -> MediaCaptured}/// The receipt's sentence for a thought kept from the box, by where it was said.enum ThoughtKept {    static func on(_ definition: TableDefinition) -> String { ShellLines.line("input", "kept.on", ["kind": "\(definition.name.lowercased())"]) }    static func among(_ definition: TableDefinition) -> String { ShellLines.line("input", "kept.among", ["plural": "\(definition.plural)"]) }    /// What the box's "+" attached, by kind and count, added to `place` (a    /// record's title, or a tool's name): "Added a photo to Pick up the slides".    static func added(_ kinds: [CaptureMediaKind], to place: String) -> String {        ShellLines.line("input", "kept.added", ["what": "\(what(kinds))", "place": "\(place)"])    }    private static func what(_ kinds: [CaptureMediaKind]) -> String {        let one = Set(kinds).count == 1 ? kinds.first : nil        let (single, plural): (String, String) = switch one {        case .photo?: (ShellLines.line("input", "kept.photo.one"), ShellLines.line("input", "kept.photo.many"))        case .video?: (ShellLines.line("input", "kept.video.one"), ShellLines.line("input", "kept.video.many"))        case .document?: (ShellLines.line("input", "kept.file.one"), ShellLines.line("input", "kept.file.many"))        case nil: (ShellLines.line("input", "kept.attachment.one"), ShellLines.line("input", "kept.attachment.many"))        }        return kinds.count == 1 ? single : ShellLines.line("input", "kept.count", ["n": "\(kinds.count)", "plural": plural])    }    /// A spoken line kept as a thought, for the agent to file.    static var saved: String { ShellLines.line("input", "kept.saved") }    /// The words could not be kept here: nothing was done with them.    static var nowhere: String { ShellLines.line("input", "kept.nowhere") }}