workbuddy-layered-psd-bridge 1.1.1 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,42 +1,46 @@
1
- # WorkBuddy Layered PSD Bridge 1.1.1
1
+ # WorkBuddy Layered PSD Bridge 1.2.1 candidate
2
2
 
3
- Create a real layered Photoshop PSD from a **structured poster plan** in WorkBuddy. Ardot is optional. The primary path needs only WorkBuddy and Windows desktop Photoshop on the same PC; WorkBuddy prepares Node for the Connector.
3
+ Create a native layered Photoshop PSD from a structured poster plan in WorkBuddy. Ardot is optional. The default route needs WorkBuddy and Windows desktop Photoshop on the same PC; WorkBuddy supplies its managed Node runtime.
4
4
 
5
- ## What this does
5
+ ## What this version adds
6
6
 
7
- WorkBuddy plans the poster as separate text, vector shapes, image assets, and groups. The Connector snapshots the assets, checks the plan, and asks local Photoshop to create a PSD and JPEG preview from one document. The user can inspect the preview in WorkBuddy, request changes by layer ID, and generate a revised PSD without reuploading unchanged assets.
7
+ - `qualitySpec` declares important reference elements and their intended independent layer IDs. `strict` mode rejects missing, wrong-type, hidden, or shared layers during preparation. The report explicitly says `declaration_only: true` and `visual_verified: false`: a successful structural check cannot prove that a background image no longer contains the original object.
8
+ - `productionSpec` accepts finished width/height in millimeters and a project-specific minimum effective PPI. Production mode checks the canvas and each visible image at its actual `cover`/`contain` placement, rejects low resolution or mismatched proportions before launching Photoshop, and sets PSD document resolution so the declared physical size is reflected in Photoshop without resampling.
9
+ - The export reads back PSD pixel dimensions, stored resolution, derived physical size, and JPEG preview pixel dimensions. The preview is capped at a 1600-pixel longest side and is for screen review only.
10
+ - Hardware checks now consider currently available RAM and warn when estimated PSD layer data may approach the PSD format's practical size limit. Existing font-substitution and layer-tree reports remain.
11
+ - The WorkBuddy Connector bundle includes a second Skill for reference-image decomposition, visual comparison, and honest editability reporting.
12
+ - `background_diagnostic.jpg` is exported from Photoshop with declared independent foreground layers hidden. It helps reveal old text, objects, and holes still present in the base. Its coverage flag refers only to `qualitySpec` elements the caller declared, and `visual_verified` remains false.
13
+ - `duplicate_audit` optionally compares opaque pixels of independent image layers against one full-canvas image base in the final PSD. A `BAKED_DUPLICATE` warning requires base repair; flat-color matches need human review. `UNVERIFIED_*` reports a bounded or unsupported audit; `NO_EXACT_DUPLICATE_DETECTED` cannot prove a clean base. The auditor uses optional pure-JavaScript `ag-psd` and skips itself if that package is unavailable, without failing PSD/JPEG export.
8
14
 
9
- A single ImageGen poster or a WorkBuddy image-edit result is a bitmap, not a recoverable layer tree. The Connector rejects a one-image poster when the user asks for a fully layered PSD. To keep layers editable, design the poster as layers from the beginning and generate photographs/illustrations as independent assets.
15
+ ## Limits
16
+
17
+ The connector builds native Photoshop text layers, solid-color rectangles/ellipses, independent PNG/JPEG smart-object image layers, and groups. It does not automatically recover original source layers from a flattened picture. An independent image layer remains pixels internally. Extracting cars, people, signs, and clean backgrounds from a single reference still requires real image-separation and reconstruction work, followed by visual inspection. This release does not export native Illustrator AI or CorelDRAW CDR files.
10
18
 
11
19
  ## Requirements
12
20
 
13
- - Windows WorkBuddy 5.0+ and Adobe Photoshop 2020 (v21) or newer. Photoshop **26.8.1** was used for the original RGB and CMYK builds and for a 1.1.1 font-selection regression. On another PC, Photoshop **25.0.0** exported a layered PSD with the 1.1.1 local candidate tarball: the export reported no warnings, and the user visually confirmed separate editable bold and regular text layers plus an independent rectangle layer. This is local candidate validation; public npm installation remains to be tested after publication.
14
- - Node 20+ when running outside WorkBuddy. WorkBuddy's Connector `runtime.type: "node"` can provide it automatically.
15
- - Enough RAM and disk for the chosen canvas. The backend checks dimensions, layer/asset counts, decoded image sizes, memory and disk estimates, and asset hashes before building. There is no single hardware minimum for every poster.
16
- - Fonts used by editable text should be installed on the target PC. Substitution is reported; text overflow fails rather than silently shifting the design.
21
+ - Windows WorkBuddy 5.0+ and a local Photoshop version accepted by `photoshop_status`. The previous 1.1.1 public connector was exercised on Photoshop 25.0.0 and 26.8.1; this candidate's new production-DPI path has been exercised on 26.8.1. Other versions should be checked on the target PC.
22
+ - Node 20+ only when running the package outside WorkBuddy. WorkBuddy's Connector runtime can provide Node automatically.
23
+ - Enough RAM and disk for the selected canvas. There is no universal hardware minimum. Large files may require a smaller pixel canvas or a future PSB route.
24
+ - Fonts for editable text should be installed on the target PC. Substitutions are reported; text overflow fails rather than silently changing the layout.
17
25
 
18
26
  ## MCP workflow
19
27
 
20
- 1. `photoshop_status` checks the target installation. Optional `progId` selects a particular registered Photoshop version, such as `Photoshop.Application.27`.
21
- 2. `prepare_workbuddy_poster` receives `canvas`, bottom-to-top `layers`, and separate `imageAssets`; it returns a preparation ID immediately. It also supports `baseDraftId` plus restricted layer `edits` for later revisions.
22
- 3. `get_poster_preparation` polls for a frozen `draftId` and SHA-256.
23
- 4. `start_psd_export` creates a durable local Photoshop job; `get_psd_job` polls for a PSD/JPEG result and warnings.
24
- 5. `get_poster_draft` provides bounded layer information for a revision without exposing local asset paths.
28
+ 1. `photoshop_status` checks the target installation. Optional `progId` selects a registered Photoshop version.
29
+ 2. Build separate text/shape/image/group layers in bottom-to-top order. For reference work, list the required elements and pass `qualitySpec: {mode:'strict',expectedElements:[...]}` to `prepare_workbuddy_poster`. For physical production, also pass `productionSpec: {mode:'production',widthMm,heightMm,minEffectivePpi}`. Use `proof` without a physical-size claim for screen drafts.
30
+ 3. Poll `get_poster_preparation` for `draftId`, SHA-256, `quality_report`, and `production_preflight`. A strict error supplies bounded `issues` so multiple missing elements can be corrected in one task.
31
+ 4. `start_psd_export` creates a durable local Photoshop job. Poll `get_psd_job` for the PSD/JPEG files, actual PSD and preview dimensions, layer-tree check, quality report, production preflight, background diagnostic, duplicate audit, and warnings.
32
+ 5. Inspect the preview and diagnostic against the reference. A `BAKED_DUPLICATE` result needs a repaired base and a new export. Where possible, hide or move key layers in Photoshop to check for old objects or holes in the background. `baseDraftId` plus `edits` revises supported layer properties without reuploading unchanged images; quality and production settings are inherited unless overridden.
25
33
 
26
- The older `prepare_ardot_canvas` and `get_ardot_preparation` route remains available for users who already have an accessible Ardot MCP node tree. It is not part of the default installation path.
34
+ The optional `prepare_ardot_canvas` and `get_ardot_preparation` route remains available when real Ardot MCP node data and per-node assets exist. It is not required for installation or the direct WorkBuddy workflow.
27
35
 
28
36
  ## Storage and recovery
29
37
 
