Skip to content

Conversation

@ammar-agent
Copy link
Collaborator

Summary

Adds support for custom slash commands that run executables in the workspace.

Features

  • Discovery: Executables at .mux/commands/<name> are discovered and appear in slash command autocomplete
  • Execution: /<name> [args...] runs the command with:
    • First line tokens become argv
    • Lines after the first become stdin
    • Stdout streams in real-time via init events
    • Stdout becomes the user message on success
  • Environment: Commands receive MUX_* env vars (project path, runtime, workspace name, workspace path)

Example

#!/bin/bash
# .mux/commands/refinement
echo "Refine this:"
cat

Then use with: /refinement\n<text to refine>

Implementation

  • Backend: SlashCommandService for discovery and execution with streaming
  • Frontend: Parser extended with rawInput for unknown commands
  • Frontend: ChatInput wired to execute custom commands and show autocomplete
  • Docs: New page at docs/hooks/slash-commands.mdx

Testing

  • All slash command parser and suggestion tests pass
  • Static checks pass
  • New functionality is exercised through manual testing

Generated with mux • Model: anthropic:claude-opus-4-5 • Thinking: high • Cost: $11.85

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c8152aa515

ℹ️ 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".

@ammar-agent ammar-agent added the docs Improvements or additions to documentation label Jan 9, 2026
@ammar-agent
Copy link
Collaborator Author

@codex review

Addressed the P1 and P2 review comments:

  • P1: Now quoting command path before exec to handle spaces in workspace paths
  • P2: Removed .trim() from stdin processing to preserve whitespace

Also added:

  • Exit code 2 handling (show output but don't send to model)
  • Progressive examples in docs (static msg, args, stdin)
  • UI integration tests covering suggestions, execution, exit codes
  • Unit tests for custom command suggestions

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ccbeaea806

ℹ️ 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".

@ammar-agent
Copy link
Collaborator Author

@codex review

Addressed additional review comments:

  • P2: Now accumulating raw stdout bytes to preserve blank lines (LineBuffer drops empty lines for streaming display, but the final output preserves them)
  • P3: Now restoring input when command produces no output (consistent with other error paths)

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 04ddac9a3d

ℹ️ 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".

@ammar-agent
Copy link
Collaborator Author

@codex review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 11cc4f1b8e

ℹ️ 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".

Adds support for custom slash commands that run executables in the workspace.

## Features

- **Discovery**: Executables at `.mux/commands/<name>` are discovered and
  appear in slash command autocomplete.

- **Execution**: `/<name> [args...]` runs the command with:
  - First line tokens become argv
  - Lines after the first become stdin
  - Stdout streams in real-time via init events
  - Stdout becomes the user message on success

- **Environment**: Commands receive MUX_* env vars (project path, runtime,
  workspace name, workspace path).

## Implementation

- Backend: SlashCommandService for discovery and execution with streaming
- Frontend: Parser extended with rawInput for unknown commands
- Frontend: ChatInput wired to execute custom commands and show autocomplete
- Docs: New page at docs/hooks/slash-commands.mdx

## Example

```bash
#!/bin/bash
# .mux/commands/refinement
echo "Refine this:"
cat
```

Then use with: `/refinement\n<text to refine>`
- Quote command path before exec to handle spaces in workspace paths (P1)
- Preserve stdin whitespace - don't trim multiline input (P2)
- Add exit code 2 handling: show output but don't send to model
- Update docs with progressive examples (static msg, args, stdin)
- Add comprehensive UI integration tests for custom slash commands
- Add unit tests for custom command suggestions
- Remove UI integration tests that were timing out in CI
- Add backend integration tests for slash command functionality:
  - Command discovery (list)
  - Command execution (run)
  - Exit code handling (0, 2, others)
  - Argument and stdin passing
- P2: Preserve blank lines in command stdout by accumulating raw bytes
  instead of using LineBuffer (which drops empty lines)
- P3: Restore input when command produces no output (consistent error handling)
Static files are read verbatim (no execution required):
- .mux/commands/<name>.txt
- .mux/commands/<name>.md

This is simpler than writing an executable script for static prompts.
Static files are preferred over executables with the same base name
(.txt checked first, then .md, then bare executable).
- Add 'custom' badge to distinguish custom commands from built-in ones
- Add 'Add custom commands' docs link in autocomplete footer
- Add isCustom property to SlashSuggestion type
- Add slashCommands mock support for storybook
- Create App.slashCommands.stories.tsx with:
  - BuiltInCommands: shows standard slash commands
  - WithCustomCommands: shows custom commands with badge
  - FilteredCommands: shows filtering behavior
Reduces duplication between static file and executable command paths by:
- Adding withCommandLifecycle() to handle init-start/end lifecycle and error handling
- Adding emitOutput() helper for streaming lines
- Both runStaticFile() and runExecutable() now use these helpers

Net reduction: ~50 lines (~15% less code)
- Badge now appears before command name to reduce visual scanning
- Custom command text uses plan-mode-light color for visual distinction
- Drop .txt support, only .md files for static commands
- Parse YAML frontmatter from .md files for description field
- Parse magic comment '# mux: <description>' from executables
- API returns skippedInvalidNames to help users debug invalid command names
- Badge now appears after command name for consistent vertical alignment
- Descriptions shown in autocomplete suggestions

New shared utility: src/node/utils/markdown.ts (simple frontmatter parsing)
- Frontmatter field changed from 'description' to 'usage'
- Executable comment changed from '# mux: ...' to '# usage: ...'
- Updated all docs examples to show usage comments
- Pattern is case-insensitive for flexibility

The 'usage:' pattern is more conventional and self-documenting.
Replace generic /context example with /todo - finds TODO/FIXME comments
and asks the model to help address them. More practical demonstration
of dynamic content.
Adds a deterministic streaming test that uses file-based synchronization
to prove output accumulates progressively during slash command execution.

The test creates an executable command that signals via temp files between
steps, allowing the test to verify streaming works without timing-based
flakiness.
When switching between storybook stories, the MemoryRouter was not
re-reading initialEntries from localStorage because it wasn't being
remounted. This caused custom slash commands to not appear because
the router stayed on the previous story's workspace.

Adding key={storyId} forces AppLoader (and its child MemoryRouter)
to remount when the story changes, ensuring the router reads the
correct workspace selection from localStorage.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant