🔄 卡若AI 同步 2026-02-22 10:57 | 更新:卡土、总索引与入口、运营中枢工作台 | 排除 >20MB: 8 个
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
name: 基因胶囊
|
||||
description: 将验证过的 Skill 打包为可遗传的能力单元(基因胶囊),支持 pack/unpack/list。触发词:基因胶囊、打包技能、解包胶囊、继承能力。
|
||||
group: 土
|
||||
triggers: 基因胶囊、打包技能、解包胶囊、继承能力、胶囊列表
|
||||
triggers: 基因胶囊、打包技能、解包胶囊、继承能力、胶囊列表、查胶囊、pack-all、全量导出
|
||||
owner: 土砖
|
||||
version: "1.0"
|
||||
updated: "2026-02-22"
|
||||
@@ -49,7 +49,16 @@ python3 .../gene_capsule.py unpack 技能工厂_abc12345.json -o 02_卡人(水
|
||||
- 默认按胶囊内 `manifest.skill_path` 写回
|
||||
- 可选 `-o` 指定目录,则写入该目录下的 `SKILL.md`
|
||||
|
||||
### 2.3 列表
|
||||
### 2.3 全量导出(所有 Skill → 基因胶囊)
|
||||
|
||||
```bash
|
||||
cd /Users/karuo/Documents/个人/卡若AI
|
||||
python3 "05_卡土(土)/土砖_技能复制/基因胶囊/脚本/gene_capsule.py" pack-all
|
||||
```
|
||||
|
||||
将 SKILL_REGISTRY 中**所有技能**批量打包为基因胶囊,并更新导出说明文档。
|
||||
|
||||
### 2.4 列表
|
||||
|
||||
```bash
|
||||
python3 .../gene_capsule.py list
|
||||
|
||||
@@ -230,8 +230,8 @@ def _write_export_readme() -> str:
|
||||
return str(readme_path)
|
||||
|
||||
|
||||
def pack(skill_ref: str, include_audit: bool = True) -> str:
|
||||
"""打包:将 SKILL 转为基因胶囊 JSON,并生成导出说明文档(含流程图)"""
|
||||
def pack(skill_ref: str, include_audit: bool = True, write_readme: bool = True) -> str:
|
||||
"""打包:将 SKILL 转为基因胶囊 JSON,并生成导出说明文档(含流程图)。pack_all 时 write_readme=False。"""
|
||||
skill_path = _find_skill_path(skill_ref)
|
||||
content = skill_path.read_text(encoding="utf-8")
|
||||
rel_path = str(skill_path.relative_to(KARUO_AI_ROOT))
|
||||
@@ -270,9 +270,11 @@ def pack(skill_ref: str, include_audit: bool = True) -> str:
|
||||
out_file = EXPORT_DIR / f"{safe_name}_{capsule_id[7:15]}.json"
|
||||
out_file.write_text(json.dumps(capsule, ensure_ascii=False, indent=2), encoding="utf-8")
|
||||
|
||||
# 生成导出说明文档(含完整流程图)
|
||||
readme_path = _write_export_readme()
|
||||
return str(out_file) + "\n📄 说明文档: " + readme_path
|
||||
# 生成导出说明文档(含完整流程图);pack_all 时由调用方统一写入
|
||||
if write_readme:
|
||||
readme_path = _write_export_readme()
|
||||
return str(out_file) + "\n📄 说明文档: " + readme_path
|
||||
return str(out_file)
|
||||
|
||||
|
||||
def unpack(capsule_path: str, target_dir: str | None = None) -> str:
|
||||
@@ -331,6 +333,45 @@ def list_capsules() -> list[dict]:
|
||||
return result
|
||||
|
||||
|
||||
def _extract_skill_paths_from_registry() -> list[str]:
|
||||
"""从 SKILL_REGISTRY.md 提取所有 SKILL 路径"""
|
||||
import re
|
||||
registry = KARUO_AI_ROOT / "SKILL_REGISTRY.md"
|
||||
if not registry.exists():
|
||||
return []
|
||||
text = registry.read_text(encoding="utf-8")
|
||||
# 匹配 `01_xxx/xxx/SKILL.md` 格式
|
||||
pattern = r"`([^`]+SKILL\.md)`"
|
||||
matches = re.findall(pattern, text)
|
||||
seen = set()
|
||||
out = []
|
||||
for m in matches:
|
||||
m = m.strip()
|
||||
if m and m not in seen and (KARUO_AI_ROOT / m).exists():
|
||||
seen.add(m)
|
||||
out.append(m)
|
||||
return out
|
||||
|
||||
|
||||
def pack_all(include_audit: bool = True) -> tuple[int, int, list[str]]:
|
||||
"""全量打包:将 SKILL_REGISTRY 中所有技能导出为基因胶囊。返回 (成功数, 失败数, 失败列表)"""
|
||||
paths = _extract_skill_paths_from_registry()
|
||||
ok, fail = 0, 0
|
||||
failed = []
|
||||
for i, rel_path in enumerate(paths, 1):
|
||||
try:
|
||||
pack(rel_path, include_audit=include_audit, write_readme=False)
|
||||
ok += 1
|
||||
print(f" [{i}/{len(paths)}] ✅ {Path(rel_path).parent.name}")
|
||||
except Exception as e:
|
||||
fail += 1
|
||||
failed.append(f"{rel_path}: {e}")
|
||||
print(f" [{i}/{len(paths)}] ❌ {Path(rel_path).parent.name}: {e}")
|
||||
# 最后统一更新说明文档(避免每次 pack 都覆盖,这里只调用一次)
|
||||
_write_export_readme()
|
||||
return ok, fail, failed
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description="基因胶囊 · pack/unpack/list")
|
||||
sub = parser.add_subparsers(dest="cmd", required=True)
|
||||
@@ -344,9 +385,24 @@ def main():
|
||||
p_unpack.add_argument("-o", "--output", help="输出目录,默认按 manifest.skill_path")
|
||||
# list
|
||||
p_list = sub.add_parser("list", help="列出本地胶囊")
|
||||
# pack-all
|
||||
p_pack_all = sub.add_parser("pack-all", help="全量导出:将 SKILL_REGISTRY 中所有技能打包为基因胶囊")
|
||||
p_pack_all.add_argument("--no-audit", action="store_true", help="不包含审计信息")
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.cmd == "pack":
|
||||
if args.cmd == "pack-all":
|
||||
paths = _extract_skill_paths_from_registry()
|
||||
print(f"📦 全量导出 {len(paths)} 个技能...")
|
||||
ok, fail, failed = pack_all(include_audit=not getattr(args, "no_audit", False))
|
||||
print(f"\n✅ 成功: {ok} | ❌ 失败: {fail}")
|
||||
print(f"📄 说明文档: {EXPORT_DIR / EXPORT_README}")
|
||||
if failed:
|
||||
print("\n失败项:")
|
||||
for f in failed[:10]:
|
||||
print(f" - {f}")
|
||||
if len(failed) > 10:
|
||||
print(f" ... 等 {len(failed)} 项")
|
||||
elif args.cmd == "pack":
|
||||
out = pack(args.skill, include_audit=not args.no_audit)
|
||||
parts = out.split("\n")
|
||||
print(f"✅ 已打包: {parts[0]}")
|
||||
|
||||
Reference in New Issue
Block a user