30
- Default drafts and final files are under `~/Documents/WorkBuddyLayeredPSD/work` and `~/Documents/WorkBuddyLayeredPSD/deliveries`. Use absolute `WORKBUDDY_PSD_DATA_DIR` and `WORKBUDDY_PSD_OUTPUT_DIR` environment variables to change them. The earlier `ZAOJIAN_PSD_DATA_DIR` and `ZAOJIAN_PSD_OUTPUT_DIR` names remain accepted for existing setups. The package does not assume any particular drive letter or creator workstation configuration.
31
-
32
- Assets are copied into immutable snapshots. The bridge serializes Photoshop jobs so concurrent requests do not manipulate the same Photoshop instance. After a script timeout, it leaves `photoshop.lock` in the data directory because Photoshop might still be running the script. Close Photoshop and WorkBuddy, remove that lock, then restart. Incomplete drafts are cleared; completed draft caches are pruned after 30 days if no active job uses them. PSD/JPEG deliverables are not pruned.
33
-
34
- HTTPS image imports are restricted to trusted hosts; local paths and MCP image bytes are supported. For a WorkBuddy generated image, use the local image file path or image data rather than assuming an undocumented remote URL is trusted.
38
+ Default drafts and final files are under the user's `Documents/WorkBuddyLayeredPSD/work` and `Documents/WorkBuddyLayeredPSD/deliveries`. Set absolute `WORKBUDDY_PSD_DATA_DIR` and `WORKBUDDY_PSD_OUTPUT_DIR` to change them. The previous `ZAOJIAN_PSD_DATA_DIR` and `ZAOJIAN_PSD_OUTPUT_DIR` names remain accepted. No publisher-machine path is embedded in the package.
35
39
 
36
- ## Distribution
40
+ Assets are copied into immutable snapshots. Photoshop jobs are serialized. After a script timeout, the bridge retains `photoshop.lock` because Photoshop may still be running; close Photoshop and WorkBuddy, remove the lock from the data directory, and restart. Incomplete drafts are cleared and completed draft caches are pruned after 30 days if no active job uses them. PSD/JPEG deliverables are not pruned.
37
41
 
38
- Publish `workbuddy-layered-psd-bridge@1.1.1` to npm **after validating the candidate** and before uploading the matching WorkBuddy Connector ZIP. The market ZIP contains metadata, `mcp.json`, icon, and a Skill; it does not itself contain this executable package. WorkBuddy's managed Node runtime allows other users to connect without installing Node manually. The published 1.1.0 package is immutable and must not be republished.
42
+ ## Distribution status
39
43
 
40
- The public WorkBuddy docs describe the built-in “设计创意” Ardot canvas but do not document a way for a third-party Connector to read its internal node tree directly. The direct WorkBuddy route therefore builds its **own explicit layer plan**. The Ardot route requires real MCP node data and has not been validated against a live account in this release.
44
+ Version 1.1.1 is the published and user-tested baseline. Version 1.2.1 in this workspace is an **unpublished candidate**. Publish the matching npm package before uploading or enabling a WorkBuddy Connector ZIP whose `mcp.json` pins `workbuddy-layered-psd-bridge@1.2.1`. The ZIP contains metadata, `mcp.json`, icon, and the two Skills; the executable package is obtained from npm. The earlier 1.2.0 candidate does not contain this audit and must not be uploaded as 1.2.1.
41
45
 
