execute method
Execute the tool with the given input.
Implementation
@override
Future<ToolResult> execute(Map<String, dynamic> input) async {
if (!_state.isInPlanMode) {
return ToolResult.error('Not in plan mode. Use EnterPlanMode first.');
}
final summary = input['plan_summary'] as String? ?? '';
final enteredAt = _state.enteredAt;
final previousPlan = _state.exitPlanMode(summary);
onPlanModeChanged?.call(false);
final duration = enteredAt != null
? DateTime.now().difference(enteredAt).inSeconds
: null;
final buf = StringBuffer();
buf.writeln('Exited plan mode. All tools are now available.');
if (previousPlan != null) {
buf.writeln('Original reason: $previousPlan');
}
buf.writeln('Plan summary: $summary');
if (duration != null) {
buf.writeln('Time in plan mode: ${duration}s');
}
return ToolResult.success(buf.toString());
}