跳转到内容

用 JSON 构建应用 UI

Graft CLI 为 repository 操作提供 JSON 输出,应用不需要解析终端文本:

Terminal window
graft status --json
graft diff --json --rows HEAD~1 HEAD data.sqlite
Terminal window
graft status --json

常用字段:

Field含义
current_head当前 commit id。
current_branch当前 branch。
work_in_progress有 staged、unstaged、conflict 或 merge state 时为 true。
countsstaged、unstaged、conflicted path counts。
paths每个 changed path 的 rollup。

大多数 UI 直接用 paths

Terminal window
graft diff --json --rows HEAD~1 HEAD data.sqlite
graft conflicts --json
graft resolve --json --theirs --row docs 42 data.sqlite

paths 适合做左侧导航,SQLite row payload 用于详情面板。

根据 path 类型渲染:

类型UI
SQLite databaserow/schema conflict review。
Text fileside picker 或 manual editor。
Binary/external fileours/theirs/manual replacement。
Terminal window
graft ls-files --json --details
graft payload status --json HEAD
graft payload fetch --json --remote origin HEAD
graft fetch --json origin main
graft pull --json origin main
graft push --json origin main

人类终端用普通输出;应用集成用 JSON 输出。