Skip to content

Add local /clear command support in the composer#23

Open
Copilot wants to merge 2 commits intomasterfrom
copilot/add-support-for-clear-command
Open

Add local /clear command support in the composer#23
Copilot wants to merge 2 commits intomasterfrom
copilot/add-support-for-clear-command

Conversation

Copy link
Contributor

Copilot AI commented Mar 12, 2026

Summary

  • Add a built-in local /clear slash command that is handled by Harnss instead of being forwarded to the active agent.
  • Route /clear through the existing new-chat flow so it behaves like clicking New Chat for the current project/session context.
  • Ensure /clear still works even when ACP options are loading or normal send gating would otherwise block composer submission.
  • Add focused tests for local command detection, command list composition, and replacement text across supported command sources.

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 💥 Breaking change (fix or feature that changes existing behavior)
  • 🎨 UI / design improvement
  • ⚡ Performance improvement
  • ♻️ Refactor (no functional changes)
  • 🧪 Tests / CI
  • 📝 Documentation

Related Issues

How to Test

  1. Open an existing chat and type / in the composer.
  2. Confirm /clear appears in slash command suggestions and inserts /clear locally without forwarding anything to the active agent.
  3. Submit /clear and confirm it opens a fresh chat, including while ACP options are loading.

Screenshots / Screen Recording

Local /clear command preview

Checklist

  • I've tested this on macOS (required for Electron/native features)
  • TypeScript compiles with no errors (pnpm build)
  • No any types introduced
  • Logical margins used (ms-*/me-* instead of ml-*/mr-*)
  • User-generated content containers have wrap-break-word
  • New shared types go in shared/types/, not src/types/
  • Large components/hooks are decomposed into sub-components/sub-hooks if needed
Original prompt

This section details on the original issue you should resolve

<issue_title>[Feature]: Add support for /clear command</issue_title>
<issue_description>### Problem / Motivation

rn /clear doesnt do anything, so you need to create a new session if you want clear context

Proposed Solution

Add support for /clear command

Alternatives Considered

No response

Area

Session Management

Relevant Engine

No response

How important is this to you?

Blocking my use of Harnss

Contribution

  • I'd be willing to submit a PR for this feature

Additional Context

No response</issue_description>

<agent_instructions>Add a special new command /clear (that will not be, once selected, forwarded to background agent).

This command will just open new chat for the user.</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@OpenSource03 Can you help me understand what should it do?

Like /clear would clear everything which is technically a new session... Does it make sense that it just moves you to new session as if you clicked new chat button? Or should it just clear existing chat and keep you inside (but in such case you completely lose history of it)</comment_new>


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

Co-authored-by: OpenSource03 <29690431+OpenSource03@users.noreply.github.com>
Copilot AI changed the title [WIP] [Feature] Add support for /clear command Add local /clear command support in the composer Mar 12, 2026
@OpenSource03 OpenSource03 marked this pull request as ready for review March 12, 2026 04:42
@OpenSource03 OpenSource03 requested a review from Copilot March 12, 2026 04:42
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a local-only /clear composer command that triggers the existing “new chat” flow (instead of being forwarded to the active engine), and integrates it into the slash-command UX and types.

Changes:

  • Introduces a built-in local /clear slash command, plus shared helper utilities for command list composition and replacement text.
  • Wires the composer’s /clear execution to AppLayout’s “open new chat” flow via a new onClear callback.
  • Extends SlashCommand.source with "local" and adds focused unit tests for helper behavior.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
src/components/InputBar.tsx Adds local /clear support, normalizes slash-command list/replacement logic, and routes /clear through onClear.
src/components/InputBar.test.ts Adds unit tests for local command injection/deduping, detection, and replacement text.
src/components/AppLayout.tsx Adds handleComposerClear to reuse the existing new-chat flow and passes it down to the composer.
shared/types/engine.ts Extends SlashCommand.source union to include "local".

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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: 22bba45d99

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".


interface InputBarProps {
onSend: (text: string, images?: ImageAttachment[], displayText?: string) => void;
onClear?: () => void | Promise<void>;

Choose a reason for hiding this comment

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

P1 Badge Require onClear prop for InputBar

/workspace/harnss/AGENTS.md explicitly forbids false optionals, but this change makes onClear optional even though the only runtime path (AppLayoutBottomComposerInputBar) provides it. Keeping it optional weakens the contract and allows future call sites to render a visible /clear command that silently does nothing except clear the composer, which is a maintainability and behavior regression the type system could prevent.

Useful? React with 👍 / 👎.

Copy link
Owner

Choose a reason for hiding this comment

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

@copilot fix this please

Comment on lines +1070 to +1074
if (isClearCommandText(trimmed)) {
try {
await onClear?.();
} finally {
clearComposer(el);

Choose a reason for hiding this comment

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

P2 Badge Prevent duplicate /clear submits while new chat is pending

This branch awaits onClear but does not set any in-flight guard before waiting, so when new-chat creation is slow users can press Enter (or click send) multiple times and trigger concurrent /clear executions. Because the composer is only cleared in finally, repeated submits can create multiple empty sessions from one intent; set a busy flag or clear/disable immediately before awaiting to make submission idempotent.

Useful? React with 👍 / 👎.

Copy link
Owner

Choose a reason for hiding this comment

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

@copilot fix this please

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.

[Feature]: Add support for /clear command

3 participants