daemon

package
v1.1.41 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 19, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckExistingDaemon

func CheckExistingDaemon(workingDir string) (int, error)

CheckExistingDaemon checks if a daemon is already running for the given working directory. Returns the PID if a running daemon is found, or 0 if none.

func CleanupDaemon

func CleanupDaemon(workingDir string)

CleanupDaemon removes the PID file for the given working directory.

func ForkIntoBackground

func ForkIntoBackground(cfgFile, workingDir, sessionID string, extraArgs ...string) (int, error)

ForkIntoBackground re-execs the current binary as a background daemon. The child process argv[0] is set to "ggcode[dirname]". stdout/stderr are redirected to a log file. Returns the child PID; the caller (parent) should os.Exit(0).

func FormatPID

func FormatPID(pid int) string

FormatPID returns a human-readable PID string.

func LogFilePath

func LogFilePath(workingDir string) (string, error)

LogFilePath returns the log file path for a given working directory.

func PIDFilePath

func PIDFilePath(workingDir string) (string, error)

PIDFilePath returns the PID file path for a given working directory.

func RemovePIDFile

func RemovePIDFile(path string) error

RemovePIDFile deletes the PID file.

func Tr

func Tr(lang Lang, key string, args ...any) string

Tr looks up a localized string by key. Falls back to English if key missing.

func WritePIDFile

func WritePIDFile(path string, pid int, sessionID, workingDir string) error

WritePIDFile writes a PID file with daemon metadata.

Types

type DaemonInfo

type DaemonInfo struct {
	PID        int       `json:"pid"`
	SessionID  string    `json:"session_id"`
	WorkingDir string    `json:"working_dir"`
	StartedAt  time.Time `json:"started_at"`
}

DaemonInfo holds metadata about a running daemon process.

func ReadPIDFile

func ReadPIDFile(path string) (*DaemonInfo, error)

ReadPIDFile reads daemon info from a PID file.

type FollowSink

type FollowSink interface {
	// OnUserMessage displays a user message.
	OnUserMessage(text string)
	// OnToolStatus is called when a tool starts (used only for internal tracking, not display).
	OnToolStatus(toolName, rawArgs string)
	// OnToolResult displays the result of a tool call.
	OnToolResult(toolName, rawArgs, result string, isError bool)
	// OnStreamText accumulates streaming text (not displayed until OnRoundDone).
	OnStreamText(text string)
	// OnRoundDone displays the accumulated assistant text and a separator.
	OnRoundDone()
	// OnError displays an error message.
	OnError(err error)
	// Close cleans up the display.
	Close()
}

FollowSink receives agent events for terminal follow-mode display.

type Lang

type Lang string

Lang represents the display language for follow output.

const (
	LangZhCN Lang = "zh-CN"
	LangEn   Lang = "en"
)

func ResolveLang

func ResolveLang(s string) Lang

ResolveLang returns a Lang from a raw config language string.

type TerminalFollowDisplay

type TerminalFollowDisplay struct {
	// contains filtered or unexported fields
}

TerminalFollowDisplay renders agent activity to the terminal using ANSI codes.

func NewTerminalFollowDisplay

func NewTerminalFollowDisplay(out *os.File, lang Lang, workDir string, formatTool ToolFormatter) *TerminalFollowDisplay

NewTerminalFollowDisplay creates a new follow display writing to the given file. The formatTool callback is used to format tool status strings; if nil, tool names are displayed as-is.

func (*TerminalFollowDisplay) Close

func (d *TerminalFollowDisplay) Close()

Close cleans up.

func (*TerminalFollowDisplay) OnError

func (d *TerminalFollowDisplay) OnError(err error)

OnError displays an error message.

func (*TerminalFollowDisplay) OnRoundDone

func (d *TerminalFollowDisplay) OnRoundDone()

OnRoundDone displays the accumulated assistant text rendered as markdown.

func (*TerminalFollowDisplay) OnStreamText

func (d *TerminalFollowDisplay) OnStreamText(text string)

OnStreamText accumulates text for the current round.

func (*TerminalFollowDisplay) OnToolResult

func (d *TerminalFollowDisplay) OnToolResult(toolName, rawArgs, result string, isError bool)

OnToolResult displays the tool call result.

func (*TerminalFollowDisplay) OnToolStatus

func (d *TerminalFollowDisplay) OnToolStatus(toolName, rawArgs string)

OnToolStatus is a no-op — we only display final results via OnToolResult.

func (*TerminalFollowDisplay) OnUserMessage

func (d *TerminalFollowDisplay) OnUserMessage(text string)

OnUserMessage displays a user message with cyan header.

type ToolFormatter

type ToolFormatter func(toolName, rawArgs string) string

ToolFormatter is a function that formats tool activity for display. It takes a tool name and raw JSON args, and returns a human-readable status string.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL