// The kind hints over the capture sheet — "todo · event · note · person" in // typewriter, with Cotton's guess underlined in red pencil (picture 30). // // **The guess is a HINT, never a decision.** The router that files a capture // is `cotton-core`'s inbox routing, on the server, and this phone does not // carry it; what the sheet can do is read the words as they are typed and // point at the kind they look like, so a person writing "lunch with Priya // tomorrow 1pm" sees "event" take the pencil before they have sent anything. // Nothing is filed by this; `DockModel.send` files what was written and the // router decides. That is also why the rules below are few and plain: a // second classifier on the phone would be a second opinion the one-router // rule exists to refuse, and a hint that is wrong costs nothing. // // The rules, in order — the first that fires wins: // // 1. an imperative opening ("buy …", "call …", "remind me …") or a duty // ("need to", "must") → **todo**, whatever else the line says: "buy // milk tomorrow" is a todo with a day, not a day with a purchase; // 2. a clock ("5pm", "13:30") or a when-word ("tomorrow", "Friday", "next // week", a month before a number) → **event**; // 3. a leading "@", or one to three capitalised words and nothing else → // **person**; // 4. everything else → **note**. // // Blank text guesses nothing, and the row wears no pencil. import Foundation /// The four kinds the sheet hints at — the ones a capture most often becomes. public enum CaptureKindGuess: String, CaseIterable, Sendable, Equatable { case todo case event case note case person /// The row's order, left to right. public static let row: [CaptureKindGuess] = [.todo, .event, .note, .person] /// The kind the words look like, or `nil` for a blank line. public static func guess(_ text: String) -> CaptureKindGuess? { let line = text.trimmingCharacters(in: .whitespacesAndNewlines) guard !line.isEmpty else { return nil } let lowered = line.lowercased() let words = lowered.split(whereSeparator: { $0.isWhitespace }).map(String.init) if opensAsATodo(words, lowered) { return .todo } if namesAWhen(lowered) { return .event } if readsAsAName(line) { return .person } return .note } // ── 1. todo ────────────────────────────────────────────────────────── private static let imperatives: Set = [ "buy", "call", "ring", "text", "email", "send", "book", "fix", "pay", "renew", "finish", "write", "ask", "check", "get", "order", "cancel", "return", "schedule", "submit", "review", "read", "reply", "update", "install", "clean", "print", "post", "sign", "file", "collect", "drop", "bring", "take", "ship", "chase", "confirm", "todo", "to-do", ] private static let openingPhrases = ["remind me", "pick up", "follow up", "to do", "don't forget", "dont forget", "remember to"] private static let duties = ["need to", "needs to", "have to", "has to", "must ", "should "] private static func opensAsATodo(_ words: [String], _ lowered: String) -> Bool { guard let first = words.first else { return false } let bare = first.trimmingCharacters(in: .punctuationCharacters) if imperatives.contains(bare) { return true } if openingPhrases.contains(where: { lowered.hasPrefix($0) }) { return true } return duties.contains(where: { lowered.contains($0) }) } // ── 2. event ───────────────────────────────────────────────────────── private static let whenWords = [ "tomorrow", "tonight", "today", "this evening", "this morning", "this afternoon", "next week", "next month", "next year", "this week", "this weekend", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday", "mon ", "tue ", "wed ", "thu ", "fri ", "sat ", "sun ", ] private static let months = [ "january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december", "jan", "feb", "mar", "apr", "jun", "jul", "aug", "sep", "sept", "oct", "nov", "dec", ] /// "5pm", "5 pm", "13:30", "9.15am". private static let clock = try? NSRegularExpression( pattern: #"\b\d{1,2}([:.]\d{2})?\s?(am|pm)\b|\b\d{1,2}:\d{2}\b"# ) /// A month followed by a day figure — "sep 14", "march 3rd". private static let dated = try? NSRegularExpression( pattern: #"\b(\#(months.joined(separator: "|")))\.?\s+\d{1,2}\b"# ) private static func namesAWhen(_ lowered: String) -> Bool { if whenWords.contains(where: { lowered.contains($0) }) { return true } let range = NSRange(lowered.startIndex..., in: lowered) if clock?.firstMatch(in: lowered, range: range) != nil { return true } return dated?.firstMatch(in: lowered, range: range) != nil } // ── 3. person ──────────────────────────────────────────────────────── private static func readsAsAName(_ line: String) -> Bool { if line.hasPrefix("@") { return true } let words = line.split(whereSeparator: { $0.isWhitespace }) guard (1...3).contains(words.count) else { return false } return words.allSatisfy { word in guard let first = word.first, first.isUppercase else { return false } return word.allSatisfy { $0.isLetter || $0 == "'" || $0 == "-" || $0 == "." } } } }