Chat: offer the session's Claude Code skills and slash commands in the palette

The server reads the commands Claude Code's initialize response lists (bundled,
user, project, plugin and claude.ai-synced skills plus CLI commands, with
descriptions and argument hints), drops terminal-only ones, and serves them per
chat over a new chat_commands request without waiting for a CLI start. The
composer palette lists them after the recorded commands; choosing one inserts
"/<name> " and sending passes it to the harness as an ordinary prompt.
Codex, OpenCode and Pi chats reply with an empty list.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-25 20:53:57 +00:00
parent 4d91720849
commit d1390994cc
24 changed files with 924 additions and 23 deletions
@@ -18,10 +18,15 @@ class ComposerBarGateway implements ApiGateway {
Future<JsonMap> Function()? interrupt;
Future<JsonMap> Function()? stopTasks;
/// The `chat_commands` reply list: the session's harness commands.
List<JsonMap> commands = const [];
@override
Future<JsonMap> call(String type, [JsonMap fields = const {}]) async {
calls.add((type: type, fields: fields));
switch (type) {
case 'chat_commands':
return <String, dynamic>{'chat_commands': commands};
case 'chat_subscribe':
return <String, dynamic>{};
case 'chat_messages':
@@ -0,0 +1,59 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/conversation/chat_harness_command_loader.dart';
import 'package:pipelines_app/features/chat/domain/chat_commands.dart';
const _skill = ChatCommand.harness(
name: 'probe-skill',
summary: 'Probe',
usage: '/probe-skill',
);
void main() {
test('an empty reply is retried and found commands are kept', () async {
final replies = <List<ChatCommand>>[
const [],
const [_skill],
];
var calls = 0;
var loaded = 0;
final loader = ChatHarnessCommandLoader(() async {
calls += 1;
return replies.removeAt(0);
}, retryAfter: Duration.zero);
loader.request(() => loaded += 1);
await pumpEventQueue();
expect(loader.commands, isEmpty);
expect(loaded, 0);
loader.request(() => loaded += 1);
await pumpEventQueue();
expect(loader.commands.single.name, 'probe-skill');
expect(loaded, 1);
loader.request(() => loaded += 1);
await pumpEventQueue();
expect(calls, 2);
});
test('a recent empty or failed load is not asked again at once', () async {
var calls = 0;
final loader = ChatHarnessCommandLoader(() async {
calls += 1;
throw StateError('offline');
}, retryAfter: const Duration(hours: 1));
loader.request(() {});
await pumpEventQueue();
loader.request(() {});
await pumpEventQueue();
expect(calls, 1);
expect(loader.commands, isEmpty);
});
test('a host without a loader offers nothing', () async {
final loader = ChatHarnessCommandLoader(null);
loader.request(() => fail('no load'));
await pumpEventQueue();
expect(loader.commands, isEmpty);
});
}
@@ -0,0 +1,147 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'chat_composer_bar_fixtures.dart';
/// Desktop keyboard: Enter sends.
final _desktop = TargetPlatformVariant.only(TargetPlatform.linux);
void main() {
late ComposerBarGateway gateway;
late int sequence;
setUp(() {
gateway = ComposerBarGateway()
..page = fixtureTurn()
..commands = [
{
'name': 'code-review',
'description': 'Review the current diff',
'argument_hint': '[low|high]',
},
{'name': 'probe-skill', 'description': 'Probe skill (user)'},
{'name': 'anthropic-skills:pdf', 'description': 'PDF files'},
// Shadowed by the client's own /rename.
{'name': 'rename', 'description': 'Rename the conversation'},
];
sequence = 0;
});
tearDown(() => gateway.close());
Future<void> pumpComposer(WidgetTester tester) async {
await tester.pumpWidget(
composerThread(gateway, newOperationId: () => 'op/${++sequence}'),
);
await tester.pumpAndSettle();
}
Finder field() => find.byKey(const Key('chat-composer-field'));
Finder row(String name) => find.byKey(ValueKey<String>('chat-command-$name'));
Future<void> type(WidgetTester tester, String text) async {
await tester.enterText(field(), text);
await tester.pumpAndSettle();
}
testWidgets(
'the palette offers session skills after the recorded commands',
(tester) async {
await pumpComposer(tester);
await type(tester, '/');
final commandCalls = gateway.calls.where(
(call) => call.type == 'chat_commands',
);
expect(commandCalls, hasLength(1));
expect(commandCalls.single.fields['chat_query'], {
'session_id': isNotEmpty,
});
expect(row('new'), findsOneWidget);
expect(row('code-review'), findsOneWidget);
expect(row('probe-skill'), findsOneWidget);
expect(find.text('/code-review [low|high]'), findsOneWidget);
expect(find.text('Review the current diff'), findsOneWidget);
// The client's /rename wins over the harness's.
expect(row('rename'), findsOneWidget);
expect(find.text('Rename the conversation'), findsNothing);
final help = tester.getTopLeft(row('help')).dy;
expect(tester.getTopLeft(row('code-review')).dy, greaterThan(help));
await type(tester, '/co');
expect(row('code-review'), findsOneWidget);
expect(row('close'), findsNothing);
expect(row('probe-skill'), findsNothing);
// A namespaced skill matches on its own name too.
await type(tester, '/pd');
expect(row('anthropic-skills:pdf'), findsOneWidget);
// The list is fetched once, not per keystroke.
expect(
gateway.calls.where((call) => call.type == 'chat_commands'),
hasLength(1),
);
},
variant: _desktop,
);
testWidgets(
'choosing a skill inserts it with a space and sending prompts the harness',
(tester) async {
await pumpComposer(tester);
await type(tester, '/prob');
await tester.tap(row('probe-skill'));
await tester.pumpAndSettle();
expect(fieldText(tester), '/probe-skill ');
expect(gateway.promptBodies, isEmpty);
await type(tester, '/probe-skill banana');
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
await tester.pumpAndSettle();
expect(gateway.promptBodies.single['text'], '/probe-skill banana');
expect(find.textContaining('is not a command'), findsNothing);
},
variant: _desktop,
);
testWidgets(
'Enter completes a partial skill name, then a whole name sends',
(tester) async {
await pumpComposer(tester);
await type(tester, '/code-r');
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
await tester.pumpAndSettle();
expect(fieldText(tester), '/code-review ');
expect(gateway.promptBodies, isEmpty);
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
await tester.pumpAndSettle();
expect(gateway.promptBodies.single['text'], '/code-review');
},
variant: _desktop,
);
testWidgets('a slash word the harness does not list still asks first', (
tester,
) async {
await pumpComposer(tester);
await type(tester, '/nope now');
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
await tester.pumpAndSettle();
expect(gateway.promptBodies, isEmpty);
expect(find.textContaining('is not a command'), findsOneWidget);
}, variant: _desktop);
testWidgets('a harness without commands offers the recorded ones alone', (
tester,
) async {
gateway.commands = const [];
await pumpComposer(tester);
await type(tester, '/');
expect(row('new'), findsOneWidget);
expect(row('code-review'), findsNothing);
}, variant: _desktop);
}
@@ -0,0 +1,67 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/domain/chat_commands.dart';
import 'package:pipelines_app/features/chat/domain/chat_harness_commands.dart';
void main() {
final harness = chatHarnessCommandsFromWire([
{
'name': 'code-review',
'description': ' Review the diff ',
'argument_hint': '[low|high]',
},
{'name': '/probe-skill'},
{'name': 'anthropic-skills:pdf', 'description': 'PDF'},
{'name': 'Code-Review', 'description': 'duplicate'},
{'name': 'two words'},
{'name': ''},
{'name': 'help', 'description': 'shadowed'},
]);
test('wire entries become harness commands with usage and summary', () {
expect(harness.map((command) => command.name), [
'code-review',
'probe-skill',
'anthropic-skills:pdf',
'help',
]);
final review = harness.first;
expect(review.fromHarness, isTrue);
expect(review.takesArgument, isTrue);
expect(review.summary, 'Review the diff');
expect(review.usage, '/code-review [low|high]');
expect(harness[1].usage, '/probe-skill');
expect(chatHarnessCommandsFromWire(const []), isEmpty);
});
test('suggestions list recorded commands first, then matching skills', () {
final all = chatCommandSuggestions('/', harness);
expect(all.take(chatCommands.length), chatCommands);
expect(all.skip(chatCommands.length).map((command) => command.name), [
'code-review',
'probe-skill',
'anthropic-skills:pdf',
]);
expect(chatCommandSuggestions('/CODE', harness).single.name, 'code-review');
expect(
chatCommandSuggestions('/pdf', harness).single.name,
'anthropic-skills:pdf',
);
expect(chatCommandSuggestions('/code-review x', harness), isEmpty);
// Without harness commands the recorded list is unchanged.
expect(chatCommandSuggestions('/'), chatCommands);
});
test('a harness command is named only when no recorded command is', () {
expect(
chatHarnessCommandNamed('/code-review low', harness)?.name,
'code-review',
);
expect(
chatHarnessCommandNamed('/Probe-Skill', harness)?.name,
'probe-skill',
);
expect(chatHarnessCommandNamed('/help', harness), isNull);
expect(chatHarnessCommandNamed('/code', harness), isNull);
expect(chatHarnessCommandNamed('plain', harness), isNull);
});
}