@wix/ditto-codegen-public 1.0.165 → 1.0.167

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/out.js +191 -91
  2. package/package.json +2 -2
package/dist/out.js CHANGED
@@ -65677,6 +65677,7 @@ var require_ErrorTypes = __commonJS({
65677
65677
  ErrorType2["EXTENSION_GENERATION_ERROR"] = "EXTENSION_GENERATION_ERROR";
65678
65678
  ErrorType2["VALIDATION_CONFIGURATION_ERROR"] = "VALIDATION_CONFIGURATION_ERROR";
65679
65679
  ErrorType2["GENERATE_OBJECT_ERROR"] = "GENERATE_OBJECT_ERROR";
65680
+ ErrorType2["AUTO_FIX_ERROR"] = "AUTO_FIX_ERROR";
65680
65681
  ErrorType2["UNEXPECTED_ERROR"] = "UNEXPECTED_ERROR";
65681
65682
  })(ErrorType || (exports2.ErrorType = ErrorType = {}));
65682
65683
  }
@@ -65691,8 +65692,7 @@ var require_enums2 = __commonJS({
65691
65692
  var ValidationType;
65692
65693
  (function(ValidationType2) {
65693
65694
  ValidationType2["TYPESCRIPT"] = "typescript";
65694
- ValidationType2["JAVASCRIPT"] = "javascript";
65695
- ValidationType2["JSON"] = "json";
65695
+ ValidationType2["BUILD"] = "build";
65696
65696
  })(ValidationType || (exports2.ValidationType = ValidationType = {}));
65697
65697
  var ProcessType;
65698
65698
  (function(ProcessType2) {
@@ -65779,27 +65779,12 @@ var require_CodeValidationError = __commonJS({
65779
65779
  this.expected = true;
65780
65780
  this.retryable = false;
65781
65781
  this.validationType = options.validationType;
65782
- this.file = options.file;
65783
- this.line = options.line;
65784
- this.column = options.column;
65785
- this.errorCode = options.errorCode;
65786
- this.errorMessage = options.errorMessage;
65787
- this.errors = options.errors;
65782
+ this.errors = options.errors || [];
65788
65783
  }
65789
65784
  getAdditionalProperties() {
65790
65785
  const props = {
65791
65786
  validationType: this.validationType
65792
65787
  };
65793
- if (this.file)
65794
- props.file = this.file;
65795
- if (this.line !== void 0)
65796
- props.line = this.line;
65797
- if (this.column !== void 0)
65798
- props.column = this.column;
65799
- if (this.errorCode)
65800
- props.errorCode = this.errorCode;
65801
- if (this.errorMessage)
65802
- props.errorMessage = this.errorMessage;
65803
65788
  if (this.errors && this.errors.length > 0)
65804
65789
  props.errors = this.errors;
65805
65790
  return props;
@@ -66175,6 +66160,35 @@ var require_ValidationConfigurationError = __commonJS({
66175
66160
  }
66176
66161
  });
66177
66162
 
66163
+ // ../codegen-types/dist/errors/AutoFixError.js
66164
+ var require_AutoFixError = __commonJS({
66165
+ "../codegen-types/dist/errors/AutoFixError.js"(exports2) {
66166
+ "use strict";
66167
+ Object.defineProperty(exports2, "__esModule", { value: true });
66168
+ exports2.AutoFixError = void 0;
66169
+ var BaseCodegenError_1 = require_BaseCodegenError();
66170
+ var ErrorTypes_1 = require_ErrorTypes();
66171
+ var AutoFixError = class extends BaseCodegenError_1.BaseCodegenError {
66172
+ constructor(message, options) {
66173
+ super(message);
66174
+ this.name = "AutoFixError";
66175
+ this.errorType = ErrorTypes_1.ErrorType.AUTO_FIX_ERROR;
66176
+ this.expected = false;
66177
+ this.retryable = true;
66178
+ this.validationType = options?.validationType;
66179
+ this.cause = options?.cause;
66180
+ }
66181
+ getAdditionalProperties() {
66182
+ return {
66183
+ validationType: this.validationType,
66184
+ cause: this.cause
66185
+ };
66186
+ }
66187
+ };
66188
+ exports2.AutoFixError = AutoFixError;
66189
+ }
66190
+ });
66191
+
66178
66192
  // ../codegen-types/dist/errors/UnexpectedError.js
66179
66193
  var require_UnexpectedError = __commonJS({
66180
66194
  "../codegen-types/dist/errors/UnexpectedError.js"(exports2) {
@@ -66352,6 +66366,7 @@ var require_errors = __commonJS({
66352
66366
  __exportStar2(require_PlanningError(), exports2);
66353
66367
  __exportStar2(require_ExtensionGenerationError(), exports2);
66354
66368
  __exportStar2(require_ValidationConfigurationError(), exports2);
66369
+ __exportStar2(require_AutoFixError(), exports2);
66355
66370
  __exportStar2(require_UnexpectedError(), exports2);
66356
66371
  __exportStar2(require_TimeoutError(), exports2);
66357
66372
  __exportStar2(require_GenerateCodegenObjectError(), exports2);
@@ -114519,12 +114534,27 @@ Given the full chat history, current user request, and all project files:
114519
114534
  * You want to check their configuration
114520
114535
  * They are related but don't need modification
114521
114536
  - **DEFAULT TO MODIFYING EXISTING EXTENSIONS** - Always prefer updating existing extensions over creating new ones
114537
+ - **AVOID DUPLICATING THE SAME EXTENSION** - Be careful about creating duplicates:
114538
+ * If "Relevant Existing Extensions" shows an extension that can handle the request, modify it in currentExtensions
114539
+ * Don't create a new extension to do the exact same thing as an existing one
114540
+ * HOWEVER: If the user uses keywords like "new", "create", "add", "another" with an extension type, CREATE it in additionalExtensions
114541
+ - **DETECTING NEW EXTENSION REQUESTS - Look for these KEYWORDS:**
114542
+ * "a new [extension type]" \u2192 CREATE new extension in additionalExtensions
114543
+ * "create a [extension type]" \u2192 CREATE new extension in additionalExtensions
114544
+ * "add a [extension type]" \u2192 CREATE new extension in additionalExtensions
114545
+ * "another [extension type]" \u2192 CREATE new extension in additionalExtensions
114546
+ * If user mentions "new" or "create" or "add" before an extension type, they want a NEW separate one
114547
+ * Even if purpose seems similar to existing, if they say "new/create/add", honor that request
114548
+ - **Examples:**
114549
+ * "add animation duration" + existing dashboard \u2192 modify existing dashboard ONLY
114550
+ * "add animation duration AND a new dashboard" \u2192 modify existing + create NEW dashboard
114551
+ * "add animation duration AND create a dashboard" \u2192 modify existing + create NEW dashboard
114552
+ * "add X, and a new dashboard page to manage Y" \u2192 modify existing (if applicable) + create NEW dashboard (user said "new")
114522
114553
  - **Only create new extensions (additionalExtensions) when:**
114523
- 1. The user EXPLICITLY asks to CREATE/ADD something entirely new
114524
- 2. The functionality does NOT exist in any current extension
114525
- 3. No existing extension can be modified to fulfill the request
114526
- - **If an extension already exists that does similar things, MODIFY IT instead of creating a new one**
114527
- - **When in doubt, use currentExtensions to modify existing code, NOT additionalExtensions**
114554
+ 1. The user EXPLICITLY uses keywords "new", "create", "add", or "another" before an extension type
114555
+ 2. OR: The functionality truly does NOT exist in any current extension
114556
+ - **If an extension already exists AND user doesn't use "new/create/add" keywords, MODIFY IT instead**
114557
+ - **When in doubt about "new" keyword presence, FAVOR CREATING the new extension - missing user intent is worse than creating extra**
114528
114558
 
114529
114559
  **IMPORTANT**: Before deciding on extensions, check if this is a data-only operation (handled by PlannerAgent). See common scenarios below.
114530
114560
 
@@ -114569,12 +114599,21 @@ ${(0, codegen_common_logic_1.getExtensionDecisionMatrix)()}`;
114569
114599
  exports2.iterationAgentCommonUseCasesGuide = iterationAgentCommonUseCasesGuideConst;
114570
114600
  exports2.iterationAgentChatHistoryContext = (0, iterationScenarios_1.getChatHistoryContext)();
114571
114601
  exports2.iterationAgentExtensionSelectionLogic = iterationAgentExtensionSelectionLogicConst;
114572
- var getIterationAgentConstraints = (supportedTypes) => `- **CRITICAL - AVOID CREATING NEW EXTENSIONS**: Only propose additionalExtensions if existing ones CANNOT fulfill the user's request. Review "Relevant Existing Extensions" carefully. If similar functionality exists, MODIFY it instead of creating new.
114602
+ var getIterationAgentConstraints = (supportedTypes) => `- **CRITICAL - AVOID UNNECESSARY DUPLICATION**: Only propose additionalExtensions if existing ones CANNOT fulfill the user's request. Review "Relevant Existing Extensions" carefully. If an existing extension can handle the request, MODIFY it instead of creating new.
114603
+ - **SMART DUPLICATION DETECTION**: When deciding between modifying vs creating:
114604
+ * If user says "add X feature" and an extension exists that handles X \u2192 modify the existing extension in currentExtensions
114605
+ * If user says "add X AND create a new Y" where Y is explicitly requested as NEW \u2192 modify existing for X + create new for Y in additionalExtensions
114606
+ * Same extension TYPE can appear in both currentExtensions and additionalExtensions if they serve DIFFERENT purposes
114607
+ * Example: "add animation field" (existing dashboard) \u2192 modify only
114608
+ * Example: "add animation field AND create new dashboard for analytics" \u2192 modify existing + create new
114573
114609
  - **STRONG DEFAULT**: Assume you should use currentExtensions (modify existing) unless there's a clear reason to create something entirely new
114574
- - **additionalExtensions ONLY WHEN**: The user explicitly asks to "create", "add", or "build" something that doesn't exist at all in the current project
114610
+ - **additionalExtensions WHEN**:
114611
+ 1. The user explicitly asks to "create", "add", or "build" something new (look for keywords like "new", "create", "add")
114612
+ 2. The new functionality serves a DIFFERENT purpose than existing extensions (even if same type)
114613
+ 3. No single existing extension can be modified to fulfill the entire request
114575
114614
  - Be specific about which file paths are relevant for each current extension (all extension types)
114576
114615
  - Consider the full chat history context when making decisions
114577
- - **PRIORITIZE REUSING EXISTING EXTENSIONS** over creating new ones - this is a hard requirement, not a suggestion
114616
+ - **PRIORITIZE REUSING EXISTING EXTENSIONS** over creating new ones when the purpose is the same
114578
114617
  - **SUPPORTED EXTENSION TYPES ONLY**: ${supportedTypes}
114579
114618
  - **IMPORTANT**: The "relatedSpis" field is ONLY for SERVICE_PLUGIN extensions - specify the SPI types
114580
114619
  - The "paths" field is for ALL extension types - specify relevant file paths to modify
@@ -114587,14 +114626,14 @@ ${(0, codegen_common_logic_1.getExtensionDecisionMatrix)()}`;
114587
114626
  * Referenced for information but don't need changes
114588
114627
  * Checked for correctness but remain unchanged
114589
114628
  * This is your DEFAULT choice for most requests unless the user explicitly wants something entirely new
114590
- - **ADDITIONAL EXTENSIONS**: ONLY use when the user explicitly asks to CREATE/ADD entirely new functionality that has no existing equivalent. Do NOT use if you can modify existing extensions.
114629
+ - **ADDITIONAL EXTENSIONS**: Use when user explicitly asks to CREATE/ADD new functionality with a different purpose. CAN be the same type as extensions in currentExtensions if they serve different purposes.
114591
114630
  - For currentExtensions, ensure relevantUserRequest precisely reflects the change to be applied in those files (e.g., "Update static fee from 5 ILS to 10 ILS"), not a generic description
114592
114631
  - For additionalExtensions, ensure relevantUserRequest describes the new functionality being created (e.g., "Add new 10 ILS static fee calculator")
114593
- - **KEY RULE - MODIFICATION FIRST**: Default to currentExtensions (modify existing). Only use additionalExtensions when the user's request is explicitly to CREATE something that has NO existing equivalent.
114632
+ - **KEY RULE - MODIFICATION FIRST**: Default to currentExtensions (modify existing). Only use additionalExtensions when the user's request explicitly includes creating NEW functionality with a different purpose.
114594
114633
  - **CRITICAL - EXTENSION-SPECIFIC DESCRIPTIONS**: The relevantUserRequest field becomes the extension's description and is passed directly to individual agents. Each agent ONLY sees its own extension - they don't have context about other extensions, the broader user request, or duplicate issues. Focus on WHAT THIS SPECIFIC EXTENSION should do, not WHY or how it relates to other extensions. Do not reference other extensions.`;
114595
114634
  exports2.getIterationAgentConstraints = getIterationAgentConstraints;
114596
114635
  var getIterationAgentKeyPoints = (supportedTypes) => `- currentExtensions: Existing extensions that need to be MODIFIED (use extensionType from: ${supportedTypes}) - **THIS IS YOUR DEFAULT CHOICE**
114597
- - additionalExtensions: New extensions that need to be CREATED (use extensionType from: ${supportedTypes}) - **ONLY USE IF USER EXPLICITLY ASKS TO CREATE SOMETHING NEW**
114636
+ - additionalExtensions: New extensions that need to be CREATED (use extensionType from: ${supportedTypes}) - **USE WHEN USER EXPLICITLY ASKS TO CREATE SOMETHING NEW WITH A DIFFERENT PURPOSE**
114598
114637
  - summary: Brief summary combining the chat history and current user request
114599
114638
  - "name" field: REQUIRED for ALL extensions - provide a descriptive name for the extension
114600
114639
  - "relatedSpis" field: ONLY for SERVICE_PLUGIN extensions - specify the SPI name
@@ -153263,9 +153302,10 @@ var require_TypescriptValidator = __commonJS({
153263
153302
  "use strict";
153264
153303
  Object.defineProperty(exports2, "__esModule", { value: true });
153265
153304
  var child_process_1 = require("child_process");
153305
+ var ditto_codegen_types_12 = require_dist();
153266
153306
  var TypescriptValidator = class {
153267
153307
  constructor() {
153268
- this.type = "typescript";
153308
+ this.type = ditto_codegen_types_12.ValidationType.TYPESCRIPT;
153269
153309
  }
153270
153310
  async validate(projectDir) {
153271
153311
  const result = this.runTypecheck(projectDir);
@@ -153301,7 +153341,7 @@ var require_TypescriptValidator = __commonJS({
153301
153341
  }
153302
153342
  async parseTypecheckError(stdout) {
153303
153343
  const lines = stdout.split(/\r?\n/);
153304
- const tsRegex = /^(?<path>.+?)\((?<line>\d+),(?<col>\d+)\):\s*error\s+TS\d+:\s*(?<msg>.+)$/;
153344
+ const tsRegex = /^(?<path>.+?)\((?<line>\d+),(?<col>\d+)\):\s*error\s+(?<code>TS\d+):\s*(?<msg>.+)$/;
153305
153345
  const results = [];
153306
153346
  for (const line of lines) {
153307
153347
  const m = line.match(tsRegex);
@@ -153310,6 +153350,7 @@ var require_TypescriptValidator = __commonJS({
153310
153350
  filePath: m.groups["path"],
153311
153351
  line: Number(m.groups["line"]),
153312
153352
  column: Number(m.groups["col"]),
153353
+ errorCode: m.groups["code"],
153313
153354
  errorMessage: m.groups["msg"].trim()
153314
153355
  });
153315
153356
  }
@@ -153334,12 +153375,12 @@ var require_ValidatorFactory = __commonJS({
153334
153375
  var ValidatorFactory = class {
153335
153376
  constructor() {
153336
153377
  }
153337
- getValidator(type = "typescript") {
153338
- if (type === "typescript") {
153378
+ getValidator(type = ditto_codegen_types_12.ValidationType.TYPESCRIPT) {
153379
+ if (type === ditto_codegen_types_12.ValidationType.TYPESCRIPT) {
153339
153380
  return new TypescriptValidator_1.default();
153340
153381
  }
153341
- throw new ditto_codegen_types_12.ValidationConfigurationError(`Invalid validator type: ${type}`, {
153342
- validatorType: type
153382
+ throw new ditto_codegen_types_12.AutoFixError(`Invalid validator type: ${type}`, {
153383
+ validationType: type
153343
153384
  });
153344
153385
  }
153345
153386
  };
@@ -153369,6 +153410,17 @@ var require_NaiveFixerAgent = __commonJS({
153369
153410
  constructor() {
153370
153411
  this.name = "BatchFixAgent";
153371
153412
  }
153413
+ formatErrors(errors) {
153414
+ return errors.map((error, index) => `${index + 1}. Line ${error.line}, Column ${error.column}${error.errorCode ? ` (${error.errorCode})` : ""}: ${error.message}`).join("\n");
153415
+ }
153416
+ formatPreviousErrors(previousErrors) {
153417
+ if (!previousErrors || previousErrors.length === 0) {
153418
+ return "";
153419
+ }
153420
+ return `The following errors persisted after your last fix attempt.
153421
+ Please try a DIFFERENT approach to solve them:
153422
+ ${previousErrors.map((err) => `- ${err}`).join("\n")}`;
153423
+ }
153372
153424
  async fixFileWithMultipleErrors(input) {
153373
153425
  const systemPrompt = (0, dedent_1.default)`You are an expert TypeScript/JavaScript developer. Your task is to fix ALL compilation errors in a file by providing the complete corrected file content.
153374
153426
 
@@ -153387,7 +153439,8 @@ Focus on common TypeScript errors:
153387
153439
  - Syntax errors
153388
153440
  - Missing semicolons or brackets
153389
153441
  - Incorrect component props`;
153390
- const errorsList = input.errors.map((error, index) => `${index + 1}. Line ${error.line}, Column ${error.column}: ${error.message}`).join("\n");
153442
+ const errorsList = this.formatErrors(input.errors);
153443
+ const previousErrorsSection = this.formatPreviousErrors(input.previousErrors);
153391
153444
  const userMessage = `File: ${input.filePath}
153392
153445
  Language: ${input.language}
153393
153446
 
@@ -153397,6 +153450,8 @@ ${errorsList}
153397
153450
  CURRENT FILE CONTENT:
153398
153451
  ${input.content}
153399
153452
 
153453
+ ${previousErrorsSection}
153454
+
153400
153455
  Please provide the complete fixed file content that resolves ALL the errors listed above.`;
153401
153456
  try {
153402
153457
  const result = await codeGenerationService_12.codegenAIProxyService.generateCodegenObject({
@@ -153443,7 +153498,7 @@ var require_NaiveErrorFixer = __commonJS({
153443
153498
  var NaiveErrorFixer = class {
153444
153499
  constructor() {
153445
153500
  }
153446
- async fixMultipleErrors(projectDir, filePath, errors) {
153501
+ async fixMultipleErrors(projectDir, filePath, errors, previousErrors) {
153447
153502
  if (errors.length === 0) {
153448
153503
  return;
153449
153504
  }
@@ -153461,9 +153516,11 @@ var require_NaiveErrorFixer = __commonJS({
153461
153516
  errors: errors.map((error) => ({
153462
153517
  line: error.line || 1,
153463
153518
  column: error.column || 1,
153519
+ errorCode: error.errorCode,
153464
153520
  message: error.errorMessage || "Unknown error"
153465
153521
  })),
153466
- language: "typescript"
153522
+ language: "typescript",
153523
+ previousErrors: previousErrors?.map(formatErrorToString)
153467
153524
  });
153468
153525
  if (batchResult.fixedContent) {
153469
153526
  fs_1.default.writeFileSync(absolutePath, batchResult.fixedContent, "utf8");
@@ -153481,6 +153538,9 @@ var require_NaiveErrorFixer = __commonJS({
153481
153538
  }
153482
153539
  };
153483
153540
  exports2.default = NaiveErrorFixer;
153541
+ var formatErrorToString = (err) => {
153542
+ return `Line ${err.line}${err.errorCode ? ` (${err.errorCode})` : ""}: ${err.errorMessage}`;
153543
+ };
153484
153544
  }
153485
153545
  });
153486
153546
 
@@ -153523,66 +153583,106 @@ var require_fixFlow = __commonJS({
153523
153583
  var ValidatorFactory_1 = __importDefault2(require_ValidatorFactory());
153524
153584
  var FixerFactory_1 = __importDefault2(require_FixerFactory());
153525
153585
  var ditto_codegen_types_12 = require_dist();
153586
+ var job_context_storage_12 = require_job_context_storage();
153587
+ var codeGenerationService_12 = require_codeGenerationService();
153526
153588
  var MAX_ERRORS_PER_BATCH = 20;
153527
- async function startFixFlow(request, eventEmitter) {
153589
+ async function startFixFlow(request) {
153528
153590
  const { projectDir } = request;
153529
- eventEmitter.emitEvent("validation:start", { outputPath: projectDir });
153530
153591
  const fixerFactory = new FixerFactory_1.default();
153531
153592
  const validatorFactory = new ValidatorFactory_1.default();
153532
153593
  const validator = validatorFactory.getValidator();
153533
- console.log("\u{1F50D} Running validation and batch fix...");
153534
- const initialValidation = await validator.validate(projectDir);
153535
- if (initialValidation.status === 0) {
153536
- console.log(`\u2705 ${validator.type} validation passed - no fixes needed`);
153537
- eventEmitter.emitEvent("validation:done", { outputPath: projectDir });
153538
- return;
153539
- }
153540
- if (!initialValidation.parsedValidationErrors || initialValidation.parsedValidationErrors.length === 0) {
153541
- const errorMessage2 = `Validation failed but no parsed errors available. Raw errors: ${initialValidation.validationErrors}`;
153542
- console.warn(`\u26A0\uFE0F ${errorMessage2}`);
153543
- const error2 = new ditto_codegen_types_12.ValidationConfigurationError(errorMessage2);
153544
- throw error2;
153545
- }
153546
- const totalErrors = initialValidation.parsedValidationErrors.length;
153547
- console.log(`\u{1F4DD} Found ${totalErrors} errors to fix`);
153548
- const errorsByFile = (0, utils_1.mapGroupBy)(initialValidation.parsedValidationErrors, (error2) => error2.filePath);
153549
- console.log(`\u{1F4C1} Errors span ${errorsByFile.size} files`);
153550
- let totalFixesApplied = 0;
153551
153594
  const fixer = fixerFactory.getFixer();
153552
- for (const [filePath, fileErrors] of errorsByFile) {
153553
- const errorsToFix = fileErrors.slice(0, MAX_ERRORS_PER_BATCH);
153554
- if (errorsToFix.length < fileErrors.length) {
153555
- console.log(`\u{1F4CB} Processing ${errorsToFix.length}/${fileErrors.length} errors for ${filePath} (batching to prevent AI overload)`);
153556
- } else {
153557
- console.log(`\u{1F4CB} Processing ${errorsToFix.length} errors for ${filePath}`);
153595
+ const MAX_FIX_ATTEMPTS = 3;
153596
+ const parentContext = job_context_storage_12.jobContextStorage.getStore();
153597
+ const fixTaskId = `fix-flow`;
153598
+ const updateFixTask = async (status, payload = {}) => {
153599
+ await codeGenerationService_12.codeGenerationService.updateTask(parentContext.jobId, fixTaskId, status, payload);
153600
+ };
153601
+ await codeGenerationService_12.codeGenerationService.addTask(parentContext.jobId, {
153602
+ id: fixTaskId,
153603
+ kind: "fix_code",
153604
+ name: "Auto-Fixer",
153605
+ status: ditto_codegen_types_12.Status.RUNNING,
153606
+ description: "Running automatic code fixes"
153607
+ });
153608
+ console.log("\u{1F50D} Running validation and batch fix...");
153609
+ const processFiles = async (fileEntries, lastRunErrors) => {
153610
+ for (const [filePath, fileErrors] of fileEntries) {
153611
+ const errorsToFix = fileErrors.slice(0, MAX_ERRORS_PER_BATCH);
153612
+ if (errorsToFix.length < fileErrors.length) {
153613
+ console.log(`\u{1F4CB} Processing ${errorsToFix.length}/${fileErrors.length} errors for ${filePath} (batching to prevent AI overload)`);
153614
+ } else {
153615
+ console.log(`\u{1F4CB} Processing ${errorsToFix.length} errors for ${filePath}`);
153616
+ }
153617
+ const previousErrors = lastRunErrors.get(filePath);
153618
+ try {
153619
+ await fixer.fixMultipleErrors(projectDir, filePath, errorsToFix, previousErrors);
153620
+ console.log(`\u2705 Applied batch fixes for ${filePath}`);
153621
+ } catch (fixError) {
153622
+ console.error(`\u274C Failed to fix errors in ${filePath}: ${fixError instanceof Error ? fixError.message : String(fixError)}`);
153623
+ }
153558
153624
  }
153559
- try {
153560
- await fixer.fixMultipleErrors(projectDir, filePath, errorsToFix);
153561
- totalFixesApplied += errorsToFix.length;
153562
- console.log(`\u2705 Applied batch fixes for ${filePath}`);
153563
- } catch (fixError) {
153564
- console.error(`\u274C Failed to fix errors in ${filePath}: ${fixError instanceof Error ? fixError.message : String(fixError)}`);
153565
- continue;
153625
+ };
153626
+ const fixState = {
153627
+ accumulatedFixes: 0,
153628
+ lastRunErrors: /* @__PURE__ */ new Map()
153629
+ };
153630
+ const handleValidationFailure = async (validation, reason) => {
153631
+ const remainingErrors = validation.parsedValidationErrors?.length || 0;
153632
+ const unfixedValidationErrors = validation.validationErrors || "Unknown validation errors";
153633
+ console.log(`\u{1F4CB} ${remainingErrors} errors remaining after fixes`);
153634
+ const errorMessage = `Validation failed: ${reason}. Fixed ${fixState.accumulatedFixes} errors, but ${remainingErrors} remain:
153635
+ ${unfixedValidationErrors}`;
153636
+ const validationErrors = validation.parsedValidationErrors || [];
153637
+ const error = new ditto_codegen_types_12.CodeValidationError(errorMessage, {
153638
+ validationType: ditto_codegen_types_12.ValidationType.TYPESCRIPT,
153639
+ errors: validationErrors
153640
+ });
153641
+ await updateFixTask(ditto_codegen_types_12.Status.FAILED, { error: errorMessage });
153642
+ throw error;
153643
+ };
153644
+ const ensureParsedErrorsExist = async (validation) => {
153645
+ const hasParsedErrorsToFix = validation.parsedValidationErrors.length > 0;
153646
+ if (!hasParsedErrorsToFix) {
153647
+ const errorMessage = `Validation failed but no parsed errors available. Raw errors: ${validation.validationErrors}`;
153648
+ console.warn(`\u26A0\uFE0F ${errorMessage}`);
153649
+ await updateFixTask(ditto_codegen_types_12.Status.FAILED, { error: errorMessage });
153650
+ throw new Error(errorMessage);
153566
153651
  }
153652
+ };
153653
+ try {
153654
+ for (let attempt = 0; attempt < MAX_FIX_ATTEMPTS; attempt++) {
153655
+ console.log(`\u{1F504} Fix Attempt ${attempt}/${MAX_FIX_ATTEMPTS}`);
153656
+ const currentValidation = await validator.validate(projectDir);
153657
+ if (currentValidation.status === 0) {
153658
+ console.log(`\u2705 ${validator.type} validation passed - no fixes needed`);
153659
+ await updateFixTask(ditto_codegen_types_12.Status.COMPLETED, {
153660
+ description: `Fixed ${fixState.accumulatedFixes} errors.`
153661
+ });
153662
+ return;
153663
+ }
153664
+ if (attempt === MAX_FIX_ATTEMPTS - 1) {
153665
+ await handleValidationFailure(currentValidation, `after ${MAX_FIX_ATTEMPTS} fix attempts`);
153666
+ }
153667
+ await ensureParsedErrorsExist(currentValidation);
153668
+ const totalErrors = currentValidation.parsedValidationErrors.length;
153669
+ console.log(`\u{1F4DD} Found ${totalErrors} errors to fix`);
153670
+ const errorsByFile = (0, utils_1.mapGroupBy)(currentValidation.parsedValidationErrors, (error) => error.filePath);
153671
+ console.log(`\u{1F4C1} Errors span ${errorsByFile.size} files`);
153672
+ await processFiles(Array.from(errorsByFile), fixState.lastRunErrors);
153673
+ fixState.lastRunErrors = errorsByFile;
153674
+ }
153675
+ } catch (error) {
153676
+ const errorMessage = error instanceof Error ? error.message : String(error);
153677
+ const finalError = new ditto_codegen_types_12.AutoFixError(errorMessage, {
153678
+ validationType: validator.type,
153679
+ cause: error
153680
+ });
153681
+ await updateFixTask(ditto_codegen_types_12.Status.FAILED, {
153682
+ error: finalError.message
153683
+ });
153684
+ throw finalError;
153567
153685
  }
153568
- console.log(`\u{1F4CA} Batch fix completed: ${totalFixesApplied} fixes applied across ${errorsByFile.size} files`);
153569
- const finalValidation = await validator.validate(projectDir);
153570
- if (finalValidation.status === 0) {
153571
- console.log(`\u2705 ${validator.type} validation passed after batch fixes`);
153572
- eventEmitter.emitEvent("validation:done", { outputPath: projectDir });
153573
- return;
153574
- }
153575
- const remainingErrors = finalValidation.parsedValidationErrors?.length || 0;
153576
- const unfixedValidationErrors = finalValidation.validationErrors || "Unknown validation errors";
153577
- console.log(`\u{1F4CB} ${remainingErrors} errors remaining after fixes`);
153578
- const errorMessage = `Validation failed after batch fix attempt. Fixed ${totalFixesApplied} errors, but ${remainingErrors} remain:
153579
- ${unfixedValidationErrors}`;
153580
- const validationErrors = finalValidation.parsedValidationErrors || [];
153581
- const error = new ditto_codegen_types_12.CodeValidationError(errorMessage, {
153582
- validationType: ditto_codegen_types_12.ValidationType.TYPESCRIPT,
153583
- errors: validationErrors
153584
- });
153585
- throw error;
153586
153686
  }
153587
153687
  }
153588
153688
  });
@@ -154714,7 +154814,7 @@ var require_orchestrator = __commonJS({
154714
154814
  });
154715
154815
  await (0, fixFlow_1.startFixFlow)({
154716
154816
  projectDir: outputPath
154717
- }, this);
154817
+ });
154718
154818
  const durationMs = Date.now() - start;
154719
154819
  this.emitEvent("finish", { outputPath, durationMs });
154720
154820
  }
@@ -374032,7 +374132,7 @@ var require_IterationOrchestrator = __commonJS({
374032
374132
  });
374033
374133
  await (0, fixFlow_1.startFixFlow)({
374034
374134
  projectDir: outputPath
374035
- }, this);
374135
+ });
374036
374136
  const durationMs = Date.now() - start;
374037
374137
  this.emitEvent("finish:iteration", { outputPath, durationMs });
374038
374138
  return iterationPlan;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/ditto-codegen-public",
3
- "version": "1.0.165",
3
+ "version": "1.0.167",
4
4
  "description": "AI-powered Wix CLI app generator - standalone executable",
5
5
  "scripts": {
6
6
  "build": "node build.mjs",
@@ -24,5 +24,5 @@
24
24
  "@wix/ditto-codegen": "1.0.0",
25
25
  "esbuild": "^0.25.9"
26
26
  },
27
- "falconPackageHash": "0b13a4cd183dcf4fcac15d021bc0c4ff6e6dbc4052a27bf1b9d2c706"
27
+ "falconPackageHash": "8b47048eb36926399b2a9361f1c4cfebf5018b9e262861c92e2ccb73"
28
28
  }