scai
Version:
> **A local-first AI CLI for understanding, querying, and iterating on large codebases.** > **100% local • No token costs • No cloud • No prompt injection • Private by design**
48 lines (47 loc) • 1.78 kB
JavaScript
export const iterationFileSelector = {
name: 'iterationFileSelector',
description: 'Resolves the TaskStep chosen by reasonNextTaskStep.',
async run(context) {
var _a;
if (!context.task) {
throw new Error("iterationFileSelector: context.task must exist — ensure runBoot has been called");
}
if (!context.task)
throw new Error("iterationFileSelector: context.task must exist");
(_a = context.task).taskSteps || (_a.taskSteps = []);
const currentStepPath = context.task.currentStep?.filePath;
if (!currentStepPath)
return null;
const nextAction = context.analysis?.iterationReasoning?.nextAction;
const resolvedStep = ensureTaskStep(context, currentStepPath, 'selected');
if (nextAction === 'redo-step') {
resolvedStep.status = 'pending';
resolvedStep.startTime = undefined;
resolvedStep.endTime = undefined;
if (resolvedStep.result && typeof resolvedStep.result === 'object') {
delete resolvedStep.result.stepReasoning;
}
}
return resolvedStep;
}
};
function ensureTaskStep(context, filePath, source) {
if (!context.task)
throw new Error("ensureTaskStep: context.task must exist");
let step = context.task.taskSteps.find(s => s.filePath === filePath);
if (!step) {
step = {
taskId: context.task.id, // guaranteed to exist
filePath,
status: 'pending',
result: {
source,
},
};
context.task.taskSteps.push(step);
}
if (context.task.currentStep?.filePath === filePath) {
context.task.currentStep = step;
}
return step;
}