详情

首页手游攻略 githits-cli:实践指南

githits-cli:实践指南

佚名 2026-09-30 12:10:01

实际评估githits-cli时,我先确认它解决的具体问题:CLI 和 MCP for GitHits - AI 编码代理的代码上下文层。对软件开发任务来说,依赖、接口和异常处理往往比主路径更影响采用往往决定它能否落地,不能只用安装成功来判断。短测时我会在隔离分支完成一个可回滚的小任务,并保留安装步骤、接口契约、测试结果和错误信息的结果,方便团队复盘。如果团队属于需要可检查开发流程而非单次演示的工程师,它有继续测试的理由;否则先看替代方案会更省时间。

GitHits CLI

AI 编码代理的代码上下文层。

Website · Documentation · Issues

GitHits 将 AI 编码代理连接到整个世界的公共开源证据 完整的软件开发生命周期:发现、规划、研究、 实施、调试和维护。

CLI 运行本地 MCP 服务器 编码工具按需启动。然后,代理可以搜索索引包并 存储库源,读取确切的文件和文档页面,检查包 健康状况,比较依赖项升级,并从真实情况中查找来源引用的示例 当模型知识和本地存储库上下文不存在时的开源项目 够了。

想要使用 GitHits 作为您的代理工具或软件工厂的一部分吗?退房 我们的 公共 API 文档。

快速入门

npx githits@latest init

init 让您登录,检测支持的编码工具,并配置 GitHits 您选择的工具。它使用本地 stdio MCP,但 Cursor 除外,其 直接设置使用托管远程 MCP。

自动设置目前支持 Claude Code、Cursor、Windsurf、 VS 代码 / Copilot、Cline、Claude Desktop、Codex CLI、Pi、Gemini CLI、 谷歌反重力、OpenCode、爱马仕特工、Zed、Junie、Qwen 代码、 Kiro、Kilo Code、Factory Droid 和 Amazon Q CLI。

设置完成后,打开您的编码代理并正常工作。多家代理商致电GitHits 当他们需要源支持的上下文时。如果您的代理开始猜测,请提示它 直接:

Use GitHits Code Navigation to inspect npm:express. Find how middleware
errors are handled, read the relevant source, and explain the fix before
editing code.

GitHits 添加了什么

GitHits 专为代理需要来自 更广泛的开源生态系统,而不仅仅是模型内存或本地存储库上下文:

能力 MCP工具 CLI 命令
工具方向 quick_start —
代码示例 get_example githits example
代码导航 search, search_status, code_files, code_grep githits search, githits search-status, githits code ...
文档发现 docs_list githits docs list
阅读源文件或文档部分 read githits read <target> [path]
Grep 源代码和托管文档在一起 仅限 CLI(MCP 迁移待定) githits grep <pattern> <targets...>
包装检验 pkg_info, pkg_vulns, pkg_deps, pkg_changelog, pkg_upgrade_review githits pkg ...

当您的代理需要执行以下操作时,请使用 GitHits:

  • 发现、计划或研究 OSS 项目如何解决模糊问题或不熟悉的错误
  • 在存储库中查找广泛的现有技术或罕见的大海捞针示例
  • 检查已知包或存储库的源代码、测试、符号或文档
  • 在更改代码之前验证依赖项的实际行为
  • 指向第三方代码的调试堆栈跟踪
  • 查看软件包运行状况、许可证、漏洞、依赖项和变更日志
  • 使用事实证据比较依赖性升级

示例

在开源中查找现有技术:

npx githits@latest example "HTTP retries with exponential backoff in Python"

搜索索引代码、文档和符号以查找依赖项:

npx githits@latest search "router middleware" --in npm:express
npx githits@latest search '"body parser" OR multer' --in npm:express --source docs
npx githits@latest search "debounce" --in npm:lodash --source symbol

读取并 grep 依赖源而不克隆:

