# WP Agentic Writer Sidebar 1:1 Migration Tasklist

**Source task plan:** `SIDEBAR_1_TO_1_MIGRATION.md`
**Source of truth:** `assets/js/sidebar.js`
**Mode:** active 1:1 migration. No build step, no inferred behavior.

Use this tasklist to execute the migration described in `SIDEBAR_1_TO_1_MIGRATION.md`. Every checkbox must be completed against `assets/js/sidebar.js`, not memory.

**Current status:** Real 1:1 monolith migration is complete in `assets/js/src/index.jsx` for mechanical `wp.element.createElement` to JSX conversion. The migrated file parses with `tsc --allowJs --checkJs false --jsx preserve --noEmit`, class inventory still verifies 226 tokens, endpoint and Gutenberg/browser side-effect inventories remain present, and only intentional `document.createElement` DOM usage remains. No build was run, no enqueue switch was made, and no extraction was performed.

**Implementation tracker:** Continue real migration work in `SIDEBAR_1_TO_1_REAL_MIGRATION_TASKLIST.md`. This document remains the Phase 0-14 parity/audit ledger.

**Readiness statement:** Phase 0 through Phase 14 have been checked twice against the current `assets/js/sidebar.js` source of truth and are considered complete for monolith parity. Optional Phase 15 is intentionally excluded because extraction must wait until after the 1:1 monolith migration. Do not re-open uncertainty about Phase 0-14 unless `assets/js/sidebar.js`, `SIDEBAR_1_TO_1_MIGRATION.md`, or `assets/js/src/index.jsx` changes. The project is ready to start the actual 1:1 migration work: mechanical `createElement` to JSX conversion inside the monolith, with no behavior changes.

**Active conversion rule:** During JSX conversion, each completed range must be recorded below with its original source line range. The global `createElement` definition-of-done item is checked only after every `wp.element.createElement` render call in the monolith has been converted and verified.

## Ground Rules

- [x] Confirm `assets/js/sidebar.js` is the current source of truth before starting.
- [x] Confirm `SIDEBAR_1_TO_1_MIGRATION.md` is open beside `assets/js/sidebar.js`.
- [x] Do not use `MIGRATION_GUIDE.md` as authority when it differs from `assets/js/sidebar.js`.
- [x] Do not rename functions during the first migration pass.
- [x] Do not extract helper files during the first migration pass.
- [x] Do not change visible text, labels, placeholders, icons, SVG markup, classes, inline styles, aria attributes, roles, or conditional render gates.
- [x] Do not replace `RawHTML`, markdown logic, stream handling, abort handling, localStorage keys, endpoint paths, request bodies, or Gutenberg APIs.
- [x] Keep the first target as a monolithic JSX port.

## Definition of Done for Each Range

- [x] Source range is copied or represented completely.
- [x] `createElement` conversion keeps the same tag/component.
- [x] Props are preserved 1:1.
- [x] Children order is preserved 1:1.
- [x] Conditional gates are preserved in the same branch position.
- [x] State/ref/effect ordering is preserved.
- [x] Callback boundaries and dependency arrays are preserved.
- [x] Inline styles, string literals, titles, placeholders, labels, and SVG strings are preserved.
- [x] Any migrated range is checked against the original source lines before moving on.

## Phase 0 - Source Lock and Boundaries

- [x] Verify `sidebar.js` has 12,363 lines.
- [x] Verify file header and IIFE boundary: lines 1-7 and 12363.
- [x] Verify dependency destructuring: lines 8-15.
- [x] Verify debug logger and `pluginIcon`: lines 16-35.
- [x] Verify `AgenticWriterSidebar` starts at line 38.
- [x] Verify `AgenticWriterSidebar` closes at line 12347.
- [x] Verify HOC/plugin boot remains separate: lines 12349-12363.
- [x] Verify main return starts at line 12307.
- [x] Record any source drift before implementation. If line numbers changed, regenerate this tasklist from the updated source.

## Phase 1 - Monolith Skeleton

