Problem
When a user clicks "+ New Story" and starts chatting with Claude, the AI creates a new story folder (e.g., `paper-chair`). But instead of the Untitled session becoming the `paper-chair` session, a new separate terminal session is spawned for `paper-chair`. The original Untitled session is left orphaned with a separate Claude instance.
This means:
- Two Claude sessions running (wasted resources)
- The context from the Untitled session (where the user discussed the story idea) is lost in the new session
- The new `paper-chair` session starts fresh without the brainstorming context
Expected Flow
- + New Story → launches Untitled terminal session (Claude CLI in `~/.plotlink-ows/stories/`)
- User chats with Claude, brainstorms ideas
- Claude creates the story folder (e.g., `mkdir stories/paper-chair` + creates `structure.md`)
- The Untitled session seamlessly becomes the `paper-chair` session — same terminal, same Claude instance, same conversation context
- Sidebar updates: "Untitled" → "Paper Chair" (from structure.md title)
- Terminal tab updates: "Untitled" → "paper-chair"
Current Behavior
- Step 3 happens: Claude creates the folder
- The polling detects the new folder → creates a NEW terminal session for `paper-chair`
- The Untitled session remains as a separate orphaned session
- User now has two tabs: "Untitled" (old) + "paper-chair" (new, no context)
Fix
When the polling in `StoriesPage.tsx` detects a new story folder:
- Don't spawn a new terminal session for it
- Instead, rename the oldest Untitled session to the new story name
- Update the PTY session key in the `ptySessions` Map (backend) from `_new_XXX` to `paper-chair`
- Update the terminal tab display name
- The Claude CLI process continues running — same PID, same conversation
Backend change needed
Add an endpoint to rename a session key:
`POST /api/terminal/rename` — body: `{ oldName: "_new_1234", newName: "paper-chair" }`
This moves the PTY entry in the sessions Map without killing/restarting the process.
Frontend change needed
In the polling effect (`StoriesPage.tsx`), when a new story is detected:
- Call the rename endpoint instead of letting a new session auto-create
- Update the session key in the local Map
- Remove the Untitled entry from `untitledSessions` state
Files
- `app/web/components/StoriesPage.tsx` — polling logic for new story detection
- `app/web/components/TerminalPanel.tsx` — session key management
- `app/routes/terminal.ts` — add rename endpoint, update session Map
Acceptance Criteria
Problem
When a user clicks "+ New Story" and starts chatting with Claude, the AI creates a new story folder (e.g., `paper-chair`). But instead of the Untitled session becoming the `paper-chair` session, a new separate terminal session is spawned for `paper-chair`. The original Untitled session is left orphaned with a separate Claude instance.
This means:
Expected Flow
Current Behavior
Fix
When the polling in `StoriesPage.tsx` detects a new story folder:
Backend change needed
Add an endpoint to rename a session key:
`POST /api/terminal/rename` — body: `{ oldName: "_new_1234", newName: "paper-chair" }`
This moves the PTY entry in the sessions Map without killing/restarting the process.
Frontend change needed
In the polling effect (`StoriesPage.tsx`), when a new story is detected:
Files
Acceptance Criteria