MCPcopy Create free account
hub / github.com/openai/codex-plugin-cc / formatUntrackedFile

Function formatUntrackedFile

plugins/codex/scripts/lib/git.mjs:196–222  ·  view source on GitHub ↗
(cwd, relativePath)

Source from the content-addressed store, hash-verified

194}
195
196function formatUntrackedFile(cwd, relativePath) {
197 const absolutePath = path.join(cwd, relativePath);
198 let stat;
199 try {
200 stat = fs.statSync(absolutePath);
201 } catch {
202 return `### ${relativePath}\n(skipped: broken symlink or unreadable file)`;
203 }
204 if (stat.isDirectory()) {
205 return `### ${relativePath}\n(skipped: directory)`;
206 }
207 if (stat.size > MAX_UNTRACKED_BYTES) {
208 return `### ${relativePath}\n(skipped: ${stat.size} bytes exceeds ${MAX_UNTRACKED_BYTES} byte limit)`;
209 }
210
211 let buffer;
212 try {
213 buffer = fs.readFileSync(absolutePath);
214 } catch {
215 return `### ${relativePath}\n(skipped: broken symlink or unreadable file)`;
216 }
217 if (!isProbablyText(buffer)) {
218 return `### ${relativePath}\n(skipped: binary file)`;
219 }
220
221 return [`### ${relativePath}`, "```", buffer.toString("utf8").trimEnd(), "```"].join("\n");
222}
223
224function collectWorkingTreeContext(cwd, state, options = {}) {
225 const includeDiff = options.includeDiff !== false;

Callers 1

Calls 1

isProbablyTextFunction · 0.90

Tested by

no test coverage detected