@wix/ditto-codegen-public 1.0.432 → 1.0.434

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 +248 -40
  2. package/package.json +2 -2
package/dist/out.js CHANGED
@@ -11458,7 +11458,19 @@ INSTRUCTIONS:
11458
11458
  function buildIterationPrompt(chatHistory) {
11459
11459
  return buildPrompt(buildIterationBasePrompt(chatHistory));
11460
11460
  }
11461
- function buildRecoveryPrompt(originalPrompt, filesChanged, error) {
11461
+ var INCREMENTAL_WRITE_STRATEGY = `WHY THE PREVIOUS SESSION FAILED:
11462
+ A single tool call tried to produce more content than one turn can stream, so it was cut off
11463
+ and nothing was saved. The same approach will fail again.
11464
+
11465
+ RECOVERY STRATEGY:
11466
+ 1. One file per tool call, ~200 lines or 1,500 words at most.
11467
+ 2. For anything larger, write the first section, then append the rest with follow-up edits,
11468
+ or split it across several files and import them.
11469
+ 3. Prefer many small steps over one big step.`;
11470
+ function buildRecoveryPrompt(originalPrompt, filesChanged, error, failureReason) {
11471
+ const strategy = failureReason === "stall" ? `
11472
+ ${INCREMENTAL_WRITE_STRATEGY}
11473
+ ` : "";
11462
11474
  return buildPrompt(`You are continuing a code generation task that was interrupted due to a session error.
11463
11475
 
11464
11476
  ORIGINAL TASK:
@@ -11469,7 +11481,7 @@ ${(0, prompt_utils_1.formatFilesList)(filesChanged)}
11469
11481
 
11470
11482
  PREVIOUS SESSION ERROR:
11471
11483
  ${error}
11472
-
11484
+ ${strategy}
11473
11485
  INSTRUCTIONS:
11474
11486
  1. Review the files listed above that were already created/modified in the previous session
11475
11487
  2. Continue with any remaining work needed to fulfill the original task
@@ -11511,7 +11523,7 @@ var require_git_conflicts_prompt = __commonJS({
11511
11523
  var prompt_utils_1 = require_prompt_utils();
11512
11524
  function buildGitConflictsPrompt(history) {
11513
11525
  const { currentUserRequest } = (0, prompt_utils_1.extractUserRequestAndFilteredHistory)(history);
11514
- const base = "Fix all Git merge conflicts in the current project. Resolve every conflict marker (<<<<<<<, =======, >>>>>>>) so the code compiles correctly.";
11526
+ const base = "Fix all Git merge conflicts in the current project. Resolve every git conflict marker so the code compiles correctly.";
11515
11527
  const sections = [
11516
11528
  base,
11517
11529
  currentUserRequest ? `Additional context from user: "${currentUserRequest}"` : "",
@@ -13112,6 +13124,59 @@ var require_http_impl3 = __commonJS({
13112
13124
  }
13113
13125
  });
13114
13126
 
13127
+ // ../../node_modules/@wix/ambassador-code-project-orchestrator-v1-code-project/cjs/build/types.impl.js
13128
+ var require_types_impl3 = __commonJS({
13129
+ "../../node_modules/@wix/ambassador-code-project-orchestrator-v1-code-project/cjs/build/types.impl.js"(exports2) {
13130
+ "use strict";
13131
+ Object.defineProperty(exports2, "__esModule", { value: true });
13132
+ exports2.TaskStatus = exports2.SyncStatus = exports2.DeploymentStatus = exports2.ConflictResolutionStrategy = exports2.CodeDeploymentStatus = exports2.CheckpointErrorType = void 0;
13133
+ var CheckpointErrorType;
13134
+ (function(CheckpointErrorType2) {
13135
+ CheckpointErrorType2["CHECKPOINT_ERROR_TYPE_UNKNOWN"] = "CHECKPOINT_ERROR_TYPE_UNKNOWN";
13136
+ CheckpointErrorType2["CHECKPOINT_ERROR_TYPE_USER"] = "CHECKPOINT_ERROR_TYPE_USER";
13137
+ CheckpointErrorType2["CHECKPOINT_ERROR_TYPE_SYSTEM"] = "CHECKPOINT_ERROR_TYPE_SYSTEM";
13138
+ })(CheckpointErrorType || (exports2.CheckpointErrorType = CheckpointErrorType = {}));
13139
+ var CodeDeploymentStatus;
13140
+ (function(CodeDeploymentStatus2) {
13141
+ CodeDeploymentStatus2["CODE_DEPLOYMENT_STATUS_UNKNOWN"] = "CODE_DEPLOYMENT_STATUS_UNKNOWN";
13142
+ CodeDeploymentStatus2["CODE_DEPLOYMENT_STATUS_IN_PROGRESS"] = "CODE_DEPLOYMENT_STATUS_IN_PROGRESS";
13143
+ CodeDeploymentStatus2["CODE_DEPLOYMENT_STATUS_COMPLETED"] = "CODE_DEPLOYMENT_STATUS_COMPLETED";
13144
+ CodeDeploymentStatus2["CODE_DEPLOYMENT_STATUS_FAILED"] = "CODE_DEPLOYMENT_STATUS_FAILED";
13145
+ })(CodeDeploymentStatus || (exports2.CodeDeploymentStatus = CodeDeploymentStatus = {}));
13146
+ var ConflictResolutionStrategy;
13147
+ (function(ConflictResolutionStrategy2) {
13148
+ ConflictResolutionStrategy2["CONFLICT_RESOLUTION_STRATEGY_UNKNOWN"] = "CONFLICT_RESOLUTION_STRATEGY_UNKNOWN";
13149
+ ConflictResolutionStrategy2["OURS"] = "OURS";
13150
+ ConflictResolutionStrategy2["THEIRS"] = "THEIRS";
13151
+ ConflictResolutionStrategy2["AI"] = "AI";
13152
+ })(ConflictResolutionStrategy || (exports2.ConflictResolutionStrategy = ConflictResolutionStrategy = {}));
13153
+ var DeploymentStatus;
13154
+ (function(DeploymentStatus2) {
13155
+ DeploymentStatus2["UNKNOWN"] = "UNKNOWN";
13156
+ DeploymentStatus2["BUILD_IN_PROGRESS"] = "BUILD_IN_PROGRESS";
13157
+ DeploymentStatus2["BUILD_COMPLETED"] = "BUILD_COMPLETED";
13158
+ DeploymentStatus2["BUILD_FAILED"] = "BUILD_FAILED";
13159
+ DeploymentStatus2["ARCHIVED"] = "ARCHIVED";
13160
+ })(DeploymentStatus || (exports2.DeploymentStatus = DeploymentStatus = {}));
13161
+ var SyncStatus;
13162
+ (function(SyncStatus2) {
13163
+ SyncStatus2["SYNC_STATUS_UNKNOWN"] = "SYNC_STATUS_UNKNOWN";
13164
+ SyncStatus2["SYNC_STATUS_IN_SYNC"] = "SYNC_STATUS_IN_SYNC";
13165
+ SyncStatus2["SYNC_STATUS_OUT_OF_SYNC"] = "SYNC_STATUS_OUT_OF_SYNC";
13166
+ })(SyncStatus || (exports2.SyncStatus = SyncStatus = {}));
13167
+ var TaskStatus;
13168
+ (function(TaskStatus2) {
13169
+ TaskStatus2["UNKNOWN_TASK_STATUS"] = "UNKNOWN_TASK_STATUS";
13170
+ TaskStatus2["NOT_STARTED"] = "NOT_STARTED";
13171
+ TaskStatus2["RUNNING"] = "RUNNING";
13172
+ TaskStatus2["COMPLETED"] = "COMPLETED";
13173
+ TaskStatus2["FAILED"] = "FAILED";
13174
+ TaskStatus2["CANCELLED"] = "CANCELLED";
13175
+ TaskStatus2["NOT_EXECUTED"] = "NOT_EXECUTED";
13176
+ })(TaskStatus || (exports2.TaskStatus = TaskStatus = {}));
13177
+ }
13178
+ });
13179
+
13115
13180
  // ../codegen-checkpoint-plugin/dist/checkpoint.js
13116
13181
  var require_checkpoint = __commonJS({
13117
13182
  "../codegen-checkpoint-plugin/dist/checkpoint.js"(exports2) {
@@ -13122,6 +13187,7 @@ var require_checkpoint = __commonJS({
13122
13187
  var path_1 = require("path");
13123
13188
  var http_1 = require_http_impl2();
13124
13189
  var http_2 = require_http_impl3();
13190
+ var types_1 = require_types_impl3();
13125
13191
  var http_client_1 = require_index_node();
13126
13192
  var FALLBACK_COMMIT_MESSAGE = "Auto-save";
13127
13193
  var EML_MARKER = "generate-eml.ts";
@@ -13154,7 +13220,24 @@ var require_checkpoint = __commonJS({
13154
13220
  return message;
13155
13221
  return message.slice(0, MAX_COMMIT_MESSAGE_LENGTH - TRUNCATION_SUFFIX.length) + TRUNCATION_SUFFIX;
13156
13222
  };
13223
+ var CHECKPOINT_CONFLICT_CODE = "CHECKPOINT_CONFLICT";
13157
13224
  var useCodeProjectOrchestrator = () => process.env.USE_CODE_PROJECT_ORCHESTRATOR === "true";
13225
+ var collaboratorLiveSyncEnabled = () => process.env.STUDIO2_COLLABORATOR_LIVE_SYNC === "true";
13226
+ var readApplicationErrorCode = (error) => {
13227
+ if (!http_client_1.HttpClient.isHttpError(error))
13228
+ return void 0;
13229
+ const data = error.response?.data;
13230
+ const code = data?.details?.applicationError?.code;
13231
+ return typeof code === "string" ? code : void 0;
13232
+ };
13233
+ var isCheckpointConflict = (error) => readApplicationErrorCode(error) === CHECKPOINT_CONFLICT_CODE;
13234
+ var readConflictedFiles = (error) => {
13235
+ if (!http_client_1.HttpClient.isHttpError(error))
13236
+ return [];
13237
+ const data = error.response?.data;
13238
+ const files = data?.details?.applicationError?.data?.files;
13239
+ return Array.isArray(files) ? files.filter((file) => typeof file === "string") : [];
13240
+ };
13158
13241
  var wasAuthorizationHeaderSent = (requestHeaders) => {
13159
13242
  if (typeof requestHeaders !== "object" || requestHeaders === null)
13160
13243
  return false;
@@ -13201,6 +13284,13 @@ var require_checkpoint = __commonJS({
13201
13284
  commitHash: resp.data?.checkpointId
13202
13285
  };
13203
13286
  };
13287
+ var callResolveCheckpointConflict = async (client, siteBranchId) => {
13288
+ const resp = await client.request((0, http_2.resolveCheckpointConflict)({
13289
+ siteBranchId,
13290
+ strategy: types_1.ConflictResolutionStrategy.AI
13291
+ }));
13292
+ return resp.data?.jobId ?? void 0;
13293
+ };
13204
13294
  var readToolCommitMessage = (input) => {
13205
13295
  if (typeof input !== "object" || input === null)
13206
13296
  return void 0;
@@ -13245,6 +13335,45 @@ var require_checkpoint = __commonJS({
13245
13335
  commitMessage
13246
13336
  });
13247
13337
  } catch (error) {
13338
+ if (useCodeProjectOrchestrator() && collaboratorLiveSyncEnabled() && job.siteBranchId && isCheckpointConflict(error)) {
13339
+ const files = readConflictedFiles(error);
13340
+ try {
13341
+ const conflictResolutionJobId = await callResolveCheckpointConflict(orchestratorHttpClient, job.siteBranchId);
13342
+ if (!conflictResolutionJobId) {
13343
+ throw new Error("resolveCheckpointConflict returned no conflict resolution job id");
13344
+ }
13345
+ outcome = {
13346
+ status: "resolvingGitConflicts",
13347
+ conflictResolutionJobId,
13348
+ conflictedFiles: files
13349
+ };
13350
+ await host.jobs.updatePayload({ jobId: job.jobId, taskId: job.taskId }, {
13351
+ checkpointStatus: "resolvingGitConflicts",
13352
+ conflictResolutionJobId,
13353
+ conflictedFiles: files
13354
+ }).catch((payloadError) => {
13355
+ host.logger.warn("[Checkpoint] failed to publish the resolving-conflicts state", {
13356
+ projectId: job.projectId,
13357
+ conflictResolutionJobId,
13358
+ error: payloadError instanceof Error ? payloadError.message : String(payloadError)
13359
+ });
13360
+ });
13361
+ host.logger.info("[Checkpoint] git conflicts handed to AI resolution", {
13362
+ projectId: job.projectId,
13363
+ siteBranchId: job.siteBranchId,
13364
+ conflictResolutionJobId,
13365
+ files
13366
+ });
13367
+ return;
13368
+ } catch (resolveError) {
13369
+ host.logger.error("[Checkpoint] git conflict resolution dispatch failed", {
13370
+ projectId: job.projectId,
13371
+ siteBranchId: job.siteBranchId,
13372
+ files,
13373
+ error: resolveError instanceof Error ? resolveError.message : String(resolveError)
13374
+ });
13375
+ }
13376
+ }
13248
13377
  outcome = { status: "failed", error };
13249
13378
  host.logger.error("[Checkpoint] create failed", {
13250
13379
  projectId: job.projectId,
@@ -13290,6 +13419,8 @@ var require_checkpoint = __commonJS({
13290
13419
  throw outcome.error;
13291
13420
  if (outcome?.status === "created")
13292
13421
  return;
13422
+ if (outcome?.status === "resolvingGitConflicts")
13423
+ return;
13293
13424
  if (codegenFailed)
13294
13425
  return;
13295
13426
  const commitMessage = capturedCommitMessage ?? FALLBACK_COMMIT_MESSAGE;
@@ -15136,9 +15267,9 @@ UNDERSTAND INTENT FIRST:
15136
15267
  - When the change is non-trivial, inspect recent history to learn what the incoming branch refactored: \`git log -p -n 3 -- <file>\` and \`git diff\` are READ-ONLY and safe. NEVER run \`git merge\`, \`git rebase\`, \`git checkout\`, \`git reset\`, \`git add\`, or \`git commit\` \u2014 only the agent's edit tools change files; git state is managed by the host.
15137
15268
 
15138
15269
  CONFLICT RESOLUTION STRATEGY:
15139
- - Identify all files containing conflict markers: <<<<<<<, =======, >>>>>>>
15140
- - The HEAD (OURS) section (between <<<<<<< and =======) represents the current branch's changes \u2014 preserve this code.
15141
- - The incoming (THEIRS) section (between ======= and >>>>>>>) represents the changes being merged in.
15270
+ - Identify all files containing git conflict markers.
15271
+ - The HEAD (OURS) section \u2014 the first side of the conflict \u2014 represents the current branch's changes; preserve this code.
15272
+ - The incoming (THEIRS) section \u2014 the second side \u2014 represents the changes being merged in.
15142
15273
  - Resolve each conflict by merging both sides logically \u2014 judge by SEMANTIC meaning, not line-by-line text:
15143
15274
  - If both sides add independent, non-overlapping code \u2014 include both.
15144
15275
  - If they modify the same logic \u2014 prefer HEAD (OURS) and incorporate non-conflicting parts from THEIRS.
@@ -15161,7 +15292,7 @@ ${(0, shared_rules_1.buildFileOperationsRules)("resolving conflicts")}
15161
15292
  - NEVER run preview, dev, release, or promote commands.
15162
15293
 
15163
15294
  WORKFLOW:
15164
- 1. **Find**: Use \`grep\` to locate all files containing "<<<<<<<".
15295
+ 1. **Find**: Use \`grep\` to locate every file containing git conflict markers, searching the whole project \u2014 any files named in the request are only a hint.
15165
15296
  2. **Resolve**: Read (\`batch-read\`) and fix all conflicts using \`multi-edit\`. Do NOT add new logic \u2014 only remove markers and merge the two sides.
15166
15297
  3. **Verify markers**: Run \`grep\` again to confirm zero conflict markers remain.
15167
15298
  4. **Validate**: Run \`validate\` (typecheck only). Fix any errors and re-validate until tsc passes, then run \`validate({ runBuild: true })\` ONCE to confirm the resolution did not break the build. Pass \`installDeps: true\` ONLY when \`package.json\` changed without already running \`npm install <package-name>\` in this iteration; otherwise omit it (node_modules is pre-installed).
@@ -16517,13 +16648,14 @@ var require_process_manager = __commonJS({
16517
16648
  "dist/opencode-integration/process-manager.js"(exports2) {
16518
16649
  "use strict";
16519
16650
  Object.defineProperty(exports2, "__esModule", { value: true });
16520
- exports2.KILL_GRACE_PERIOD_MS = exports2.IDLE_CHECK_INTERVAL_MS = exports2.IDLE_TIMEOUT_MS = void 0;
16651
+ exports2.MAX_STARTS_WITHOUT_FINISH = exports2.KILL_GRACE_PERIOD_MS = exports2.IDLE_CHECK_INTERVAL_MS = exports2.IDLE_TIMEOUT_MS = void 0;
16521
16652
  exports2.clearTimers = clearTimers;
16522
16653
  exports2.killProcess = killProcess;
16523
16654
  var logger_12 = require_logger();
16524
16655
  exports2.IDLE_TIMEOUT_MS = 6e5;
16525
16656
  exports2.IDLE_CHECK_INTERVAL_MS = 15e3;
16526
16657
  exports2.KILL_GRACE_PERIOD_MS = 5e3;
16658
+ exports2.MAX_STARTS_WITHOUT_FINISH = 3;
16527
16659
  function clearTimers(timers) {
16528
16660
  if (timers.timeoutId) {
16529
16661
  clearTimeout(timers.timeoutId);
@@ -16570,24 +16702,13 @@ var require_result_builder = __commonJS({
16570
16702
  Object.defineProperty(exports2, "__esModule", { value: true });
16571
16703
  exports2.createTimeoutResult = createTimeoutResult;
16572
16704
  exports2.createSuccessResult = createSuccessResult;
16705
+ exports2.createFailedResult = createFailedResult;
16573
16706
  exports2.createSpawnErrorResult = createSpawnErrorResult;
16574
16707
  var ditto_codegen_types_12 = require_dist4();
16575
16708
  var tool_usage_1 = require_tool_usage();
16576
16709
  var parser_1 = require_parser();
16577
16710
  function createTimeoutResult(message, stdout, stderr, startTime) {
16578
- return {
16579
- success: false,
16580
- exitCode: null,
16581
- stdout,
16582
- stderr,
16583
- agentMessage: (0, parser_1.parseAnswerText)(stdout),
16584
- error: new ditto_codegen_types_12.TimeoutError(message),
16585
- durationMs: Date.now() - startTime,
16586
- requiredPermissions: [],
16587
- usage: (0, parser_1.parseUsageStats)(stdout),
16588
- skillsUsed: [],
16589
- toolUsage: (0, tool_usage_1.emptyToolUsage)()
16590
- };
16711
+ return createFailedResult(new ditto_codegen_types_12.TimeoutError(message), stdout, stderr, startTime);
16591
16712
  }
16592
16713
  function createSuccessResult(code, stdout, stderr, startTime) {
16593
16714
  return {
@@ -16608,6 +16729,21 @@ var require_result_builder = __commonJS({
16608
16729
  toolUsage: (0, tool_usage_1.emptyToolUsage)()
16609
16730
  };
16610
16731
  }
16732
+ function createFailedResult(error, stdout, stderr, startTime) {
16733
+ return {
16734
+ success: false,
16735
+ exitCode: null,
16736
+ stdout,
16737
+ stderr,
16738
+ agentMessage: (0, parser_1.parseAnswerText)(stdout),
16739
+ error,
16740
+ durationMs: Date.now() - startTime,
16741
+ requiredPermissions: [],
16742
+ usage: (0, parser_1.parseUsageStats)(stdout),
16743
+ skillsUsed: [],
16744
+ toolUsage: (0, tool_usage_1.emptyToolUsage)()
16745
+ };
16746
+ }
16611
16747
  function createSpawnErrorResult(errorMessage, stdout, stderr, startTime) {
16612
16748
  return {
16613
16749
  success: false,
@@ -16636,12 +16772,14 @@ var require_process_handlers = __commonJS({
16636
16772
  Object.defineProperty(exports2, "__esModule", { value: true });
16637
16773
  exports2.setupTotalTimeout = setupTotalTimeout;
16638
16774
  exports2.setupIdleWatchdog = setupIdleWatchdog;
16775
+ exports2.trackTurnProgress = trackTurnProgress;
16639
16776
  exports2.setupStdoutHandler = setupStdoutHandler;
16640
16777
  exports2.setupStderrHandler = setupStderrHandler;
16641
16778
  exports2.setupCloseHandler = setupCloseHandler;
16642
16779
  exports2.setupErrorHandler = setupErrorHandler;
16643
16780
  var parser_1 = require_parser();
16644
16781
  var config_12 = require_config();
16782
+ var ditto_codegen_types_12 = require_dist4();
16645
16783
  var process_manager_1 = require_process_manager();
16646
16784
  var result_builder_1 = require_result_builder();
16647
16785
  var logger_12 = require_logger();
@@ -16666,6 +16804,49 @@ var require_process_handlers = __commonJS({
16666
16804
  }
16667
16805
  }, process_manager_1.IDLE_CHECK_INTERVAL_MS);
16668
16806
  }
16807
+ function trackTurnProgress(state, event) {
16808
+ if (event.type === "step_finish") {
16809
+ state.startsWithoutFinish = 0;
16810
+ return;
16811
+ }
16812
+ if (event.type !== "step_start")
16813
+ return;
16814
+ state.startsWithoutFinish += 1;
16815
+ if (state.startsWithoutFinish < process_manager_1.MAX_STARTS_WITHOUT_FINISH)
16816
+ return;
16817
+ throw new ditto_codegen_types_12.TimeoutError(`Process stalled - ${process_manager_1.MAX_STARTS_WITHOUT_FINISH} turns started without completing`);
16818
+ }
16819
+ function handleStdoutLine(ctx, line, trackProgress) {
16820
+ ctx.taskTracker.processLine(line);
16821
+ if (!line.trim())
16822
+ return null;
16823
+ let event = null;
16824
+ try {
16825
+ event = JSON.parse(line);
16826
+ logger_12.logger.debug("[OpenCode] stdout", (0, parser_1.summarizeOpenCodeLine)(event));
16827
+ } catch {
16828
+ logger_12.logger.debug("[OpenCode] stdout", { line: line.slice(0, 200) });
16829
+ }
16830
+ if (!event || !trackProgress)
16831
+ return null;
16832
+ try {
16833
+ trackTurnProgress(ctx.state, event);
16834
+ return null;
16835
+ } catch (error) {
16836
+ return error instanceof ditto_codegen_types_12.TimeoutError ? error : new ditto_codegen_types_12.TimeoutError(String(error));
16837
+ }
16838
+ }
16839
+ function failStalledRun(ctx, stall) {
16840
+ logger_12.logger.warn("[OpenCode] Killing stalled process", {
16841
+ error: stall.message,
16842
+ startsWithoutFinish: ctx.state.startsWithoutFinish
16843
+ });
16844
+ (0, process_manager_1.killProcess)(ctx.child, ctx.state.resolved);
16845
+ ctx.finalize({
16846
+ ...(0, result_builder_1.createFailedResult)(stall, ctx.state.stdout, ctx.state.stderr, ctx.startTime),
16847
+ stalled: true
16848
+ });
16849
+ }
16669
16850
  function setupStdoutHandler(ctx, onStdout) {
16670
16851
  ctx.child?.stdout?.on("data", (data) => {
16671
16852
  const text = data.toString();
@@ -16674,21 +16855,18 @@ var require_process_handlers = __commonJS({
16674
16855
  ctx.state.lineBuffer += text;
16675
16856
  const lines = ctx.state.lineBuffer.split("\n");
16676
16857
  ctx.state.lineBuffer = lines.pop() || "";
16858
+ let stall = null;
16677
16859
  for (const line of lines) {
16678
- ctx.taskTracker.processLine(line);
16679
- if (line.trim()) {
16680
- try {
16681
- logger_12.logger.debug("[OpenCode] stdout", (0, parser_1.summarizeOpenCodeLine)(JSON.parse(line)));
16682
- } catch {
16683
- logger_12.logger.debug("[OpenCode] stdout", { line: line.slice(0, 200) });
16684
- }
16685
- }
16860
+ const found = handleStdoutLine(ctx, line, !stall && !ctx.state.resolved);
16861
+ stall ??= found;
16686
16862
  }
16687
16863
  if (onStdout) {
16688
16864
  onStdout(text);
16689
16865
  } else {
16690
16866
  process.stdout.write(text);
16691
16867
  }
16868
+ if (stall && !ctx.state.resolved)
16869
+ failStalledRun(ctx, stall);
16692
16870
  });
16693
16871
  }
16694
16872
  function setupStderrHandler(ctx, onStderr) {
@@ -16725,6 +16903,7 @@ var require_executor = __commonJS({
16725
16903
  "use strict";
16726
16904
  Object.defineProperty(exports2, "__esModule", { value: true });
16727
16905
  exports2.notifyValidatorOutputsToSlack = notifyValidatorOutputsToSlack;
16906
+ exports2.classifyAttempt = classifyAttempt;
16728
16907
  exports2.executeOpenCode = executeOpenCode;
16729
16908
  exports2.resolveFinalRunCost = resolveFinalRunCost;
16730
16909
  var child_process_1 = require("child_process");
@@ -16742,6 +16921,7 @@ var require_executor = __commonJS({
16742
16921
  var process_handlers_1 = require_process_handlers();
16743
16922
  var logger_12 = require_logger();
16744
16923
  var MAX_RETRIES = 5;
16924
+ var MAX_STALL_ATTEMPTS = 2;
16745
16925
  async function notifyValidatorOutputsToSlack(stdout, costUsd) {
16746
16926
  try {
16747
16927
  const store = job_context_storage_12.jobContextStorage.getStore();
@@ -16773,12 +16953,33 @@ var require_executor = __commonJS({
16773
16953
  });
16774
16954
  }
16775
16955
  }
16956
+ function failureReason(result) {
16957
+ if (result.stalled)
16958
+ return "stall";
16959
+ if ((0, parser_1.hasSessionError)(result.stdout))
16960
+ return "session error";
16961
+ if (result.error instanceof ditto_codegen_types_12.ProcessExecutionError) {
16962
+ return "process execution error";
16963
+ }
16964
+ if (!result.success && result.error instanceof ditto_codegen_types_12.TimeoutError) {
16965
+ return "timeout";
16966
+ }
16967
+ return null;
16968
+ }
16969
+ function classifyAttempt(result, stalls) {
16970
+ const reason = failureReason(result);
16971
+ if (!reason)
16972
+ return { retryable: false, reason: null };
16973
+ return { retryable: stalls < MAX_STALL_ATTEMPTS, reason };
16974
+ }
16776
16975
  async function executeOpenCode(options) {
16777
16976
  let lastResult = null;
16778
16977
  let accumulatedUsage = (0, parser_1.createEmptyUsageStats)();
16779
16978
  const accumulatedSkills = [];
16780
16979
  const toolUsage = new tool_usage_1.ToolUsageCollector();
16781
16980
  let currentPrompt = options.prompt;
16981
+ let lastFailureReason = null;
16982
+ let stalls = 0;
16782
16983
  let continueSession = options.continueSession ?? false;
16783
16984
  const env = (0, config_12.getOpenCodeEnv)(options.projectId, job_context_storage_12.jobContextStorage.getStore()?.kind);
16784
16985
  const statsBaseline = await (0, cost_tracker_1.fetchOpenCodeStats)(options.outputPath, env);
@@ -16786,20 +16987,25 @@ var require_executor = __commonJS({
16786
16987
  logger_12.logger.debug("[OpenCode] Stats baseline before run", { baselineCost });
16787
16988
  for (let attempt = 1; attempt <= MAX_RETRIES; attempt++) {
16788
16989
  if (attempt > 1) {
16789
- logger_12.logger.info(`[OpenCode] Retry attempt ${attempt}/${MAX_RETRIES} - starting fresh session with recovery context`);
16990
+ const failureDetail = lastResult?.error?.message || lastResult?.stderr || "Process timed out";
16991
+ logger_12.logger.info(`[OpenCode] Retry attempt ${attempt}/${MAX_RETRIES} after ${lastFailureReason} - starting fresh session with recovery context`, { reason: lastFailureReason, detail: failureDetail.slice(0, 500) });
16790
16992
  const filesChanged = await (0, git_file_changes_1.collectGitFileChanges)(options.outputPath, options.gitBaseline);
16791
- currentPrompt = (0, prompts_1.buildRecoveryPrompt)(options.prompt, filesChanged, lastResult?.error?.message || lastResult?.stderr || "Process timed out");
16993
+ currentPrompt = (0, prompts_1.buildRecoveryPrompt)(options.prompt, filesChanged, failureDetail, lastFailureReason);
16792
16994
  continueSession = false;
16793
16995
  }
16794
16996
  const result = await executeOpenCodeOnce({ ...options, prompt: currentPrompt, continueSession }, attempt, toolUsage);
16795
16997
  accumulatedUsage = (0, parser_1.mergeUsageStats)(accumulatedUsage, result.usage);
16796
16998
  accumulatedSkills.push(...result.skillsUsed);
16797
- const errorMsg = result.error?.message.toLowerCase() ?? "";
16798
- const isIdleTimeout = !result.success && errorMsg.includes("idle timeout");
16799
- const isSessionError = (0, parser_1.hasSessionError)(result.stdout);
16800
- const isProcessError = result.error instanceof ditto_codegen_types_12.ProcessExecutionError;
16801
- const isRetryableFailure = isIdleTimeout || isSessionError || isProcessError;
16802
- if (!isRetryableFailure) {
16999
+ if (result.stalled)
17000
+ stalls += 1;
17001
+ const { retryable, reason } = classifyAttempt(result, stalls);
17002
+ if (!retryable) {
17003
+ if (reason) {
17004
+ logger_12.logger.warn(`[OpenCode] Not retrying after ${reason}`, {
17005
+ attempt,
17006
+ stalls
17007
+ });
17008
+ }
16803
17009
  accumulatedUsage = await resolveFinalRunCost(accumulatedUsage, options, baselineCost);
16804
17010
  const finalResult2 = {
16805
17011
  ...result,
@@ -16812,10 +17018,11 @@ var require_executor = __commonJS({
16812
17018
  return finalResult2;
16813
17019
  }
16814
17020
  lastResult = result;
16815
- const reason = isSessionError ? "session error" : isProcessError ? "process execution error" : "idle timeout";
17021
+ lastFailureReason = reason;
16816
17022
  logger_12.logger.warn(`[OpenCode] Attempt failed due to ${reason}, will retry`, {
16817
17023
  attempt,
16818
- maxRetries: MAX_RETRIES
17024
+ maxRetries: MAX_RETRIES,
17025
+ detail: (result.error?.message || result.stderr || "").slice(0, 500)
16819
17026
  });
16820
17027
  }
16821
17028
  logger_12.logger.warn("[OpenCode] All retry attempts exhausted", {
@@ -16866,7 +17073,8 @@ var require_executor = __commonJS({
16866
17073
  stderr: "",
16867
17074
  lineBuffer: "",
16868
17075
  lastOutputTime: Date.now(),
16869
- resolved: false
17076
+ resolved: false,
17077
+ startsWithoutFinish: 0
16870
17078
  };
16871
17079
  const timers = {
16872
17080
  timeoutId: null,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/ditto-codegen-public",
3
- "version": "1.0.432",
3
+ "version": "1.0.434",
4
4
  "description": "AI-powered Wix CLI app generator - standalone executable",
5
5
  "scripts": {
6
6
  "build": "node build.mjs",
@@ -29,5 +29,5 @@
29
29
  "esbuild": "^0.27.2",
30
30
  "vitest": "^4.0.16"
31
31
  },
32
- "falconPackageHash": "138387ddb94767f45627512cde3a8a5d6dd67ce1200ce29873f584f9"
32
+ "falconPackageHash": "b849b4780b251c081a437506b4ded2164211e1e078b19bd3e61e64b7"
33
33
  }