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:
@@ -3,7 +3,8 @@ import 'package:flutter/material.dart';
|
||||
import '../domain/chat_commands.dart';
|
||||
|
||||
/// The command palette above the composer: the recorded commands matching the
|
||||
/// slash word, each with its own `/name` and summary.
|
||||
/// slash word, each with its own `/name` and summary, then the session's
|
||||
/// harness commands and skills with their argument hint and description.
|
||||
///
|
||||
/// Rows are standard Material `ListTile`s, so typography, colours and text
|
||||
/// scaling stay the theme's. The list is content-sized and never imposes a fixed height;
|
||||
@@ -52,8 +53,22 @@ class ChatCommandPalette extends StatelessWidget {
|
||||
ListTile(
|
||||
key: ValueKey<String>('chat-command-${commands[index].name}'),
|
||||
selected: index == selectedIndex,
|
||||
title: Text('/${commands[index].name}'),
|
||||
subtitle: Text(commands[index].summary),
|
||||
title: Text(
|
||||
commands[index].fromHarness
|
||||
? commands[index].usage
|
||||
: '/${commands[index].name}',
|
||||
),
|
||||
// A skill's description can run to a paragraph; two lines
|
||||
// identify it without crowding the list.
|
||||
subtitle: commands[index].summary.isEmpty
|
||||
? null
|
||||
: Text(
|
||||
commands[index].summary,
|
||||
maxLines: commands[index].fromHarness ? 2 : null,
|
||||
overflow: commands[index].fromHarness
|
||||
? TextOverflow.ellipsis
|
||||
: null,
|
||||
),
|
||||
onTap: () => onSelected(commands[index]),
|
||||
),
|
||||
],
|
||||
|
||||
@@ -20,6 +20,7 @@ import 'chat_command_actions.dart';
|
||||
import 'chat_command_palette.dart';
|
||||
import 'chat_composer_controller.dart';
|
||||
import 'chat_composer_paste_focus.dart';
|
||||
import 'chat_harness_command_loader.dart';
|
||||
import '../ui/transcript/chat_attachment_frame.dart';
|
||||
import '../../../ui/adaptive/glass_bar.dart';
|
||||
import '../../../ui/adaptive/glass_pill.dart';
|
||||
@@ -107,9 +108,11 @@ const String chatQueuedNotice =
|
||||
/// A leading `/` opens the recorded command palette
|
||||
/// above the field: rows are filtered by name prefix, Up/Down move the
|
||||
/// highlight, Enter or a tap completes the highlighted command, Escape closes
|
||||
/// the palette. A slash draft is never handed to the prompt path: `/new`,
|
||||
/// the palette. The session's harness commands and skills follow the recorded
|
||||
/// ones; a draft naming one is sent as an ordinary prompt for the harness to
|
||||
/// expand. No other slash draft is handed to the prompt path: `/new`,
|
||||
/// `/close` and `/rename` run through [commands], `/stop` and `/help` run
|
||||
/// locally or through the existing Stop path; text naming no recorded command
|
||||
/// locally or through the existing Stop path; text naming no known command
|
||||
/// becomes the web client's local no-send report with its explicit "Send as
|
||||
/// message" offer. Picked files are memory-only chips:
|
||||
/// their names are shown with the host's own remove action and the bounded
|
||||
@@ -135,8 +138,15 @@ class ChatComposerBar extends StatefulWidget {
|
||||
this.images,
|
||||
this.chatColor,
|
||||
this.limitBanner,
|
||||
this.loadHarnessCommands,
|
||||
});
|
||||
|
||||
/// Loads the session's harness commands and skills (`chat_commands`), which
|
||||
/// the palette offers after the recorded commands. Choosing one inserts
|
||||
/// `/<name> ` and sending passes the draft to the harness as a prompt. Null
|
||||
/// (no session) offers the recorded commands alone.
|
||||
final Future<List<ChatCommand>> Function()? loadHarnessCommands;
|
||||
|
||||
/// Builds the usage-limit banner above the pill (see
|
||||
/// ChatUsageLimitBanner); it is handed this bar's own send, so a scheduled
|
||||
/// draft carries its files and clears the composer as Send does.
|
||||
@@ -224,6 +234,11 @@ class _ChatComposerBarState extends State<ChatComposerBar> {
|
||||
/// The highlighted command row, wrapped to the filtered list on each build.
|
||||
int _selectedCommand = 0;
|
||||
|
||||
/// The session's harness commands, loaded on the first slash draft.
|
||||
late final ChatHarnessCommandLoader _harness = ChatHarnessCommandLoader(
|
||||
widget.loadHarnessCommands,
|
||||
);
|
||||
|
||||
/// The local no-send report shown under the field. Every slash draft takes
|
||||
/// this path instead of the prompt, as the web client records: an unknown
|
||||
/// command carries [_commandOffer] back for an explicit "Send as message".
|
||||
@@ -422,15 +437,24 @@ class _ChatComposerBarState extends State<ChatComposerBar> {
|
||||
/// the first send; only a partial word is completed first.
|
||||
bool _paletteCompletes() =>
|
||||
_paletteCommands().isNotEmpty &&
|
||||
chatCommandNamed(widget.composer.draft) == null;
|
||||
chatCommandNamed(widget.composer.draft) == null &&
|
||||
chatHarnessCommandNamed(widget.composer.draft, _harness.commands) == null;
|
||||
|
||||
/// The recorded commands matching the current draft while the palette is
|
||||
/// open. A dismissed or completed draft keeps its palette closed until the
|
||||
/// operator types something newer.
|
||||
/// The recorded and harness commands matching the current draft while the
|
||||
/// palette is open. A dismissed or completed draft keeps its palette closed
|
||||
/// until the operator types something newer.
|
||||
List<ChatCommand> _paletteCommands() {
|
||||
final draft = widget.composer.draft;
|
||||
if (_paletteClosedFor == draft) return const <ChatCommand>[];
|
||||
return chatCommandSuggestions(draft);
|
||||
return chatCommandSuggestions(draft, _harness.commands);
|
||||
}
|
||||
|
||||
/// Asks for the harness commands once a draft opens the palette.
|
||||
void _requestHarnessCommands(String draft) {
|
||||
if (chatCommandQuery(draft) == null) return;
|
||||
_harness.request(() {
|
||||
if (mounted) setState(() {});
|
||||
});
|
||||
}
|
||||
|
||||
/// Mirrors the typed text into the composer after clearing the per-keystroke
|
||||
@@ -438,7 +462,8 @@ class _ChatComposerBarState extends State<ChatComposerBar> {
|
||||
/// report, and resets the highlight when the filtered list no longer holds it
|
||||
/// (the web client's `refreshComposerControls`).
|
||||
void _onDraftEdited(String value) {
|
||||
final suggestions = chatCommandSuggestions(value);
|
||||
_requestHarnessCommands(value);
|
||||
final suggestions = chatCommandSuggestions(value, _harness.commands);
|
||||
setState(() {
|
||||
_paletteClosedFor = null;
|
||||
_dismissCommandReport();
|
||||
@@ -622,6 +647,12 @@ class _ChatComposerBarState extends State<ChatComposerBar> {
|
||||
}
|
||||
return;
|
||||
}
|
||||
// A session skill or harness command is the harness's to expand: the
|
||||
// draft goes out as an ordinary prompt, argument and all.
|
||||
if (chatHarnessCommandNamed(draft, _harness.commands) != null) {
|
||||
unawaited(_send());
|
||||
return;
|
||||
}
|
||||
final offer = draft.trim();
|
||||
setState(() {
|
||||
_commandFailed = true;
|
||||
@@ -691,11 +722,11 @@ class _ChatComposerBarState extends State<ChatComposerBar> {
|
||||
await _send();
|
||||
}
|
||||
|
||||
/// Puts the chosen recorded command in the composer and closes the palette.
|
||||
/// Nothing is sent to the agent: selecting a command is completion, not an
|
||||
/// execution path (this slice adds the palette, not the command actions).
|
||||
/// Puts the chosen command in the composer and closes the palette. Nothing
|
||||
/// is sent to the agent: selecting a command is completion, not an execution
|
||||
/// path. A harness command is followed by a space, ready for its arguments.
|
||||
void _completeCommand(ChatCommand command) {
|
||||
final text = '/${command.name}';
|
||||
final text = command.fromHarness ? '/${command.name} ' : '/${command.name}';
|
||||
setState(() {
|
||||
_paletteClosedFor = text;
|
||||
_selectedCommand = 0;
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
import 'dart:async';
|
||||
|
||||
import '../domain/chat_commands.dart';
|
||||
|
||||
/// Loads the session's harness commands (skills) for the composer palette the
|
||||
/// first time a slash draft asks for them, and keeps them once found.
|
||||
///
|
||||
/// An empty reply is not final: the server answers at once from what it knows
|
||||
/// and starts the session's CLI in the background, so the commands may arrive
|
||||
/// on a later ask. An empty or failed load is retried after [retryAfter] on the
|
||||
/// next slash draft; meanwhile the palette offers the recorded commands alone.
|
||||
class ChatHarnessCommandLoader {
|
||||
ChatHarnessCommandLoader(
|
||||
this._load, {
|
||||
this.retryAfter = const Duration(seconds: 3),
|
||||
});
|
||||
|
||||
final Future<List<ChatCommand>> Function()? _load;
|
||||
final Duration retryAfter;
|
||||
|
||||
List<ChatCommand> _commands = const <ChatCommand>[];
|
||||
bool _loading = false;
|
||||
DateTime? _lastEmpty;
|
||||
|
||||
/// The commands loaded so far, empty until a load found some.
|
||||
List<ChatCommand> get commands => _commands;
|
||||
|
||||
/// Starts a load unless commands are known, one is running, or the last one
|
||||
/// came back empty too recently; [onLoaded] runs when commands arrive.
|
||||
void request(void Function() onLoaded) {
|
||||
final load = _load;
|
||||
if (load == null || _commands.isNotEmpty || _loading) return;
|
||||
final lastEmpty = _lastEmpty;
|
||||
if (lastEmpty != null &&
|
||||
DateTime.now().difference(lastEmpty) < retryAfter) {
|
||||
return;
|
||||
}
|
||||
_loading = true;
|
||||
unawaited(() async {
|
||||
try {
|
||||
final commands = await load();
|
||||
if (commands.isEmpty) {
|
||||
_lastEmpty = DateTime.now();
|
||||
return;
|
||||
}
|
||||
_commands = List<ChatCommand>.unmodifiable(commands);
|
||||
onLoaded();
|
||||
} catch (_) {
|
||||
// The palette's recorded commands still work, and a typed skill can
|
||||
// still be sent through the unknown-command offer.
|
||||
_lastEmpty = DateTime.now();
|
||||
} finally {
|
||||
_loading = false;
|
||||
}
|
||||
}());
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,7 @@ import '../data/chat_attachment_images.dart';
|
||||
import '../data/chat_repository.dart';
|
||||
import '../domain/chat_activity_detail.dart';
|
||||
import '../domain/chat_notice.dart';
|
||||
import '../domain/chat_harness_commands.dart';
|
||||
import '../domain/chat_attachment_picker.dart';
|
||||
import '../domain/chat_colors.dart';
|
||||
import '../../../core/transport/pipelines_client.dart'
|
||||
@@ -1241,6 +1242,9 @@ class _ChatThreadViewState extends State<ChatThreadView> {
|
||||
composer: _composer,
|
||||
running: _controller.running,
|
||||
commands: _commandActions(),
|
||||
loadHarnessCommands: () async => chatHarnessCommandsFromWire(
|
||||
await ChatRepository(widget.gateway).commands(widget.sessionId),
|
||||
),
|
||||
picker: widget.attachmentPicker,
|
||||
images: _images,
|
||||
placeholder: chatComposerPlaceholderFor(
|
||||
|
||||
@@ -32,6 +32,21 @@ class ChatRepository {
|
||||
return value is List ? _maps(value) : const [];
|
||||
}
|
||||
|
||||
/// The slash commands and skills the session's harness offers
|
||||
/// (`chat_commands`), in the server's order. A harness without any replies
|
||||
/// with no list, which is an empty catalog.
|
||||
Future<List<JsonMap>> commands(String sessionId) async {
|
||||
final session = sessionId.trim();
|
||||
if (session.isEmpty) {
|
||||
throw ArgumentError('Select a chat session first.');
|
||||
}
|
||||
final reply = await gateway.call('chat_commands', {
|
||||
'chat_query': {'session_id': session},
|
||||
});
|
||||
final value = reply['chat_commands'];
|
||||
return value is List ? _maps(value) : const [];
|
||||
}
|
||||
|
||||
Future<JsonMap> selectModel(String sessionId, String provider, String model) {
|
||||
final session = sessionId.trim();
|
||||
if (session.isEmpty) {
|
||||
|
||||
@@ -13,12 +13,24 @@ class ChatCommand {
|
||||
required this.summary,
|
||||
required this.usage,
|
||||
this.takesArgument = false,
|
||||
this.fromHarness = false,
|
||||
});
|
||||
|
||||
/// A slash command or skill the session's harness reported (`chat_commands`).
|
||||
/// The client never runs it: the draft `/<name> args` is sent as an ordinary
|
||||
/// prompt and the harness expands it.
|
||||
const ChatCommand.harness({
|
||||
required this.name,
|
||||
required this.summary,
|
||||
required this.usage,
|
||||
}) : takesArgument = true,
|
||||
fromHarness = true;
|
||||
|
||||
final String name;
|
||||
final String summary;
|
||||
final String usage;
|
||||
final bool takesArgument;
|
||||
final bool fromHarness;
|
||||
}
|
||||
|
||||
const String chatCommandNew = 'new';
|
||||
@@ -79,16 +91,51 @@ String? chatCommandQuery(String draft) {
|
||||
}
|
||||
|
||||
/// The recorded commands matching [draft], filtered case-insensitively by name
|
||||
/// prefix. Empty when no palette should show.
|
||||
List<ChatCommand> chatCommandSuggestions(String draft) {
|
||||
/// prefix, then the session's [harness] commands (skills) matching it. A
|
||||
/// harness command named like a recorded one is shadowed: the client's own
|
||||
/// command runs. A namespaced harness name (`plugin:skill`) also matches on
|
||||
/// the part after its colon. Empty when no palette should show.
|
||||
List<ChatCommand> chatCommandSuggestions(
|
||||
String draft, [
|
||||
List<ChatCommand> harness = const <ChatCommand>[],
|
||||
]) {
|
||||
final query = chatCommandQuery(draft);
|
||||
if (query == null) return const <ChatCommand>[];
|
||||
return <ChatCommand>[
|
||||
for (final command in chatCommands)
|
||||
if (command.name.toLowerCase().startsWith(query)) command,
|
||||
for (final command in harness)
|
||||
if (!_isRecorded(command.name) && _harnessMatches(command.name, query))
|
||||
command,
|
||||
];
|
||||
}
|
||||
|
||||
bool _isRecorded(String name) {
|
||||
final lower = name.toLowerCase();
|
||||
return chatCommands.any((command) => command.name == lower);
|
||||
}
|
||||
|
||||
bool _harnessMatches(String name, String query) {
|
||||
final lower = name.toLowerCase();
|
||||
if (lower.startsWith(query)) return true;
|
||||
final colon = lower.lastIndexOf(':');
|
||||
return colon >= 0 && lower.substring(colon + 1).startsWith(query);
|
||||
}
|
||||
|
||||
/// The session [harness] command [draft]'s slash word names exactly
|
||||
/// (case-insensitive), or null. A recorded command of the same name wins, so
|
||||
/// this is asked only after [chatCommandNamed] found none.
|
||||
ChatCommand? chatHarnessCommandNamed(String draft, List<ChatCommand> harness) {
|
||||
final word = chatCommandWord(draft);
|
||||
if (word == null) return null;
|
||||
final name = word.substring(1).toLowerCase();
|
||||
if (_isRecorded(name)) return null;
|
||||
for (final command in harness) {
|
||||
if (command.name.toLowerCase() == name) return command;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// The slash word [draft] starts with, including its `/`, or null when the
|
||||
/// draft does not start with one. Only the first word counts, so an argument
|
||||
/// (`/rename My chat`) still names `/rename`.
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
import '../../../core/api_gateway.dart';
|
||||
import 'chat_commands.dart';
|
||||
|
||||
/// The session's harness commands from a `chat_commands` reply list: each
|
||||
/// entry's `name`, `description` and `argument_hint`. Entries without a usable
|
||||
/// single-word name are skipped and duplicates keep their first entry, in the
|
||||
/// server's order. A harness without commands yields an empty list.
|
||||
List<ChatCommand> chatHarnessCommandsFromWire(List<JsonMap> entries) {
|
||||
final seen = <String>{};
|
||||
final commands = <ChatCommand>[];
|
||||
for (final entry in entries) {
|
||||
var name = '${entry['name'] ?? ''}'.trim();
|
||||
if (name.startsWith('/')) name = name.substring(1);
|
||||
if (name.isEmpty || name.contains(RegExp(r'\s'))) continue;
|
||||
if (!seen.add(name.toLowerCase())) continue;
|
||||
final description = '${entry['description'] ?? ''}'.trim();
|
||||
final hint = '${entry['argument_hint'] ?? ''}'.trim();
|
||||
commands.add(
|
||||
ChatCommand.harness(
|
||||
name: name,
|
||||
summary: description,
|
||||
usage: hint.isEmpty ? '/$name' : '/$name $hint',
|
||||
),
|
||||
);
|
||||
}
|
||||
return commands;
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
# Chat harness commands and skills in the slash palette
|
||||
|
||||
User request (2026-11-25): the chat should offer every skill / slash command the
|
||||
operator's Claude Code has (bundled ones like `code-review`, `~/.claude/skills`,
|
||||
plugin and claude.ai-synced skills) with no import step.
|
||||
|
||||
## Verified live (Claude Code 2.1.332, haiku, scratch dir, no persistence)
|
||||
|
||||
- The `initialize` control response carries `commands: [{name, description,
|
||||
argumentHint}]` (80 entries here): skills of every source, with the source in
|
||||
the description (`(user)`, `(claude.ai sync)`, `(dynamic workflow)`), and the
|
||||
CLI's own commands. It arrives before any turn.
|
||||
- The `system`/`init` line (only after the first user message) has
|
||||
`slash_commands`, `skills` (names only), `plugins` and
|
||||
`terminal_slash_commands` (`doctor`, `color`, `focus`, `reload-plugins`).
|
||||
- A stream-json user message `/probe-skill banana` expanded a project skill;
|
||||
`/code-review low` ran the bundled skill (as a forked subagent, final answer on
|
||||
the main thread); `/import-memory` resolved to `anthropic-skills:import-memory`.
|
||||
So sending the slash text as an ordinary prompt is the supported path.
|
||||
|
||||
## Server
|
||||
|
||||
`chat_commands` (ChatQuery → `chat_commands: [{name, description,
|
||||
argument_hint}]`). Claude parses the initialize commands (dropping `__…`
|
||||
internals and duplicates), removes `terminal_slash_commands` once the init line
|
||||
names them, and never waits for a CLI: without a live CLI it answers from the
|
||||
latest list a CLI in the same directory reported and starts the CLI in the
|
||||
background. Codex, OpenCode and Pi reply with an empty list (not implemented).
|
||||
|
||||
## App
|
||||
|
||||
The composer asks for `chat_commands` on the first slash draft (retrying an
|
||||
empty reply after 3 s) and lists them after the recorded commands, filtered by
|
||||
prefix (a `plugin:skill` name also matches on `skill`). A harness name equal to
|
||||
a recorded command is shadowed. Choosing one inserts `/<name> `; sending a draft
|
||||
whose slash word is a harness command goes out as an ordinary prompt. Unknown
|
||||
slash words still get the local "Send as message" offer.
|
||||
|
||||
Unverified: rendered browser capture of the palette; device behaviour.
|
||||
@@ -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);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user