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.
This commit is contained in:
Levi Neely 2026-05-20 16:49:41 +02:00
parent 1479aea274
commit fa9c98fb05
3 changed files with 10 additions and 6 deletions

View File

@ -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
}

View File

@ -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

View File

@ -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)
}
}