首页 / 全部技能 / 基础工具与工作流 / codex-image-gallery
基础工具与工作流 · daymade/claude-code-skills

codex-image-gallery

Start or reuse a self-contained local web gallery for browsing Codex-generated images. Use when the user asks to browse Codex generated images, open a local image gallery, inspect ~/.codex/generated_images, view a Codex image output folder, or browse image files produced by Codex.

L4 高权限 · 分级授权与审计V1 已固定执行命令联网读写文件Dual-pass Audit
Author daymadeGitHub daymade/claude-code-skills ↗Stars 1385License MIT(仓库根 LICENSE;GitHub API spdx MIT)Commit d5c4678cb5
管控等级描述 skill 的能力与建议配套的管控措施,不代表质量或安全认证,也不表示可用或不可用。是否使用由用户和管理者决定。不同 agent 宿主对权限的约束各不相同,请勿假定宿主一定会提供安全兜底。第三方 skill 版权归原作者,使用风险由使用者自行承担。

1实现原理 · 为什么它能做到

自包含本地服务:scripts/server.mjs 是纯 Node stdlib HTTP 服务器(无第三方包),绑定 127.0.0.1,默认端口 8765,被占则自动 +1 递增(上限 +20);UI 模板 assets/index.html 由同一目录提供。

daymade-codex/codex-image-gallery/SKILL.md
The server prints the actual URL. It starts at `http://127.0.0.1:8765/` and tries later ports if the default is occupied.
server.mjs:'const HOST = process.env.HOST || "127.0.0.1"';listen() 内 'if (error.code === "EADDRINUSE" && port < DEFAULT_PORT + 20) { listen(port + 1); }'。

API 面就两个:GET /api/images 递归 walk 图片根目录返回 {rootPath, items[](path/mtime/size)}(按 mtime 降序);GET /images/<rel> 流式返回图片文件——两者都做路径穿越防护(safePath 校验解析后路径必须留在根内)。

daymade-codex/codex-image-gallery/scripts/server.mjs
if (fullPath !== root && !fullPath.startsWith(`${root}${path.sep}`)) { return null; }
/api/images 带 'cache-control: no-store';/images/ 的 rel 经 decodeURIComponent 后再 safePath,越界回 403。默认根 ~/.codex/generated_images,可用 GALLERY_ROOT env 覆盖。

『复用优先』协议:先 fetch /api/images 探测默认 URL(成功即复用已在跑的 server),失败再 pgrep 找进程并试后续端口,最后才新起 server——避免每请求叠一个实例。

daymade-codex/codex-image-gallery/SKILL.md
If this succeeds, reuse the running server at `http://127.0.0.1:8765/`.
SKILL workflow 1-4 步:探测→pgrep→按端口验证复用→起服务;'Keep the process running for the user and read stdout for the URL.'

前端 index.html 是同源 fetch('/api/images') 渲染网格/灯箱/批量标签,纯本地数据无第三方 CDN/字体/脚本依赖。

daymade-codex/codex-image-gallery/assets/index.html
const response = await fetch("/api/images", { cache: "no-store" });
页面另有 'Open another folder'(浏览器内选目录)+ 复制路径等本地功能;渲染逃逸用 escapeHtml。

验收路径可自动验证:node --check 语法 + 起服后核对 /api/images 有 items、/images/<rel> 能出图、首页来自 bundled index.html——SKILL 明示改完代码后要跑这三条再宣称 healthy。

daymade-codex/codex-image-gallery/SKILL.md
Before declaring the skill healthy after edits, run: `node --check scripts/server.mjs`
这是作者自带的『改完必须验证』纪律,与 statusline-generator 的 health check 同思路。

2核心能力

01浏览 Codex 生成图片(默认 ~/.codex/generated_images,GALLERY_ROOT 可换目录)
02递归列目录 + 按 mtime 排序 + 逐图服务(png/jpg/webp/gif)
03运行中 server 的探测复用(API check → pgrep → 端口递增定位)
04浏览器内批量浏览/筛选/灯箱/路径复制(bundled 单文件 UI)
05路径穿越防护的静态文件服务

3外部依赖

KindDependency / Endpoint
clinode(运行 server.mjs;SKILL 亦用 node -e fetch 做探测)
clipgrep(探测已有 server 进程)
cliopen(可选,打开浏览器到本地 URL)

4管控建议与判定依据

建议配套管控措施
面向 Agent
分级或逐次授权,建议在沙箱运行
面向管理者
审批流程、可回滚、全程审计
判定依据(文件路径与关键语句摘要)
  • scripts/: 执行本地脚本或命令: node scripts/server.mjs(本地 HTTP 服务,纯 stdlib)
  • 环境变量 / API Key: 读取厂商服务密钥: 无
  • 本地工作目录: 文件读写与工件输出: 无(服务器只读图片目录与 assets;不写任何文件)
审计说明: 。自带 Node stdlib 本地脚本、仅回环监听、无外发、无凭证、无写盘;按准则『运行自带本地脚本、仅本地读写』落 blue。注意点:无鉴权回环 HTTP 暴露 ~/.codex/generated_images 内容,本机其他用户/进程可读;现代浏览器 PNA 缓解公网页直连,但本地进程不受限——共享机器上使用需自行评估。

5第二遍独立确认

  • [ok] 绑定地址与端口递增 — server.mjs 'HOST = process.env.HOST || "127.0.0.1"' + 'error.code === "EADDRINUSE" && port < DEFAULT_PORT + 20'。
  • [ok] 路径穿越防护 — safePath resolve 后 prefix 校验,越界 403;decodeURIComponent 包 try/catch。
  • [ok] 无外发网络/第三方依赖 — server imports 仅 node:http/fs/os/path/url;index.html 外链扫描仅同源。
  • [ok] SKILL 探测复用协议可实现性 — fetch('/api/images')、pgrep pattern 'node .*server\.mjs' 与 server 实际进程命令行一致(node scripts/server.mjs)。
  • [ok] 鉴权缺失的暴露半径 — 代码无任何鉴权/CORS 头;暴露限于回环(本机)——已在 risk 记录;浏览器 PNA 缓解无法在源码验证,标注为宿主/浏览器行为。
  • [unlocatable] 真实浏览器端渲染验证 — index.html 视觉行为未在浏览器实测(本环境无 Codex 图片目录/浏览器),验证止于静态代码与 SKILL 自述。

6结论

  • 零依赖自包含(Node stdlib + 单 HTML),clone 即用
  • 复用优先协议省资源,防多实例叠端口
  • 路径穿越在实现层防护,不是靠文档承诺
  • 改码三连验证内建,宣称 healthy 有依据
  • 适合: 适合 Codex 生成图片的本地浏览/挑选:agent 在会话里快速起一个图库让用户翻看输出、对比 batch、找图;适合要零第三方依赖、纯本地、可随时 kill 的轻量场景。
    不适合: 不适合多用户共享机器(无鉴权暴露不可接受)或需要远程访问的图库(只绑回环);不适合浏览非图片资产/需要缩略图管线/大目录分页的高级需求(walkImages 全量递归,无分页);已有常驻图库服务的用户可直接复用 URL 而不必起本 skill。
    Install Agent-Ready
    ① Verified Mirror 2026-09-09
    Option A · Direct DownloadDownload codex-image-gallery.tar.gz
    sha256: b2b0045b3baaf9a9…
    Option B · Copy Guide for Agent
    install.json
    agent 读 JSON 指南后会自动从本站下载安装,无需更多说明。
    ② Upstream GitHub
    GitHub Repo ↗
    Pinned to commit d5c4678cb5.