opt(goal): minutes feeds do no word work; word rail goes count-only [cold-turkey-full-tokenization] #188

Merged
AlexKucera merged 4 commits from opt/cold-turkey-full-tokenization into main 2026-11-13 16:51:06 +01:00
2 changed files with 37 additions and 11 deletions
Showing only changes of commit 9f4d9ef9ea - Show all commits

No files matched your search

+20 -2
View File
@@ -79,10 +79,28 @@ nonisolated struct DraftStats: Equatable {
/// Word count over the same token semantics every text metric /// Word count over the same token semantics every text metric
/// rides (#161: Cold Turkey net-words counts with this — one /// rides (#161: Cold Turkey net-words counts with this — one
/// tokenizer, no drift). "writer's" is two words here, headings /// word rail, no drift). "writer's" is two words here, headings
/// are body text, frontmatter is not (the editor never shows it). /// are body text, frontmatter is not (the editor never shows it).
/// Count-only (opt pass 2026-11-09): one Character pass counting
/// maximal isLetter/isNumber runs — the lowercased [String] the
/// per-keystroke editor feed once paid for is never built. Equal
/// to the tokenizer's split by construction (omitting empty
/// subsequences leaves exactly the maximal runs); pinned against
/// the split expression over a mixed-script corpus.
static func words(in text: String) -> Int { static func words(in text: String) -> Int {
tokens(in: text).count var count = 0
var inRun = false
for character in text {
if character.isLetter || character.isNumber {
if !inRun {
count += 1
inRun = true
}
} else {
inRun = false
}
}
return count
} }
/// Lowercased runs of Characters where isLetter || isNumber — the /// Lowercased runs of Characters where isLetter || isNumber — the
+17 -9
View File
@@ -24,9 +24,9 @@ nonisolated enum WritingGoal: Equatable {
/// (typing, deleting, pasting, undo all land as whole-document /// (typing, deleting, pasting, undo all land as whole-document
/// text), and `now` is injected, so the countdown can never be /// text), and `now` is injected, so the countdown can never be
/// paused or deferred from inside the engine. Word counting rides /// paused or deferred from inside the engine. Word counting rides
/// `DraftStats.words` — the one tokenizer all text metrics share, so /// `DraftStats.words` — the one word-count rail all text metrics
/// net-words can never drift from first-draft stats ("writer's" is /// share, so net-words can never drift from first-draft stats
/// two words there, headings are body text; frontmatter is not body /// ("writer's" is two words there, headings are body text; frontmatter is not body
/// text — the editor never shows it, so it never counts). /// text — the editor never shows it, so it never counts).
nonisolated struct WritingGoalRun: Equatable { nonisolated struct WritingGoalRun: Equatable {
let goal: WritingGoal let goal: WritingGoal
@@ -35,7 +35,9 @@ nonisolated struct WritingGoalRun: Equatable {
let armedAt: Date let armedAt: Date
/// Whole-document word count at arm. /// Whole-document word count at arm.
let baselineWords: Int let baselineWords: Int
/// Whole-document word count as of the last `update(text:)`. /// Whole-document word count as of the last `update(text:)` —
/// words goals only; a minutes run freezes at the arm-time
/// count (the verdict never reads it).
private(set) var currentWords: Int private(set) var currentWords: Int
init(goal: WritingGoal, armedAt: Date, body: String) { init(goal: WritingGoal, armedAt: Date, body: String) {
@@ -46,12 +48,18 @@ nonisolated struct WritingGoalRun: Equatable {
currentWords = words currentWords = words
} }
/// Record the live editor text. The caller passes the whole /// Record the live editor text — words goals only. The caller
/// document every time; the net falls out of the delta. /// passes the whole document every time; the net falls out of
/// `countWords` is the injectable word rail — the pins count /// the delta. A minutes run never re-counts: its verdict and
/// rail trips through this seam (a global counter would race /// progress ride the clock alone, so the per-keystroke feed
/// the hosted suite's parallel DraftStats calls). /// does no word work at all (opt pass 2026-11-09 — the feed
/// once tokenized the whole document per keystroke for a count
/// nothing read). `countWords` is the injectable word rail —
/// the pins count rail trips through this seam (a global
/// counter would race the hosted suite's parallel DraftStats
/// calls).
mutating func update(text: String, countWords: (String) -> Int = DraftStats.words(in:)) { mutating func update(text: String, countWords: (String) -> Int = DraftStats.words(in:)) {
guard case .words = goal else { return }
currentWords = countWords(text) currentWords = countWords(text)
} }