agent: inject detached process output on exit
When a detached process exits, its output (last 2KB of ring buffer) is queued as a prompt wrapped in <detached-process-result> tags. The agent sees it on its next turn (or immediately if idle via Queue). - InjectSystemEvent(content) added to Core interface - SetOnExit(fn) added to execute.Server for external hook wiring
This commit is contained in:
parent
c0a52a8031
commit
f8ed2189f1
|
|
@ -540,6 +540,10 @@ func (s *agent) DismissDetached(pid int) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
func (s *agent) InjectSystemEvent(content string) {
|
||||
s.Queue("<detached-process-result>\n" + content + "\n</detached-process-result>")
|
||||
}
|
||||
|
||||
func (s *agent) AgentName() string {
|
||||
v := s.agentName
|
||||
s.log.Debug("AgentName() = %q", v)
|
||||
|
|
|
|||
|
|
@ -162,6 +162,11 @@ type Core interface {
|
|||
|
||||
// DismissDetached removes an exited process from the list.
|
||||
DismissDetached(pid int) bool
|
||||
|
||||
// InjectSystemEvent appends a system-originated message to the session
|
||||
// context and emits it on the event bus. The agent sees it on its next
|
||||
// turn; it appears in the chat log immediately.
|
||||
InjectSystemEvent(content string)
|
||||
}
|
||||
|
||||
// DetachedInfo describes a detached process for external consumers.
|
||||
|
|
|
|||
|
|
@ -89,6 +89,9 @@ func WithOnPreDispatch(fn func()) Option { return func(s *Server) { s.OnPreDispa
|
|||
// WithOnClose registers a hook called during Close.
|
||||
func WithOnClose(fn func()) Option { return func(s *Server) { s.OnClose = fn } }
|
||||
|
||||
// SetOnExit sets the hook called when a detached process exits.
|
||||
func (e *Server) SetOnExit(fn func(pid, exitCode int)) { e.OnExit = fn }
|
||||
|
||||
// WithOnEnvSet registers a hook called each time SetEnv is called.
|
||||
func WithOnEnvSet(fn func(key, value string)) Option { return func(s *Server) { s.OnEnvSet = fn } }
|
||||
|
||||
|
|
|
|||
Reference in New Issue