Repository navigation
Description
Summary
RTK's filtering engine and command classifier are valuable beyond CLI proxy use.
Several modules (filter.rs, discover/registry.rs, utils.rs) already have clean public APIs that return values; they just can't be consumed externally because there's no [lib] target and all modules are private.
i.e. they use mod not pub mod.
Proposal:
- Add a
[lib]target toCargo.toml - Create
src/lib.rswith curated public re-exports.
This will allow downstream crates to depend on rtk as a library (git dependency).
Motivation
Consuming rtk as a library enables:
- In-process output filtering: no subprocess overhead, call
filter.filter(content, lang)directly - Embedding in other tools: LLM agent frameworks, coding tools, etc. without complexity of downloading
rtk.
Current State (Why It Doesn't Work Today)
| Check | Result |
|---|---|
[lib] section in Cargo.toml |
Missing |
src/lib.rs |
Does not exist |
| Module visibility | All mod (not pub mod) |
| crates.io package | Name collision ("Rust Type Kit") |
Proposed Change
Modules ready for public exposure (no refactoring needed)
These already return values and avoid println! / std::process::exit():
filter:FilterStrategytrait,get_filter(level),Language::from_extension(),smart_truncate()discover::registry:classify_command(),rewrite_command()discover::rules: static pattern/rule data (PATTERNS,RULES,IGNORED_PREFIXES)utils:strip_ansi(),truncate(),format_tokens()
Changes needed
- Add
[lib]section toCargo.toml(name = "rtk",path = "src/lib.rs") - Create
src/lib.rswithpub modfor the modules listed above - Change
mod→pub modinsrc/main.rsfor those modules - Ensure
src/discover/mod.rssubmodules arepubwhere needed
The [lib] target coexists with the existing [bin]. cargo build produces both, no breaking change.
Out of scope for this issue
The 57+ *_cmd.rs modules (git.rs, cargo_cmd.rs, etc.) use println! and std::process::exit(). Refactoring those to return String is a separate effort that can be tracked in a follow-up issue.
Alternatives Considered
- Fork with lib support: works but fragments the ecosystem; you don't want forks if you can avoid it.
- Separate
rtk-libcrate: splits the codebase; inlining the[lib]target in the existing repo is simpler
Also a fork would require publishing under a different name to crates.io , which is undesireable.
Activity
pszymkowiak commentedon Mar 20, 2026
🔍 Automated Triage
featuremediumSummary
Well-scoped feature request to add a [lib] target so RTK's filter/discovery modules can be consumed as a Rust library; author has identified exact files and mechanical changes needed.
📁 Relevant files
Cargo.tomlsrc/lib.rssrc/main.rssrc/filter.rssrc/utils.rssrc/discover/mod.rssrc/discover/registry.rssrc/discover/rules.rsTriaged automatically by wshm · This is an automated analysis, not a human review.
reneleonhardt commentedon May 1, 2026
Great idea 👍
This would allow Rust apps like https://github.com/farion1231/cc-switch to integrate it into their own proxies easier!
photino commentedon Jun 24, 2026
The relevant PR: #1693
dredozubov commentedon Jun 24, 2026
Adding a concrete use case plus a finding that may make this smaller and lower-risk than the full lib/bin refactor in #1693.
Use case: embedding rtk's output filtering directly in an in-process code/agent harness — string in → compressed string out — without spawning the binary per call, and without maintaining a fork.
Finding (verified against #1693): most of what an in-process consumer needs is already shaped as a clean public API; the only blocker is the missing
[lib]target. Two surfaces are enough:core::filter—FilterStrategy,get_filter(level),Language::from_extension,smart_truncate— all alreadypub(generic language-aware code filtering).cmds::system::pipe_cmd::resolve_filter(name) -> Option<fn(&str) -> String>— alreadypub, and it returns function pointers to the per-command filters (the same ~17rtk pipeexposes:cargo-test,pytest,tsc,vitest,git-log,git-diff,ruff-check,mypy,prettier, …).I checked out #1693 and built an external consumer crate against its
libtarget. All three paths work today:The per-command
filter_*functions staypub(crate)— a direct call fails withE0603— which is fine:resolve_filteris the intended stable entry point and keeps the internal functions free to change.Suggestion: this doesn't require the full
main.rs→lib.rs+dispatch.rsrestructure from #1693 (large diff, now labeledinvalid/postponed). A minimal[lib]target +src/lib.rsre-exporting justcore::filterandpipe_cmd::resolve_filter(plus the curated list already in this issue) would unblock embedding with a small, reviewable surface and zero behavioral change to the binary —[lib]and[[bin]]coexist, socargo buildstill produces the samertk.Happy to open a PR scoped to exactly that minimal surface if maintainers are open to it. (Related: #2037 wants the same foundation for Python bindings.)
dredozubov commentedon Jul 1, 2026
For people who need a library distribution before upstream provides one, I have published a public fork here:
https://github.com/dredozubov/rtk
The fork keeps the original
rtk-ai/rtkwork and upstream contributors clearly credited inFORK.md, preserves the Apache-2.0 license text, and identifies itself as an unofficial fork. It adds a minimal library target to the existing crate/package with the surface we needed:rtk::core::filterrtk::pipe_cmd::resolve_filterUntil the upstream maintainers decide to provide a clear official library build target, consumers who need this can use the fork as a git dependency, for example:
This is intended as an interim community fork for library consumers, not an official
rtk-ai/rtkdistribution.