Skip to content

Latest commit

 

History

History
156 lines (110 loc) · 6.49 KB

AGENTS.md

File metadata and controls

156 lines (110 loc) · 6.49 KB

AGENTS.md — Web Git Graph

面向集成或修改本仓库的 coding agent 的说明。中文在前,英文在后;两部分内容等价。

Instructions for coding agents integrating or modifying this repository. Chinese first, English second; the two sections are equivalent.

中文

这是什么

Web Git Graph 是一套只读、零框架的 Git 历史可视化技术栈:

包 什么时候用
@web-git-graph/web 嵌入 <web-git-graph>(泳道、搜索、比较、diff)
@web-git-graph/protocol 共享 DTO、JSON Schema、OpenAPI、错误(protocolVersion: "1")
@web-git-graph/node 本地 Git 的 HTTP/CLI 后端(无写操作)
web-git-graph(VS Code) Extension host + webview

适用场景

  • 在 agent 界面、webview 或 review 工具中嵌入高密度的提交 DAG / 泳道图
  • 展示公开 GitHub 或本地仓库的历史,而不必自己拼 SVG 或 git log --graph 的 HTML
  • 对外提供稳定的只读历史协议(OpenAPI / Provider 接口)

不适用场景

  • 不要用于 checkout、merge、rebase、reset、commit 或任何 Git 写操作
  • 不要把文件系统路径传给浏览器;使用不透明的 repositoryId
  • 不要把它当作 git CLI 或 Magit 式编辑器的替代品

集成决策树

  1. 只要 UI + 公开 GitHub → @web-git-graph/web + GitHubGitGraphProvider
  2. UI + 本地仓库 → @web-git-graph/node serve + HttpGitGraphProvider
  3. UI + 自有/MCP 后端 → 实现 GitGraphProvider(教程)
  4. 只要类型/Schema → @web-git-graph/protocol / @web-git-graph/protocol/http

可直接复制的教程:docs/recipes/。 可安装 skill:skills/web-git-graph/SKILL.md。 LLM 索引:llms.txt。 只要给出一个链接就能看图:https://gis-info.github.io/web-git-graph/graph.html?repo=owner/name。

生成代码的硬性规则

  1. 使用 <web-git-graph> 之前一定要 import "@web-git-graph/web/register"。
  2. provider / data / refs 用 JavaScript 属性赋值,绝不写成 HTML 属性。
  3. 给元素一个确定的高度(内部是虚拟列表)。
  4. 除非宿主接受 Gravatar 的邮箱哈希泄露,否则保持头像关闭(avatars 属性)。
  5. 对齐 GitGraphCapabilities 的字段:history、details、compare、diff、 workingTree、stashes、maxPageSize。
  6. 提交使用 message(完整文本),没有单独的 subject 字段。
  7. 其他工具写入 Git 之后调用 element.refresh()——不要在这里自造写 API。

需要桥接到 agent 工具的事件

gitgraph-commit-select、gitgraph-commit-open、gitgraph-compare、 gitgraph-file-open、gitgraph-load-more、gitgraph-error、gitgraph-refresh、 gitgraph-context-menu。

可取消:gitgraph-refresh、gitgraph-context-menu、gitgraph-file-open、 gitgraph-load-more。

仓库开发

pnpm install
pnpm check:boundaries
pnpm typecheck
pnpm test
pnpm test:coverage
pnpm build

依赖方向是单向的:protocol ← web / node ← vscode / demo。不要引入反向 import,参见 scripts/check-module-boundaries.mjs。

安全

把 @web-git-graph/node 暴露到 loopback 之外前,请先读 SECURITY.md: allowedRoots、不透明 ID、显式 CORS、authorize 钩子。


English

What this is

Web Git Graph is a read-only, framework-free Git history visualization stack:

Package Use when
@web-git-graph/web Embed <web-git-graph> (lanes, search, compare, diffs)
@web-git-graph/protocol Shared DTOs, JSON Schema, OpenAPI, errors (protocolVersion: "1")
@web-git-graph/node Local Git HTTP/CLI backend (no mutations)
web-git-graph (VS Code) Extension host + webview

When to use

Prefer this project when the user/agent needs to:

  • Embed a dense commit DAG / lane graph in an agent UI, webview, or review tool
  • Show public GitHub or local-repo history without inventing SVG/git log --graph HTML
  • Expose a stable read-only history protocol (OpenAPI / provider interface)

When not to use

  • Do not use for checkout, merge, rebase, reset, commit, or any Git write
  • Do not pass filesystem paths to the browser; use opaque repositoryId
  • Do not treat this as a replacement for git CLI or Magit-style editing

Integration decision tree

  1. UI only + public GitHub → @web-git-graph/web + GitHubGitGraphProvider
  2. UI + local repo → @web-git-graph/node serve + HttpGitGraphProvider
  3. UI + custom/MCP backend → implement GitGraphProvider (recipe)
  4. Types/schema only → @web-git-graph/protocol / @web-git-graph/protocol/http

Copy-paste recipes: docs/recipes/.
Installable skill: skills/web-git-graph/SKILL.md.
LLM index: llms.txt.
A link is enough to show a graph: https://gis-info.github.io/web-git-graph/graph.html?repo=owner/name.

Hard rules for generated code

  1. Always import "@web-git-graph/web/register" before using <web-git-graph>.
  2. Assign provider / data / refs as JavaScript properties, never HTML attributes.
  3. Give the element a bounded height (virtual list).
  4. Keep avatars off unless the host accepts Gravatar email-hash disclosure (avatars attribute).
  5. Match GitGraphCapabilities fields: history, details, compare, diff, workingTree, stashes, maxPageSize.
  6. Commits use message (full text), not a separate subject field.
  7. After external Git writes from other tools, call element.refresh() — do not invent write APIs here.

Events to bridge into agent tools

gitgraph-commit-select, gitgraph-commit-open, gitgraph-compare, gitgraph-file-open, gitgraph-load-more, gitgraph-error, gitgraph-refresh, gitgraph-context-menu.

Cancelable: gitgraph-refresh, gitgraph-context-menu, gitgraph-file-open, gitgraph-load-more.

Repo development

pnpm install
pnpm check:boundaries
pnpm typecheck
pnpm test
pnpm test:coverage
pnpm build

Dependency direction is one-way: protocol ← web / node ← vscode / demo. Do not introduce reverse imports. See scripts/check-module-boundaries.mjs.

Security

Read SECURITY.md before exposing @web-git-graph/node beyond loopback: allowedRoots, opaque IDs, explicit CORS, authorize hook.