editmamei 0.19.0 → 0.22.0

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.
Files changed (72) hide show
  1. package/NOTICES.md +17 -1
  2. package/README.md +9 -8
  3. package/dist/api/extendscript/_helpers.js +1 -1
  4. package/dist/bin/editmamei-core-darwin-arm64 +0 -0
  5. package/dist/bin/editmamei-core-darwin-x64 +0 -0
  6. package/dist/bin/editmamei-core-win-x64.exe +0 -0
  7. package/dist/cli/config.js +3 -3
  8. package/dist/cli/help.js +4 -0
  9. package/dist/cli/install.js +2 -2
  10. package/dist/cli/report.js +11 -0
  11. package/dist/cli/router.js +20 -0
  12. package/dist/core/server.js +8 -8
  13. package/dist/core/settings.js +2 -2
  14. package/dist/core/tool-groups.js +92 -82
  15. package/dist/core/tool-tiers.js +91 -81
  16. package/dist/detection/landmark-detection-client.js +8 -0
  17. package/dist/detection/mesh-eye-correction.js +126 -0
  18. package/dist/detection/sam-segmenter.js +83 -0
  19. package/dist/diagnostics/collect.js +169 -0
  20. package/dist/index.js +2 -0
  21. package/dist/license/entitlement.js +52 -0
  22. package/dist/modules/ce/index.js +6 -4
  23. package/dist/perception/grounding-anchors.js +37 -0
  24. package/dist/perception/grounding-corners.js +93 -0
  25. package/dist/perception/grounding-edge-trace.js +90 -0
  26. package/dist/perception/grounding-extrema.js +41 -0
  27. package/dist/perception/grounding-gate.js +154 -0
  28. package/dist/perception/grounding-geometry.js +132 -0
  29. package/dist/perception/grounding-grid.js +34 -0
  30. package/dist/perception/grounding-landmarks.js +40 -0
  31. package/dist/perception/grounding-locate.js +341 -0
  32. package/dist/perception/grounding-resolver.js +202 -0
  33. package/dist/perception/grounding-review-crop.js +85 -0
  34. package/dist/perception/grounding-warp.js +182 -0
  35. package/dist/perception/sky-mask-transfer.js +50 -18
  36. package/dist/skills/editmamei-skill.zip +0 -0
  37. package/dist/tools/adjustment-tools.js +3 -3
  38. package/dist/tools/brush-tools.js +111 -23
  39. package/dist/tools/channel-compose-tools.js +241 -0
  40. package/dist/tools/detection-tools.js +1 -1
  41. package/dist/tools/diagnostics-tools.js +66 -0
  42. package/dist/tools/document-tools.js +6 -6
  43. package/dist/tools/filter-tools.js +476 -19
  44. package/dist/tools/group-tools.js +10 -10
  45. package/dist/tools/guide-tools.js +4 -4
  46. package/dist/tools/history-tools.js +4 -4
  47. package/dist/tools/image-placement-tools.js +1 -1
  48. package/dist/tools/image-tools.js +62 -19
  49. package/dist/tools/inspect-tools.js +2 -2
  50. package/dist/tools/layer-ordering-tools.js +1 -1
  51. package/dist/tools/layer-properties-tools.js +42 -23
  52. package/dist/tools/layer-tools.js +10 -10
  53. package/dist/tools/layer-transform-tools.js +80 -41
  54. package/dist/tools/overview-tools.js +42 -42
  55. package/dist/tools/path-tools.js +53 -10
  56. package/dist/tools/portrait-tools.js +3 -3
  57. package/dist/tools/preview-tools.js +7 -82
  58. package/dist/tools/retouch-tools.js +93 -25
  59. package/dist/tools/scene-tools.js +13 -13
  60. package/dist/tools/selection-tools.js +319 -40
  61. package/dist/tools/shape-tools.js +216 -0
  62. package/dist/tools/text-tools.js +1 -1
  63. package/dist/tools/transform-canvas-tools.js +2 -2
  64. package/dist/tools/vector-mask-tools.js +23 -8
  65. package/dist/utils/log-buffer.js +41 -0
  66. package/dist/utils/logger.js +12 -1
  67. package/dist/utils/session-log-reader.js +27 -1
  68. package/dist/version.js +1 -1
  69. package/package.json +1 -1
  70. package/dist/preview/coordinate-grid.js +0 -250
  71. package/dist/tools/object-tools.js +0 -193
  72. package/dist/tools/text-on-object-tools.js +0 -225
@@ -2,6 +2,8 @@ import { readFile } from 'node:fs/promises';
2
2
  import { runScript } from '../utils/run-script.js';
3
3
  import { TempDir } from '../utils/temp.js';
4
4
  import { validateArgs } from '../utils/validate.js';
5
+ import { OnnxLandmarkDetectionClient } from '../detection/landmark-detection-client.js';
6
+ import { resolveExpectedPlacement, PLACEMENT_SCHEMA } from '../perception/grounding-locate.js';
5
7
  export const SELECTION_TYPE_ENUM = ['replace', 'add', 'subtract', 'intersect'];
