# Change Request: CR-002

> Created: 2026-03-16
> Status: Approved
> Classification: Modification to FEATURE-037-B
> Related Feature: FEATURE-037-B (Compose Idea Modal — Link Existing & Re-Edit)
> Source: UIUX Feedback (Feedback-20260316-113736) — .docx/.msg preview extension to ideation

## Request Details

**Requestor:** Human (Project Author)
**Date Received:** 2026-03-16
**Priority:** Medium

## Description

Extend .docx/.msg file content preview support to the ideation stage (Link Existing mode in Compose Idea Modal). The backend conversion is already in place via FEATURE-038-C CR-001 (shared endpoint `GET /api/ideas/file?path=`). The frontend `compose-idea-modal.js` `_selectFile()` method needs to:

1. **Detect `X-Converted: true` header** — indicates backend converted a binary file to HTML
2. **Render converted HTML in sandboxed iframe** — same pattern as `deliverable-viewer.js`
3. **Handle 413 (too large) and 415 (unsupported)** — show appropriate error messages
4. **Fall back to existing behavior** for non-converted files (markdown via `marked.js`, others as text)

**Scope:** Frontend-only change (~15 lines in `_selectFile()`). No backend changes needed.

## Business Justification

The backend already converts .docx/.msg files to HTML for all callers of `/api/ideas/file`. However, the ideation preview panel (Link Existing mode) doesn't detect the conversion header, so converted HTML is incorrectly passed through `marked.parse()` or displayed as escaped text. Users see raw HTML tags instead of rendered document content when previewing .docx/.msg files in the compose idea modal. This creates an inconsistent experience between the deliverable viewer (which renders correctly) and the ideation preview.

## Impact Analysis

### Classification

**Type:** Modification to FEATURE-037-B

**Reasoning:**
- Same users (workflow idea authors), same UI surface (compose idea modal)
- Same backend endpoint (already done — no API changes)
- Works within current system boundaries (~15 lines of frontend code)
- Extends existing preview functionality, doesn't change its purpose
- No new API endpoints, no new data models, no new user types

### Comparison Matrix

| Aspect | CR Requirement | Existing Feature(s) |
|--------|---------------|---------------------|
| Users | Workflow idea authors | FEATURE-037-B: same |
| Workflow | Select .docx/.msg → see rendered preview | FEATURE-037-B: select file → see markdown/text preview |
| Data Model | Same (workflow JSON + idea files) | Same |
| UI Elements | Sandboxed iframe for converted HTML | FEATURE-037-B: marked.js or pre-formatted text |
| API Endpoints | None new (uses existing /api/ideas/file) | Same endpoint already supports conversion |

### Conflict Analysis

**Conflicts Found:** Yes (5 total: 4 expected, 1 unexpected)

| # | Type | Affected Feature | Severity | Classification | Description |
|---|------|-----------------|----------|----------------|-------------|
| 1 | specification | FEATURE-037-B | High | expected | AC-004 restricts rendering to `.md` only; CR adds `.docx`/`.msg` HTML rendering |
| 2 | specification | FEATURE-037-B | Medium | expected | AC-005 requires metadata for non-markdown files; CR renders converted HTML for .docx/.msg |
| 3 | specification | FEATURE-037-B | High | expected | FR-037-B.3 doesn't mention X-Converted detection or converted HTML rendering |
| 4 | code | FEATURE-037-B | High | expected | `_selectFile()` never checks X-Converted header; always uses `marked.parse()` |
| 5 | specification | FEATURE-038-C | Low | unexpected | CR-001 "Also Affects" section doesn't list FEATURE-037-B |

**Unexpected Conflict Resolution:**
- Conflict #5 (LOW): FEATURE-038-C CR-001 scope documentation gap — will be updated to add FEATURE-037-B to "Also Affects" section. No functional impact.

**Mitigation Strategy:**
- AC-004, AC-005, FR-037-B.3 will be updated during Feature Refinement to document X-Converted exception
- Code change follows same proven pattern from deliverable-viewer.js (defensive `resp.headers &&` check)

### Affected Components

| Component | Impact Level | Details |
|-----------|--------------|---------|
| FEATURE-037-B (compose-idea-modal.js) | High | Add X-Converted header detection + sandboxed iframe rendering in `_selectFile()` |
| FEATURE-037-B (specification.md) | Medium | Update AC-004, AC-005, FR-037-B.3 for converted binary support |
| FEATURE-038-C (CR-001.md) | Low | Add FEATURE-037-B to "Also Affects" documentation |

### Dependencies

- FEATURE-038-C CR-001 must be implemented (it is — backend conversion + X-Converted header in place)
- `mammoth` and `extract-msg` packages already installed via FEATURE-038-C CR-001

## Proposed Approach

1. **compose-idea-modal.js**: In `_selectFile()`, after `resp.text()`, check `resp.headers.get('X-Converted') === 'true'`. If true, render content in sandboxed iframe (`sandbox='allow-same-origin'`, no `allow-scripts`). Otherwise, fall through to existing `marked.parse()` / text rendering.
2. **specification.md**: Update AC-004 (clarify markdown vs converted HTML), AC-005 (add exception for convertible binary), FR-037-B.3 (add X-Converted detection to process).
3. **FEATURE-038-C CR-001.md**: Add FEATURE-037-B to "Also Affects" section.

## Mockup Impact

**UI/UX Change:** No — converted HTML renders in the same preview panel area, just in an iframe instead of marked.js div. No layout changes needed.

**Existing Mockups Referenced:**

| Original Mockup | Path | Status After CR |
|-----------------|------|-----------------|
| Compose Idea Modal v1 | [mockups/compose-idea-modal-v1.html](x-ipe-docs/requirements/EPIC-037/mockups/compose-idea-modal-v1.html) | current (unchanged) |

**Updated Mockup(s):** None needed — preview rendering method changes but visible layout is identical.

## Approval

- [x] Classification approved (DAO-097, confidence 0.96)
- [x] Conflict analysis reviewed (DAO-097)
- [x] Approach approved (DAO-097)
- [x] Ready for execution

## Execution

**Classification Result:** modification
**Conflicts Resolution:** all_expected (4 expected, 1 unexpected LOW resolved)

**Actions Taken:**
- [x] CR document created in FEATURE-037-B folder
- [x] Conflict analysis completed and documented
- [x] Specification Version History updated with CR-002 link
- [ ] [Next] Specification to be refined via Feature Refinement skill
- [x] Next task type set: x-ipe-task-based-feature-refinement

## Links

- Feature Specification: [specification.md](./specification.md)
- FEATURE-038-C CR-001: [CR-001.md](../EPIC-038/FEATURE-038-C/CR-001.md)
- UIUX Feedback: [Feedback-20260316-113736](x-ipe-docs/uiux-feedback/Feedback-20260316-113736/)

---

## Change History

| Date | Change | By |
|------|--------|----|
| 2026-03-16 | CR-002 created — .docx/.msg converted preview in ideation (Link Existing mode) | Cipher 🔐 (Agent) |
