Merge branch 'sipeed:main' into main

This commit is contained in:
anthrodjear 2026-05-05 06:31:54 +03:00 committed by GitHub
commit 6fb5531500
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 130 additions and 17 deletions

4
go.mod
View file

@ -10,7 +10,7 @@ require (
github.com/atc0005/go-teams-notify/v2 v2.14.0 github.com/atc0005/go-teams-notify/v2 v2.14.0
github.com/aws/aws-sdk-go-v2 v1.41.7 github.com/aws/aws-sdk-go-v2 v1.41.7
github.com/aws/aws-sdk-go-v2/config v1.32.17 github.com/aws/aws-sdk-go-v2/config v1.32.17
github.com/aws/aws-sdk-go-v2/service/bedrockruntime v1.50.5 github.com/aws/aws-sdk-go-v2/service/bedrockruntime v1.50.6
github.com/bwmarrin/discordgo v0.29.0 github.com/bwmarrin/discordgo v0.29.0
github.com/caarlos0/env/v11 v11.4.0 github.com/caarlos0/env/v11 v11.4.0
github.com/charmbracelet/lipgloss v1.1.0 github.com/charmbracelet/lipgloss v1.1.0
@ -52,7 +52,7 @@ require (
require ( require (
aead.dev/minisign v0.2.0 // indirect aead.dev/minisign v0.2.0 // indirect
filippo.io/edwards25519 v1.2.0 // indirect filippo.io/edwards25519 v1.2.0 // indirect
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.9 // indirect github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.10 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.19.16 // indirect github.com/aws/aws-sdk-go-v2/credentials v1.19.16 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.23 // indirect github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.23 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.23 // indirect github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.23 // indirect

8
go.sum
View file

@ -23,8 +23,8 @@ github.com/atc0005/go-teams-notify/v2 v2.14.0 h1:7N+xw+COnYANLREaAveQ65rsNQ12nIZ
github.com/atc0005/go-teams-notify/v2 v2.14.0/go.mod h1:EECsWM2b0Hvoz7O+QdlsvyN2KCUOFQCGj8bUBXv3A3Q= github.com/atc0005/go-teams-notify/v2 v2.14.0/go.mod h1:EECsWM2b0Hvoz7O+QdlsvyN2KCUOFQCGj8bUBXv3A3Q=
github.com/aws/aws-sdk-go-v2 v1.41.7 h1:DWpAJt66FmnnaRIOT/8ASTucrvuDPZASqhhLey6tLY8= github.com/aws/aws-sdk-go-v2 v1.41.7 h1:DWpAJt66FmnnaRIOT/8ASTucrvuDPZASqhhLey6tLY8=
github.com/aws/aws-sdk-go-v2 v1.41.7/go.mod h1:4LAfZOPHNVNQEckOACQx60Y8pSRjIkNZQz1w92xpMJc= github.com/aws/aws-sdk-go-v2 v1.41.7/go.mod h1:4LAfZOPHNVNQEckOACQx60Y8pSRjIkNZQz1w92xpMJc=
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.9 h1:adBsCIIpLbLmYnkQU+nAChU5yhVTvu5PerROm+/Kq2A= github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.10 h1:gx1AwW1Iyk9Z9dD9F4akX5gnN3QZwUB20GGKH/I+Rho=
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.9/go.mod h1:uOYhgfgThm/ZyAuJGNQ5YgNyOlYfqnGpTHXvk3cpykg= github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.10/go.mod h1:qqY157uZoqm5OXq/amuaBJyC9hgBCBQnsaWnPe905GY=
github.com/aws/aws-sdk-go-v2/config v1.32.17 h1:FpL4/758/diKwqbytU0prpuiu60fgXKUWCpDJtApclU= github.com/aws/aws-sdk-go-v2/config v1.32.17 h1:FpL4/758/diKwqbytU0prpuiu60fgXKUWCpDJtApclU=
github.com/aws/aws-sdk-go-v2/config v1.32.17/go.mod h1:OXqUMzgXytfoF9JaKkhrOYsyh72t9G+MJH8mMRaexOE= github.com/aws/aws-sdk-go-v2/config v1.32.17/go.mod h1:OXqUMzgXytfoF9JaKkhrOYsyh72t9G+MJH8mMRaexOE=
github.com/aws/aws-sdk-go-v2/credentials v1.19.16 h1:r3RJBuU7X9ibt8RHbMjWE6y60QbKBiII6wSrXnapxSU= github.com/aws/aws-sdk-go-v2/credentials v1.19.16 h1:r3RJBuU7X9ibt8RHbMjWE6y60QbKBiII6wSrXnapxSU=
@ -37,8 +37,8 @@ github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.23 h1:bpd8vxhlQi2r1hiueO
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.23/go.mod h1:15DfR2nw+CRHIk0tqNyifu3G1YdAOy68RftkhMDDwYk= github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.23/go.mod h1:15DfR2nw+CRHIk0tqNyifu3G1YdAOy68RftkhMDDwYk=
github.com/aws/aws-sdk-go-v2/internal/v4a v1.4.24 h1:OQqn11BtaYv1WLUowvcA30MpzIu8Ti4pcLPIIyoKZrA= github.com/aws/aws-sdk-go-v2/internal/v4a v1.4.24 h1:OQqn11BtaYv1WLUowvcA30MpzIu8Ti4pcLPIIyoKZrA=
github.com/aws/aws-sdk-go-v2/internal/v4a v1.4.24/go.mod h1:X5ZJyfwVrWA96GzPmUCWFQaEARPR7gCrpq2E92PJwAE= github.com/aws/aws-sdk-go-v2/internal/v4a v1.4.24/go.mod h1:X5ZJyfwVrWA96GzPmUCWFQaEARPR7gCrpq2E92PJwAE=
github.com/aws/aws-sdk-go-v2/service/bedrockruntime v1.50.5 h1:ZGTl4Rxft1uyENAlGESY04hMzE4cLLNUPI7dGw08haw= github.com/aws/aws-sdk-go-v2/service/bedrockruntime v1.50.6 h1:Wbo1WlWyGaAXlr6C7OGXq9avbdJhIV9cQ4M6E34b5x8=
github.com/aws/aws-sdk-go-v2/service/bedrockruntime v1.50.5/go.mod h1:jnugA+VgESQGgXuEKK6zVToET/DtODq7LQYpe+BkKT4= github.com/aws/aws-sdk-go-v2/service/bedrockruntime v1.50.6/go.mod h1:uY1fJe6m3I3w/m8UAkQ89Cm/ZAt/um6LW+AOZU33LDI=
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.9 h1:FLudkZLt5ci0ozzgkVo8BJGwvqNaZbTWb3UcucAateA= github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.9 h1:FLudkZLt5ci0ozzgkVo8BJGwvqNaZbTWb3UcucAateA=
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.9/go.mod h1:w7wZ/s9qK7c8g4al+UyoF1Sp/Z45UwMGcqIzLWVQHWk= github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.9/go.mod h1:w7wZ/s9qK7c8g4al+UyoF1Sp/Z45UwMGcqIzLWVQHWk=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.23 h1:pbrxO/kuIwgEsOPLkaHu0O+m4fNgLU8B3vxQ+72jTPw= github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.23 h1:pbrxO/kuIwgEsOPLkaHu0O+m4fNgLU8B3vxQ+72jTPw=

View file

@ -4,7 +4,6 @@ package agent
import ( import (
"context" "context"
"encoding/json"
"fmt" "fmt"
"maps" "maps"
"path/filepath" "path/filepath"
@ -171,15 +170,8 @@ func toolFeedbackExplanationFromMessages(messages []providers.Message) string {
} }
func toolFeedbackArgsPreview(args map[string]any, maxLen int) string { func toolFeedbackArgsPreview(args map[string]any, maxLen int) string {
if args == nil { argsJSON := utils.FormatArgsJSON(args, true, false)
args = map[string]any{} return utils.Truncate(argsJSON, maxLen)
}
argsJSON, err := json.MarshalIndent(args, "", " ")
if err != nil {
return utils.Truncate(fmt.Sprintf("%v", args), maxLen)
}
return utils.Truncate(string(argsJSON), maxLen)
} }
func shouldPublishToolFeedback(cfg *config.Config, ts *turnState) bool { func shouldPublishToolFeedback(cfg *config.Config, ts *turnState) bool {

View file

@ -1,12 +1,35 @@
package utils package utils
import ( import (
"bytes"
"encoding/json"
"fmt" "fmt"
"strings" "strings"
) )
const ToolFeedbackContinuationHint = "Continuing the current task." const ToolFeedbackContinuationHint = "Continuing the current task."
func FormatArgsJSON(args map[string]any, prettyPrint, disableEscapeHTML bool) string {
// Normalize nil to empty map for consistent output
if args == nil {
args = map[string]any{}
}
var buf bytes.Buffer
enc := json.NewEncoder(&buf)
if prettyPrint {
enc.SetIndent("", " ")
}
if disableEscapeHTML {
enc.SetEscapeHTML(false)
}
if err := enc.Encode(args); err != nil {
// Fallback to fmt.Sprintf to preserve visibility of problematic args
return fmt.Sprintf("%v", args)
}
return strings.TrimSpace(buf.String())
}
// FormatToolFeedbackMessage renders a tool feedback message for chat channels. // FormatToolFeedbackMessage renders a tool feedback message for chat channels.
// It keeps the tool name on the first line for animation and can include both // It keeps the tool name on the first line for animation and can include both
// a human explanation and the serialized tool arguments in the body. // a human explanation and the serialized tool arguments in the body.

View file

@ -1,6 +1,9 @@
package utils package utils
import "testing" import (
"encoding/json"
"testing"
)
func TestFormatToolFeedbackMessage(t *testing.T) { func TestFormatToolFeedbackMessage(t *testing.T) {
got := FormatToolFeedbackMessage( got := FormatToolFeedbackMessage(
@ -56,3 +59,98 @@ func TestFitToolFeedbackMessage_TruncatesSingleLineMessage(t *testing.T) {
t.Fatalf("FitToolFeedbackMessage() = %q, want %q", got, want) t.Fatalf("FitToolFeedbackMessage() = %q, want %q", got, want)
} }
} }
func TestFormatArgsJSON_Defaults(t *testing.T) {
args := map[string]any{"path": "README.md", "line": 42}
got := FormatArgsJSON(args, false, false)
var gotVal, wantVal any
if err := json.Unmarshal([]byte(got), &gotVal); err != nil {
t.Fatalf("FormatArgsJSON() returned invalid JSON: %v", err)
}
want := `{"path":"README.md","line":42}`
if err := json.Unmarshal([]byte(want), &wantVal); err != nil {
t.Fatalf("invalid test want JSON: %v", err)
}
if !jsonValEq(gotVal, wantVal) {
t.Fatalf("FormatArgsJSON() = %q, want %q", got, want)
}
}
func TestFormatArgsJSON_PrettyPrint(t *testing.T) {
args := map[string]any{"path": "README.md", "line": 42}
got := FormatArgsJSON(args, true, false)
var gotVal any
if err := json.Unmarshal([]byte(got), &gotVal); err != nil {
t.Fatalf("FormatArgsJSON() returned invalid JSON: %v", err)
}
want := `{"path":"README.md","line":42}`
var wantVal any
if err := json.Unmarshal([]byte(want), &wantVal); err != nil {
t.Fatalf("invalid test want JSON: %v", err)
}
if !jsonValEq(gotVal, wantVal) {
t.Fatalf("FormatArgsJSON() prettyPrint = %q, want structure %q", got, want)
}
}
func TestFormatArgsJSON_DisableEscapeHTML(t *testing.T) {
args := map[string]any{"msg": "a < b && c > d"}
got := FormatArgsJSON(args, false, true)
var gotVal, wantVal any
want := `{"msg":"a < b && c > d"}`
if err := json.Unmarshal([]byte(got), &gotVal); err != nil {
t.Fatalf("FormatArgsJSON() returned invalid JSON: %v", err)
}
if err := json.Unmarshal([]byte(want), &wantVal); err != nil {
t.Fatalf("invalid test want JSON: %v", err)
}
if !jsonValEq(gotVal, wantVal) {
t.Fatalf("FormatArgsJSON() disableEscapeHTML = %q, want %q", got, want)
}
}
func TestFormatArgsJSON_PrettyPrintAndDisableEscapeHTML(t *testing.T) {
args := map[string]any{"msg": "a < b && c > d"}
got := FormatArgsJSON(args, true, true)
var gotVal, wantVal any
want := `{"msg":"a < b && c > d"}`
if err := json.Unmarshal([]byte(got), &gotVal); err != nil {
t.Fatalf("FormatArgsJSON() returned invalid JSON: %v", err)
}
if err := json.Unmarshal([]byte(want), &wantVal); err != nil {
t.Fatalf("invalid test want JSON: %v", err)
}
if !jsonValEq(gotVal, wantVal) {
t.Fatalf("FormatArgsJSON() combined = %q, want %q", got, want)
}
}
func TestFormatArgsJSON_EscapeHTMLByDefault(t *testing.T) {
args := map[string]any{"msg": "a < b && c > d"}
got := FormatArgsJSON(args, false, false)
var gotVal, wantVal any
want := `{"msg":"a \u003c b \u0026\u0026 c \u003e d"}`
if err := json.Unmarshal([]byte(got), &gotVal); err != nil {
t.Fatalf("FormatArgsJSON() returned invalid JSON: %v", err)
}
if err := json.Unmarshal([]byte(want), &wantVal); err != nil {
t.Fatalf("invalid test want JSON: %v", err)
}
if !jsonValEq(gotVal, wantVal) {
t.Fatalf("FormatArgsJSON() default escape = %q, want %q", got, want)
}
}
func TestFormatArgsJSON_NilArgs(t *testing.T) {
got := FormatArgsJSON(nil, false, false)
want := `{}`
if got != want {
t.Fatalf("FormatArgsJSON() nil = %q, want %q", got, want)
}
}
func jsonValEq(a, b any) bool {
aJSON, _ := json.Marshal(a)
bJSON, _ := json.Marshal(b)
return string(aJSON) == string(bJSON)
}