6
8
  export const selectionTypeFragment = {
7
9
  type: 'string',
@@ -74,9 +76,12 @@ const selectRectangleSchema = {
74
76
  minimum: 0,
75
77
  default: 0,
76
78
  },
79
+ placement: {
80
+ ...PLACEMENT_SCHEMA,
81
+ description: 'Grounded alternative to left/top/right/bottom: NAME the region (a `placement` resolving to a REGION — relation `inside` / `gap`) and the selection is its resolved, gate-verified bounding box. Wins over the raw edges. Provide THIS or left+top+right+bottom.',
82
+ },
77
83
  selection_type: selectionTypeFragment,
78
84
  },
79
- required: ['left', 'top', 'right', 'bottom'],
80
85
  };
81
86
  const featherSelectionSchema = {
82
87
  type: 'object',
@@ -209,9 +214,12 @@ const magicWandSchema = {
209
214
  description: 'If true, samples color across all visible layers. If false (default), samples the active layer only.',
210
215
  default: false,
211
216
  },
217
+ placement: {
218
+ ...PLACEMENT_SCHEMA,
219
+ description: 'Grounded alternative to x/y: NAME the click point (a `placement` resolving to a POINT — a centroid, extremum, grid intersection) and the wand clicks the resolved, gate-verified point. Wins over the raw x/y. Provide THIS or x + y.',
220
+ },
212
221
  selection_type: selectionTypeFragment,
213
222
  },
214
- required: ['x', 'y'],
215
223
  };
216
224
  const selectEllipseSchema = {
217
225
  type: 'object',
@@ -235,9 +243,12 @@ const selectEllipseSchema = {
235
243
  minimum: 0,
236
244
  default: 0,
237
245
  },
246
+ placement: {
247
+ ...PLACEMENT_SCHEMA,
248
+ description: 'Grounded alternative to left/top/right/bottom: NAME the region (a `placement` resolving to a REGION) and the ellipse is inscribed in its resolved, gate-verified bounding box. Wins over the raw edges. Provide THIS or left+top+right+bottom.',
249
+ },
238
250
  selection_type: selectionTypeFragment,
239
251
  },
240
- required: ['left', 'top', 'right', 'bottom'],
241
252
  };
