# V4 Queue UI Implementation Plan > **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. **Goal:** Bring the v4 queue panel in line with the z-code-2 queue UI, make queue edit extract the item into the composer, and wire drag reorder to CLI projection state. **Architecture:** Keep queue authority in CLI projection (`snapshot.queue.items`) and send all mutations through v4 commands. UI renders projection state only; drag reorder computes a `beforeQueueItemId` anchor and lets `TurnSteerReordered` update projection. Queue edit deletes the item through `deleteQueueItem` before filling the composer. **Tech Stack:** React 19, TypeScript, `@dnd-kit/core`, `@dnd-kit/sortable`, lucide-react, v4 command protocol. ## Global Constraints - Specs/docs must be updated before implementation. - UI changes must follow `DESIGN.md`, use semantic tokens, support light/dark themes and mobile web. - UI logs must use `packages/ui/src/logger.ts`. - Queue state remains CLI projection authority, not renderer-local order state. - Produce exactly three commits: visual UI, edit extraction, drag reorder. --- ### Task 1: Queue Panel Visual Parity **Files:** - Modify: `docs/ui/chat-message-queue.md` - Modify: `packages/ui/src/v4/ConversationQueuePanel.tsx` - Test: `packages/ui/test/v4ConversationQueuePanel.test.tsx` **Interfaces:** - Consumes: `QueueState.items` with `queueItemId`, `text`, and `kind`. - Produces: a queue panel with drag-handle visual affordance, compact icon actions, and unchanged command callbacks. - [ ] **Step 1: Write the failing visual test** Create a test that renders two queue items and asserts: - the panel uses `data-testid="v4-queue"` - each item exposes `data-queue-item-id` - the handle uses `data-v4-queue-drag-handle` - the visible action text is `立即`, not `立即发送` - the old `上移` button copy is absent. - [ ] **Step 2: Run test to verify it fails** Run: `pnpm exec vitest run packages/ui/test/v4ConversationQueuePanel.test.tsx` - [ ] **Step 3: Implement visual markup** Update `ConversationQueuePanel` to use `Button`, `ControlHintTooltip`, lucide icons, semantic classes, and `chat.queue.*` i18n labels. Keep reorder callback inert until Task 3. - [ ] **Step 4: Run test to verify it passes** Run: `pnpm exec vitest run packages/ui/test/v4ConversationQueuePanel.test.tsx` - [ ] **Step 5: Commit** Commit: `feat(ui): align v4 queue panel visuals` ### Task 2: Queue Edit Extracts Into Composer **Files:** - Modify: `docs/ui/chat-message-queue.md` - Modify: `packages/ui/src/v4/SessionPane.tsx` - Modify: `packages/ui/src/v4/ConversationComposer.tsx` - Modify: `packages/ui/src/v4/ConversationQueuePanel.tsx` - Test: `packages/ui/test/v4SessionPaneQueueEdit.test.tsx` - Test: `packages/ui/test/v4ConversationComposerErrorBanner.test.ts` **Interfaces:** - Consumes: `onEditItem(queueItemId)` from queue panel. - Produces: `ConversationComposer` prop `externalTextInsertRequest?: { requestId: number; text: string }`. - [ ] **Step 1: Write failing tests** Add a SessionPane test that clicks queue edit and expects `deleteQueueItem` to be sent before composer receives the queue text. Add a ConversationComposer test that changes `externalTextInsertRequest` and expects the editor API `setText` and `onTextChange` to receive the text. - [ ] **Step 2: Run tests to verify they fail** Run: `pnpm exec vitest run packages/ui/test/v4SessionPaneQueueEdit.test.tsx packages/ui/test/v4ConversationComposerErrorBanner.test.ts` - [ ] **Step 3: Implement edit extraction** In `SessionPane`, look up the queue item text from the current projection, send `deleteQueueItem`, then set the composer insert request only for accepted/noop ACKs. In `ConversationComposer`, apply each new request once via `inputApiRef.current.setText()`, update local text state, persist draft, and focus. - [ ] **Step 4: Run tests to verify they pass** Run: `pnpm exec vitest run packages/ui/test/v4SessionPaneQueueEdit.test.tsx packages/ui/test/v4ConversationComposerErrorBanner.test.ts` - [ ] **Step 5: Commit** Commit: `feat(ui): extract queued edit into composer` ### Task 3: Drag Reorder Command Wiring **Files:** - Modify: `docs/ui/chat-message-queue.md` - Modify: `packages/ui/src/v4/ConversationQueuePanel.tsx` - Modify: `packages/desktop/test/e2e/helpers/v4-conversation.ts` - Modify: `packages/desktop/test/e2e/conversation-session/queue/conversation-session-v4-queue.test.ts` - Test: `packages/ui/test/v4ConversationQueuePanel.test.tsx` **Interfaces:** - Consumes: `onMoveItem(queueItemId, beforeQueueItemId)` from panel props. - Produces: `resolveV4QueueReorderAnchor(items, activeId, overId)` where downward moves use the item after `overId`, and tail moves use `null`. - [ ] **Step 1: Write failing reorder tests** Add unit tests for upward, downward, tail, no-op, and missing-id anchor calculations. - [ ] **Step 2: Run test to verify it fails** Run: `pnpm exec vitest run packages/ui/test/v4ConversationQueuePanel.test.tsx` - [ ] **Step 3: Implement dnd-kit reorder** Wrap queue items in `DndContext` and `SortableContext`. On drag end, compute the `beforeQueueItemId` anchor and call `onMoveItem`; do not mutate local queue order. - [ ] **Step 4: Update E2E helper/spec** Replace the old `clickV4QueueItemUp` path with drag helpers that move the second item above the first and assert projection order changes. - [ ] **Step 5: Run focused tests** Run: `pnpm exec vitest run packages/ui/test/v4ConversationQueuePanel.test.tsx` - [ ] **Step 6: Commit** Commit: `feat(ui): reorder v4 queue by drag` ## Final Verification - [ ] Run `pnpm exec vitest run packages/ui/test/v4ConversationQueuePanel.test.tsx packages/ui/test/v4SessionPaneQueueEdit.test.tsx packages/ui/test/v4ConversationComposerErrorBanner.test.ts` - [ ] Run `pnpm --filter @zcode/bootstrap test -- tests/product-projection.test.ts tests/v4-native-queue.test.ts` - [ ] Run `pnpm typecheck` - [ ] Run `pnpm lint`