MCPcopy Index your code
hub / github.com/openai/codex-plugin-cc / collectWorkingTreeContext

Function collectWorkingTreeContext

plugins/codex/scripts/lib/git.mjs:224–259  ·  view source on GitHub ↗
(cwd, state, options = {})

Source from the content-addressed store, hash-verified

222}
223
224function collectWorkingTreeContext(cwd, state, options = {}) {
225 const includeDiff = options.includeDiff !== false;
226 const status = gitChecked(cwd, ["status", "--short", "--untracked-files=all"]).stdout.trim();
227 const changedFiles = listUniqueFiles(state.staged, state.unstaged, state.untracked);
228
229 let parts;
230 if (includeDiff) {
231 const stagedDiff = gitChecked(cwd, ["diff", "--cached", "--binary", "--no-ext-diff", "--submodule=diff"]).stdout;
232 const unstagedDiff = gitChecked(cwd, ["diff", "--binary", "--no-ext-diff", "--submodule=diff"]).stdout;
233 const untrackedBody = state.untracked.map((file) => formatUntrackedFile(cwd, file)).join("\n\n");
234 parts = [
235 formatSection("Git Status", status),
236 formatSection("Staged Diff", stagedDiff),
237 formatSection("Unstaged Diff", unstagedDiff),
238 formatSection("Untracked Files", untrackedBody)
239 ];
240 } else {
241 const stagedStat = gitChecked(cwd, ["diff", "--shortstat", "--cached"]).stdout.trim();
242 const unstagedStat = gitChecked(cwd, ["diff", "--shortstat"]).stdout.trim();
243 const untrackedBody = state.untracked.map((file) => formatUntrackedFile(cwd, file)).join("\n\n");
244 parts = [
245 formatSection("Git Status", status),
246 formatSection("Staged Diff Stat", stagedStat),
247 formatSection("Unstaged Diff Stat", unstagedStat),
248 formatSection("Changed Files", changedFiles.join("\n")),
249 formatSection("Untracked Files", untrackedBody)
250 ];
251 }
252
253 return {
254 mode: "working-tree",
255 summary: `Reviewing ${state.staged.length} staged, ${state.unstaged.length} unstaged, and ${state.untracked.length} untracked file(s).`,
256 content: parts.join("\n"),
257 changedFiles
258 };
259}
260
261function collectBranchContext(cwd, baseRef, options = {}) {
262 const includeDiff = options.includeDiff !== false;

Callers 1

collectReviewContextFunction · 0.85

Calls 4

gitCheckedFunction · 0.85
listUniqueFilesFunction · 0.85
formatUntrackedFileFunction · 0.85
formatSectionFunction · 0.85

Tested by

no test coverage detected