Skip to content

zjs105910/workbuddy-market / bundled/github-project-manager/skills/github-project-manager

github-project-manager

Verified

管理从 GitHub 下载到本机的开源项目与技能包:列出、扫描发现、安装前预检、检查更新、一键更新、移除、回滚、数据完整性校验与环境诊断。带 O_EXCL 原子锁 + 心跳租约、事务级失败回滚、InstallPlan 状态收敛、单次遍历的磁盘预检、批量更新复用远程信息(消灭 N+1 请求)、ZIP 预扫描与压缩炸弹/设备名双重防护、skill 冲突阻断、内容指纹校验、硬链接与 rename 两种备份介质。触发方式:/ghpm、『GitHub 项目管理』『检查插件更新』『更新开源项目』『我装了哪些 GitHub 项目』『这个插件有新版吗』『卸载插件』『这个仓库能装吗』『ghpm doctor』『ghpm verify』『文件丢了/装坏了』。

scripts/ghpm/commands/remove.py

View on GitHub
# -*- coding: utf-8 -*-
"""remove:移除项目(备份后删除,可回滚)。"""
from __future__ import annotations

import sys
from pathlib import Path

from .. import config
from ..errors import E_LOCKED, E_NOT_FOUND, E_UNSAFE_PATH, E_WRITE, UnsafePathError
from ..lock import LockSession
from ..pathguard import remove_managed_path, validate_managed_path, validate_skill_name
from ..registry import drop_project, find_project, load, save, skill_owner_map
from ..transaction import Transaction, report_rollback
from ..util import classify_write_error, emit


def cmd_remove(args):
    data = load()
    hit = find_project(data, args.name)
    if not hit:
        emit("failed", "未找到项目", percent=100, code=E_NOT_FOUND, detail=args.name)
        print("未找到项目:%s" % args.name)
        return
    ident = hit.get("repo") or hit["name"]

    def on_busy(holder):
        emit("failed", "有另一个任务正在修改,请稍后再试", percent=100, code=E_LOCKED,
             detail="占用者:%s" % holder.get("op", "?"))

    with LockSession("remove %s" % ident, on_busy=on_busy):
        # 路径全部先过 containment:清单里的 source_dir / skill_names 未必可信
        # (手工编辑、旧版本写坏、别的程序污染)。越界就整条拒绝,
        # 不能「跳过不认识的路径然后把剩下的删了」—— 那是半吊子安全。
        try:
            paths = []
            for n in hit.get("skill_names", []):
                paths.append(config.SKILLS / validate_skill_name(n))
            if hit.get("source_dir"):
                paths.append(validate_managed_path(hit["source_dir"], config.WB, "source_dir"))
            for p in paths:
                validate_managed_path(p, config.WB, "待删除路径")
        except UnsafePathError as e:
            emit("failed", "清单里的路径不合法,已拒绝删除", percent=100,
                 code=E_UNSAFE_PATH, detail=str(e),
                 hint="这通常意味着 %s 被手工改坏了。先把它改回 %s 之内的路径,"
                      "或直接手动删除。" % (config.REGISTRY, config.WB),
                 data={"repo": ident})
            raise
        paths = [Path(p) for p in paths]
        owners = skill_owner_map(data)
        for n in hit.get("skill_names", []):
            other = owners.get(n)
            if other and other.lower() != str(ident).lower():
                print("  [警告] skill %s 同时被登记在 %s 名下,本次只按本项目的记录删除。"
                      % (n, other), file=sys.stderr)

        tx = Transaction(ident, hit.get("name", ident), "remove")
        tx.track(paths)
        try:
            bd = tx.begin()
        except Exception as e:
            emit("failed", "备份失败,未删除任何文件", percent=100, code=E_WRITE,
                 detail=str(e)[:160], hint=classify_write_error(e))
            raise
        emit("backing-up", "备份待删除内容", percent=30)
        emit("applying", "删除文件", percent=60, backup=str(bd))
        try:
            for d in paths:
                remove_managed_path(d, "待删除路径")
            drop_project(data, ident)
            save(data)      # 原子提交;失败则连同删除的文件一起回滚
        except Exception as e:
            emit("rollback", "移除失败,正在回滚…", percent=90, backup=str(bd))
            restored = tx.rollback()
            report_rollback(bd, restored, e)
            raise
        # 移除成功后**保留**备份:这是唯一的撤销手段
        # (rename 模式下备份目录本身就是被删掉的那份内容,回滚是 O(1) rename)
        tx.commit(purge=False)
        print("已移除 %s,备份保留在 %s" % (hit.get("name", ident), bd))
        print("要撤销:`ghpm rollback %s`" % bd)
        emit("done", "已移除 · %s" % hit.get("name", ident), percent=100, backup=str(bd),
             data={"removed": [str(p) for p in paths], "backup": str(bd)})
reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis.Stars: 470kUpdated Claude CodeCodexVerifiedInstall
diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.Stars: 322kUpdated Claude CodeCodexVerifiedInstall
dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependenciesStars: 322kUpdated Claude CodeCodexVerifiedInstall
executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is availableStars: 322kUpdated Claude CodeCodexVerifiedInstall