Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Agent.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -118,7 +118,7 @@ Community needs voiced in HN agent-UI discussions map directly to EMRG's design:
pkill -f "emrg.server"; rm -f ~/.emrg/emrgd.port; python -m emrg
```

Python: `uv run pytest tests/ -v` (748) — import check: `uv run python -c "from emrg.client.app import run_client"`
Python: `uv run pytest tests/ -v` (758) — import check: `uv run python -c "from emrg.client.app import run_client"`
GUI: `cd emrg/gui && npm test` (229: 44 daemon_client + 19 conn-manager + 22 app-commands + 107 renderer smoke + 15 i18n + 7 integration + 3 commands + 5 build-config + 7 gui-state) — syntax: `node --check main.js preload.js daemon_client.js renderer/js/*.js`
CI: `uv run pytest` + GUI tests + **actionlint workflow lint** (`rhysd/actionlint@v1.7.12` gate, #444 — workflow 解析错误在 PR CI 即失败,如 `if:` secrets 上下文)
Re-trigger: `scripts/re-trigger-ci.sh [branch]` (workflow_dispatch, #527 — 替代空 commit 重触发:Actions outage 会整段丢弃 push 事件,dispatch 走 API 路径不受影响)
Expand Down
220 changes: 40 additions & 180 deletions packaging/gen-assets.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -20,6 +20,9 @@ set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
OUT="$ROOT/packaging/assets"
SVG="$OUT/icon.svg"
# pngutil.py (filter-aware PNG decode) lives next to this script — the inline
# python heredocs below import it via PNGUTIL_DIR.
export PNGUTIL_DIR="$ROOT/packaging"
mkdir -p "$OUT"

if [ ! -f "$SVG" ]; then
Expand DownExpand Up@@ -122,129 +125,53 @@ HTMLEOF
# alpha channel; if >90% of pixels are transparent, the renderer failed.
# Returns 0 when the icon is opaque enough (accepted), 1 when blank (caller
# falls back to the next renderer).
# ⚡ Filter-aware decode (v0.2.29 Build Release lesson): rsvg-convert /
# Chrome emit adaptively-filtered PNG rows (Sub/Up/Average/Paeth). A naive
# "strip filter byte" read returns deltas, not pixels — a fully opaque icon
# falsely read as "99.2% transparent" (and the area-average resize produced
# garbage hues). pngutil.read_png reverses filters, so the check sees real
# alpha and the derived icon-512/256/icns/ico are correct.
check_icon_opaque() {
python3 - "$OUT/icon.png" <<'PYEOF'
import sys, struct, zlib

data = open(sys.argv[1], "rb").read()
assert data[:8] == b"\x89PNG\r\n\x1a\n", "not a PNG"
pos, w, h, idat, colortype = 8, 0, 0, b"", 0
while pos < len(data):
ln = struct.unpack(">I", data[pos:pos+4])[0]
tag = data[pos+4:pos+8]
chunk = data[pos+8:pos+8+ln]
if tag == b"IHDR":
w, h = struct.unpack(">II", chunk[:8])
colortype = chunk[9]
elif tag == b"IDAT":
idat += chunk
pos += 12 + ln
import os, sys
sys.path.insert(0, os.environ.get("PNGUTIL_DIR", os.path.join(os.path.dirname(sys.argv[1]), "..")))
import pngutil

w, h, bpp, px = pngutil.read_png(sys.argv[1])
if (w, h) != (1024, 1024):
sys.stderr.write(f"ERROR: expected 1024x1024 PNG, got {w}x{h} — renderer failed\n")
sys.exit(1)
print(f" icon.png OK: {w}x{h}")

if colortype == 6: # RGBA — only then is transparency meaningful
raw = zlib.decompress(idat)
stride0 = w * 4 + 1
raw = b"".join(raw[y*stride0+1:(y+1)*stride0] for y in range(h))
total = opaque = 0
for y in range(0, h, 8):
for x in range(0, w, 8):
a = raw[y*w*4 + x*4 + 3]
total += 1
if a > 0:
opaque += 1
ratio = opaque / total
print(f" icon.png alpha: {ratio:.1%} opaque ({opaque}/{total} sampled)")
if bpp == 4:
ratio = pngutil.opaque_ratio(w, h, bpp, px)
print(f" icon.png alpha: {ratio:.1%} opaque")
if ratio < 0.10:
sys.stderr.write(
f"ERROR: icon.png is {1-ratio:.1%} transparent — renderer failed to paint "
"the SVG. Falling back to next renderer (see rant 2026-08-12T17:25:28).\n"
)
sys.exit(1)
else:
print(f" icon.png alpha: colortype={colortype} (no alpha channel) — assumed opaque")
print(f" icon.png alpha: colortype={'RGB' if bpp == 3 else bpp} (no alpha channel) — assumed opaque")
PYEOF
}

render_svg_to_png || exit 1

echo "==> resizing to 512/256 (stdlib area-average box filter)"
python3 - "$OUT/icon.png" "$OUT" <<'PYEOF'
import sys, zlib, struct
import os, sys
sys.path.insert(0, os.environ.get("PNGUTIL_DIR", os.path.join(os.path.dirname(sys.argv[1]), "..")))
import pngutil

src, outdir = sys.argv[1], sys.argv[2]

def read_png(path):
data = open(path, "rb").read()
assert data[:8] == b"\x89PNG\r\n\x1a\n"
pos, w, h, idat, ct = 8, 0, 0, b"", 0
while pos < len(data):
ln = struct.unpack(">I", data[pos:pos+4])[0]
tag = data[pos+4:pos+8]
chunk = data[pos+8:pos+8+ln]
if tag == b"IHDR":
w, h = struct.unpack(">II", chunk[:8])
ct = chunk[9]
elif tag == b"IDAT":
idat += chunk
pos += 12 + ln
raw = zlib.decompress(idat)
# PNG scanlines each have a leading filter byte (0 for None); strip them.
# Chrome headless emits RGB (ct=2) when the page bg is opaque; rsvg-convert
# emits RGBA (ct=6). Normalize to RGBA so downstream code can assume 4 bpp.
if ct == 6:
stride0 = w * 4 + 1
raw = b"".join(raw[y*stride0+1:(y+1)*stride0] for y in range(h))
elif ct == 2:
stride0 = w * 3 + 1
rows = [raw[y*stride0+1:(y+1)*stride0] for y in range(h)]
out = bytearray()
for row in rows:
for i in range(0, len(row), 3):
out += row[i:i+3] + b"\xff"
raw = bytes(out)
else:
raise SystemExit(f"unsupported PNG colortype {ct}")
return w, h, raw

w, h, raw = read_png(src)
stride = w * 4

def resize_area(nw, nh):
"""Area-average (box filter) downscale — better antialiasing than nearest."""
out = bytearray([0, 0, 0, 0]) * (nw * nh)
for yy in range(nh):
y0 = yy * h // nh
y1 = max(y0 + 1, (yy + 1) * h // nh)
for xx in range(nw):
x0 = xx * w // nw
x1 = max(x0 + 1, (xx + 1) * w // nw)
r = g = b = a = 0
n = 0
for sy in range(y0, y1):
for sx in range(x0, x1):
i = sy * stride + sx * 4
r += raw[i]; g += raw[i+1]; b += raw[i+2]; a += raw[i+3]
n += 1
o = (yy * nw + xx) * 4
out[o] = r // n; out[o+1] = g // n; out[o+2] = b // n; out[o+3] = a // n
return bytes(out)

def write_png(path, nw, nh, rgba):
def chunk(tag, data):
c = struct.pack(">I", len(data)) + tag + data
c += struct.pack(">I", zlib.crc32(tag + data) & 0xffffffff)
return c
raw = b"".join(b"\x00" + rgba[y*nw*4:(y+1)*nw*4] for y in range(nh))
png = b"\x89PNG\r\n\x1a\n" + chunk(b"IHDR", struct.pack(">IIBBBBB", nw, nh, 8, 6, 0, 0, 0)) + chunk(b"IDAT", zlib.compress(raw, 9)) + chunk(b"IEND", b"")
open(path, "wb").write(png)
w, h, bpp, px = pngutil.read_png(src)
rgba = pngutil.to_rgba(w, h, bpp, px)

for size in (512, 256):
p = f"{outdir}/icon-{size}.png"
write_png(p, size, size, resize_area(size, size))
pngutil.write_png(p, size, size, pngutil.resize_area(rgba, w, h, size, size))
print(" wrote", p)
PYEOF

Expand All@@ -255,47 +182,14 @@ if command -v iconutil >/dev/null 2>&1; then
# iconutil wants specific sizes
for s in 16 32 128 256 512; do
python3 - "$OUT/icon.png" "$ICONSET/icon_${s}x${s}.png" "$s" <<'PYEOF'
import sys, zlib, struct
import os, sys
sys.path.insert(0, os.environ.get("PNGUTIL_DIR", os.path.join(os.path.dirname(sys.argv[1]), "..")))
import pngutil

src, dst, size = sys.argv[1], sys.argv[2], int(sys.argv[3])
data = open(src, "rb").read(); pos, w, h, idat, ct = 8, 0, 0, b"", 0
while pos < len(data):
ln = struct.unpack(">I", data[pos:pos+4])[0]; tag = data[pos+4:pos+8]; chunk = data[pos+8:pos+8+ln]
if tag == b"IHDR": w, h = struct.unpack(">II", chunk[:8]); ct = chunk[9]
elif tag == b"IDAT": idat += chunk
pos += 12 + ln
raw = zlib.decompress(idat)
if ct == 6:
stride0 = w*4 + 1
raw = b"".join(raw[y*stride0+1:(y+1)*stride0] for y in range(h))
else: # ct==2 RGB → expand to RGBA
stride0 = w*3 + 1
rows = [raw[y*stride0+1:(y+1)*stride0] for y in range(h)]
out = bytearray()
for row in rows:
for i in range(0, len(row), 3):
out += row[i:i+3] + b"\xff"
raw = bytes(out)
stride = w*4
def resize_area(nw, nh):
out = bytearray([0,0,0,0])*(nw*nh)
for yy in range(nh):
y0 = yy*h//nh; y1 = max(y0+1, (yy+1)*h//nh)
for xx in range(nw):
x0 = xx*w//nw; x1 = max(x0+1, (xx+1)*w//nw)
r = g = b = a = n = 0
for sy in range(y0, y1):
for sx in range(x0, x1):
i = sy*stride + sx*4
r += raw[i]; g += raw[i+1]; b += raw[i+2]; a += raw[i+3]; n += 1
o = (yy*nw+xx)*4
out[o] = r//n; out[o+1] = g//n; out[o+2] = b//n; out[o+3] = a//n
return bytes(out)
def chunk(tag, data):
c = struct.pack(">I", len(data))+tag+data; c += struct.pack(">I", zlib.crc32(tag+data)&0xffffffff); return c
rgba = resize_area(size, size)
raw2 = b"".join(b"\x00"+rgba[y*size*4:(y+1)*size*4] for y in range(size))
png = b"\x89PNG\r\n\x1a\n"+chunk(b"IHDR", struct.pack(">IIBBBBB", size, size, 8, 6, 0, 0, 0))+chunk(b"IDAT", zlib.compress(raw2,9))+chunk(b"IEND", b"")
open(dst, "wb").write(png)
w, h, bpp, px = pngutil.read_png(src)
rgba = pngutil.to_rgba(w, h, bpp, px)
pngutil.write_png(dst, size, size, pngutil.resize_area(rgba, w, h, size, size))
PYEOF
cp "$ICONSET/icon_${s}x${s}.png" "$ICONSET/icon_${s}x${s}@2x.png" 2>/dev/null || true
done
Expand All@@ -309,57 +203,23 @@ fi

echo "==> icon.ico (multi-size, win)"
python3 - "$OUT/icon.png" "$OUT/icon.ico" <<'PYEOF'
import sys, zlib, struct
src, dst = sys.argv[1], sys.argv[2]
data = open(src, "rb").read(); pos, w, h, idat, ct = 8, 0, 0, b"", 0
while pos < len(data):
ln = struct.unpack(">I", data[pos:pos+4])[0]; tag = data[pos+4:pos+8]; chunk = data[pos+8:pos+8+ln]
if tag == b"IHDR": w, h = struct.unpack(">II", chunk[:8]); ct = chunk[9]
elif tag == b"IDAT": idat += chunk
pos += 12 + ln
raw = zlib.decompress(idat)
if ct == 6:
stride0 = w*4 + 1
raw = b"".join(raw[y*stride0+1:(y+1)*stride0] for y in range(h))
else: # ct==2 RGB → expand to RGBA
stride0 = w*3 + 1
rows = [raw[y*stride0+1:(y+1)*stride0] for y in range(h)]
out = bytearray()
for row in rows:
for i in range(0, len(row), 3):
out += row[i:i+3] + b"\xff"
raw = bytes(out)
stride = w*4
import os, sys
sys.path.insert(0, os.environ.get("PNGUTIL_DIR", os.path.join(os.path.dirname(sys.argv[1]), "..")))
import struct
import pngutil

def resize_area(nw, nh):
out = bytearray([0,0,0,0])*(nw*nh)
for yy in range(nh):
y0 = yy*h//nh; y1 = max(y0+1, (yy+1)*h//nh)
for xx in range(nw):
x0 = xx*w//nw; x1 = max(x0+1, (xx+1)*w//nw)
r = g = b = a = n = 0
for sy in range(y0, y1):
for sx in range(x0, x1):
i = sy*stride + sx*4
r += raw[i]; g += raw[i+1]; b += raw[i+2]; a += raw[i+3]; n += 1
o = (yy*nw+xx)*4
out[o] = r//n; out[o+1] = g//n; out[o+2] = b//n; out[o+3] = a//n
return bytes(out)

def png_bytes(nw, nh, rgba):
def chunk(tag, data):
c = struct.pack(">I", len(data))+tag+data; c += struct.pack(">I", zlib.crc32(tag+data)&0xffffffff); return c
raw2 = b"".join(b"\x00"+rgba[y*nw*4:(y+1)*nw*4] for y in range(nh))
return b"\x89PNG\r\n\x1a\n"+chunk(b"IHDR", struct.pack(">IIBBBBB", nw, nh, 8, 6, 0, 0, 0))+chunk(b"IDAT", zlib.compress(raw2,9))+chunk(b"IEND", b"")
src, dst = sys.argv[1], sys.argv[2]
w, h, bpp, px = pngutil.read_png(src)
rgba = pngutil.to_rgba(w, h, bpp, px)

# ICO: header + directory + PNG-embedded entries
sizes = [16, 24, 32, 48, 64, 128, 256]
imgs = [(s, png_bytes(s, s, resize_area(s, s))) for s in sizes]
imgs = [(s, pngutil.write_png_bytes(s, s, pngutil.resize_area(rgba, w, h, s, s))) for s in sizes]
header = struct.pack("<HHH", 0, 1, len(imgs))
offset = 6 + 16*len(imgs)
offset = 6 + 16 * len(imgs)
entries = b""
for s, png in imgs:
entries += struct.pack("<BBBBHHII", s if s<256 else 0, s if s<256 else 0, 0, 0, 1, 32, len(png), offset)
entries += struct.pack("<BBBBHHII", s if s < 256 else 0, s if s < 256 else 0, 0, 0, 1, 32, len(png), offset)
offset += len(png)
with open(dst, "wb") as f:
f.write(header + entries + b"".join(p for _, p in imgs))
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
emrg: fix v0.2.29 Build Release gates — Windows git.EXE fake + filter-aware icon decode by argszero · Pull Request #723 · argszero/emrg · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Agent.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -118,7 +118,7 @@ Community needs voiced in HN agent-UI discussions map directly to EMRG's design:
pkill -f "emrg.server"; rm -f ~/.emrg/emrgd.port; python -m emrg
```

Python: `uv run pytest tests/ -v` (748) — import check: `uv run python -c "from emrg.client.app import run_client"`
Python: `uv run pytest tests/ -v` (758) — import check: `uv run python -c "from emrg.client.app import run_client"`
GUI: `cd emrg/gui && npm test` (229: 44 daemon_client + 19 conn-manager + 22 app-commands + 107 renderer smoke + 15 i18n + 7 integration + 3 commands + 5 build-config + 7 gui-state) — syntax: `node --check main.js preload.js daemon_client.js renderer/js/*.js`
CI: `uv run pytest` + GUI tests + **actionlint workflow lint** (`rhysd/actionlint@v1.7.12` gate, #444 — workflow 解析错误在 PR CI 即失败,如 `if:` secrets 上下文)
Re-trigger: `scripts/re-trigger-ci.sh [branch]` (workflow_dispatch, #527 — 替代空 commit 重触发:Actions outage 会整段丢弃 push 事件,dispatch 走 API 路径不受影响)
Expand Down
220 changes: 40 additions & 180 deletions packaging/gen-assets.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -20,6 +20,9 @@ set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
OUT="$ROOT/packaging/assets"
SVG="$OUT/icon.svg"
# pngutil.py (filter-aware PNG decode) lives next to this script — the inline
# python heredocs below import it via PNGUTIL_DIR.
export PNGUTIL_DIR="$ROOT/packaging"
mkdir -p "$OUT"

if [ ! -f "$SVG" ]; then
Expand DownExpand Up@@ -122,129 +125,53 @@ HTMLEOF
# alpha channel; if >90% of pixels are transparent, the renderer failed.
# Returns 0 when the icon is opaque enough (accepted), 1 when blank (caller
# falls back to the next renderer).
# ⚡ Filter-aware decode (v0.2.29 Build Release lesson): rsvg-convert /
# Chrome emit adaptively-filtered PNG rows (Sub/Up/Average/Paeth). A naive
# "strip filter byte" read returns deltas, not pixels — a fully opaque icon
# falsely read as "99.2% transparent" (and the area-average resize produced
# garbage hues). pngutil.read_png reverses filters, so the check sees real
# alpha and the derived icon-512/256/icns/ico are correct.
check_icon_opaque() {
python3 - "$OUT/icon.png" <<'PYEOF'
import sys, struct, zlib

data = open(sys.argv[1], "rb").read()
assert data[:8] == b"\x89PNG\r\n\x1a\n", "not a PNG"
pos, w, h, idat, colortype = 8, 0, 0, b"", 0
while pos < len(data):
ln = struct.unpack(">I", data[pos:pos+4])[0]
tag = data[pos+4:pos+8]
chunk = data[pos+8:pos+8+ln]
if tag == b"IHDR":
w, h = struct.unpack(">II", chunk[:8])
colortype = chunk[9]
elif tag == b"IDAT":
idat += chunk
pos += 12 + ln
import os, sys
sys.path.insert(0, os.environ.get("PNGUTIL_DIR", os.path.join(os.path.dirname(sys.argv[1]), "..")))
import pngutil

w, h, bpp, px = pngutil.read_png(sys.argv[1])
if (w, h) != (1024, 1024):
sys.stderr.write(f"ERROR: expected 1024x1024 PNG, got {w}x{h} — renderer failed\n")
sys.exit(1)
print(f" icon.png OK: {w}x{h}")

if colortype == 6: # RGBA — only then is transparency meaningful
raw = zlib.decompress(idat)
stride0 = w * 4 + 1
raw = b"".join(raw[y*stride0+1:(y+1)*stride0] for y in range(h))
total = opaque = 0
for y in range(0, h, 8):
for x in range(0, w, 8):
a = raw[y*w*4 + x*4 + 3]
total += 1
if a > 0:
opaque += 1
ratio = opaque / total
print(f" icon.png alpha: {ratio:.1%} opaque ({opaque}/{total} sampled)")
if bpp == 4:
ratio = pngutil.opaque_ratio(w, h, bpp, px)
print(f" icon.png alpha: {ratio:.1%} opaque")
if ratio < 0.10:
sys.stderr.write(
f"ERROR: icon.png is {1-ratio:.1%} transparent — renderer failed to paint "
"the SVG. Falling back to next renderer (see rant 2026-08-12T17:25:28).\n"
)
sys.exit(1)
else:
print(f" icon.png alpha: colortype={colortype} (no alpha channel) — assumed opaque")
print(f" icon.png alpha: colortype={'RGB' if bpp == 3 else bpp} (no alpha channel) — assumed opaque")
PYEOF
}

render_svg_to_png || exit 1

echo "==> resizing to 512/256 (stdlib area-average box filter)"
python3 - "$OUT/icon.png" "$OUT" <<'PYEOF'
import sys, zlib, struct
import os, sys
sys.path.insert(0, os.environ.get("PNGUTIL_DIR", os.path.join(os.path.dirname(sys.argv[1]), "..")))
import pngutil

src, outdir = sys.argv[1], sys.argv[2]

def read_png(path):
data = open(path, "rb").read()
assert data[:8] == b"\x89PNG\r\n\x1a\n"
pos, w, h, idat, ct = 8, 0, 0, b"", 0
while pos < len(data):
ln = struct.unpack(">I", data[pos:pos+4])[0]
tag = data[pos+4:pos+8]
chunk = data[pos+8:pos+8+ln]
if tag == b"IHDR":
w, h = struct.unpack(">II", chunk[:8])
ct = chunk[9]
elif tag == b"IDAT":
idat += chunk
pos += 12 + ln
raw = zlib.decompress(idat)
# PNG scanlines each have a leading filter byte (0 for None); strip them.
# Chrome headless emits RGB (ct=2) when the page bg is opaque; rsvg-convert
# emits RGBA (ct=6). Normalize to RGBA so downstream code can assume 4 bpp.
if ct == 6:
stride0 = w * 4 + 1
raw = b"".join(raw[y*stride0+1:(y+1)*stride0] for y in range(h))
elif ct == 2:
stride0 = w * 3 + 1
rows = [raw[y*stride0+1:(y+1)*stride0] for y in range(h)]
out = bytearray()
for row in rows:
for i in range(0, len(row), 3):
out += row[i:i+3] + b"\xff"
raw = bytes(out)
else:
raise SystemExit(f"unsupported PNG colortype {ct}")
return w, h, raw

w, h, raw = read_png(src)
stride = w * 4

def resize_area(nw, nh):
"""Area-average (box filter) downscale — better antialiasing than nearest."""
out = bytearray([0, 0, 0, 0]) * (nw * nh)
for yy in range(nh):
y0 = yy * h // nh
y1 = max(y0 + 1, (yy + 1) * h // nh)
for xx in range(nw):
x0 = xx * w // nw
x1 = max(x0 + 1, (xx + 1) * w // nw)
r = g = b = a = 0
n = 0
for sy in range(y0, y1):
for sx in range(x0, x1):
i = sy * stride + sx * 4
r += raw[i]; g += raw[i+1]; b += raw[i+2]; a += raw[i+3]
n += 1
o = (yy * nw + xx) * 4
out[o] = r // n; out[o+1] = g // n; out[o+2] = b // n; out[o+3] = a // n
return bytes(out)

def write_png(path, nw, nh, rgba):
def chunk(tag, data):
c = struct.pack(">I", len(data)) + tag + data
c += struct.pack(">I", zlib.crc32(tag + data) & 0xffffffff)
return c
raw = b"".join(b"\x00" + rgba[y*nw*4:(y+1)*nw*4] for y in range(nh))
png = b"\x89PNG\r\n\x1a\n" + chunk(b"IHDR", struct.pack(">IIBBBBB", nw, nh, 8, 6, 0, 0, 0)) + chunk(b"IDAT", zlib.compress(raw, 9)) + chunk(b"IEND", b"")
open(path, "wb").write(png)
w, h, bpp, px = pngutil.read_png(src)
rgba = pngutil.to_rgba(w, h, bpp, px)

for size in (512, 256):
p = f"{outdir}/icon-{size}.png"
write_png(p, size, size, resize_area(size, size))
pngutil.write_png(p, size, size, pngutil.resize_area(rgba, w, h, size, size))
print(" wrote", p)
PYEOF

Expand All@@ -255,47 +182,14 @@ if command -v iconutil >/dev/null 2>&1; then
# iconutil wants specific sizes
for s in 16 32 128 256 512; do
python3 - "$OUT/icon.png" "$ICONSET/icon_${s}x${s}.png" "$s" <<'PYEOF'
import sys, zlib, struct
import os, sys
sys.path.insert(0, os.environ.get("PNGUTIL_DIR", os.path.join(os.path.dirname(sys.argv[1]), "..")))
import pngutil

src, dst, size = sys.argv[1], sys.argv[2], int(sys.argv[3])
data = open(src, "rb").read(); pos, w, h, idat, ct = 8, 0, 0, b"", 0
while pos < len(data):
ln = struct.unpack(">I", data[pos:pos+4])[0]; tag = data[pos+4:pos+8]; chunk = data[pos+8:pos+8+ln]
if tag == b"IHDR": w, h = struct.unpack(">II", chunk[:8]); ct = chunk[9]
elif tag == b"IDAT": idat += chunk
pos += 12 + ln
raw = zlib.decompress(idat)
if ct == 6:
stride0 = w*4 + 1
raw = b"".join(raw[y*stride0+1:(y+1)*stride0] for y in range(h))
else: # ct==2 RGB → expand to RGBA
stride0 = w*3 + 1
rows = [raw[y*stride0+1:(y+1)*stride0] for y in range(h)]
out = bytearray()
for row in rows:
for i in range(0, len(row), 3):
out += row[i:i+3] + b"\xff"
raw = bytes(out)
stride = w*4
def resize_area(nw, nh):
out = bytearray([0,0,0,0])*(nw*nh)
for yy in range(nh):
y0 = yy*h//nh; y1 = max(y0+1, (yy+1)*h//nh)
for xx in range(nw):
x0 = xx*w//nw; x1 = max(x0+1, (xx+1)*w//nw)
r = g = b = a = n = 0
for sy in range(y0, y1):
for sx in range(x0, x1):
i = sy*stride + sx*4
r += raw[i]; g += raw[i+1]; b += raw[i+2]; a += raw[i+3]; n += 1
o = (yy*nw+xx)*4
out[o] = r//n; out[o+1] = g//n; out[o+2] = b//n; out[o+3] = a//n
return bytes(out)
def chunk(tag, data):
c = struct.pack(">I", len(data))+tag+data; c += struct.pack(">I", zlib.crc32(tag+data)&0xffffffff); return c
rgba = resize_area(size, size)
raw2 = b"".join(b"\x00"+rgba[y*size*4:(y+1)*size*4] for y in range(size))
png = b"\x89PNG\r\n\x1a\n"+chunk(b"IHDR", struct.pack(">IIBBBBB", size, size, 8, 6, 0, 0, 0))+chunk(b"IDAT", zlib.compress(raw2,9))+chunk(b"IEND", b"")
open(dst, "wb").write(png)
w, h, bpp, px = pngutil.read_png(src)
rgba = pngutil.to_rgba(w, h, bpp, px)
pngutil.write_png(dst, size, size, pngutil.resize_area(rgba, w, h, size, size))
PYEOF
cp "$ICONSET/icon_${s}x${s}.png" "$ICONSET/icon_${s}x${s}@2x.png" 2>/dev/null || true
done
Expand All@@ -309,57 +203,23 @@ fi

echo "==> icon.ico (multi-size, win)"
python3 - "$OUT/icon.png" "$OUT/icon.ico" <<'PYEOF'
import sys, zlib, struct
src, dst = sys.argv[1], sys.argv[2]
data = open(src, "rb").read(); pos, w, h, idat, ct = 8, 0, 0, b"", 0
while pos < len(data):
ln = struct.unpack(">I", data[pos:pos+4])[0]; tag = data[pos+4:pos+8]; chunk = data[pos+8:pos+8+ln]
if tag == b"IHDR": w, h = struct.unpack(">II", chunk[:8]); ct = chunk[9]
elif tag == b"IDAT": idat += chunk
pos += 12 + ln
raw = zlib.decompress(idat)
if ct == 6:
stride0 = w*4 + 1
raw = b"".join(raw[y*stride0+1:(y+1)*stride0] for y in range(h))
else: # ct==2 RGB → expand to RGBA
stride0 = w*3 + 1
rows = [raw[y*stride0+1:(y+1)*stride0] for y in range(h)]
out = bytearray()
for row in rows:
for i in range(0, len(row), 3):
out += row[i:i+3] + b"\xff"
raw = bytes(out)
stride = w*4
import os, sys
sys.path.insert(0, os.environ.get("PNGUTIL_DIR", os.path.join(os.path.dirname(sys.argv[1]), "..")))
import struct
import pngutil

def resize_area(nw, nh):
out = bytearray([0,0,0,0])*(nw*nh)
for yy in range(nh):
y0 = yy*h//nh; y1 = max(y0+1, (yy+1)*h//nh)
for xx in range(nw):
x0 = xx*w//nw; x1 = max(x0+1, (xx+1)*w//nw)
r = g = b = a = n = 0
for sy in range(y0, y1):
for sx in range(x0, x1):
i = sy*stride + sx*4
r += raw[i]; g += raw[i+1]; b += raw[i+2]; a += raw[i+3]; n += 1
o = (yy*nw+xx)*4
out[o] = r//n; out[o+1] = g//n; out[o+2] = b//n; out[o+3] = a//n
return bytes(out)

def png_bytes(nw, nh, rgba):
def chunk(tag, data):
c = struct.pack(">I", len(data))+tag+data; c += struct.pack(">I", zlib.crc32(tag+data)&0xffffffff); return c
raw2 = b"".join(b"\x00"+rgba[y*nw*4:(y+1)*nw*4] for y in range(nh))
return b"\x89PNG\r\n\x1a\n"+chunk(b"IHDR", struct.pack(">IIBBBBB", nw, nh, 8, 6, 0, 0, 0))+chunk(b"IDAT", zlib.compress(raw2,9))+chunk(b"IEND", b"")
src, dst = sys.argv[1], sys.argv[2]
w, h, bpp, px = pngutil.read_png(src)
rgba = pngutil.to_rgba(w, h, bpp, px)

# ICO: header + directory + PNG-embedded entries
sizes = [16, 24, 32, 48, 64, 128, 256]
imgs = [(s, png_bytes(s, s, resize_area(s, s))) for s in sizes]
imgs = [(s, pngutil.write_png_bytes(s, s, pngutil.resize_area(rgba, w, h, s, s))) for s in sizes]
header = struct.pack("<HHH", 0, 1, len(imgs))
offset = 6 + 16*len(imgs)
offset = 6 + 16 * len(imgs)
entries = b""
for s, png in imgs:
entries += struct.pack("<BBBBHHII", s if s<256 else 0, s if s<256 else 0, 0, 0, 1, 32, len(png), offset)
entries += struct.pack("<BBBBHHII", s if s < 256 else 0, s if s < 256 else 0, 0, 0, 1, 32, len(png), offset)
offset += len(png)
with open(dst, "wb") as f:
f.write(header + entries + b"".join(p for _, p in imgs))
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' emrg: fix v0.2.29 Build Release gates — Windows git.EXE fake + filter-aware icon decode by argszero · Pull Request #723 · argszero/emrg · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Agent.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -118,7 +118,7 @@ Community needs voiced in HN agent-UI discussions map directly to EMRG's design:
pkill -f "emrg.server"; rm -f ~/.emrg/emrgd.port; python -m emrg
```

Python: `uv run pytest tests/ -v` (748) — import check: `uv run python -c "from emrg.client.app import run_client"`
Python: `uv run pytest tests/ -v` (758) — import check: `uv run python -c "from emrg.client.app import run_client"`
GUI: `cd emrg/gui && npm test` (229: 44 daemon_client + 19 conn-manager + 22 app-commands + 107 renderer smoke + 15 i18n + 7 integration + 3 commands + 5 build-config + 7 gui-state) — syntax: `node --check main.js preload.js daemon_client.js renderer/js/*.js`
CI: `uv run pytest` + GUI tests + **actionlint workflow lint** (`rhysd/actionlint@v1.7.12` gate, #444 — workflow 解析错误在 PR CI 即失败,如 `if:` secrets 上下文)
Re-trigger: `scripts/re-trigger-ci.sh [branch]` (workflow_dispatch, #527 — 替代空 commit 重触发:Actions outage 会整段丢弃 push 事件,dispatch 走 API 路径不受影响)
Expand Down
220 changes: 40 additions & 180 deletions packaging/gen-assets.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -20,6 +20,9 @@ set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
OUT="$ROOT/packaging/assets"
SVG="$OUT/icon.svg"
# pngutil.py (filter-aware PNG decode) lives next to this script — the inline
# python heredocs below import it via PNGUTIL_DIR.
export PNGUTIL_DIR="$ROOT/packaging"
mkdir -p "$OUT"

if [ ! -f "$SVG" ]; then
Expand DownExpand Up@@ -122,129 +125,53 @@ HTMLEOF
# alpha channel; if >90% of pixels are transparent, the renderer failed.
# Returns 0 when the icon is opaque enough (accepted), 1 when blank (caller
# falls back to the next renderer).
# ⚡ Filter-aware decode (v0.2.29 Build Release lesson): rsvg-convert /
# Chrome emit adaptively-filtered PNG rows (Sub/Up/Average/Paeth). A naive
# "strip filter byte" read returns deltas, not pixels — a fully opaque icon
# falsely read as "99.2% transparent" (and the area-average resize produced
# garbage hues). pngutil.read_png reverses filters, so the check sees real
# alpha and the derived icon-512/256/icns/ico are correct.
check_icon_opaque() {
python3 - "$OUT/icon.png" <<'PYEOF'
import sys, struct, zlib

data = open(sys.argv[1], "rb").read()
assert data[:8] == b"\x89PNG\r\n\x1a\n", "not a PNG"
pos, w, h, idat, colortype = 8, 0, 0, b"", 0
while pos < len(data):
ln = struct.unpack(">I", data[pos:pos+4])[0]
tag = data[pos+4:pos+8]
chunk = data[pos+8:pos+8+ln]
if tag == b"IHDR":
w, h = struct.unpack(">II", chunk[:8])
colortype = chunk[9]
elif tag == b"IDAT":
idat += chunk
pos += 12 + ln
import os, sys
sys.path.insert(0, os.environ.get("PNGUTIL_DIR", os.path.join(os.path.dirname(sys.argv[1]), "..")))
import pngutil

w, h, bpp, px = pngutil.read_png(sys.argv[1])
if (w, h) != (1024, 1024):
sys.stderr.write(f"ERROR: expected 1024x1024 PNG, got {w}x{h} — renderer failed\n")
sys.exit(1)
print(f" icon.png OK: {w}x{h}")

if colortype == 6: # RGBA — only then is transparency meaningful
raw = zlib.decompress(idat)
stride0 = w * 4 + 1
raw = b"".join(raw[y*stride0+1:(y+1)*stride0] for y in range(h))
total = opaque = 0
for y in range(0, h, 8):
for x in range(0, w, 8):
a = raw[y*w*4 + x*4 + 3]
total += 1
if a > 0:
opaque += 1
ratio = opaque / total
print(f" icon.png alpha: {ratio:.1%} opaque ({opaque}/{total} sampled)")
if bpp == 4:
ratio = pngutil.opaque_ratio(w, h, bpp, px)
print(f" icon.png alpha: {ratio:.1%} opaque")
if ratio < 0.10:
sys.stderr.write(
f"ERROR: icon.png is {1-ratio:.1%} transparent — renderer failed to paint "
"the SVG. Falling back to next renderer (see rant 2026-08-12T17:25:28).\n"
)
sys.exit(1)
else:
print(f" icon.png alpha: colortype={colortype} (no alpha channel) — assumed opaque")
print(f" icon.png alpha: colortype={'RGB' if bpp == 3 else bpp} (no alpha channel) — assumed opaque")
PYEOF
}

render_svg_to_png || exit 1

echo "==> resizing to 512/256 (stdlib area-average box filter)"
python3 - "$OUT/icon.png" "$OUT" <<'PYEOF'
import sys, zlib, struct
import os, sys
sys.path.insert(0, os.environ.get("PNGUTIL_DIR", os.path.join(os.path.dirname(sys.argv[1]), "..")))
import pngutil

src, outdir = sys.argv[1], sys.argv[2]

def read_png(path):
data = open(path, "rb").read()
assert data[:8] == b"\x89PNG\r\n\x1a\n"
pos, w, h, idat, ct = 8, 0, 0, b"", 0
while pos < len(data):
ln = struct.unpack(">I", data[pos:pos+4])[0]
tag = data[pos+4:pos+8]
chunk = data[pos+8:pos+8+ln]
if tag == b"IHDR":
w, h = struct.unpack(">II", chunk[:8])
ct = chunk[9]
elif tag == b"IDAT":
idat += chunk
pos += 12 + ln
raw = zlib.decompress(idat)
# PNG scanlines each have a leading filter byte (0 for None); strip them.
# Chrome headless emits RGB (ct=2) when the page bg is opaque; rsvg-convert
# emits RGBA (ct=6). Normalize to RGBA so downstream code can assume 4 bpp.
if ct == 6:
stride0 = w * 4 + 1
raw = b"".join(raw[y*stride0+1:(y+1)*stride0] for y in range(h))
elif ct == 2:
stride0 = w * 3 + 1
rows = [raw[y*stride0+1:(y+1)*stride0] for y in range(h)]
out = bytearray()
for row in rows:
for i in range(0, len(row), 3):
out += row[i:i+3] + b"\xff"
raw = bytes(out)
else:
raise SystemExit(f"unsupported PNG colortype {ct}")
return w, h, raw

w, h, raw = read_png(src)
stride = w * 4

def resize_area(nw, nh):
"""Area-average (box filter) downscale — better antialiasing than nearest."""
out = bytearray([0, 0, 0, 0]) * (nw * nh)
for yy in range(nh):
y0 = yy * h // nh
y1 = max(y0 + 1, (yy + 1) * h // nh)
for xx in range(nw):
x0 = xx * w // nw
x1 = max(x0 + 1, (xx + 1) * w // nw)
r = g = b = a = 0
n = 0
for sy in range(y0, y1):
for sx in range(x0, x1):
i = sy * stride + sx * 4
r += raw[i]; g += raw[i+1]; b += raw[i+2]; a += raw[i+3]
n += 1
o = (yy * nw + xx) * 4
out[o] = r // n; out[o+1] = g // n; out[o+2] = b // n; out[o+3] = a // n
return bytes(out)

def write_png(path, nw, nh, rgba):
def chunk(tag, data):
c = struct.pack(">I", len(data)) + tag + data
c += struct.pack(">I", zlib.crc32(tag + data) & 0xffffffff)
return c
raw = b"".join(b"\x00" + rgba[y*nw*4:(y+1)*nw*4] for y in range(nh))
png = b"\x89PNG\r\n\x1a\n" + chunk(b"IHDR", struct.pack(">IIBBBBB", nw, nh, 8, 6, 0, 0, 0)) + chunk(b"IDAT", zlib.compress(raw, 9)) + chunk(b"IEND", b"")
open(path, "wb").write(png)
w, h, bpp, px = pngutil.read_png(src)
rgba = pngutil.to_rgba(w, h, bpp, px)

for size in (512, 256):
p = f"{outdir}/icon-{size}.png"
write_png(p, size, size, resize_area(size, size))
pngutil.write_png(p, size, size, pngutil.resize_area(rgba, w, h, size, size))
print(" wrote", p)
PYEOF

Expand All@@ -255,47 +182,14 @@ if command -v iconutil >/dev/null 2>&1; then
# iconutil wants specific sizes
for s in 16 32 128 256 512; do
python3 - "$OUT/icon.png" "$ICONSET/icon_${s}x${s}.png" "$s" <<'PYEOF'
import sys, zlib, struct
import os, sys
sys.path.insert(0, os.environ.get("PNGUTIL_DIR", os.path.join(os.path.dirname(sys.argv[1]), "..")))
import pngutil

src, dst, size = sys.argv[1], sys.argv[2], int(sys.argv[3])
data = open(src, "rb").read(); pos, w, h, idat, ct = 8, 0, 0, b"", 0
while pos < len(data):
ln = struct.unpack(">I", data[pos:pos+4])[0]; tag = data[pos+4:pos+8]; chunk = data[pos+8:pos+8+ln]
if tag == b"IHDR": w, h = struct.unpack(">II", chunk[:8]); ct = chunk[9]
elif tag == b"IDAT": idat += chunk
pos += 12 + ln
raw = zlib.decompress(idat)
if ct == 6:
stride0 = w*4 + 1
raw = b"".join(raw[y*stride0+1:(y+1)*stride0] for y in range(h))
else: # ct==2 RGB → expand to RGBA
stride0 = w*3 + 1
rows = [raw[y*stride0+1:(y+1)*stride0] for y in range(h)]
out = bytearray()
for row in rows:
for i in range(0, len(row), 3):
out += row[i:i+3] + b"\xff"
raw = bytes(out)
stride = w*4
def resize_area(nw, nh):
out = bytearray([0,0,0,0])*(nw*nh)
for yy in range(nh):
y0 = yy*h//nh; y1 = max(y0+1, (yy+1)*h//nh)
for xx in range(nw):
x0 = xx*w//nw; x1 = max(x0+1, (xx+1)*w//nw)
r = g = b = a = n = 0
for sy in range(y0, y1):
for sx in range(x0, x1):
i = sy*stride + sx*4
r += raw[i]; g += raw[i+1]; b += raw[i+2]; a += raw[i+3]; n += 1
o = (yy*nw+xx)*4
out[o] = r//n; out[o+1] = g//n; out[o+2] = b//n; out[o+3] = a//n
return bytes(out)
def chunk(tag, data):
c = struct.pack(">I", len(data))+tag+data; c += struct.pack(">I", zlib.crc32(tag+data)&0xffffffff); return c
rgba = resize_area(size, size)
raw2 = b"".join(b"\x00"+rgba[y*size*4:(y+1)*size*4] for y in range(size))
png = b"\x89PNG\r\n\x1a\n"+chunk(b"IHDR", struct.pack(">IIBBBBB", size, size, 8, 6, 0, 0, 0))+chunk(b"IDAT", zlib.compress(raw2,9))+chunk(b"IEND", b"")
open(dst, "wb").write(png)
w, h, bpp, px = pngutil.read_png(src)
rgba = pngutil.to_rgba(w, h, bpp, px)
pngutil.write_png(dst, size, size, pngutil.resize_area(rgba, w, h, size, size))
PYEOF
cp "$ICONSET/icon_${s}x${s}.png" "$ICONSET/icon_${s}x${s}@2x.png" 2>/dev/null || true
done
Expand All@@ -309,57 +203,23 @@ fi

echo "==> icon.ico (multi-size, win)"
python3 - "$OUT/icon.png" "$OUT/icon.ico" <<'PYEOF'
import sys, zlib, struct
src, dst = sys.argv[1], sys.argv[2]
data = open(src, "rb").read(); pos, w, h, idat, ct = 8, 0, 0, b"", 0
while pos < len(data):
ln = struct.unpack(">I", data[pos:pos+4])[0]; tag = data[pos+4:pos+8]; chunk = data[pos+8:pos+8+ln]
if tag == b"IHDR": w, h = struct.unpack(">II", chunk[:8]); ct = chunk[9]
elif tag == b"IDAT": idat += chunk
pos += 12 + ln
raw = zlib.decompress(idat)
if ct == 6:
stride0 = w*4 + 1
raw = b"".join(raw[y*stride0+1:(y+1)*stride0] for y in range(h))
else: # ct==2 RGB → expand to RGBA
stride0 = w*3 + 1
rows = [raw[y*stride0+1:(y+1)*stride0] for y in range(h)]
out = bytearray()
for row in rows:
for i in range(0, len(row), 3):
out += row[i:i+3] + b"\xff"
raw = bytes(out)
stride = w*4
import os, sys
sys.path.insert(0, os.environ.get("PNGUTIL_DIR", os.path.join(os.path.dirname(sys.argv[1]), "..")))
import struct
import pngutil

def resize_area(nw, nh):
out = bytearray([0,0,0,0])*(nw*nh)
for yy in range(nh):
y0 = yy*h//nh; y1 = max(y0+1, (yy+1)*h//nh)
for xx in range(nw):
x0 = xx*w//nw; x1 = max(x0+1, (xx+1)*w//nw)
r = g = b = a = n = 0
for sy in range(y0, y1):
for sx in range(x0, x1):
i = sy*stride + sx*4
r += raw[i]; g += raw[i+1]; b += raw[i+2]; a += raw[i+3]; n += 1
o = (yy*nw+xx)*4
out[o] = r//n; out[o+1] = g//n; out[o+2] = b//n; out[o+3] = a//n
return bytes(out)

def png_bytes(nw, nh, rgba):
def chunk(tag, data):
c = struct.pack(">I", len(data))+tag+data; c += struct.pack(">I", zlib.crc32(tag+data)&0xffffffff); return c
raw2 = b"".join(b"\x00"+rgba[y*nw*4:(y+1)*nw*4] for y in range(nh))
return b"\x89PNG\r\n\x1a\n"+chunk(b"IHDR", struct.pack(">IIBBBBB", nw, nh, 8, 6, 0, 0, 0))+chunk(b"IDAT", zlib.compress(raw2,9))+chunk(b"IEND", b"")
src, dst = sys.argv[1], sys.argv[2]
w, h, bpp, px = pngutil.read_png(src)
rgba = pngutil.to_rgba(w, h, bpp, px)

# ICO: header + directory + PNG-embedded entries
sizes = [16, 24, 32, 48, 64, 128, 256]
imgs = [(s, png_bytes(s, s, resize_area(s, s))) for s in sizes]
imgs = [(s, pngutil.write_png_bytes(s, s, pngutil.resize_area(rgba, w, h, s, s))) for s in sizes]
header = struct.pack("<HHH", 0, 1, len(imgs))
offset = 6 + 16*len(imgs)
offset = 6 + 16 * len(imgs)
entries = b""
for s, png in imgs:
entries += struct.pack("<BBBBHHII", s if s<256 else 0, s if s<256 else 0, 0, 0, 1, 32, len(png), offset)
entries += struct.pack("<BBBBHHII", s if s < 256 else 0, s if s < 256 else 0, 0, 0, 1, 32, len(png), offset)
offset += len(png)
with open(dst, "wb") as f:
f.write(header + entries + b"".join(p for _, p in imgs))
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' emrg: fix v0.2.29 Build Release gates — Windows git.EXE fake + filter-aware icon decode by argszero · Pull Request #723 · argszero/emrg · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Agent.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -118,7 +118,7 @@ Community needs voiced in HN agent-UI discussions map directly to EMRG's design:
pkill -f "emrg.server"; rm -f ~/.emrg/emrgd.port; python -m emrg
```

Python: `uv run pytest tests/ -v` (748) — import check: `uv run python -c "from emrg.client.app import run_client"`
Python: `uv run pytest tests/ -v` (758) — import check: `uv run python -c "from emrg.client.app import run_client"`
GUI: `cd emrg/gui && npm test` (229: 44 daemon_client + 19 conn-manager + 22 app-commands + 107 renderer smoke + 15 i18n + 7 integration + 3 commands + 5 build-config + 7 gui-state) — syntax: `node --check main.js preload.js daemon_client.js renderer/js/*.js`
CI: `uv run pytest` + GUI tests + **actionlint workflow lint** (`rhysd/actionlint@v1.7.12` gate, #444 — workflow 解析错误在 PR CI 即失败,如 `if:` secrets 上下文)
Re-trigger: `scripts/re-trigger-ci.sh [branch]` (workflow_dispatch, #527 — 替代空 commit 重触发:Actions outage 会整段丢弃 push 事件,dispatch 走 API 路径不受影响)
Expand Down
220 changes: 40 additions & 180 deletions packaging/gen-assets.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -20,6 +20,9 @@ set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
OUT="$ROOT/packaging/assets"
SVG="$OUT/icon.svg"
# pngutil.py (filter-aware PNG decode) lives next to this script — the inline
# python heredocs below import it via PNGUTIL_DIR.
export PNGUTIL_DIR="$ROOT/packaging"
mkdir -p "$OUT"

if [ ! -f "$SVG" ]; then
Expand DownExpand Up@@ -122,129 +125,53 @@ HTMLEOF
# alpha channel; if >90% of pixels are transparent, the renderer failed.
# Returns 0 when the icon is opaque enough (accepted), 1 when blank (caller
# falls back to the next renderer).
# ⚡ Filter-aware decode (v0.2.29 Build Release lesson): rsvg-convert /
# Chrome emit adaptively-filtered PNG rows (Sub/Up/Average/Paeth). A naive
# "strip filter byte" read returns deltas, not pixels — a fully opaque icon
# falsely read as "99.2% transparent" (and the area-average resize produced
# garbage hues). pngutil.read_png reverses filters, so the check sees real
# alpha and the derived icon-512/256/icns/ico are correct.
check_icon_opaque() {
python3 - "$OUT/icon.png" <<'PYEOF'
import sys, struct, zlib

data = open(sys.argv[1], "rb").read()
assert data[:8] == b"\x89PNG\r\n\x1a\n", "not a PNG"
pos, w, h, idat, colortype = 8, 0, 0, b"", 0
while pos < len(data):
ln = struct.unpack(">I", data[pos:pos+4])[0]
tag = data[pos+4:pos+8]
chunk = data[pos+8:pos+8+ln]
if tag == b"IHDR":
w, h = struct.unpack(">II", chunk[:8])
colortype = chunk[9]
elif tag == b"IDAT":
idat += chunk
pos += 12 + ln
import os, sys
sys.path.insert(0, os.environ.get("PNGUTIL_DIR", os.path.join(os.path.dirname(sys.argv[1]), "..")))
import pngutil

w, h, bpp, px = pngutil.read_png(sys.argv[1])
if (w, h) != (1024, 1024):
sys.stderr.write(f"ERROR: expected 1024x1024 PNG, got {w}x{h} — renderer failed\n")
sys.exit(1)
print(f" icon.png OK: {w}x{h}")

if colortype == 6: # RGBA — only then is transparency meaningful
raw = zlib.decompress(idat)
stride0 = w * 4 + 1
raw = b"".join(raw[y*stride0+1:(y+1)*stride0] for y in range(h))
total = opaque = 0
for y in range(0, h, 8):
for x in range(0, w, 8):
a = raw[y*w*4 + x*4 + 3]
total += 1
if a > 0:
opaque += 1
ratio = opaque / total
print(f" icon.png alpha: {ratio:.1%} opaque ({opaque}/{total} sampled)")
if bpp == 4:
ratio = pngutil.opaque_ratio(w, h, bpp, px)
print(f" icon.png alpha: {ratio:.1%} opaque")
if ratio < 0.10:
sys.stderr.write(
f"ERROR: icon.png is {1-ratio:.1%} transparent — renderer failed to paint "
"the SVG. Falling back to next renderer (see rant 2026-08-12T17:25:28).\n"
)
sys.exit(1)
else:
print(f" icon.png alpha: colortype={colortype} (no alpha channel) — assumed opaque")
print(f" icon.png alpha: colortype={'RGB' if bpp == 3 else bpp} (no alpha channel) — assumed opaque")
PYEOF
}

render_svg_to_png || exit 1

echo "==> resizing to 512/256 (stdlib area-average box filter)"
python3 - "$OUT/icon.png" "$OUT" <<'PYEOF'
import sys, zlib, struct
import os, sys
sys.path.insert(0, os.environ.get("PNGUTIL_DIR", os.path.join(os.path.dirname(sys.argv[1]), "..")))
import pngutil

src, outdir = sys.argv[1], sys.argv[2]

def read_png(path):
data = open(path, "rb").read()
assert data[:8] == b"\x89PNG\r\n\x1a\n"
pos, w, h, idat, ct = 8, 0, 0, b"", 0
while pos < len(data):
ln = struct.unpack(">I", data[pos:pos+4])[0]
tag = data[pos+4:pos+8]
chunk = data[pos+8:pos+8+ln]
if tag == b"IHDR":
w, h = struct.unpack(">II", chunk[:8])
ct = chunk[9]
elif tag == b"IDAT":
idat += chunk
pos += 12 + ln
raw = zlib.decompress(idat)
# PNG scanlines each have a leading filter byte (0 for None); strip them.
# Chrome headless emits RGB (ct=2) when the page bg is opaque; rsvg-convert
# emits RGBA (ct=6). Normalize to RGBA so downstream code can assume 4 bpp.
if ct == 6:
stride0 = w * 4 + 1
raw = b"".join(raw[y*stride0+1:(y+1)*stride0] for y in range(h))
elif ct == 2:
stride0 = w * 3 + 1
rows = [raw[y*stride0+1:(y+1)*stride0] for y in range(h)]
out = bytearray()
for row in rows:
for i in range(0, len(row), 3):
out += row[i:i+3] + b"\xff"
raw = bytes(out)
else:
raise SystemExit(f"unsupported PNG colortype {ct}")
return w, h, raw

w, h, raw = read_png(src)
stride = w * 4

def resize_area(nw, nh):
"""Area-average (box filter) downscale — better antialiasing than nearest."""
out = bytearray([0, 0, 0, 0]) * (nw * nh)
for yy in range(nh):
y0 = yy * h // nh
y1 = max(y0 + 1, (yy + 1) * h // nh)
for xx in range(nw):
x0 = xx * w // nw
x1 = max(x0 + 1, (xx + 1) * w // nw)
r = g = b = a = 0
n = 0
for sy in range(y0, y1):
for sx in range(x0, x1):
i = sy * stride + sx * 4
r += raw[i]; g += raw[i+1]; b += raw[i+2]; a += raw[i+3]
n += 1
o = (yy * nw + xx) * 4
out[o] = r // n; out[o+1] = g // n; out[o+2] = b // n; out[o+3] = a // n
return bytes(out)

def write_png(path, nw, nh, rgba):
def chunk(tag, data):
c = struct.pack(">I", len(data)) + tag + data
c += struct.pack(">I", zlib.crc32(tag + data) & 0xffffffff)
return c
raw = b"".join(b"\x00" + rgba[y*nw*4:(y+1)*nw*4] for y in range(nh))
png = b"\x89PNG\r\n\x1a\n" + chunk(b"IHDR", struct.pack(">IIBBBBB", nw, nh, 8, 6, 0, 0, 0)) + chunk(b"IDAT", zlib.compress(raw, 9)) + chunk(b"IEND", b"")
open(path, "wb").write(png)
w, h, bpp, px = pngutil.read_png(src)
rgba = pngutil.to_rgba(w, h, bpp, px)

for size in (512, 256):
p = f"{outdir}/icon-{size}.png"
write_png(p, size, size, resize_area(size, size))
pngutil.write_png(p, size, size, pngutil.resize_area(rgba, w, h, size, size))
print(" wrote", p)
PYEOF

Expand All@@ -255,47 +182,14 @@ if command -v iconutil >/dev/null 2>&1; then
# iconutil wants specific sizes
for s in 16 32 128 256 512; do
python3 - "$OUT/icon.png" "$ICONSET/icon_${s}x${s}.png" "$s" <<'PYEOF'
import sys, zlib, struct
import os, sys
sys.path.insert(0, os.environ.get("PNGUTIL_DIR", os.path.join(os.path.dirname(sys.argv[1]), "..")))
import pngutil

src, dst, size = sys.argv[1], sys.argv[2], int(sys.argv[3])
data = open(src, "rb").read(); pos, w, h, idat, ct = 8, 0, 0, b"", 0
while pos < len(data):
ln = struct.unpack(">I", data[pos:pos+4])[0]; tag = data[pos+4:pos+8]; chunk = data[pos+8:pos+8+ln]
if tag == b"IHDR": w, h = struct.unpack(">II", chunk[:8]); ct = chunk[9]
elif tag == b"IDAT": idat += chunk
pos += 12 + ln
raw = zlib.decompress(idat)
if ct == 6:
stride0 = w*4 + 1
raw = b"".join(raw[y*stride0+1:(y+1)*stride0] for y in range(h))
else: # ct==2 RGB → expand to RGBA
stride0 = w*3 + 1
rows = [raw[y*stride0+1:(y+1)*stride0] for y in range(h)]
out = bytearray()
for row in rows:
for i in range(0, len(row), 3):
out += row[i:i+3] + b"\xff"
raw = bytes(out)
stride = w*4
def resize_area(nw, nh):
out = bytearray([0,0,0,0])*(nw*nh)
for yy in range(nh):
y0 = yy*h//nh; y1 = max(y0+1, (yy+1)*h//nh)
for xx in range(nw):
x0 = xx*w//nw; x1 = max(x0+1, (xx+1)*w//nw)
r = g = b = a = n = 0
for sy in range(y0, y1):
for sx in range(x0, x1):
i = sy*stride + sx*4
r += raw[i]; g += raw[i+1]; b += raw[i+2]; a += raw[i+3]; n += 1
o = (yy*nw+xx)*4
out[o] = r//n; out[o+1] = g//n; out[o+2] = b//n; out[o+3] = a//n
return bytes(out)
def chunk(tag, data):
c = struct.pack(">I", len(data))+tag+data; c += struct.pack(">I", zlib.crc32(tag+data)&0xffffffff); return c
rgba = resize_area(size, size)
raw2 = b"".join(b"\x00"+rgba[y*size*4:(y+1)*size*4] for y in range(size))
png = b"\x89PNG\r\n\x1a\n"+chunk(b"IHDR", struct.pack(">IIBBBBB", size, size, 8, 6, 0, 0, 0))+chunk(b"IDAT", zlib.compress(raw2,9))+chunk(b"IEND", b"")
open(dst, "wb").write(png)
w, h, bpp, px = pngutil.read_png(src)
rgba = pngutil.to_rgba(w, h, bpp, px)
pngutil.write_png(dst, size, size, pngutil.resize_area(rgba, w, h, size, size))
PYEOF
cp "$ICONSET/icon_${s}x${s}.png" "$ICONSET/icon_${s}x${s}@2x.png" 2>/dev/null || true
done
Expand All@@ -309,57 +203,23 @@ fi

echo "==> icon.ico (multi-size, win)"
python3 - "$OUT/icon.png" "$OUT/icon.ico" <<'PYEOF'
import sys, zlib, struct
src, dst = sys.argv[1], sys.argv[2]
data = open(src, "rb").read(); pos, w, h, idat, ct = 8, 0, 0, b"", 0
while pos < len(data):
ln = struct.unpack(">I", data[pos:pos+4])[0]; tag = data[pos+4:pos+8]; chunk = data[pos+8:pos+8+ln]
if tag == b"IHDR": w, h = struct.unpack(">II", chunk[:8]); ct = chunk[9]
elif tag == b"IDAT": idat += chunk
pos += 12 + ln
raw = zlib.decompress(idat)
if ct == 6:
stride0 = w*4 + 1
raw = b"".join(raw[y*stride0+1:(y+1)*stride0] for y in range(h))
else: # ct==2 RGB → expand to RGBA
stride0 = w*3 + 1
rows = [raw[y*stride0+1:(y+1)*stride0] for y in range(h)]
out = bytearray()
for row in rows:
for i in range(0, len(row), 3):
out += row[i:i+3] + b"\xff"
raw = bytes(out)
stride = w*4
import os, sys
sys.path.insert(0, os.environ.get("PNGUTIL_DIR", os.path.join(os.path.dirname(sys.argv[1]), "..")))
import struct
import pngutil

def resize_area(nw, nh):
out = bytearray([0,0,0,0])*(nw*nh)
for yy in range(nh):
y0 = yy*h//nh; y1 = max(y0+1, (yy+1)*h//nh)
for xx in range(nw):
x0 = xx*w//nw; x1 = max(x0+1, (xx+1)*w//nw)
r = g = b = a = n = 0
for sy in range(y0, y1):
for sx in range(x0, x1):
i = sy*stride + sx*4
r += raw[i]; g += raw[i+1]; b += raw[i+2]; a += raw[i+3]; n += 1
o = (yy*nw+xx)*4
out[o] = r//n; out[o+1] = g//n; out[o+2] = b//n; out[o+3] = a//n
return bytes(out)

def png_bytes(nw, nh, rgba):
def chunk(tag, data):
c = struct.pack(">I", len(data))+tag+data; c += struct.pack(">I", zlib.crc32(tag+data)&0xffffffff); return c
raw2 = b"".join(b"\x00"+rgba[y*nw*4:(y+1)*nw*4] for y in range(nh))
return b"\x89PNG\r\n\x1a\n"+chunk(b"IHDR", struct.pack(">IIBBBBB", nw, nh, 8, 6, 0, 0, 0))+chunk(b"IDAT", zlib.compress(raw2,9))+chunk(b"IEND", b"")
src, dst = sys.argv[1], sys.argv[2]
w, h, bpp, px = pngutil.read_png(src)
rgba = pngutil.to_rgba(w, h, bpp, px)

# ICO: header + directory + PNG-embedded entries
sizes = [16, 24, 32, 48, 64, 128, 256]
imgs = [(s, png_bytes(s, s, resize_area(s, s))) for s in sizes]
imgs = [(s, pngutil.write_png_bytes(s, s, pngutil.resize_area(rgba, w, h, s, s))) for s in sizes]
header = struct.pack("<HHH", 0, 1, len(imgs))
offset = 6 + 16*len(imgs)
offset = 6 + 16 * len(imgs)
entries = b""
for s, png in imgs:
entries += struct.pack("<BBBBHHII", s if s<256 else 0, s if s<256 else 0, 0, 0, 1, 32, len(png), offset)
entries += struct.pack("<BBBBHHII", s if s < 256 else 0, s if s < 256 else 0, 0, 0, 1, 32, len(png), offset)
offset += len(png)
with open(dst, "wb") as f:
f.write(header + entries + b"".join(p for _, p in imgs))
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ' emrg: fix v0.2.29 Build Release gates — Windows git.EXE fake + filter-aware icon decode by argszero · Pull Request #723 · argszero/emrg · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Agent.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -118,7 +118,7 @@ Community needs voiced in HN agent-UI discussions map directly to EMRG's design:
pkill -f "emrg.server"; rm -f ~/.emrg/emrgd.port; python -m emrg
```

Python: `uv run pytest tests/ -v` (748) — import check: `uv run python -c "from emrg.client.app import run_client"`
Python: `uv run pytest tests/ -v` (758) — import check: `uv run python -c "from emrg.client.app import run_client"`
GUI: `cd emrg/gui && npm test` (229: 44 daemon_client + 19 conn-manager + 22 app-commands + 107 renderer smoke + 15 i18n + 7 integration + 3 commands + 5 build-config + 7 gui-state) — syntax: `node --check main.js preload.js daemon_client.js renderer/js/*.js`
CI: `uv run pytest` + GUI tests + **actionlint workflow lint** (`rhysd/actionlint@v1.7.12` gate, #444 — workflow 解析错误在 PR CI 即失败,如 `if:` secrets 上下文)
Re-trigger: `scripts/re-trigger-ci.sh [branch]` (workflow_dispatch, #527 — 替代空 commit 重触发:Actions outage 会整段丢弃 push 事件,dispatch 走 API 路径不受影响)
Expand Down
220 changes: 40 additions & 180 deletions packaging/gen-assets.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -20,6 +20,9 @@ set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
OUT="$ROOT/packaging/assets"
SVG="$OUT/icon.svg"
# pngutil.py (filter-aware PNG decode) lives next to this script — the inline
# python heredocs below import it via PNGUTIL_DIR.
export PNGUTIL_DIR="$ROOT/packaging"
mkdir -p "$OUT"

if [ ! -f "$SVG" ]; then
Expand DownExpand Up@@ -122,129 +125,53 @@ HTMLEOF
# alpha channel; if >90% of pixels are transparent, the renderer failed.
# Returns 0 when the icon is opaque enough (accepted), 1 when blank (caller
# falls back to the next renderer).
# ⚡ Filter-aware decode (v0.2.29 Build Release lesson): rsvg-convert /
# Chrome emit adaptively-filtered PNG rows (Sub/Up/Average/Paeth). A naive
# "strip filter byte" read returns deltas, not pixels — a fully opaque icon
# falsely read as "99.2% transparent" (and the area-average resize produced
# garbage hues). pngutil.read_png reverses filters, so the check sees real
# alpha and the derived icon-512/256/icns/ico are correct.
check_icon_opaque() {
python3 - "$OUT/icon.png" <<'PYEOF'
import sys, struct, zlib

data = open(sys.argv[1], "rb").read()
assert data[:8] == b"\x89PNG\r\n\x1a\n", "not a PNG"
pos, w, h, idat, colortype = 8, 0, 0, b"", 0
while pos < len(data):
ln = struct.unpack(">I", data[pos:pos+4])[0]
tag = data[pos+4:pos+8]
chunk = data[pos+8:pos+8+ln]
if tag == b"IHDR":
w, h = struct.unpack(">II", chunk[:8])
colortype = chunk[9]
elif tag == b"IDAT":
idat += chunk
pos += 12 + ln
import os, sys
sys.path.insert(0, os.environ.get("PNGUTIL_DIR", os.path.join(os.path.dirname(sys.argv[1]), "..")))
import pngutil

w, h, bpp, px = pngutil.read_png(sys.argv[1])
if (w, h) != (1024, 1024):
sys.stderr.write(f"ERROR: expected 1024x1024 PNG, got {w}x{h} — renderer failed\n")
sys.exit(1)
print(f" icon.png OK: {w}x{h}")

if colortype == 6: # RGBA — only then is transparency meaningful
raw = zlib.decompress(idat)
stride0 = w * 4 + 1
raw = b"".join(raw[y*stride0+1:(y+1)*stride0] for y in range(h))
total = opaque = 0
for y in range(0, h, 8):
for x in range(0, w, 8):
a = raw[y*w*4 + x*4 + 3]
total += 1
if a > 0:
opaque += 1
ratio = opaque / total
print(f" icon.png alpha: {ratio:.1%} opaque ({opaque}/{total} sampled)")
if bpp == 4:
ratio = pngutil.opaque_ratio(w, h, bpp, px)
print(f" icon.png alpha: {ratio:.1%} opaque")
if ratio < 0.10:
sys.stderr.write(
f"ERROR: icon.png is {1-ratio:.1%} transparent — renderer failed to paint "
"the SVG. Falling back to next renderer (see rant 2026-08-12T17:25:28).\n"
)
sys.exit(1)
else:
print(f" icon.png alpha: colortype={colortype} (no alpha channel) — assumed opaque")
print(f" icon.png alpha: colortype={'RGB' if bpp == 3 else bpp} (no alpha channel) — assumed opaque")
PYEOF
}

render_svg_to_png || exit 1

echo "==> resizing to 512/256 (stdlib area-average box filter)"
python3 - "$OUT/icon.png" "$OUT" <<'PYEOF'
import sys, zlib, struct
import os, sys
sys.path.insert(0, os.environ.get("PNGUTIL_DIR", os.path.join(os.path.dirname(sys.argv[1]), "..")))
import pngutil

src, outdir = sys.argv[1], sys.argv[2]

def read_png(path):
data = open(path, "rb").read()
assert data[:8] == b"\x89PNG\r\n\x1a\n"
pos, w, h, idat, ct = 8, 0, 0, b"", 0
while pos < len(data):
ln = struct.unpack(">I", data[pos:pos+4])[0]
tag = data[pos+4:pos+8]
chunk = data[pos+8:pos+8+ln]
if tag == b"IHDR":
w, h = struct.unpack(">II", chunk[:8])
ct = chunk[9]
elif tag == b"IDAT":
idat += chunk
pos += 12 + ln
raw = zlib.decompress(idat)
# PNG scanlines each have a leading filter byte (0 for None); strip them.
# Chrome headless emits RGB (ct=2) when the page bg is opaque; rsvg-convert
# emits RGBA (ct=6). Normalize to RGBA so downstream code can assume 4 bpp.
if ct == 6:
stride0 = w * 4 + 1
raw = b"".join(raw[y*stride0+1:(y+1)*stride0] for y in range(h))
elif ct == 2:
stride0 = w * 3 + 1
rows = [raw[y*stride0+1:(y+1)*stride0] for y in range(h)]
out = bytearray()
for row in rows:
for i in range(0, len(row), 3):
out += row[i:i+3] + b"\xff"
raw = bytes(out)
else:
raise SystemExit(f"unsupported PNG colortype {ct}")
return w, h, raw

w, h, raw = read_png(src)
stride = w * 4

def resize_area(nw, nh):
"""Area-average (box filter) downscale — better antialiasing than nearest."""
out = bytearray([0, 0, 0, 0]) * (nw * nh)
for yy in range(nh):
y0 = yy * h // nh
y1 = max(y0 + 1, (yy + 1) * h // nh)
for xx in range(nw):
x0 = xx * w // nw
x1 = max(x0 + 1, (xx + 1) * w // nw)
r = g = b = a = 0
n = 0
for sy in range(y0, y1):
for sx in range(x0, x1):
i = sy * stride + sx * 4
r += raw[i]; g += raw[i+1]; b += raw[i+2]; a += raw[i+3]
n += 1
o = (yy * nw + xx) * 4
out[o] = r // n; out[o+1] = g // n; out[o+2] = b // n; out[o+3] = a // n
return bytes(out)

def write_png(path, nw, nh, rgba):
def chunk(tag, data):
c = struct.pack(">I", len(data)) + tag + data
c += struct.pack(">I", zlib.crc32(tag + data) & 0xffffffff)
return c
raw = b"".join(b"\x00" + rgba[y*nw*4:(y+1)*nw*4] for y in range(nh))
png = b"\x89PNG\r\n\x1a\n" + chunk(b"IHDR", struct.pack(">IIBBBBB", nw, nh, 8, 6, 0, 0, 0)) + chunk(b"IDAT", zlib.compress(raw, 9)) + chunk(b"IEND", b"")
open(path, "wb").write(png)
w, h, bpp, px = pngutil.read_png(src)
rgba = pngutil.to_rgba(w, h, bpp, px)

for size in (512, 256):
p = f"{outdir}/icon-{size}.png"
write_png(p, size, size, resize_area(size, size))
pngutil.write_png(p, size, size, pngutil.resize_area(rgba, w, h, size, size))
print(" wrote", p)
PYEOF

Expand All@@ -255,47 +182,14 @@ if command -v iconutil >/dev/null 2>&1; then
# iconutil wants specific sizes
for s in 16 32 128 256 512; do
python3 - "$OUT/icon.png" "$ICONSET/icon_${s}x${s}.png" "$s" <<'PYEOF'
import sys, zlib, struct
import os, sys
sys.path.insert(0, os.environ.get("PNGUTIL_DIR", os.path.join(os.path.dirname(sys.argv[1]), "..")))
import pngutil

src, dst, size = sys.argv[1], sys.argv[2], int(sys.argv[3])
data = open(src, "rb").read(); pos, w, h, idat, ct = 8, 0, 0, b"", 0
while pos < len(data):
ln = struct.unpack(">I", data[pos:pos+4])[0]; tag = data[pos+4:pos+8]; chunk = data[pos+8:pos+8+ln]
if tag == b"IHDR": w, h = struct.unpack(">II", chunk[:8]); ct = chunk[9]
elif tag == b"IDAT": idat += chunk
pos += 12 + ln
raw = zlib.decompress(idat)
if ct == 6:
stride0 = w*4 + 1
raw = b"".join(raw[y*stride0+1:(y+1)*stride0] for y in range(h))
else: # ct==2 RGB → expand to RGBA
stride0 = w*3 + 1
rows = [raw[y*stride0+1:(y+1)*stride0] for y in range(h)]
out = bytearray()
for row in rows:
for i in range(0, len(row), 3):
out += row[i:i+3] + b"\xff"
raw = bytes(out)
stride = w*4
def resize_area(nw, nh):
out = bytearray([0,0,0,0])*(nw*nh)
for yy in range(nh):
y0 = yy*h//nh; y1 = max(y0+1, (yy+1)*h//nh)
for xx in range(nw):
x0 = xx*w//nw; x1 = max(x0+1, (xx+1)*w//nw)
r = g = b = a = n = 0
for sy in range(y0, y1):
for sx in range(x0, x1):
i = sy*stride + sx*4
r += raw[i]; g += raw[i+1]; b += raw[i+2]; a += raw[i+3]; n += 1
o = (yy*nw+xx)*4
out[o] = r//n; out[o+1] = g//n; out[o+2] = b//n; out[o+3] = a//n
return bytes(out)
def chunk(tag, data):
c = struct.pack(">I", len(data))+tag+data; c += struct.pack(">I", zlib.crc32(tag+data)&0xffffffff); return c
rgba = resize_area(size, size)
raw2 = b"".join(b"\x00"+rgba[y*size*4:(y+1)*size*4] for y in range(size))
png = b"\x89PNG\r\n\x1a\n"+chunk(b"IHDR", struct.pack(">IIBBBBB", size, size, 8, 6, 0, 0, 0))+chunk(b"IDAT", zlib.compress(raw2,9))+chunk(b"IEND", b"")
open(dst, "wb").write(png)
w, h, bpp, px = pngutil.read_png(src)
rgba = pngutil.to_rgba(w, h, bpp, px)
pngutil.write_png(dst, size, size, pngutil.resize_area(rgba, w, h, size, size))
PYEOF
cp "$ICONSET/icon_${s}x${s}.png" "$ICONSET/icon_${s}x${s}@2x.png" 2>/dev/null || true
done
Expand All@@ -309,57 +203,23 @@ fi

echo "==> icon.ico (multi-size, win)"
python3 - "$OUT/icon.png" "$OUT/icon.ico" <<'PYEOF'
import sys, zlib, struct
src, dst = sys.argv[1], sys.argv[2]
data = open(src, "rb").read(); pos, w, h, idat, ct = 8, 0, 0, b"", 0
while pos < len(data):
ln = struct.unpack(">I", data[pos:pos+4])[0]; tag = data[pos+4:pos+8]; chunk = data[pos+8:pos+8+ln]
if tag == b"IHDR": w, h = struct.unpack(">II", chunk[:8]); ct = chunk[9]
elif tag == b"IDAT": idat += chunk
pos += 12 + ln
raw = zlib.decompress(idat)
if ct == 6:
stride0 = w*4 + 1
raw = b"".join(raw[y*stride0+1:(y+1)*stride0] for y in range(h))
else: # ct==2 RGB → expand to RGBA
stride0 = w*3 + 1
rows = [raw[y*stride0+1:(y+1)*stride0] for y in range(h)]
out = bytearray()
for row in rows:
for i in range(0, len(row), 3):
out += row[i:i+3] + b"\xff"
raw = bytes(out)
stride = w*4
import os, sys
sys.path.insert(0, os.environ.get("PNGUTIL_DIR", os.path.join(os.path.dirname(sys.argv[1]), "..")))
import struct
import pngutil

def resize_area(nw, nh):
out = bytearray([0,0,0,0])*(nw*nh)
for yy in range(nh):
y0 = yy*h//nh; y1 = max(y0+1, (yy+1)*h//nh)
for xx in range(nw):
x0 = xx*w//nw; x1 = max(x0+1, (xx+1)*w//nw)
r = g = b = a = n = 0
for sy in range(y0, y1):
for sx in range(x0, x1):
i = sy*stride + sx*4
r += raw[i]; g += raw[i+1]; b += raw[i+2]; a += raw[i+3]; n += 1
o = (yy*nw+xx)*4
out[o] = r//n; out[o+1] = g//n; out[o+2] = b//n; out[o+3] = a//n
return bytes(out)

def png_bytes(nw, nh, rgba):
def chunk(tag, data):
c = struct.pack(">I", len(data))+tag+data; c += struct.pack(">I", zlib.crc32(tag+data)&0xffffffff); return c
raw2 = b"".join(b"\x00"+rgba[y*nw*4:(y+1)*nw*4] for y in range(nh))
return b"\x89PNG\r\n\x1a\n"+chunk(b"IHDR", struct.pack(">IIBBBBB", nw, nh, 8, 6, 0, 0, 0))+chunk(b"IDAT", zlib.compress(raw2,9))+chunk(b"IEND", b"")
src, dst = sys.argv[1], sys.argv[2]
w, h, bpp, px = pngutil.read_png(src)
rgba = pngutil.to_rgba(w, h, bpp, px)

# ICO: header + directory + PNG-embedded entries
sizes = [16, 24, 32, 48, 64, 128, 256]
imgs = [(s, png_bytes(s, s, resize_area(s, s))) for s in sizes]
imgs = [(s, pngutil.write_png_bytes(s, s, pngutil.resize_area(rgba, w, h, s, s))) for s in sizes]
header = struct.pack("<HHH", 0, 1, len(imgs))
offset = 6 + 16*len(imgs)
offset = 6 + 16 * len(imgs)
entries = b""
for s, png in imgs:
entries += struct.pack("<BBBBHHII", s if s<256 else 0, s if s<256 else 0, 0, 0, 1, 32, len(png), offset)
entries += struct.pack("<BBBBHHII", s if s < 256 else 0, s if s < 256 else 0, 0, 0, 1, 32, len(png), offset)
offset += len(png)
with open(dst, "wb") as f:
f.write(header + entries + b"".join(p for _, p in imgs))
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' emrg: fix v0.2.29 Build Release gates — Windows git.EXE fake + filter-aware icon decode by argszero · Pull Request #723 · argszero/emrg · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Agent.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -118,7 +118,7 @@ Community needs voiced in HN agent-UI discussions map directly to EMRG's design:
pkill -f "emrg.server"; rm -f ~/.emrg/emrgd.port; python -m emrg
```

Python: `uv run pytest tests/ -v` (748) — import check: `uv run python -c "from emrg.client.app import run_client"`
Python: `uv run pytest tests/ -v` (758) — import check: `uv run python -c "from emrg.client.app import run_client"`
GUI: `cd emrg/gui && npm test` (229: 44 daemon_client + 19 conn-manager + 22 app-commands + 107 renderer smoke + 15 i18n + 7 integration + 3 commands + 5 build-config + 7 gui-state) — syntax: `node --check main.js preload.js daemon_client.js renderer/js/*.js`
CI: `uv run pytest` + GUI tests + **actionlint workflow lint** (`rhysd/actionlint@v1.7.12` gate, #444 — workflow 解析错误在 PR CI 即失败,如 `if:` secrets 上下文)
Re-trigger: `scripts/re-trigger-ci.sh [branch]` (workflow_dispatch, #527 — 替代空 commit 重触发:Actions outage 会整段丢弃 push 事件,dispatch 走 API 路径不受影响)
Expand Down
220 changes: 40 additions & 180 deletions packaging/gen-assets.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -20,6 +20,9 @@ set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
OUT="$ROOT/packaging/assets"
SVG="$OUT/icon.svg"
# pngutil.py (filter-aware PNG decode) lives next to this script — the inline
# python heredocs below import it via PNGUTIL_DIR.
export PNGUTIL_DIR="$ROOT/packaging"
mkdir -p "$OUT"

if [ ! -f "$SVG" ]; then
Expand DownExpand Up@@ -122,129 +125,53 @@ HTMLEOF
# alpha channel; if >90% of pixels are transparent, the renderer failed.
# Returns 0 when the icon is opaque enough (accepted), 1 when blank (caller
# falls back to the next renderer).
# ⚡ Filter-aware decode (v0.2.29 Build Release lesson): rsvg-convert /
# Chrome emit adaptively-filtered PNG rows (Sub/Up/Average/Paeth). A naive
# "strip filter byte" read returns deltas, not pixels — a fully opaque icon
# falsely read as "99.2% transparent" (and the area-average resize produced
# garbage hues). pngutil.read_png reverses filters, so the check sees real
# alpha and the derived icon-512/256/icns/ico are correct.
check_icon_opaque() {
python3 - "$OUT/icon.png" <<'PYEOF'
import sys, struct, zlib

data = open(sys.argv[1], "rb").read()
assert data[:8] == b"\x89PNG\r\n\x1a\n", "not a PNG"
pos, w, h, idat, colortype = 8, 0, 0, b"", 0
while pos < len(data):
ln = struct.unpack(">I", data[pos:pos+4])[0]
tag = data[pos+4:pos+8]
chunk = data[pos+8:pos+8+ln]
if tag == b"IHDR":
w, h = struct.unpack(">II", chunk[:8])
colortype = chunk[9]
elif tag == b"IDAT":
idat += chunk
pos += 12 + ln
import os, sys
sys.path.insert(0, os.environ.get("PNGUTIL_DIR", os.path.join(os.path.dirname(sys.argv[1]), "..")))
import pngutil

w, h, bpp, px = pngutil.read_png(sys.argv[1])
if (w, h) != (1024, 1024):
sys.stderr.write(f"ERROR: expected 1024x1024 PNG, got {w}x{h} — renderer failed\n")
sys.exit(1)
print(f" icon.png OK: {w}x{h}")

if colortype == 6: # RGBA — only then is transparency meaningful
raw = zlib.decompress(idat)
stride0 = w * 4 + 1
raw = b"".join(raw[y*stride0+1:(y+1)*stride0] for y in range(h))
total = opaque = 0
for y in range(0, h, 8):
for x in range(0, w, 8):
a = raw[y*w*4 + x*4 + 3]
total += 1
if a > 0:
opaque += 1
ratio = opaque / total
print(f" icon.png alpha: {ratio:.1%} opaque ({opaque}/{total} sampled)")
if bpp == 4:
ratio = pngutil.opaque_ratio(w, h, bpp, px)
print(f" icon.png alpha: {ratio:.1%} opaque")
if ratio < 0.10:
sys.stderr.write(
f"ERROR: icon.png is {1-ratio:.1%} transparent — renderer failed to paint "
"the SVG. Falling back to next renderer (see rant 2026-08-12T17:25:28).\n"
)
sys.exit(1)
else:
print(f" icon.png alpha: colortype={colortype} (no alpha channel) — assumed opaque")
print(f" icon.png alpha: colortype={'RGB' if bpp == 3 else bpp} (no alpha channel) — assumed opaque")
PYEOF
}

render_svg_to_png || exit 1

echo "==> resizing to 512/256 (stdlib area-average box filter)"
python3 - "$OUT/icon.png" "$OUT" <<'PYEOF'
import sys, zlib, struct
import os, sys
sys.path.insert(0, os.environ.get("PNGUTIL_DIR", os.path.join(os.path.dirname(sys.argv[1]), "..")))
import pngutil

src, outdir = sys.argv[1], sys.argv[2]

def read_png(path):
data = open(path, "rb").read()
assert data[:8] == b"\x89PNG\r\n\x1a\n"
pos, w, h, idat, ct = 8, 0, 0, b"", 0
while pos < len(data):
ln = struct.unpack(">I", data[pos:pos+4])[0]
tag = data[pos+4:pos+8]
chunk = data[pos+8:pos+8+ln]
if tag == b"IHDR":
w, h = struct.unpack(">II", chunk[:8])
ct = chunk[9]
elif tag == b"IDAT":
idat += chunk
pos += 12 + ln
raw = zlib.decompress(idat)
# PNG scanlines each have a leading filter byte (0 for None); strip them.
# Chrome headless emits RGB (ct=2) when the page bg is opaque; rsvg-convert
# emits RGBA (ct=6). Normalize to RGBA so downstream code can assume 4 bpp.
if ct == 6:
stride0 = w * 4 + 1
raw = b"".join(raw[y*stride0+1:(y+1)*stride0] for y in range(h))
elif ct == 2:
stride0 = w * 3 + 1
rows = [raw[y*stride0+1:(y+1)*stride0] for y in range(h)]
out = bytearray()
for row in rows:
for i in range(0, len(row), 3):
out += row[i:i+3] + b"\xff"
raw = bytes(out)
else:
raise SystemExit(f"unsupported PNG colortype {ct}")
return w, h, raw

w, h, raw = read_png(src)
stride = w * 4

def resize_area(nw, nh):
"""Area-average (box filter) downscale — better antialiasing than nearest."""
out = bytearray([0, 0, 0, 0]) * (nw * nh)
for yy in range(nh):
y0 = yy * h // nh
y1 = max(y0 + 1, (yy + 1) * h // nh)
for xx in range(nw):
x0 = xx * w // nw
x1 = max(x0 + 1, (xx + 1) * w // nw)
r = g = b = a = 0
n = 0
for sy in range(y0, y1):
for sx in range(x0, x1):
i = sy * stride + sx * 4
r += raw[i]; g += raw[i+1]; b += raw[i+2]; a += raw[i+3]
n += 1
o = (yy * nw + xx) * 4
out[o] = r // n; out[o+1] = g // n; out[o+2] = b // n; out[o+3] = a // n
return bytes(out)

def write_png(path, nw, nh, rgba):
def chunk(tag, data):
c = struct.pack(">I", len(data)) + tag + data
c += struct.pack(">I", zlib.crc32(tag + data) & 0xffffffff)
return c
raw = b"".join(b"\x00" + rgba[y*nw*4:(y+1)*nw*4] for y in range(nh))
png = b"\x89PNG\r\n\x1a\n" + chunk(b"IHDR", struct.pack(">IIBBBBB", nw, nh, 8, 6, 0, 0, 0)) + chunk(b"IDAT", zlib.compress(raw, 9)) + chunk(b"IEND", b"")
open(path, "wb").write(png)
w, h, bpp, px = pngutil.read_png(src)
rgba = pngutil.to_rgba(w, h, bpp, px)

for size in (512, 256):
p = f"{outdir}/icon-{size}.png"
write_png(p, size, size, resize_area(size, size))
pngutil.write_png(p, size, size, pngutil.resize_area(rgba, w, h, size, size))
print(" wrote", p)
PYEOF

Expand All@@ -255,47 +182,14 @@ if command -v iconutil >/dev/null 2>&1; then
# iconutil wants specific sizes
for s in 16 32 128 256 512; do
python3 - "$OUT/icon.png" "$ICONSET/icon_${s}x${s}.png" "$s" <<'PYEOF'
import sys, zlib, struct
import os, sys
sys.path.insert(0, os.environ.get("PNGUTIL_DIR", os.path.join(os.path.dirname(sys.argv[1]), "..")))
import pngutil

src, dst, size = sys.argv[1], sys.argv[2], int(sys.argv[3])
data = open(src, "rb").read(); pos, w, h, idat, ct = 8, 0, 0, b"", 0
while pos < len(data):
ln = struct.unpack(">I", data[pos:pos+4])[0]; tag = data[pos+4:pos+8]; chunk = data[pos+8:pos+8+ln]
if tag == b"IHDR": w, h = struct.unpack(">II", chunk[:8]); ct = chunk[9]
elif tag == b"IDAT": idat += chunk
pos += 12 + ln
raw = zlib.decompress(idat)
if ct == 6:
stride0 = w*4 + 1
raw = b"".join(raw[y*stride0+1:(y+1)*stride0] for y in range(h))
else: # ct==2 RGB → expand to RGBA
stride0 = w*3 + 1
rows = [raw[y*stride0+1:(y+1)*stride0] for y in range(h)]
out = bytearray()
for row in rows:
for i in range(0, len(row), 3):
out += row[i:i+3] + b"\xff"
raw = bytes(out)
stride = w*4
def resize_area(nw, nh):
out = bytearray([0,0,0,0])*(nw*nh)
for yy in range(nh):
y0 = yy*h//nh; y1 = max(y0+1, (yy+1)*h//nh)
for xx in range(nw):
x0 = xx*w//nw; x1 = max(x0+1, (xx+1)*w//nw)
r = g = b = a = n = 0
for sy in range(y0, y1):
for sx in range(x0, x1):
i = sy*stride + sx*4
r += raw[i]; g += raw[i+1]; b += raw[i+2]; a += raw[i+3]; n += 1
o = (yy*nw+xx)*4
out[o] = r//n; out[o+1] = g//n; out[o+2] = b//n; out[o+3] = a//n
return bytes(out)
def chunk(tag, data):
c = struct.pack(">I", len(data))+tag+data; c += struct.pack(">I", zlib.crc32(tag+data)&0xffffffff); return c
rgba = resize_area(size, size)
raw2 = b"".join(b"\x00"+rgba[y*size*4:(y+1)*size*4] for y in range(size))
png = b"\x89PNG\r\n\x1a\n"+chunk(b"IHDR", struct.pack(">IIBBBBB", size, size, 8, 6, 0, 0, 0))+chunk(b"IDAT", zlib.compress(raw2,9))+chunk(b"IEND", b"")
open(dst, "wb").write(png)
w, h, bpp, px = pngutil.read_png(src)
rgba = pngutil.to_rgba(w, h, bpp, px)
pngutil.write_png(dst, size, size, pngutil.resize_area(rgba, w, h, size, size))
PYEOF
cp "$ICONSET/icon_${s}x${s}.png" "$ICONSET/icon_${s}x${s}@2x.png" 2>/dev/null || true
done
Expand All@@ -309,57 +203,23 @@ fi

echo "==> icon.ico (multi-size, win)"
python3 - "$OUT/icon.png" "$OUT/icon.ico" <<'PYEOF'
import sys, zlib, struct
src, dst = sys.argv[1], sys.argv[2]
data = open(src, "rb").read(); pos, w, h, idat, ct = 8, 0, 0, b"", 0
while pos < len(data):
ln = struct.unpack(">I", data[pos:pos+4])[0]; tag = data[pos+4:pos+8]; chunk = data[pos+8:pos+8+ln]
if tag == b"IHDR": w, h = struct.unpack(">II", chunk[:8]); ct = chunk[9]
elif tag == b"IDAT": idat += chunk
pos += 12 + ln
raw = zlib.decompress(idat)
if ct == 6:
stride0 = w*4 + 1
raw = b"".join(raw[y*stride0+1:(y+1)*stride0] for y in range(h))
else: # ct==2 RGB → expand to RGBA
stride0 = w*3 + 1
rows = [raw[y*stride0+1:(y+1)*stride0] for y in range(h)]
out = bytearray()
for row in rows:
for i in range(0, len(row), 3):
out += row[i:i+3] + b"\xff"
raw = bytes(out)
stride = w*4
import os, sys
sys.path.insert(0, os.environ.get("PNGUTIL_DIR", os.path.join(os.path.dirname(sys.argv[1]), "..")))
import struct
import pngutil

def resize_area(nw, nh):
out = bytearray([0,0,0,0])*(nw*nh)
for yy in range(nh):
y0 = yy*h//nh; y1 = max(y0+1, (yy+1)*h//nh)
for xx in range(nw):
x0 = xx*w//nw; x1 = max(x0+1, (xx+1)*w//nw)
r = g = b = a = n = 0
for sy in range(y0, y1):
for sx in range(x0, x1):
i = sy*stride + sx*4
r += raw[i]; g += raw[i+1]; b += raw[i+2]; a += raw[i+3]; n += 1
o = (yy*nw+xx)*4
out[o] = r//n; out[o+1] = g//n; out[o+2] = b//n; out[o+3] = a//n
return bytes(out)

def png_bytes(nw, nh, rgba):
def chunk(tag, data):
c = struct.pack(">I", len(data))+tag+data; c += struct.pack(">I", zlib.crc32(tag+data)&0xffffffff); return c
raw2 = b"".join(b"\x00"+rgba[y*nw*4:(y+1)*nw*4] for y in range(nh))
return b"\x89PNG\r\n\x1a\n"+chunk(b"IHDR", struct.pack(">IIBBBBB", nw, nh, 8, 6, 0, 0, 0))+chunk(b"IDAT", zlib.compress(raw2,9))+chunk(b"IEND", b"")
src, dst = sys.argv[1], sys.argv[2]
w, h, bpp, px = pngutil.read_png(src)
rgba = pngutil.to_rgba(w, h, bpp, px)

# ICO: header + directory + PNG-embedded entries
sizes = [16, 24, 32, 48, 64, 128, 256]
imgs = [(s, png_bytes(s, s, resize_area(s, s))) for s in sizes]
imgs = [(s, pngutil.write_png_bytes(s, s, pngutil.resize_area(rgba, w, h, s, s))) for s in sizes]
header = struct.pack("<HHH", 0, 1, len(imgs))
offset = 6 + 16*len(imgs)
offset = 6 + 16 * len(imgs)
entries = b""
for s, png in imgs:
entries += struct.pack("<BBBBHHII", s if s<256 else 0, s if s<256 else 0, 0, 0, 1, 32, len(png), offset)
entries += struct.pack("<BBBBHHII", s if s < 256 else 0, s if s < 256 else 0, 0, 0, 1, 32, len(png), offset)
offset += len(png)
with open(dst, "wb") as f:
f.write(header + entries + b"".join(p for _, p in imgs))
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' emrg: fix v0.2.29 Build Release gates — Windows git.EXE fake + filter-aware icon decode by argszero · Pull Request #723 · argszero/emrg · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Agent.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -118,7 +118,7 @@ Community needs voiced in HN agent-UI discussions map directly to EMRG's design:
pkill -f "emrg.server"; rm -f ~/.emrg/emrgd.port; python -m emrg
```

Python: `uv run pytest tests/ -v` (748) — import check: `uv run python -c "from emrg.client.app import run_client"`
Python: `uv run pytest tests/ -v` (758) — import check: `uv run python -c "from emrg.client.app import run_client"`
GUI: `cd emrg/gui && npm test` (229: 44 daemon_client + 19 conn-manager + 22 app-commands + 107 renderer smoke + 15 i18n + 7 integration + 3 commands + 5 build-config + 7 gui-state) — syntax: `node --check main.js preload.js daemon_client.js renderer/js/*.js`
CI: `uv run pytest` + GUI tests + **actionlint workflow lint** (`rhysd/actionlint@v1.7.12` gate, #444 — workflow 解析错误在 PR CI 即失败,如 `if:` secrets 上下文)
Re-trigger: `scripts/re-trigger-ci.sh [branch]` (workflow_dispatch, #527 — 替代空 commit 重触发:Actions outage 会整段丢弃 push 事件,dispatch 走 API 路径不受影响)
Expand Down
220 changes: 40 additions & 180 deletions packaging/gen-assets.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -20,6 +20,9 @@ set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
OUT="$ROOT/packaging/assets"
SVG="$OUT/icon.svg"
# pngutil.py (filter-aware PNG decode) lives next to this script — the inline
# python heredocs below import it via PNGUTIL_DIR.
export PNGUTIL_DIR="$ROOT/packaging"
mkdir -p "$OUT"

if [ ! -f "$SVG" ]; then
Expand DownExpand Up@@ -122,129 +125,53 @@ HTMLEOF
# alpha channel; if >90% of pixels are transparent, the renderer failed.
# Returns 0 when the icon is opaque enough (accepted), 1 when blank (caller
# falls back to the next renderer).
# ⚡ Filter-aware decode (v0.2.29 Build Release lesson): rsvg-convert /
# Chrome emit adaptively-filtered PNG rows (Sub/Up/Average/Paeth). A naive
# "strip filter byte" read returns deltas, not pixels — a fully opaque icon
# falsely read as "99.2% transparent" (and the area-average resize produced
# garbage hues). pngutil.read_png reverses filters, so the check sees real
# alpha and the derived icon-512/256/icns/ico are correct.
check_icon_opaque() {
python3 - "$OUT/icon.png" <<'PYEOF'
import sys, struct, zlib

data = open(sys.argv[1], "rb").read()
assert data[:8] == b"\x89PNG\r\n\x1a\n", "not a PNG"
pos, w, h, idat, colortype = 8, 0, 0, b"", 0
while pos < len(data):
ln = struct.unpack(">I", data[pos:pos+4])[0]
tag = data[pos+4:pos+8]
chunk = data[pos+8:pos+8+ln]
if tag == b"IHDR":
w, h = struct.unpack(">II", chunk[:8])
colortype = chunk[9]
elif tag == b"IDAT":
idat += chunk
pos += 12 + ln
import os, sys
sys.path.insert(0, os.environ.get("PNGUTIL_DIR", os.path.join(os.path.dirname(sys.argv[1]), "..")))
import pngutil

w, h, bpp, px = pngutil.read_png(sys.argv[1])
if (w, h) != (1024, 1024):
sys.stderr.write(f"ERROR: expected 1024x1024 PNG, got {w}x{h} — renderer failed\n")
sys.exit(1)
print(f" icon.png OK: {w}x{h}")

if colortype == 6: # RGBA — only then is transparency meaningful
raw = zlib.decompress(idat)
stride0 = w * 4 + 1
raw = b"".join(raw[y*stride0+1:(y+1)*stride0] for y in range(h))
total = opaque = 0
for y in range(0, h, 8):
for x in range(0, w, 8):
a = raw[y*w*4 + x*4 + 3]
total += 1
if a > 0:
opaque += 1
ratio = opaque / total
print(f" icon.png alpha: {ratio:.1%} opaque ({opaque}/{total} sampled)")
if bpp == 4:
ratio = pngutil.opaque_ratio(w, h, bpp, px)
print(f" icon.png alpha: {ratio:.1%} opaque")
if ratio < 0.10:
sys.stderr.write(
f"ERROR: icon.png is {1-ratio:.1%} transparent — renderer failed to paint "
"the SVG. Falling back to next renderer (see rant 2026-08-12T17:25:28).\n"
)
sys.exit(1)
else:
print(f" icon.png alpha: colortype={colortype} (no alpha channel) — assumed opaque")
print(f" icon.png alpha: colortype={'RGB' if bpp == 3 else bpp} (no alpha channel) — assumed opaque")
PYEOF
}

render_svg_to_png || exit 1

echo "==> resizing to 512/256 (stdlib area-average box filter)"
python3 - "$OUT/icon.png" "$OUT" <<'PYEOF'
import sys, zlib, struct
import os, sys
sys.path.insert(0, os.environ.get("PNGUTIL_DIR", os.path.join(os.path.dirname(sys.argv[1]), "..")))
import pngutil

src, outdir = sys.argv[1], sys.argv[2]

def read_png(path):
data = open(path, "rb").read()
assert data[:8] == b"\x89PNG\r\n\x1a\n"
pos, w, h, idat, ct = 8, 0, 0, b"", 0
while pos < len(data):
ln = struct.unpack(">I", data[pos:pos+4])[0]
tag = data[pos+4:pos+8]
chunk = data[pos+8:pos+8+ln]
if tag == b"IHDR":
w, h = struct.unpack(">II", chunk[:8])
ct = chunk[9]
elif tag == b"IDAT":
idat += chunk
pos += 12 + ln
raw = zlib.decompress(idat)
# PNG scanlines each have a leading filter byte (0 for None); strip them.
# Chrome headless emits RGB (ct=2) when the page bg is opaque; rsvg-convert
# emits RGBA (ct=6). Normalize to RGBA so downstream code can assume 4 bpp.
if ct == 6:
stride0 = w * 4 + 1
raw = b"".join(raw[y*stride0+1:(y+1)*stride0] for y in range(h))
elif ct == 2:
stride0 = w * 3 + 1
rows = [raw[y*stride0+1:(y+1)*stride0] for y in range(h)]
out = bytearray()
for row in rows:
for i in range(0, len(row), 3):
out += row[i:i+3] + b"\xff"
raw = bytes(out)
else:
raise SystemExit(f"unsupported PNG colortype {ct}")
return w, h, raw

w, h, raw = read_png(src)
stride = w * 4

def resize_area(nw, nh):
"""Area-average (box filter) downscale — better antialiasing than nearest."""
out = bytearray([0, 0, 0, 0]) * (nw * nh)
for yy in range(nh):
y0 = yy * h // nh
y1 = max(y0 + 1, (yy + 1) * h // nh)
for xx in range(nw):
x0 = xx * w // nw
x1 = max(x0 + 1, (xx + 1) * w // nw)
r = g = b = a = 0
n = 0
for sy in range(y0, y1):
for sx in range(x0, x1):
i = sy * stride + sx * 4
r += raw[i]; g += raw[i+1]; b += raw[i+2]; a += raw[i+3]
n += 1
o = (yy * nw + xx) * 4
out[o] = r // n; out[o+1] = g // n; out[o+2] = b // n; out[o+3] = a // n
return bytes(out)

def write_png(path, nw, nh, rgba):
def chunk(tag, data):
c = struct.pack(">I", len(data)) + tag + data
c += struct.pack(">I", zlib.crc32(tag + data) & 0xffffffff)
return c
raw = b"".join(b"\x00" + rgba[y*nw*4:(y+1)*nw*4] for y in range(nh))
png = b"\x89PNG\r\n\x1a\n" + chunk(b"IHDR", struct.pack(">IIBBBBB", nw, nh, 8, 6, 0, 0, 0)) + chunk(b"IDAT", zlib.compress(raw, 9)) + chunk(b"IEND", b"")
open(path, "wb").write(png)
w, h, bpp, px = pngutil.read_png(src)
rgba = pngutil.to_rgba(w, h, bpp, px)

for size in (512, 256):
p = f"{outdir}/icon-{size}.png"
write_png(p, size, size, resize_area(size, size))
pngutil.write_png(p, size, size, pngutil.resize_area(rgba, w, h, size, size))
print(" wrote", p)
PYEOF

Expand All@@ -255,47 +182,14 @@ if command -v iconutil >/dev/null 2>&1; then
# iconutil wants specific sizes
for s in 16 32 128 256 512; do
python3 - "$OUT/icon.png" "$ICONSET/icon_${s}x${s}.png" "$s" <<'PYEOF'
import sys, zlib, struct
import os, sys
sys.path.insert(0, os.environ.get("PNGUTIL_DIR", os.path.join(os.path.dirname(sys.argv[1]), "..")))
import pngutil

src, dst, size = sys.argv[1], sys.argv[2], int(sys.argv[3])
data = open(src, "rb").read(); pos, w, h, idat, ct = 8, 0, 0, b"", 0
while pos < len(data):
ln = struct.unpack(">I", data[pos:pos+4])[0]; tag = data[pos+4:pos+8]; chunk = data[pos+8:pos+8+ln]
if tag == b"IHDR": w, h = struct.unpack(">II", chunk[:8]); ct = chunk[9]
elif tag == b"IDAT": idat += chunk
pos += 12 + ln
raw = zlib.decompress(idat)
if ct == 6:
stride0 = w*4 + 1
raw = b"".join(raw[y*stride0+1:(y+1)*stride0] for y in range(h))
else: # ct==2 RGB → expand to RGBA
stride0 = w*3 + 1
rows = [raw[y*stride0+1:(y+1)*stride0] for y in range(h)]
out = bytearray()
for row in rows:
for i in range(0, len(row), 3):
out += row[i:i+3] + b"\xff"
raw = bytes(out)
stride = w*4
def resize_area(nw, nh):
out = bytearray([0,0,0,0])*(nw*nh)
for yy in range(nh):
y0 = yy*h//nh; y1 = max(y0+1, (yy+1)*h//nh)
for xx in range(nw):
x0 = xx*w//nw; x1 = max(x0+1, (xx+1)*w//nw)
r = g = b = a = n = 0
for sy in range(y0, y1):
for sx in range(x0, x1):
i = sy*stride + sx*4
r += raw[i]; g += raw[i+1]; b += raw[i+2]; a += raw[i+3]; n += 1
o = (yy*nw+xx)*4
out[o] = r//n; out[o+1] = g//n; out[o+2] = b//n; out[o+3] = a//n
return bytes(out)
def chunk(tag, data):
c = struct.pack(">I", len(data))+tag+data; c += struct.pack(">I", zlib.crc32(tag+data)&0xffffffff); return c
rgba = resize_area(size, size)
raw2 = b"".join(b"\x00"+rgba[y*size*4:(y+1)*size*4] for y in range(size))
png = b"\x89PNG\r\n\x1a\n"+chunk(b"IHDR", struct.pack(">IIBBBBB", size, size, 8, 6, 0, 0, 0))+chunk(b"IDAT", zlib.compress(raw2,9))+chunk(b"IEND", b"")
open(dst, "wb").write(png)
w, h, bpp, px = pngutil.read_png(src)
rgba = pngutil.to_rgba(w, h, bpp, px)
pngutil.write_png(dst, size, size, pngutil.resize_area(rgba, w, h, size, size))
PYEOF
cp "$ICONSET/icon_${s}x${s}.png" "$ICONSET/icon_${s}x${s}@2x.png" 2>/dev/null || true
done
Expand All@@ -309,57 +203,23 @@ fi

echo "==> icon.ico (multi-size, win)"
python3 - "$OUT/icon.png" "$OUT/icon.ico" <<'PYEOF'
import sys, zlib, struct
src, dst = sys.argv[1], sys.argv[2]
data = open(src, "rb").read(); pos, w, h, idat, ct = 8, 0, 0, b"", 0
while pos < len(data):
ln = struct.unpack(">I", data[pos:pos+4])[0]; tag = data[pos+4:pos+8]; chunk = data[pos+8:pos+8+ln]
if tag == b"IHDR": w, h = struct.unpack(">II", chunk[:8]); ct = chunk[9]
elif tag == b"IDAT": idat += chunk
pos += 12 + ln
raw = zlib.decompress(idat)
if ct == 6:
stride0 = w*4 + 1
raw = b"".join(raw[y*stride0+1:(y+1)*stride0] for y in range(h))
else: # ct==2 RGB → expand to RGBA
stride0 = w*3 + 1
rows = [raw[y*stride0+1:(y+1)*stride0] for y in range(h)]
out = bytearray()
for row in rows:
for i in range(0, len(row), 3):
out += row[i:i+3] + b"\xff"
raw = bytes(out)
stride = w*4
import os, sys
sys.path.insert(0, os.environ.get("PNGUTIL_DIR", os.path.join(os.path.dirname(sys.argv[1]), "..")))
import struct
import pngutil

def resize_area(nw, nh):
out = bytearray([0,0,0,0])*(nw*nh)
for yy in range(nh):
y0 = yy*h//nh; y1 = max(y0+1, (yy+1)*h//nh)
for xx in range(nw):
x0 = xx*w//nw; x1 = max(x0+1, (xx+1)*w//nw)
r = g = b = a = n = 0
for sy in range(y0, y1):
for sx in range(x0, x1):
i = sy*stride + sx*4
r += raw[i]; g += raw[i+1]; b += raw[i+2]; a += raw[i+3]; n += 1
o = (yy*nw+xx)*4
out[o] = r//n; out[o+1] = g//n; out[o+2] = b//n; out[o+3] = a//n
return bytes(out)

def png_bytes(nw, nh, rgba):
def chunk(tag, data):
c = struct.pack(">I", len(data))+tag+data; c += struct.pack(">I", zlib.crc32(tag+data)&0xffffffff); return c
raw2 = b"".join(b"\x00"+rgba[y*nw*4:(y+1)*nw*4] for y in range(nh))
return b"\x89PNG\r\n\x1a\n"+chunk(b"IHDR", struct.pack(">IIBBBBB", nw, nh, 8, 6, 0, 0, 0))+chunk(b"IDAT", zlib.compress(raw2,9))+chunk(b"IEND", b"")
src, dst = sys.argv[1], sys.argv[2]
w, h, bpp, px = pngutil.read_png(src)
rgba = pngutil.to_rgba(w, h, bpp, px)

# ICO: header + directory + PNG-embedded entries
sizes = [16, 24, 32, 48, 64, 128, 256]
imgs = [(s, png_bytes(s, s, resize_area(s, s))) for s in sizes]
imgs = [(s, pngutil.write_png_bytes(s, s, pngutil.resize_area(rgba, w, h, s, s))) for s in sizes]
header = struct.pack("<HHH", 0, 1, len(imgs))
offset = 6 + 16*len(imgs)
offset = 6 + 16 * len(imgs)
entries = b""
for s, png in imgs:
entries += struct.pack("<BBBBHHII", s if s<256 else 0, s if s<256 else 0, 0, 0, 1, 32, len(png), offset)
entries += struct.pack("<BBBBHHII", s if s < 256 else 0, s if s < 256 else 0, 0, 0, 1, 32, len(png), offset)
offset += len(png)
with open(dst, "wb") as f:
f.write(header + entries + b"".join(p for _, p in imgs))
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Universal Dark Mode - works on any site (function() { var enabled = true; function applyDarkMode() { if (!enabled) return; // Create style element if it doesn't exist var style = document.getElementById('universal-dark-mode-style'); if (!style) { style = document.createElement('style'); style.id = 'universal-dark-mode-style'; document.head.appendChild(style); } // Dark mode CSS - inverts colors but preserves images/video style.textContent = ' /* Invert everything except media */ html { filter: invert(1) hue-rotate(180deg) !important; background: #1a1a2e !important; } /* Restore images, videos, iframes, canvas */ img, video, iframe, canvas, svg, picture, [style*="background-image"] { filter: invert(1) hue-rotate(180deg) !important; } /* Preserve specific elements that should not be inverted */ .no-dark-mode, .no-dark-mode *, [data-theme="light"], [data-theme="light"], .ace_editor, .ace_editor *, .CodeMirror, .CodeMirror *, .monaco-editor, .monaco-editor *, .markdown-body pre, .markdown-body pre *, .highlight, .highlight *, pre code, pre code * { filter: none !important; } /* Fix common UI elements */ .modal, .popup, .dropdown-menu, .tooltip, .popover { filter: invert(1) hue-rotate(180deg) !important; background: #2d2d44 !important; border-color: #444 !important; } /* Scrollbars */ ::-webkit-scrollbar { background: #1a1a2e !important; } ::-webkit-scrollbar-thumb { background: #444 !important; } ::-webkit-scrollbar-thumb:hover { background: #555 !important; } /* Selection */ ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; } ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; } '; } function removeDarkMode() { var style = document.getElementById('universal-dark-mode-style'); if (style) style.remove(); } // Toggle with Alt+Shift+D document.addEventListener('keydown', function(e) { if (e.altKey && e.shiftKey && e.key === 'D') { e.preventDefault(); enabled = !enabled; if (enabled) { applyDarkMode(); console.log('[Universal Dark Mode] Enabled'); } else { removeDarkMode(); console.log('[Universal Dark Mode] Disabled'); } } }); // Apply on load applyDarkMode(); // Re-apply on dynamic content var observer = new MutationObserver(function(mutations) { if (enabled && !document.getElementById('universal-dark-mode-style')) { applyDarkMode(); } }); observer.observe(document.head, { childList: true }); console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle'); })(); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })(); emrg: fix v0.2.29 Build Release gates — Windows git.EXE fake + filter-aware icon decode by argszero · Pull Request #723 · argszero/emrg · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Agent.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -118,7 +118,7 @@ Community needs voiced in HN agent-UI discussions map directly to EMRG's design:
pkill -f "emrg.server"; rm -f ~/.emrg/emrgd.port; python -m emrg
```

Python: `uv run pytest tests/ -v` (748) — import check: `uv run python -c "from emrg.client.app import run_client"`
Python: `uv run pytest tests/ -v` (758) — import check: `uv run python -c "from emrg.client.app import run_client"`
GUI: `cd emrg/gui && npm test` (229: 44 daemon_client + 19 conn-manager + 22 app-commands + 107 renderer smoke + 15 i18n + 7 integration + 3 commands + 5 build-config + 7 gui-state) — syntax: `node --check main.js preload.js daemon_client.js renderer/js/*.js`
CI: `uv run pytest` + GUI tests + **actionlint workflow lint** (`rhysd/actionlint@v1.7.12` gate, #444 — workflow 解析错误在 PR CI 即失败,如 `if:` secrets 上下文)
Re-trigger: `scripts/re-trigger-ci.sh [branch]` (workflow_dispatch, #527 — 替代空 commit 重触发:Actions outage 会整段丢弃 push 事件,dispatch 走 API 路径不受影响)
Expand Down
220 changes: 40 additions & 180 deletions packaging/gen-assets.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -20,6 +20,9 @@ set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
OUT="$ROOT/packaging/assets"
SVG="$OUT/icon.svg"
# pngutil.py (filter-aware PNG decode) lives next to this script — the inline
# python heredocs below import it via PNGUTIL_DIR.
export PNGUTIL_DIR="$ROOT/packaging"
mkdir -p "$OUT"

if [ ! -f "$SVG" ]; then
Expand DownExpand Up@@ -122,129 +125,53 @@ HTMLEOF
# alpha channel; if >90% of pixels are transparent, the renderer failed.
# Returns 0 when the icon is opaque enough (accepted), 1 when blank (caller
# falls back to the next renderer).
# ⚡ Filter-aware decode (v0.2.29 Build Release lesson): rsvg-convert /
# Chrome emit adaptively-filtered PNG rows (Sub/Up/Average/Paeth). A naive
# "strip filter byte" read returns deltas, not pixels — a fully opaque icon
# falsely read as "99.2% transparent" (and the area-average resize produced
# garbage hues). pngutil.read_png reverses filters, so the check sees real
# alpha and the derived icon-512/256/icns/ico are correct.
check_icon_opaque() {
python3 - "$OUT/icon.png" <<'PYEOF'
import sys, struct, zlib

data = open(sys.argv[1], "rb").read()
assert data[:8] == b"\x89PNG\r\n\x1a\n", "not a PNG"
pos, w, h, idat, colortype = 8, 0, 0, b"", 0
while pos < len(data):
ln = struct.unpack(">I", data[pos:pos+4])[0]
tag = data[pos+4:pos+8]
chunk = data[pos+8:pos+8+ln]
if tag == b"IHDR":
w, h = struct.unpack(">II", chunk[:8])
colortype = chunk[9]
elif tag == b"IDAT":
idat += chunk
pos += 12 + ln
import os, sys
sys.path.insert(0, os.environ.get("PNGUTIL_DIR", os.path.join(os.path.dirname(sys.argv[1]), "..")))
import pngutil

w, h, bpp, px = pngutil.read_png(sys.argv[1])
if (w, h) != (1024, 1024):
sys.stderr.write(f"ERROR: expected 1024x1024 PNG, got {w}x{h} — renderer failed\n")
sys.exit(1)
print(f" icon.png OK: {w}x{h}")

if colortype == 6: # RGBA — only then is transparency meaningful
raw = zlib.decompress(idat)
stride0 = w * 4 + 1
raw = b"".join(raw[y*stride0+1:(y+1)*stride0] for y in range(h))
total = opaque = 0
for y in range(0, h, 8):
for x in range(0, w, 8):
a = raw[y*w*4 + x*4 + 3]
total += 1
if a > 0:
opaque += 1
ratio = opaque / total
print(f" icon.png alpha: {ratio:.1%} opaque ({opaque}/{total} sampled)")
if bpp == 4:
ratio = pngutil.opaque_ratio(w, h, bpp, px)
print(f" icon.png alpha: {ratio:.1%} opaque")
if ratio < 0.10:
sys.stderr.write(
f"ERROR: icon.png is {1-ratio:.1%} transparent — renderer failed to paint "
"the SVG. Falling back to next renderer (see rant 2026-08-12T17:25:28).\n"
)
sys.exit(1)
else:
print(f" icon.png alpha: colortype={colortype} (no alpha channel) — assumed opaque")
print(f" icon.png alpha: colortype={'RGB' if bpp == 3 else bpp} (no alpha channel) — assumed opaque")
PYEOF
}

render_svg_to_png || exit 1

echo "==> resizing to 512/256 (stdlib area-average box filter)"
python3 - "$OUT/icon.png" "$OUT" <<'PYEOF'
import sys, zlib, struct
import os, sys
sys.path.insert(0, os.environ.get("PNGUTIL_DIR", os.path.join(os.path.dirname(sys.argv[1]), "..")))
import pngutil

src, outdir = sys.argv[1], sys.argv[2]

def read_png(path):
data = open(path, "rb").read()
assert data[:8] == b"\x89PNG\r\n\x1a\n"
pos, w, h, idat, ct = 8, 0, 0, b"", 0
while pos < len(data):
ln = struct.unpack(">I", data[pos:pos+4])[0]
tag = data[pos+4:pos+8]
chunk = data[pos+8:pos+8+ln]
if tag == b"IHDR":
w, h = struct.unpack(">II", chunk[:8])
ct = chunk[9]
elif tag == b"IDAT":
idat += chunk
pos += 12 + ln
raw = zlib.decompress(idat)
# PNG scanlines each have a leading filter byte (0 for None); strip them.
# Chrome headless emits RGB (ct=2) when the page bg is opaque; rsvg-convert
# emits RGBA (ct=6). Normalize to RGBA so downstream code can assume 4 bpp.
if ct == 6:
stride0 = w * 4 + 1
raw = b"".join(raw[y*stride0+1:(y+1)*stride0] for y in range(h))
elif ct == 2:
stride0 = w * 3 + 1
rows = [raw[y*stride0+1:(y+1)*stride0] for y in range(h)]
out = bytearray()
for row in rows:
for i in range(0, len(row), 3):
out += row[i:i+3] + b"\xff"
raw = bytes(out)
else:
raise SystemExit(f"unsupported PNG colortype {ct}")
return w, h, raw

w, h, raw = read_png(src)
stride = w * 4

def resize_area(nw, nh):
"""Area-average (box filter) downscale — better antialiasing than nearest."""
out = bytearray([0, 0, 0, 0]) * (nw * nh)
for yy in range(nh):
y0 = yy * h // nh
y1 = max(y0 + 1, (yy + 1) * h // nh)
for xx in range(nw):
x0 = xx * w // nw
x1 = max(x0 + 1, (xx + 1) * w // nw)
r = g = b = a = 0
n = 0
for sy in range(y0, y1):
for sx in range(x0, x1):
i = sy * stride + sx * 4
r += raw[i]; g += raw[i+1]; b += raw[i+2]; a += raw[i+3]
n += 1
o = (yy * nw + xx) * 4
out[o] = r // n; out[o+1] = g // n; out[o+2] = b // n; out[o+3] = a // n
return bytes(out)

def write_png(path, nw, nh, rgba):
def chunk(tag, data):
c = struct.pack(">I", len(data)) + tag + data
c += struct.pack(">I", zlib.crc32(tag + data) & 0xffffffff)
return c
raw = b"".join(b"\x00" + rgba[y*nw*4:(y+1)*nw*4] for y in range(nh))
png = b"\x89PNG\r\n\x1a\n" + chunk(b"IHDR", struct.pack(">IIBBBBB", nw, nh, 8, 6, 0, 0, 0)) + chunk(b"IDAT", zlib.compress(raw, 9)) + chunk(b"IEND", b"")
open(path, "wb").write(png)
w, h, bpp, px = pngutil.read_png(src)
rgba = pngutil.to_rgba(w, h, bpp, px)

for size in (512, 256):
p = f"{outdir}/icon-{size}.png"
write_png(p, size, size, resize_area(size, size))
pngutil.write_png(p, size, size, pngutil.resize_area(rgba, w, h, size, size))
print(" wrote", p)
PYEOF

Expand All@@ -255,47 +182,14 @@ if command -v iconutil >/dev/null 2>&1; then
# iconutil wants specific sizes
for s in 16 32 128 256 512; do
python3 - "$OUT/icon.png" "$ICONSET/icon_${s}x${s}.png" "$s" <<'PYEOF'
import sys, zlib, struct
import os, sys
sys.path.insert(0, os.environ.get("PNGUTIL_DIR", os.path.join(os.path.dirname(sys.argv[1]), "..")))
import pngutil

src, dst, size = sys.argv[1], sys.argv[2], int(sys.argv[3])
data = open(src, "rb").read(); pos, w, h, idat, ct = 8, 0, 0, b"", 0
while pos < len(data):
ln = struct.unpack(">I", data[pos:pos+4])[0]; tag = data[pos+4:pos+8]; chunk = data[pos+8:pos+8+ln]
if tag == b"IHDR": w, h = struct.unpack(">II", chunk[:8]); ct = chunk[9]
elif tag == b"IDAT": idat += chunk
pos += 12 + ln
raw = zlib.decompress(idat)
if ct == 6:
stride0 = w*4 + 1
raw = b"".join(raw[y*stride0+1:(y+1)*stride0] for y in range(h))
else: # ct==2 RGB → expand to RGBA
stride0 = w*3 + 1
rows = [raw[y*stride0+1:(y+1)*stride0] for y in range(h)]
out = bytearray()
for row in rows:
for i in range(0, len(row), 3):
out += row[i:i+3] + b"\xff"
raw = bytes(out)
stride = w*4
def resize_area(nw, nh):
out = bytearray([0,0,0,0])*(nw*nh)
for yy in range(nh):
y0 = yy*h//nh; y1 = max(y0+1, (yy+1)*h//nh)
for xx in range(nw):
x0 = xx*w//nw; x1 = max(x0+1, (xx+1)*w//nw)
r = g = b = a = n = 0
for sy in range(y0, y1):
for sx in range(x0, x1):
i = sy*stride + sx*4
r += raw[i]; g += raw[i+1]; b += raw[i+2]; a += raw[i+3]; n += 1
o = (yy*nw+xx)*4
out[o] = r//n; out[o+1] = g//n; out[o+2] = b//n; out[o+3] = a//n
return bytes(out)
def chunk(tag, data):
c = struct.pack(">I", len(data))+tag+data; c += struct.pack(">I", zlib.crc32(tag+data)&0xffffffff); return c
rgba = resize_area(size, size)
raw2 = b"".join(b"\x00"+rgba[y*size*4:(y+1)*size*4] for y in range(size))
png = b"\x89PNG\r\n\x1a\n"+chunk(b"IHDR", struct.pack(">IIBBBBB", size, size, 8, 6, 0, 0, 0))+chunk(b"IDAT", zlib.compress(raw2,9))+chunk(b"IEND", b"")
open(dst, "wb").write(png)
w, h, bpp, px = pngutil.read_png(src)
rgba = pngutil.to_rgba(w, h, bpp, px)
pngutil.write_png(dst, size, size, pngutil.resize_area(rgba, w, h, size, size))
PYEOF
cp "$ICONSET/icon_${s}x${s}.png" "$ICONSET/icon_${s}x${s}@2x.png" 2>/dev/null || true
done
Expand All@@ -309,57 +203,23 @@ fi

echo "==> icon.ico (multi-size, win)"
python3 - "$OUT/icon.png" "$OUT/icon.ico" <<'PYEOF'
import sys, zlib, struct
src, dst = sys.argv[1], sys.argv[2]
data = open(src, "rb").read(); pos, w, h, idat, ct = 8, 0, 0, b"", 0
while pos < len(data):
ln = struct.unpack(">I", data[pos:pos+4])[0]; tag = data[pos+4:pos+8]; chunk = data[pos+8:pos+8+ln]
if tag == b"IHDR": w, h = struct.unpack(">II", chunk[:8]); ct = chunk[9]
elif tag == b"IDAT": idat += chunk
pos += 12 + ln
raw = zlib.decompress(idat)
if ct == 6:
stride0 = w*4 + 1
raw = b"".join(raw[y*stride0+1:(y+1)*stride0] for y in range(h))
else: # ct==2 RGB → expand to RGBA
stride0 = w*3 + 1
rows = [raw[y*stride0+1:(y+1)*stride0] for y in range(h)]
out = bytearray()
for row in rows:
for i in range(0, len(row), 3):
out += row[i:i+3] + b"\xff"
raw = bytes(out)
stride = w*4
import os, sys
sys.path.insert(0, os.environ.get("PNGUTIL_DIR", os.path.join(os.path.dirname(sys.argv[1]), "..")))
import struct
import pngutil

def resize_area(nw, nh):
out = bytearray([0,0,0,0])*(nw*nh)
for yy in range(nh):
y0 = yy*h//nh; y1 = max(y0+1, (yy+1)*h//nh)
for xx in range(nw):
x0 = xx*w//nw; x1 = max(x0+1, (xx+1)*w//nw)
r = g = b = a = n = 0
for sy in range(y0, y1):
for sx in range(x0, x1):
i = sy*stride + sx*4
r += raw[i]; g += raw[i+1]; b += raw[i+2]; a += raw[i+3]; n += 1
o = (yy*nw+xx)*4
out[o] = r//n; out[o+1] = g//n; out[o+2] = b//n; out[o+3] = a//n
return bytes(out)

def png_bytes(nw, nh, rgba):
def chunk(tag, data):
c = struct.pack(">I", len(data))+tag+data; c += struct.pack(">I", zlib.crc32(tag+data)&0xffffffff); return c
raw2 = b"".join(b"\x00"+rgba[y*nw*4:(y+1)*nw*4] for y in range(nh))
return b"\x89PNG\r\n\x1a\n"+chunk(b"IHDR", struct.pack(">IIBBBBB", nw, nh, 8, 6, 0, 0, 0))+chunk(b"IDAT", zlib.compress(raw2,9))+chunk(b"IEND", b"")
src, dst = sys.argv[1], sys.argv[2]
w, h, bpp, px = pngutil.read_png(src)
rgba = pngutil.to_rgba(w, h, bpp, px)

# ICO: header + directory + PNG-embedded entries
sizes = [16, 24, 32, 48, 64, 128, 256]
imgs = [(s, png_bytes(s, s, resize_area(s, s))) for s in sizes]
imgs = [(s, pngutil.write_png_bytes(s, s, pngutil.resize_area(rgba, w, h, s, s))) for s in sizes]
header = struct.pack("<HHH", 0, 1, len(imgs))
offset = 6 + 16*len(imgs)
offset = 6 + 16 * len(imgs)
entries = b""
for s, png in imgs:
entries += struct.pack("<BBBBHHII", s if s<256 else 0, s if s<256 else 0, 0, 0, 1, 32, len(png), offset)
entries += struct.pack("<BBBBHHII", s if s < 256 else 0, s if s < 256 else 0, 0, 0, 1, 32, len(png), offset)
offset += len(png)
with open(dst, "wb") as f:
f.write(header + entries + b"".join(p for _, p in imgs))
Expand Down
Loading
Loading