feat(cli): add /md command to render markdown files#8305
feat(cli): add /md command to render markdown files#8305mvanhorn wants to merge 2 commits intoaaif-goose:mainfrom
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 70b57ebb13
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| println!("{}", console::style("⚠️ Note: /summarize has been renamed to /compact and will be removed in a future release.").yellow()); | ||
| Some(InputResult::Compact) | ||
| } | ||
| s if s.starts_with("/md ") => { |
There was a problem hiding this comment.
Match bare /md command before requiring an argument
The new slash-command branch only matches s.starts_with("/md "), so entering /md without a trailing space does not hit this handler and is treated as a normal chat message (InputResult::Message) instead of showing the intended usage/retry path. This causes an unintended model request whenever a user types /md directly (or removes the auto-inserted space), so the command parser should explicitly handle the exact /md token as invalid usage.
Useful? React with 👍 / 👎.
|
thanks @mvanhorn - do you want to sign the DCO so we can get this in? also - we are moving to ui/text for the TUI, may be worth considering there. |
Adds a /md <file> slash command that reads a markdown file and renders it in the terminal using the existing print_markdown function with bat-based syntax highlighting and theme support. Signed-off-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>
Typing /md without a space was falling through to chat instead of showing usage. Match the exact "/md" token in addition to "/md ". Signed-off-by: Matt Van Horn <mvanhorn@users.noreply.github.com> Signed-off-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>
70b57eb to
359a5a8
Compare
|
Signed both commits and force-pushed. Also added a fix for bare Good to know about the ui/text move for the TUI. Happy to port this there if that's the preferred path, or keep it in the current CLI layer if it still makes sense here. |
|
Hey @mvanhorn, thanks for the contribution! I'm going to close this one out for a couple of reasons:
We really do appreciate you taking the time to contribute though! If you'd like to keep working with us, we'd suggest picking one of your existing PRs to focus on and we can go from there. 🙏 |
|
Totally fair, thanks for explaining. I'll focus on getting #8271 across the line first and pace future submissions better. |
Summary
Adds a
/md <file>slash command to the interactive CLI session. Reads a markdown file and renders it in the terminal using the existingprint_markdownfunction (bat-based syntax highlighting, table extraction, theme support).Changes
crates/goose-cli/src/session/input.rs: Added/md <path>handler inhandle_slash_command(). Reads the file withstd::fs::read_to_string, renders viaprint_markdown_for_command, returnsInputResult::Retryto re-show the prompt.crates/goose-cli/src/session/output.rs: Addedpub fn print_markdown_for_command(content: &str)wrapper that callsprint_markdownwith the current theme fromget_theme().crates/goose-cli/src/session/completion.rs: Added/mdto the slash command completion list.Error handling: prints "Error reading : " for missing/unreadable files. Shows "Usage: /md " for empty path.
Testing
Verified via cargo clippy and cargo fmt. The implementation reuses existing, tested infrastructure (
print_markdown,get_theme,InputResult::Retrypattern).Fixes #8249
This contribution was developed with AI assistance (Codex).