Stream attachments end to end, ship files to a remote session's machine, and write up the transcript work
Uploads no longer sit whole in memory anywhere: the phone writes the multipart body chunked as it reads the picked file, and the server writes each chunk to a `.part` file under the session and renames it when whole. The per-request cap is 4 GB and bounds disk, not memory. A file attached to a session on another machine is copied there in the same request: one ssh invocation takes the bytes on stdin into the setup's `attachmentsDir` (new, optional, on the machine form and in the config), else the session's cwd, else the login home, and answers with `pwd -P`, which is recorded beside the file as `<name>.remote` and is the path the driver tells the CLI. A failed copy fails the upload and says why, so no message ever names a file that is not there. The host keeps its copy so transcripts can reference and fetch it. Measured against the Gentoo test guest: a 40 MB file shared from the phone arrived there byte for byte. The tilde in that setting is the remote home, so it is not expanded on the server the way other setup paths are. TRANSCRIPT_RENDERING.md records the week of transcript work -- the measurements behind each decision, the harness, what was rejected, and what to do next -- so a new session can start from it. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
1 parent
6180663f14
commit
801618ba0e
12 files changed
+499
-57
No files matched your search
@@ -1220,6 +1220,14 @@ fn attachment_path(session_dir: &Path, id: &str) -> Result<PathBuf> {
|
||||
anyhow::bail!("invalid attachment id");
|
||||
}
|
||||
let path = session_dir.join("attachments").join(id);
|
||||
// A file copied to the session's own machine is named where it landed
|
||||
// there -- `routes::upload_attachment` writes that down beside it --
|
||||
// because the path has to be one the CLI can open, not one this server
|
||||
// can.
|
||||
let shipped = path.with_file_name(format!("{id}.remote"));
|
||||
if let Ok(remote) = std::fs::read_to_string(&shipped) {
|
||||
return Ok(PathBuf::from(remote.trim()));
|
||||
}
|
||||
std::fs::canonicalize(&path).with_context(|| format!("find {}", path.display()))
|
||||
}
|
||||
|
||||
@@ -1244,6 +1252,30 @@ fn attachment_block(session_dir: &Path, id: &str) -> Result<Value> {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn an_attachment_is_named_where_the_cli_can_open_it() {
|
||||
let dir = tempfile::tempdir().expect("temp dir");
|
||||
let attachments = dir.path().join("attachments");
|
||||
std::fs::create_dir(&attachments).unwrap();
|
||||
std::fs::write(attachments.join("ab12-x.bin"), b"x").unwrap();
|
||||
assert_eq!(
|
||||
attachment_path(dir.path(), "ab12-x.bin").unwrap(),
|
||||
attachments.join("ab12-x.bin").canonicalize().unwrap()
|
||||
);
|
||||
// Shipped to the session's machine: the path there, not here.
|
||||
std::fs::write(
|
||||
attachments.join("ab12-x.bin.remote"),
|
||||
"/home/t/in/ab12-x.bin\n",
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
attachment_path(dir.path(), "ab12-x.bin").unwrap(),
|
||||
PathBuf::from("/home/t/in/ab12-x.bin")
|
||||
);
|
||||
assert!(attachment_path(dir.path(), "../config.ron").is_err());
|
||||
assert!(attachment_path(dir.path(), "missing.bin").is_err());
|
||||
}
|
||||
|
||||
/// Drives real CLI output lines through the reader and collects what
|
||||
/// came out, which is the only way to check the wiring between "the
|
||||
/// CLI said this" and "the transcript records that".
|
||||
|
||||
Reference in new issue
Block a user