npx githits@latest code files npm:express lib
npx githits@latest code read npm:express lib/router/index.js --lines 120-200
npx githits@latest code grep npm:express "router.use" lib --regex

检查包运行状况和升级证据:

npx githits@latest pkg info npm:express
npx githits@latest pkg vulns npm:[email protected] --severity high
npx githits@latest pkg deps npm:[email protected] --depth 2
npx githits@latest pkg changelog npm:express --from 4.18.2 --to 5.2.1
npx githits@latest pkg upgrade-review npm:[email protected] --to 4.4.3

浏览并阅读包文档:

npx githits@latest docs list npm:express
npx githits@latest docs read <docs-read-target> --lines 20-80

实验工具

GitHits 0.10 添加了两个用于早期测试的本地工具:

  • resolve_target / githits resolve 变成模糊或不明确的包, 存储库或文档站点名称到分组规范目标中 相关的项目标识保存在一起。
  • code_diff / githits code diff 比较从以下位置解析的存储库树 确切的软件包版本或公共 GitHub 参考。

默认情况下它们是隐藏和禁用的。它们只能通过 本地 githits CLI 和本地 stdio MCP 服务器;托管的 MCP 和插件或 扩展安装保持稳定的工具集。在 GitHits 主机中启用它们 配置,然后重新启动编码代理,以便重新启动本地 MCP 服务器:

# macOS/Linux: ~/.config/githits/config.toml
# Windows: %APPDATA%githitsconfig.toml
[experimental]
tools = true

请参阅 实验工具 了解特定于平台的信息 配置发现,CLI 示例、限制以及如何 禁用这些工具。

支持的来源

GitHits 适用于包和存储库目标,例如:

  • 封装规格:npm:react、npm:[email protected]、pypi:requests、crates:serde
  • GitHub 存储库:https://github.com/expressjs/express、github:expressjs/express@main

包检查支持 npm、PyPI、Hex、Crates、NuGet、Maven、Packagist、 RubyGems、Go、Swift、vcpkg 和 Zig。 vcpkg 和 没有咨询数据 之字形;依赖关系图支持因注册表而异。

认证

正常的本地设置由以下方式处理:

npx githits@latest init

对于手动登录:

npx githits@latest login

本地开发推荐使用浏览器OAuth。凭证存储在 默认系统钥匙串并自动刷新。有用的标志:

  • init --no-browser 或 login --no-browser 打印登录信息 URL 而不是启动浏览器
  • init --port <port> 或 login --port <port> 修复环回回调端口
  • login --force 即使您已经登录也会重新进行身份验证

OAuth 回调始终在运行 GitHits 的机器上侦听。 当GitHits运行在SSH上并且浏览器本地运行时,转发所选内容 来自浏览器机器的端口:

ssh -N -L 8765:127.0.0.1:8765 user@remote-host

打开该隧道后,使用相同端口在远程计算机上运行 GitHits:

npx githits@latest init --no-browser --port 8765

在本地浏览器中打开GitHits打印的URL。更换 user@remote-host 与您通常使用的 SSH 目的地。相同的标志 设置后与 githits login 一起使用。

浏览器 OAuth 是交互式的。对于CI等无人值守环境,供应 GITHITS_API_TOKEN 通过环境的秘密管理器。

钥匙串提示和文件存储

GitHits 默认使用系统钥匙串,因为 OAuth 凭证包含 刷新令牌。在 macOS 上,这意味着钥匙串访问;在 Windows 上这意味着 凭证管理器;在 Linux 上,这意味着可用的 Secret Service 或密钥环 后端。

如果 macOS 显示诸如“gititswant to access ... in your keychain”之类的提示, 当您信任已安装的 githits CLI 时,选择始终允许。 GitHits 无法自定义操作系统提示符;它是由macOS生成的。

GitHits 还写入一个小的非秘密元数据文件,以便最近的启动检查 不需要读取钥匙串。仅当 GitHits 需要时才读取钥匙串 令牌,例如在工具调用、令牌刷新、githits auth status 或 元数据过时或过期后进行登录检查。

