Skip to content

feat(vscode-ide-companion): support local clear slash commands#3111

Draft
yiliang114 wants to merge 1 commit intofollowup/2874-review-suggestionsfrom
feat/2621-vscode-clear-command
Draft

feat(vscode-ide-companion): support local clear slash commands#3111
yiliang114 wants to merge 1 commit intofollowup/2874-review-suggestionsfrom
feat/2621-vscode-clear-command

Conversation

@yiliang114
Copy link
Copy Markdown
Collaborator

TLDR

✅ Add a local /clear slash command to the VS Code IDE Companion so it is visible in slash completion and can explicitly trigger the fresh-session reset flow.
✅ The companion now supports /clear, /reset, and /new as equivalent entry points, while avoiding false positives for plain text like clear.
❓ This is a stacked follow-up and targets followup/2874-review-suggestions, not main.

Screenshots / Video Demo

N/A — this change is mainly about slash-command discoverability and session reset behavior, and I have not recorded a separate demo.

Reviewers can validate it directly in the VS Code IDE Companion using the test plan below.

Dive Deeper

Background and Motivation

In #2621, VS Code extension users explicitly asked for a more obvious way to clear the current context and start a fresh session, instead of relying only on the existing New Session UI.

The CLI already exposes /clear, with /reset and /new as aliases, but the VS Code IDE Companion did not surface that workflow explicitly.

Design Approach

This change does not introduce a second session-reset implementation. Instead, it reuses the companion’s existing “start a new session and clear the current conversation UI” flow.

The implementation works in three layers:

  1. A local slash-command definition is merged into the webview slash completion list so /clear is discoverable.
  2. Selecting that command still goes through the existing sendMessage pathway.
  3. SessionMessageHandler intercepts local fresh-session commands and routes them into the existing handleNewQwenSession() logic instead of treating them as normal prompts.

Implementation Details

  • Added localSlashCommands.ts
    • Defines the local fresh-session command set
    • Centralizes recognition of /clear, /reset, and /new
    • Merges the local clear command into ACP-provided availableCommands
  • Updated App.tsx
    • Slash completion now uses the merged command source
    • Selecting the slash item sends /${command.name}
  • Updated SessionMessageHandler.ts
    • Detects local fresh-session commands before normal prompt submission
    • Calls the existing new-session flow and emits conversationCleared
  • Added regression coverage
    • /clear starts a fresh session
    • /reset works as an alias
    • bare text clear is still treated as a normal prompt
    • local command merging does not duplicate an ACP-provided clear

Backward Compatibility

This does not change normal message submission behavior.

Only explicit slash commands /clear, /reset, or /new trigger the local fresh-session path. Plain text like clear continues to be sent as a normal prompt.

Performance Considerations

The change is limited to lightweight command merging and a small pre-send string check. It does not add any heavy state management or new async flows.

Runtime overhead should be negligible, and the main regression points are covered by targeted tests.

Reviewer Test Plan

Automated Verification

Run:

cd packages/vscode-ide-companion
npx vitest run src/webview/handlers/SessionMessageHandler.test.ts src/webview/providers/WebViewProvider.test.ts src/webview/utils/localSlashCommands.test.ts
npm run build:dev

Manual Validation

  1. Open the IDE Companion in VS Code.
  2. Type /cl in the input box and confirm /clear appears in slash completion.
  3. Select /clear and confirm the current conversation is cleared and a fresh session starts.
  4. Type /reset and send it, then confirm it behaves the same as /clear.
  5. Type /new and send it, then confirm it behaves the same as /clear.
  6. Type plain text clear and send it, then confirm it is treated as a normal message rather than resetting the session.
  7. If ACP also provides a clear command, confirm the slash list does not show duplicates.

Testing Matrix

🍏 🪟 🐧
npm run
npx
Docker - - -
Podman - - -
Seatbelt - - -

Notes:

  • Validation was performed locally on macOS.
  • No additional Windows, Linux, Docker, Podman, or Seatbelt verification was run.

Linked issues / bugs

Related to #2621

@github-actions
Copy link
Copy Markdown
Contributor

📋 Review Summary

This PR adds local slash command support (/clear, /reset, /new) to the VS Code IDE Companion, enabling users to explicitly trigger a fresh-session reset flow. The implementation is well-structured, reusing existing session management logic rather than introducing duplicate code paths. The changes are focused and include appropriate test coverage.

🔍 General Feedback

  • Good architectural decision: The implementation correctly reuses the existing handleNewQwenSession() logic rather than creating a second session-reset implementation.
  • Clean separation of concerns: The new localSlashCommands.ts module centralizes command recognition and merging logic.
  • Test coverage: Tests cover the main use cases including /clear, /reset aliases, and the important edge case that bare text clear should not trigger the reset.
  • Backward compatibility: The change correctly preserves existing behavior for plain text input.

🎯 Specific Feedback

🟢 Medium

  • File: localSlashCommands.ts:23-24 - The isLocalFreshSessionCommand function splits on whitespace but then checks if the token starts with /. Consider early-returning if the trimmed input doesn't start with / to avoid unnecessary string operations:
export function isLocalFreshSessionCommand(input: string): boolean {
  const trimmed = input.trim();
  if (!trimmed.startsWith('/')) {
    return false;
  }
  const token = trimmed.split(/\s+/, 1)[0]?.toLowerCase() ?? '';
  const normalized = token.slice(1);
  return LOCAL_FRESH_SESSION_COMMANDS.some((command) => command === normalized);
}
  • File: App.tsx:108-112 - The slashCommands memo dependency includes availableCommands which triggers re-computation whenever ACP sends updated commands. This is correct behavior, but consider adding a comment explaining why this memo is needed (to prevent duplicate clear commands when ACP also provides one).

  • File: SessionMessageHandler.ts:309-312 - The local fresh-session command check happens after the empty/whitespace guard but before image attachment processing. This is correct, but consider adding a comment explaining why /clear with attachments should still trigger the reset (or if it shouldn't, add a guard).

🔵 Low

  • File: localSlashCommands.ts:1 - Missing copyright header. The other files in this PR include the standard Qwen Team copyright license header (as seen in SessionMessageHandler.ts and App.tsx).

  • File: localSlashCommands.ts:10-12 - The CLEAR_COMMAND_DESCRIPTION mentions aliases but the description is only applied to the local clear command. Consider whether the description should be more explicit about what "fresh session" means for user clarity.

  • File: App.tsx:589-590 - The comment says "Handle slash commands by either invoking a local action or sending them as a message to the ACP session." However, the current implementation sends all slash commands as messages (including /clear), and the local action is handled in SessionMessageHandler. Consider clarifying the comment to reflect that the "local action" happens downstream in the message handler.

✅ Highlights

  • Well-designed command merging: The mergeLocalAvailableCommands function smartly avoids duplicates when ACP already provides a clear command, and the withClearAliases helper ensures consistent description text.
  • Precise command detection: The isLocalFreshSessionCommand function correctly requires the / prefix, preventing false positives from plain text like clear.
  • Comprehensive test coverage: The tests in SessionMessageHandler.test.ts cover the critical paths: /clear triggers reset, /reset works as an alias, and bare text clear is treated as a normal prompt.
  • Clean integration: The changes integrate seamlessly with the existing completion system and message handling flow without disrupting other functionality.

Copy link
Copy Markdown
Collaborator

@wenshao wenshao left a comment

Choose a reason for hiding this comment

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

No issues found. LGTM! ✅ — gpt-5.4 via Qwen Code /review

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