draftify-cli 1.0.33 → 1.0.35

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.
Files changed (2) hide show
  1. package/dist/repl.js +76 -38
  2. package/package.json +1 -1
package/dist/repl.js CHANGED
@@ -745,50 +745,88 @@ async function startRepl(initialUsername) {
745
745
  activeSkillsData = allAvailable.filter((s) => activeSkillNames.includes(s.name));
746
746
  }
747
747
  const activeActions = new Set();
748
- spinner = (0, ui_1.createSpinner)("Thinking...").start();
749
- const rawResult = await (0, api_1.refactorCodeApi)(requestPayloadFileName, requestPayloadCode, finalPrompt, conversationHistory, currentModel, activeSkillsData, (0, config_1.getThinkingLevel)(), (chunk) => {
750
- currentStreamedText += chunk;
751
- // Find the last opened tag that hasn't been closed yet
752
- const createMatch = currentStreamedText.match(/<FILE_CREATE\s+path="([^"]+)"[^>]*>(?![\s\S]*<\/FILE_CREATE>)/);
753
- const modifyMatch = currentStreamedText.match(/<FILE_MODIFY\s+path="([^"]+)"[^>]*>(?![\s\S]*<\/FILE_MODIFY>)/);
754
- const deleteMatch = currentStreamedText.match(/<FILE_DELETE\s+path="([^"]+)"/);
755
- if (createMatch) {
756
- const filePath = createMatch[1];
757
- const actionKey = `create:${filePath}`;
758
- if (!activeActions.has(actionKey)) {
759
- activeActions.add(actionKey);
760
- spinner.stop();
761
- ui_1.ui.fileCreate(filePath);
762
- spinner.start();
748
+ let rawResult = "";
749
+ let retryCount = 0;
750
+ let success = false;
751
+ let partialText = "";
752
+ while (retryCount < 3 && !success) {
753
+ try {
754
+ let retryHistory = [...conversationHistory];
755
+ let retryPrompt = finalPrompt;
756
+ if (partialText) {
757
+ retryHistory.push({ role: "user", content: finalPrompt });
758
+ retryHistory.push({ role: "assistant", content: partialText });
759
+ retryPrompt = "Continue exactly from where you left off. Do not repeat what you already said, just continue the exact code or sentence you were writing.";
763
760
  }
764
- spinner.setPrefix(`Creating ${filePath}...`);
765
- }
766
- else if (modifyMatch) {
767
- const filePath = modifyMatch[1];
768
- const actionKey = `modify:${filePath}`;
769
- if (!activeActions.has(actionKey)) {
770
- activeActions.add(actionKey);
771
- spinner.stop();
772
- ui_1.ui.fileModify(filePath);
773
- spinner.start();
761
+ spinner = (0, ui_1.createSpinner)("Thinking...").start();
762
+ if (retryCount > 0) {
763
+ spinner.setPrefix(`Retrying... (${retryCount}/3)`);
774
764
  }
775
- spinner.setPrefix(`Modifying ${filePath}...`);
765
+ let thisAttemptText = "";
766
+ const attemptResult = await (0, api_1.refactorCodeApi)(requestPayloadFileName, requestPayloadCode, retryPrompt, retryHistory, currentModel, activeSkillsData, (0, config_1.getThinkingLevel)(), (chunk) => {
767
+ thisAttemptText += chunk;
768
+ currentStreamedText = partialText + thisAttemptText;
769
+ // Find the last opened tag that hasn't been closed yet
770
+ const createMatch = currentStreamedText.match(/<FILE_CREATE\s+path="([^"]+)"[^>]*>(?![\s\S]*<\/FILE_CREATE>)/);
771
+ const modifyMatch = currentStreamedText.match(/<FILE_MODIFY\s+path="([^"]+)"[^>]*>(?![\s\S]*<\/FILE_MODIFY>)/);
772
+ const deleteMatch = currentStreamedText.match(/<FILE_DELETE\s+path="([^"]+)"/);
773
+ if (createMatch) {
774
+ const filePath = createMatch[1];
775
+ const actionKey = `create:${filePath}`;
776
+ if (!activeActions.has(actionKey)) {
777
+ activeActions.add(actionKey);
778
+ spinner.stop();
779
+ ui_1.ui.fileCreate(filePath);
780
+ spinner.start();
781
+ }
782
+ spinner.setPrefix(`Creating ${filePath}...`);
783
+ }
784
+ else if (modifyMatch) {
785
+ const filePath = modifyMatch[1];
786
+ const actionKey = `modify:${filePath}`;
787
+ if (!activeActions.has(actionKey)) {
788
+ activeActions.add(actionKey);
789
+ spinner.stop();
790
+ ui_1.ui.fileModify(filePath);
791
+ spinner.start();
792
+ }
793
+ spinner.setPrefix(`Modifying ${filePath}...`);
794
+ }
795
+ else if (deleteMatch) {
796
+ const filePath = deleteMatch[1];
797
+ const actionKey = `delete:${filePath}`;
798
+ if (!activeActions.has(actionKey)) {
799
+ activeActions.add(actionKey);
800
+ spinner.stop();
801
+ ui_1.ui.fileDelete(filePath);
802
+ spinner.start();
803
+ }
804
+ spinner.setPrefix(`Deleting ${filePath}...`);
805
+ }
806
+ else if (currentStreamedText.length > 10) {
807
+ spinner.setPrefix("Analyzing...");
808
+ }
809
+ }, exports.globalAbortController.signal);
810
+ rawResult = partialText + attemptResult;
811
+ success = true;
776
812
  }
777
- else if (deleteMatch) {
778
- const filePath = deleteMatch[1];
779
- const actionKey = `delete:${filePath}`;
780
- if (!activeActions.has(actionKey)) {
781
- activeActions.add(actionKey);
813
+ catch (e) {
814
+ if (e.name === "AbortError" || e.message === "terminated") {
815
+ throw e;
816
+ }
817
+ if (spinner)
782
818
  spinner.stop();
783
- ui_1.ui.fileDelete(filePath);
784
- spinner.start();
819
+ const errStr = e.message || String(e);
820
+ // Only print error code / concise message
821
+ ui_1.ui.error(`API Error: ${errStr}. (Attempt ${retryCount + 1}/3)`);
822
+ retryCount++;
823
+ partialText = currentStreamedText;
824
+ if (retryCount >= 3) {
825
+ throw new Error(`Generálás leállt 3 sikertelen próbálkozás után. (Utolsó hiba: ${errStr})`);
785
826
  }
786
- spinner.setPrefix(`Deleting ${filePath}...`);
787
- }
788
- else if (currentStreamedText.length > 10) {
789
- spinner.setPrefix("Analyzing...");
827
+ await new Promise(r => setTimeout(r, 2000));
790
828
  }
791
- }, exports.globalAbortController.signal);
829
+ }
792
830
  spinner.stop();
793
831
  const { cleanResult, commandsToRun, filesToReadAuto, dirsToListAuto } = await applyFileOperations(rawResult);
794
832
  // --- PARSE CLARIFICATION QUESTIONS ---
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "draftify-cli",
3
- "version": "1.0.33",
3
+ "version": "1.0.35",
4
4
  "description": "Draftify AI CLI tool",
5
5
  "main": "dist/index.js",
6
6
  "bin": {