inspect: report each smart object's source

document.inspect (and photocraft-cli info) now gives every smart object a
smartSource: embedded with its file name, or linked with a file path or,
for a PSD placed layer, the Idnt uuid its duplicates share. A script can
then tell duplicates of one placed file from independent contents, e.g.
to check that every location in a mockup template has its own art.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Juan Manuel Verges SolanasandClaude Opus 5.5 committed 2026-10-09 11:17:15 +00:00
1 parent 2515fa7cee
commit 0103edfdfd
3 files changed
+47 -2

No files matched your search

+8 -1
View File
@@ -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});
+36
View File
@@ -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());
}
+3 -1
View File
@@ -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,