diff --git a/src/cai/repl/commands/load.py b/src/cai/repl/commands/load.py index c78a8f9c..a7889857 100644 --- a/src/cai/repl/commands/load.py +++ b/src/cai/repl/commands/load.py @@ -57,6 +57,7 @@ class LoadCommand(Command): jsonl_file = args[0] # Try to load the jsonl file try: + # fetch messages from JSONL file messages = load_history_from_jsonl(jsonl_file) console.print(f"[green]Jsonl file {jsonl_file} loaded[/green]") except BaseException: # pylint: disable=broad-exception-caught @@ -64,13 +65,10 @@ class LoadCommand(Command): # process console.print(f"[red]Error: Failed to load jsonl file {jsonl_file}[/red]") - # fetch messages from JSONL file and add them to message_history - import pprint - pprint.pprint(messages) - - # for message in messages: - # message_history.append(message) - + # add them to message_history + for message in messages: + message_history.append(message) + return True except Exception as e: # pylint: disable=broad-exception-caught console.print(f"[red]Error loading jsonl file: {str(e)}[/red]") diff --git a/tools/replay.py b/tools/replay.py index 4ab42921..5a729578 100644 --- a/tools/replay.py +++ b/tools/replay.py @@ -319,23 +319,23 @@ def main(): sys.exit(1) print(color(f"Loading JSONL file: {jsonl_file_path}", fg="blue")) - + try: # Load the full JSONL file to extract tool outputs full_data = load_jsonl(jsonl_file_path) - + # Extract tool outputs from events and find last assistant message tool_outputs = {} # Load the JSONL file for messages messages = load_history_from_jsonl(jsonl_file_path) - + # Attach tool outputs to messages for message in messages: if message.get("role") == "assistant" and message.get("tool_calls"): if "tool_outputs" not in message: message["tool_outputs"] = {} - + for tool_call in message.get("tool_calls", []): call_id = tool_call.get("id", "") if call_id in tool_outputs: @@ -361,7 +361,7 @@ def main(): active_time = usage[4] if len(usage) > 4 else 0 idle_time = usage[5] if len(usage) > 5 else 0 total_time = active_time + idle_time - + # Format time values as strings with units def format_time(seconds): """Format time in seconds to a human-readable string.""" @@ -371,7 +371,7 @@ def main(): # Convert seconds to hours, minutes, seconds hours, remainder = divmod(seconds, 3600) minutes, seconds = divmod(remainder, 60) - + if hours > 0: return f"{int(hours)}h {int(minutes)}m {int(seconds)}s" else: