# Agent Integration Reference
`kcode-rust-libs` is a synchronous Rust library for creating, opening, editing, validating, and publishing small agent-authored Rust libraries. An integrating server supplies its own API transport, authentication, discovery, sessions, and concurrency control.
```rust
use kcode_rust_libs::{KcodeRustLibs, RustLibFile, RustLibPath};
let rust_libs = KcodeRustLibs::new("/srv/kcode-rust-libs")?;
```
| `KcodeRustLibs::new(root)` | Creates or opens the persistent Rust libraries root. |
| `rust_libs.create_rust_lib(name)` | Creates a Rust 2024 library and returns it fully loaded. |
| `rust_libs.open_rust_lib(name)` | Opens an existing Rust library and returns every file. |
| `rust_lib.name()` | Returns the Rust library name. |
| `rust_lib.files()` | Returns sorted `&[RustLibFile]`; each has public `path` and `contents`. |
| `rust_lib.docs()` | Returns `&RustLibDocs` with canonical `version` and `documentation` text. |
| `rust_lib.write(&files)` | Creates or fully overwrites supplied files; omitted files remain. |
| `rust_lib.check()` | Runs formatting, build, Clippy, tests, and doc tests in Podman. |
| `rust_lib.publish()` | Checks, then publishes the root package to crates.io. |
Construct a write with `RustLibFile::new(RustLibPath::new("src/lib.rs")?, complete_text)`. Paths use `/`, are relative, and reject traversal. All paths and files are UTF-8. There is no deletion, patch, reload, close, listing, or arbitrary-command API.
Every managed Rust library requires root-level `Documentation.md` and `Version.txt`. `Version.txt` is a canonical stable `major.minor.patch`, with at most one trailing LF. `write()` rejects a batch that would violate this. Before publication, that version must equal the literal `[package].version` in the root `Cargo.toml`; workspace-inherited versions are rejected.
This crate is itself laid out as a managed Rust library. Place its directory at `<rust-libs-root>/kcode-rust-libs`, open it with `open_rust_lib("kcode-rust-libs")`, and an agent can read or replace its source, tests, specification, and documentation through the same API. Keep generated build output and non-UTF-8 editor artifacts outside the managed directory; `check()` already uses disposable external work and target directories.
`check()` returns code-quality failures as `Ok(CheckResult)` with `passed() == false`; infrastructure failures are `Err`. `publish()` requires operator-provisioned `<root>/cargo_registry_token.txt`, which is never exposed through the API. Agents do not run Podman or supply a token or image name.
The integrating server must allow only one active handle per Rust library and drop it when the session ends. Run `check()` and `publish()` on a blocking worker in asynchronous servers.