truncation: avoid mid-rune cut with ToValidUTF8
This commit is contained in:
parent
7237980ff5
commit
93c0b374d5
|
|
@ -345,7 +345,7 @@ func run(ctx context.Context, cfg agentConfig, state state) error {
|
|||
}
|
||||
if !isErr && cfg.ToolResultMaxBytes > 0 && len(result) > cfg.ToolResultMaxBytes {
|
||||
orig := len(result)
|
||||
result = result[:cfg.ToolResultMaxBytes]
|
||||
result = strings.ToValidUTF8(result[:cfg.ToolResultMaxBytes], "")
|
||||
result += fmt.Sprintf("\n\n[HARD LIMIT: %s output truncated — %d of %d bytes shown. This is a safety ceiling, not a semantic boundary.]",
|
||||
tc.Name, cfg.ToolResultMaxBytes, orig)
|
||||
}
|
||||
|
|
|
|||
Reference in New Issue