Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions source/Calamari.AiAgent/ClaudeCodeBehaviour/ClaudeCodeCliRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ public async Task<string> RunAsync(ClaudeCommandArgsBuilder argsBuilder,

if (File.Exists(verboseLogPath))
{
ThrowIfTranscriptTooBig(verboseLogPath);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This throws once the task has completed already right?
Wonder if we can keep track of this as we append the transcript and throw mid-execution, just to avoid this being a way to hide something malicious

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep track as in audit this?


log.WriteServiceMessage(new ServiceMessage(ClaudeCodeServiceMessages.Transcript.Name, new Dictionary<string, string>()
{
{ClaudeCodeServiceMessages.Transcript.TranscriptAttribute, await File.ReadAllTextAsync(verboseLogPath, cancellationToken)},
Expand All @@ -71,6 +73,14 @@ public async Task<string> RunAsync(ClaudeCommandArgsBuilder argsBuilder,
return responseBuilder.ToString();
}

static void ThrowIfTranscriptTooBig(string verboseLogPath)
{
const long maxTranscriptSize = 1L * 1024 * 1024 * 1024;
var transcriptSize = new FileInfo(verboseLogPath).Length;
if (transcriptSize > maxTranscriptSize)
throw new InvalidOperationException($"Claude agent transcript log is too large ({transcriptSize:N0} bytes). The 1 GB limit was exceeded.");
}

async Task ProcessError(Process process)
{
var buffer = new char[1024];
Expand Down