Something went wrong. Try again.
A small AI buddy that lives in the bottom right-hand corner of your Mac that wakes when you press a keybind.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566import Foundation
/// A task the user showed Seer by doing it once: plain-language steps the agent follows next time.struct Lesson: Codable, Identifiable, Sendable, Equatable { var id = UUID() var name: String var steps: [String] var created = Date()}
/// The taught tasks, kept in Application Support so they survive relaunches.@MainActorfinal class LessonStore: ObservableObject { static let shared = LessonStore()
@Published private(set) var lessons: [Lesson]
private init() { lessons = Self.load() }
/// Teaching a task under an existing name replaces it. func add(_ lesson: Lesson) { lessons.removeAll { $0.name.lowercased() == lesson.name.lowercased() } lessons.append(lesson) Self.save(lessons) }
func remove(_ id: UUID) { lessons.removeAll { $0.id == id } Self.save(lessons) }
nonisolated static func names() -> [String] { load().map(\.name) }
/// Up to two taught tasks whose name the goal mentions, whole or mostly. nonisolated static func relevant(to goal: String) -> [Lesson] { let stop: Set<String> = ["the", "and", "for", "with", "to", "a", "an", "my", "on", "in", "of", "please"] func words(_ text: String) -> Set<String> { Set(text.lowercased().split { !$0.isLetter && !$0.isNumber }.map(String.init).filter { !stop.contains($0) }) } let lowerGoal = goal.lowercased() let goalWords = words(goal) return Array(load().filter { lesson in if lowerGoal.contains(lesson.name.lowercased()) { return true } let nameWords = words(lesson.name) guard !nameWords.isEmpty else { return false } return Double(nameWords.intersection(goalWords).count) / Double(nameWords.count) >= 0.67 }.prefix(2)) }
private nonisolated static var fileURL: URL { let base = FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask)[0] return base.appendingPathComponent("Seer", isDirectory: true).appendingPathComponent("lessons.json") }
private nonisolated static func load() -> [Lesson] { guard let data = try? Data(contentsOf: fileURL) else { return [] } return (try? JSONDecoder().decode([Lesson].self, from: data)) ?? [] }
private nonisolated static func save(_ lessons: [Lesson]) { let url = fileURL try? FileManager.default.createDirectory(at: url.deletingLastPathComponent(), withIntermediateDirectories: true) if let data = try? JSONEncoder().encode(lessons) { try? data.write(to: url, options: .atomic) } }}