Files
craft-ai-integrations/docs/sam3-scripts/start_comfy_headless.py
T
JeremyandClaude 197a7175ed ai-comfyui: SAM 3 mask batches, grounding instances and point candidates
sg1: return every instance mask from text grounding, bounded (100 masks,
32 MiB encoded, 64 Mpx decoded, identical dimensions, output type checked
before download), with an explicit pixelwise-max union. A bad later mask
fails the whole batch. Repeat requests use a unique SaveImage prefix
because ComfyUI omits a fully cached output node from /history.

sg2a: Sam3Session::ground_instances returns each instance with mask,
detector box, score and mask-measured bounds, plus pick-under-pixel.
Boxes and scores travel as PreviewAny text stamped per request through
StringConcatenate, which keeps grounding cached and rejects text that
is not from this request.

sg2b: Sam3Session::candidates returns the alternative masks SAM 3 offers
for a point prompt (up to three, server order, scores, measured bounds).
Boxes and refinement passes are not wired yet.

Verified: 90 crate tests, clippy, fmt and wasm check clean, 33 deliberate
bugs caught, and live runs on the installed headless ComfyUI. Evidence,
probe and verification scripts are under docs/research/sam3-headless.
The roadmap, README and handoff notes are updated to match.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-10-12 18:59:50 +01:00

36 lines
1.6 KiB
Python

"""Start Jeremy's existing ComfyUI Desktop server without Electron.
No install, config edit or browser window. Log is in the Hermes scratch directory.
"""
import os
import subprocess
from pathlib import Path
home = Path.home()
base = home / "Documents" / "ComfyUI"
program = home / "AppData" / "Local" / "Programs" / "ComfyUI" / "resources" / "ComfyUI"
config = home / "AppData" / "Roaming" / "ComfyUI" / "extra_models_config.yaml"
python = base / ".venv" / "Scripts" / "python.exe"
log = home / "AppData" / "Local" / "hermes" / "cache" / "scratch" / "comfy-headless.log"
for p in (base, program / "main.py", config, python):
if not p.exists():
raise SystemExit(f"Missing existing ComfyUI path: {p}")
argv = [
str(python), str(program / "main.py"),
"--user-directory", str(base / "user"),
"--input-directory", str(base / "input"),
"--output-directory", str(base / "output"),
"--front-end-root", str(program / "web_custom_versions" / "desktop_app"),
"--base-directory", str(base),
"--database-url", f"sqlite:///{(base / 'user' / 'comfyui.db').as_posix()}",
"--extra-model-paths-config", str(config),
"--log-stdout", "--disable-auto-launch", "--listen", "127.0.0.1",
"--port", "8000", "--enable-manager",
]
with log.open("wb") as stream:
proc = subprocess.Popen(
argv, cwd=program, stdin=subprocess.DEVNULL, stdout=stream,
stderr=subprocess.STDOUT,
creationflags=subprocess.CREATE_NO_WINDOW | subprocess.DETACHED_PROCESS | subprocess.CREATE_NEW_PROCESS_GROUP,
)
print(f"Started existing ComfyUI headless, parent PID {proc.pid}; log {log}")