script

package
v0.0.22 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ShouldSkipScriptFile

func ShouldSkipScriptFile(filename string) bool

ShouldSkipScriptFile returns true if the given filename looks like an editor swap file, backup file, or other temporary file that should not be registered as a script.

It checks for:

  • Hidden files (filenames starting with ".")
  • Known temporary/swap file suffixes (.swp, .swo, ~, .bak, .tmp, .orig, .rej)
  • Emacs auto-save files (filenames wrapped in "#", e.g. #deploy.sh#)

Types

type ExecutionRequester

type ExecutionRequester interface {
	// RequestScriptExecution sends an execute command to a connected agent-manager
	// using the provided requestID for tracking the result.
	RequestScriptExecution(requestID string, projectID string, script *Script) error
	// RequestScriptStop sends a stop command to connected agent-managers
	// for the given project to cancel a running script execution.
	RequestScriptStop(projectID string, requestID string) error
}

ExecutionRequester is an interface for triggering script execution on agent-managers.

type Repository

type Repository interface {
	Create(ctx context.Context, s *Script) error
	Get(ctx context.Context, id string) (*Script, error)
	List(ctx context.Context, projectID string, limit, offset int) ([]*Script, int, error)
	FindByName(ctx context.Context, projectID, name string) (*Script, error)
	Update(ctx context.Context, s *Script) error
	Delete(ctx context.Context, id string) error
}

type Script

type Script struct {
	ID          string    `yaml:"id"`
	ProjectID   string    `yaml:"project_id"`
	Name        string    `yaml:"name"`
	Description string    `yaml:"description"`
	Filename    string    `yaml:"filename"`
	Content     string    `yaml:"content"`
	IsSynced    bool      `yaml:"is_synced"`
	CreatedAt   time.Time `yaml:"created_at"`
	UpdatedAt   time.Time `yaml:"updated_at"`
}

type ScriptExecutionBroker

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

ScriptExecutionBroker manages per-request channels for streaming script execution output to frontend subscribers. It supports late joiners by buffering all events for each execution.

func NewScriptExecutionBroker

func NewScriptExecutionBroker() *ScriptExecutionBroker

NewScriptExecutionBroker creates a new broker for streaming script output.

func (*ScriptExecutionBroker) ActiveCount

func (b *ScriptExecutionBroker) ActiveCount() int

ActiveCount returns the number of currently active (non-completed) executions.

func (*ScriptExecutionBroker) CompleteExecution

func (b *ScriptExecutionBroker) CompleteExecution(requestID string, success bool, exitCode int32, logEntries []*taskguildv1.ScriptLogEntry, errorMessage string, stoppedByUser bool)

CompleteExecution marks an execution as complete and sends the completion event to all subscribers. Subscriber channels are closed after sending.

func (*ScriptExecutionBroker) Drain

Drain blocks until all active executions have completed or the context is cancelled (e.g. timeout). Must call SetDraining(true) before calling Drain. Returns the context error if the context was cancelled before all executions completed, or nil if all executions completed successfully.

func (*ScriptExecutionBroker) GetProjectID

func (b *ScriptExecutionBroker) GetProjectID(requestID string) string

GetProjectID returns the projectID for a given requestID, or empty string if unknown.

func (*ScriptExecutionBroker) IsDraining

func (b *ScriptExecutionBroker) IsDraining() bool

IsDraining returns true if the broker is in draining mode (rejecting new executions in preparation for graceful shutdown).

func (*ScriptExecutionBroker) ListExecutions

func (b *ScriptExecutionBroker) ListExecutions(projectID string) []*taskguildv1.ScriptExecutionInfo

ListExecutions returns information about all executions for a given project (both active and recently completed within TTL).

func (*ScriptExecutionBroker) PushOutput

func (b *ScriptExecutionBroker) PushOutput(requestID string, entries []*taskguildv1.ScriptLogEntry)

PushOutput sends an output chunk to all subscribers and buffers it for late joiners. It is a no-op if the execution is not registered or already completed.

func (*ScriptExecutionBroker) RegisterExecution

func (b *ScriptExecutionBroker) RegisterExecution(requestID, scriptID, projectID string)

RegisterExecution registers a new script execution. Must be called before PushOutput or CompleteExecution for the given requestID.

func (*ScriptExecutionBroker) RemoveExecution

func (b *ScriptExecutionBroker) RemoveExecution(requestID string)

RemoveExecution removes a registered execution that was never started (e.g. when sending the command to the agent fails after registration).

func (*ScriptExecutionBroker) SetDraining

func (b *ScriptExecutionBroker) SetDraining(draining bool)

SetDraining sets the draining flag. When draining, the broker signals when all active executions have completed.

func (*ScriptExecutionBroker) StartCleanup

func (b *ScriptExecutionBroker) StartCleanup(ctx context.Context)

StartCleanup starts a background goroutine that periodically removes expired completed executions. It stops when the context is cancelled.

func (*ScriptExecutionBroker) Subscribe

func (b *ScriptExecutionBroker) Subscribe(requestID string) (<-chan *taskguildv1.ScriptExecutionEvent, func())

Subscribe returns a channel that receives ScriptExecutionEvents for the given requestID. The channel is closed when the execution completes. A cleanup function is returned to unsubscribe. Returns nil channel if the requestID is unknown.

Late joiners receive all buffered events immediately before live events.

type Server

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

func NewServer

func NewServer(repo Repository, execReq ExecutionRequester, broker *ScriptExecutionBroker) *Server

func (*Server) ExecuteScript

ExecuteScript triggers execution of a script on a connected agent-manager.

func (*Server) ListActiveExecutions

ListActiveExecutions returns currently running and recently completed executions.

func (*Server) StopScriptExecution

StopScriptExecution stops a running script execution by sending a stop command to the agent.

func (*Server) StreamScriptExecution

StreamScriptExecution streams real-time output from a script execution.

func (*Server) SyncScriptsFromDir

SyncScriptsFromDir scans a directory for .claude/scripts/* files and syncs them.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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