diff --git a/crates/engine/src/inspect.rs b/crates/engine/src/inspect.rs index a98851137a..713f5b4c78 100644 --- a/crates/engine/src/inspect.rs +++ b/crates/engine/src/inspect.rs @@ -1,6 +1,6 @@ //! JSON views of engine state for automation, tests and debugging. -use photocraft_doc::{Layer, LayerContent}; +use photocraft_doc::{Layer, LayerContent, SmartSource}; use serde_json::{Value, json}; use crate::{DocState, Session}; @@ -103,6 +103,13 @@ fn layer_sel(l: &Layer, selected: &[photocraft_doc::LayerId]) -> Value { .collect(), ); v["smartFiltersEnabled"] = json!(sm.filters_enabled); + // Where the contents come from. A PSD placed layer (embedded or linked in Photoshop) is + // `linked` to the `Idnt` uuid of its file, which its duplicates share; New Smart Object + // via Copy embeds its own copy of the file instead. + v["smartSource"] = match &sm.source { + SmartSource::Embedded { file_name, .. } => json!({"kind": "embedded", "fileName": file_name}), + SmartSource::Linked { path } => json!({"kind": "linked", "path": path}), + }; } LayerContent::Text(t) => { v["text"] = json!({"text": t.text, "font": t.font_family, "sizePt": t.size_pt}); diff --git a/crates/engine/src/smart_cmds/tests.rs b/crates/engine/src/smart_cmds/tests.rs index ac00eb3472..0d3ca1e02f 100644 --- a/crates/engine/src/smart_cmds/tests.rs +++ b/crates/engine/src/smart_cmds/tests.rs @@ -733,3 +733,39 @@ fn convert_to_layers_conforms_the_contents_to_the_document_mode_and_depth() { let fmt = s.active().unwrap().doc.pixel_format(); assert!(matches!(&active_layer(&s).content, LayerContent::Raster(px) if px.format().mode == fmt.mode && px.format().sample == fmt.sample)); } + +#[test] +fn inspect_reports_the_smart_source() { + // A PSD placed layer: its file in the global `lnk2` block, the layer linked to its uuid. + let inner = Document::with_background( + "in", + Size::new(4, 4), + photocraft_color::ColorMode::Rgb, + photocraft_color::SampleType::U8, + photocraft_color::Color::rgba(0.0, 1.0, 0.0, 1.0), + ); + let png = photocraft_io::export(&inner, "png", &Default::default()).unwrap().bytes; + let lnk2 = photocraft_io::linked::encode_linked_file(&photocraft_io::linked::LinkedFile { uuid: "uuid-1".into(), file_name: "in.png".into(), bytes: png }); + let mut s = session(8); + s.edit("place", |doc, active| { + doc.metadata.psd_global_blocks.push((*b"8BIM", *b"lnk2", Arc::new(lnk2))); + let sm = SmartObject::new(SmartSource::Linked { path: "uuid-1".into() }, Affine::IDENTITY, None); + *active = Some(doc.insert_above(*active, Layer::new("front", LayerContent::Smart(sm)))); + Ok(()) + }) + .unwrap(); + let source = |s: &Session| crate::inspect::layer(s.active().unwrap().doc.layer(s.active().unwrap().active_layer.unwrap()).unwrap())["smartSource"].clone(); + let front = source(&s); + assert_eq!(front, json!({"kind": "linked", "path": "uuid-1"})); + // A duplicate shares the file; New Smart Object via Copy gets its own. + s.execute("layer.duplicate", json!({})).unwrap(); + assert_eq!(source(&s), front, "a duplicate shares its source"); + s.execute("layer.smartObjects.newSmartObjectViaCopy", json!({})).unwrap(); + assert_eq!(source(&s), json!({"kind": "embedded", "fileName": "in.png"}), "via copy embeds its own"); + + let mut s = session(8); + paint(&mut s); + convert(&mut s); + assert_eq!(source(&s)["kind"], "embedded"); + assert!(source(&s)["fileName"].is_string()); +} diff --git a/docs/development.md b/docs/development.md index 5b3f6f2390..81a07d2371 100644 --- a/docs/development.md +++ b/docs/development.md @@ -169,7 +169,9 @@ claude mcp add photocraft -- "$PWD/target/release/photocraft-cli" mcp ``` `doc_inspect` (and the engine command `document.inspect`) reports the layer tree with kinds, -bounds, masks, selection, effects (`effects.items[].kind`), smart filters (`smartFilters[]`), type +bounds, masks, selection, effects (`effects.items[].kind`), smart filters (`smartFilters[]`), smart +object sources (`smartSource`: `embedded` with its file name, or `linked` with a file path or, for a +PSD placed layer, the `Idnt` uuid its duplicates share), type text, adjustment settings, channels and history, so agents can verify what they did without a screenshot. `crates/automation/tests/agent_tasks.rs` is the reference: ten realistic edit tasks (title card, colour grade, undo/redo, editable smart blur, masks, saved selections, align,