@dickpy/dsh-oil-slide 0.0.0-stage → 0.2.7

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 (97) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +89 -2
  3. package/bundled-assets/brand/empty-deck-cobalt.webp +0 -0
  4. package/bundled-assets/brand/oil-slide-mark-512.png +0 -0
  5. package/bundled-assets/skill/LICENSE +21 -0
  6. package/bundled-assets/skill/README.md +61 -0
  7. package/bundled-assets/skill/SKILL.md +185 -0
  8. package/bundled-assets/skill/references/art-directions.md +99 -0
  9. package/bundled-assets/skill/references/brand-and-canvas.md +72 -0
  10. package/bundled-assets/skill/references/design-baseline.txt +1 -0
  11. package/bundled-assets/skill/references/prompt-compiler.md +99 -0
  12. package/bundled-assets/skill/references/restore-and-pptx.md +178 -0
  13. package/bundled-assets/skill/references/staged-pptx.md +71 -0
  14. package/bundled-assets/skill/scripts/_runtime_utils.py +351 -0
  15. package/bundled-assets/skill/scripts/asset_sheet.py +528 -0
  16. package/bundled-assets/skill/scripts/brand_ref.py +776 -0
  17. package/bundled-assets/skill/scripts/crop_asset.py +1709 -0
  18. package/bundled-assets/skill/scripts/deck_shell.py +2322 -0
  19. package/bundled-assets/skill/scripts/export_images.py +280 -0
  20. package/bundled-assets/skill/scripts/extract_pptx.py +360 -0
  21. package/bundled-assets/skill/scripts/extract_slide_dom.js +1640 -0
  22. package/bundled-assets/skill/scripts/html_to_pptx.py +4042 -0
  23. package/bundled-assets/skill/scripts/measure_slide_layout.py +952 -0
  24. package/bundled-assets/skill/scripts/oiloil-connect.mjs +1493 -0
  25. package/bundled-assets/skill/scripts/oiloil-image.mjs +492 -0
  26. package/bundled-assets/skill/scripts/prepare_plate.py +412 -0
  27. package/bundled-assets/skill/scripts/render_gradient.py +258 -0
  28. package/bundled-assets/skill/scripts/slide_brand.py +111 -0
  29. package/bundled-assets/skill/scripts/slide_incremental.py +122 -0
  30. package/bundled-assets/skill/scripts/slide_workflow.py +711 -0
  31. package/bundled-assets/skill/scripts/verify_deck.py +3483 -0
  32. package/bundled-assets/skill/vendor/README.md +4 -0
  33. package/bundled-assets/skill/vendor/codex-ppt/LICENSE +21 -0
  34. package/bundled-assets/skill/vendor/codex-ppt/assemble_ppt.py +435 -0
  35. package/bundled-assets/skill/vendor/codex-ppt/codex_ppt_runtime.py +284 -0
  36. package/bundled-assets/skill/vendor/codex-ppt/image_gen.py +972 -0
  37. package/bundled-assets/skill/vendor/codex-ppt/image_providers/__init__.py +6 -0
  38. package/bundled-assets/skill/vendor/codex-ppt/image_providers/atlascloud.py +222 -0
  39. package/bundled-assets/skill/vendor/codex-ppt/image_providers/base.py +32 -0
  40. package/bundled-assets/skill/vendor/codex-ppt/image_providers/factory.py +21 -0
  41. package/bundled-assets/skill/vendor/codex-ppt/image_providers/openai_compatible.py +238 -0
  42. package/bundled-assets/skill/vendor/codex-ppt/requirements.txt +5 -0
  43. package/bundled-assets/skill/vendor/codex-ppt/styles//345/205/232/346/224/277/347/272/242/351/243/216/346/240/274.md +98 -0
  44. package/bundled-assets/skill/vendor/codex-ppt/styles//345/210/233/346/204/217/346/235/202/345/277/227/351/243/216.md +72 -0
  45. package/bundled-assets/skill/vendor/codex-ppt/styles//345/244/215/345/217/244/346/211/201/345/271/263/346/217/222/347/224/273/351/243/216.md +72 -0
  46. package/bundled-assets/skill/vendor/codex-ppt/styles//346/211/213/347/273/230/346/212/200/346/234/257/350/247/243/351/207/212/351/243/216.md +86 -0
  47. package/bundled-assets/skill/vendor/codex-ppt/styles//346/211/213/347/273/230/347/231/275/346/235/277/351/243/216.md +72 -0
  48. package/bundled-assets/skill/vendor/codex-ppt/styles//346/225/231/345/255/246/350/257/276/344/273/266/351/243/216.md +107 -0
  49. package/bundled-assets/skill/vendor/codex-ppt/styles//346/225/260/346/215/256/344/273/252/350/241/250/347/233/230/351/243/216.md +73 -0
  50. package/bundled-assets/skill/vendor/codex-ppt/styles//346/270/205/347/210/275/344/270/223/344/270/232/351/243/216.md +87 -0
  51. package/bundled-assets/skill/vendor/codex-ppt/styles//346/270/251/346/232/226/346/211/213/345/267/245/351/243/216.md +72 -0
  52. package/bundled-assets/skill/vendor/codex-ppt/styles//347/224/265/345/255/220/345/242/250/346/260/264/346/235/202/345/277/227/351/243/216.md +86 -0
  53. package/bundled-assets/skill/vendor/codex-ppt/styles//347/247/221/347/240/224/347/255/224/350/276/251/351/243/216.md +138 -0
  54. package/bundled-assets/skill/vendor/codex-ppt/styles//351/272/246/350/202/257/351/224/241/351/243/216/346/240/274.md +119 -0
  55. package/bundled-assets/skill/vendor/image-to-editable-ppt/LICENSE +21 -0
  56. package/bundled-assets/skill/vendor/image-to-editable-ppt/SKILL.md +171 -0
  57. package/bundled-assets/skill/vendor/image-to-editable-ppt/agents/openai.yaml +4 -0
  58. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/__init__.py +1 -0
  59. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/cli.py +25 -0
  60. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/__init__.py +1 -0
  61. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/_input_normalization.py +355 -0
  62. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/_page_artifacts.py +132 -0
  63. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/build_pptx_from_manifest.py +1029 -0
  64. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/configure_image_backend.py +52 -0
  65. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/deck_run_state.py +214 -0
  66. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/deck_text_hints.py +179 -0
  67. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/finalize_deck_run.py +96 -0
  68. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/formula_renderer.py +254 -0
  69. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/image_gen.py +206 -0
  70. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/main.py +795 -0
  71. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/make_page_contact_sheet.py +28 -0
  72. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/native_tables.py +140 -0
  73. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/paddle_text_hints.py +212 -0
  74. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/page_job_status.py +54 -0
  75. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/page_text_metrics.py +334 -0
  76. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/path_geometry.py +174 -0
  77. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/prepare_deck_run.py +209 -0
  78. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/process_asset_sheet.py +104 -0
  79. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/record_imagegen_result.py +118 -0
  80. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/record_page_dispatch.py +83 -0
  81. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/record_page_result.py +130 -0
  82. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/remove_chroma_key.py +441 -0
  83. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/reset_page_job.py +74 -0
  84. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/runtime_env.py +283 -0
  85. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/split_alpha_components.py +323 -0
  86. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/text_hints.py +309 -0
  87. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/validate_pptx.py +873 -0
  88. package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/pyproject.toml +29 -0
  89. package/bundled-assets/skill/vendor/image-to-editable-ppt/prompts/page-worker.md +47 -0
  90. package/bundled-assets/skill/vendor/image-to-editable-ppt/references/cli-helper.md +282 -0
  91. package/bundled-assets/skill/vendor/image-to-editable-ppt/references/manifest-schema.md +423 -0
  92. package/bundled-assets/skill/vendor/image-to-editable-ppt/references/page-decision-tree.md +301 -0
  93. package/bundled-assets/skill/vendor/image-to-editable-ppt/scripts/build-page-worker-prompt.py +134 -0
  94. package/cordis.patch.yml +3 -0
  95. package/lib/client.js +11282 -0
  96. package/lib/index.js +2638 -0
  97. package/package.json +140 -4
