diff --git a/app/lib/features/chat/domain/chat_turn_activity.dart b/app/lib/features/chat/domain/chat_turn_activity.dart index 5d2b0b16..e85a4c89 100644 --- a/app/lib/features/chat/domain/chat_turn_activity.dart +++ b/app/lib/features/chat/domain/chat_turn_activity.dart @@ -103,18 +103,38 @@ class ChatTurnActivityData { final noun = commands ? (calls.length == 1 ? 'command' : 'commands') : (calls.length == 1 ? 'tool' : 'tools'); + // A question still open is the agent waiting on the operator, not a + // stopped turn: say so instead of "Stopped after". + final asking = calls.any( + (p) => chatToolIsQuestion(p) && !chatToolSettled(p), + ); final summary = - '${unfinished + '${unfinished && !asking ? 'Stopped after' : commands ? 'Ran' : 'Used'} ${calls.length} $noun'; - return failed == 0 ? summary : '$summary · $failed failed'; + final status = asking ? '$summary · waiting for your answer' : summary; + return failed == 0 ? status : '$status · $failed failed'; } bool get failed => tools.any(chatToolFailed); } +/// Whether [tool] asks the operator a question (Claude Code's +/// AskUserQuestion, or a harness tool named like it). +bool chatToolIsQuestion(JsonMap tool) { + final name = chatToolLabel(tool).toLowerCase().replaceAll('_', ''); + return name == 'askuserquestion' || name == 'question'; +} + +/// Whether [tool] has a final state (completed, failed or answered). +bool chatToolSettled(JsonMap tool) { + final state = tool['state']; + final status = state is Map ? '${state['status']}' : '$state'; + return const ['completed', 'error', 'failed', 'done'].contains(status); +} + /// Whether [tool] is a shell command (`Ran N commands`), not another tool. bool chatToolIsCommand(JsonMap tool) => const [ 'bash', diff --git a/app/test/features/chat/domain/chat_turn_activity_question_test.dart b/app/test/features/chat/domain/chat_turn_activity_question_test.dart new file mode 100644 index 00000000..ad4eb83a --- /dev/null +++ b/app/test/features/chat/domain/chat_turn_activity_question_test.dart @@ -0,0 +1,35 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:pipelines_app/features/chat/domain/chat_turn_activity.dart'; + +Map _tool(String name, String status) => { + 'type': 'tool', + 'id': name, + 'name': name, + 'state': {'status': status, 'title': ''}, +}; + +void main() { + test('an open question reads as waiting for the operator, not stopped', () { + final activity = ChatTurnActivityData([ + _tool('Bash', 'completed'), + _tool('AskUserQuestion', 'pending'), + ], streaming: false); + expect(activity.label, 'Used 2 tools · waiting for your answer'); + }); + + test('an answered question is an ordinary used tool', () { + final activity = ChatTurnActivityData([ + _tool('Bash', 'completed'), + _tool('AskUserQuestion', 'completed'), + ], streaming: false); + expect(activity.label, 'Used 2 tools'); + }); + + test('another interrupted tool still reads as stopped', () { + final activity = ChatTurnActivityData([ + _tool('Bash', 'completed'), + _tool('Read', 'interrupted'), + ], streaming: false); + expect(activity.label, 'Stopped after 2 tools'); + }); +} diff --git a/internal/chattools/tools.go b/internal/chattools/tools.go index e8f3b33d..e6c065ad 100644 --- a/internal/chattools/tools.go +++ b/internal/chattools/tools.go @@ -26,7 +26,9 @@ func IsTool(name string) bool { const Instructions = "These tools act on Pipelines, the app the operator reads this chat in, not on your workspace. " + "Use show_file / show_image instead of telling the operator a path to open, show_html for diagrams, charts or small visual views, " + "show_diff when the operator asks to see changes or a diff (for example before submitting a pull request), " + - "and notify only when the operator should look at their phone now." + "and notify only when the operator should look at their phone now. " + + "Your thinking is not shown to the operator: before asking them a question (for example with AskUserQuestion), " + + "write what you found and why you are asking as a normal message, because the question form shows only the question and its options." type toolDefinition struct { Name string `json:"name"`