Skip to content

feat(cli): add /editor to compose prompts in $EDITOR#194

Merged
emal-avala merged 1 commit intomainfrom
feat/editor-command
Apr 23, 2026
Merged

feat(cli): add /editor to compose prompts in $EDITOR#194
emal-avala merged 1 commit intomainfrom
feat/editor-command

Conversation

@emal-avala
Copy link
Copy Markdown
Member

Summary

New /editor slash command (alias /ed) that opens the user's editor on a tempfile, then submits the contents as the user turn when the editor exits.

> /editor
(vim opens; write multi-paragraph prompt; :wq)
<agent receives the composed prompt and responds>

> /editor initial draft text
(editor opens pre-filled with "initial draft text")

Why

rustyline is great for one-liners but painful for multi-paragraph prompts — \ continuations and no way to scroll back through what you've typed. `/editor` solves the most-requested readline limitation: compose long prompts in your real editor where tab/indent/copy-paste all work.

Editor resolution

  1. $VISUAL
  2. $EDITOR
  3. vim if on PATH
  4. vi if on PATH
  5. nano if on PATH

Returns a helpful error if none are found.

Behaviour details

  • Empty content → "Editor closed with empty content; nothing to send." (no turn submitted)
  • Lines starting with # are stripped (so the pre-fill hint at the bottom of a blank file doesn't leak into the prompt)
  • Pre-fill supported: /editor first draft text opens the editor already containing that text
  • Tempfile uses .md suffix so editors with markdown modes get syntax highlighting
  • Non-zero exit from the editor aborts (no prompt submitted)

Test plan

  • `cargo fmt --all` — clean
  • `cargo clippy --workspace --all-targets -- -D warnings` — clean
  • `cargo test -p agent-code --bin agent -- resolve_editor which_in_path` — 5/5 pass
    • `resolve_editor_prefers_visual` (VISUAL beats EDITOR)
    • `resolve_editor_falls_back_to_editor_env` (uses EDITOR when VISUAL unset)
    • `resolve_editor_ignores_empty_env` (empty/whitespace strings don't leak through)
    • `which_in_path_finds_shell` (sanity check: /bin/sh exists on *nix, cmd on Windows)
    • `which_in_path_rejects_missing` (nonexistent binary)
  • Manual: with `EDITOR=vim`, `/editor` opens an empty buffer with a hint; writing content and `:wq` submits; `:q!` (no save) cancels; `/editor pre` pre-fills with `pre`

Opens $VISUAL → $EDITOR → vim → vi → nano on a tempfile, reads the
contents back when the editor exits, and submits them as the user
turn. Empty content cancels. Lines starting with # are stripped
(so the pre-fill hint doesn't leak into the prompt).

  > /editor
  (vim opens; write multi-line prompt; :wq)
  <agent receives the composed prompt and responds>

  > /editor initial draft text
  (editor opens pre-filled with "initial draft text")

Unblocks the most-requested readline limitation: composing a long,
multi-paragraph prompt without wrangling rustyline's single-line
input and `\` continuations.

Alias: /ed
@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@emal-avala emal-avala merged commit 337e350 into main Apr 23, 2026
14 checks passed
@emal-avala emal-avala deleted the feat/editor-command branch April 23, 2026 05:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant