Z ZPI 文档 v0.3.8
介绍页

源码

packages/desktop/src/shared/review.ts

typescript30 行查看原文
import type { DiffItem } from "./bridge.ts";

export type { ReviewDiffData } from "@zpi-dev/ui";

export const reviewSources = {
  unstaged: "未暂存",
  staged: "已暂存",
  branch: "全部分支更改",
  "last-turn": "上一轮更改",
} as const;
export type ReviewSource = keyof typeof reviewSources;
export interface ReviewSnapshot {
  entries: DiffItem[];
  isRepository: boolean;
  isGitAvailable?: boolean;
  runId?: string;
  watchPaths?: string[];
}
export function reviewPatchStats(patch: string | undefined) {
  let added = 0;
  let removed = 0;
  let hunk = false;
  for (const line of patch?.split("\n") ?? []) {
    if (line.startsWith("@@ ")) hunk = true;
    else if (hunk && line.startsWith("+")) added++;
    else if (hunk && line.startsWith("-")) removed++;
  }
  return { added, removed };
}