- [x] Create the migrated target as one monolithic sidebar component.
- [x] Map every WordPress dependency from lines 8-15.
- [x] Preserve `pluginIcon` behavior from lines 31-35.
- [x] Preserve component prop shape: `AgenticWriterSidebar = ({ postId })`.
- [x] Preserve `mapSelectToProps` behavior from lines 12349-12352.
- [x] Preserve `ConnectedSidebar` behavior from lines 12355-12356.
- [x] Preserve `registerPlugin("wp-agentic-writer")` behavior from lines 12358-12362.
- [x] Do not split files yet.

## Phase 2 - State, Refs, and Constants

- [x] Migrate settings and error formatting: lines 40-138.
- [x] Migrate chat/top-level state: lines 139-149.
- [x] Migrate session lock state and refs: lines 152-160.
- [x] Migrate config defaults, config state, and config refs: lines 163-188.
- [x] Migrate cost/provider state and provider metadata helper: lines 191-223.
- [x] Migrate editor/refinement lock state and refs: lines 224-237.
- [x] Migrate SEO audit state: lines 240-243.
- [x] Migrate clarification, pending plan, and request refs: lines 246-268.
- [x] Migrate active operation refs/state: lines 269-279.
- [x] Migrate writing state: lines 280-289.
- [x] Migrate workspace snapshot/collapse state and toggle: lines 290-321.
- [x] Migrate mention/slash/input refs and state: lines 323-336.
- [x] Migrate focus keyword state and persistence refs: lines 338-347.
- [x] Migrate welcome state: lines 349-352.
- [x] Migrate undo stack and max size: lines 354-356.
- [x] Migrate Memanto restore state/ref: lines 358-366.
- [x] Verify state/ref/hook order matches `sidebar.js` exactly.

## Phase 3 - Effects, Saving, Timeline, and Editor Locks

- [x] Migrate agent mode reset effect: lines 367-371.
- [x] Migrate post config load effect: lines 373-400.
- [x] Migrate `savePostConfig`: lines 402-448.
- [x] Migrate debounced post config effect: lines 449-473.
- [x] Migrate cost tracking effect: lines 474-499.
- [x] Migrate `normalizeWritingState`: lines 500-510.
- [x] Migrate `saveWritingState`: lines 511-539.
- [x] Migrate `persistWritingStatePatch`: lines 540-550.
- [x] Migrate writing state load effect: lines 551-585.
- [x] Migrate scroll refs/effect: lines 586-595.
- [x] Migrate timeline regex/status constants and helpers: lines 596-673.
- [x] Migrate active operation helpers: lines 674-728.
- [x] Migrate refine-all confirmation callbacks: lines 729-752.
- [x] Migrate undo snapshot helpers: lines 753-812.
- [x] Migrate post saving lock effects: lines 813-841.
- [x] Migrate editor input lock and DOM blocker effect: lines 842-981.
- [x] Migrate text/config/keyword helpers and welcome start: lines 1020-1194.

## Phase 4 - SEO, Workspace, Sessions, and Locks

- [x] Migrate `runSeoAudit`: lines 1195-1269.
- [x] Migrate SEO fix instruction helpers: lines 1270-1348.
- [x] Migrate `handleSeoAuditFix`: lines 1349-1459.
- [x] Migrate `generateMetaDescription`: lines 1460-1563.
- [x] Migrate block preview helpers: lines 1564-1599.
- [x] Migrate workspace snapshot helper/effects: lines 1600-1668.
- [x] Migrate beforeunload/session restore effects: lines 1669-1716.
- [x] Migrate session storage sanitizing and hydration: lines 1717-1781.
- [x] Migrate session message persistence: lines 1782-1889.
- [x] Migrate session lock acquire/release/heartbeat/takeover: lines 1890-2026.
- [x] Migrate lock/chat-history/post-session effects: lines 2027-2300.
- [x] Migrate `loadPostSessions`: lines 2301-2397.
- [x] Migrate `openSessionById`: lines 2398-2515.

## Phase 5 - Mentions, Commands, Plans, and Agent Decisions

