deliver slash commands typed so the Claude TUI runs them

The composer routed everything through tmux paste-buffer -p (bracketed
paste), and Claude's TUI deliberately doesn't parse a leading slash on
pasted input — so /command and /skill arrived as literal text instead of
running. Now a recognised command (single-line, leading slash, token in
ClaudeConfig's slash list) is delivered via send-keys -l (typed) so the
TUI fires it; everything else keeps the bracketed-paste path, which also
leaves a stray leading slash (e.g. a /tmp path) as literal text rather
than mis-parsing it. The slash list is warmed lazily when a Claude pane
opens so custom commands are recognised.

T-153.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-23 12:35:53 +02:00
co-authored by Claude Opus 4.7
parent 0a781de0cd
commit 5fad8dc430
8 changed files with 109 additions and 1 deletions
@@ -0,0 +1,38 @@
import 'package:clide/builtin/claude/src/slash_commands.dart';
import 'package:test/test.dart';
void main() {
group('slashCommandToken', () {
test('extracts the command word from single-line slash input', () {
expect(slashCommandToken('/model sonnet'), 'model');
expect(slashCommandToken('/whats-next'), 'whats-next');
expect(slashCommandToken('/foo\tbar'), 'foo');
});
test('returns null for non-command input', () {
expect(slashCommandToken('hello'), isNull);
expect(slashCommandToken(' /leading-space'), isNull);
expect(slashCommandToken('/'), isNull); // empty token
expect(slashCommandToken('/foo\nbar'), isNull); // multi-line
});
});
group('isKnownSlashCommand', () {
const known = {'model', 'clear', 'whats-next'};
test('true only when the token is a recognised command', () {
expect(isKnownSlashCommand('/model opus', known), isTrue);
expect(isKnownSlashCommand('/whats-next', known), isTrue);
expect(isKnownSlashCommand('/unknown-cmd', known), isFalse);
});
test('a path-like leading slash is not a command (stays literal)', () {
expect(isKnownSlashCommand('/tmp/foo.log has errors', known), isFalse);
});
test('non-slash and multi-line input is never a command', () {
expect(isKnownSlashCommand('hello world', known), isFalse);
expect(isKnownSlashCommand('/clear\nand more', {'clear'}), isFalse);
});
});
}
@@ -124,4 +124,14 @@ void main() {
]);
});
});
group('sendCommand', () {
test('types the text literally (no bracketed paste) then submits Enter', () async {
await tmux.sendCommand('clide-claude-foo', '/whats-next');
expect(runner.calls, [
['-L', 'clide', 'send-keys', '-t', 'clide-claude-foo', '-l', '--', '/whats-next'],
['-L', 'clide', 'send-keys', '-t', 'clide-claude-foo', 'Enter'],
]);
});
});
}