Official

git

Built-in git UI (JavaScript UI plugin).

The app opens the listing; nothing installs until an agent in your Plugins workspace has read the files and you enable the plugin. In a terminal: dvg install divergence/git@0.3.3

Permissions in 0.3.3

  • Run git commands git.writeHighRuns any git command.Stage, commit, switch branches and sync with the remote
  • Use your agents' models models.useHighRuns prompts through the agents you enabled.Write commit messages and pull requests with the cheapest model of your agents, on your own account
  • Read chats chats.readMediumReads your transcripts and chat lists.Refresh when an agent finishes a turn
  • Run named programs processMediumStarts the listed programs.Find and open the branch's pull request with the GitHub CLIPrograms: gh
  • Read git status and diffs git.readLowReads git status and diffs.Show the repository's status and diffs, and follow its changes
  • Show panels ui.slotsAlways grantedShows views in the listed parts of the window.Show the source control button and panelSlots: railright

Files

status.ts6.5 KB
// Porcelain grouping and panel/menu choices, kept pure for regression tests.
// A path can appear on both sides of the index; conflicts belong only to merge.
import * as z from "zod";
import type { EffectClient } from "divergence/effect";
import type { AppState, GitEntry, GitStatus } from "divergence";
import type { Tabs } from "../tabs/contract.ts";

export const TONE: Readonly<Record<string, string>> = {
  M: "warning",
  T: "warning",
  A: "success",
  U: "success",
  D: "danger",
  R: "info",
  C: "info",
  "!": "danger",
};
const CONFLICT = new Set(["DD", "AU", "UD", "UA", "DU", "AA", "UU"]);
export type Section = "merge" | "staged" | "changes";
export interface Entry extends GitEntry {
  letter: string;
  side: Section;
}
export type Groups = Record<Section, Entry[]>;
/** Where a pull request of the branch goes: the repository at `root` (where gh runs), the remote and its branch it
 * starts from (`head`), and the repository's default branch it goes into (`base`). */
export interface PullTarget {
  readonly root: string;
  readonly remote: string;
  readonly head: string;
  readonly base: string;
}
/** What the panel shows for the branch's pull request. */
export type Pull =
  // Nothing: the branch has no upstream on GitHub, gh is not installed, the branch is the default one, or the
  // lookup has not answered yet.
  | { readonly kind: "none" }
  // The lookup failed, in git's or gh's own words.
  | { readonly kind: "failed"; readonly message: string }
  // Create Pull Request.
  | ({ readonly kind: "offer" } & PullTarget)
  // The form, while an agent writes its title and description or the user edits them.
  | ({ readonly kind: "draft"; readonly title: string; readonly body: string; readonly writing: boolean } & PullTarget)
  // The branch's open pull request, as a link.
  | { readonly kind: "link"; readonly url: string; readonly number: number };
export interface GitState {
  workspaceId: string | null;
  status: GitStatus | null;
  error: string | null;
  message: string;
  // An agent writes the commit message.
  writing: boolean;
  busy: string | null;
  collapsed: Record<Section, boolean>;
  confirm: string | null;
  menuOpen: boolean;
  branchOpen: boolean;
  branches: string[];
  branchQuery: string;
  pull: Pull;
  // The divergence/tabs client while its provider runs; diffs and files
  // open through it, and stay closed without it.
  tabs: EffectClient<typeof Tabs> | undefined;
}
export const initialState = (): GitState => ({
  workspaceId: null,
  status: null,
  error: null,
  message: "",
  writing: false,
  busy: null,
  collapsed: { merge: false, staged: false, changes: false },
  confirm: null,
  menuOpen: false,
  branchOpen: false,
  branches: [],
  branchQuery: "",
  pull: { kind: "none" },
  tabs: undefined,
});

