xonecas.io
7517
Cd

clanker-and-the-dev / commit 893385e

chore: wipe out the old gen

xonecas2026-06-10 893385e98fdb61b1291640018e5009bc7af44882 parent 5c72998

15 files changed

This diff is too big to show in full. The first 1000 lines are below, and every file is listed with its counts.

.agents/skills/add-new-comic/SKILL.md+0−194
@@ -1,194 +0,0 @@
1----
2-name: add-new-comic
3-description: Use when the user wants to add, generate, render, regenerate, or submit a new Clanker and the Dev comic/joke. This skill is the formal entrypoint for comic generation and uses the SDXL image pipeline in this skill folder.
4-allowed-tools: Read, Write, Edit, Bash
5----
6-
7-# Add a New Clanker and the Dev Comic
8-
9-This repo is a Jekyll/GitHub Pages comic-strip blog. Comic generation is driven by this agent skill and the Python SDXL pipeline in `scripts/`.
10-
11-The skill is the only supported generation path. Do not use the old deterministic SVG renderer or `job.sh` workflow.
12-
13-## Important project rules
14-
15-- Do not install Ruby gems locally.
16-- Local Jekyll preview runs through Docker with `./dev.sh`.
17-- Use `uv` for Python environment management and Python package installation.
18-- Python generation code lives inside this skill folder.
19-- Generated image assets live under `assets/comics/<slug>/`.
20-- Generated Jekyll posts live in `_posts/`.
21-- Comic specs live in `comic/specs/` and use the current image-generation schema in `comic/schema.md`.
22-- Do not ask Stable Diffusion to render dialogue, captions, terminal text, lettering, title cards, headers, footers, watermarks, or UI chrome. The Python compositor adds readable comic text with Pillow, and the site adds page chrome with HTML/CSS.
23-- Default SDXL model: `stabilityai/stable-diffusion-xl-base-1.0`.
24-- Default IP-Adapter: `h94/IP-Adapter`, subfolder `sdxl_models`, weight `ip-adapter_sdxl.bin`.
25-- Default IP-Adapter reference images: `art-reference/training-reference.png` plus `art-reference/ip-character-reference.png`.
26-- The generator extracts per-panel crops from the training sheet plus character-only crops from `ip-character-reference.png`, then averages IP-Adapter image embeddings so the model sees the characters without copying sheet grids/cards.
27-- ControlNet is enabled by default with reference-derived layout guides (`control-panel-XX.png`) to stabilize composition and character proportions.
28-- The compositor converts soft SDXL output back into crisp terminal line art, clips generated strokes to the reference-derived guide to remove scanlines/blobs/header-footer bars, and merges that guide to repair character drift.
29-- Model CPU offload is enabled by default so SDXL/IP-Adapter/ControlNet can run on a 12 GB GPU.
30-
31-## Standard workflow
32-
33-### 1. Turn the user's joke into an image-generation spec
34-
35-Create or update:
36-
37-```txt
38-comic/specs/<slug>.json
39-```
40-
41-The spec must be valid JSON only. It should follow `comic/schema.md`.
42-
43-Use this shape:
44-
45-```json
46-{
47- "title": "My Great Joke",
48- "slug": "my-great-joke",
49- "timestamp": "YYYY-MM-DD",
50- "credit": "User / handle / inspiration",
51- "summary": "One sentence premise for the whole strip.",
52- "generation": {
53- "modelId": "stabilityai/stable-diffusion-xl-base-1.0",
54- "ipAdapterRepo": "h94/IP-Adapter",
55- "ipAdapterSubfolder": "sdxl_models",
56- "ipAdapterWeight": "ip-adapter_sdxl.bin",
57- "ipAdapterScale": 0.82,
58- "referenceImages": [
59- "art-reference/training-reference.png",
60- "art-reference/ip-character-reference.png"
61- ],
62- "referenceCropMode": "auto",
63- "width": 1024,
64- "height": 768,
65- "steps": 34,
66- "guidanceScale": 5.0,
67- "enableControlNet": true,
68- "controlNetModelId": "diffusers/controlnet-canny-sdxl-1.0",
69- "controlGuideMode": "layout",
70- "controlNetScale": 0.88,
71- "controlNetStart": 0.0,
72- "controlNetEnd": 0.90,
73- "artPostprocessMode": "terminal-lineart",
74- "lineArtThreshold": 112,
75- "lineArtStroke": 3
76- },
77- "panels": [
78- {
79- "artPrompt": "Dev leans toward a terminal laptop while Clanker, a boxy robot assistant, offers help in a pure black terminal room.",
80- "composition": "Dev on the left, Clanker on the right, laptop in the foreground, empty dark upper area for speech bubbles.",
81- "shot": "medium",
82- "dialogue": [
83- { "speaker": "dev", "text": "Can you make this simpler?" },
84- { "speaker": "clanker", "text": "Absolutely." }
85- ],
86- "terminalLines": ["$ git status", "legacy code: haunted"]
87- }
88- ]
89-}
90-```
91-
92-Guidelines:
93-
94-- Usually make 3–5 panels.
95-- Preserve the user's core joke and attribution.
96-- Keep dialogue short; the compositor has limited bubble space.
97-- `artPrompt` describes only visuals, acting, mood, props, and setting.
98-- Never put dialogue text, title/header/footer copy, watermarks, or UI chrome inside `artPrompt`; comic text is overlaid later and page chrome is HTML/CSS.
99-- Prompt for the recurring characters explicitly: Dev is a human developer with simple glasses; Clanker is a boxy robot assistant with screen eyes and antenna.
100-- Include composition directions such as character positions and reserved empty space for bubbles.
101-- Use optional explicit `seed` values only for debugging/reruns. Default generation is non-deterministic.
102-
103-### 2. Generate the comic with uv
104-
105-From the repo root, run:
106-
107-```bash
108-HF_HOME="$PWD/.cache/huggingface" PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True uv run --project .agents/skills/add-new-comic python .agents/skills/add-new-comic/scripts/generate_comic.py comic/specs/<slug>.json
109-```
110-
111-This creates or updates:
112-
113-```txt
114-assets/comics/<slug>/control-panel-01.png
115-assets/comics/<slug>/raw-panel-01.png
116-assets/comics/<slug>/panel-01.png
117-assets/comics/<slug>/panel-02.png
118-assets/comics/<slug>/strip.png
119-assets/comics/<slug>/generation.json
120-_posts/YYYY-MM-DD-<slug>.md
121-```
122-
123-Notes:
124-
125-- `control-panel-XX.png` files are generated ControlNet layout guides for review/debugging.
126-- Raw panels are SDXL output before text/borders.
127-- Final `panel-XX.png` files include cleaned line art, the merged reference guide, composited comic lettering/code snippets, and a simple panel frame.
128-- `strip.png` is a panels-only comic image with no baked-in title/header/footer/metadata chrome; the Jekyll page adds those with HTML/CSS.
129-- Strip composition uses Pillow; no ImageMagick dependency is required for this step.
130-- The first run downloads Hugging Face model weights and may require accepted model terms / Hugging Face credentials in the environment.
131-- SDXL + IP-Adapter + ControlNet is VRAM-heavy; generation uses model CPU offload and one isolated worker process per panel to avoid VRAM accumulation.
132-
133-### 3. Review generated files
134-
135-Check status and diff:
136-
137-```bash
138-git status
139-git diff
140-```
141-
142-Review:
143-
144-```txt
145-comic/specs/<slug>.json
146-assets/comics/<slug>/strip.png
147-_posts/YYYY-MM-DD-<slug>.md
148-```
149-
150-If the result is not good enough:
151-
152-1. Edit visual prompts, composition, dialogue length, reference strength, or generation settings in the spec.
153-2. Re-run the `uv run --project ... generate_comic.py ...` command.
154-
155-### 4. Preview locally when useful
156-
157-Use Docker only:
158-
159-```bash
160-./dev.sh
161-```
162-
163-Then open:
164-
165-```txt
166-http://localhost:4000
167-```
168-
169-Do not install or run Bundler/Ruby gems locally outside Docker.
170-
171-### 5. Commit or prepare for PR
172-
173-If the user asks to commit, include the generated spec, assets, and post:
174-
175-```bash
176-git add comic/specs assets/comics _posts
177-git commit -m "Add <comic title> comic"
178-```
179-
180-If the user is contributing from a fork, remind them to open a pull request with their generated spec, image assets, and post.
181-
182-## Regenerating existing comics
183-
184-To regenerate an existing comic, update its spec in `comic/specs/<slug>.json`, then run:
185-
186-```bash
187-HF_HOME="$PWD/.cache/huggingface" PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True uv run --project .agents/skills/add-new-comic python .agents/skills/add-new-comic/scripts/generate_comic.py comic/specs/<slug>.json
188-```
189-
190-Existing generated SVG posts should be replaced by image posts that embed the panels-only strip through `relative_url`:
191-
192-```liquid
193-{{ '/assets/comics/<slug>/strip.png' | relative_url }}
194-```
.agents/skills/add-new-comic/pyproject.toml+0−19
@@ -1,19 +0,0 @@
1-[project]
2-name = "clanker-comic-generator"
3-version = "0.1.0"
4-description = "SDXL image generation pipeline for Clanker and the Dev comics"
5-requires-python = ">=3.10,<3.13"
6-dependencies = [
7- "torch",
8- "diffusers>=0.29.0",
9- "transformers",
10- "accelerate",
11- "safetensors",
12- "Pillow",
13- "pydantic>=2",
14- "opencv-python",
15- "peft",
16-]
17-
18-[tool.uv]
19-package = false
.agents/skills/add-new-comic/requirements.txt+0−9
@@ -1,9 +0,0 @@
1-torch
2-diffusers>=0.29.0
3-transformers
4-accelerate
5-safetensors
6-Pillow
7-pydantic>=2
8-opencv-python
9-peft
.agents/skills/add-new-comic/scripts/composite_panel.py+0−340
@@ -1,340 +0,0 @@
1-from __future__ import annotations
2-
3-import re
4-import textwrap
5-from pathlib import Path
6-
7-from PIL import Image, ImageChops, ImageDraw, ImageFont, ImageFilter, ImageOps
8-
9-from models import DialogueLine, PanelSpec
10-
11-GREEN = "#00ff66"
12-LIGHT_GREEN = "#7cff8a"
13-DARK = "#020806"
14-BLACK_ALPHA = (0, 0, 0, 205)
15-
16-
17-def clean_markup(text: str) -> str:
18- return re.sub(r"[*_`]+", "", text).strip()
19-
20-
21-def load_font(project_root: Path, size: int) -> ImageFont.FreeTypeFont | ImageFont.ImageFont:
22- font_path = project_root / "assets" / "fonts" / "VT323-Regular.ttf"
23- if font_path.exists():
24- return ImageFont.truetype(str(font_path), size=size)
25- return ImageFont.load_default()
26-
27-
28-def terminal_line_art(raw: Image.Image, threshold: int = 95, stroke: int = 3) -> Image.Image:
29- """Convert soft SDXL output into the crisp green-on-black reference style."""
30- raw = ImageOps.exif_transpose(raw).convert("RGB")
31- try:
32- import cv2
33- import numpy as np
34-
35- gray = np.array(ImageOps.autocontrast(ImageOps.grayscale(raw), cutoff=1))
36- mask = (gray > threshold).astype(np.uint8) * 255
37- mask = cv2.medianBlur(mask, 3)
38-
39- height, width = mask.shape
40- # Panel specs reserve the upper band for compositor-owned bubbles.
41- # Clearing it removes common SDXL hallucinations copied from reference
42- # sheet headers/frames without touching the staged characters.
43- mask[: int(height * 0.28), :] = 0
44- clean_mask = np.zeros_like(mask)
45- keep_filled = np.zeros_like(mask)
46- label_count, labels, stats, _ = cv2.connectedComponentsWithStats(mask, connectivity=8)
47- for label in range(1, label_count):
48- x, y, w, h, area = stats[label]
49- if area < 8:
50- continue
51- # SDXL sometimes invents a full panel/grid because the reference
52- # sheets contain panels. Drop huge border components; our compositor
53- # draws the real frame afterward.
54- if w > width * 0.82 and h > height * 0.58:
55- continue
56- # Reject thin generated header/footer bars copied from reference
57- # sheets, screenshots, or UI mockups. Real comic lettering is drawn
58- # later by the compositor.
59- if w > width * 0.45 and h < height * 0.06 and (y < height * 0.18 or y + h > height * 0.82):
60- continue
61- if h > height * 0.46 and w < width * 0.18:
62- continue
63- if y < height * 0.50 and y + h < height * 0.66 and w > width * 0.16 and h > height * 0.15:
64- continue
65- component = labels == label
66- clean_mask[component] = 255
67- # Preserve small filled UI/robot-eye shapes instead of skeletonizing
68- # them into X marks.
69- if area <= 1200 and w <= 52 and h <= 52:
70- keep_filled[component] = 255
71- mask = clean_mask
72-
73- skeleton = np.zeros(mask.shape, np.uint8)
74- element = cv2.getStructuringElement(cv2.MORPH_CROSS, (3, 3))
75- working = mask.copy()
76- while cv2.countNonZero(working):
77- eroded = cv2.erode(working, element)
78- opened = cv2.dilate(eroded, element)
79- skeleton = cv2.bitwise_or(skeleton, cv2.subtract(working, opened))
80- working = eroded
81-
82- line_mask = cv2.bitwise_or(skeleton, keep_filled)
83- if stroke > 1:
84- kernel = np.ones((stroke, stroke), np.uint8)
85- line_mask = cv2.dilate(line_mask, kernel, iterations=1)
86-
87- canvas = np.zeros((*line_mask.shape, 3), dtype=np.uint8)
88- canvas[:] = (2, 8, 6)
89- canvas[line_mask > 0] = (0, 255, 102)
90- return Image.fromarray(canvas, "RGB")
91- except Exception:
92- gray = ImageOps.autocontrast(ImageOps.grayscale(raw), cutoff=1)
93- mask = gray.point(lambda p: 255 if p > threshold else 0)
94- if stroke > 1:
95- mask = mask.filter(ImageFilter.MaxFilter(stroke if stroke % 2 else stroke + 1))
96- return Image.composite(Image.new("RGB", raw.size, GREEN), Image.new("RGB", raw.size, DARK), mask)
97-
98-
99-def prepare_art(
100- raw: Image.Image,
101- mode: str = "terminal-lineart",
102- threshold: int = 95,
103- stroke: int = 3,
104-) -> Image.Image:
105- if mode == "none":
106- return ImageOps.exif_transpose(raw).convert("RGB")
107- if mode == "monochrome":
108- return ImageOps.colorize(ImageOps.grayscale(raw), black=DARK, white=GREEN)
109- return terminal_line_art(raw, threshold=threshold, stroke=stroke)
110-
111-
112-def control_guide_line_art(control_path: Path, size: tuple[int, int]) -> Image.Image | None:
113- if not control_path.exists():
114- return None
115- guide = Image.open(control_path).convert("L")
116- if guide.size != size:
117- guide = guide.resize(size, Image.Resampling.LANCZOS)
118- mask = guide.point(lambda p: 255 if p > 24 else 0)
119- if not mask.getbbox():
120- return None
121- return Image.composite(Image.new("RGB", size, GREEN), Image.new("RGB", size, DARK), mask)
122-
123-
124-def control_guide_mask(control_path: Path, size: tuple[int, int]) -> Image.Image | None:
125- if not control_path.exists():
126- return None
127- guide = Image.open(control_path).convert("L")
128- if guide.size != size:
129- guide = guide.resize(size, Image.Resampling.LANCZOS)
130- mask = guide.point(lambda p: 255 if p > 24 else 0)
131- if not mask.getbbox():
132- return None
133- return mask
134-
135-
136-def line_mask_from_terminal_art(art: Image.Image) -> Image.Image:
137- gray = ImageOps.grayscale(art.convert("RGB"))
138- return gray.point(lambda p: 255 if p > 28 else 0)
139-
140-
141-def mask_to_terminal_art(mask: Image.Image, size: tuple[int, int]) -> Image.Image:
142- if mask.size != size:
143- mask = mask.resize(size, Image.Resampling.NEAREST)
144- return Image.composite(Image.new("RGB", size, GREEN), Image.new("RGB", size, DARK), mask)
145-
146-
147-def filter_line_art_to_control_guide(art: Image.Image, guide_mask: Image.Image, padding: int = 0) -> Image.Image:
148- """Keep generated strokes only when they support the reference-derived guide.
149-
150- SDXL often creates faint CRT bands, window/card rectangles, and floating blobs
151- because the references are terminal-style screenshots. The guide already has
152- the desired character/prop sketch, so generated strokes are treated as local
153- embellishment and are clipped back to the guide before the guide is merged.
154- """
155- try:
156- import cv2
157- import numpy as np
158-
159- raw_mask = np.array(line_mask_from_terminal_art(art), dtype=np.uint8)
160- guide = np.array(guide_mask, dtype=np.uint8)
161- kernel_size = max(1, padding * 2 + 1)
162- kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (kernel_size, kernel_size))
163- keep_zone = cv2.dilate(guide, kernel, iterations=1)
164- clipped = cv2.bitwise_and(raw_mask, keep_zone)
165-
166- cleaned = np.zeros_like(clipped)
167- label_count, labels, stats, _ = cv2.connectedComponentsWithStats(clipped, connectivity=8)
168- for label in range(1, label_count):
169- x, y, w, h, area = stats[label]
170- if area < 8:
171- continue
172- component = labels == label
173- density = area / max(1, w * h)
174-
175- # Filled SDXL blobs make the final panels look less like the clean
176- # reference sketches. The exact guide is merged later, so dense raw
177- # fills can be rejected even when they overlap a desired guide mark.
178- if density > 0.34 and area > 24:
179- continue
180- if w > raw_mask.shape[1] * 0.38 and h < raw_mask.shape[0] * 0.04:
181- continue
182- cleaned[component] = 255
183-
184- return mask_to_terminal_art(Image.fromarray(cleaned, "L"), art.size)
185- except Exception:
186- clipped = ImageChops.multiply(line_mask_from_terminal_art(art), guide_mask.filter(ImageFilter.MaxFilter(padding | 1)))
187- return mask_to_terminal_art(clipped, art.size)
188-
189-
190-def merge_control_guide(art: Image.Image, raw_art_path: Path, panel_number: int) -> Image.Image:
191- control_path = raw_art_path.with_name(f"control-panel-{panel_number:02d}.png")
192- guide = control_guide_line_art(control_path, art.size)
193- guide_mask = control_guide_mask(control_path, art.size)
194- if guide is None or guide_mask is None:
195- return art
196- # The ControlNet guide is derived from art-reference sprites. Keeping it in
197- # the final line art repairs SDXL drift. Generated strokes are now kept only
198- # to that guide, which removes scanlines/floating artifacts while retaining
199- # the cleaned SDXL panel generation as the raw/debug artifact.
200- filtered = filter_line_art_to_control_guide(art.convert("RGB"), guide_mask)
201- return ImageChops.lighter(filtered, guide)
202-
203-
204-def wrap_for_width(draw: ImageDraw.ImageDraw, text: str, font: ImageFont.ImageFont, max_width: int) -> list[str]:
205- text = clean_markup(text)
206- words = text.split()
207- lines: list[str] = []
208- current: list[str] = []
209- for word in words:
210- candidate = " ".join([*current, word])
211- if draw.textlength(candidate, font=font) <= max_width or not current:
212- current.append(word)
213- else:
214- lines.append(" ".join(current))
215- current = [word]
216- if current:
217- lines.append(" ".join(current))
218- return lines or [""]
219-
220-
221-def draw_tail(draw: ImageDraw.ImageDraw, box: tuple[int, int, int, int], speaker: str, outline: str):
222- x0, y0, x1, y1 = box
223- if speaker == "dev":
224- points = [(x0 + 80, y1 - 2), (x0 + 105, y1 + 34), (x0 + 145, y1 - 2)]
225- elif speaker == "clanker":
226- points = [(x1 - 145, y1 - 2), (x1 - 105, y1 + 34), (x1 - 80, y1 - 2)]
227- else:
228- return
229- draw.polygon(points, fill=BLACK_ALPHA, outline=outline)
230-
231-
232-def draw_bubble(
233- overlay: Image.Image,
234- text: str,
235- speaker: str,
236- box: tuple[int, int, int, int],
237- font: ImageFont.ImageFont,
238-):
239- draw = ImageDraw.Draw(overlay)
240- x0, y0, x1, y1 = box
241- draw.rounded_rectangle(box, radius=18, fill=BLACK_ALPHA, outline=GREEN, width=4)
242- draw_tail(draw, box, speaker, GREEN)
243-
244- label = "" if speaker == "narrator" else f"{speaker.upper()}: "
245- lines = wrap_for_width(draw, f"{label}{text}", font, (x1 - x0) - 36)
246- line_height = int(font.size * 0.9) if hasattr(font, "size") else 24
247- total_height = len(lines) * line_height
248- y = y0 + max(12, ((y1 - y0) - total_height) // 2)
249- for line in lines:
250- draw.text((x0 + 18, y), line, font=font, fill=LIGHT_GREEN)
251- y += line_height
252-
253-
254-def bubble_box(index: int, total: int, speaker: str, image_width: int) -> tuple[int, int, int, int]:
255- top = 28 + index * 116
256- height = 92
257- margin = 34
258- if speaker == "dev":
259- return (margin, top, int(image_width * 0.62), top + height)
260- if speaker == "clanker":
261- return (int(image_width * 0.38), top, image_width - margin, top + height)
262- return (margin, top, image_width - margin, top + height)
263-
264-
265-def draw_terminal(
266- overlay: Image.Image,
267- lines: list[str],
268- project_root: Path,
269-):
270- if not lines:
271- return
272- draw = ImageDraw.Draw(overlay)
273- width, height = overlay.size
274- font = load_font(project_root, 34)
275- clean_lines = [clean_markup(line) for line in lines[:4]]
276- line_height = 35
277- x = 56
278- y = height - (len(clean_lines) * line_height) - 48
279- # Render only the joke's code/output text. Avoid terminal-window chrome,
280- # title bars, boxed footers, or UI panels inside the comic image.
281- for line in clean_lines:
282- shortened = textwrap.shorten(line, width=42, placeholder="…")
283- draw.text(
284- (x, y),
285- shortened,
286- font=font,
287- fill=LIGHT_GREEN,
288- stroke_width=2,
289- stroke_fill=(0, 0, 0, 230),
290- )
291- y += line_height
292-
293-
294-def composite_panel(
295- raw_art_path: Path,
296- output_path: Path,
297- panel: PanelSpec,
298- project_root: Path,
299- panel_number: int,
300- art_postprocess_mode: str = "terminal-lineart",
301- line_art_threshold: int = 95,
302- line_art_stroke: int = 3,
303-) -> Path:
304- raw = Image.open(raw_art_path).convert("RGB")
305- base_art = prepare_art(
306- raw,
307- mode=art_postprocess_mode,
308- threshold=line_art_threshold,
309- stroke=line_art_stroke,
310- )
311- if art_postprocess_mode == "terminal-lineart":
312- base_art = merge_control_guide(base_art, raw_art_path, panel_number)
313- base = base_art.convert("RGBA")
314- overlay = Image.new("RGBA", base.size, (0, 0, 0, 0))
315- draw = ImageDraw.Draw(overlay)
316- width, height = base.size
317-
318- # Simple comic panel frame. No baked-in panel number, title card, header,
319- # footer, or site chrome; the page provides that in HTML.
320- draw.rectangle((8, 8, width - 8, height - 8), outline=GREEN, width=3)
321-
322- bubble_font = load_font(project_root, 42)
323- items: list[DialogueLine | tuple[str, str]] = []
324- if panel.caption:
325- items.append(("narrator", panel.caption))
326- items.extend(panel.dialogue)
327-
328- for index, item in enumerate(items[:3]):
329- if isinstance(item, tuple):
330- speaker, text = item
331- else:
332- speaker, text = item.speaker, item.text
333- draw_bubble(overlay, text, speaker, bubble_box(index, len(items), speaker, width), bubble_font)
334-
335- draw_terminal(overlay, panel.terminalLines, project_root)
336-
337- composed = Image.alpha_composite(base, overlay).convert("RGB")
338- output_path.parent.mkdir(parents=True, exist_ok=True)
339- composed.save(output_path, quality=95)
340- return output_path
.agents/skills/add-new-comic/scripts/generate_comic.py+0−199
@@ -1,199 +0,0 @@
1-from __future__ import annotations
2-
3-import argparse
4-import html
5-import json
6-import subprocess
7-import sys
8-from pathlib import Path
9-
10-from PIL import Image, ImageOps
11-
12-from composite_panel import composite_panel
13-from models import ComicSpec, load_spec
14-
15-
16-def default_project_root() -> Path:
17- current = Path(__file__).resolve()
18- for parent in current.parents:
19- if (parent / "_config.yml").exists() and (parent / "AGENTS.md").exists():
20- return parent
21- raise RuntimeError("Could not locate repository root from skill script path")
22-
23-
24-def compose_strip(_comic: ComicSpec, panel_paths: list[Path], output_path: Path, _project_root: Path) -> Path:
25- """Compose a panels-only comic image.
26-
27- Page titles, credits, labels, and other site chrome belong in HTML/CSS, not
28- inside the generated PNG. The strip image should be reusable as comic art
29- without baked-in headers, footers, metadata, or branding bars.
30- """
31- output_path.parent.mkdir(parents=True, exist_ok=True)
32- gap = 16
33- panels = [Image.open(path).convert("RGB") for path in panel_paths]
34- if not panels:
35- raise ValueError("Cannot compose a strip with no panels")
36-
37- panel_width, panel_height = panels[0].size
38-
39- if len(panels) == 1:
40- rows = [[panels[0]]]
41- strip_width = panel_width
42- elif len(panels) == 5:
43- strip_width = panel_width * 2 + gap
44- wide_final = Image.new("RGB", (strip_width, panel_height), "#000000")
45- final_panel = ImageOps.contain(panels[4], (strip_width, panel_height), method=Image.Resampling.LANCZOS)
46- wide_final.paste(final_panel, ((strip_width - final_panel.width) // 2, (panel_height - final_panel.height) // 2))
47- rows = [[panels[0], panels[1]], [panels[2], panels[3]], [wide_final]]
48- elif len(panels) == 3:
49- rows = [panels]
50- strip_width = panel_width * 3 + gap * 2
51- else:
52- cols = 2 if len(panels) in (2, 4) else 3
53- rows = [panels[i : i + cols] for i in range(0, len(panels), cols)]
54- strip_width = panel_width * cols + gap * (cols - 1)
55-
56- strip_height = sum(row[0].height for row in rows) + gap * (len(rows) - 1)
57- strip = Image.new("RGB", (strip_width, strip_height), "#000000")
58-
59- y = 0
60- for row in rows:
61- row_width = sum(panel.width for panel in row) + gap * (len(row) - 1)
62- x = (strip_width - row_width) // 2
63- for panel in row:
64- strip.paste(panel, (x, y))
65- x += panel.width + gap
66- y += row[0].height + gap
67-
68- strip.save(output_path)
69- return output_path
70-
71-
72-def write_post(comic: ComicSpec, strip_path: Path, project_root: Path) -> Path:
73- post_path = project_root / "_posts" / f"{comic.timestamp}-{comic.slug}.md"
74- asset_path = "/" + strip_path.relative_to(project_root).as_posix()
75- alt = html.escape(f"{comic.title} comic strip", quote=True)
76- credit = f"\n<p class=\"comic-credit\">Credit: {html.escape(comic.credit)}</p>\n" if comic.credit else ""
77- title_yaml = comic.title.replace('"', '\\"')
78- body = f"""---
79-layout: post
80-title: "{title_yaml}"
81----
82-
83-<div class="comic-strip image-comic">
84- <img src="{{{{ '{asset_path}' | relative_url }}}}" alt="{alt}">
85-</div>{credit}
86-"""
87- post_path.parent.mkdir(parents=True, exist_ok=True)
88- post_path.write_text(body, encoding="utf-8")
89- return post_path
90-
91-
92-def generate_panel_in_worker(
93- spec_path: Path,
94- panel_index: int,
95- raw_path: Path,
96- output_dir: Path,
97- project_root: Path,
98-) -> int:
99- seed_path = output_dir / f"seed-panel-{panel_index:02d}.json"
100- worker_path = Path(__file__).with_name("generate_panel_worker.py")
101- subprocess.run(
102- [
103- sys.executable,
104- str(worker_path),
105- str(spec_path),
106- str(panel_index),
107- str(raw_path),
108- "--project-root",
109- str(project_root),
110- "--seed-output",
111- str(seed_path),
112- ],
113- check=True,
114- )
115- data = json.loads(seed_path.read_text(encoding="utf-8"))
116- seed_path.unlink(missing_ok=True)
117- return int(data["seed"])
118-
119-
120-def write_generation_metadata(output_dir: Path, panel_seeds: list[int], comic: ComicSpec) -> Path:
121- metadata_path = output_dir / "generation.json"
122- metadata = {
123- "title": comic.title,
124- "slug": comic.slug,
125- "timestamp": comic.timestamp,
126- "modelId": comic.generation.modelId,
127- "ipAdapterRepo": comic.generation.ipAdapterRepo,
128- "ipAdapterWeight": comic.generation.ipAdapterWeight,
129- "ipAdapterScale": comic.generation.ipAdapterScale,
130- "referenceImages": comic.generation.referenceImages,
131- "referenceCropMode": comic.generation.referenceCropMode,
132- "enableControlNet": comic.generation.enableControlNet,
133- "controlNetModelId": comic.generation.controlNetModelId if comic.generation.enableControlNet else None,
134- "controlGuideMode": comic.generation.controlGuideMode if comic.generation.enableControlNet else None,
135- "controlNetScale": comic.generation.controlNetScale if comic.generation.enableControlNet else None,
136- "controlNetStart": comic.generation.controlNetStart if comic.generation.enableControlNet else None,
137- "controlNetEnd": comic.generation.controlNetEnd if comic.generation.enableControlNet else None,
138- "artPostprocessMode": comic.generation.artPostprocessMode,
139- "lineArtThreshold": comic.generation.lineArtThreshold,
140- "lineArtStroke": comic.generation.lineArtStroke,
141- "panelSeeds": panel_seeds,
142- }
143- metadata_path.write_text(json.dumps(metadata, indent=2) + "\n", encoding="utf-8")
144- return metadata_path
145-
146-
147-def generate_comic(spec_path: Path, project_root: Path) -> None:
148- comic = load_spec(spec_path)
149- output_dir = project_root / "assets" / "comics" / comic.slug
150- output_dir.mkdir(parents=True, exist_ok=True)
151-
152- panel_paths: list[Path] = []
153- panel_seeds: list[int] = []
154- for index, panel in enumerate(comic.panels, start=1):
155- raw_path = output_dir / f"raw-panel-{index:02d}.png"
156- panel_path = output_dir / f"panel-{index:02d}.png"
157- seed = generate_panel_in_worker(spec_path, index, raw_path, output_dir, project_root)
158- composite_panel(
159- raw_path,
160- panel_path,
161- panel,
162- project_root,
163- index,
164- comic.generation.artPostprocessMode,
165- comic.generation.lineArtThreshold,
166- comic.generation.lineArtStroke,
167- )
168- panel_paths.append(panel_path)
169- panel_seeds.append(seed)
170- print(f"Generated {panel_path.relative_to(project_root)} with seed {seed}")
171-
172- strip_path = compose_strip(comic, panel_paths, output_dir / "strip.png", project_root)
173- post_path = write_post(comic, strip_path, project_root)
174- metadata_path = write_generation_metadata(output_dir, panel_seeds, comic)
175-
176- print(f"Wrote {strip_path.relative_to(project_root)}")
177- print(f"Wrote {post_path.relative_to(project_root)}")
178- print(f"Wrote {metadata_path.relative_to(project_root)}")
179-
180-
181-def parse_args() -> argparse.Namespace:
182- parser = argparse.ArgumentParser(description="Generate a Clanker and the Dev SDXL comic from a JSON spec")
183- parser.add_argument("spec", type=Path, help="Path to comic image-generation spec JSON")
184- parser.add_argument(
185- "--project-root",
186- type=Path,
187- default=default_project_root(),
188- help="Repository root. Defaults to the parent repo of this skill.",
189- )
190- return parser.parse_args()
191-
192-
193-def main() -> None:
194- args = parse_args()
195- generate_comic(args.spec.resolve(), args.project_root.resolve())
196-
197-
198-if __name__ == "__main__":
199- main()
.agents/skills/add-new-comic/scripts/generate_panel.py+0−857
@@ -1,857 +0,0 @@
1-from __future__ import annotations
2-
3-import random
4-import re
5-from pathlib import Path
6-
7-from PIL import Image, ImageDraw, ImageOps
8-
9-from models import ComicSpec, GenerationConfig, PanelSpec
10-
11-_PIPELINE = None
12-_PIPELINE_KEY = None
13-
14-STYLE_PROMPT = (
15- "single plain wordless comic illustration, clean green line sketch on solid black background, "
16- "thin unfilled strokes, simple Dev, boxy Clanker, comic art only"
17-)
18-
19-# Normalized crop boxes for art-reference/training-reference.png. The sheet is
20-# intentionally clean and black-backed; cropping lets IP-Adapter see large
21-# character examples instead of a tiny downscaled full character sheet.
22-TRAINING_REFERENCE_CROPS: dict[str, tuple[float, float, float, float]] = {
23- "clanker_neutral_body": (0.013, 0.026, 0.101, 0.271),
24- "clanker_happy_body": (0.106, 0.026, 0.193, 0.271),
25- "clanker_side_body": (0.382, 0.026, 0.430, 0.270),
26- "clanker_at_laptop": (0.720, 0.043, 0.859, 0.272),
27- "clanker_neutral_face": (0.019, 0.297, 0.100, 0.492),
28- "clanker_happy_face": (0.119, 0.298, 0.210, 0.492),
29- "clanker_thinking_face": (0.322, 0.300, 0.403, 0.492),
30- "clanker_concerned_face": (0.423, 0.299, 0.503, 0.492),
31- "clanker_overheated_face": (0.632, 0.300, 0.727, 0.492),
32- "clanker_heart_face": (0.749, 0.299, 0.829, 0.492),
33- "dev_neutral_body": (0.024, 0.523, 0.080, 0.729),
34- "dev_mug_body": (0.105, 0.523, 0.161, 0.729),
35- "dev_laptop_body": (0.286, 0.536, 0.370, 0.727),
36- "dev_seated_laptop": (0.387, 0.537, 0.508, 0.728),
37- "dev_thumbs_body": (0.544, 0.523, 0.618, 0.726),
38- "dev_excited_body": (0.796, 0.525, 0.885, 0.723),
39- "dev_running_body": (0.896, 0.526, 0.989, 0.723),
40- "dev_neutral_face": (0.020, 0.775, 0.084, 0.915),
41- "dev_happy_face": (0.106, 0.775, 0.170, 0.915),
42- "dev_confused_face": (0.193, 0.776, 0.257, 0.915),
43- "dev_frown_face": (0.279, 0.776, 0.343, 0.914),
44- "dev_panic_face": (0.443, 0.768, 0.537, 0.914),
45- "dev_love_face": (0.752, 0.762, 0.906, 0.917),
46-}
47-
48-# Normalized crop boxes for art-reference/ip-character-reference.png. The
49-# source file is a good high-quality style anchor, but the full image contains
50-# two large black character cards and baseline shadows that SDXL tends to copy
51-# as stray background panels. Auto-cropping feeds just the characters to
52-# IP-Adapter while keeping the high-resolution proportions/style signal.
53-IP_CHARACTER_REFERENCE_CROPS: dict[str, tuple[float, float, float, float]] = {
54- "ip_dev_full": (0.080, 0.085, 0.270, 0.555),
55- "ip_clanker_full": (0.385, 0.088, 0.620, 0.560),
56-}
57-
58-BASE_REFERENCE_CROPS = [
59- "dev_neutral_body",
60- "clanker_neutral_body",
61- "dev_laptop_body",
62- "clanker_happy_body",
63-]
64-
65-# Extra pose crops used only for auto ControlNet guides. These are cut from
66-# the clean art-reference sheets so the guide itself has the same proportions
67-# as the target comic instead of a generic stick-figure sketch.
68-CONTROL_REFERENCE_SPRITES: dict[str, tuple[str, tuple[float, float, float, float]]] = {
69- **{name: ("training-reference.png", box) for name, box in TRAINING_REFERENCE_CROPS.items()},
70- "dev_pose_overwhelmed": ("dev-poses-sheet.png", (0.845, 0.285, 0.940, 0.470)),
71- "dev_pose_collapsed": ("dev-poses-sheet.png", (0.345, 0.590, 0.485, 0.775)),
72- "dev_pose_dead": ("dev-poses-sheet.png", (0.505, 0.570, 0.640, 0.775)),
73- "dev_pose_slumped": ("dev-poses-sheet.png", (0.170, 0.600, 0.325, 0.755)),
74- "dev_pose_zombie": ("dev-poses-sheet.png", (0.655, 0.600, 0.790, 0.790)),
75-}
76-
77-_CONTROL_SPRITE_CACHE: dict[tuple[str, str], Image.Image] = {}
78-
79-
80-def _torch_dtype(torch, dtype_name: str):
81- return {
82- "float16": torch.float16,
83- "bfloat16": torch.bfloat16,
84- "float32": torch.float32,
85- }[dtype_name]
86-
87-
88-def _pipeline_key(config: GenerationConfig) -> tuple[object, ...]:
89- return (
90- config.modelId,
91- config.enableControlNet,
92- config.controlNetModelId,
93- config.ipAdapterRepo,
94- config.ipAdapterSubfolder,
95- config.ipAdapterWeight,
96- config.ipAdapterScale,
97- config.device,
98- config.torchDtype,
99- )
100-
101-
102-def load_pipeline(config: GenerationConfig):
103- global _PIPELINE, _PIPELINE_KEY
104- key = _pipeline_key(config)
105- if _PIPELINE is not None and _PIPELINE_KEY == key:
106- return _PIPELINE
107-
108- import torch
109- from diffusers import ControlNetModel, StableDiffusionXLControlNetPipeline, StableDiffusionXLPipeline
110-
111- if config.device == "cuda" and not torch.cuda.is_available():
112- raise RuntimeError("CUDA was requested but torch.cuda.is_available() is false")
113-
114- dtype = _torch_dtype(torch, config.torchDtype)
115- variant = "fp16" if config.torchDtype == "float16" else None
116-
117- if config.enableControlNet:
118- controlnet = ControlNetModel.from_pretrained(
119- config.controlNetModelId,
120- torch_dtype=dtype,
121- use_safetensors=True,
122- )
123- pipe = StableDiffusionXLControlNetPipeline.from_pretrained(
124- config.modelId,
125- controlnet=controlnet,
126- torch_dtype=dtype,
127- use_safetensors=True,
128- variant=variant,
129- )
130- else:
131- pipe = StableDiffusionXLPipeline.from_pretrained(
132- config.modelId,
133- torch_dtype=dtype,
134- use_safetensors=True,
135- variant=variant,
136- )
137-
138- pipe.load_ip_adapter(
139- config.ipAdapterRepo,
140- subfolder=config.ipAdapterSubfolder,
141- weight_name=config.ipAdapterWeight,
142- )
143- pipe.set_ip_adapter_scale(config.ipAdapterScale)
144-
145- if config.device == "cuda" and config.enableSequentialCpuOffload and hasattr(pipe, "enable_sequential_cpu_offload"):
146- # SDXL + IP-Adapter + ControlNet does not fit reliably in 12 GB with
147- # model-level offload. Sequential offload is slower but keeps the full
148- # quality path usable on the target RTX 3080 Ti.
149- pipe.enable_sequential_cpu_offload()
150- elif config.device == "cuda" and config.enableModelCpuOffload:
151- pipe.enable_model_cpu_offload()
152- else:
153- pipe.to(config.device)
154-
155- if config.enableVaeSlicing and hasattr(pipe, "enable_vae_slicing"):
156- pipe.enable_vae_slicing()
157- if config.enableVaeTiling and hasattr(pipe, "enable_vae_tiling"):
158- pipe.enable_vae_tiling()
159- if config.enableAttentionSlicing and hasattr(pipe, "enable_attention_slicing"):
160- pipe.enable_attention_slicing()
161-
162- _PIPELINE = pipe
163- _PIPELINE_KEY = key
164- return pipe
165-
166-
167-def release_pipeline(device: str = "cuda") -> None:
168- global _PIPELINE, _PIPELINE_KEY
169- if _PIPELINE is None:
170- return
171-
172- pipe = _PIPELINE
173- _PIPELINE = None
174- _PIPELINE_KEY = None
175-
176- try:
177- if hasattr(pipe, "maybe_free_model_hooks"):
178- pipe.maybe_free_model_hooks()
179- except Exception:
180- pass
181- try:
182- pipe.to("cpu")
183- except Exception:
184- pass
185-
186- del pipe
187-
188- import gc
189-
190- gc.collect()
191- if device == "cuda":
192- try:
193- import torch
194-
195- torch.cuda.empty_cache()
196- torch.cuda.ipc_collect()
197- except Exception:
198- pass
199-
200-
201-def compact_visual_text(text: str) -> str:
202- replacements = {
203- "Dev, a human software developer with simple rectangular glasses": "Dev",
204- "a human software developer with simple rectangular glasses": "Dev",
205- "Clanker, a helpful boxy robot assistant with screen eyes and antenna": "Clanker",
206- "Clanker, a boxy robot assistant with screen eyes and antenna": "Clanker",
207- "a helpful boxy robot assistant with screen eyes and antenna": "Clanker",
208- "a boxy robot assistant with screen eyes and antenna": "Clanker",
209- "pure black terminal room": "plain black room",
210- "pure black terminal workspace": "plain black workspace",
211- "dark neon terminal room": "plain black room",
212- "black neon terminal room": "plain black room",
213- "black terminal room": "plain black room",
214- "dark neon terminal workspace": "plain black workspace",
215- "black neon terminal workspace": "plain black workspace",
216- "black terminal workspace": "plain black workspace",
217- "green screen glow": "terminal lines",
218- "small green suggestion glow": "small cursor",
219- "boot-up glow": "boot-up cursor",
220- "terminal boot glow": "boot cursor",
221- "glowing laptop": "laptop",
222- "glowing": "terminal",
223- "glows": "shows",
224- "glow": "terminal line",
225- "in the same neon terminal room with a confident robot grin on its screen eyes while": "while",
226- "in a plain black room while": "while",
227- "in a black terminal room while": "while",
228- "sparks and tiny green debris implying the source code vanished": "sparks and debris",
229- "sparse dark upper area reserved for speech bubbles": "empty dark top",
230- "dark upper area reserved for a speech bubble": "empty dark top",
231- "empty dark upper area": "empty top",
232- "empty top area": "empty top",
233- "terminal line energy": "simple motion lines",
Cut short: this commit's diff is over 1000 lines.
.agents/skills/add-new-comic/scripts/generate_panel_worker.py+0−39
Cut short: this commit's diff is over 1000 lines.
.agents/skills/add-new-comic/scripts/models.py+0−111
Cut short: this commit's diff is over 1000 lines.
.agents/skills/add-new-comic/uv.lock+0−1281
Cut short: this commit's diff is over 1000 lines.
AGENTS.md+22−19
Cut short: this commit's diff is over 1000 lines.
README.md+18−126
Cut short: this commit's diff is over 1000 lines.
comic/schema.md+0−149
Cut short: this commit's diff is over 1000 lines.
comic/sdxl-generation-plan.md+0−237
Cut short: this commit's diff is over 1000 lines.
comic/style-guide.md+0−129
Cut short: this commit's diff is over 1000 lines.
index.html+2−2
Cut short: this commit's diff is over 1000 lines.