draftify-cli 1.0.91 → 1.0.94
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/repl.js +33 -4
- package/package.json +1 -1
package/dist/repl.js
CHANGED
|
@@ -905,18 +905,32 @@ async function startRepl(initialUsername) {
|
|
|
905
905
|
let retryCount = 0;
|
|
906
906
|
let success = false;
|
|
907
907
|
let partialText = "";
|
|
908
|
-
|
|
908
|
+
// Detect if a successful response was actually truncated mid-content
|
|
909
|
+
function detectTruncation(text) {
|
|
910
|
+
// Check for unclosed FILE_CREATE
|
|
911
|
+
const createOpenMatch = text.match(/<FILE_CREATE\s+path="([^"]+)"[^>]*>/);
|
|
912
|
+
if (createOpenMatch && !/<\/FILE_CREATE>/i.test(text)) {
|
|
913
|
+
return { truncated: true, filePath: createOpenMatch[1], tagType: 'FILE_CREATE' };
|
|
914
|
+
}
|
|
915
|
+
// Check for unclosed FILE_MODIFY
|
|
916
|
+
const modifyOpenMatch = text.match(/<FILE_MODIFY\s+path="([^"]+)"[^>]*>/);
|
|
917
|
+
if (modifyOpenMatch && !/<\/FILE_MODIFY>/i.test(text)) {
|
|
918
|
+
return { truncated: true, filePath: modifyOpenMatch[1], tagType: 'FILE_MODIFY' };
|
|
919
|
+
}
|
|
920
|
+
return { truncated: false };
|
|
921
|
+
}
|
|
922
|
+
while (retryCount < 4 && !success) {
|
|
909
923
|
try {
|
|
910
924
|
let retryHistory = [...conversationHistory];
|
|
911
925
|
let retryPrompt = finalPrompt;
|
|
912
926
|
if (partialText) {
|
|
913
927
|
retryHistory.push({ role: "user", content: finalPrompt });
|
|
914
928
|
retryHistory.push({ role: "assistant", content: partialText });
|
|
915
|
-
retryPrompt = "Continue exactly from where you left off. Do not repeat
|
|
929
|
+
retryPrompt = "Continue exactly from where you left off. Do not repeat anything you already wrote. Continue the file content from the exact character where it was cut off.";
|
|
916
930
|
}
|
|
917
931
|
spinner = (0, ui_1.createSpinner)("Working...").start();
|
|
918
932
|
if (retryCount > 0) {
|
|
919
|
-
spinner.setPrefix(`
|
|
933
|
+
spinner.setPrefix(`Continuing... (${retryCount}/3)`);
|
|
920
934
|
}
|
|
921
935
|
let thisAttemptText = "";
|
|
922
936
|
const attemptResult = await (0, api_1.refactorCodeApi)(requestPayloadFileName, requestPayloadCode, retryPrompt, retryHistory, currentModel, activeSkillsData, (0, config_1.getThinkingLevel)(), (chunk) => {
|
|
@@ -948,7 +962,22 @@ async function startRepl(initialUsername) {
|
|
|
948
962
|
spinner.setPrefix("Analyzing...");
|
|
949
963
|
}
|
|
950
964
|
}, exports.globalAbortController.signal);
|
|
951
|
-
|
|
965
|
+
const combined = partialText + attemptResult;
|
|
966
|
+
// --- TRUNCATION DETECTION ---
|
|
967
|
+
// If the stream ended cleanly but the content is still incomplete (token-limited),
|
|
968
|
+
// treat it like a retry scenario and continue generation.
|
|
969
|
+
const truncationInfo = detectTruncation(combined);
|
|
970
|
+
if (truncationInfo.truncated && retryCount < 3) {
|
|
971
|
+
if (spinner)
|
|
972
|
+
spinner.stop();
|
|
973
|
+
ui_1.ui.info(`Response truncated mid-file (${truncationInfo.filePath}). Continuing...`);
|
|
974
|
+
partialText = combined;
|
|
975
|
+
retryCount++;
|
|
976
|
+
currentStreamedText = combined;
|
|
977
|
+
await new Promise(r => setTimeout(r, 500));
|
|
978
|
+
continue; // restart the while loop with updated partialText
|
|
979
|
+
}
|
|
980
|
+
rawResult = combined;
|
|
952
981
|
success = true;
|
|
953
982
|
}
|
|
954
983
|
catch (e) {
|