From fa9c98fb0549384c7a41c727aeb505971efdc44d Mon Sep 17 00:00:00 2001 From: Levi Neely Date: Wed, 20 May 2026 16:49:41 +0200 Subject: [PATCH] agent: add exec event role for ! command output Shell command output uses a dedicated "exec" role instead of "info", formatted with ``` fences in the chat log. --- pkg/agent/commands.go | 2 +- pkg/agent/core.go | 4 ++++ pkg/agent/core_test.go | 10 +++++----- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/pkg/agent/commands.go b/pkg/agent/commands.go index 30f4113..8386985 100644 --- a/pkg/agent/commands.go +++ b/pkg/agent/commands.go @@ -33,7 +33,7 @@ func (s *agent) handleCommand(ctx context.Context, input string) bool { s.emit(infoEvent("error: " + err.Error())) } if len(o) > 0 { - s.emit(infoEvent(strings.TrimRight(string(o), "\n"))) + s.emit(execEvent(strings.TrimRight(string(o), "\n"))) } return true } diff --git a/pkg/agent/core.go b/pkg/agent/core.go index 3f0e4b6..ecf935e 100644 --- a/pkg/agent/core.go +++ b/pkg/agent/core.go @@ -223,6 +223,10 @@ func infoEvent(text string) Event { return Event{Role: "info", Content: text + "\n"} } +func execEvent(text string) Event { + return Event{Role: "exec", Content: text} +} + // actionHandle holds the cancel function for the current agent turn. type actionHandle struct { cancel context.CancelCauseFunc diff --git a/pkg/agent/core_test.go b/pkg/agent/core_test.go index 4db6e21..40fd8f0 100644 --- a/pkg/agent/core_test.go +++ b/pkg/agent/core_test.go @@ -648,13 +648,13 @@ func TestShellCommand_Basic(t *testing.T) { c := newCore(t, nil, nil) evs := collectEvents(context.Background(), c, "!echo shellout") found := false - for _, s := range byRole(evs, "info") { + for _, s := range byRole(evs, "exec") { if strings.Contains(s, "shellout") { found = true } } if !found { - t.Errorf("!echo shellout: output not in info events: %v", byRole(evs, "info")) + t.Errorf("!echo shellout: output not in exec events: %v", byRole(evs, "exec")) } if c.IsRunning() { t.Error("IsRunning() = true after shell command; want false") @@ -2227,15 +2227,15 @@ func TestSetEnv_ShellCommandSeesEnv(t *testing.T) { c.SetEnv("OLLIE_TEST_VAR", "sentinel_value") evs := collectEvents(context.Background(), c, "!echo $OLLIE_TEST_VAR") - infos := byRole(evs, "info") + execs := byRole(evs, "exec") found := false - for _, s := range infos { + for _, s := range execs { if strings.Contains(s, "sentinel_value") { found = true } } if !found { - t.Errorf("shell command did not see OLLIE_TEST_VAR; info events: %v", infos) + t.Errorf("shell command did not see OLLIE_TEST_VAR; exec events: %v", execs) } }