- [x] Migrate stream target and mention token helpers: lines 2516-2569.
- [x] Migrate title refinement: lines 2570-2689.
- [x] Migrate slash command parsing/options/block index: lines 2690-2758.
- [x] Migrate target block resolution and insert refinement block: lines 2759-2870.
- [x] Migrate plan streaming: lines 2871-3188.
- [x] Migrate retry helpers: lines 3189-3473.
- [x] Migrate plan block/preview helpers: lines 3474-3604.
- [x] Migrate section block helpers and persistence: lines 3605-3696.
- [x] Migrate plan task/target/matching/status/index helpers: lines 3697-3906.
- [x] Migrate chat summary, intent detection, context, reset, plan message, keyword suggestion, and runtime helpers: lines 3907-4218.
- [x] Migrate plan ID, intent classifier, and action decider: lines 4219-4320.

## Phase 6 - Execution, Refinement, and Block Context

- [x] Migrate `executePlanFromCard`: lines 4321-4768.
- [x] Migrate stop execution: lines 4769-4794.
- [x] Migrate clear chat context: lines 4795-4870.
- [x] Migrate serialized block creation: lines 4871-4953.
- [x] Migrate block reformatting: lines 4954-5056.
- [x] Migrate plan revision: lines 5057-5142.
- [x] Migrate edit plan apply/cancel: lines 5143-5280.
- [x] Migrate clarification context effect/helper: lines 5281-5327.
- [x] Migrate duplicate heading removal: lines 5328-5362.
- [x] Migrate refineable block/list helpers: lines 5363-5442.
- [x] Migrate context block helpers: lines 5443-5520.
- [x] Migrate slang/AI-slop detection helpers: lines 5521-5606.
- [x] Migrate refinement diagnosis and block mention resolution: lines 5607-5799.
- [x] Migrate `handleChatRefinement`: lines 5800-6388.
- [x] Verify `wpaw-diff-added` and `wpaw-diff-removed` behavior survives unchanged.

## Phase 7 - Chat Input and Main Async Flows

- [x] Migrate refine-all modal: lines 6389-6455.
- [x] Migrate mention options: lines 6456-6579.
- [x] Migrate custom insert-mention event effect: lines 6580-6612.
- [x] Migrate input change/key handling: lines 6613-6701.
- [x] Migrate mention and slash insertion helpers: lines 6702-6758.
- [x] Migrate `sendMessage`: lines 6759-8056.
- [x] Migrate `submitAnswers`: lines 8057-8476.
- [x] Verify all stream readers, decoders, timeouts, active readers, and abort branches match the source.

## Phase 8 - Render Surfaces

- [x] Migrate `renderClarification`: lines 8477-8829.
- [x] Verify `renderSingleChoice`: lines 8486-8547.
- [x] Verify `renderMultipleChoice`: lines 8550-8577.
- [x] Verify `renderOpenText`: lines 8580-8597.
- [x] Verify `renderConfigForm`: lines 8600-8723.
- [x] Verify answer input switch: lines 8725-8742.
- [x] Migrate conversation session actions: lines 8830-9004.
- [x] Migrate `renderWelcomeScreen`: lines 9005-9184.
- [x] Migrate `renderWritingEmptyState`: lines 9185-9253.
- [x] Migrate `renderFocusKeywordBar`: lines 9254-9459.
- [x] Migrate `renderAgentWorkspaceCard`: lines 9460-9629.
- [x] Preserve `renderContextIndicator = renderAgentWorkspaceCard`: lines 9630-9632.
- [x] Migrate `renderContextualAction`: lines 9633-9996.
- [x] Migrate `renderMessages`: lines 9997-10917.
- [x] Migrate `renderConfigTab`: lines 10918-11434.
- [x] Migrate `getAgentStatus`: lines 11435-11448.
- [x] Migrate `renderGlobalStatusBar`: lines 11449-11585.
- [x] Migrate `renderChatTab`: lines 11586-12020.
- [x] Migrate cost state/effect/helpers: lines 12021-12057.
- [x] Migrate `renderCostTab`: lines 12058-12306.
- [x] Migrate main component return tree: lines 12307-12346.

