// // TokenEstimator.swift // Poche // // Author: Simon-Pierre Boucher // Contact: contact@spboucher.ai // import Foundation /// Conservative token estimation. /// /// Constraint: the iOS 26 SDK exposes no public token-count API for the /// on-device model, so the preflight described in CLAUDE.md §2 cannot call /// `tokenCount(for:)` yet. This estimator deliberately over-counts /// (~3 characters per token, French text averages closer to 3.5–4) so the /// budget errs toward condensing early rather than hitting /// `exceededContextWindowSize`. Replace with the system API the day Apple /// ships one. enum TokenEstimator { static func tokens(in text: String) -> Int { max(1, text.count / 3) } /// Flat per-tool overhead: name + description + generated argument schema /// all live in the context window for the whole session. static let perToolOverhead = 120 }