用 JSON 构建应用 UI
Graft CLI 为 repository 操作提供 JSON 输出,应用不需要解析终端文本:
graft status --jsongraft diff --json --rows HEAD~1 HEAD data.sqliteStatus Panel
Section titled “Status Panel”graft status --json常用字段:
| Field | 含义 |
|---|---|
current_head | 当前 commit id。 |
current_branch | 当前 branch。 |
work_in_progress | 有 staged、unstaged、conflict 或 merge state 时为 true。 |
counts | staged、unstaged、conflicted path counts。 |
paths | 每个 changed path 的 rollup。 |
大多数 UI 直接用 paths。
Diff 和 Conflict UI
Section titled “Diff 和 Conflict UI”graft diff --json --rows HEAD~1 HEAD data.sqlitegraft conflicts --jsongraft resolve --json --theirs --row docs 42 data.sqlitepaths 适合做左侧导航,SQLite row payload 用于详情面板。
根据 path 类型渲染:
| 类型 | UI |
|---|---|
| SQLite database | row/schema conflict review。 |
| Text file | side picker 或 manual editor。 |
| Binary/external file | ours/theirs/manual replacement。 |
Payload 和 Sync UI
Section titled “Payload 和 Sync UI”graft ls-files --json --detailsgraft payload status --json HEADgraft payload fetch --json --remote origin HEADgraft fetch --json origin maingraft pull --json origin maingraft push --json origin main人类终端用普通输出;应用集成用 JSON 输出。