export function groups(status: GitStatus): Groups {
  const result: Groups = { merge: [], staged: [], changes: [] };
  for (const entry of status.entries) {
    const x = entry.staged ?? " ",
      y = entry.unstaged ?? " ";
    if (CONFLICT.has(x + y)) result.merge.push({ ...entry, letter: "!", side: "merge" });
    else if (x === "?") result.changes.push({ ...entry, letter: "U", side: "changes" });
    else {
      if (x !== " ") result.staged.push({ ...entry, letter: x, side: "staged" });
      if (y !== " ") result.changes.push({ ...entry, letter: y, side: "changes" });
    }
  }
  return result;
}
/** The paths a command on these entries names. A staged rename names both paths, so unstaging it puts the old file
 * back in the index; in the work tree only the new path exists, and git refuses a path that matches no file. */
export const pathsOf = (entries: readonly Entry[]): string[] =>
  entries.flatMap((entry) => (entry.origPath && entry.side === "staged" ? [entry.origPath, entry.path] : [entry.path]));
export const isOpen = (app: AppState): boolean =>
  app.shared?.rightPanel === "git" || app.shared?.rightPanelPreview === "git";

/** The branches the picker offers from `git branch -a --format=%(refname)`: the local ones, then those only a remote has
 * by their own name, which `git checkout` turns into a local branch that tracks the remote one. */
export function branchNames(refs: string): string[] {
  const names = new Set<string>();
  const remote: string[] = [];
  for (const ref of refs.split("\n").map((line) => line.trim())) {
    if (ref.startsWith("refs/heads/")) names.add(ref.slice("refs/heads/".length));
    else if (ref.startsWith("refs/remotes/")) {
      const name = ref.slice("refs/remotes/".length).split("/").slice(1).join("/");
      if (name && name !== "HEAD") remote.push(name);
    }
  }
  for (const name of remote) names.add(name);
  return [...names];
}
export function branchOptions(branches: readonly string[], query: string) {
  const q = query.trim();
  return {
    query: q,
    shown: branches.filter((branch) => branch.toLowerCase().includes(q.toLowerCase())),
    create: !!q && !branches.includes(q),
  };
}
/** Whether HEAD is on a branch, which a push can publish; git --branch names a detached HEAD this way. */
export const onBranch = (status: GitStatus): boolean => !!status.branch && status.branch !== "HEAD (no branch)";
export function primaryAction(status: GitStatus, total: number): "commit" | "publish" | "sync" | "idle" {
  if (total) return "commit";
  if (onBranch(status) && !status.upstream) return "publish";
  return status.ahead || status.behind ? "sync" : "idle";
}
export function discardPaths(entries: readonly Entry[]) {
  return {
    untracked: entries.filter((entry) => entry.letter === "U").map((entry) => entry.path),
    tracked: pathsOf(entries.filter((entry) => entry.letter !== "U")),
  };
}

export type MenuAction = "pull" | "push" | "fetch" | "amend" | "undo" | "stage-all" | "unstage-all" | "stash" | "pop";
export const MENU: readonly { action: MenuAction; label: string; icon: string }[] = [
  { action: "pull", label: "Pull", icon: "arrow-down" },
  { action: "push", label: "Push", icon: "arrow-up" },
  { action: "fetch", label: "Fetch", icon: "refresh-cw" },
  { action: "amend", label: "Commit (Amend)", icon: "git-commit-horizontal" },
  { action: "undo", label: "Undo Last Commit", icon: "undo-2" },
  { action: "stage-all", label: "Stage All Changes", icon: "plus" },
  { action: "unstage-all", label: "Unstage All Changes", icon: "minus" },
  { action: "stash", label: "Stash", icon: "archive" },
  { action: "pop", label: "Pop Latest Stash", icon: "archive-restore" },
];

const finished = z.object({ event: z.literal("run_finished") });
export const runFinished = (kind: unknown): boolean => finished.safeParse(kind).success;

Versions

VersionPublishedPlugin APISizePermissionsStatus
0.3.3latestNov 21, 2026>=5 <630.8 KB6 permissionsListed
0.3.2Nov 16, 2026>=5 <630.4 KB6 permissionsListed
0.3.1Nov 11, 2026>=5 <630.2 KB6 permissionsListed
0.3.0Nov 9, 2026>=5 <629.2 KB6 permissionsListed
0.2.1Oct 27, 2026>=2 <413.6 KB4 permissionsListed

Reviews and comments

0 threads · 0 reviews

No comments yet.