Rebuilding in Rust
The TypeScript Friday works. Nineteen chapters of incremental change, and the system handles multiple users, background tasks, multimedia attachments, workflow commands, worktrees, and a HUD. Each chapter solved a real problem. Each solution left a small residue of complexity.
After enough chapters, the question stops being "how do we add this?" and starts being "if we started over, what would we keep?" Not because the TypeScript version is broken – it isn't – but because a clean-room rebuild is one of the best ways to find out which decisions were load-bearing and which were just accidents of order.
The other reason: Rust. I've wanted a reason to build something real in it for a while. A personal assistant is the right kind of project – complex enough to stress-test the language, small enough that a solo builder can hold the whole thing in their head.
The Rust version lives at github.com/assertchris/friday-rs. It isn't a port. It doesn't try to replicate the TypeScript architecture decision by decision. It starts with the same goal – a Claude-powered personal assistant that runs as a background service, answers via Telegram, and can work on my behalf – and asks what that looks like when you design it from scratch.
One Process, One Concern
The TypeScript Friday is a single Node.js process. It polls Telegram, runs Claude sessions, manages background tasks, serves an HTTP API, watches worktrees, and handles multimedia – all in one runtime. Isolating concerns means module boundaries and shared-by-convention patterns. There's nothing stopping one part of the code from reaching into another.
The Rust version takes a different approach: one binary per concern. Four daemons, each compiled separately, each doing exactly one thing:
- The coordinator owns the lifecycle. It spawns the other three, restarts them if they crash, and routes messages between them.
- The agent daemon manages a single Claude session. It accepts one connection at a time over a Unix socket, forwards turns to the Claude CLI subprocess, and streams the response events back.
- The telegram daemon polls the Telegram Bot API, filters incoming messages by allowed user IDs, and sends them up to the coordinator as structured commands.
- The tools daemon runs an MCP server – an HTTP API that Claude can call to interact with the Friday service layer (notes, calendar, settings, and so on).
They talk to each other over Unix sockets using newline-delimited JSON. No shared memory, no function calls across process boundaries. Each daemon can be restarted independently without affecting the others.
The coordinator supervises with simple restart loops:
pub fn supervise(name: &'static str, bin_path: impl Into<PathBuf>) {
let bin_path = bin_path.into();
tokio::spawn(async move {
loop {
match tokio::process::Command::new(&bin_path).status().await {
Err(_) => tokio::time::sleep(Duration::from_secs(5)).await,
Ok(_) => tokio::time::sleep(Duration::from_secs(1)).await,
}
}
});
}
This is from
crates/daemons/coordinator/src/children.rs
Five seconds on a spawn error (binary likely missing). One second on a clean exit (restart quickly). No exponential backoff yet – this is enough for a prototype.
Config That Can't Lie
The TypeScript Friday accumulates config in a few different ways – environment variables checked directly in code, a database for settings, a TOML file, and a handful of inline defaults. Finding out where a value comes from requires reading three or four files.
The Rust version has exactly two config types and three legal forms, documented in AGENTS.md as a hard rule:
| Category | TOML form | Resolves to |
|---|---|---|
| Hard-coded | port = 7654 | always 7654 |
| Env-overridable with default | port = { env = "TOOL_PORT", default = 7654 } | env var wins, then 7654 |
| Secret – required from env | token = { env = "MY_TOKEN" } | Option<String>, None if unset |
ConfigValue<T> handles the first two. SecretValue handles the third. That's it. No hidden std::env::var() calls inside config methods. No fourth way to sneak in a value.
The ConfigValue<T> enum is straightforward:
#[derive(Debug, Deserialize, Clone)]
#[serde(untagged)]
pub enum ConfigValue<T: Clone> {
Plain(T),
Env { env: String, default: T },
}
impl<T: Clone + std::str::FromStr> ConfigValue<T> {
pub fn resolve(&self) -> T {
match self {
ConfigValue::Plain(v) => v.clone(),
ConfigValue::Env { env, default } => std::env::var(env)
.ok()
.and_then(|s| s.parse().ok())
.unwrap_or_else(|| default.clone()),
}
}
}
This is from
crates/config/src/values.rs
SecretValue is similar but returns Option<String> – if the env var is unset or empty, you get None. Fields marked #[serde(default)] on SecretValue produce Plain(""), which also resolves to None. That's the "absent optional secret" state, not a bug.
There's one intentional exception to the no-hidden-env-vars rule: CONFIG_PATH. The path to the config file can't live inside the config file. It's documented as a bootstrap exception:
// CONFIG_PATH is a bootstrap value: it names the file we are about to
// read, so it cannot itself live inside that file.
let path = std::env::var("CONFIG_PATH")
.ok()
.or_else(|| Path::new("config.toml").exists().then_some("config.toml".into()));
This is from
crates/config/src/config.rs
The rule has exactly one named exception. That's a kind of discipline the TypeScript version never managed.
Running Claude as a Subprocess
The TypeScript Friday uses the Anthropic SDK directly – it makes API calls, manages streaming, handles tool use in the process. The Rust version doesn't use the API at all. It shells out to the Claude CLI binary.
This is a deliberate trade-off. The Claude CLI handles streaming, tool use, MCP connections, and session state natively. Building all of that from scratch in Rust would take weeks and produce something worse. By treating the CLI as a black box that accepts JSON on stdin and emits events on stdout, we can iterate on the daemon architecture without touching the AI layer.
The agent daemon's main loop looks like this:
loop {
let (socket, _) = listener.accept().await?;
let (read_half, mut write_half) = socket.into_split();
let mut socket_lines = BufReader::new(read_half).lines();
while let Some(raw_line) = socket_lines.next_line().await? {
let line = raw_line.trim();
if line.is_empty() { continue; }
claude_stdin.write_all(line.as_bytes()).await?;
claude_stdin.write_all(b"\n").await?;
claude_stdin.flush().await?;
while let Some(raw_event) = claude_lines.next_line().await? {
let event = raw_event.trim();
write_half.write_all(event.as_bytes()).await?;
write_half.write_all(b"\n").await?;
if serde_json::from_str::<EventType>(event)
.ok().map(|e| e.kind == "result").unwrap_or(false) {
break;
}
}
}
}
This is from
crates/daemons/agent/src/main.rs
A few things worth noting about this design. The outer loop calls accept() once per client – no tokio::spawn. One client at a time is intentional: each session socket belongs to exactly one coordinator connection, and concurrent clients would interleave their turns into Claude's stdin, producing garbled output. Serial is correct here.
The inner loop reads events from Claude's stdout until it sees a {"type":"result"} event, then breaks and waits for the next turn from the socket. The Claude CLI's stream-json format makes this clean – every turn ends with a result event, so we know exactly when to stop forwarding and go back to listening.
The --dangerously-skip-permissions flag is hard-coded. The daemon only runs tools that the coordinator has explicitly authorised via the MCP config. Without this flag, Claude would prompt for tool approval on every call – and there's nobody there to answer.
A Test Suite That Talks to Claude
There's no Rust toolchain on the host machine. Every build and every test run happens inside a Podman container. The Containerfile compiles all four daemon binaries, archives the test suite with cargo-nextest, and layers the result into a runtime image. The build command is podman build -t friday . and the test command is podman run.
This sounds inconvenient, and it is, a little. But it also means the test environment is completely reproducible. Anyone with Podman and valid Claude credentials can run the full suite.
The test structure follows the same domain-per-binary pattern as the source code. Each crate with interesting behaviour has at least one test binary in tests/:
tests/
claude_daemon/
integration.rs ← Claude CLI reachability and auth
session_daemon.rs ← multi-turn conversation over a Unix socket
The integration tests aren't mocked. claude_responds_with_text spawns the actual Claude CLI, sends "Reply with the word pong and nothing else", and asserts the response contains "pong". If the container doesn't have valid Claude credentials mounted in, the test fails – which is exactly what you want from a smoke test.
The rest of the suite – 210 tests across 26 binaries – mixes real integration tests with wiremock-backed HTTP tests. The Telegram poller tests stand up a local mock server, mount it as the bot API base URL, and assert that the poller sends the right requests, advances the offset correctly, and emits the right events. The coordinator socket tests verify fan-out behaviour, stale socket cleanup, and connection lifecycle.
The code review pass tightened a lot of this. Some tests were asserting unwrap() succeeded without checking the actual value. Others were spinning up real MockServer instances for tests that never made any network calls. Each cleanup made the failure messages more useful and the intent clearer.
After the review: 210/210 passing.
Conclusion
The Rust version of Friday isn't a replacement yet. The TypeScript version is still running, still handling real requests, still getting new features. But the prototype is further along than I expected it to be at this stage.
Four daemon binaries exist and compile. The config system enforces its own rules at the type level – you can't accidentally create a fourth config form without editing the enum. The agent daemon can hold a multi-turn Claude conversation over a Unix socket. The telegram daemon polls for messages and filters by user. The coordinator supervises the others and restarts them on failure. The tools daemon exposes the Friday service layer as an MCP server that Claude can call.
The code review pass was genuinely useful. Removing EnvRequired from ConfigValue<T> simplified the type and caught a real violation of the project's own rules. Tightening test assertions turned vague green tests into tests that actually describe the system's behaviour. Adding RAII env guards and error-path tests to the integration suite makes the config crate provably correct under adversarial inputs.
What the Rust version has that the TypeScript version doesn't: process isolation between concerns, a config system with exactly three legal forms, a test suite that makes real API calls as part of CI, and a foundation that's cheap to reason about because every piece has exactly one job.
What it doesn't have yet: a working end-to-end conversation from Telegram message to Claude response to Telegram reply. That's the next milestone – wiring the four daemons together and watching the whole thing run.