242
253
  const growSelectionSchema = {
243
254
  type: 'object',
@@ -279,7 +290,7 @@ const selectPolygonSchema = {
279
290
  properties: {
280
291
  points: {
281
292
  type: 'array',
282
- description: 'Polygon vertices in ABSOLUTE document pixels: [{x, y}, ...], minimum 3. (0,0) is top-left. The ring auto-closes (last vertex connects back to the first). You must know the pixel coordinates to aim this — pair with photoshop_inspect (dimensions) / photoshop_get_preview (content). Covers polygonal/freehand/magnetic lasso shapes.',
293
+ description: 'Polygon vertices in ABSOLUTE document pixels: [{x, y}, ...], minimum 3. (0,0) is top-left. The ring auto-closes (last vertex connects back to the first). You must know the pixel coordinates to aim this — pair with ps_inspect (dimensions) / ps_get_preview (content). Covers polygonal/freehand/magnetic lasso shapes.',
283
294
  minItems: 3,
284
295
  items: {
285
296
  type: 'object',
@@ -382,6 +393,30 @@ const loadSelectionFromChannelSchema = {
382
393
  },
383
394
  required: ['channel_name'],
384
395
  };
396
+ const duplicateChannelSchema = {
397
+ type: 'object',
398
+ properties: {
399
+ channel_name: {
400
+ type: 'string',
401
+ description: 'Name of the existing alpha/spot channel to duplicate.',
402
+ },
403
+ new_channel_name: {
404
+ type: 'string',
405
+ description: 'Optional name for the duplicate. Photoshop auto-names it "<source> copy" when omitted.',
406
+ },
407
+ },
408
+ required: ['channel_name'],
409
+ };
410
+ const deleteChannelSchema = {
411
+ type: 'object',
412
+ properties: {
413
+ channel_name: {
414
+ type: 'string',
415
+ description: 'Name of the alpha/spot channel to delete. Component (RGB/CMYK/Lab) channels are refused.',
416
+ },
417
+ },
418
+ required: ['channel_name'],
419
+ };
385
420
  const SELECT_MODES = [
386
421
  'all',
387
422
  'none',
@@ -413,7 +448,8 @@ const SELECT_INPUT_SCHEMA = {
413
448
  'similar: expand the CURRENT selection to ALL similar-colour pixels document-wide (+tolerance, anti_alias). ' +
414
449
  'skin_tones: select skin-coloured pixels (+fuzziness; use_faces=true adds face-aware refinement). ' +
415
450
  'out_of_gamut: select colours outside the printable CMYK gamut (no params). ' +
416
- 'polygon: points [{x,y},...] in ABSOLUTE document pixels (min 3, auto-closes) — covers polygonal/freehand lasso. Coordinate-driven: you must know the pixel positions (use photoshop_inspect / photoshop_get_preview to aim). ' +
451
+ 'polygon: points [{x,y},...] in ABSOLUTE document pixels (min 3, auto-closes) — covers polygonal/freehand lasso. Coordinate-driven: you must know the pixel positions (use ps_inspect / ps_get_preview to aim, or ps_path create_from_placement → load_as_selection for a grounded outline). ' +
452
+ 'rectangle/ellipse/magic_wand also take a grounded `placement` instead of raw coords (region → the bbox; point → the wand click). ' +
417
453
  'rectangle/ellipse/polygon/color_range/luminance_range/magic_wand/skin_tones/out_of_gamut also take selection_type to combine with an existing selection.',
418
454
  },
419
455
  ...selectRectangleSchema.properties,
@@ -422,6 +458,10 @@ const SELECT_INPUT_SCHEMA = {
422
458
  ...magicWandSchema.properties,
423
459
  ...colorPresetSchema.properties,
424
460
  ...selectPolygonSchema.properties,
461
+ placement: {
462
+ ...PLACEMENT_SCHEMA,
463
+ description: 'Grounded coordinates (rectangle/ellipse/magic_wand): NAME anchors + a relation instead of guessing pixels. rectangle/ellipse ← a REGION relation (inside/gap) → the selection bounding box; magic_wand ← a POINT relation (centroid/extremum/grid) → the click. Verified by the objective gate; wins over the raw edges/x-y. See ps_resolve_placement for the vocabulary.',
464
+ },
425
465
  },
426
466
  required: ['mode'],
427
467
  };
@@ -455,7 +495,7 @@ const MODIFY_SELECTION_INPUT_SCHEMA = {
455
495
  },
456
496
  required: ['op'],
457
497
  };
458
- const SELECTION_CHANNEL_OPS = ['save', 'load'];
498
+ const SELECTION_CHANNEL_OPS = ['save', 'load', 'duplicate', 'delete'];
459
499
  const SELECTION_CHANNEL_INPUT_SCHEMA = {
460
500
  type: 'object',
461
501
  properties: {
@@ -463,10 +503,16 @@ const SELECTION_CHANNEL_INPUT_SCHEMA = {
463
503
  type: 'string',
464
504
  enum: [...SELECTION_CHANNEL_OPS],
465
505
  description: 'save: store the current selection to a named Alpha channel (channel_name; overwrites if it exists). ' +
466
- 'load: restore a saved Alpha channel as the selection (channel_name + operation to combine).',
506
+ 'load: restore a saved Alpha channel as the selection (channel_name + operation to combine). ' +
507
+ 'duplicate: copy an existing alpha/spot channel (channel_name) to a new channel (optional new_channel_name; auto-named "<src> copy" otherwise). ' +
508
+ 'delete: remove an alpha/spot channel (channel_name). Refuses to delete component RGB/CMYK/Lab channels.',
467
509
  },
468
510
  ...saveSelectionToChannelSchema.properties,
469
511
  ...loadSelectionFromChannelSchema.properties,
512
+ new_channel_name: {
513
+ type: 'string',
514
+ description: 'duplicate only: name for the new channel. Optional — Photoshop auto-names it "<source> copy" when omitted.',
515
+ },
470
516
  },
471
517
  required: ['op', 'channel_name'],
472
518
  };
@@ -484,12 +530,12 @@ const LAYER_MASK_INPUT_SCHEMA = {
484
530
  },
485
531
  required: ['op'],
486
532
  };
487
- export function createSelectionTools(connection, snippetClient) {
533
+ export function createSelectionTools(connection, snippetClient, client = new OnnxLandmarkDetectionClient()) {
488
534
  return [
489
535
  {
490
536
  tool: {
491
- name: 'photoshop_select',
492
- description: 'Create or modify a selection — choose with `mode`. `all` selects the canvas; `none` deselects; `inverse` inverts the current selection (e.g. select the subject, then inverse to act on the background). `rectangle` (left/top/right/bottom, optional feather_px to avoid hard block-edges in smooth sky). `ellipse` (left/top/right/bottom bounding box + anti_alias — circles/ovals). `color_range` (target red/green/blue + fuzziness — "select all the red / skin tones"). `luminance_range` (highlights/shadows/midtones — foundation for glow / dodge-burn). `magic_wand` (click x/y + tolerance, contiguous). `grow` / `similar` expand the CURRENT selection to similar-colour pixels (adjacent vs document-wide; both honour `tolerance`). The geometric/color/wand modes take selection_type (replace|add|subtract|intersect) to combine with an existing selection and return a rich selection_info bundle — verify it (or photoshop_get_selection_preview) before committing to a mask.',
537
+ name: 'ps_select',
538
+ description: 'Create or modify a selection — choose with `mode`. `all` selects the canvas; `none` deselects; `inverse` inverts the current selection (e.g. select the subject, then inverse to act on the background). `rectangle` (left/top/right/bottom, optional feather_px to avoid hard block-edges in smooth sky). `ellipse` (left/top/right/bottom bounding box + anti_alias — circles/ovals). `color_range` (target red/green/blue + fuzziness — "select all the red / skin tones"). `luminance_range` (highlights/shadows/midtones — foundation for glow / dodge-burn). `magic_wand` (click x/y + tolerance, contiguous). `grow` / `similar` expand the CURRENT selection to similar-colour pixels (adjacent vs document-wide; both honour `tolerance`). rectangle/ellipse/magic_wand also accept a grounded `placement` (NAME a region/point instead of guessing pixels — resolved + gate-verified). The geometric/color/wand modes take selection_type (replace|add|subtract|intersect) to combine with an existing selection and return a rich selection_info bundle — verify it (or ps_get_selection_preview) before committing to a mask.',
493
539
  inputSchema: SELECT_INPUT_SCHEMA,
494
540
  outputSchema: {
495
541
  type: 'object',
@@ -514,6 +560,7 @@ export function createSelectionTools(connection, snippetClient) {
514
560
  sample_all_layers: { type: 'boolean' },
515
561
  preset: { type: 'string' },
516
562
  point_count: { type: 'number' },
563
+ placement: { type: 'object' },
517
564
  selection_info: selectionInfoFragment,
518
565
  },
519
566
  },
@@ -522,11 +569,11 @@ export function createSelectionTools(connection, snippetClient) {
522
569
  idempotentHint: false,
523
570
  },
524
571
  },
525
- handler: async (args) => select(connection, snippetClient, args),
572
+ handler: async (args) => select(connection, snippetClient, client, args),
526
573
  },
527
574
  {
528
575
  tool: {
529
- name: 'photoshop_modify_selection',
576
+ name: 'ps_modify_selection',
530
577
  description: "Modify the CURRENT selection — choose with `op`. `feather` softens by radius_px (use when a selection was made hard, e.g. after select all/inverse, before applying an adjustment). `refine_edge` runs Select-and-Mask's global sliders headlessly (smooth, feather, contrast, shift_edge, edge-detection radius, decontaminate) to clean halos and soft/fuzzy edges (hair) after a rough color-range / magic-wand / subject selection. `expand` / `contract` grow / shrink the selection by `amount` px. `border` replaces the selection with an `amount`-px band around its edge. `smooth` rounds the corners with an `amount`-px radius. `transform` relatively scales (scale_x_percent / scale_y_percent), rotates (rotate_degrees) and/or translates (offset_x / offset_y) the marching ants — pixels are untouched. All require an active selection and return selection_info.",
531
578
  inputSchema: MODIFY_SELECTION_INPUT_SCHEMA,
532
579
  outputSchema: {
@@ -563,7 +610,7 @@ export function createSelectionTools(connection, snippetClient) {
563
610
  },
564
611
  {
565
612
  tool: {
566
- name: 'photoshop_get_selection_preview',
613
+ name: 'ps_get_selection_preview',
567
614
  description: 'Render TWO inline JPEGs so the agent can visually verify what is currently selected: (1) an OVERLAY of the document with a 50% red wash over the selected area (Quick Mask-style — most intuitive); (2) a B/W MASK where black = selected, white = not. Heavier than the selection_info bundle (~2-4s) — call this when the stats look off or before committing a mask. Does NOT modify the source document.',
568
615
  inputSchema: selectionPreviewSchema,
569
616
  outputSchema: {
@@ -586,7 +633,7 @@ export function createSelectionTools(connection, snippetClient) {
586
633
  },
587
634
  {
588
635
  tool: {
589
- name: 'photoshop_layer_mask',
636
+ name: 'ps_layer_mask',
590
637
  description: 'Manage the active layer\'s mask — choose with `op`. `create`: add a layer mask; if a selection is active it reveals the selection and hides the rest (the one-call "mask the placed image to the frame opening" — make the selection first, then create); with no selection, a reveal-all mask; adjustment layers load the current selection into their built-in mask. `delete`: remove the mask (layer pixels preserved). `apply`: DESTRUCTIVE — permanently bake the mask into the pixels (outside-mask pixels lost). Prefer keeping masks non-destructive unless flattening for export. **Don\'t write `Mk Chnl At=Msk` AM scripts in execute_script — this tool already does that.**',
591
638
  inputSchema: LAYER_MASK_INPUT_SCHEMA,
592
639
  outputSchema: {
@@ -610,22 +657,25 @@ export function createSelectionTools(connection, snippetClient) {
610
657
  },
611
658
  {
612
659
  tool: {
613
- name: 'photoshop_selection_channel',
614
- description: 'Persist or restore a selection via a named Alpha channel — choose with `op`. `save`: store the current selection to channel_name (overwrites if it exists) so a complex AI/multi-step/feathered selection can be reloaded without rebuilding (throws if no active selection). `load`: restore a saved channel as the selection, with `operation` (replace|add|subtract|intersect) to combine — reapply one selection across layers.',
660
+ name: 'ps_selection_channel',
661
+ description: "Persist, restore, or manage a named Alpha channel — choose with `op`. `save`: store the current selection to channel_name (overwrites if it exists) so a complex AI/multi-step/feathered selection can be reloaded without rebuilding (throws if no active selection). `load`: restore a saved channel as the selection, with `operation` (replace|add|subtract|intersect) to combine — reapply one selection across layers. `duplicate`: copy an existing alpha/spot channel to a new one (optional new_channel_name). `delete`: remove an alpha/spot channel (won't touch the RGB/CMYK/Lab component channels).",
615
662
  inputSchema: SELECTION_CHANNEL_INPUT_SCHEMA,
616
663
  outputSchema: {
617
664
  type: 'object',
618
665
  properties: {
619
666
  saved: { type: 'boolean' },
620
667
  loaded: { type: 'boolean' },
668
+ duplicated: { type: 'boolean' },
669
+ deleted: { type: 'boolean' },
621
670
  channel_name: { type: 'string' },
671
+ new_channel_name: { type: 'string' },
622
672
  overwritten: {
623
673
  type: 'boolean',
624
674
  description: 'True if an existing channel with the same name was replaced.',
625
675
  },
626
676
  channel_count: {
627
677
  type: 'number',
628
- description: 'Total channels in the document after saving.',
678
+ description: 'Total channels in the document after the op.',
629
679
  },
630
680
  operation: { type: 'string' },
631
681
  selection_info: selectionInfoFragment,
@@ -638,8 +688,138 @@ export function createSelectionTools(connection, snippetClient) {
638
688
  },
639
689
  handler: async (args) => selectionChannel(connection, snippetClient, args),
640
690
  },
691
+ {
692
+ tool: {
693
+ name: 'ps_select_subject',
694
+ description: 'Run Photoshop\'s "Select Subject" (Adobe Sensei). One-call selection of the main subject — person, animal, product, etc. ~2-5s on typical images. Default sample_all_layers=true analyzes the full visible composite, which matches PS 2025 behavior and works around the PS 2026 "active layer only" default that fails opaquely when the active layer is a blurred / adjusted copy. Combines with existing selection via selection_type. Returns selection_info so the agent can verify area / edge complexity; if results look off, call ps_get_selection_preview for a visual. On failure, the error message lists fallbacks (Cloud processing in PS Preferences, manual UI selection).',
695
+ inputSchema: selectSubjectSchema,
696
+ outputSchema: {
697
+ type: 'object',
698
+ properties: {
699
+ selected: { type: 'boolean' },
700
+ method: { type: 'string' },
701
+ strategy_used: {
702
+ type: 'string',
703
+ description: '"dom:selectSubject" (preferred — DOM method, PS handles descriptor internals) or "executeAction:autoCutout" (legacy AM fallback). Telemetry surface: lets us see in the field whether the DOM path needs widening.',
704
+ },
705
+ sample_all_layers: { type: 'boolean' },
706
+ active_layer_temporarily_changed: {
707
+ type: 'boolean',
708
+ description: 'True if we temporarily switched the active layer to the bottom layer during detection (to work around PS 2026 "active layer only" behavior when sample_all_layers=true). Original active layer is restored before return.',
709
+ },
710
+ selection_type: { type: 'string' },
711
+ selection_info: selectionInfoFragment,
712
+ },
713
+ },
714
+ annotations: {
715
+ title: 'Select Subject (Sensei)',
716
+ idempotentHint: true,
717
+ },
718
+ },
719
+ handler: async (args) => selectSubject(connection, snippetClient, args),
720
+ },
721
+ {
722
+ tool: {
723
+ name: 'ps_select_sky',
724
+ description: 'Run Photoshop\'s "Select Sky" (Adobe Sensei, PS 2021+). One-call sky masking for landscape work. Default sample_all_layers=true analyzes the full visible composite. Returns selection_info — high edge_complexity on tricky horizons (foreground objects against sky) is the signal to verify with ps_get_selection_preview before committing.',
725
+ inputSchema: selectSkySchema,
726
+ outputSchema: {
727
+ type: 'object',
728
+ properties: {
729
+ selected: { type: 'boolean' },
730
+ method: { type: 'string' },
731
+ strategy_used: {
732
+ type: 'string',
733
+ description: '"dom:selectSky" (preferred DOM method when exposed) or "executeAction:selectSky" (AM fallback).',
734
+ },
735
+ sample_all_layers: { type: 'boolean' },
736
+ active_layer_temporarily_changed: {
737
+ type: 'boolean',
738
+ description: 'True if active layer was temporarily switched to the bottom layer during detection. Restored before return.',
739
+ },
740
+ selection_type: { type: 'string' },
741
+ selection_info: selectionInfoFragment,
742
+ },
743
+ },
744
+ annotations: {
745
+ title: 'Select Sky (Sensei)',
746
+ idempotentHint: true,
747
+ },
748
+ },
749
+ handler: async (args) => selectSky(connection, snippetClient, args),
750
+ },
641
751
  ];
642
752
  }
753
+ const selectSubjectSchema = {
754
+ type: 'object',
755
+ properties: {
756
+ sample_all_layers: {
757
+ type: 'boolean',
758
+ description: 'If true (default), the model considers all visible layers — matches PS 2025 behavior and the user mental model of "select the subject of this image." If false, considers only the active layer (PS 2026 menu default — but on processed/blurred active layers this often yields "no subject" and an opaque "parameters not valid" error). Override to false only when you specifically want layer-isolated detection.',
759
+ default: true,
760
+ },
761
+ selection_type: selectionTypeFragment,
762
+ },
763
+ };
764
+ const selectSkySchema = {
765
+ type: 'object',
766
+ properties: {
767
+ sample_all_layers: {
768
+ type: 'boolean',
769
+ description: 'If true (default), the sky model considers all visible layers — the correct setting for most workflows. If false, considers only the active layer.',
770
+ default: true,
771
+ },
772
+ selection_type: selectionTypeFragment,
773
+ },
774
+ };
775
+ async function selectSubject(connection, snippetClient, rawArgs) {
776
+ try {
777
+ const args = validateArgs(selectSubjectSchema, rawArgs);
778
+ const sampleAllLayers = args.sample_all_layers ?? true;
779
+ const selectionType = normalizeSelectionType(args.selection_type);
780
+ const script = await snippetClient.build('selectSubject', { sampleAllLayers, selectionType });
781
+ const result = await runScript(connection, script, 120000);
782
+ return {
783
+ content: [{ type: 'text', text: `Select Subject (${selectionType}) complete` }],
784
+ structuredContent: result,
785
+ };
786
+ }
787
+ catch (error) {
788
+ return {
789
+ content: [
790
+ {
791
+ type: 'text',
792
+ text: `Error running Select Subject: ${error instanceof Error ? error.message : String(error)}`,
793
+ },
794
+ ],
795
+ isError: true,
796
+ };
797
+ }
798
+ }
799
+ async function selectSky(connection, snippetClient, rawArgs) {
800
+ try {
801
+ const args = validateArgs(selectSkySchema, rawArgs);
802
+ const sampleAllLayers = args.sample_all_layers ?? true;
803
+ const selectionType = normalizeSelectionType(args.selection_type);
804
+ const script = await snippetClient.build('selectSky', { sampleAllLayers, selectionType });
805
+ const result = await runScript(connection, script, 120000);
806
+ return {
807
+ content: [{ type: 'text', text: `Select Sky (${selectionType}) complete` }],
808
+ structuredContent: result,
809
+ };
810
+ }
811
+ catch (error) {
812
+ return {
813
+ content: [
814
+ {
815
+ type: 'text',
816
+ text: `Error running Select Sky: ${error instanceof Error ? error.message : String(error)}`,
817
+ },
818
+ ],
819
+ isError: true,
820
+ };
821
+ }
822
+ }
643
823
  function unknownDiscriminator(kind, value, allowed) {
644
824
  return {
645
825
  content: [
@@ -651,7 +831,7 @@ function unknownDiscriminator(kind, value, allowed) {
651
831
  isError: true,
652
832
  };
653
833
  }
654
- async function select(connection, snippetClient, rawArgs) {
834
+ async function select(connection, snippetClient, detClient, rawArgs) {
655
835
  const mode = rawArgs.mode;
656
836
  const { mode: _omit, ...rest } = rawArgs;
657
837
  switch (mode) {
@@ -662,15 +842,15 @@ async function select(connection, snippetClient, rawArgs) {
662
842
  case 'inverse':
663
843
  return invertSelection(connection, snippetClient);
664
844
  case 'rectangle':
665
- return selectRectangle(connection, snippetClient, rest);
845
+ return selectRectangle(connection, snippetClient, detClient, rest);
666
846
  case 'ellipse':
667
- return selectEllipse(connection, snippetClient, rest);
847
+ return selectEllipse(connection, snippetClient, detClient, rest);
668
848
  case 'color_range':
669
849
  return selectColorRange(connection, snippetClient, rest);
670
850
  case 'luminance_range':
671
851
  return selectLuminanceRange(connection, snippetClient, rest);
672
852
  case 'magic_wand':
673
- return magicWand(connection, snippetClient, rest);
853
+ return magicWand(connection, snippetClient, detClient, rest);
674
854
  case 'grow':
675
855
  return growSelection(connection, snippetClient, 'grow', rest);
676
856
  case 'similar':
@@ -712,6 +892,10 @@ async function selectionChannel(connection, snippetClient, rawArgs) {
712
892
  return saveSelectionToChannel(connection, snippetClient, rest);
713
893
  case 'load':
714
894
  return loadSelectionFromChannel(connection, snippetClient, rest);
895
+ case 'duplicate':
896
+ return duplicateChannel(connection, snippetClient, rest);
897
+ case 'delete':
898
+ return deleteChannel(connection, snippetClient, rest);
715
899
  default:
716
900
  return unknownDiscriminator('selection_channel op', op, SELECTION_CHANNEL_OPS);
717
901
  }
@@ -744,13 +928,45 @@ function describeMaskOutcome(result) {
744
928
  }
745
929
  return 'No mask change — active layer already has a mask and no selection was active';
746
930
  }
747
- async function selectRectangle(connection, snippetClient, rawArgs) {
931
+ async function resolveSelectionBox(connection, detClient, args, mode, label) {
932
+ if (args.placement) {
933
+ const rp = await resolveExpectedPlacement(connection, detClient, args.placement, 'region', label);
934
+ return {
935
+ bounds: rp.bbox,
936
+ placement: { target: 'region', gate: { pass: true }, anchors: rp.anchors, bbox: rp.bbox },
937
+ note: ` — region ${rp.summary} via placement (gate PASS)`,
938
+ };
939
+ }
940
+ const left = args.left;
941
+ const top = args.top;
942
+ const right = args.right;
943
+ const bottom = args.bottom;
944
+ if (left === undefined || top === undefined || right === undefined || bottom === undefined) {
945
+ throw new Error(`${mode} needs left+top+right+bottom, or a placement resolving to a region.`);
946
+ }
947
+ return { bounds: { left, top, right, bottom }, note: '' };
948
+ }
949
+ async function resolveSelectionPoint(connection, detClient, args, label) {
950
+ if (args.placement) {
951
+ const rp = await resolveExpectedPlacement(connection, detClient, args.placement, 'point', label);
952
+ return {
953
+ point: rp.point,
954
+ placement: { target: 'point', gate: { pass: true }, anchors: rp.anchors, point: rp.point },
955
+ note: ` — point ${rp.summary} via placement (gate PASS)`,
956
+ };
957
+ }
958
+ const x = args.x;
959
+ const y = args.y;
960
+ if (x === undefined || y === undefined) {
961
+ throw new Error('magic_wand needs x+y, or a placement resolving to a point.');
962
+ }
963
+ return { point: { x, y }, note: '' };
964
+ }
965
+ async function selectRectangle(connection, snippetClient, detClient, rawArgs) {
748
966
  try {
749
967
  const args = validateArgs(selectRectangleSchema, rawArgs);
750
- const left = args.left;
751
- const top = args.top;
752
- const right = args.right;
753
- const bottom = args.bottom;
968
+ const box = await resolveSelectionBox(connection, detClient, args, 'rectangle', 'rectangle selection');
969
+ const { left, top, right, bottom } = box.bounds;
754
970
  const featherPx = args.feather_px ?? 0;
755
971
  const selectionType = normalizeSelectionType(args.selection_type);
756
972
  const script = await snippetClient.build('selectRectangle', {
@@ -761,13 +977,15 @@ async function selectRectangle(connection, snippetClient, rawArgs) {
761
977
  featherPx,
762
978
  selectionType,
763
979
  });
764
- const result = await runScript(connection, script);
980
+ const result = (await runScript(connection, script));
981
+ if (box.placement)
982
+ result.placement = box.placement;
765
983
  const featherNote = featherPx > 0 ? `, feathered ${featherPx}px` : '';
766
984
  return {
767
985
  content: [
768
986
  {
769
987
  type: 'text',
770
- text: `Rectangular selection (${selectionType}) (${left}, ${top}) to (${right}, ${bottom})${featherNote}`,
988
+ text: `Rectangular selection (${selectionType}) (${left}, ${top}) to (${right}, ${bottom})${featherNote}${box.note}`,
771
989
  },
772
990
  ],
773
991
  structuredContent: result,
@@ -785,13 +1003,11 @@ async function selectRectangle(connection, snippetClient, rawArgs) {
785
1003
  };
786
1004
  }
787
1005
  }
788
- async function selectEllipse(connection, snippetClient, rawArgs) {
1006
+ async function selectEllipse(connection, snippetClient, detClient, rawArgs) {
789
1007
  try {
790
1008
  const args = validateArgs(selectEllipseSchema, rawArgs);
791
- const left = args.left;
792
- const top = args.top;
793
- const right = args.right;
794
- const bottom = args.bottom;
1009
+ const box = await resolveSelectionBox(connection, detClient, args, 'ellipse', 'ellipse selection');
1010
+ const { left, top, right, bottom } = box.bounds;
795
1011
  const featherPx = args.feather_px ?? 0;
796
1012
  const antiAlias = args.anti_alias ?? true;
797
1013
  const selectionType = normalizeSelectionType(args.selection_type);
@@ -804,13 +1020,15 @@ async function selectEllipse(connection, snippetClient, rawArgs) {
804
1020
  antiAlias,
805
1021
  selectionType,
806
1022
  });
807
- const result = await runScript(connection, script);
1023
+ const result = (await runScript(connection, script));
1024
+ if (box.placement)
1025
+ result.placement = box.placement;
808
1026
  const featherNote = featherPx > 0 ? `, feathered ${featherPx}px` : '';
809
1027
  return {
810
1028
  content: [
811
1029
  {
812
1030
  type: 'text',
813
- text: `Elliptical selection (${selectionType}) (${left}, ${top}) to (${right}, ${bottom})${featherNote}`,
1031
+ text: `Elliptical selection (${selectionType}) (${left}, ${top}) to (${right}, ${bottom})${featherNote}${box.note}`,
814
1032
  },
815
1033
  ],
816
1034
  structuredContent: result,
@@ -1118,11 +1336,11 @@ async function selectColorRange(connection, snippetClient, rawArgs) {
1118
1336
  };
1119
1337
  }
1120
1338
  }
1121
- async function magicWand(connection, snippetClient, rawArgs) {
1339
+ async function magicWand(connection, snippetClient, detClient, rawArgs) {
1122
1340
  try {
1123
1341
  const args = validateArgs(magicWandSchema, rawArgs);
1124
- const x = args.x;
1125
- const y = args.y;
1342
+ const pt = await resolveSelectionPoint(connection, detClient, args, 'magic-wand click');
1343
+ const { x, y } = pt.point;
1126
1344
  const tolerance = args.tolerance ?? 32;
1127
1345
  const contiguous = args.contiguous ?? true;
1128
1346
  const antiAlias = args.anti_alias ?? true;
@@ -1137,12 +1355,14 @@ async function magicWand(connection, snippetClient, rawArgs) {
1137
1355
  sampleAllLayers,
1138
1356
  selectionType,
1139
1357
  });
1140
- const result = await runScript(connection, script);
1358
+ const result = (await runScript(connection, script));
1359
+ if (pt.placement)
1360
+ result.placement = pt.placement;
1141
1361
  return {
1142
1362
  content: [
1143
1363
  {
1144
1364
  type: 'text',
1145
- text: `Magic wand @ (${x},${y}) tol=${tolerance} (${selectionType})`,
1365
+ text: `Magic wand @ (${x},${y}) tol=${tolerance} (${selectionType})${pt.note}`,
1146
1366
  },
1147
1367
  ],
1148
1368
  structuredContent: result,
@@ -1463,3 +1683,62 @@ async function loadSelectionFromChannel(connection, snippetClient, rawArgs) {
1463
1683
  };
1464
1684
  }
1465
1685
  }
1686
+ async function duplicateChannel(connection, snippetClient, rawArgs) {
1687
+ try {
1688
+ const args = validateArgs(duplicateChannelSchema, rawArgs);
1689
+ const channelName = args.channel_name;
1690
+ const params = { channelName };
1691
+ if (args.new_channel_name !== undefined)
1692
+ params.newName = args.new_channel_name;
1693
+ const script = await snippetClient.build('duplicateChannel', params);
1694
+ const result = (await runScript(connection, script));
1695
+ return {
1696
+ content: [
1697
+ {
1698
+ type: 'text',
1699
+ text: `Channel "${channelName}" duplicated to "${String(result.new_channel_name ?? '')}".`,
1700
+ },
1701
+ ],
1702
+ structuredContent: result,
1703
+ };
1704
+ }
1705
+ catch (error) {
1706
+ return {
1707
+ content: [
1708
+ {
1709
+ type: 'text',
1710
+ text: `Error duplicating channel: ${error instanceof Error ? error.message : String(error)}`,
1711
+ },
1712
+ ],
1713
+ isError: true,
1714
+ };
1715
+ }
1716
+ }
1717
+ async function deleteChannel(connection, snippetClient, rawArgs) {
1718
+ try {
1719
+ const args = validateArgs(deleteChannelSchema, rawArgs);
1720
+ const channelName = args.channel_name;
1721
+ const script = await snippetClient.build('deleteChannel', { channelName });
1722
+ const result = (await runScript(connection, script));
1723
+ return {
1724
+ content: [
1725
+ {
1726
+ type: 'text',
1727
+ text: `Channel "${channelName}" deleted.`,
1728
+ },
1729
+ ],
1730
+ structuredContent: result,
1731
+ };
1732
+ }
1733
+ catch (error) {
1734
+ return {
1735
+ content: [
1736
+ {
1737
+ type: 'text',
1738
+ text: `Error deleting channel: ${error instanceof Error ? error.message : String(error)}`,
1739
+ },
1740
+ ],
1741
+ isError: true,
1742
+ };
1743
+ }
1744
+ }