// 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.importFoundation/// The four kinds the sheet hints at — the ones a capture most often becomes.publicenumCaptureKindGuess: String, CaseIterable, Sendable, Equatable {case todocase eventcase notecase person/// The row's order, left to right.publicstaticlet row: [CaptureKindGuess] = [.todo, .event, .note, .person]/// The kind the words look like, or `nil` for a blank line.publicstaticfunc guess(_ text: String) -> CaptureKindGuess? {let line = text.trimmingCharacters(in: .whitespacesAndNewlines)guard !line.isEmpty else { returnnil }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 ──────────────────────────────────────────────────────────privatestaticlet imperatives: Set<String> = ["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", ]privatestaticlet openingPhrases = ["remind me", "pick up", "follow up", "to do", "don't forget", "dont forget", "remember to"]privatestaticlet duties = ["need to", "needs to", "have to", "has to", "must ", "should "]privatestaticfunc opensAsATodo(_ words: [String], _ lowered: String) -> Bool {guardlet first = words.first else { returnfalse }let bare = first.trimmingCharacters(in: .punctuationCharacters)if imperatives.contains(bare) { returntrue }if openingPhrases.contains(where: { lowered.hasPrefix($0) }) { returntrue }return duties.contains(where: { lowered.contains($0) }) }// ── 2. event ─────────────────────────────────────────────────────────privatestaticlet 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 ", ]privatestaticlet 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".privatestaticlet 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".privatestaticlet dated = try? NSRegularExpression( pattern: #"\b(\#(months.joined(separator: "|")))\.?\s+\d{1,2}\b"# )privatestaticfunc namesAWhen(_ lowered: String) -> Bool {if whenWords.contains(where: { lowered.contains($0) }) { returntrue }let range = NSRange(lowered.startIndex..., in: lowered)if clock?.firstMatch(in: lowered, range: range) != nil { returntrue }return dated?.firstMatch(in: lowered, range: range) != nil }// ── 3. person ────────────────────────────────────────────────────────privatestaticfunc readsAsAName(_ line: String) -> Bool {if line.hasPrefix("@") { returntrue }let words = line.split(whereSeparator: { $0.isWhitespace })guard (1...3).contains(words.count) else { returnfalse }return words.allSatisfy { word inguardlet first = word.first, first.isUppercase else { returnfalse }return word.allSatisfy { $0.isLetter || $0 == "'" || $0 == "-" || $0 == "." } } }}