SuperAPI AI 工具集

git-profile

编程与开发

查看项目

更新于 10-16 04:07

技能介绍

用途

Git Profile 是一个 Git 身份与 GPG 签名配置管理器,用于按仓库(per-repository)管理 git 身份和 GPG 签名配置。它可以从 GPG 与 git config 中发现配置档案,切换当前仓库的本地身份,并检查签名健康状态。

主要能力

工具通过子命令提供以下能力:

  • doctor(默认):对当前仓库的 git 身份与 GPG 签名配置运行诊断,输出健康报告表格,包含 Name、Email、Signing、GPG Key、Env Override、Worktree、Profile Match 等条目及来源与状态。若状态为 halt 则显示问题并停止;若为 warn 则显示警告并继续;若注册表缺失且为首次运行,则触发自动发现。
  • list:列出所有已注册档案,并标记当前匹配的档案。
  • use <profile>:将当前仓库切换到指定档案。执行前会解析出计划(包含档案数据、计划执行的命令和 plan-hash),展示将要写入的配置键(user.name、user.email、user.signingkey、commit.gpgsign)的当前值与新值,经用户确认后应用。无密钥档案会取消设置签名相关键,而非设置它们。
  • remove <profile>:从注册表移除档案。若档案仍在某些仓库中处于活动状态,会提示确认是否使用 --force 移除。
  • verify:对当前身份设置进行深度校验,检查项包括密钥有效期(90 天警告阈值)、git config 与 GPG 密钥 UID 之间的邮箱匹配、注册表一致性。

使用方式

各子命令通过脚本调用,例如:

  • bash scripts/run-skill.sh git-profile git-profile.sh doctor
  • bash scripts/run-skill.sh git-profile git-profile.sh list
  • bash scripts/run-skill.sh git-profile git-profile.sh resolve <profile>
  • bash scripts/run-skill.sh git-profile git-profile.sh apply --plan-hash <hash>
  • bash scripts/run-skill.sh git-profile git-profile.sh remove-check <profile>
  • bash scripts/run-skill.sh git-profile git-profile.sh remove-exec <profile> [--force]
  • bash scripts/run-skill.sh git-profile git-profile.sh verify
  • bash scripts/run-skill.sh git-profile git-profile.sh discover

命令输出为 JSON,由技能解析后渲染为表格或报告。所有写入操作均通过 AskUserQuestion 进行确认。

自动发现

当首次运行 doctor 且注册表文件缺失时触发。运行 discover 命令解析候选档案,通过 AskUserQuestion 询问用户是否将发现的档案保存到注册表;若跳过,则创建空注册表以避免重复提示。

适用场景

适用于需要在不同仓库间使用不同 Git 身份或 GPG 签名配置的用户,例如同时参与多个项目、需要区分工作与个人提交身份、或需要校验签名配置健康度的场景。

限制与安全规则

  • v1 从不写入 ~/.gitconfig,仅进行 --local 作用域写入。
  • v1 从不启用 extensions.worktreeConfig;对于链接工作树仅检测并警告。
  • 未经确认绝不自动修复,所有写入均由 AskUserQuestion 把关。
  • 绝不存储密钥材料,注册表仅存储指纹。
  • 应用前重新计算 plan-hash 进行校验,若已过期则拒绝。
  • 注册表采用原子写入:临时文件 + chmod 0600 + mv。

诊断集成

doctor --json 输出遵循共享诊断契约。其他技能(如 /smart-commit 第 1c 步)可调用:

bash scripts/run-skill.sh git-profile git-profile.sh doctor --json

降级策略:若脚本未找到或执行失败,调用方技能回退到自身的内联诊断。基础设施故障仅警告;身份/签名缺失则停止(保持不变)。