1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
// SPDX-License-Identifier: MIT OR Apache-2.0
//! Exfiltrate is a remote debugging framework for Rust applications.
//!
//! It allows you to inspect and control a running application (even in WASM/browser environments)
//! from a CLI tool. This is particularly useful when trying to debug programs with agents such as
//! Claude Code, Codex, Gemini, etc.
//!
//! 
//!
//! # Overview
//!
//! Exfiltrate provides a simple, self-contained, and embeddable server implementation,
//! primarily motivated by the need to embed in debuggable programs. It is designed to be
//! easy to use, easy to extend with custom commands, and easy to integrate with existing Rust codebases,
//!
//! Unlike traditional debuggers (gdb, lldb) which require ptrace/OS support, exfiltrate
//! works by embedding a small server thread into your application. This allows it to work
//! in constrained environments like WebAssembly, mobile devices, on remote machines, in sandboxes,
//! etc.
//!
//! # Key Features
//!
//! - **No async runtime required**: Uses threads instead of tokio, simplifying integration.
//! - **Embeddable**: Drop into any Rust application for debugging or agent interaction.
//! - **Platform support**: Works on desktop, mobile, and WebAssembly (with limitations).
//! - **Proxy architecture**: Enables remote debugging of browser/WASM apps via WebSockets.
//! - **Privacy-aware logging**: Integration with `logwise` for controlled log capture.
//!
//! # Use Cases
//!
//! Exfiltrate is the answer to these frequently-asked questions:
//!
//! * How can I quickly expose internal state or operations of my program to a CLI?
//! * How can I add a custom debug command into debug builds of my program?
//! * How can I interact with my program running in a foreign environment, like a mobile app or browser?
//! * How can I steer an LLM agent to reason about my program's state at runtime?
//!
//! # Quick start
//!
//! claude "Run the exfiltrate_cli command, then integrate the library into my program."
//!
//! ## Progressive disclosure
//!
//! A key design philosophy is to use a feature similar to [agent skills](https://code.claude.com/docs/en/skills)
//! to progressively disclose information useful to a task. When exfiltrate starts up, it provides
//! a helpful menu of topics that can be perused by either humans or agents at their leisure.
//!
//! Use `exfiltrate list` in the CLI to see all available commands (both built-in and custom),
//! and `exfiltrate help <command>` to get detailed information about any command.
//!
//! ## Agent use
//!
//! I recommend instructing agents explicitly to use the exfiltrate command prior to debugging a Rust
//! program.
//!
//! # Less-Quick Start
//!
//! ## Basic Usage
//!
//! 1. Add `exfiltrate` as a dependency.
//! 2. Call [`exfiltrate::begin()`](begin) at the start of your program.
//! 3. Use the `exfiltrate` CLI to connect and run commands.
//!
//! ## Implementing a Custom Command
//!
//! ```rust
//! # #[cfg(target_arch = "wasm32")]
//! wasm_lite::set_panic_hook();
//! use exfiltrate::command::{Command, Response};
//!
//! struct HelloCommand;
//!
//! impl Command for HelloCommand {
//! fn name(&self) -> &'static str {
//! "hello"
//! }
//!
//! fn short_description(&self) -> &'static str {
//! "Greets a user"
//! }
//!
//! fn full_description(&self) -> &'static str {
//! "Greets a user. Usage: hello [name]"
//! }
//!
//! fn execute(&self, args: Vec<String>) -> Result<Response, Response> {
//! let name = args.get(0).map(|s| s.as_str()).unwrap_or("World");
//! Ok(format!("Hello, {}!", name).into())
//! }
//! }
//!
//! // Register the command
//! exfiltrate::add_command(HelloCommand);
//! ```
//!
//! # Architecture
//!
//! ## Why threads?
//!
//! Many Rust networking libraries depend on `tokio` or other async runtimes. This makes sense for
//! high-concurrency servers, but it adds significant weight and complexity when you just want
//! to debug a program.
//!
//! This codebase has no dependency on `tokio`. Instead, it just uses threads. Threads for everyone.
//!
//! ## WebAssembly Support
//!
//! WebAssembly applications running in a browser cannot open raw TCP sockets. To support debugging
//! these applications, `exfiltrate` uses a proxy architecture:
//!
//! 1. The WASM application connects to a local proxy (`exfiltrate_proxy`) via WebSockets.
//! 2. The `exfiltrate` CLI connects to the same proxy via TCP.
//! 3. The proxy bridges the connection, allowing the CLI to control the WASM app as if it were local.
//!
//! # Feature Flags
//!
//! - `logwise` - Enables integration with the `logwise` logging framework for log capture.
//!
//! # Response Types
//!
//! Commands can return different response types:
//!
//! - **String** - Text output (most common)
//! - **Files** - Binary files via [`FileInfo`](command::FileInfo)
//! - **Images** - RGBA images via [`ImageInfo`](command::ImageInfo)
//!
//! For file and image responses, use the types from [`command`] module. Images use
//! [`RGBA8`](rgb::RGBA8) from the re-exported [`rgb`] crate.
//!
//! For integration guidance, run `exfiltrate help integration`. For detailed examples of
//! all response types, run `exfiltrate help custom_commands` in the CLI.
/// Re-export of the [`rgb`](https://docs.rs/rgb) crate for image pixel types.
///
/// Use [`rgb::RGBA8`] when constructing [`ImageInfo`](command::ImageInfo) responses.
pub use rgb;
use crateregister_commands;
use Command;
/// Initializes the exfiltrate debugging server.
///
/// This function should be called as early as possible in your application's lifecycle
/// (e.g., at the start of `main`). It starts the background server thread (or WASM worker)
/// that listens for connections from the CLI.
///
/// # Example
///
/// ```rust
/// # #[cfg(target_arch = "wasm32")]
/// wasm_lite::set_panic_hook();
/// exfiltrate::begin();
///
/// // ... rest of your application
/// ```
/// Registers a custom command with the exfiltrate server.
///
/// Custom commands allow you to expose application-specific state or actions
/// to the CLI.
///
/// # Example
///
/// ```rust
/// # #[cfg(target_arch = "wasm32")]
/// wasm_lite::set_panic_hook();
/// use exfiltrate::command::{Command, Response};
///
/// struct MyCommand;
/// impl Command for MyCommand {
/// fn name(&self) -> &'static str { "my_command" }
/// fn short_description(&self) -> &'static str { "Does something cool" }
/// fn full_description(&self) -> &'static str { "Does something cool..." }
/// fn execute(&self, _args: Vec<String>) -> Result<Response, Response> {
/// Ok("Cool!".into())
/// }
/// }
///
/// exfiltrate::add_command(MyCommand);
/// ```
/// Re-exports of types needed to implement custom commands.