Skip to content

feat: add prompt composer to terminal context menu#2

Open
mpmisha wants to merge 3 commits into
mainfrom
users/mimer/feature/prompt-composer
Open

feat: add prompt composer to terminal context menu#2
mpmisha wants to merge 3 commits into
mainfrom
users/mimer/feature/prompt-composer

Conversation

@mpmisha

@mpmisha mpmisha commented Jun 14, 2026

Copy link
Copy Markdown
Owner

What

Adds a notepad-style Prompt Composer to each AI-session terminal pane, accessible from the pane right-click context menu (📝 Prompt composer), the Command Palette, or the Ctrl+Alt+P (⌘⌥P on Mac) shortcut. Closes TASK-180.

Availability: The composer is intentionally surfaced only on AI-session panes (Copilot CLI, Claude Code, etc.) — same gating as Show prompts and Session summary. On a plain shell pane the context-menu item, the Command Palette entry, and the shortcut are all hidden / no-op.

image image

Why

Composing long, multi-line prompts directly in the terminal is awkward — newlines and paste are fiddly, and a stray Enter submits a half-written message. The composer is a plain modal <textarea> so users can write and edit freely, then copy or paste the whole thing into the terminal as a single block.

How it works

Three buttons in the footer:

  • 📋 Copy — write the draft to the clipboard, with transient "✓ Copied" feedback.
  • ➤ Submit — bracketed-paste the draft into the focused terminal via writePty. We do not also send Enter — the user reviews in the terminal and presses Enter themselves. Intentional:
    • avoids accidental submission of half-thought-out prompts
    • Ink-based AI CLIs (Copilot CLI, Claude Code) handle a programmatic \r after bracketed paste inconsistently
  • Close — dismiss (also bound to Esc and backdrop click).

Drafts persist per-terminal for the current session, so closing and reopening the dialog doesn't lose work. Drafts are dropped when the owning pane is closed, and the composer auto-dismisses if its target pane goes away.

Submit reuses the existing prepareClipboardPaste helper for bracketed-paste wrapping + CRLF→LF normalization (so Windows-CRLF drafts work cleanly).

Keyboard shortcut

Ctrl+Alt+P (rendered as ⌘⌥P on Mac) opens the composer for the focused pane. While adding this, the keybinding matcher was fixed to fall back to event.code on macOS — Option+letter on Mac produces special characters (Option+P → π), which broke matching against the literal p key. The fix also unblocks the pre-existing Ctrl+Alt+R and Ctrl+Alt+N bindings on Mac.

Files

Added

  • src/renderer/components/PromptComposer.tsx — the modal
  • src/renderer/utils/prompt-composer.ts — pure draft-map helpers (DRY + testable)
  • tests/e2e/task-180-prompt-composer.spec.ts — 14 pure-function tests
  • backlog/tasks/task-180 - …md — Backlog task

Modified

  • src/renderer/state/terminal-store.ts — new state (promptComposerRequest, composerDrafts), open/close/setDraft actions, closeTerminal cleanup
  • src/renderer/components/TerminalPanel.tsx — context menu item (AI-only) between "Show prompts" and "Session summary"
  • src/renderer/components/CommandPalette.tsx — "Open Prompt Composer" entry (AI-only)
  • src/renderer/components/ShortcutsHelp.tsx — Ctrl+Alt+P listed under the AI category
  • src/renderer/hooks/useKeybindings.tsCtrl+Alt+P binding + event.code fallback for macOS Option-key combos
  • src/renderer/App.tsx — mounts <PromptComposer />
  • src/renderer/styles/global.css.prompt-composer-* styles, matches the SessionSummary card family

Out of scope

  • Persisting drafts across app restarts (session-only by design).
  • Auto-pressing Enter after Submit (tried it, behaved inconsistently with AI CLIs; deferred).

Validation

  • npx tsc --noEmit: no new errors introduced (same 32 pre-existing errors on this branch vs. main; remaining errors are all in unrelated code paths).
  • npx vite build --config vite.renderer.config.ts: succeeds.
  • npx playwright test tests/e2e/task-180-prompt-composer.spec.ts: 14/14 pass.
  • Existing related specs (paste-wrap, smart-unwrap-on-copy) still pass.
  • Manually smoke-tested in npm start: right-click AI pane → composer opens → Copy & Submit both work → Esc/backdrop close → draft persists across reopen → draft cleared on pane close → shortcut and Command Palette entry both hidden / no-op on plain shell panes.
assistance: agentic-cli
type: feature
agent-tool: copilot-cli
agent-model: claude-opus-4.7
work-item: TASK-180

Adds a notepad-style scratchpad to each terminal pane, accessible from the
pane right-click menu (📝 Prompt composer). Lets users compose long,
multi-line prompts in a real text editor before sending them - avoids the
fiddliness of editing multi-line input directly in the terminal and stops
stray Enter keys from submitting half-written messages.

The modal has three footer buttons:
- Copy:   writes the draft to the clipboard.
- Submit: bracketed-pastes the draft into the focused terminal. We do not
          also send Enter - the user reviews in the terminal and presses
          Enter themselves. Intentional: avoids accidental submission and
          Ink-based AI CLIs handle programmatic \r post-paste inconsistently.
- Close:  dismiss (also bound to Esc and backdrop click).

Drafts are per-terminal and persist for the session; they're dropped when
the owning pane closes (and the composer auto-dismisses if its target pane
goes away).

Reuses the existing prepareClipboardPaste helper for bracketed-paste
wrapping + CRLF→LF normalization (so Windows-CRLF drafts work cleanly).

Pure draft-map helpers (updateComposerDrafts, dropComposerDraft) extracted
to src/renderer/utils/prompt-composer.ts and covered by 14 focused tests in
tests/e2e/task-180-prompt-composer.spec.ts. All tests pass; tsc error count
unchanged vs main; renderer vite build succeeds.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@mpmisha mpmisha added the enhancement New feature or request label Jun 14, 2026
mpmisha and others added 2 commits June 14, 2026 10:37
…atcher

- Bind Ctrl+Alt+P (⌘⌥P on Mac) to open the prompt composer for the
  focused pane. Ctrl+Shift+P was already taken by the command palette.
- Surface the shortcut in the pane context menu hint, the Command
  Palette ('Open Prompt Composer'), and the Shortcuts Help overlay.
- Fix matchesCombo() to also compare against event.code on Mac for
  letter/digit keys. Without this, Option+P reports event.key='π'
  (Option+R → '®', etc.) and every Cmd+Option+<letter> shortcut
  silently no-ops on Mac. Side benefit: the pre-existing Ctrl+Alt+R
  (refresh pane) and Ctrl+Alt+N (new terminal in place) bindings now
  also work on Mac.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The prompt composer is mainly useful for drafting chat prompts for AI
CLIs; on a plain shell pane it would be a surprising surface. Hide it
in all three entry points when the focused/target pane has no
aiSessionId:

- Pane context menu item: wrapped in {aiSessionId && (...)}, same as
  'Show prompts' and 'Session summary'.
- Ctrl+Alt+P shortcut: no-ops when the focused pane isn't AI.
- Command Palette 'Open Prompt Composer' entry: conditionally included
  based on the focused pane's aiSessionId; useMemo dep added so the
  list rebuilds on focus changes.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant