Skip to main content

Module vcs

Module vcs 

Source
Expand description

/vcs/* — git status/diff/info, freeze-parity (WEBUI-PLAN W5).

Shapes probed live against opencode 1.18.31 (2026-10-08):

  • GET /vcs → {branch, default_branch} (strings or null)
  • GET /vcs/status → FileStatus[] {file, additions, deletions, status} (status ∈ added|deleted|modified), sorted by file
  • GET /vcs/diff?mode=git|branch[&context=N] → FileDiff[] {file, patch, additions, deletions, status}
  • GET /vcs/diff/raw → the raw patch text (empty string when clean)
  • bad mode → 400 Effect Query envelope

Subprocess discipline (the “large diffs are slow” complaint): a single status --porcelain + a single diff --numstat for stats, and ONE batched diff --patch for all tracked files (git diff … -- .), split by diff --git headers — never one spawn per file. Untracked files are synthesized per-file like freeze (unavoidable: --no-index is per path), capped. Total patch bytes capped at 10 MB (freeze MAX_TOTAL_PATCH_BYTES). All git runs off the async workers via run_blocking at the call site.

/vcs/apply applies a patch to the worktree via git apply - (SNAPSHOT §5); vcs::apply is the shell-out used by the v2 handler.

Functions§

apply
git apply - in dir with patch on stdin (upstream Git.applyPatch). None when dir is not inside a git work tree; Some(ok) otherwise.
diff
mode: git | branch. context: unified context lines (default full).
diff_raw
diff_raw_bounded
/vcs/diff/raw variant: same patch text but bounded by MAX_TOTAL_PATCH_BYTES (the tracked diff() caps its aggregate; the raw route concatenated the tracked patch AND one --no-index per untracked file with no cap — an unbounded request-reachable allocation on a large dirty tree). Truncation is at a char boundary; the caller marks it truncated.
info
status
toplevel
Git worktree toplevel for dir (upstream project.worktree). None when dir is not inside a git work tree.