## Phase 9 - Render Surface Element Audit

- [x] Refine modal: confirm dialog role, aria modal/label, overlay, modal, title, body, checkbox, cancel, continue.
- [x] Clarification UI: confirm all question types, custom answer field, config fields, progress bar, previous/skip/next/finish behavior.
- [x] Welcome UI: confirm recent session, older session details, open/delete buttons, keyword input, mode pills, start button.
- [x] Writing empty state: confirm SVG icon, copy, create outline button, hint text.
- [x] Focus keyword bar: confirm expanded/compact branches, suggestions, selected state, provider/cost display, expand/collapse.
- [x] Workspace card: confirm collapsed state, status, context grid, keyword field, conversation/provider summary, resume card.
- [x] Contextual action: confirm `create_outline` action, clarity check branch, generate-plan stream branch, action card.
- [x] Messages: confirm markdown helpers, grouping, timeline, plan, edit plan, structured errors, retry buttons, default response, resume actions.
- [x] Config tab: confirm every section, control, description, SEO controls, meta generation, audit score, check list, fix buttons.
- [x] Status bar: confirm status dot, memory badge, undo, sessions, chat, workspace toggle, config, cost buttons.
- [x] Chat tab: confirm lock banners, health notices, welcome/empty/workspace/activity gates, command area, hint, textarea, autocompletes, search toggle, stop/send, keyboard hints, modal.
- [x] Cost tab: confirm header, refresh, cards, budget section, warning, action summary table, history table, footer link.
- [x] Final shell: confirm menu item, sidebar title, icon, panel, tab wrapper, active tab branch.

## Phase 10 - Class Inventory Audit

- [x] Verify every literal `className` token from `SIDEBAR_1_TO_1_MIGRATION.md` exists in the migrated target.
- [x] Verify dynamic classes remain dynamic expressions.
- [x] Verify `wpaw-diff-removed` append branch: lines 6075-6078 and 6111-6114.
- [x] Verify `wpaw-diff-added` append branches: lines 6085-6089 and 6128-6129.
- [x] Verify welcome pill `active` branches: lines 9152-9154 and 9162-9164.
- [x] Verify focus suggestion `selected`: lines 9322-9324.
- [x] Verify workspace `is-collapsed` and `status-${activeWorkspaceStatus}`: lines 9489 and 9514.
- [x] Verify timeline `statusClass` and `is-current`: lines 10351-10375.
- [x] Verify plan section `section.status || "pending"`: line 10582.
- [x] Verify SEO/meta status classes: lines 11165-11374.
- [x] Verify status-bar `is-active` branches: lines 11510-11572.
- [x] Verify chat input classes: lines 11596-11955.
- [x] Verify budget status classes: lines 12129, 12158, and 12167.

## Phase 11 - Non-Render Class and Selector Audit

- [x] Preserve WordPress lock key `wpaw-writing`: lines 824 and 828.
- [x] Preserve body class `wpaw-editor-locked`: lines 825 and 829.
- [x] Preserve WordPress lock key `wpaw-refining`: lines 835 and 838.
- [x] Preserve body class `wpaw-refining-locked`: lines 836 and 839.
- [x] Preserve editor block class `wpaw-block-refining`: lines 895, 903, and 916.
- [x] Preserve input-blocking selector `.wpaw-sidebar, .wpaw-command-area, .wpaw-messages`: line 933.
- [x] Preserve diff cleanup removal of `wpaw-diff-removed`: line 5262.

## Phase 12 - Endpoint and Integration Audit

