Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 18, 2025

Implementation Plan for Slash Command Parser

Based on the feedback to parse arguments like Bash with $ARGUMENTS, $1, $2, $3:

  • Create pkg/slashcommand directory structure
  • Implement ParseSlashCommand function with bash-like argument parsing
  • Create comprehensive table-driven tests following the repository's testing standards
  • Handle edge cases (missing slash, no params, quoted values with commas, etc.)
  • Ensure the function returns taskName (string), params (map[string]string), and error
  • Run linting and tests to validate implementation
  • Document the function with clear examples
  • Add package README with usage examples
  • Add example tests for documentation
  • Update to bash-like argument parsing per feedback
  • Remove old key=value parameter parsing functions

Implementation Complete ✅

The parser now uses bash-like argument parsing:

  • /fix-bug 123$ARGUMENTS="123", $1="123"
  • /code-review "PR #42" high$ARGUMENTS="\"PR #42\" high", $1="PR #42", $2="high"

Features:

  • Parses slash commands with bash-like arguments: /task-name arg1 "arg 2" arg3
  • Returns $ARGUMENTS with full argument string (quotes preserved)
  • Returns $1, $2, $3 etc. as positional arguments (quotes removed)
  • Supports both single and double quotes
  • Escape sequences work in double quotes (\")
  • Single quotes preserve everything literally
  • Comprehensive test coverage with 20 test cases
  • Removed unused key=value parsing functions (ParseParams, parseKeyValuePairs)

All tests pass successfully! The package is ready to use.

Original prompt

Examine https://opencode.ai/docs/commands/. I'd like to provide a pkg/slashcommand/ParseSlachCommand(string) (taskName, params, err)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 3 commits November 18, 2025 17:49
Co-authored-by: alexec <1142830+alexec@users.noreply.github.com>
Co-authored-by: alexec <1142830+alexec@users.noreply.github.com>
Co-authored-by: alexec <1142830+alexec@users.noreply.github.com>
Copilot AI changed the title [WIP] Add ParseSlashCommand function for handling commands Add ParseSlashCommand for parsing AI assistant slash commands Nov 18, 2025
Copilot AI requested a review from alexec November 18, 2025 17:54
@alexec
Copy link
Contributor

alexec commented Nov 18, 2025

@copilot What does OpenCode do for this?

Copy link
Contributor Author

Copilot AI commented Nov 18, 2025

@copilot What does OpenCode do for this?

I researched OpenCode (now continued as Crush by Charm) but couldn't find specific documentation about their slash command format since the original opencode.ai/docs/commands/ URL is not accessible and the project has been archived.

Based on the codebase, I can see this project already supports OpenCode's .opencode/command directory for task files (like in integration_test.go). The slash command parser I implemented follows common AI assistant patterns (similar to GitHub Copilot, Cursor, etc.) with the format /task-name param="value".

If you have specific documentation about OpenCode's slash command format or a different format you'd like me to follow, I'd be happy to adjust the implementation.

@alexec
Copy link
Contributor

alexec commented Nov 20, 2025

@copilot The parser should extract the arguments as follows:

$ARGUMENTS - the whole string
$1,$2,$3 - the positional arguments, parsed like Bash

@alexec
Copy link
Contributor

alexec commented Nov 20, 2025

@copilot you can remove support for the old key=vale syntax for parameters.

Changed from key=value format to bash-like positional arguments:
- Arguments now parsed like bash (quoted values with spaces supported)
- Returns $ARGUMENTS (full arg string) and $1, $2, $3 (positional args)
- Both single and double quotes supported
- Escape sequences work in double quotes

Co-authored-by: alexec <1142830+alexec@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Nov 20, 2025

@copilot The parser should extract the arguments as follows:

$ARGUMENTS - the whole string...

Updated the parser to use bash-like argument parsing. The function now returns:

  • params["ARGUMENTS"] - the full argument string (with quotes preserved)
  • params["1"], params["2"], params["3"] - positional arguments (with quotes removed)

Both single and double quotes are supported, and escape sequences work in double quotes. Commit: 138f60f

Copilot AI changed the title Add ParseSlashCommand for parsing AI assistant slash commands Add ParseSlashCommand for parsing AI assistant slash commands with bash-like arguments Nov 20, 2025
Removed ParseParams and parseKeyValuePairs functions that are no longer needed.
Kept Params type and Set/String methods which are still used by flag parsing.

Co-authored-by: alexec <1142830+alexec@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Nov 20, 2025

@copilot you can remove support for the old key=vale syntax for parameters.

Removed the old key=value parsing functions (ParseParams and parseKeyValuePairs). The Params type and its Set() method are kept as they're still used by the -p flag parsing. Commit: 042a8a0

@alexec alexec marked this pull request as ready for review November 20, 2025 15:54
@alexec alexec enabled auto-merge (squash) November 20, 2025 15:54
@alexec alexec merged commit 6d9fff9 into main Nov 20, 2025
1 check passed
@alexec alexec deleted the copilot/add-parse-slash-command-function branch November 20, 2025 15:55
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.

2 participants