spb/poche Public
Agent personnel 100 % on-device — SwiftUI + Apple Foundation Models + EventKit + SwiftData. Aucune API, aucun serveur.
Swift 100%
1//2// TokenEstimator.swift3// Poche4//5// Author: Simon-Pierre Boucher6// Contact: contact@spboucher.ai7//89import Foundation1011/// Conservative token estimation.12///13/// Constraint: the iOS 26 SDK exposes no public token-count API for the14/// on-device model, so the preflight described in CLAUDE.md §2 cannot call15/// `tokenCount(for:)` yet. This estimator deliberately over-counts16/// (~3 characters per token, French text averages closer to 3.5–4) so the17/// budget errs toward condensing early rather than hitting18/// `exceededContextWindowSize`. Replace with the system API the day Apple19/// ships one.20enum TokenEstimator {21 static func tokens(in text: String) -> Int {22 max(1, text.count / 3)23 }2425 /// Flat per-tool overhead: name + description + generated argument schema26 /// all live in the context window for the whole session.27 static let perToolOverhead = 12028}29