脚本化图片 alt/title 补全工具。脚本负责提取和替换,模型只负责看图生成描述。支持 Markdown 和 HTML 图片,严格不改路径、不丢图。
Automates batch processing of images to generate semantic alt/title attributes for Markdown and HTML.
/plugin marketplace add z-soulx/ai-toolkit/plugin install notes-skills@ai-toolkitThis skill inherits all available tools. When active, it can use any tool Claude has access to.
CHANGELOG.mdSAFETY_REVIEW.mdSKILL_非脚本.mdscripts/01_extract_manifest.pyscripts/02_make_batch_prompts.pyscripts/03_apply_patch.py✅ 脚本化操作 - 查找和替换都由脚本完成,速度快 ✅ 模型只看图 - 模型只负责读取图片生成描述,不做文本操作 ✅ 批次处理 - 支持分批处理大量图片 ✅ 降级机制 - 图片读取失败时自动使用上下文推断 ✅ 完整账本 - 记录每张图片的变更详情 ✅ 预览模式 - 必须先预览再执行,保证数据安全 ✅ 自动备份 - 执行前自动创建带时间戳的备份文件
本 skill 采用 planning-with-files 的 3-file 模式:
| 文件 | 用途 | 更新时机 |
|---|---|---|
| task_plan.md | 跟踪 A-D 工作流阶段进度 | 每个阶段完成后 |
| notes.md | 记录批次处理发现(可选) | 处理批次时 |
| image_ledger.md | 最终交付物:图片变更账本 | 步骤 D 完成后 |
⚠️ 遵循 planning-with-files 原则
创建 task_plan.md:
# Task Plan: 图片 Alt/Title 补全
## Goal
为 [文档名] 的所有图片生成语义化的 alt/title
## Phases
- [ ] Phase A: 提取图片清单
- [ ] Phase B: 生成批次任务
- [ ] Phase C: 处理批次(看图生成描述)
- [ ] Phase D: 应用补丁并验证
## Status
**Currently in Phase A** - 准备提取图片清单
python scripts/01_extract_manifest.py --target_md <你的文档.md> --out_dir .
输出: manifest.json - 包含所有图片的位置、上下文信息
完成后: 更新 task_plan.md,标记 Phase A 完成
python scripts/02_make_batch_prompts.py --manifest manifest.json --out_dir batches --batch_size 8
输出: batches/batch_001.md, batch_002.md, ... - 每个批次的处理任务
完成后: 更新 task_plan.md,标记 Phase B 完成
打开 batches/batch_001.md,按照提示:
results/batch_001.results.jsonnotes.md结果格式示例:
{
"batch": 1,
"results": [
{
"index": 0,
"src": "images/architecture.png",
"new_alt": "系统架构图展示微服务间的调用关系",
"new_title": "系统架构图展示微服务间的调用关系",
"fallback": false,
"note": ""
},
{
"index": 1,
"src": "images/missing.png",
"new_alt": "Redis 缓存穿透解决方案流程图",
"new_title": "Redis 缓存穿透解决方案流程图",
"fallback": true,
"note": "图片无法打开,基于上下文推断"
}
]
}
重复处理所有批次,直到完成。
完成后: 更新 task_plan.md,标记 Phase C 完成
⚠️ 安全要求: 必须先预览,确认无误后再执行
python scripts/03_apply_patch.py \
--target_md <你的文档.md> \
--manifest manifest.json \
--results_dir results \
--out_md patched.md \
--out_ledger image_ledger.md \
--update_policy smart \
--title_policy same_as_alt \
--max_len_alt 40 \
--max_len_title 40 \
--dry-run
预览输出:
检查要点:
完成后: 在 task_plan.md 中记录预览结果
⚠️ 仅在预览确认无误后执行
python scripts/03_apply_patch.py \
--target_md <你的文档.md> \
--manifest manifest.json \
--results_dir results \
--out_md patched.md \
--out_ledger image_ledger.md \
--update_policy smart \
--title_policy same_as_alt \
--max_len_alt 40 \
--max_len_title 40
输出:
patched.md - 更新后的文档image_ledger.md - 完整的变更账本(最终交付物)完成后: 更新 task_plan.md,标记 Phase D 完成
# 1. 检查账本文件
cat image_ledger.md
# 2. 对比原文件和新文件
diff <你的文档.md> patched.md
# 3. 确认无误后替换原文件
cp patched.md <你的文档.md>
always - 总是更新 alt/titlesmart - 智能更新(如果原有内容不像文件名则保留)empty_only - 仅更新空的 alt/titlesame_as_alt - title 与 alt 相同(推荐)keep - 保持原 title 不变update - 独立更新 titletable - 表格汇总格式(默认,推荐)
detailed - 详细逐条格式
--no-backup - 不创建备份文件(完全信任流程)--auto-cleanup-backup - 执行成功后自动删除备份文件(推荐)
.codex/skills/image-alt-title-filler/
├── SKILL.md # 本文件
├── scripts/
│ ├── 01_extract_manifest.py # 提取图片清单
│ ├── 02_make_batch_prompts.py # 生成批次任务
│ └── 03_apply_patch.py # 应用补丁
├── SAFETY_REVIEW.md # 安全审查报告
└── CHANGELOG.md # 版本更新记录
working_directory/
├── task_plan.md # 任务计划(遵循 planning-with-files)
├── notes.md # 批次处理笔记(可选)
├── manifest.json # 提取的图片元数据
├── batches/ # 批次任务
│ ├── batch_001.md
│ └── batch_002.md
├── results/ # AI 生成的描述
│ ├── batch_001.results.json
│ └── batch_002.results.json
├── patched.md # 更新后的文档
└── image_ledger.md # 最终交付物:变更账本
# 0. 创建任务计划
cat > task_plan.md <<'EOF'
# Task Plan: 图片 Alt/Title 补全
## Goal
为 node/中间件/redis/redis实战.md 的所有图片生成语义化的 alt/title
## Phases
- [ ] Phase A: 提取图片清单
- [ ] Phase B: 生成批次任务
- [ ] Phase C: 处理批次
- [ ] Phase D: 应用补丁并验证
## Status
**Currently in Phase A**
EOF
# A. 提取图片
python scripts/01_extract_manifest.py --target_md "node/中间件/redis/redis实战.md" --out_dir .
# 更新 task_plan.md: 标记 Phase A 完成
# B. 生成批次(每批 8 张图)
python scripts/02_make_batch_prompts.py --manifest manifest.json --out_dir batches --batch_size 8
# 更新 task_plan.md: 标记 Phase B 完成
# C. 在 IDE 中打开 batches/batch_001.md,按提示处理
# 更新 task_plan.md: 标记 Phase C 完成
# D1. 预览变更(必须!)
python scripts/03_apply_patch.py \
--target_md "node/中间件/redis/redis实战.md" \
--manifest manifest.json \
--results_dir results \
--out_md patched.md \
--out_ledger image_ledger.md \
--dry-run
# D2. 确认预览无误后,正式执行(使用表格格式 + 自动清理备份)
python scripts/03_apply_patch.py \
--target_md "node/中间件/redis/redis实战.md" \
--manifest manifest.json \
--results_dir results \
--out_md patched.md \
--out_ledger image_ledger.md \
--ledger_format table \
--auto-cleanup-backup
# 更新 task_plan.md: 标记 Phase D 完成
# E. 检查账本并替换原文件
cat image_ledger.md
cp patched.md "node/中间件/redis/redis实战.md"
--dry-run 预览,确认无误后再正式执行原文件名.backup_时间戳.md)fallback: trueimage_ledger.md 确认所有图片都已处理Q: 为什么要分批处理? A: 避免单次处理过多图片导致超时或内存问题,分批处理更稳定。
Q: 图片打不开怎么办?
A: 设置 fallback: true,基于上下文推断生成描述,脚本会自动标记。
Q: 如何只更新空的 alt/title?
A: 使用 --update_policy empty_only 参数。
Q: 可以自定义 alt 和 title 的长度吗?
A: 可以,使用 --max_len_alt 和 --max_len_title 参数。
You MUST use this before any creative work - creating features, building components, adding functionality, or modifying behavior. Explores user intent, requirements and design before implementation.