- [x] Verify `/post-config/${postId}` calls.
- [x] Verify `/cost-tracking/${postId}` calls.
- [x] Verify `/writing-state/${postId}` calls.
- [x] Verify `/seo-audit/${postId}` call.
- [x] Verify `/generate-meta` call.
- [x] Verify all conversation endpoints.
- [x] Verify `/conversation/${postId}` and `/conversation/${data.post_id}` calls.
- [x] Verify `/chat-history/${postId}` call.
- [x] Verify `/memanto/restore?post_id=${postId}` call.
- [x] Verify `/refine-title` call.
- [x] Verify all `/generate-plan` calls.
- [x] Verify all `/chat` calls.
- [x] Verify `/section-blocks/${postId}` and `/section-blocks` calls.
- [x] Verify `/summarize-context` call.
- [x] Verify `/detect-intent` call.
- [x] Verify `/clear-context` call.
- [x] Verify `/suggest-keywords` call.
- [x] Verify `/execute-article` call.
- [x] Verify `/reformat-blocks` call.
- [x] Verify `/revise-plan` call.
- [x] Verify `/refine-from-chat` call.
- [x] Verify `/check-clarity` calls.
- [x] For every endpoint, verify method, nonce header, content type, body shape, stream/non-stream handling, provider metadata, cost updates, and error handling.

## Phase 13 - Gutenberg and Browser Side Effects Audit

- [x] Verify all `select("core/block-editor")` calls.
- [x] Verify all `dispatch("core/block-editor")` calls.
- [x] Verify all `select("core/editor")` calls.
- [x] Verify all `dispatch("core/editor")` calls.
- [x] Verify `wp.data.subscribe` behavior.
- [x] Verify `wp.data.withSelect` behavior.
- [x] Verify localStorage keys: `wpaw_agent_workspace_collapsed` and `wpawSessionId_${postId}`.
- [x] Verify beforeunload handlers.
- [x] Verify global document event listeners and cleanups.
- [x] Verify window `wpaw:insert-mention` listener and cleanup.
- [x] Verify lock heartbeat interval setup and cleanup.
- [x] Verify debounced config/message/keyword saves.
- [x] Verify `AbortController` lifecycle.
- [x] Verify stream reader lifecycle and active reader cancellation.
- [x] Verify `TextDecoder` usage.

## Phase 14 - Final Parity Audit

- [x] Confirm no functions are missing from `SIDEBAR_1_TO_1_MIGRATION.md`.
- [x] Confirm no state/ref/effect entries are missing.
- [x] Confirm no render surface entries are missing.
- [x] Confirm no class inventory entries are missing.
- [x] Confirm no dynamic class expressions were flattened.
- [x] Confirm no endpoint inventory entries are missing.
- [x] Confirm no editor/browser side effects are missing.
- [x] Confirm final plugin registration still renders `ConnectedSidebar`.
- [x] Confirm no optional extraction was performed before monolith parity.
- [x] Confirm any future extraction task references the source line range it moves.

## Active JSX Conversion Pass

- [x] Convert `renderRefineAllConfirmModal`: source lines 6389-6455. Verified overlay `div`, modal `div`, title/body `div`s, `CheckboxControl`, two `Button` components, class names, role/aria attributes, labels, text, callbacks, and child order.
- [x] Convert all remaining `wp.element.createElement` render calls in the monolith. Verified `assets/js/src/index.jsx` has zero remaining `wp.element.createElement`/`React.createElement` calls, preserves intentional `document.createElement`, parses with TypeScript JSX, preserves class inventory, endpoint inventory, Gutenberg/browser side effects, and final plugin registration.

## Optional Phase 15 - Extraction After Monolith Parity Only

- [ ] Extract only one helper group at a time.
- [ ] Before extraction, record source range and destination file.
- [ ] Move code without renaming public/internal symbols.
- [ ] Preserve imports/dependencies exactly.
- [ ] Re-run the same parity checks for the moved range.
- [ ] Do not extract render surfaces until all behavior helpers are proven equivalent.
- [ ] Do not delete the monolith source range until the moved range is checked line-by-line.

## Stop Conditions

- [ ] Stop if `sidebar.js` changes and this tasklist has not been regenerated.
- [ ] Stop if a migrated range requires guessing.
- [ ] Stop if a function seems unused but exists in `sidebar.js`.
- [ ] Stop if a class appears styling-only but exists in `sidebar.js`.
- [ ] Stop if an endpoint or request body differs from `sidebar.js`.
- [ ] Stop if hook order would change.