如果您的代理即使在始终允许之后仍然显示钥匙串提示,请切换 OAuth 存储为文件模式:

# macOS/Linux: ~/.config/githits/config.toml, or $XDG_CONFIG_HOME/githits/config.toml
# Windows: %APPDATA%githitsconfig.toml
[auth]
storage = "file"

在创建 config.toml 或 GitHits 之前,配置目录可能为空 写入身份验证元数据。较旧的 macOS 安装可能已使用 ~/Library/Application Support/githits; GitHits 仍读取该位置 迁移,但新的身份验证配置和文件存储使用 ~/.config/githits。

您还可以选择加入一个流程:

GITHITS_AUTH_STORAGE=file githits login --force

文件模式将 OAuth 凭证存储为 GitHits 配置下的 JSON 文件 目录。这些文件是使用平台的私有权限编写的 支持它,但它们没有加密。任何可以读取文件的进程 操作系统用户也许能够读取令牌。

仅在您信任本地用户帐户访问的计算机上使用文件模式。对于 CI 和自动化,更喜欢 GITHITS_API_TOKEN 而不是浏览器 OAuth。

使用以下命令检查身份验证和运行时状态:

npx githits@latest auth status
npx githits@latest doctor

请参阅 身份验证文档 钥匙串行为、文件存储模式、CI 设置和故障排除。

手动 MCP 设置

如果您的编码工具不是由 init 自动配置的,请将 GitHits 添加到其 MCP 手动配置:

{
  "mcpServers": {
    "githits": {
      "command": "npx",
      "args": ["-y", "githits@latest", "mcp", "start"]
    }
  }
}

您的工具通过 stdio 运行此命令。无后台守护程序或全局安装 是必需的。

删除 init 写入的配置:

npx githits@latest uninstall

这删除了 GitHits MCP 配置和 init 编写的指南,而 保留存储的凭据。单独运行npx githits@latest logout 删除凭据。兼容性形式 npx githits@latest init uninstall 接受相同的 --yes、--project 和 --keep-guidance 选项。

项目设置

对于项目本地 MCP 配置,运行:

npx githits@latest init --project

项目设置仅适用于经过验证的项目本地 MCP 的工具 支持。项目配置不包含任何秘密,但可以像其他项目一样提交 工具配置,因此在将生成的文件添加到源之前检查它们 控制。

代理安全的非交互式安装使用分阶段发现和显式安装:

npx githits@latest init --detect-agents --json
npx githits@latest init --install-agents cursor,codex-cli

插件和扩展打包

存储库和发布的包提供插件和扩展资产 由兼容主机使用。基于 Git 的安装还保留上下文文件 到规范 AGENTS.md 的符号链接(CLAUDE.md 和 GEMINI.md):

  • .plugin/plugin.json
  • .claude-plugin/plugin.json
  • .claude-plugin/marketplace.json
  • .codex-plugin/plugin.json
  • .cursor-plugin/plugin.json
  • .mcp.json
  • gemini-extension.json
  • plugin.json(谷歌反重力)
  • mcp_config.json(谷歌反重力)
  • AGENTS.md
  • CLAUDE.md
  • GEMINI.md
  • skills/

根技能树由所有支持的主机共享。每个插件和扩展 安装使用托管远程MCP,包括Claude、Codex、Cursor、Gemini CLI、 Google 反重力和 VS Code/GitHub 副驾驶 OpenPlugin。直接 githits init setup 是一个单独的路径:它安装支持的本地 stdio 配置 除了 Cursor 之外的工具,它仍然只能远程使用。存储库根是本机的 通过 plugin.json、mcp_config.json 以及共享的反重力插件 skills/ 树。生成的清单使用 bun run plugins:generate 刷新 并通过 bun run plugins:check 进行验证。

引导init安装四个规范技能(githits-code、githits-mcp、 githits-onboarding 和 githits-package)仅适用于选定的代理。共享 有技能的代理在用户范围内使用 ~/.agents/skills/ 或 .agents/skills/ 在项目范围内;仅本机代理使用经过验证的本机技能目录。 读取共享根的兼容代理可以发现这些技能。后来的一个 引导运行修复缺失的技能,迁移仅删除历史记录 验证完整共享集后,Cline 或 Junie githits-mcp/SKILL.md。

对于 Claude Code 市场安装:

claude plugin marketplace add githits-com/githits-cli
claude plugin install githits@githits-plugins

对于 Gemini CLI 扩展安装:

gemini extensions install https://github.com/githits-com/githits-cli

命令参考

githits init             Connect GitHits to your coding agents
githits uninstall        Remove GitHits MCP configuration and guidance
githits init uninstall   Compatibility alias for `githits uninstall`
githits login            Sign in to your GitHits account
githits logout           Remove stored credentials
githits mcp              Show setup instructions or start the local MCP server
githits mcp start        Always start the local MCP server over stdio
githits example          Find real-world implementations from open source
githits doctor           Diagnose configuration and auth state
githits resolve          Experimental: resolve a fuzzy name to canonical targets
githits settings         View and update preferences, privacy, and terms
githits search           Explore repository code, dependencies, docs, and symbols
githits search-status    Check the status of a previous indexed search
githits code             List, read, grep, or experimentally diff indexed source
githits pkg              Inspect package metadata, vulnerabilities, deps, and changelogs
githits docs             Browse and read package documentation
githits auth             Manage authentication
githits auth status      Show authentication status

完整 CLI 参考号:https://docs.githits.com/cli/commands

环境变量

大多数用户不需要环境变量。这些是常见的覆盖 CI、身份验证存储和本地诊断:

变量 目的 默认
GITHITS_API_TOKEN API 用于身份验证的令牌 未设置
GITHITS_AUTH_STORAGE 覆盖OAuth存储模式:keychain或file keychain
GITHITS_DISABLE_UPDATE_CHECK 禁用 npm 最新版本更新通知 未设置
GITHITS_TELEMETRY 向 stderr 发出本地时序诊断 未设置

完整参考:https://docs.githits.com/cli/environment-variables

源布局

此存储库包含 GitHits CLI 和可重用的 MCP 包:

  • src/ - CLI 命令、本地身份验证、设置流程和本地 MCP stdio 启动
  • packages/mcp/ - 公共 @githits/mcp 运输中性包 MCP 服务器 APIs、工具注册、说明和冒烟测试助手
  • packages/core-internal/ - CLI 使用的共享工作区实现 和 MCP 封装
  • docs/ - 实施说明和贡献者指南
  • scripts/ - 包验证、冒烟测试和开发实用程序

有关已发布的更改、待处理的工作和 当前软件包版本的影响。

发展

要求:

  • Node.js ^20.18.1 || >=22.13.0
  • 包子

常用命令:

bun install
bun run dev --help
bun test
bun run typecheck
bun run build

更改 MCP 工具、CLI 命令、共享格式化程序、auth/error 信封时, 或 MCP/CLI 奇偶校验行为,也运行相关的烟雾套件:

bun run smoke:mcp
bun run smoke:cli

CI 还会在没有凭据或实时后端调用的情况下检查构建的产品。运行 bun run build 之后在本地进行相同的检查:

bun run smoke:cli:built
bun run smoke:mcp:built

线束保留在 Bun 上,而产品子流程执行 dist/cli.js 与 node 来自 PATH。 CI 从 .node-version 规定运行时间。

更改 MCP 指令、工具描述或面向代理的行为时, 使用 eval/agentic/README.md 中描述的目标代理评估:

bun run agent:e2e
相关资讯
点击查看更多
游戏推荐
推荐专题
热门阅读
推荐下载