feat(process): capture stdout/stderr and fan out to subscribers
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
package process
|
||||
|
||||
import "os/exec"
|
||||
import (
|
||||
"io"
|
||||
"os/exec"
|
||||
"sync"
|
||||
)
|
||||
|
||||
// Status represents the status of a process for a workspace.
|
||||
type Status struct {
|
||||
@@ -9,9 +13,32 @@ type Status struct {
|
||||
PID int `json:"pid,omitempty"`
|
||||
}
|
||||
|
||||
// ExitInfo holds the exit reason of a process.
|
||||
type ExitInfo struct {
|
||||
Code int
|
||||
Signal string
|
||||
}
|
||||
|
||||
// Session holds the runtime state of a started OpenCode process.
|
||||
type Session struct {
|
||||
WorkspaceID string
|
||||
Root string
|
||||
Cmd *exec.Cmd
|
||||
Stdin io.WriteCloser
|
||||
Subscribers []Subscription
|
||||
Exit ExitInfo
|
||||
mu sync.Mutex
|
||||
}
|
||||
|
||||
// removeSubscription removes sub from s.Subscribers. It is safe to call when
|
||||
// the subscription is no longer present.
|
||||
func (s *Session) removeSubscription(sub *subscription) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
for i, cur := range s.Subscribers {
|
||||
if cur == sub {
|
||||
s.Subscribers = append(s.Subscribers[:i], s.Subscribers[i+1:]...)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user