# Change Request: CR-001

> Created: 2026-02-19
> Status: Approved
> Classification: Modification to FEATURE-037-B
> Related Feature: FEATURE-037-B (Compose Idea Modal — Link Existing & Re-Edit)
> Source: IDEA-024 (CR-Compose Idea Supporting Re-open)

## Request Details

**Requestor:** Human (Project Author)
**Date Received:** 2026-02-19
**Priority:** Medium

## Description

Enrich the Re-Edit capability (FR-037.12) of FEATURE-037-B with detailed design requirements from IDEA-024:

1. **Stage gate check** — a completed action can only be re-opened if no action in the **next stage** has moved to `in_progress` or `done`. Implemented as a reusable function (not hardcoded to `compose_idea`).
2. **Confirmation dialog** — clicking a completed `compose_idea` action shows "Re-open for editing?" with Confirm/Cancel (replaces current "already completed" toast).
3. **Edit mode** — `ComposeIdeaModal` accepts `{ mode: 'edit', filePath, folderPath, folderName }` and pre-loads existing content.
4. **File auto-detection** — file path auto-detected from deliverables stored in workflow JSON; new API: `GET /api/ideas/file?path=...` with path security validation.
5. **Overwrite-in-place** — saves overwrite the original file (no version increment). Git history serves as safety net.
6. **Update button** — submit button label changes to "Update Idea" in edit mode.

**Scope exclusion:** Link Existing mode is NOT part of this CR. It remains in FEATURE-037-B scope for a future CR.

## Business Justification

Once a user completes `compose_idea`, the idea is permanently locked. Users cannot fix typos, refine content, or re-link to a different idea folder. This forces manual file editing outside the workflow, breaking deliverable tracking. The stage gate ensures re-opening is safe (no downstream actions have consumed the deliverables).

## Impact Analysis

### Classification

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

**Reasoning:**
- FEATURE-037-B already includes FR-037.12 (Re-Edit) in its planned scope
- This CR does NOT expand the feature's purpose — it provides detailed design for an already-planned capability
- Same users, same data model, same UI surface (compose modal + workflow stage)
- One new API endpoint (`GET /api/ideas/file`) is needed but fits within existing system boundaries
- The stage gate function is a cross-cutting concern that also touches FEATURE-036-C (workflow-stage.js) but is a minor enhancement, not a new feature

### Comparison Matrix

| Aspect | CR Requirement | Existing Feature(s) |
|--------|---------------|---------------------|
| Users | Workflow idea authors | FEATURE-037-A/B: same |
| Workflow | Click done action → confirm → edit → save | FEATURE-037-A: create only. 037-B planned: re-edit (unspecified) |
| Data Model | Same (workflow JSON + idea files) | Same |
| UI Elements | Confirmation dialog (reuse workflow-modal), compose modal edit mode | FEATURE-037-A: create mode. 036-C: action buttons |
| API Endpoints | New: `GET /api/ideas/file?path=...` | Existing: POST /upload, POST /action |

### Affected Components

| Component | Impact Level | Details |
|-----------|--------------|---------|
| FEATURE-037-B (compose-idea-modal.js) | High | Add edit mode: pre-load content, folder name, "Update Idea" button, overwrite save |
| FEATURE-036-C (workflow-stage.js) | Medium | Replace "already completed" toast with gate check + confirmation dialog for compose_idea |
| Backend (ideas_routes.py) | Low | New `GET /api/ideas/file` endpoint with path security validation |
| Backend (workflow_manager_service.py) | None | Already supports status rollback via POST /action |

### Dependencies

- FEATURE-037-A must be implemented (it is — v1.0)
- FEATURE-036-C workflow-stage.js action button rendering (implemented)

## Proposed Approach

1. **workflow-stage.js**: Add reusable `_canReopenAction(actionKey, stages)` function. Replace the "already completed" toast for `compose_idea` with: gate check → confirmation dialog → status rollback → open modal in edit mode.
2. **compose-idea-modal.js**: Extend constructor to accept `mode: 'edit'` with `filePath`, `folderPath`, `folderName`. In edit mode: fetch file content via API, populate EasyMDE, pre-fill folder name, change button to "Update Idea", overwrite on save.
3. **Backend**: Add `GET /api/ideas/file?path=...` endpoint. Validate path within project root. Return raw file content or 404.

## Mockup Impact

**UI/UX Change:** Yes — but within existing modal layout
**Existing Mockups Referenced:**

| Original Mockup | Path | Status After CR |
|-----------------|------|-----------------|
| Compose Idea Modal v1 | [mockups/compose-idea-modal-v1.html](../mockups/compose-idea-modal-v1.html) | current (unchanged — edit mode reuses same layout) |

**Updated Mockup(s):** None needed — edit mode reuses the same modal layout with minor label changes (button text, pre-populated fields). No new screens.

## Approval

- [x] Classification approved by human (auto-proceed)
- [x] Approach approved by human (auto-proceed)
- [x] Ready for execution

## Execution

**Classification Result:** modification

**Actions Taken:**
- [x] CR document created in FEATURE-037-B folder
- [x] Requirement-details-part-10.md reviewed (FEATURE-037-B already has FR-037.12 for Re-Edit)
- [ ] [Next] Specification to be created/refined via Feature Refinement skill
- [x] Next task type set: x-ipe-task-based-feature-refinement

## Links

- Idea Summary: [idea-summary-v1.md](../../../ideas/024.%20CR-Compose%20idea%20Supporting%20Re-open/idea-summary-v1.md)
- FEATURE-037-A Specification: [specification.md](../FEATURE-037-A/specification.md)
- Requirement Details: [requirement-details-part-10.md](../../requirement-details-part-10.md)

---

## Change History

| Date | Change | By |
|------|--------|----|
| 2026-02-19 | CR-001 created — Re-Edit with stage gate, confirmation dialog, edit mode, file auto-detection | Zephyr (Agent) |