42
- References: [WorkBuddy Connector format](https://open.workbuddy.cn/docs/connector) · [WorkBuddy design mode](https://www.workbuddy.cn/docs/workbuddy/From-Beginner-to-Expert-Guide/Function-Description/Design-Idea) · [Ardot MCP](https://docs.ardot.tencent.com/ardot-mcp/features.html)
46
+ References: [WorkBuddy Connector format](https://open.workbuddy.cn/docs/connector) · [Ardot MCP](https://docs.ardot.tencent.com/ardot-mcp/features.html)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "workbuddy-layered-psd-bridge",
3
- "version": "1.1.1",
3
+ "version": "1.2.1",
4
4
  "description": "Local WorkBuddy MCP bridge from structured poster layers to editable Photoshop PSD",
5
5
  "type": "module",
6
6
  "bin": {
@@ -19,5 +19,8 @@
19
19
  "dependencies": {
20
20
  "@modelcontextprotocol/server": "2.4.0",
21
21
  "zod": "4.6.7"
22
+ },
23
+ "optionalDependencies": {
24
+ "ag-psd": "34.2.3"
22
25
  }
23
26
  }
@@ -4,12 +4,14 @@ This directory is a standalone Windows backend for the `zaojian.psd.manifest.v1`
4
4
 
5
5
  ## Requirements and compatibility
6
6
 
7
- - Windows desktop Photoshop with a registered `Photoshop.Application` COM server. Photoshop 2020 (internal version 21) is the minimum accepted version. The integration was exercised on Photoshop 26.8.1 on Windows x64; other versions must be checked on the installed machine.
7
+ - Windows desktop Photoshop with a registered `Photoshop.Application` COM server. Photoshop 2020 (internal version 21) is the minimum accepted version. The earlier 1.1.1 flow was exercised on Photoshop 25.0.0 and 26.8.1; the new production-DPI flow has been exercised on 26.8.1. Other versions must be checked on the installed machine.
8
8
  - Node.js 20 or newer and Windows PowerShell 5.1. The WorkBuddy connector package can use its managed Node runtime.
9
- - Enough memory and disk space for the canvas and source images. The preflight estimates RAM and free space and rejects jobs beyond its limits; Photoshop may require more memory for complex files.
9
+ - Enough memory and disk space for the canvas and source images. The preflight estimates RAM, current available memory, and free space and rejects jobs beyond its limits; Photoshop may require more memory for complex files. Large layer data receives a PSD-size warning because this backend does not yet write PSB.
10
10
  - Installed fonts for best fidelity. If a requested font is absent, the backend chooses a local fallback and reports a warning. Text stays editable.
11
11
 
12
- The backend rejects unsupported layer styles and malformed manifests before opening Photoshop. It creates editable text layers, vector solid-color shape layers, independent embedded image smart objects, and nested groups. It applies visibility, opacity, and leaf rotation. It saves a layered PSD and then duplicates that same Photoshop document to make the JPEG preview. CMYK documents are supported by the code path and the preview is converted to RGB; the integration fixture currently validates RGB.
12
+ The backend rejects unsupported layer styles and malformed manifests before opening Photoshop. It creates editable text layers, vector solid-color shape layers, independent embedded image smart objects, and nested groups. It applies visibility, opacity, and leaf rotation. It saves a layered PSD and then duplicates that same Photoshop document to make the JPEG preview. CMYK documents are supported and the preview is converted to RGB; the new production-size regression used RGB.
13
+
14
+ Optional `qualitySpec` checks a caller's reference-element-to-layer declaration; it does not analyze pixels inside the images. Optional `productionSpec` checks effective PPI at actual physical size, including `cover`/`contain` scaling, and rejects low-resolution production jobs before Photoshop starts. Production mode sets the document resolution from pixel width and requested millimeters without adding image detail. The result reads back actual PSD pixels/resolution/physical size and JPEG pixels independently.
13
15
 
14
16
  ## CLI
15
17
 
@@ -18,7 +20,7 @@ node ps_backend/cli.mjs status --json
18
20
  node ps_backend/cli.mjs build --manifest C:\absolute\work\manifest.json --data-root C:\absolute\work --output-root C:\absolute\deliveries --output-dir C:\absolute\deliveries\job
19
21
  ```
20
22
 
21
- `status` prints one compact JSON line with Photoshop version, platform, architecture, RAM, and a support note. `build` prints one compact JSON line as its last stdout line, with `ok`, PSD and preview absolute paths, Photoshop version, verified layer count/tree, hardware estimate, and warnings. Failures print `{ "ok": false, "code": "...", "error": "..." }` and exit nonzero. `--progid Photoshop.Application.N` can select a separately registered Photoshop version.
23
+ `status` prints one compact JSON line with Photoshop version, platform, architecture, available RAM, and a support note. `build` prints one compact JSON line as its last stdout line, with `ok`, PSD and preview absolute paths, Photoshop version, verified layer count/tree, `quality_report` when declared, `production_preflight`, `psd_dimensions`, `preview_dimensions`, hardware estimate, and warnings. Failures print `{ "ok": false, "code": "...", "error": "..." }` and exit nonzero. `--progid Photoshop.Application.N` can select a separately registered Photoshop version.
22
24
 
23
25
  The manifest and all assets must resolve inside `--data-root`. `--output-dir` must resolve inside the explicitly configured `--output-root`. Both roots may be siblings. Assets are copied into a unique run cache after hash validation so Photoshop reads a stable snapshot. The backend rejects path traversal, symlink escape, mismatched hashes, invalid PNG/JPEG headers, oversized decoded images, unsupported styles, and unavailable output space.
24
26
 
@@ -4,6 +4,8 @@ var ZJ_WARNINGS = [];
4
4
  var ZJ_CREATED = 0;
5
5
  var ZJ_DOC = null;
6
6
  var ZJ_PREVIEW_DOC = null;
7
+ var ZJ_DIAGNOSTIC_DOC = null;
8
+ var ZJ_CREATED_LAYERS = {};
7
9
 
8
10
  function zjPx(value) { return UnitValue(Number(value), "px"); }
9
11
  function zjHex(value) {
@@ -146,8 +148,8 @@ function zjText(parent, node) {
146
148
  item.kind = TextType.POINTTEXT;
147
149
  var textValue = spec.lines && spec.lines.length ? spec.lines.join("\r") : String(spec.value).replace(/\r\n|\r|\n/g, "\r");
148
150
  item.contents = textValue;
149
- item.size = UnitValue(Number(spec.fontSizePx) * 72 / JOB.canvas.dpi, "pt");
150
- item.leading = UnitValue(Number(spec.lineHeightPx || spec.fontSizePx * 1.2) * 72 / JOB.canvas.dpi, "pt");
151
+ item.size = UnitValue(Number(spec.fontSizePx) * 72 / JOB.documentDpi, "pt");
152
+ item.leading = UnitValue(Number(spec.lineHeightPx || spec.fontSizePx * 1.2) * 72 / JOB.documentDpi, "pt");
151
153
  zjSetFont(item, spec, node.name);
152
154
  item.color = zjHex(spec.color);
153
155
  if (spec.align == "center") item.justification = Justification.CENTER;
@@ -238,16 +240,51 @@ function zjBuildNode(parent, node) {
238
240
  if (node.opacity != null) layer.opacity = Math.max(0,Math.min(100,Number(node.opacity)*100));
239
241
  if (node.rotation && node.type != "group") layer.rotate(Number(node.rotation), AnchorPosition.MIDDLECENTER);
240
242
  if (node.visible === false) layer.visible = false;
243
+ ZJ_CREATED_LAYERS["L:" + String(node.id)] = layer;
241
244
  ZJ_CREATED++;
242
245
  return layer;
243
246
  }
247
+ function zjSaveBackgroundDiagnostic() {
248
+ if (!JOB.backgroundDiagnosticPath || !JOB.backgroundDiagnosticLayerIds ||
249
+ JOB.backgroundDiagnosticLayerIds.length === 0) return;
250
+ var changed = [];
251
+ try {
252
+ for (var i = 0; i < JOB.backgroundDiagnosticLayerIds.length; i++) {
253
+ var id = String(JOB.backgroundDiagnosticLayerIds[i]);
254
+ var layer = ZJ_CREATED_LAYERS["L:" + id];
255
+ if (!layer || layer.typename == "LayerSet")
256
+ throw new Error("Diagnostic target missing or not a leaf layer: " + id);
257
+ if (!layer.visible) throw new Error("Diagnostic target already hidden: " + id);
258
+ layer.visible = false;
259
+ changed.push(layer);
260
+ }
261
+ ZJ_DIAGNOSTIC_DOC = ZJ_DOC.duplicate("Zaojian background diagnostic", false);
262
+ ZJ_DIAGNOSTIC_DOC.flatten();
263
+ if (ZJ_DIAGNOSTIC_DOC.mode != DocumentMode.RGB)
264
+ ZJ_DIAGNOSTIC_DOC.changeMode(ChangeMode.RGB);
265
+ var maxSide = Math.max(ZJ_DIAGNOSTIC_DOC.width.as("px"), ZJ_DIAGNOSTIC_DOC.height.as("px"));
266
+ if (maxSide > 1200) {
267
+ var ratio = 1200 / maxSide;
268
+ ZJ_DIAGNOSTIC_DOC.resizeImage(zjPx(ZJ_DIAGNOSTIC_DOC.width.as("px") * ratio),
269
+ zjPx(ZJ_DIAGNOSTIC_DOC.height.as("px") * ratio), null, ResampleMethod.BICUBIC);
270
+ }
271
+ var jpgOptions = new JPEGSaveOptions();
272
+ jpgOptions.quality = 8;
273
+ jpgOptions.embedColorProfile = true;
274
+ ZJ_DIAGNOSTIC_DOC.saveAs(new File(JOB.backgroundDiagnosticPath), jpgOptions, true, Extension.LOWERCASE);
275
+ } finally {
276
+ try { if (ZJ_DIAGNOSTIC_DOC) ZJ_DIAGNOSTIC_DOC.close(SaveOptions.DONOTSAVECHANGES); } catch (ignoreDiagnostic) {}
277
+ ZJ_DIAGNOSTIC_DOC = null;
278
+ for (var j = changed.length - 1; j >= 0; j--) changed[j].visible = true;
279
+ }
280
+ }
244
281
  function zjBuild() {
245
282
  var originalDialogs = app.displayDialogs;
246
283
  var originalDoc = app.documents.length ? app.activeDocument : null;
247
284
  try {
248
285
  app.displayDialogs = DialogModes.NO;
249
286
  var mode = JOB.canvas.colorMode == "CMYK" ? NewDocumentMode.CMYK : NewDocumentMode.RGB;
250
- ZJ_DOC = app.documents.add(zjPx(JOB.canvas.widthPx),zjPx(JOB.canvas.heightPx),Number(JOB.canvas.dpi),
287
+ ZJ_DOC = app.documents.add(zjPx(JOB.canvas.widthPx),zjPx(JOB.canvas.heightPx),Number(JOB.documentDpi),
251
288
  String(JOB.canvas.name),mode,DocumentFill.WHITE);
252
289
  for (var i = 0; i < JOB.layers.length; i++) zjBuildNode(ZJ_DOC,JOB.layers[i]);
253
290
  zjWriteLayerReport();
@@ -270,12 +307,19 @@ function zjBuild() {
270
307
  ZJ_PREVIEW_DOC.saveAs(new File(JOB.previewPath),jpgOptions,true,Extension.LOWERCASE);
271
308
  ZJ_PREVIEW_DOC.close(SaveOptions.DONOTSAVECHANGES);
272
309
  ZJ_PREVIEW_DOC = null;
310
+ try {
311
+ zjSaveBackgroundDiagnostic();
312
+ } catch (diagnosticError) {
313
+ ZJ_WARNINGS.push("BACKGROUND_DIAGNOSTIC_FAILED: " +
314
+ String(diagnosticError.message || diagnosticError));
315
+ }
273
316
  ZJ_DOC.close(SaveOptions.DONOTSAVECHANGES);
274
317
  ZJ_DOC = null;
275
318
  if (originalDoc) app.activeDocument = originalDoc;
276
319
  zjStatus("OK", "PSD and preview saved");
277
320
  } catch (error) {
278
321
  try { if (ZJ_PREVIEW_DOC) ZJ_PREVIEW_DOC.close(SaveOptions.DONOTSAVECHANGES); } catch (ignorePreview) {}
322
+ try { if (ZJ_DIAGNOSTIC_DOC) ZJ_DIAGNOSTIC_DOC.close(SaveOptions.DONOTSAVECHANGES); } catch (ignoreDiagnostic) {}
279
323
  try { if (ZJ_DOC) ZJ_DOC.close(SaveOptions.DONOTSAVECHANGES); } catch (ignoreDocument) {}
280
324
  try { if (originalDoc) app.activeDocument = originalDoc; } catch (ignoreRestore) {}
281
325
  zjStatus("ERROR", String(error.message || error) + " at line " + String(error.line || "?"));