everydaytok commited on
Commit
9609b4f
·
verified ·
1 Parent(s): 10bad20

Update app.js

Browse files
Files changed (1) hide show
  1. app.js +10 -8
app.js CHANGED
@@ -290,9 +290,7 @@ async function runAsyncFeedback(projectId, userId, fullInput, images = []) {
290
  let finalResponseToSave = firstTurnResponse;
291
 
292
  if (routeTask || pmQuestion) {
293
- // --- CRITICAL FIX: Save the Worker's first turn immediately ---
294
- // This ensures if we crash or reload, the question/delegation is preserved.
295
- // It also fixes the "Amnesia" where the worker forgets it asked a question.
296
  await StateManager.addHistory(projectId, 'worker', 'user', fullInput);
297
  await StateManager.addHistory(projectId, 'worker', 'model', firstTurnResponse);
298
 
@@ -335,12 +333,16 @@ async function runAsyncFeedback(projectId, userId, fullInput, images = []) {
335
  }
336
  );
337
 
338
- diamondUsage += 0; // Adjust if tracking PM usage
339
 
340
  // Save PM History
341
  await StateManager.addHistory(projectId, 'pm', 'user', pmPrompt);
342
  await StateManager.addHistory(projectId, 'pm', 'model', pmResponseText);
343
 
 
 
 
 
344
  // 5. Run Worker Continuation (The "Answer" Phase)
345
  const nextInstruction = extractWorkerPrompt(pmResponseText) || pmResponseText;
346
  const workerContinuationPrompt = `${pmContextPrefix} ${nextInstruction}\n\nBased on this, continue the task and output the code.`;
@@ -351,7 +353,7 @@ async function runAsyncFeedback(projectId, userId, fullInput, images = []) {
351
  let secondTurnResponse = "";
352
 
353
  await AIEngine.callWorkerStream(
354
- currentWorkerHistory, // Uses the updated history including the Question
355
  workerContinuationPrompt,
356
  (thought) => {
357
  stopStatus();
@@ -370,7 +372,7 @@ async function runAsyncFeedback(projectId, userId, fullInput, images = []) {
370
  await StateManager.addHistory(projectId, 'worker', 'user', workerContinuationPrompt);
371
  await StateManager.addHistory(projectId, 'worker', 'model', secondTurnResponse);
372
 
373
- // Update the variable for execution
374
  finalResponseToSave = secondTurnResponse;
375
  } else {
376
  // Standard path (No PM needed), save history normally
@@ -380,8 +382,8 @@ async function runAsyncFeedback(projectId, userId, fullInput, images = []) {
380
 
381
  StateManager.setStatus(projectId, "Idle");
382
 
383
- // 6. Execute Logic
384
- // We execute 'finalResponseToSave' which is either the simple response OR the post-PM complex response
385
  await processAndQueueResponse(projectId, finalResponseToSave, userId);
386
 
387
  // 7. Update Status & Timestamp
 
290
  let finalResponseToSave = firstTurnResponse;
291
 
292
  if (routeTask || pmQuestion) {
293
+ // --- Save the Worker's first turn immediately ---
 
 
294
  await StateManager.addHistory(projectId, 'worker', 'user', fullInput);
295
  await StateManager.addHistory(projectId, 'worker', 'model', firstTurnResponse);
296
 
 
333
  }
334
  );
335
 
336
+ diamondUsage += 0;
337
 
338
  // Save PM History
339
  await StateManager.addHistory(projectId, 'pm', 'user', pmPrompt);
340
  await StateManager.addHistory(projectId, 'pm', 'model', pmResponseText);
341
 
342
+ // --- CRITICAL FIX: EXECUTE PM CODE ---
343
+ // If the PM wrote code (backend logic), execute it now.
344
+ await processAndQueueResponse(projectId, pmResponseText, userId);
345
+
346
  // 5. Run Worker Continuation (The "Answer" Phase)
347
  const nextInstruction = extractWorkerPrompt(pmResponseText) || pmResponseText;
348
  const workerContinuationPrompt = `${pmContextPrefix} ${nextInstruction}\n\nBased on this, continue the task and output the code.`;
 
353
  let secondTurnResponse = "";
354
 
355
  await AIEngine.callWorkerStream(
356
+ currentWorkerHistory,
357
  workerContinuationPrompt,
358
  (thought) => {
359
  stopStatus();
 
372
  await StateManager.addHistory(projectId, 'worker', 'user', workerContinuationPrompt);
373
  await StateManager.addHistory(projectId, 'worker', 'model', secondTurnResponse);
374
 
375
+ // Update the variable for the FINAL execution (Worker's part)
376
  finalResponseToSave = secondTurnResponse;
377
  } else {
378
  // Standard path (No PM needed), save history normally
 
382
 
383
  StateManager.setStatus(projectId, "Idle");
384
 
385
+ // 6. Execute Logic (Worker's part)
386
+ // If PM ran before this, their code is already queued. Now we queue the Worker's code.
387
  await processAndQueueResponse(projectId, finalResponseToSave, userId);
388
 
389
  // 7. Update Status & Timestamp