Commit a5b737f
committed
fix(desktop): unify agent history on chat_messages, remove store.messages mirror
Fixes an agent context corruption where a broken session + user typing
"继续" would make the agent drift onto an unrelated task. Root cause: two
histories were kept in parallel — `store.messages` (legacy, thin) fed
the agent, while the sidebar UI showed the richer `chat_messages` table.
On session break + resume the two diverged, so the agent saw either an
empty or stale history and hallucinated a new plan.
Changes:
- New `buildHistoryFromChat(designId)` helper reads chat_messages as the
single source of truth (seedFromSnapshots first to backfill legacy
designs), converts user + assistant_text rows to ChatMessage[].
- `sendPrompt` feeds that into the agent instead of store.messages.
- `persistDesignState` drops its messages param and derives the design
thumbnail text from chat_messages directly.
- `store.messages` field + all reducer branches deleted. Removes legacy
listMessages / replaceMessages IPC call sites in the renderer (main-
side handlers remain vestigial; safe to drop in a future cleanup).
- `applyInlineComment` now appends user / assistant / error rows to
chat_messages so inline comments actually show in the sidebar chat.
- `retryLastPrompt` simplified — chat_messages carries the failed turn
forward; no more in-memory pruning.
- Tests updated: drop assertions on the removed field, add vi.waitFor
around generate mocks since sendPrompt now has an extra await for the
chat.list read before invoking generate.
All 374 desktop tests pass; typecheck clean.1 parent 983c036 commit a5b737f
3 files changed
Lines changed: 96 additions & 93 deletions
Lines changed: 2 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
20 | 19 | | |
21 | 20 | | |
22 | 21 | | |
| |||
119 | 118 | | |
120 | 119 | | |
121 | 120 | | |
| 121 | + | |
122 | 122 | | |
123 | 123 | | |
124 | 124 | | |
| |||
137 | 137 | | |
138 | 138 | | |
139 | 139 | | |
| 140 | + | |
140 | 141 | | |
141 | 142 | | |
142 | 143 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
30 | 29 | | |
31 | 30 | | |
32 | 31 | | |
| |||
71 | 70 | | |
72 | 71 | | |
73 | 72 | | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
74 | 77 | | |
75 | 78 | | |
76 | 79 | | |
| |||
156 | 159 | | |
157 | 160 | | |
158 | 161 | | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | 162 | | |
163 | 163 | | |
164 | 164 | | |
| |||
210 | 210 | | |
211 | 211 | | |
212 | 212 | | |
| 213 | + | |
| 214 | + | |
213 | 215 | | |
214 | 216 | | |
215 | 217 | | |
| |||
218 | 220 | | |
219 | 221 | | |
220 | 222 | | |
221 | | - | |
222 | | - | |
223 | | - | |
224 | | - | |
225 | 223 | | |
226 | 224 | | |
227 | 225 | | |
| |||
432 | 430 | | |
433 | 431 | | |
434 | 432 | | |
435 | | - | |
| 433 | + | |
436 | 434 | | |
437 | 435 | | |
438 | 436 | | |
| |||
454 | 452 | | |
455 | 453 | | |
456 | 454 | | |
457 | | - | |
458 | | - | |
459 | | - | |
460 | | - | |
461 | | - | |
462 | | - | |
463 | | - | |
464 | | - | |
465 | 455 | | |
466 | 456 | | |
467 | 457 | | |
468 | 458 | | |
469 | | - | |
470 | 459 | | |
471 | 460 | | |
472 | 461 | | |
| |||
477 | 466 | | |
478 | 467 | | |
479 | 468 | | |
480 | | - | |
481 | 469 | | |
482 | 470 | | |
483 | | - | |
484 | | - | |
485 | | - | |
486 | | - | |
| 471 | + | |
487 | 472 | | |
488 | 473 | | |
489 | 474 | | |
| |||
508 | 493 | | |
509 | 494 | | |
510 | 495 | | |
511 | | - | |
512 | 496 | | |
513 | 497 | | |
514 | 498 | | |
| |||
517 | 501 | | |
518 | 502 | | |
519 | 503 | | |
520 | | - | |
521 | 504 | | |
522 | 505 | | |
523 | 506 | | |
| |||
698 | 681 | | |
699 | 682 | | |
700 | 683 | | |
701 | | - | |
702 | 684 | | |
703 | 685 | | |
704 | 686 | | |
| |||
707 | 689 | | |
708 | 690 | | |
709 | 691 | | |
710 | | - | |
711 | | - | |
712 | | - | |
713 | | - | |
714 | 692 | | |
715 | 693 | | |
716 | 694 | | |
| |||
0 commit comments