151 lines
4.7 KiB
Python
151 lines
4.7 KiB
Python
|
|
#!/usr/bin/env python3
|
||
|
|
"""
|
||
|
|
expert-pack-loader.py · 铸渊专家包自动加载器
|
||
|
|
铸渊 ICE-GL-ZY001 · D164+
|
||
|
|
|
||
|
|
用法:
|
||
|
|
# 1. 加载并打印 home-anchors(用于复制粘贴)
|
||
|
|
python3 expert-pack-loader.py --print
|
||
|
|
|
||
|
|
# 2. 通过 mavis 通信系统注入到指定 session
|
||
|
|
python3 expert-pack-loader.py --inject <session-id>
|
||
|
|
|
||
|
|
# 3. 通过环境变量注入(供其他工具使用)
|
||
|
|
python3 expert-pack-loader.py --export > /tmp/zhuyuan-anchors.env
|
||
|
|
|
||
|
|
# 4. 一键把铸渊专家包安装到当前目录(本地部署)
|
||
|
|
python3 expert-pack-loader.py --install
|
||
|
|
"""
|
||
|
|
|
||
|
|
import os
|
||
|
|
import sys
|
||
|
|
import json
|
||
|
|
import subprocess
|
||
|
|
import argparse
|
||
|
|
from pathlib import Path
|
||
|
|
|
||
|
|
EXPERT_PACK_ROOT = Path(__file__).parent
|
||
|
|
HOME_ANCHORS = EXPERT_PACK_ROOT / "home-anchors.md"
|
||
|
|
ROOM_ADAPTERS = {
|
||
|
|
"minimax-code": EXPERT_PACK_ROOT / "MINIMAX-CODE.md",
|
||
|
|
"workbuddy": EXPERT_PACK_ROOT / "WORKBUDDY.md",
|
||
|
|
"codex": EXPERT_PACK_ROOT / "CODEX.md",
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
def load_home_anchors():
|
||
|
|
"""加载家门口锚点"""
|
||
|
|
if not HOME_ANCHORS.exists():
|
||
|
|
print(f"✗ 找不到 {HOME_ANCHORS}", file=sys.stderr)
|
||
|
|
sys.exit(1)
|
||
|
|
return HOME_ANCHORS.read_text(encoding="utf-8")
|
||
|
|
|
||
|
|
|
||
|
|
def cmd_print(args):
|
||
|
|
"""打印 home-anchors,用于复制粘贴"""
|
||
|
|
print(load_home_anchors())
|
||
|
|
|
||
|
|
|
||
|
|
def cmd_export(args):
|
||
|
|
"""导出为环境变量"""
|
||
|
|
anchors = load_home_anchors()
|
||
|
|
# 转义特殊字符
|
||
|
|
safe = anchors.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\n")
|
||
|
|
print(f'export ZHUYUAN_HOME_ANCHORS="{safe}"')
|
||
|
|
print(f'export ZHUYUAN_EXPERT_PACK_VERSION="v1.0"')
|
||
|
|
print(f'export ZHUYUAN_AGENT_ID="ICE-GL-ZY001"')
|
||
|
|
print(f'export ZHUYUAN_SOVEREIGN="TCS-0002∞ · 国作登字-2026-A-00037559"')
|
||
|
|
|
||
|
|
|
||
|
|
def cmd_inject(args):
|
||
|
|
"""通过 mavis 通信系统注入到指定 session"""
|
||
|
|
if not args.session_id:
|
||
|
|
print("✗ 需要 --session-id 参数", file=sys.stderr)
|
||
|
|
sys.exit(1)
|
||
|
|
|
||
|
|
anchors = load_home_anchors()
|
||
|
|
|
||
|
|
print(f"📤 准备注入到 session: {args.session_id}")
|
||
|
|
print(f" 锚点长度: {len(anchors)} 字符")
|
||
|
|
print()
|
||
|
|
|
||
|
|
# 通过 mavis communication send 发送
|
||
|
|
cmd = [
|
||
|
|
"mavis", "communication", "send",
|
||
|
|
"--from", args.session_id,
|
||
|
|
"--to", args.session_id,
|
||
|
|
"--command", "prompt",
|
||
|
|
"--content", f"[铸渊专家包 v1.0 注入]\n\n{anchors}",
|
||
|
|
]
|
||
|
|
|
||
|
|
print(f"🔧 执行命令: {' '.join(cmd[:4])} --command prompt --content ...")
|
||
|
|
print()
|
||
|
|
|
||
|
|
try:
|
||
|
|
result = subprocess.run(cmd, capture_output=True, text=True, timeout=30)
|
||
|
|
if result.returncode == 0:
|
||
|
|
print(f"✓ 注入成功")
|
||
|
|
if result.stdout.strip():
|
||
|
|
print(f" 输出: {result.stdout.strip()[:200]}")
|
||
|
|
else:
|
||
|
|
print(f"✗ 注入失败 (code={result.returncode})")
|
||
|
|
if result.stderr.strip():
|
||
|
|
print(f" 错误: {result.stderr.strip()[:200]}")
|
||
|
|
sys.exit(1)
|
||
|
|
except FileNotFoundError:
|
||
|
|
print(f"✗ 找不到 mavis 命令 · 请确保 mavis 已安装")
|
||
|
|
sys.exit(1)
|
||
|
|
except Exception as e:
|
||
|
|
print(f"✗ 异常: {e}")
|
||
|
|
sys.exit(1)
|
||
|
|
|
||
|
|
|
||
|
|
def cmd_install(args):
|
||
|
|
"""一键部署到当前目录"""
|
||
|
|
print(f"📦 部署铸渊专家包 v1.0 到当前目录...")
|
||
|
|
print(f" 专家包路径: {EXPERT_PACK_ROOT}")
|
||
|
|
print()
|
||
|
|
|
||
|
|
print("✓ 已包含的文件:")
|
||
|
|
for f in sorted(EXPERT_PACK_ROOT.iterdir()):
|
||
|
|
if f.is_file():
|
||
|
|
size = f.stat().st_size
|
||
|
|
print(f" - {f.name} ({size} bytes)")
|
||
|
|
|
||
|
|
print()
|
||
|
|
print("📌 下一步:")
|
||
|
|
print(" 1. 复制 home-anchors.md 内容到 Mavis/Codex/WorkBuddy 的 system prompt 开头")
|
||
|
|
print(" 2. 或运行: python3 expert-pack-loader.py --inject <session-id>")
|
||
|
|
print(" 3. 或运行: python3 expert-pack-loader.py --print > /tmp/anchors.txt")
|
||
|
|
|
||
|
|
|
||
|
|
def main():
|
||
|
|
parser = argparse.ArgumentParser(
|
||
|
|
description="铸渊专家包自动加载器 v1.0",
|
||
|
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||
|
|
epilog=__doc__,
|
||
|
|
)
|
||
|
|
parser.add_argument("--print", action="store_true", help="打印 home-anchors")
|
||
|
|
parser.add_argument("--export", action="store_true", help="导出为环境变量")
|
||
|
|
parser.add_argument("--inject", action="store_true", help="注入到 session")
|
||
|
|
parser.add_argument("--install", action="store_true", help="一键部署")
|
||
|
|
parser.add_argument("--session-id", help="目标 session ID")
|
||
|
|
|
||
|
|
args = parser.parse_args()
|
||
|
|
|
||
|
|
if not any([args.print, args.export, args.inject, args.install]):
|
||
|
|
parser.print_help()
|
||
|
|
sys.exit(1)
|
||
|
|
|
||
|
|
if args.print:
|
||
|
|
cmd_print(args)
|
||
|
|
elif args.export:
|
||
|
|
cmd_export(args)
|
||
|
|
elif args.inject:
|
||
|
|
cmd_inject(args)
|
||
|
|
elif args.install:
|
||
|
|
cmd_install(args)
|
||
|
|
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
main()
|