Files
wehub-resource-sync 26f897c1ec
release / release-please (push) Failing after 1m49s
docs / build (push) Failing after 6m34s
release / build-and-upload (arm64, linux) (push) Has been cancelled
release / build-and-upload (arm64, windows) (push) Has been cancelled
release / build-darwin (amd64, darwin) (push) Has been cancelled
release / checksums (push) Has been cancelled
release / finalize (push) Has been cancelled
release / build-darwin (arm64, darwin) (push) Has been cancelled
release / build-and-upload (amd64, linux) (push) Has been cancelled
release / build-and-upload (amd64, windows) (push) Has been cancelled
docs / deploy (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:34:16 +08:00

56 lines
1.4 KiB
Go

package agent
import "fmt"
const (
// LifecyclePhaseStart marks native subprocess startup.
LifecyclePhaseStart = "start"
// LifecyclePhaseExit marks native subprocess exit.
LifecyclePhaseExit = "exit"
// LifecyclePhaseRetry marks a transient retry before the next subprocess attempt.
LifecyclePhaseRetry = "retry"
)
func emitAgentStarted(opts RunOpts, name string, pid int) {
emitLifecycle(opts, LifecycleEvent{
Agent: name,
Phase: LifecyclePhaseStart,
PID: pid,
Message: fmt.Sprintf("%s started pid=%d", name, pid),
})
}
func emitAgentExited(opts RunOpts, name string, pid int, err error) {
message := fmt.Sprintf("%s exited pid=%d status=success", name, pid)
if err != nil {
message = fmt.Sprintf("%s exited pid=%d error=%s", name, pid, err.Error())
}
emitLifecycle(opts, LifecycleEvent{
Agent: name,
Phase: LifecyclePhaseExit,
PID: pid,
Message: message,
})
}
func emitAgentRetry(opts RunOpts, name string, label string, attempt, max int) {
message := fmt.Sprintf("%s retrying after transient error %q (attempt %d/%d)", name, label, attempt, max)
if opts.OnLifecycle != nil {
emitLifecycle(opts, LifecycleEvent{
Agent: name,
Phase: LifecyclePhaseRetry,
Message: message,
})
return
}
if opts.OnChunk != nil {
opts.OnChunk(message)
}
}
func emitLifecycle(opts RunOpts, event LifecycleEvent) {
if opts.OnLifecycle != nil {
opts.OnLifecycle(event)
}
}