@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
35 lines • 1.83 kB
JavaScript
/**
* ENOENT (missing file), EACCES/EPERM (permission), ENOTDIR/EISDIR (path) are
* not context mismatches — rereading will not fix them. Only context-line
* failures (no error code, thrown by replaceChunks) benefit from a reread.
*/
function isRereadCandidate(failure) {
return failure.code === undefined;
}
export function createRecoveryInstructions(result) {
const mustReadFiles = [...new Set(result.failures.filter(isRereadCandidate).map((failure) => failure.filePath))];
const mustReadFileSet = new Set(mustReadFiles);
const failedFileSet = new Set(result.failures.map((failure) => failure.filePath));
const mustNotReadFiles = [...new Set(result.appliedFiles.filter((filePath) => !mustReadFileSet.has(filePath)))];
return { mustReadFiles, mustNotReadFiles, failedFiles: [...failedFileSet] };
}
export function buildPartialFailureText(result) {
const failureLines = result.failures.map((failure) => `- ${failure.filePath} (${failure.operation}): ${failure.message}`);
const mustReadFiles = result.recoveryInstructions.mustReadFiles;
const mustReadText = mustReadFiles.join(" and ");
return [
result.hasPartialSuccess ? "apply_patch partially failed." : "apply_patch failed.",
"Failed:",
...failureLines,
mustReadFiles.length > 0 ? `Recovery: MUST read ${mustReadText} before retrying.` : "",
result.appliedFiles.length > 0
? "Earlier file actions in this patch were already applied."
: "No file actions were applied.",
result.recoveryInstructions.mustNotReadFiles.length > 0
? "Recovery: MUST NOT reread other files from this patch unless a specific dependency requires it."
: "",
]
.filter((line) => line.length > 0)
.join("\n");
}
//# sourceMappingURL=recovery.js.map