@@ -0,0 +1,441 @@
1
+ #!/usr/bin/env python3
2
+ """Remove a solid chroma-key background from an image-to-editable-ppt slide image.
3
+
4
+ This helper supports the CLI/API transparent fallback workflow: generate an
5
+ image on a flat key color, then convert that key color to alpha.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import argparse
11
+ from io import BytesIO
12
+ from pathlib import Path
13
+ import re
14
+ from statistics import median
15
+ import sys
16
+ from typing import Tuple
17
+
18
+
19
+ Color = Tuple[int, int, int]
20
+ KEY_DOMINANCE_THRESHOLD = 16.0
21
+ ALPHA_NOISE_FLOOR = 8
22
+
23
+
24
+ def _die(message: str, code: int = 1) -> None:
25
+ print(f"Error: {message}", file=sys.stderr)
26
+ raise SystemExit(code)
27
+
28
+
29
+ def _dependency_hint(package: str) -> str:
30
+ python = sys.executable
31
+ install_hint = "`pipx install --force --editable <path-to-image-to-editable-ppt>/cli`"
32
+ return (
33
+ "Install image-to-editable-ppt with pipx so CLI dependencies are installed, for example "
34
+ f"{install_hint}, "
35
+ f"or install {package} directly with `{python} -m pip install {package}`."
36
+ )
37
+
38
+
39
+ def _load_pillow():
40
+ try:
41
+ from PIL import Image, ImageFilter
42
+ except ImportError:
43
+ _die(f"Pillow is required for chroma-key removal. {_dependency_hint('pillow')}")
44
+ return Image, ImageFilter
45
+
46
+
47
+ def _parse_key_color(raw: str) -> Color:
48
+ value = raw.strip()
49
+ match = re.fullmatch(r"#?([0-9a-fA-F]{6})", value)
50
+ if not match:
51
+ _die("key color must be a hex RGB value like #00ff00.")
52
+ hex_value = match.group(1)
53
+ return (
54
+ int(hex_value[0:2], 16),
55
+ int(hex_value[2:4], 16),
56
+ int(hex_value[4:6], 16),
57
+ )
58
+
59
+
60
+ def _validate_args(args: argparse.Namespace) -> None:
61
+ if args.tolerance < 0 or args.tolerance > 255:
62
+ _die("--tolerance must be between 0 and 255.")
63
+ if args.transparent_threshold < 0 or args.transparent_threshold > 255:
64
+ _die("--transparent-threshold must be between 0 and 255.")
65
+ if args.opaque_threshold < 0 or args.opaque_threshold > 255:
66
+ _die("--opaque-threshold must be between 0 and 255.")
67
+ if args.soft_matte and args.transparent_threshold >= args.opaque_threshold:
68
+ _die("--transparent-threshold must be lower than --opaque-threshold.")
69
+ if args.edge_feather < 0 or args.edge_feather > 64:
70
+ _die("--edge-feather must be between 0 and 64.")
71
+ if args.edge_contract < 0 or args.edge_contract > 16:
72
+ _die("--edge-contract must be between 0 and 16.")
73
+
74
+ src = Path(args.input)
75
+ if not src.exists():
76
+ _die(f"Input image not found: {src}")
77
+
78
+ out = Path(args.out)
79
+ if out.exists() and not args.force:
80
+ _die(f"Output already exists: {out} (use --force to overwrite)")
81
+
82
+ if out.suffix.lower() not in {".png", ".webp"}:
83
+ _die("--out must end in .png or .webp so the alpha channel is preserved.")
84
+
85
+
86
+ def _channel_distance(a: Color, b: Color) -> int:
87
+ return max(abs(a[0] - b[0]), abs(a[1] - b[1]), abs(a[2] - b[2]))
88
+
89
+
90
+ def _clamp_channel(value: float) -> int:
91
+ return max(0, min(255, int(round(value))))
92
+
93
+
94
+ def _smoothstep(value: float) -> float:
95
+ value = max(0.0, min(1.0, value))
96
+ return value * value * (3.0 - 2.0 * value)
97
+
98
+
99
+ def _soft_alpha(distance: int, transparent_threshold: float, opaque_threshold: float) -> int:
100
+ if distance <= transparent_threshold:
101
+ return 0
102
+ if distance >= opaque_threshold:
103
+ return 255
104
+ ratio = (float(distance) - transparent_threshold) / (
105
+ opaque_threshold - transparent_threshold
106
+ )
107
+ return _clamp_channel(255.0 * _smoothstep(ratio))
108
+
109
+
110
+ def _dominance_alpha(rgb: Color, key: Color) -> int:
111
+ spill_channels = _spill_channels(key)
112
+ if not spill_channels:
113
+ return 255
114
+
115
+ channels = [float(value) for value in rgb]
116
+ non_spill = [idx for idx in range(3) if idx not in spill_channels]
117
+ key_strength = (
118
+ min(channels[idx] for idx in spill_channels)
119
+ if len(spill_channels) > 1
120
+ else channels[spill_channels[0]]
121
+ )
122
+ non_key_strength = max((channels[idx] for idx in non_spill), default=0.0)
123
+ dominance = key_strength - non_key_strength
124
+ if dominance <= 0:
125
+ return 255
126
+
127
+ denominator = max(1.0, float(max(key)) - non_key_strength)
128
+ alpha = 1.0 - min(1.0, dominance / denominator)
129
+ return _clamp_channel(alpha * 255.0)
130
+
131
+
132
+ def _spill_channels(key: Color) -> list[int]:
133
+ key_max = max(key)
134
+ if key_max < 128:
135
+ return []
136
+ return [idx for idx, value in enumerate(key) if value >= key_max - 16 and value >= 128]
137
+
138
+
139
+ def _key_channel_dominance(rgb: Color, key: Color) -> float:
140
+ spill_channels = _spill_channels(key)
141
+ if not spill_channels:
142
+ return 0.0
143
+
144
+ channels = [float(value) for value in rgb]
145
+ non_spill = [idx for idx in range(3) if idx not in spill_channels]
146
+ key_strength = (
147
+ min(channels[idx] for idx in spill_channels)
148
+ if len(spill_channels) > 1
149
+ else channels[spill_channels[0]]
150
+ )
151
+ non_key_strength = max((channels[idx] for idx in non_spill), default=0.0)
152
+ return key_strength - non_key_strength
153
+
154
+
155
+ def _looks_key_colored(rgb: Color, key: Color, distance: int) -> bool:
156
+ if distance <= 32:
157
+ return True
158
+
159
+ spill_channels = _spill_channels(key)
160
+ if not spill_channels:
161
+ return True
162
+
163
+ return _key_channel_dominance(rgb, key) >= KEY_DOMINANCE_THRESHOLD
164
+
165
+
166
+ def _cleanup_spill(rgb: Color, key: Color, alpha: int = 255) -> Color:
167
+ if alpha >= 252:
168
+ return rgb
169
+
170
+ spill_channels = _spill_channels(key)
171
+ if not spill_channels:
172
+ return rgb
173
+
174
+ channels = [float(value) for value in rgb]
175
+ non_spill = [idx for idx in range(3) if idx not in spill_channels]
176
+ if non_spill:
177
+ anchor = max(channels[idx] for idx in non_spill)
178
+ cap = max(0.0, anchor - 1.0)
179
+ for idx in spill_channels:
180
+ if channels[idx] > cap:
181
+ channels[idx] = cap
182
+
183
+ return (
184
+ _clamp_channel(channels[0]),
185
+ _clamp_channel(channels[1]),
186
+ _clamp_channel(channels[2]),
187
+ )
188
+
189
+
190
+ def _apply_alpha_to_image(
191
+ image,
192
+ *,
193
+ key: Color,
194
+ tolerance: int,
195
+ spill_cleanup: bool,
196
+ soft_matte: bool,
197
+ transparent_threshold: float,
198
+ opaque_threshold: float,
199
+ ) -> int:
200
+ pixels = image.load()
201
+ width, height = image.size
202
+ transparent = 0
203
+
204
+ for y in range(height):
205
+ for x in range(width):
206
+ red, green, blue, alpha = pixels[x, y]
207
+ rgb = (red, green, blue)
208
+ distance = _channel_distance(rgb, key)
209
+ key_like = _looks_key_colored(rgb, key, distance)
210
+ output_alpha = (
211
+ min(
212
+ _soft_alpha(distance, transparent_threshold, opaque_threshold),
213
+ _dominance_alpha(rgb, key),
214
+ )
215
+ if soft_matte and key_like
216
+ else (0 if distance <= tolerance else 255)
217
+ )
218
+ output_alpha = int(round(output_alpha * (alpha / 255.0)))
219
+ if 0 < output_alpha <= ALPHA_NOISE_FLOOR:
220
+ output_alpha = 0
221
+
222
+ if output_alpha == 0:
223
+ pixels[x, y] = (0, 0, 0, 0)
224
+ transparent += 1
225
+ continue
226
+
227
+ if spill_cleanup and key_like:
228
+ red, green, blue = _cleanup_spill(rgb, key, output_alpha)
229
+ pixels[x, y] = (red, green, blue, output_alpha)
230
+
231
+ return transparent
232
+
233
+
234
+ def _contract_alpha(image, pixels: int):
235
+ if pixels == 0:
236
+ return image
237
+
238
+ _, ImageFilter = _load_pillow()
239
+ alpha = image.getchannel("A")
240
+ for _ in range(pixels):
241
+ alpha = alpha.filter(ImageFilter.MinFilter(3))
242
+ image.putalpha(alpha)
243
+ return image
244
+
245
+
246
+ def _apply_edge_feather(image, radius: float):
247
+ if radius == 0:
248
+ return image
249
+
250
+ _, ImageFilter = _load_pillow()
251
+ alpha = image.getchannel("A")
252
+ alpha = alpha.filter(ImageFilter.GaussianBlur(radius=radius))
253
+ image.putalpha(alpha)
254
+ return image
255
+
256
+
257
+ def _encode_image(image, output_format: str) -> bytes:
258
+ out = BytesIO()
259
+ image.save(out, format=output_format.upper())
260
+ return out.getvalue()
261
+
262
+
263
+ def _alpha_counts(image) -> tuple[int, int, int]:
264
+ pixels = image.load()
265
+ width, height = image.size
266
+ total = 0
267
+ transparent = 0
268
+ partial = 0
269
+
270
+ for y in range(height):
271
+ for x in range(width):
272
+ alpha = pixels[x, y][3]
273
+ total += 1
274
+ if alpha == 0:
275
+ transparent += 1
276
+ elif alpha < 255:
277
+ partial += 1
278
+
279
+ return total, transparent, partial
280
+
281
+
282
+ def _sample_border_key(image, mode: str) -> Color:
283
+ width, height = image.size
284
+ pixels = image.load()
285
+ samples: list[Color] = []
286
+
287
+ if mode == "corners":
288
+ patch = max(1, min(width, height, 12))
289
+ boxes = [
290
+ (0, 0, patch, patch),
291
+ (width - patch, 0, width, patch),
292
+ (0, height - patch, patch, height),
293
+ (width - patch, height - patch, width, height),
294
+ ]
295
+ for left, top, right, bottom in boxes:
296
+ for y in range(top, bottom):
297
+ for x in range(left, right):
298
+ red, green, blue = pixels[x, y][:3]
299
+ samples.append((red, green, blue))
300
+ else:
301
+ band = max(1, min(width, height, 6))
302
+ step = max(1, min(width, height) // 256)
303
+ for x in range(0, width, step):
304
+ for y in range(band):
305
+ red, green, blue = pixels[x, y][:3]
306
+ samples.append((red, green, blue))
307
+ red, green, blue = pixels[x, height - 1 - y][:3]
308
+ samples.append((red, green, blue))
309
+ for y in range(0, height, step):
310
+ for x in range(band):
311
+ red, green, blue = pixels[x, y][:3]
312
+ samples.append((red, green, blue))
313
+ red, green, blue = pixels[width - 1 - x, y][:3]
314
+ samples.append((red, green, blue))
315
+
316
+ if not samples:
317
+ _die("Could not sample background key color from image border.")
318
+
319
+ return (
320
+ int(round(median(sample[0] for sample in samples))),
321
+ int(round(median(sample[1] for sample in samples))),
322
+ int(round(median(sample[2] for sample in samples))),
323
+ )
324
+
325
+
326
+ def _remove_chroma_key(args: argparse.Namespace) -> None:
327
+ Image, _ = _load_pillow()
328
+ src = Path(args.input)
329
+ out = Path(args.out)
330
+
331
+ with Image.open(src) as image:
332
+ rgba = image.convert("RGBA")
333
+ key = (
334
+ _sample_border_key(rgba, args.auto_key)
335
+ if args.auto_key != "none"
336
+ else _parse_key_color(args.key_color)
337
+ )
338
+
339
+ transparent = _apply_alpha_to_image(
340
+ rgba,
341
+ key=key,
342
+ tolerance=args.tolerance,
343
+ spill_cleanup=args.spill_cleanup,
344
+ soft_matte=args.soft_matte,
345
+ transparent_threshold=args.transparent_threshold,
346
+ opaque_threshold=args.opaque_threshold,
347
+ )
348
+ rgba = _contract_alpha(rgba, args.edge_contract)
349
+ rgba = _apply_edge_feather(rgba, args.edge_feather)
350
+
351
+ total, transparent_after, partial_after = _alpha_counts(rgba)
352
+
353
+ out.parent.mkdir(parents=True, exist_ok=True)
354
+ output_format = "PNG" if out.suffix.lower() == ".png" else "WEBP"
355
+ out.write_bytes(_encode_image(rgba, output_format))
356
+
357
+ print(f"Wrote {out}")
358
+ print(f"Key color: #{key[0]:02x}{key[1]:02x}{key[2]:02x}")
359
+ print(f"Transparent pixels: {transparent_after}/{total}")
360
+ print(f"Partially transparent pixels: {partial_after}/{total}")
361
+ if transparent == 0:
362
+ print("Warning: no pixels matched the key color before feathering.", file=sys.stderr)
363
+
364
+
365
+ def _build_parser() -> argparse.ArgumentParser:
366
+ parser = argparse.ArgumentParser(
367
+ description="Remove a solid chroma-key background and write an image with alpha."
368
+ )
369
+ parser.add_argument("--input", required=True, help="Input image path.")
370
+ parser.add_argument("--out", required=True, help="Output .png or .webp path.")
371
+ parser.add_argument(
372
+ "--key-color",
373
+ default="#00ff00",
374
+ help="Hex RGB key color to remove, for example #00ff00.",
375
+ )
376
+ parser.add_argument(
377
+ "--tolerance",
378
+ type=int,
379
+ default=12,
380
+ help="Hard-key per-channel tolerance for matching the key color, 0-255.",
381
+ )
382
+ parser.add_argument(
383
+ "--auto-key",
384
+ choices=["none", "corners", "border"],
385
+ default="none",
386
+ help="Sample the key color from image corners or border instead of --key-color.",
387
+ )
388
+ parser.add_argument(
389
+ "--soft-matte",
390
+ action="store_true",
391
+ help="Use a smooth alpha ramp between transparent and opaque thresholds.",
392
+ )
393
+ parser.add_argument(
394
+ "--transparent-threshold",
395
+ type=float,
396
+ default=12.0,
397
+ help="Soft-matte distance at or below which pixels become fully transparent.",
398
+ )
399
+ parser.add_argument(
400
+ "--opaque-threshold",
401
+ type=float,
402
+ default=96.0,
403
+ help="Soft-matte distance at or above which pixels become fully opaque.",
404
+ )
405
+ parser.add_argument(
406
+ "--edge-feather",
407
+ type=float,
408
+ default=0.0,
409
+ help="Optional alpha blur radius for softened edges, 0-64.",
410
+ )
411
+ parser.add_argument(
412
+ "--edge-contract",
413
+ type=int,
414
+ default=0,
415
+ help="Shrink the visible alpha matte by this many pixels before feathering.",
416
+ )
417
+ parser.add_argument(
418
+ "--spill-cleanup",
419
+ dest="spill_cleanup",
420
+ action="store_true",
421
+ help="Reduce obvious key-color spill on opaque pixels.",
422
+ )
423
+ parser.add_argument(
424
+ "--despill",
425
+ dest="spill_cleanup",
426
+ action="store_true",
427
+ help="Alias for --spill-cleanup; decontaminate key-color edge spill.",
428
+ )
429
+ parser.add_argument("--force", action="store_true", help="Overwrite an existing output file.")
430
+ return parser
431
+
432
+
433
+ def main() -> None:
434
+ parser = _build_parser()
435
+ args = parser.parse_args()
436
+ _validate_args(args)
437
+ _remove_chroma_key(args)
438
+
439
+
440
+ if __name__ == "__main__":
441
+ main()
@@ -0,0 +1,74 @@
1
+ #!/usr/bin/env python3
2
+ """Reset an inactive or explicitly reopened page back to pending so it can be re-dispatched."""
3
+ import argparse
4
+ import json
5
+
6
+ from deck_run_state import (
7
+ find_page,
8
+ load_jobs,
9
+ now_iso,
10
+ run_dir_from_target,
11
+ save_jobs,
12
+ update_jobs_run_status,
13
+ )
14
+
15
+
16
+ def main():
17
+ parser = argparse.ArgumentParser(
18
+ description="Reset a dispatched or recorded page back to pending for re-dispatch."
19
+ )
20
+ parser.add_argument("run", help="Run directory or deck_manifest.json")
21
+ parser.add_argument("--page", required=True, help="page_001 or 1")
22
+ parser.add_argument("--agent-id", help="Required for dispatched pages; must match the recorded worker id.")
23
+ parser.add_argument(
24
+ "--confirm-lost",
25
+ action="store_true",
26
+ help="Required for dispatched pages. Confirms the original worker is no longer active or has been explicitly cancelled.",
27
+ )
28
+ args = parser.parse_args()
29
+
30
+ run_dir = run_dir_from_target(args.run)
31
+ jobs = load_jobs(run_dir)
32
+ page = find_page(jobs, args.page)
33
+ status = page.get("status")
34
+ if status not in {"dispatched", "recorded"}:
35
+ raise SystemExit(
36
+ f"{page['page_id']} cannot be reset from status {status}; "
37
+ "reset only applies to dispatched or recorded pages"
38
+ )
39
+ if status == "dispatched":
40
+ dispatch = page.get("dispatch") or {}
41
+ expected_agent_id = dispatch.get("agent_id")
42
+ if not args.confirm_lost:
43
+ raise SystemExit(
44
+ f"{page['page_id']} is still dispatched. Do not reset active workers because they are slow. "
45
+ "Use --confirm-lost with --agent-id only after a terminal worker state, "
46
+ "user cancellation, or lost-worker verification."
47
+ )
48
+ if not args.agent_id:
49
+ raise SystemExit(f"{page['page_id']} dispatched reset requires --agent-id.")
50
+ if expected_agent_id and args.agent_id != expected_agent_id:
51
+ raise SystemExit(
52
+ f"Agent id mismatch for {page['page_id']}: "
53
+ f"dispatch={expected_agent_id} reset={args.agent_id}"
54
+ )
55
+ page["status"] = "pending"
56
+ page["dispatch"] = None
57
+ page["result"] = None
58
+ page["reset_at"] = now_iso()
59
+ update_jobs_run_status(jobs)
60
+ save_jobs(run_dir, jobs)
61
+ print(
62
+ json.dumps(
63
+ {
64
+ "page_id": page["page_id"],
65
+ "status": "pending",
66
+ "next": "rebuild the worker prompt and dispatch a new worker",
67
+ },
68
+ ensure_ascii=False,
69
+ )
70
+ )
71
+
72
+
73
+ if __name__ == "__main__":
74
+ main()