Skip to content

Add first-class app-level slash command handling to chat (/help, /session)#114

Draft
IeuanWalker with Copilot wants to merge 2 commits into
mainfrom
copilot/add-slash-command-support
Draft

Add first-class app-level slash command handling to chat (/help, /session)#114
IeuanWalker with Copilot wants to merge 2 commits into
mainfrom
copilot/add-slash-command-support

Conversation

Copilot AI commented May 7, 2026

Copy link
Copy Markdown

Cockpit chat now supports slash commands directly in the app pipeline, without relying on external SDK argument autocomplete. Inputs starting with / are parsed and routed through a .NET command registry before normal LLM dispatch.

  • Slash command feature (new app abstraction)

    • Added SlashCommandFeature with reusable command metadata + handler routing.
    • Added command models (SlashCommandDefinition, SlashCommandContext, SlashCommandResult) for clean command registration and execution responses.
    • Implemented argument tokenization (including quoted args) in .NET.
  • Pipeline integration (pre-LLM command routing)

    • Integrated command interception in SessionFeature.SendMessageAsync.
    • Command inputs are handled locally and immediately:
      • user command is appended to chat
      • command response is appended as assistant/error message
      • SDK SendAsync is skipped for handled commands
    • Non-command inputs continue through existing chat behavior unchanged.
  • Built-in command set

    • /help: returns available commands with usage/description.
    • /session: returns current session metadata (id/title/model/working dir/branch).
    • Unknown/invalid commands return explicit guidance (e.g. Try /help, Usage: /session).
  • Dependency wiring

    • Registered SlashCommandFeature in DI and injected into SessionFeature.
  • Tests + discoverability

    • Added focused unit tests for non-command pass-through, help output, unknown command handling, /session behavior, and quoted argument parsing.
    • Updated README feature list to include built-in slash command support.
if(_slashCommandFeature.TryHandle(session, content, out SlashCommandResult? commandResult))
{
	AddCommandMessages(session, content, attachments, commandResult);
	_sessionListFeature.NotifyStateChanged();
	return;
}
Original prompt

Add first-class slash command support to the chat interface in IeuanWalker/Cockpit, implemented in the repository itself rather than relying on external SDK autocomplete support. The user has a chat interface in the app and wants slash commands to work now using .NET.

Implement a practical, app-level slash command system for the chat experience with these goals:

  • Detect chat inputs that start with / and treat them as commands.
  • Parse command name and arguments in .NET.
  • Route commands to handlers before normal LLM/chat processing.
  • Return a clear command response to the chat UI.
  • Provide an initial built-in command set sufficient to demonstrate the feature, such as /help and at least one additional example command relevant to the app.
  • Preserve normal chat behavior for non-command input.

Suggested scope:

  1. Inspect the existing chat interface and backend flow in IeuanWalker/Cockpit.
  2. Add a reusable slash command abstraction/registry in the .NET application.
  3. Integrate command handling into the existing chat request pipeline.
  4. Add at least minimal discoverability for commands, such as returning usage/help text from /help.
  5. If the frontend already supports suggestion UIs or metadata fetches, wire in a lightweight command metadata endpoint; otherwise keep the implementation focused on server-side command execution.
  6. Add or update tests if the repository has an existing test pattern.
  7. Update relevant docs/README if appropriate.

Constraints:

  • Create a pull request with the implementation.
  • Keep the design aligned with the repository’s current architecture and coding conventions.
  • Do not depend on unreleased Copilot SDK support for slash-command argument autocomplete.
  • Prefer a small, maintainable implementation over an over-engineered framework.

Context from the conversation:

  • The user asked how to allow slash commands to work now using .NET.
  • The repository is explicitly IeuanWalker/Cockpit.
  • The user then explicitly requested: "Yes please generate a PR for this".
  • A referenced issue in another repository (github/copilot-sdk#1219) is only motivational context about missing SDK autocomplete/ghost-text support for extension command arguments; the implementation should be in this app repo, not in github/copilot-sdk.

The following is the prior conversation context from the user's chat exploration (may be truncated):

User: How can i allow slash commands to work now? using .net?

Assistant: You can make slash commands work today in .NET by handling the entire command line yourself inside a normal extension command handler.

The short version:

  • Register a command like /cost
  • Accept the raw argument text after /cost
  • Parse subcommands/options in your .NET code
  • Provide your own help/usage output because SDK autocomplete/ghost text for extension command arguments does not exist yet

Given issue #1219 is about autocomplete/ghost text support, the current workaround is to make /cost a single entry point and implement argument parsing yourself.

Example shape in practice:

  • /cost
  • /cost help
  • /cost panel on
  • /cost session abc123
  • /cost --plan pro

What to do in .NET

  1. Expose a command handler from your extension.
  2. Read the raw command arguments as a string.
  3. Parse with:
    • System.CommandLine, or
    • a simple custom parser, or
    • Spectre.Console.Cli if you want richer command modeling
  4. Return helpful usage text when args are missing/invalid.

Recommended approach
Use System.CommandLine semantics in your own app/library, even if the Copilot SDK only gives you one command entry point. That lets you model subcommands cleanly.

Conceptually:

public static async Task<string> HandleCostCommandAsync(string rawArgs)
{
    var args = SplitArgs(rawArgs);

    if (args.Length == 0 || args[0] is "help" or "--help" or "-h")
        return GetHelpText();

    return args[0] switch
    {
        "panel" => await HandlePanelAsync(args.Skip(1).ToArray()),
        "session" => await HandleSessionAsync(args.Skip(1).ToArray()),
        "live-session" => await HandleLiveSessionAsync(args.Skip(1).ToArray()),
        _ => await HandleOptionsOrDefaultAsync(args)
    };
}

Example help text
Show this when the user types just /cost or invalid args:

/cost help
/cost panel on|off|refresh
/cost session <session-id>
/cost live-session <session-id>
/cost --plan pro|pro-plus|business|enterprise
/cost --billing-model usage-based|premium-requests
/cost --currency USD

Good UX workarounds right now

  • Make bare /cost show concise usage
  • Support /cost help
  • Accept forgiving aliases
  • Return validation errors with examples
  • If possible, emit clickable/suggested follow-up examples in your response text

For example:

  • “Unknown subcommand panle. Did you mean panel?”
  • “Usage: /cost panel on|off|refresh

If you mean “using a .NET extension specifically”
Then the answer is still: yes, ...

This pull request was created from Copilot chat.

Agent-Logs-Url: https://github.com/IeuanWalker/Cockpit/sessions/31cad225-5721-46b2-bdc6-b7aa9364c972

Co-authored-by: IeuanWalker <6544051+IeuanWalker@users.noreply.github.com>
Copilot AI changed the title [WIP] Add first-class slash command support to chat interface Add first-class app-level slash command handling to chat (/help, /session) May 7, 2026
Copilot AI requested a review from IeuanWalker May 7, 2026 14:41
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