PhilRobinluo/ai-coevolution-skills / skills/lls-image-renamer
lls-image-renamer
Verified批量规划可搜索、可追溯的图片文件名,在真正改名之前检查重名、越界和引用影响。 当用户要处理相关材料并需要可验证交付物时使用。
| File | Kind | Size |
|---|---|---|
| README.md | markdown | 1.8 KB |
| SKILL.md | skill md | 4.5 KB |
| references/rename-review.md | markdown | 358 B |
| scripts/plan_rename.pyexecutable | script | 2.7 KB |
| tests/test_plan_rename.py | script | 1.2 KB |
scripts/plan_rename.py
View on GitHub#!/usr/bin/env python3
"""生成可审阅的图片改名清单;显式 --apply 后才执行,且绝不覆盖现有文件。"""
from __future__ import annotations
import argparse,json,re
from pathlib import Path
def safe_name(text:str,max_len:int=40)->str:
name=re.sub(r'[^0-9A-Za-z\u4e00-\u9fff-]+','-',text.strip()).strip('-')
name=re.sub(r'-+','-',name)[:max_len].rstrip('-')
if not name: raise ValueError('描述无法生成有效文件名')
return name
def main()->int:
p=argparse.ArgumentParser(); p.add_argument('file',nargs='?'); p.add_argument('--description'); p.add_argument('--mapping',type=Path,help='JSON 列表:file, description'); p.add_argument('--root',type=Path,default=Path('.')); p.add_argument('--manifest',type=Path); p.add_argument('--apply',action='store_true'); a=p.parse_args()
if a.mapping:
raw=json.loads(a.mapping.read_text()); entries=raw
elif a.file and a.description: entries=[{'file':a.file,'description':a.description}]
else: p.error('使用 file + --description,或 --mapping')
root=a.root.resolve(); plan=[]; targets=set(); errors=[]
for item in entries:
src=(root/item['file']).resolve() if not Path(item['file']).is_absolute() else Path(item['file']).resolve()
try: src.relative_to(root)
except ValueError: errors.append({'file':str(src),'error':'文件不在 root 内'}); continue
if not src.is_file(): errors.append({'file':str(src),'error':'源文件不存在'}); continue
try: prefix=safe_name(item['description'])
except ValueError as e: errors.append({'file':str(src),'error':str(e)}); continue
dst=src.with_name(f'{prefix}__{src.name}')
if dst==src: errors.append({'file':str(src),'error':'目标与源相同'}); continue
if dst.exists() or str(dst) in targets: errors.append({'file':str(src),'error':f'目标冲突:{dst}'}); continue
targets.add(str(dst)); plan.append({'from':str(src),'to':str(dst),'description':item['description'],'status':'planned'})
result={'root':str(root),'dry_run':not a.apply,'count':len(plan),'errors':errors,'items':plan}
if errors: result['applied']=False
elif a.apply:
# 所有项目先完成冲突检查,再逐项 rename;Path.rename 在这里不覆盖已存在目标。
for item in plan:
Path(item['from']).rename(item['to']); item['status']='renamed'
result['applied']=True
if a.manifest: a.manifest.parent.mkdir(parents=True,exist_ok=True); a.manifest.write_text(json.dumps(result,ensure_ascii=False,indent=2)+'\n')
print(json.dumps(result,ensure_ascii=False,indent=2))
return 1 if errors else 0
if __name__=='__main__': raise SystemExit(main())
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack." | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |