@dickpy/dsh-oil-slide 0.0.0-stage → 0.2.8
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/LICENSE +21 -0
- package/README.md +90 -2
- package/bundled-assets/brand/empty-deck-cobalt.webp +0 -0
- package/bundled-assets/brand/oil-slide-mark-512.png +0 -0
- package/bundled-assets/skill/LICENSE +21 -0
- package/bundled-assets/skill/README.md +61 -0
- package/bundled-assets/skill/SKILL.md +185 -0
- package/bundled-assets/skill/references/art-directions.md +99 -0
- package/bundled-assets/skill/references/brand-and-canvas.md +72 -0
- package/bundled-assets/skill/references/design-baseline.txt +1 -0
- package/bundled-assets/skill/references/prompt-compiler.md +99 -0
- package/bundled-assets/skill/references/restore-and-pptx.md +178 -0
- package/bundled-assets/skill/references/staged-pptx.md +71 -0
- package/bundled-assets/skill/scripts/_runtime_utils.py +351 -0
- package/bundled-assets/skill/scripts/asset_sheet.py +528 -0
- package/bundled-assets/skill/scripts/brand_ref.py +776 -0
- package/bundled-assets/skill/scripts/crop_asset.py +1709 -0
- package/bundled-assets/skill/scripts/deck_shell.py +2322 -0
- package/bundled-assets/skill/scripts/export_images.py +280 -0
- package/bundled-assets/skill/scripts/extract_pptx.py +360 -0
- package/bundled-assets/skill/scripts/extract_slide_dom.js +1640 -0
- package/bundled-assets/skill/scripts/html_to_pptx.py +4042 -0
- package/bundled-assets/skill/scripts/measure_slide_layout.py +952 -0
- package/bundled-assets/skill/scripts/oiloil-connect.mjs +1493 -0
- package/bundled-assets/skill/scripts/oiloil-image.mjs +492 -0
- package/bundled-assets/skill/scripts/prepare_plate.py +412 -0
- package/bundled-assets/skill/scripts/render_gradient.py +258 -0
- package/bundled-assets/skill/scripts/slide_brand.py +111 -0
- package/bundled-assets/skill/scripts/slide_incremental.py +122 -0
- package/bundled-assets/skill/scripts/slide_workflow.py +711 -0
- package/bundled-assets/skill/scripts/verify_deck.py +3483 -0
- package/bundled-assets/skill/vendor/README.md +4 -0
- package/bundled-assets/skill/vendor/codex-ppt/LICENSE +21 -0
- package/bundled-assets/skill/vendor/codex-ppt/assemble_ppt.py +435 -0
- package/bundled-assets/skill/vendor/codex-ppt/codex_ppt_runtime.py +284 -0
- package/bundled-assets/skill/vendor/codex-ppt/image_gen.py +972 -0
- package/bundled-assets/skill/vendor/codex-ppt/image_providers/__init__.py +6 -0
- package/bundled-assets/skill/vendor/codex-ppt/image_providers/atlascloud.py +222 -0
- package/bundled-assets/skill/vendor/codex-ppt/image_providers/base.py +32 -0
- package/bundled-assets/skill/vendor/codex-ppt/image_providers/factory.py +21 -0
- package/bundled-assets/skill/vendor/codex-ppt/image_providers/openai_compatible.py +238 -0
- package/bundled-assets/skill/vendor/codex-ppt/requirements.txt +5 -0
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- package/bundled-assets/skill/vendor/image-to-editable-ppt/LICENSE +21 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/SKILL.md +171 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/agents/openai.yaml +4 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/__init__.py +1 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/cli.py +25 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/__init__.py +1 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/_input_normalization.py +355 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/_page_artifacts.py +132 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/build_pptx_from_manifest.py +1029 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/configure_image_backend.py +52 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/deck_run_state.py +214 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/deck_text_hints.py +179 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/finalize_deck_run.py +96 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/formula_renderer.py +254 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/image_gen.py +206 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/main.py +795 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/make_page_contact_sheet.py +28 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/native_tables.py +140 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/paddle_text_hints.py +212 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/page_job_status.py +54 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/page_text_metrics.py +334 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/path_geometry.py +174 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/prepare_deck_run.py +209 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/process_asset_sheet.py +104 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/record_imagegen_result.py +118 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/record_page_dispatch.py +83 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/record_page_result.py +130 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/remove_chroma_key.py +441 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/reset_page_job.py +74 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/runtime_env.py +283 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/split_alpha_components.py +323 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/text_hints.py +309 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/validate_pptx.py +873 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/pyproject.toml +29 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/prompts/page-worker.md +47 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/references/cli-helper.md +282 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/references/manifest-schema.md +423 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/references/page-decision-tree.md +301 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/scripts/build-page-worker-prompt.py +134 -0
- package/cordis.patch.yml +3 -0
- package/lib/client.js +11423 -0
- package/lib/index.js +2638 -0
- package/package.json +140 -4
|
@@ -0,0 +1,711 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Persist the staged Oil Slide workflow; never call image providers implicitly."""
|
|
3
|
+
import argparse
|
|
4
|
+
import contextlib
|
|
5
|
+
import hashlib
|
|
6
|
+
import importlib.util
|
|
7
|
+
import json
|
|
8
|
+
import os
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
import shutil
|
|
11
|
+
import subprocess
|
|
12
|
+
import sys
|
|
13
|
+
import tempfile
|
|
14
|
+
import uuid
|
|
15
|
+
from types import SimpleNamespace
|
|
16
|
+
from slide_brand import list_brands, save_brand, attach_brand, brand_inputs
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
STATE = "slide-workflow.json"
|
|
20
|
+
CANVASES = {"16:9": (1536, 864), "3:4": (1104, 1472), "9:16": (864, 1536), "1:1": (1024, 1024)}
|
|
21
|
+
VENDOR = Path(__file__).resolve().parents[1] / "vendor"
|
|
22
|
+
IMAGE_PPTX = "dist/deck-images.pptx"
|
|
23
|
+
EDITABLE_PPTX = "dist/deck-editable.pptx"
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def need(condition, reason):
|
|
27
|
+
if not condition:
|
|
28
|
+
raise ValueError(reason)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def digest(path):
|
|
32
|
+
return hashlib.sha256(path.read_bytes()).hexdigest()
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def inside(root, name):
|
|
36
|
+
path = root / name
|
|
37
|
+
need(path.resolve().is_relative_to(root), f"Path escapes deck: {name}")
|
|
38
|
+
return path
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def atomic_write(path, data):
|
|
42
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
43
|
+
with tempfile.NamedTemporaryFile(dir=path.parent, delete=False) as temp:
|
|
44
|
+
pending = Path(temp.name)
|
|
45
|
+
try:
|
|
46
|
+
pending.write_bytes(data)
|
|
47
|
+
pending.replace(path)
|
|
48
|
+
finally:
|
|
49
|
+
pending.unlink(missing_ok=True)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def archive_file(root, source, relative):
|
|
53
|
+
target = inside(root, relative)
|
|
54
|
+
target.parent.mkdir(parents=True, exist_ok=True)
|
|
55
|
+
with tempfile.NamedTemporaryFile(dir=target.parent, delete=False) as temp:
|
|
56
|
+
pending = Path(temp.name)
|
|
57
|
+
try:
|
|
58
|
+
shutil.copyfile(source, pending)
|
|
59
|
+
pending.replace(target)
|
|
60
|
+
finally:
|
|
61
|
+
pending.unlink(missing_ok=True)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
@contextlib.contextmanager
|
|
65
|
+
def lock(root):
|
|
66
|
+
root.mkdir(parents=True, exist_ok=True)
|
|
67
|
+
handle = inside(root, f".{STATE}.lock").open("a+b")
|
|
68
|
+
try:
|
|
69
|
+
if os.name == "nt":
|
|
70
|
+
import msvcrt
|
|
71
|
+
if handle.seek(0, 2) == 0:
|
|
72
|
+
handle.write(b"0")
|
|
73
|
+
handle.flush()
|
|
74
|
+
handle.seek(0)
|
|
75
|
+
msvcrt.locking(handle.fileno(), msvcrt.LK_NBLCK, 1)
|
|
76
|
+
else:
|
|
77
|
+
import fcntl
|
|
78
|
+
fcntl.flock(handle, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
|
79
|
+
yield
|
|
80
|
+
finally:
|
|
81
|
+
handle.close()
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def canvas_image(src, out, ratio):
|
|
85
|
+
from io import BytesIO
|
|
86
|
+
from PIL import Image, ImageOps
|
|
87
|
+
with Image.open(src) as raw:
|
|
88
|
+
need(raw.format in {"PNG", "JPEG", "WEBP"}, "Expected a PNG, JPEG or WebP image")
|
|
89
|
+
need(raw.width * raw.height <= 32_000_000, "Image exceeds 32 megapixels")
|
|
90
|
+
# Normalize before showing a candidate. Later reuse this exact PNG with no
|
|
91
|
+
# scaling/redrawing. If a provider returns a different aspect ratio, keep
|
|
92
|
+
# all the slide text; pad rather than cropping or distorting.
|
|
93
|
+
image = ImageOps.exif_transpose(raw).convert("RGBA")
|
|
94
|
+
image = ImageOps.contain(image, CANVASES[ratio], method=Image.Resampling.LANCZOS)
|
|
95
|
+
color = image.getpixel((0, 0))
|
|
96
|
+
bg = Image.new("RGB", CANVASES[ratio], color[:3] if color[3] == 255 else "white")
|
|
97
|
+
bg.paste(image, ((bg.width - image.width) // 2, (bg.height - image.height) // 2), image)
|
|
98
|
+
buf = BytesIO()
|
|
99
|
+
bg.save(buf, format="PNG")
|
|
100
|
+
atomic_write(out, buf.getvalue())
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def assemble(root, state, pages, destination=IMAGE_PPTX):
|
|
104
|
+
path = VENDOR / "codex-ppt" / "assemble_ppt.py"
|
|
105
|
+
spec = importlib.util.spec_from_file_location("oil_codex_ppt_assemble", path)
|
|
106
|
+
mod = importlib.util.module_from_spec(spec)
|
|
107
|
+
spec.loader.exec_module(mod)
|
|
108
|
+
out = inside(root, destination)
|
|
109
|
+
out.parent.mkdir(parents=True, exist_ok=True)
|
|
110
|
+
with tempfile.TemporaryDirectory(dir=out.parent) as tmp:
|
|
111
|
+
stage = Path(tmp) / "result.pptx"
|
|
112
|
+
notes = {i + 1: page["notes"] for i, page in enumerate(state["outline"]) if page.get("notes")}
|
|
113
|
+
with contextlib.redirect_stdout(sys.stderr):
|
|
114
|
+
success = mod.create_presentation([str(p) for p in pages], str(stage), state["ratio"],
|
|
115
|
+
speaker_notes=notes, preserve_pixels=True)
|
|
116
|
+
need(success, "Image PPTX assembly failed")
|
|
117
|
+
from pptx import Presentation
|
|
118
|
+
from pptx.enum.shapes import MSO_SHAPE_TYPE
|
|
119
|
+
result = Presentation(stage)
|
|
120
|
+
need(len(result.slides) == len(pages), "PPTX page count differs from outline")
|
|
121
|
+
for index, slide in enumerate(result.slides):
|
|
122
|
+
need(len(slide.shapes) == 1 and slide.shapes[0].shape_type == MSO_SHAPE_TYPE.PICTURE
|
|
123
|
+
and slide.shapes[0].image.blob == pages[index].read_bytes(),
|
|
124
|
+
f"Page {index + 1} does not contain the exact approved PNG")
|
|
125
|
+
stage.replace(out)
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def checked_pages(root, state):
|
|
129
|
+
ordered = []
|
|
130
|
+
for number in range(1, len(state["outline"]) + 1):
|
|
131
|
+
entry = state["pages"].get(str(number))
|
|
132
|
+
need(entry is not None, f"Page {number} is missing")
|
|
133
|
+
p = inside(root, entry["path"])
|
|
134
|
+
need(p.is_file() and digest(p) == entry["sha256"], f"Page {number} changed on disk")
|
|
135
|
+
ordered.append(p)
|
|
136
|
+
return ordered
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def check_editable(path, pages):
|
|
140
|
+
from pptx import Presentation
|
|
141
|
+
from pptx.enum.shapes import MSO_SHAPE_TYPE as Shape
|
|
142
|
+
pres = Presentation(path)
|
|
143
|
+
need(len(pres.slides) == len(pages), "Editable deck page count differs from image deck")
|
|
144
|
+
from PIL import Image
|
|
145
|
+
with Image.open(pages[0]) as src:
|
|
146
|
+
need(abs(pres.slide_width / pres.slide_height - src.width / src.height) < .002,
|
|
147
|
+
"Editable deck aspect ratio differs from image deck")
|
|
148
|
+
for number, (slide, source) in enumerate(zip(pres.slides, pages), 1):
|
|
149
|
+
def walk(shapes):
|
|
150
|
+
for item in shapes:
|
|
151
|
+
yield item
|
|
152
|
+
if item.shape_type == Shape.GROUP:
|
|
153
|
+
yield from walk(item.shapes)
|
|
154
|
+
all_shapes = list(walk(slide.shapes))
|
|
155
|
+
need(any((s.has_text_frame and s.text.strip())
|
|
156
|
+
or (s.has_table and any(cell.text.strip() for cell in s.table.iter_cells()))
|
|
157
|
+
for s in all_shapes), f"Page {number} has no native editable text")
|
|
158
|
+
source_bytes = source.read_bytes()
|
|
159
|
+
def original_picture(s):
|
|
160
|
+
return s.shape_type == Shape.PICTURE and s.image.blob == source_bytes
|
|
161
|
+
need(not any(original_picture(s) for s in all_shapes),
|
|
162
|
+
f"Page {number} embeds the original slide image")
|
|
163
|
+
return pres
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
def editppt(args, *, output=False):
|
|
167
|
+
# The user installs the pinned, vendored runtime in their chosen Python env.
|
|
168
|
+
executable = shutil.which("editppt")
|
|
169
|
+
need(executable, f"Install the bundled converter: pipx install --force --editable {VENDOR / 'image-to-editable-ppt' / 'cli'}")
|
|
170
|
+
return subprocess.run([executable, *map(str, args)], check=True, text=True,
|
|
171
|
+
stdout=subprocess.PIPE if output else sys.stderr).stdout
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
def run_path(root, state):
|
|
175
|
+
if state.get("activeEditableRun"):
|
|
176
|
+
return inside(root, state["activeEditableRun"])
|
|
177
|
+
revision = state.get("deckRevision", 1)
|
|
178
|
+
return inside(root, "editable-run" if revision == 1 else f"dist/work/r{revision}/editable-run")
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
def native_plan(root, state, pages):
|
|
182
|
+
from slide_incremental import previous_deck
|
|
183
|
+
snapshot = state.get("nativeSnapshot")
|
|
184
|
+
if snapshot:
|
|
185
|
+
base = inside(root, snapshot["base"])
|
|
186
|
+
hashes = snapshot["hashes"]
|
|
187
|
+
need(base.is_file() and len(hashes) == len(pages), "Previous editable file or slide mapping is missing")
|
|
188
|
+
return dict(base=snapshot["base"], baseHash=digest(base), hashes=hashes, total=len(pages),
|
|
189
|
+
changed=[n for n, h in enumerate(hashes, 1) if state["pages"][str(n)]["sha256"] != h])
|
|
190
|
+
if state["stage"] == "editable_ready":
|
|
191
|
+
file = inside(root, EDITABLE_PPTX)
|
|
192
|
+
return dict(base=EDITABLE_PPTX, baseHash=digest(file), changed=[], total=len(pages),
|
|
193
|
+
hashes=[state["pages"][str(n)]["sha256"] for n in range(1, len(pages) + 1)])
|
|
194
|
+
return previous_deck(root, state.get("deckRevision", 1), pages)
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
def archive_design(root, candidate):
|
|
198
|
+
folder = f"assets/design-history/{candidate['number']}/{candidate['sha256']}"
|
|
199
|
+
image = inside(root, folder + ".png")
|
|
200
|
+
source = inside(root, candidate["path"])
|
|
201
|
+
need(digest(source) == candidate["sha256"], "Design changed since review")
|
|
202
|
+
if not image.exists():
|
|
203
|
+
atomic_write(image, source.read_bytes())
|
|
204
|
+
atomic_write(inside(root, folder + ".txt"), candidate["style"].encode())
|
|
205
|
+
return image
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
def render_editable_preview(root, state, pptx):
|
|
209
|
+
from verify_deck import render_pptx_to_pngs
|
|
210
|
+
folder = inside(root, f"dist/preview/{digest(pptx)}")
|
|
211
|
+
folder.mkdir(parents=True, exist_ok=True)
|
|
212
|
+
with tempfile.TemporaryDirectory(dir=folder) as tmp:
|
|
213
|
+
result = render_pptx_to_pngs(pptx, Path(tmp))
|
|
214
|
+
need(result["ok"] and len(result["images"]) == len(state["outline"]),
|
|
215
|
+
result.get("error") or "Editable preview has missing pages")
|
|
216
|
+
for i, image in enumerate(result["images"], 1):
|
|
217
|
+
Path(image).replace(inside(root, folder / f"s{i}.png"))
|
|
218
|
+
state["editablePreview"] = folder.name
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
def read_outline(file):
|
|
222
|
+
outline = json.loads(file.read_text(encoding="utf-8"))
|
|
223
|
+
return validate_outline(outline)
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
def validate_outline(outline):
|
|
227
|
+
need(isinstance(outline, list) and 1 <= len(outline) <= 60, "Outline needs 1–60 pages")
|
|
228
|
+
for index, page in enumerate(outline, 1):
|
|
229
|
+
need(isinstance(page, dict) and set(page) <= {"title", "content", "takeaway", "layout", "notes", "assets"},
|
|
230
|
+
f"Invalid outline page {index}")
|
|
231
|
+
need(all(isinstance(page.get(k), str) and page[k].strip() for k in ("title", "content")),
|
|
232
|
+
f"Page {index}: title and content are required")
|
|
233
|
+
need(all(isinstance(v, str) and len(v) <= 4000 for v in page.values()),
|
|
234
|
+
f"Page {index}: layout, notes and assets must be text")
|
|
235
|
+
return outline
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
def production_prompt(root, state, number):
|
|
239
|
+
need(1 <= number <= len(state["outline"]), "Page is outside the outline")
|
|
240
|
+
changes = state.get("revisionsPending", {})
|
|
241
|
+
revision = changes.get(str(number))
|
|
242
|
+
need(number != state["samplePage"] or revision, "The approved sample is already the final image for this page")
|
|
243
|
+
draft = state["approved"]
|
|
244
|
+
anchor_info = state.get("styleAnchor", draft)
|
|
245
|
+
anchor = inside(root, anchor_info["path"])
|
|
246
|
+
need(digest(anchor) == anchor_info["sha256"], "Approved style image changed on disk")
|
|
247
|
+
page = state["outline"][number - 1]
|
|
248
|
+
base = (Path(__file__).resolve().parents[1] / "references/design-baseline.txt").read_text(encoding="utf-8")
|
|
249
|
+
prompt = f"""Create a finished single {state['ratio']} PowerPoint slide, including the exact text.
|
|
250
|
+
Reference image 1 is the approved design. Preserve its palette, typography hierarchy,
|
|
251
|
+
texture, illustration treatment, margins and visual identity. Do not copy its page
|
|
252
|
+
content or force its composition on this slide. Use a distinct layout fitting the content.
|
|
253
|
+
Use the full canvas edge to edge, with comfortable safe margins and no browser UI.
|
|
254
|
+
Page {number}/{len(state['outline'])}
|
|
255
|
+
Title: {page['title']}
|
|
256
|
+
Takeaway: {page.get('takeaway','')}
|
|
257
|
+
Required content: {page['content']}
|
|
258
|
+
Layout intent: {page.get('layout','Choose a distinct content-appropriate layout')}
|
|
259
|
+
Strict assets: {page.get('assets','None specified; never invent a logo or data.')}
|
|
260
|
+
Approved visual direction: {draft['style']}
|
|
261
|
+
{base}"""
|
|
262
|
+
if revision:
|
|
263
|
+
prompt += ("\nThe last reference is the previous version of THIS page. Preserve its content and "
|
|
264
|
+
"unaffected details. Apply these user changes, which supersede earlier directions: "
|
|
265
|
+
+ revision["feedback"])
|
|
266
|
+
return dict(prompt=prompt, reference=str(anchor), canvas=CANVASES[state["ratio"]])
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
def provider_render(root, prompt, refs, state, out, a):
|
|
270
|
+
brand_prompt, brand_refs = brand_inputs(state)
|
|
271
|
+
prompt += brand_prompt
|
|
272
|
+
# Keep the style anchor first and the previously rendered page last.
|
|
273
|
+
split = 1 if refs else 0
|
|
274
|
+
refs = [*refs[:split], *brand_refs, *refs[split:]]
|
|
275
|
+
engine = VENDOR / "image-to-editable-ppt/cli/editppt/runtime/image_gen.py"
|
|
276
|
+
with tempfile.TemporaryDirectory() as tmp:
|
|
277
|
+
ask = Path(tmp) / "prompt.txt"
|
|
278
|
+
response = Path(tmp) / "image.png"
|
|
279
|
+
ask.write_text(prompt, encoding="utf-8")
|
|
280
|
+
size = a.size or "x".join(str(x) for x in CANVASES[state["ratio"]])
|
|
281
|
+
command = [sys.executable, str(engine), "edit" if refs else "generate",
|
|
282
|
+
"--size", size, "--quality", a.quality,
|
|
283
|
+
"--prompt-file", str(ask), "--out", str(response)]
|
|
284
|
+
if a.model:
|
|
285
|
+
command += ["--model", a.model]
|
|
286
|
+
for ref in refs:
|
|
287
|
+
source = inside(root, ref)
|
|
288
|
+
need(source.is_file(), f"Missing reference image: {ref}")
|
|
289
|
+
command += ["--image", str(source)]
|
|
290
|
+
subprocess.run(command, check=True, stdout=sys.stderr, cwd=root)
|
|
291
|
+
canvas_image(response, out, state["ratio"])
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
def update(root, a):
|
|
295
|
+
file = inside(root, STATE)
|
|
296
|
+
if a.cmd == "brand-list":
|
|
297
|
+
return list_brands()
|
|
298
|
+
if a.cmd == "brand-create":
|
|
299
|
+
return save_brand(json.loads(a.file.read_text(encoding="utf-8")), a.workspace.resolve())
|
|
300
|
+
if a.cmd in {"outline", "edit-outline"}:
|
|
301
|
+
old = json.loads(file.read_text(encoding="utf-8")) if file.is_file() else None
|
|
302
|
+
need(not old or old["stage"] == "outline_review", "The outline has already been approved")
|
|
303
|
+
brand = (old or {}).get("brand")
|
|
304
|
+
if a.cmd == "edit-outline":
|
|
305
|
+
data = json.loads(a.file.read_text(encoding="utf-8"))
|
|
306
|
+
need(old and old["outlineRevision"] == data["revision"], "The outline changed. Refresh and reapply your changes.")
|
|
307
|
+
pages = validate_outline(data["pages"])
|
|
308
|
+
ratio = old["ratio"]
|
|
309
|
+
if "brandId" in data:
|
|
310
|
+
brand = attach_brand(root, data["brandId"]) if data["brandId"] else None
|
|
311
|
+
else:
|
|
312
|
+
pages = read_outline(a.file)
|
|
313
|
+
ratio = a.ratio
|
|
314
|
+
state = dict(version=1, stage="outline_review", outline=pages, ratio=ratio,
|
|
315
|
+
outlineQuestionId=(old or {}).get("outlineQuestionId") or "oil_outline_" + uuid.uuid4().hex[:16],
|
|
316
|
+
candidates=[], approved=None, pages={})
|
|
317
|
+
identity = [pages, ratio]
|
|
318
|
+
if brand:
|
|
319
|
+
state["brand"] = brand
|
|
320
|
+
identity.append(brand["id"])
|
|
321
|
+
state["outlineRevision"] = hashlib.sha256(json.dumps(
|
|
322
|
+
identity, ensure_ascii=False, sort_keys=True).encode()).hexdigest()[:12]
|
|
323
|
+
else:
|
|
324
|
+
need(file.is_file(), "Create and review an outline first")
|
|
325
|
+
state = json.loads(file.read_text(encoding="utf-8"))
|
|
326
|
+
stage = state["stage"]
|
|
327
|
+
|
|
328
|
+
if a.cmd == "status":
|
|
329
|
+
return state
|
|
330
|
+
if a.cmd == "approve-outline":
|
|
331
|
+
need(stage == "outline_review" and a.revision == state["outlineRevision"],
|
|
332
|
+
"Approve the current outline revision first")
|
|
333
|
+
need(1 <= a.sample_page <= len(state["outline"]), "Sample page is outside the outline")
|
|
334
|
+
state.update(stage="drafts", count=a.count, samplePage=a.sample_page)
|
|
335
|
+
elif a.cmd == "new-design-set":
|
|
336
|
+
need(stage == "style_review", "Finish the current review round first")
|
|
337
|
+
need(not a.review_id or a.review_id == state.get("reviewId"), "Design round changed")
|
|
338
|
+
state["pendingDesigns"] = list(range(1, state["count"] + 1))
|
|
339
|
+
state["stage"] = "drafts"
|
|
340
|
+
elif a.cmd in {"add-draft", "render-draft", "restore-draft"}:
|
|
341
|
+
need(stage in {"drafts", "style_review"}, "Confirm outline and draft quantity before adding designs")
|
|
342
|
+
need(1 <= a.number <= state["count"], "Candidate number is outside the approved quantity")
|
|
343
|
+
current = next((c for c in state["candidates"] if c["number"] == a.number), None)
|
|
344
|
+
expected = getattr(a, "from_sha256", None)
|
|
345
|
+
if expected:
|
|
346
|
+
need(current and current["sha256"] == expected, "This design has changed. Refresh before revising.")
|
|
347
|
+
history = list(current.get("history", [])) if current else []
|
|
348
|
+
if current:
|
|
349
|
+
old_image = archive_design(root, current)
|
|
350
|
+
if current["sha256"] not in history:
|
|
351
|
+
history.append(current["sha256"])
|
|
352
|
+
if a.cmd == "restore-draft":
|
|
353
|
+
need(a.version in history, "Unknown design version")
|
|
354
|
+
source = inside(root, f"assets/design-history/{a.number}/{a.version}.png")
|
|
355
|
+
need(digest(source) == a.version, "Archived design changed")
|
|
356
|
+
style = source.with_suffix(".txt").read_text(encoding="utf-8")
|
|
357
|
+
else:
|
|
358
|
+
style = a.style.read_text(encoding="utf-8").strip()
|
|
359
|
+
need(0 < len(style) <= 12000, "Provide the candidate's visual specification")
|
|
360
|
+
path = f"assets/explore/design-{a.number:02}.png"
|
|
361
|
+
if a.cmd == "render-draft":
|
|
362
|
+
page = state["outline"][state["samplePage"] - 1]
|
|
363
|
+
prompt = (f"Create a finished single {state['ratio']} slide style sample using this exact text."
|
|
364
|
+
f" Use a full canvas with safe margins. Title: {page['title']}. "
|
|
365
|
+
f"Takeaway: {page.get('takeaway','')}. Content: {page['content']}. Layout: {page.get('layout', '')}. "
|
|
366
|
+
f"Required assets: {page.get('assets', '')}. Visual specification: {style}")
|
|
367
|
+
refs = a.ref
|
|
368
|
+
if a.feedback:
|
|
369
|
+
need(current, "Choose the design to revise first")
|
|
370
|
+
refs = [old_image.relative_to(root), *refs]
|
|
371
|
+
prompt += "\nEdit reference 1. Keep what was not requested to change. Feedback: " + a.feedback
|
|
372
|
+
provider_render(root, prompt, refs, state, inside(root, path), a)
|
|
373
|
+
elif a.cmd == "restore-draft":
|
|
374
|
+
atomic_write(inside(root, path), source.read_bytes())
|
|
375
|
+
else:
|
|
376
|
+
canvas_image(a.image, inside(root, path), state["ratio"])
|
|
377
|
+
entries = [x for x in state["candidates"] if x["number"] != a.number]
|
|
378
|
+
hash_now = digest(inside(root, path))
|
|
379
|
+
entries.append(dict(number=a.number, path=path, sha256=hash_now, style=style,
|
|
380
|
+
history=[h for h in history if h != hash_now]))
|
|
381
|
+
state["reviewId"] = "oil_style_" + uuid.uuid4().hex[:16]
|
|
382
|
+
state["candidates"] = sorted(entries, key=lambda x: x["number"])
|
|
383
|
+
pending_designs = state.get("pendingDesigns", [])
|
|
384
|
+
if a.number in pending_designs:
|
|
385
|
+
pending_designs.remove(a.number)
|
|
386
|
+
state["stage"] = "style_review" if len(entries) == state["count"] and not pending_designs else "drafts"
|
|
387
|
+
elif a.cmd == "approve-style":
|
|
388
|
+
need(stage == "style_review", "Show the approved number of same-page candidates before choosing one")
|
|
389
|
+
draft = next((x for x in state["candidates"] if x["number"] == a.number), None)
|
|
390
|
+
need(draft is not None and draft["sha256"] == a.sha256, "Select the current version of a displayed design")
|
|
391
|
+
source = inside(root, draft["path"])
|
|
392
|
+
data = source.read_bytes()
|
|
393
|
+
need(hashlib.sha256(data).hexdigest() == a.sha256, "Selected design changed on disk")
|
|
394
|
+
sample = state["samplePage"]
|
|
395
|
+
ref = f"assets/reference/s{sample}.png"
|
|
396
|
+
atomic_write(inside(root, ref), data)
|
|
397
|
+
state.update(stage="production", approved=draft, pages={str(sample): {"path":ref,"sha256":a.sha256}})
|
|
398
|
+
elif a.cmd == "page-prompt":
|
|
399
|
+
need(stage == "production", "Confirm a visual draft before producing pages")
|
|
400
|
+
return production_prompt(root, state, a.number)
|
|
401
|
+
elif a.cmd in {"add-page", "render-page"}:
|
|
402
|
+
need(stage == "production", "Confirm a visual draft before recording final images")
|
|
403
|
+
pending_pages = state.get("revisionsPending", {})
|
|
404
|
+
sample = str(state["samplePage"])
|
|
405
|
+
if pending_pages.get(sample, {}).get("restyle"):
|
|
406
|
+
need(str(a.number) == sample, "Revise the style sample before rendering other pages")
|
|
407
|
+
job = production_prompt(root, state, a.number)
|
|
408
|
+
rel = f"assets/reference/s{a.number}.png"
|
|
409
|
+
p = inside(root, rel)
|
|
410
|
+
if a.cmd == "render-page":
|
|
411
|
+
refs = [Path(job["reference"]).relative_to(root), *a.ref]
|
|
412
|
+
pending = state.get("revisionsPending", {}).get(str(a.number))
|
|
413
|
+
if pending:
|
|
414
|
+
refs.append(pending["previous"])
|
|
415
|
+
provider_render(root, job["prompt"], refs, state, p, a)
|
|
416
|
+
else:
|
|
417
|
+
canvas_image(a.image, p, state["ratio"])
|
|
418
|
+
state["pages"][str(a.number)] = dict(path=rel, sha256=digest(p))
|
|
419
|
+
change = pending_pages.pop(str(a.number), None)
|
|
420
|
+
if change and change.get("restyle"):
|
|
421
|
+
name = f"assets/style-anchors/{digest(p)}.png"
|
|
422
|
+
atomic_write(inside(root, name), p.read_bytes())
|
|
423
|
+
state["styleAnchor"] = dict(path=name, sha256=digest(p))
|
|
424
|
+
state["approved"] = dict(state["approved"], style=state["approved"]["style"] + "\n" + change["feedback"])
|
|
425
|
+
elif a.cmd == "export-images":
|
|
426
|
+
need(stage in {"production", "image_ready", "converting", "editable_ready"}, "Finish image production first")
|
|
427
|
+
pages = checked_pages(root, state)
|
|
428
|
+
assemble(root, state, pages)
|
|
429
|
+
if stage == "production":
|
|
430
|
+
state["stage"] = "image_ready"
|
|
431
|
+
elif a.cmd == "inspect-native":
|
|
432
|
+
from slide_incremental import native_objects
|
|
433
|
+
need(1 <= a.number <= len(state["outline"]), "Page is outside the deck")
|
|
434
|
+
pages = [inside(root, row["path"]) for _, row in sorted(state["pages"].items(), key=lambda pair: int(pair[0]))]
|
|
435
|
+
if len(pages) != len(state["outline"]):
|
|
436
|
+
return dict(changed=[], objects=[])
|
|
437
|
+
plan = native_plan(root, state, pages)
|
|
438
|
+
if not plan:
|
|
439
|
+
return dict(changed=list(range(1, len(pages)+1)), objects=[])
|
|
440
|
+
preview = f"dist/preview/{plan['baseHash']}/s{a.number}.png"
|
|
441
|
+
result = dict(changed=plan["changed"], objects=native_objects(inside(root, plan["base"]), a.number),
|
|
442
|
+
file=plan["base"])
|
|
443
|
+
if inside(root, preview).is_file():
|
|
444
|
+
result["preview"] = preview
|
|
445
|
+
return result
|
|
446
|
+
elif a.cmd == "approve-images":
|
|
447
|
+
need(not state.get("regionProposal"), "Review the region proposal first")
|
|
448
|
+
need(stage in {"image_ready", "editable_ready"}, "Review the image PPTX before conversion")
|
|
449
|
+
pages = checked_pages(root, state)
|
|
450
|
+
page = getattr(a, "number", None)
|
|
451
|
+
if stage == "editable_ready" or page is not None:
|
|
452
|
+
plan = native_plan(root, state, pages)
|
|
453
|
+
need(plan and plan["changed"], "No changed slides are awaiting conversion")
|
|
454
|
+
need(page is None or page in plan["changed"], "This page does not need an update")
|
|
455
|
+
token = uuid.uuid4().hex
|
|
456
|
+
state["activeEditableRun"] = f"dist/work/sync-{token}/editable-run"
|
|
457
|
+
if plan["base"] == EDITABLE_PPTX:
|
|
458
|
+
copy = f"dist/work/sync-{token}/previous.pptx"
|
|
459
|
+
archive_file(root, inside(root, EDITABLE_PPTX), copy)
|
|
460
|
+
state["nativeSnapshot"] = dict(base=copy, hashes=plan["hashes"])
|
|
461
|
+
state["updatePage"] = page
|
|
462
|
+
need(inside(root, IMAGE_PPTX).is_file(), "Re-export the missing image PPTX before conversion")
|
|
463
|
+
state["stage"] = "converting"
|
|
464
|
+
elif a.cmd == "propose-region":
|
|
465
|
+
need(stage in {"image_ready", "editable_ready"} and state.get("deckRevision", 1) == a.revision,
|
|
466
|
+
"Finish or refresh the current revision before editing a region")
|
|
467
|
+
need(not state.get("regionProposal"), "Review the existing proposal first")
|
|
468
|
+
need(1 <= a.number <= len(state["outline"]) and a.feedback.strip(), "Choose a page and describe the change")
|
|
469
|
+
x, y, right, bottom = a.box
|
|
470
|
+
need(0 <= x < right <= 1000 and 0 <= y < bottom <= 1000, "Invalid region coordinates")
|
|
471
|
+
from PIL import Image, ImageDraw
|
|
472
|
+
source = checked_pages(root, state)[a.number - 1]
|
|
473
|
+
proposal = uuid.uuid4().hex
|
|
474
|
+
folder = inside(root, f"assets/region-edits/{proposal}")
|
|
475
|
+
folder.mkdir(parents=True)
|
|
476
|
+
with tempfile.TemporaryDirectory(dir=folder) as tmp, Image.open(source) as original:
|
|
477
|
+
w, h = original.size
|
|
478
|
+
box = (x*w//1000, y*h//1000, (right*w+999)//1000, (bottom*h+999)//1000)
|
|
479
|
+
guide = original.convert("RGB")
|
|
480
|
+
ImageDraw.Draw(guide).rectangle((box[0], box[1], box[2]-1, box[3]-1), outline="#e92940", width=max(2, w//450))
|
|
481
|
+
guide_path = Path(tmp) / "guide.png"
|
|
482
|
+
guide.save(guide_path)
|
|
483
|
+
generated = Path(tmp) / "generated.png"
|
|
484
|
+
provider_render(root, "Edit the first full slide, keeping all elements aligned. The last image marks "
|
|
485
|
+
"the edit area in red. Return the full slide without the red border. User feedback: " +
|
|
486
|
+
a.feedback, [source.relative_to(root), guide_path.relative_to(root)], state, generated, a)
|
|
487
|
+
with Image.open(generated) as result:
|
|
488
|
+
merged = original.convert("RGB")
|
|
489
|
+
merged.paste(result.crop(box), box[:2])
|
|
490
|
+
merged.save(folder / "candidate.png")
|
|
491
|
+
state["regionProposal"] = dict(id=proposal, number=a.number, revision=a.revision, box=a.box,
|
|
492
|
+
feedback=a.feedback, sha256=digest(folder / "candidate.png"))
|
|
493
|
+
elif a.cmd == "resolve-region":
|
|
494
|
+
item = state.get("regionProposal")
|
|
495
|
+
need(item and item["id"] == a.proposal, "The proposal has already been resolved or replaced")
|
|
496
|
+
if a.choice == "keep":
|
|
497
|
+
need(not item.get("applying"), "Finish applying this proposal")
|
|
498
|
+
else:
|
|
499
|
+
candidate = inside(root, f"assets/region-edits/{item['id']}/candidate.png")
|
|
500
|
+
need(digest(candidate) == item["sha256"], "Proposal changed on disk")
|
|
501
|
+
rev, page = item["revision"], item["number"]
|
|
502
|
+
if not item.get("applying"):
|
|
503
|
+
need(state.get("deckRevision", 1) == rev and stage in {"image_ready", "editable_ready"}, "Stale proposal")
|
|
504
|
+
item["applying"] = True
|
|
505
|
+
atomic_write(file, json.dumps(state, ensure_ascii=False).encode())
|
|
506
|
+
if state.get("deckRevision", 1) == rev:
|
|
507
|
+
state = update(root, SimpleNamespace(cmd="revise-pages", revision=rev, number=[page], restyle=False,
|
|
508
|
+
feedback=item["feedback"], applying=True))
|
|
509
|
+
need(state.get("deckRevision") == rev + 1, "Proposal revision no longer active")
|
|
510
|
+
if state["stage"] == "production":
|
|
511
|
+
if str(page) not in state["pages"]:
|
|
512
|
+
state = update(root, SimpleNamespace(cmd="add-page", number=page, image=candidate))
|
|
513
|
+
state = update(root, SimpleNamespace(cmd="export-images"))
|
|
514
|
+
del state["regionProposal"]
|
|
515
|
+
elif a.cmd == "revise-pages":
|
|
516
|
+
need(not state.get("regionProposal") or getattr(a, "applying", False), "Review the region proposal first")
|
|
517
|
+
need(stage in {"image_ready", "editable_ready", "converting"}, "Finish the current page revision first")
|
|
518
|
+
feedback = (a.feedback or "").strip()
|
|
519
|
+
sample = state["samplePage"]
|
|
520
|
+
numbers = set(a.number)
|
|
521
|
+
need(all(1 <= n <= len(state["outline"]) for n in numbers), "Page is outside the deck")
|
|
522
|
+
need(feedback or (sample not in numbers and stage == "image_ready"),
|
|
523
|
+
"Provide feedback for this revision")
|
|
524
|
+
need(not a.restyle or (feedback and numbers == {sample}), "Restyle from the sample page")
|
|
525
|
+
rev = state.get("deckRevision", 1)
|
|
526
|
+
if a.revision is not None:
|
|
527
|
+
need(rev == a.revision, "This deck revision has already changed")
|
|
528
|
+
pages = checked_pages(root, state)
|
|
529
|
+
archive = f"dist/revisions/r{rev}"
|
|
530
|
+
for output in [IMAGE_PPTX] + ([EDITABLE_PPTX] if stage == "editable_ready" else []):
|
|
531
|
+
source = inside(root, output)
|
|
532
|
+
archive_file(root, source, f"{archive}/{source.name}")
|
|
533
|
+
if stage == "editable_ready":
|
|
534
|
+
hashes = (state.get("nativeSnapshot") or {}).get("hashes") or [state["pages"][str(n)]["sha256"] for n in range(1,len(pages)+1)]
|
|
535
|
+
state["nativeSnapshot"] = dict(base=f"{archive}/deck-editable.pptx", hashes=hashes)
|
|
536
|
+
state.pop("activeEditableRun", None)
|
|
537
|
+
state.pop("updatePage", None)
|
|
538
|
+
if a.restyle:
|
|
539
|
+
numbers = set(range(1, len(pages) + 1))
|
|
540
|
+
pending = {}
|
|
541
|
+
for number in sorted(numbers):
|
|
542
|
+
old = f"{archive}/s{number}.png"
|
|
543
|
+
atomic_write(inside(root, old), pages[number - 1].read_bytes())
|
|
544
|
+
pending[str(number)] = dict(previous=old, feedback=feedback, restyle=a.restyle and number == sample)
|
|
545
|
+
del state["pages"][str(number)]
|
|
546
|
+
state["revisionsPending"] = pending
|
|
547
|
+
state["deckRevision"] = rev + 1
|
|
548
|
+
state.pop("editablePreview", None)
|
|
549
|
+
state["stage"] = "production"
|
|
550
|
+
elif a.cmd == "editable-prepare":
|
|
551
|
+
need(stage == "converting", "Confirm the image deck and request editable PPTX first")
|
|
552
|
+
pages = checked_pages(root, state)
|
|
553
|
+
target = run_path(root, state)
|
|
554
|
+
plan_file = inside(root, target.parent / (target.name + "-oil-update.json"))
|
|
555
|
+
target.mkdir(parents=True, exist_ok=True)
|
|
556
|
+
if plan_file.exists():
|
|
557
|
+
plan = json.loads(plan_file.read_text(encoding="utf-8"))
|
|
558
|
+
else:
|
|
559
|
+
plan = None if (target / "deck_manifest.json").exists() else native_plan(root, state, pages)
|
|
560
|
+
if state.get("updatePage") is not None:
|
|
561
|
+
need(plan and state["updatePage"] in plan["changed"], "Page changed during preparation")
|
|
562
|
+
plan["changed"] = [state["updatePage"]]
|
|
563
|
+
atomic_write(plan_file, json.dumps(plan).encode())
|
|
564
|
+
changed = plan["changed"] if plan else list(range(1, len(pages)+1))
|
|
565
|
+
if not changed:
|
|
566
|
+
return dict(run=str(target), pages=0, changed=[], reused=len(pages), next=["editable-finalize"])
|
|
567
|
+
if not (target / "deck_manifest.json").is_file():
|
|
568
|
+
source = inside(root, IMAGE_PPTX)
|
|
569
|
+
if plan:
|
|
570
|
+
source = target.parent / "changed-input.pptx"
|
|
571
|
+
assemble(root, dict(state, outline=[state["outline"][n-1] for n in changed]),
|
|
572
|
+
[pages[n-1] for n in changed], source)
|
|
573
|
+
command = ["prepare", source, "--job-dir", target, "--serial-local"]
|
|
574
|
+
command += ["--image-backend", "openai-compatible-api"]
|
|
575
|
+
editppt(command)
|
|
576
|
+
else:
|
|
577
|
+
manifest = json.loads((target / "deck_manifest.json").read_text(encoding="utf-8"))
|
|
578
|
+
if (manifest.get("image_backend") or {}).get("backend_id") != "openai-compatible-api":
|
|
579
|
+
editppt(["run", "backend", target, "--mode", "openai-compatible-api"])
|
|
580
|
+
return dict(run=str(target), pages=len(changed), changed=changed, reused=len(pages)-len(changed),
|
|
581
|
+
next=["editppt", "run", "next", str(target), "--json"])
|
|
582
|
+
elif a.cmd == "editable-finalize":
|
|
583
|
+
need(stage == "converting", "Approve image conversion before finalizing an editable PPTX")
|
|
584
|
+
pages = checked_pages(root, state)
|
|
585
|
+
target = run_path(root, state)
|
|
586
|
+
out = inside(root, EDITABLE_PPTX)
|
|
587
|
+
with tempfile.TemporaryDirectory(dir=out.parent) as tmp:
|
|
588
|
+
plan_file = inside(root, target.parent / (target.name + "-oil-update.json"))
|
|
589
|
+
plan = json.loads(plan_file.read_text(encoding="utf-8")) if plan_file.is_file() else None
|
|
590
|
+
result = None
|
|
591
|
+
if not plan or plan["changed"]:
|
|
592
|
+
editppt(["run", "finalize", target])
|
|
593
|
+
manifest = json.loads((target / "deck_manifest.json").read_text(encoding="utf-8"))
|
|
594
|
+
result = inside(target.resolve(), manifest["output"])
|
|
595
|
+
need(result.is_file(), "Converter did not produce an editable PPTX")
|
|
596
|
+
staged = Path(tmp) / "result.pptx"
|
|
597
|
+
if plan:
|
|
598
|
+
base = inside(root, plan["base"])
|
|
599
|
+
need(digest(base) == plan["baseHash"], "Previous editable PPTX changed during conversion")
|
|
600
|
+
from slide_incremental import patch_native_slides
|
|
601
|
+
patch_native_slides(base, result, plan["changed"], staged)
|
|
602
|
+
else:
|
|
603
|
+
shutil.copyfile(result, staged)
|
|
604
|
+
check_editable(staged, pages)
|
|
605
|
+
staged.replace(out)
|
|
606
|
+
hashes = [state["pages"][str(n)]["sha256"] for n in range(1, len(pages)+1)]
|
|
607
|
+
if plan and plan.get("hashes"):
|
|
608
|
+
changed = set(plan["changed"])
|
|
609
|
+
hashes = [h if n in changed else plan["hashes"][n-1] for n, h in enumerate(hashes, 1)]
|
|
610
|
+
state["nativeSnapshot"] = dict(base=EDITABLE_PPTX, hashes=hashes)
|
|
611
|
+
state.pop("editablePreview", None)
|
|
612
|
+
state.pop("activeEditableRun", None)
|
|
613
|
+
state.pop("updatePage", None)
|
|
614
|
+
state["stage"] = "editable_ready"
|
|
615
|
+
try:
|
|
616
|
+
render_editable_preview(root, state, out)
|
|
617
|
+
except (OSError, ValueError, ImportError, subprocess.SubprocessError) as exc:
|
|
618
|
+
print(f"Editable PPTX saved. Preview unavailable: {exc}", file=sys.stderr)
|
|
619
|
+
elif a.cmd == "preview-editable":
|
|
620
|
+
need(stage == "editable_ready", "Finish editable conversion first")
|
|
621
|
+
render_editable_preview(root, state, inside(root, EDITABLE_PPTX))
|
|
622
|
+
atomic_write(file, (json.dumps(state, ensure_ascii=False, indent=2) + "\n").encode("utf-8"))
|
|
623
|
+
return state
|
|
624
|
+
|
|
625
|
+
|
|
626
|
+
def parser():
|
|
627
|
+
p = argparse.ArgumentParser(description=__doc__)
|
|
628
|
+
p.add_argument("--deck", required=True, type=Path)
|
|
629
|
+
sub = p.add_subparsers(dest="cmd", required=True)
|
|
630
|
+
sub.add_parser("edit-outline").add_argument("--file", required=True, type=Path)
|
|
631
|
+
brand = sub.add_parser("brand-create")
|
|
632
|
+
brand.add_argument("--file", required=True, type=Path)
|
|
633
|
+
brand.add_argument("--workspace", required=True, type=Path)
|
|
634
|
+
sub.add_parser("inspect-native").add_argument("--number", type=int, required=True)
|
|
635
|
+
sub.add_parser("approve-images").add_argument("--number", type=int)
|
|
636
|
+
for cmd in ["brand-list", "status", "export-images", "editable-finalize", "preview-editable"]:
|
|
637
|
+
sub.add_parser(cmd)
|
|
638
|
+
revise = sub.add_parser("revise-pages")
|
|
639
|
+
revise.add_argument("--feedback")
|
|
640
|
+
revise.add_argument("--restyle", action="store_true")
|
|
641
|
+
revise.add_argument("--revision", type=int)
|
|
642
|
+
revise.add_argument("--number", required=True, type=int, action="append")
|
|
643
|
+
outline = sub.add_parser("outline")
|
|
644
|
+
outline.add_argument("--file", required=True, type=Path)
|
|
645
|
+
outline.add_argument("--ratio", choices=CANVASES, default="16:9")
|
|
646
|
+
confirm = sub.add_parser("approve-outline")
|
|
647
|
+
confirm.add_argument("--revision", required=True)
|
|
648
|
+
confirm.add_argument("--count", required=True, type=int, choices=(1, 2, 3))
|
|
649
|
+
confirm.add_argument("--sample-page", required=True, type=int)
|
|
650
|
+
def render_args(command):
|
|
651
|
+
command.add_argument("--model", help="Model alias for an explicitly configured environment channel")
|
|
652
|
+
command.add_argument("--size", help="Override API size, e.g. auto on providers with fixed sizes")
|
|
653
|
+
command.add_argument("--quality", choices=["low", "medium", "high", "auto"], default="high")
|
|
654
|
+
command.add_argument("--ref", action="append", default=[], help="Task-local asset, relative to deck")
|
|
655
|
+
|
|
656
|
+
region = sub.add_parser("propose-region")
|
|
657
|
+
region.add_argument("--number", required=True, type=int)
|
|
658
|
+
region.add_argument("--revision", required=True, type=int)
|
|
659
|
+
region.add_argument("--box", nargs=4, required=True, type=int)
|
|
660
|
+
region.add_argument("--feedback", required=True)
|
|
661
|
+
render_args(region)
|
|
662
|
+
resolve = sub.add_parser("resolve-region")
|
|
663
|
+
resolve.add_argument("--proposal", required=True)
|
|
664
|
+
resolve.add_argument("--choice", required=True, choices=["keep", "apply"])
|
|
665
|
+
for cmd in ("add-draft", "render-draft"):
|
|
666
|
+
draft = sub.add_parser(cmd)
|
|
667
|
+
draft.add_argument("--number", required=True, type=int)
|
|
668
|
+
draft.add_argument("--from-sha256")
|
|
669
|
+
draft.add_argument("--style", required=True, type=Path)
|
|
670
|
+
if cmd == "add-draft":
|
|
671
|
+
draft.add_argument("--image", required=True, type=Path)
|
|
672
|
+
else:
|
|
673
|
+
draft.add_argument("--feedback")
|
|
674
|
+
render_args(draft)
|
|
675
|
+
sub.add_parser("new-design-set").add_argument("--review-id")
|
|
676
|
+
restore = sub.add_parser("restore-draft")
|
|
677
|
+
restore.add_argument("--number", type=int, required=True)
|
|
678
|
+
restore.add_argument("--version", required=True)
|
|
679
|
+
restore.add_argument("--from-sha256", required=True)
|
|
680
|
+
choose = sub.add_parser("approve-style")
|
|
681
|
+
choose.add_argument("--number", required=True, type=int)
|
|
682
|
+
choose.add_argument("--sha256", required=True)
|
|
683
|
+
for cmd in ("page-prompt", "add-page", "render-page"):
|
|
684
|
+
p2 = sub.add_parser(cmd)
|
|
685
|
+
p2.add_argument("--number", required=True, type=int)
|
|
686
|
+
if cmd == "add-page":
|
|
687
|
+
p2.add_argument("--image", required=True, type=Path)
|
|
688
|
+
elif cmd == "render-page":
|
|
689
|
+
render_args(p2)
|
|
690
|
+
sub.add_parser("editable-prepare").add_argument("--backend", choices=["openai-compatible-api", "editppt-image-cli"])
|
|
691
|
+
return p
|
|
692
|
+
|
|
693
|
+
|
|
694
|
+
def main():
|
|
695
|
+
args = parser().parse_args()
|
|
696
|
+
root = args.deck.resolve()
|
|
697
|
+
try:
|
|
698
|
+
if args.cmd in {"status", "page-prompt", "brand-list", "brand-create", "inspect-native"}:
|
|
699
|
+
result = update(root, args)
|
|
700
|
+
else:
|
|
701
|
+
with lock(root):
|
|
702
|
+
result = update(root, args)
|
|
703
|
+
print(json.dumps(result, ensure_ascii=False, indent=2))
|
|
704
|
+
except (ValueError, OSError, ImportError, subprocess.CalledProcessError) as e:
|
|
705
|
+
print(f"Oil Slide: {e}", file=sys.stderr)
|
|
706
|
+
return 1
|
|
707
|
+
return 0
|
|
708
|
+
|
|
709
|
+
|
|
710
|
+
if __name__ == "__main__":
|
|
711
|
+
sys.exit(main())
|