Skip to content

cratify: extract 5 ccft crates, add lib facade - #10

Open
adiled wants to merge 2 commits into
mainfrom
cratify
Open

cratify: extract 5 ccft crates, add lib facade#10
adiled wants to merge 2 commits into
mainfrom
cratify

Conversation

@adiled

@adiled adiled commented Sep 5, 2026

Copy link
Copy Markdown
Owner

What

Extract the reusable, generic logic out of the ccft binary into five cratified sub-crates, and turn the root ccft into both a binary and a library facade that re-exports them.

Crates

  • ccft-ledger — append/tail/range-read a growing JSONL ledger (Record, TailReader, parse_range, percentile, coverage)
  • ccft-session — session-id extraction from hyper headers + JSON metadata bodies
  • ccft-lex — pure text fingerprinting: lexical stats, content bigrams, novelty, system-block stripping
  • ccft-brainrot — agentic turn classification, EM gap mixture, baseline fingerprint, driver/bot scoring
  • ccft-sse — generic hyper Body tap for OpenAI/Anthropic SSE + non-stream JSON token/usage accounting

Library facade

src/lib.rs re-exports the five crates so downstream Rust code can
use ccft::{ledger, lex, sse}; without depending on each crate individually:

let r = ledger::parse_range("24h")?;
let (ttr, _, _) = lex::lexical_stats(text);
assert_eq!(sse::PROVIDER_OPENAI, "openai");

The binary's own modules (handler/config/lifecycle/…) stay ccft-specific and are not part of the library surface.

Verification

  • cargo build --workspace green
  • 24 tests pass (1 lib facade + 8 bin + 5 brainrot + 2 ledger + 5 lex + 3 sse)
  • All 5 crates clippy-clean (bin retains only ~30 pre-existing warnings)
  • Bin depends on exactly the 5 crates + ops; re-export layer is thin (path glue/adapters), no duplicated implementation logic

Extract the core logic out of the ccft binary into standalone workspace
crates, keeping the binary as a thin re-export/glue layer:

- ccft-ledger: Record/TailReader/parse_range/percentile/coverage,
  top-N/window/state-event readers (range.rs + tail.rs)
- ccft-session: hyper HeaderMap+body -> session-id extraction
- ccft-lex: lexical_stats, content_bigrams, novelty_fraction,
  strip_system_blocks, clean_user_text
- ccft-brainrot: Aggregate/ingest_into, classify_turns, fit_gap_mixture,
  Baseline::from_records, driver/bot scores, score_breakdown, diagnosis,
  compute_signal/VLPV
- ccft-sse: generic hyper Body tap (SseTap/TapMeta/TapReport) that parses
  SSE/JSON into a provider-agnostic report; the bin wires it to the
  write-side ledger via a callback

Binary re-export layer:
- src/ledger_read.rs: ccft-specific path glue + thin pub use
- src/session.rs, src/brainrot/aggregate.rs: thin pub use re-exports
- src/sse_tap.rs: FlowMeta->TapMeta adapter + ledger write callback

Fixes along the way: percentile re-export, UNIX_EPOCH import, iter_records
now takes Vec<PathBuf> by value (self-contained 'static iterator), Default
derive on TailReader, corrected ccft-lex test, clippy-clean across all 5
crates. 23 tests pass across workspace; build green.
Root ccft is now both a binary and a library. src/lib.rs re-exports
ccft_ledger/ccft_session/ccft_lex/ccft_brainrot/ccft_sse as
ccft::{ledger, session, lex, brainrot, sse} so downstream Rust code can
use ccft::… without depending on each crate. Adds a facade smoke test
(1 new test; workspace 24 pass).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant