in src/entrypoints/handle-results.ts [18:85]
export async function handleResults() {
try {
const stringJunieJsonOutput = process.env[ENV_VARS.JSON_JUNIE_OUTPUT]
if (!stringJunieJsonOutput) {
throw new Error(
`❌ Failed to retrieve Junie execution results. ` +
`This could be due to:\n` +
`• Junie execution did not complete successfully\n` +
`• Junie output was empty or invalid\n` +
`Please check the Junie execution logs for details.`
);
}
const junieJsonOutput = JSON.parse(stringJunieJsonOutput) as any
const context = JSON.parse(process.env[OUTPUT_VARS.PARSED_CONTEXT]!) as JunieExecutionContext
const isResolveConflict = context.inputs.resolveConflicts || isReviewOrCommentHasResolveConflictsTrigger(context)
const junieErrors = junieJsonOutput.errors
if (junieErrors && (junieErrors as string[]).length > 0) {
const errorList = (junieErrors as string[]).map(err => ` • ${err}`).join('\n');
throw new Error(
`❌ Junie execution encountered errors during task processing.\n\n` +
`Errors reported:\n${errorList}\n\n` +
`Review the errors above and check the Junie execution logs for more details.`
);
}
const rawResult = junieJsonOutput.result
if (rawResult === "Empty" || !rawResult || rawResult.trim() === "") {
throw new Error(
`❌ Junie execution returned an empty result.\n\n` +
`This typically indicates an error during task processing.\n` +
`Please check the Junie execution logs for details.`
);
}
const actionToDo = await getActionToDo(context);
// Sanitize Junie's output to prevent token leakage and self-triggering
const rawTitle = junieJsonOutput.taskName || (isResolveConflict ? `Resolve conflicts for ${context.entityNumber} PR` : 'Junie finished task successfully')
const rawBody = junieJsonOutput.result
const triggerPhrase = context.inputs.triggerPhrase
const title = sanitizeJunieOutput(rawTitle, triggerPhrase)
const body = sanitizeJunieOutput(rawBody, triggerPhrase)
let issueId
if (isTriggeredByUserInteraction(context)) {
issueId = context.entityNumber
}
const commitMessage = COMMIT_MESSAGE_TEMPLATE(title, issueId)
// Export outputs based on action type
switch (actionToDo) {
case ActionType.CREATE_PR:
exportResultsOutputs(
title,
body,
commitMessage,
PR_TITLE_TEMPLATE(title),
PR_BODY_TEMPLATE(body, issueId));
break;
case ActionType.COMMIT_CHANGES:
case ActionType.PUSH:
exportResultsOutputs(title, body, commitMessage);
break;
case ActionType.WRITE_COMMENT:
case ActionType.NOTHING:
exportResultsOutputs(title, body);
break;
}
} catch (error) {
handleStepError("Handle results step", error);
}
}