feat(stats): first-draft stats capture (S5.1) (#31)
CI / ci (push) Canceled after 0s
CI / ci (push) Canceled after 0s
Measure the writer, not the text. Running Pass 1 or Pass 2 on an unaided draft (origin: writer, First Draft Pass State, post type - lenient defaults, so bare legacy posts qualify) computes four style metrics natively in Swift at the invocation - before the engine sees anything - and stamps stats_captured plus four stats_* values into the piece's frontmatter in place, so the S5.2 trend view is a plain scan of Post.frontmatter. Capture re-fires while still First Draft (latest draft wins); a cancelled pass keeps its capture; ai-origin and advanced pieces never qualify. The capture exposed an erasure class: the existingStamp-to-stamped block rewrite rebuilt frontmatter from three parsed fields, silently dropping everything else. advancePassState and overwrite now update their owned keys in place (stampingFrontmatter, widened internal per its own third-caller trigger; bare posts still normalize through stamped), so captured stats and foreign YAML survive pass completion AND mid-pass editor saves. Both fixes are flip-verified by pins. DraftStats carries the four metrics (burstiness, type-token ratio, sentence-length variation, trigram repetition) as a pure Foundation model - full precision out, %.3f at store time. 16 new pins across DraftStatsTests, PostStoreTests, and PassRunTests; full unit bundle 396/396 (sequential gate; parallel runs flake under external CPU load per the #30 learning). Finish-audit fanout (ponytail/security/ review) ran on the diff: its MEDIUM (overwrite erasure) and the converged deletions landed here. Closes #31
This commit is contained in:
1 parent
ae234350ef
commit
42bcfce9ba
13 files changed
+611
-20
No files matched your search
@@ -184,11 +184,14 @@ nonisolated enum LearningDecay {
|
||||
/// insert absent ones before the closing `---`, preserve every other
|
||||
/// line verbatim (leading hand-edit lines above the opening `---`
|
||||
/// included), keep the block's trailing newline. No frontmatter
|
||||
/// block at all → prepend a fresh one.
|
||||
/// block at all → prepend a fresh one. Internal since #31: the
|
||||
/// first-draft stats capture is the third caller.
|
||||
// ponytail: PostStore.mergedFrontmatter's line-walk duplicated and
|
||||
// generalized — extracting the shared walk would grow PostStore at its
|
||||
// type-body ceiling; do it when a third caller appears.
|
||||
private static func stampingFrontmatter(of text: String, with pairs: [(key: String, value: String)]) -> String {
|
||||
// generalized — extraction would grow PostStore at its type-body
|
||||
// ceiling; #31's capture is the third caller and it STILL isn't
|
||||
// extracted (LearningDecay + PostStore stay the two owners; the
|
||||
// type-body ceilings named above are unchanged).
|
||||
static func stampingFrontmatter(of text: String, with pairs: [(key: String, value: String)]) -> String {
|
||||
let (block, body) = PostStore.splitFrontmatter(text)
|
||||
guard !block.isEmpty else {
|
||||
return "---\n" + pairs.map { "\($0.key): \($0.value)" }.joined(separator: "\n") + "\n---\n" + body
|
||||
|
||||
Reference in new issue
Block a user