Selaa lähdekoodia

docs: plan EventPrompt order preservation

Problem: regenerating EventPrompt after tool or mode changes moved it to the end of the sortable prompt list.\n\nRisk: the repair must preserve derived-state deduplication while retaining the first generated prompt position.
zhenyu.hu 2 viikkoa sitten
vanhempi
commit
bbedaa2c94
2 muutettua tiedostoa jossa 39 lisäystä ja 0 poistoa
  1. 38 0
      docs/plans/todo-53.1-event-prompt-order-preservation.md
  2. 1 0
      docs/plans/todos.md

+ 38 - 0
docs/plans/todo-53.1-event-prompt-order-preservation.md

@@ -0,0 +1,38 @@
+# Todo 53.1: EventPrompt Order Preservation
+
+## Problem
+
+Commit `cf481ab` correctly made EventPrompt derived state, but `removeEventPromptItems()` deletes it and `ensureEventPromptItem()` appends the replacement. Tool changes, mode round trips, and restored prompt lists therefore move EventPrompt to the end and change serialized system-message order.
+
+## Scope
+
+- Preserve the first generated EventPrompt's position relative to retained custom prompts.
+- Remember that insertion position while `chat_agent_tools` hides EventPrompt.
+- Restore the saved typed/legacy EventPrompt position when loading prompt items.
+- Continue removing duplicate generated EventPrompt items and preserving ordinary custom prompts.
+- Do not add frontend dependencies or change backend contracts.
+
+## TDD Steps
+
+1. Add a failing regression in `tests/test_websocket_api.py` that requires an explicit EventPrompt insertion-position state/helper, captures position before removal, and reinserts with `insertBefore` instead of unconditional append.
+2. Run the focused test and confirm it fails for the current append-only implementation.
+3. Implement the smallest position-preserving logic in `src/agent_lab/presentation/static/app.js`.
+4. Verify tool refresh, `dual_agent -> chat_agent_tools -> dual_agent`, and restore paths use the same remembered position.
+5. Run:
+
+   ```bash
+   uv run pytest tests/test_websocket_api.py -k "event_prompt or prompt_restore or tool_mode" -q
+   node --check src/agent_lab/presentation/static/app.js
+   git diff --check
+   ```
+
+6. Commit with the solved problem and ordering risk, then repeat spec and code-quality reviews.
+
+## Acceptance
+
+- EventPrompt content and visibility remain mode/tool-derived.
+- At most one EventPrompt exists.
+- Refreshing tools does not move EventPrompt.
+- Hiding and showing EventPrompt restores its previous insertion position.
+- Restoring typed or legacy prompt data derives the insertion position from the first generated EventPrompt while discarding duplicates.
+- Custom prompt order and outbound request contracts remain unchanged.

+ 1 - 0
docs/plans/todos.md

@@ -115,3 +115,4 @@
 | 52.12 | done | `docs/plans/todo-52.12-benchmark-metric-integrity-and-parallel-proof.md` | Exclude consumer backpressure from model elapsed, reject missing token usage, and prove parallel handlers overlap. | Model latency measures provider-await time; absent usage cannot appear as zero cost; the parallel case fails unless both handlers start concurrently. |
 | 52.13 | done | `docs/plans/todo-52.13-provider-cleanup-exception-priority.md` | Preserve active provider/cancellation exceptions when iterator cleanup also fails. | Provider failures and cancellation retain priority; cleanup failures propagate only when no earlier exception is active; timing attempts are still recorded. |
 | 53 | in_progress | `docs/plans/todo-53-professional-debug-console-ui.md` | Redesign the static UI as a professional debug console and make EventPrompt visibility/content follow invocation mode and selected tools. | Written design is approved; implementation verification covers focused static/WebSocket regressions, JS syntax, full pytest, and desktop/narrow browser QA. |
+| 53.1 | in_progress | `docs/plans/todo-53.1-event-prompt-order-preservation.md` | Preserve the user-selected EventPrompt position while mode/tool refreshes still deduplicate and regenerate its content. | A failing regression proves refresh and dual/direct/dual transitions retain the EventPrompt insertion position; focused tests, JS syntax, and review gates pass. |