Documentation
¶
Overview ¶
Package tasks manages long-running background shell commands and daemons with bounded memory+disk log streaming, stdin interaction, expect-regex waiting, session isolation, and recursive process-tree cleanup.
Index ¶
- Constants
- func DefaultShellName() string
- func FormatManageResult(res *ManageResult) string
- func FormatStartResult(res *StartResult) string
- func MergeEnv(extra map[string]string) []string
- func ResolveShell(name string) (string, []string, error)
- type ManageRequest
- type ManageResult
- type Manager
- func (m *Manager) Close()
- func (m *Manager) CloseSession(sessionID string) int
- func (m *Manager) Manage(ctx context.Context, req ManageRequest) (*ManageResult, error)
- func (m *Manager) SetEventHub(hub *events.Hub)
- func (m *Manager) Start(ctx context.Context, pol *policy.Engine, req StartRequest) (*StartResult, error)
- type StartRequest
- type StartResult
- type Status
- type TaskSummary
Constants ¶
const ( DefaultMaxConcurrent = 16 DefaultMaxRetained = 64 DefaultMaxMemLogBytes = 512 * 1024 // 512 KB rolling in-memory buffer per task DefaultMaxFileLogBytes = 50 * 1024 * 1024 // 50 MB max persisted log per task DefaultNormalWaitMs = 5000 DefaultDaemonWaitMs = 1500 MaxStartWaitMs = 30000 DefaultManageWaitMs = 15000 MaxManageWaitMs = 60000 DefaultNormalTimeout = 30 * time.Minute DefaultLogTailLines = 80 MaxInlineLogBytes = 24 * 1024 )
Variables ¶
This section is empty.
Functions ¶
func DefaultShellName ¶
func DefaultShellName() string
DefaultShellName returns the default shell dialect for the current OS.
func FormatManageResult ¶
func FormatManageResult(res *ManageResult) string
FormatManageResult renders a compact, LLM-friendly summary of a `task` tool invocation.
func FormatStartResult ¶
func FormatStartResult(res *StartResult) string
FormatStartResult renders a compact, LLM-friendly summary of a `spawn` tool invocation.
Types ¶
type ManageRequest ¶
type ManageRequest struct {
Action string `json:"action"` // list | status | logs | wait | input | kill | kill_all
TaskID string `json:"taskId,omitempty"`
Tail int `json:"tail,omitempty"`
Offset *int64 `json:"offset,omitempty"`
WaitMs int `json:"waitMs,omitempty"`
Expect string `json:"expect,omitempty"`
Input string `json:"input,omitempty"`
AppendNewline *bool `json:"appendNewline,omitempty"`
CloseStdin bool `json:"closeStdin,omitempty"`
SessionID string `json:"-"`
}
ManageRequest operates on existing background tasks.
type ManageResult ¶
type ManageResult struct {
Action string `json:"action"`
Tasks []TaskSummary `json:"tasks,omitempty"`
Task *TaskSummary `json:"task,omitempty"`
Output string `json:"output,omitempty"`
NextOffset int64 `json:"nextOffset,omitempty"`
TotalBytes int64 `json:"totalBytes,omitempty"`
Truncated bool `json:"truncated,omitempty"`
Matched bool `json:"matched,omitempty"`
MatchLine string `json:"matchLine,omitempty"`
TimedOut bool `json:"timedOut,omitempty"`
BytesWritten int `json:"bytesWritten,omitempty"`
KilledCount int `json:"killedCount,omitempty"`
}
ManageResult is the unified response for all task management actions.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager coordinates background shell tasks and daemons.
func NewManager ¶
NewManager creates a TaskManager storing per-task logs under <dataDir>/tasks when dataDir != "".
func (*Manager) Close ¶
func (m *Manager) Close()
Close shuts down the manager and terminates all running background process trees.
func (*Manager) CloseSession ¶
CloseSession kills all running tasks created by sessionID (used on HTTP DELETE /mcp).
func (*Manager) Manage ¶
func (m *Manager) Manage(ctx context.Context, req ManageRequest) (*ManageResult, error)
Manage executes list, status, logs, wait, input, kill, or kill_all actions.
func (*Manager) SetEventHub ¶
SetEventHub attaches an optional real-time event hub for streaming live task output.
func (*Manager) Start ¶
func (m *Manager) Start(ctx context.Context, pol *policy.Engine, req StartRequest) (*StartResult, error)
Start validates policy, launches a shell command, waits up to waitMs, and hands off to background if still running.
type StartRequest ¶
type StartRequest struct {
Command string `json:"command"`
Cwd string `json:"cwd,omitempty"`
Shell string `json:"shell,omitempty"`
Env map[string]string `json:"env,omitempty"`
Daemon bool `json:"daemon,omitempty"`
WaitMs *int `json:"waitMs,omitempty"`
TimeoutSec *int `json:"timeoutSec,omitempty"`
Name string `json:"name,omitempty"`
SessionID string `json:"-"`
}
StartRequest describes a command to run with hybrid sync-wait -> background handoff.
type StartResult ¶
type StartResult struct {
TaskID string `json:"taskId"`
Name string `json:"name,omitempty"`
PID int `json:"pid"`
Status Status `json:"status"`
Daemon bool `json:"daemon"`
Backgrounded bool `json:"backgrounded"`
Command string `json:"command"`
Cwd string `json:"cwd"`
ExitCode *int `json:"exitCode,omitempty"`
DurationMs int64 `json:"durationMs"`
Output string `json:"output"`
LogFile string `json:"logFile,omitempty"`
NextOffset int64 `json:"nextOffset"`
}
StartResult reports the initial outcome of starting a command.
type TaskSummary ¶
type TaskSummary struct {
TaskID string `json:"taskId"`
Name string `json:"name,omitempty"`
PID int `json:"pid"`
Status Status `json:"status"`
Daemon bool `json:"daemon"`
Command string `json:"command"`
Cwd string `json:"cwd"`
ExitCode *int `json:"exitCode,omitempty"`
StartedAt string `json:"startedAt"`
EndedAt string `json:"endedAt,omitempty"`
DurationMs int64 `json:"durationMs"`
TotalBytes int64 `json:"totalBytes"`
LogFile string `json:"logFile,omitempty"`
}
TaskSummary is a compact metadata view returned by list/status.