refactor: simplify pass (trekexecute)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
f6bdc2de59
commit
af90e82794
12 changed files with 303 additions and 186 deletions
|
|
@ -116,15 +116,18 @@ const GATES_USAGE = 'usage: --gates takes true, false, closed or open';
|
|||
|
||||
function parseArgs(argv) {
|
||||
const out = {};
|
||||
const setGates = (v) => {
|
||||
const g = gatesValue(v);
|
||||
if (g === undefined) out.error = GATES_USAGE;
|
||||
else out.gates = g;
|
||||
};
|
||||
for (let i = 0; i < argv.length; i++) {
|
||||
const a = argv[i];
|
||||
if (a === '--state') out.state = argv[++i];
|
||||
else if (a === '--event') out.event = argv[++i];
|
||||
else if (a.startsWith('--gates=')) {
|
||||
// The one-token form, read as `--gates <value>`; an empty value is no value.
|
||||
const g = gatesValue(a.slice('--gates='.length));
|
||||
if (g === undefined) out.error = GATES_USAGE;
|
||||
else out.gates = g;
|
||||
setGates(a.slice('--gates='.length));
|
||||
} else if (a === '--gates') {
|
||||
// Bare `--gates` (last, or followed by another flag) means on and
|
||||
// consumes nothing. A value is case-sensitive: true|closed = on,
|
||||
|
|
@ -133,9 +136,7 @@ function parseArgs(argv) {
|
|||
if (v === undefined || v.startsWith('--')) {
|
||||
out.gates = true;
|
||||
} else {
|
||||
const g = gatesValue(v);
|
||||
if (g === undefined) out.error = GATES_USAGE;
|
||||
else out.gates = g;
|
||||
setGates(v);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,11 +47,11 @@ export function newFilesInDiff(diffText) {
|
|||
const paths = [];
|
||||
const unread = [];
|
||||
let header = null;
|
||||
let headers = 0;
|
||||
let sawHeader = false;
|
||||
const lines = String(diffText).split('\n').map((l) => l.replace(ANSI_RE, ''));
|
||||
for (const line of lines) {
|
||||
if (line.startsWith('diff --git ')) {
|
||||
headers++;
|
||||
sawHeader = true;
|
||||
header = line;
|
||||
continue;
|
||||
}
|
||||
|
|
@ -64,7 +64,7 @@ export function newFilesInDiff(diffText) {
|
|||
}
|
||||
}
|
||||
const first = lines.find((l) => l.trim() !== '');
|
||||
if (headers === 0 && first !== undefined) unread.push(`no diff --git header in a non-empty diff (first line: ${first.slice(0, 200)})`);
|
||||
if (!sawHeader && first !== undefined) unread.push(`no diff --git header in a non-empty diff (first line: ${first.slice(0, 200)})`);
|
||||
return { paths, unread };
|
||||
}
|
||||
|
||||
|
|
@ -118,14 +118,9 @@ export function parkAttemptFiles({ diffText, step, attempt, cwd = process.cwd()
|
|||
continue;
|
||||
}
|
||||
const posix = rel.split('\\').join('/');
|
||||
let intentToAdd = false;
|
||||
if (trackedPaths.has(posix)) {
|
||||
if (inHead(root, posix)) {
|
||||
kept.push({ path, reason: 'tracked since the attempt: not the executor\'s to move', blocking: false });
|
||||
continue;
|
||||
}
|
||||
// In the index but not in HEAD: registered --intent-to-add by the attempt.
|
||||
intentToAdd = true;
|
||||
if (trackedPaths.has(posix) && inHead(root, posix)) {
|
||||
kept.push({ path, reason: 'tracked since the attempt: not the executor\'s to move', blocking: false });
|
||||
continue;
|
||||
}
|
||||
const target = join(to, rel);
|
||||
if (lexists(target)) {
|
||||
|
|
@ -133,7 +128,8 @@ export function parkAttemptFiles({ diffText, step, attempt, cwd = process.cwd()
|
|||
continue;
|
||||
}
|
||||
moves.push({ path, abs, rel, target });
|
||||
if (intentToAdd) unindex.push(posix);
|
||||
// In the index but not in HEAD: registered --intent-to-add by the attempt.
|
||||
if (trackedPaths.has(posix)) unindex.push(posix);
|
||||
}
|
||||
// Out of the index first, all in ONE call before anything moves: git
|
||||
// refuses the whole call when one path cannot be removed, so a failure
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue