Add design containers with deduplicated blobs and JSON compatibility (#327)

* Add fast design containers with lossless deduplicated payloads

* Keep display caching opt-in to avoid default save overhead
This commit is contained in:
selune authored and GitHub committed 2026-10-12 19:15:41 -04:00
1 parent 8e0c3d2794
commit 006a23a767
30 files changed
+1921 -71

No files matched your search

+32
View File
@@ -178,6 +178,38 @@ fn agent_builds_box_fillet_hole() {
let _ = std::fs::remove_dir_all(&dir);
}
#[test]
fn save_selects_container_or_json_and_reopens_by_contents() {
let mut s = server();
tool(&mut s, "execute", json!({"command": "solid.box", "params": {"length": 10, "width": 20, "height": 30}}));
let dir = std::env::temp_dir().join(format!("solidcraft-mcp-encodings-{}", std::process::id()));
std::fs::create_dir_all(&dir).unwrap();
for (name, format, is_json) in [
("default.solidcraft", None, false),
("explicit.solidcraft", Some("json"), true),
("legacy.solvecraft", None, false),
("inferred.json", None, true),
("container.json", Some("container"), false),
] {
let path = dir.join(name);
let mut args = json!({"path": path.to_string_lossy()});
if let Some(format) = format {
args["format"] = json!(format);
}
tool(&mut s, "save", args);
let bytes = std::fs::read(&path).unwrap();
if is_json {
assert!(serde_json::from_slice::<Value>(&bytes).unwrap().is_object());
} else {
assert!(bytes.starts_with(b"PK\x03\x04"));
}
tool(&mut s, "new_design", json!({}));
tool(&mut s, "open", json!({"path": path.to_string_lossy()}));
assert!(rel(volume(&mut s), 6000.0) < 1e-9);
}
std::fs::remove_dir_all(&dir).unwrap();
}
#[test]
fn parameters_drive_the_design() {
let mut s = server();
+6 -3
View File
@@ -224,8 +224,11 @@ pub fn tool_definitions() -> Vec<Value> {
tool(
"save",
"Save the design",
"Save the design as a .solidcraft file (to `path`, or to the file it came from).",
obj(json!({"path": string("Path to save to (default: the current file)")}), &[]),
"Save the design to `path` or its current file. The default is a design container; a .json path selects plain JSON. Set format to container or json to override the path.",
obj(
json!({"path": string("Path to save to (default: the current file)"), "format": {"type": "string", "enum": ["container", "json"], "description": "Design encoding (default: JSON for .json, container otherwise)"}}),
&[],
),
false,
false,
),
@@ -378,7 +381,7 @@ fn dispatch(b: &mut dyn Backend, name: &str, a: &Map<String, Value>) -> Result<V
"redo" => exec(b, "edit.redo", json!({})),
"new_design" => exec(b, "file.new", pick(a, &["name"])),
"open" => exec(b, "doc.open", pick(a, &["path"])),
"save" => exec(b, "file.save", pick(a, &["path"])),
"save" => exec(b, "file.save", pick(a, &["path", "format"])),
other => Err(format!("unknown tool `{other}`")),
}
}