exec

package
v2.10.2 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 22 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package exec holds Scribe's execution tools: shell (foreground and background), project (detected test, lint, build and run commands) and git.

Index

Constants

View Source
const (
	StatusRunning = "running"
	StatusExited  = "exited"
	StatusKilled  = "killed"
)

Job statuses.

View Source
const NoTimeout = 1000 * time.Hour

NoTimeout is the limit to pass as Options.ToolTimeout for "no limit".

Variables

View Source
var Actions = []string{"test", "lint", "typecheck", "build", "format", "run"}

Actions lists the project actions in display order.

View Source
var ErrNoFormatter = errors.New("no format command detected for this project")

ErrNoFormatter means the project has no format command to run on a file.

View Source
var TeeDir string

TeeDir overrides where tee files are written. Empty means the user data directory: $XDG_DATA_HOME/lectern/scribe/tee, or %LOCALAPPDATA% on Windows.

Functions

func ChangedFiles

func ChangedFiles(dir string) ([]string, error)

ChangedFiles lists files that differ from HEAD or are untracked, as paths relative to dir. Files outside dir (when dir is a subdirectory of the repository) are left out.

func Ecosystems

func Ecosystems() []string

Ecosystems lists every ecosystem the detection table knows, in table order.

func FormatFile

func FormatFile(ctx context.Context, dir, abs string, timeout time.Duration) error

FormatFile runs the project's format command on one file, bounded by timeout, and returns once it has finished. Output is discarded; callers compare the file before and after to see what changed. A failing formatter is not an error here: the file is simply left as it was.

func GitContextBlock

func GitContextBlock(dir string) string

GitContextBlock returns the git state of dir for the system prompt: the branch with its upstream position, a count of staged, unstaged and untracked files, any merge conflicts, and the last few commits. It returns "" outside a repository.

func MutatesRepo

func MutatesRepo(tool string, args json.RawMessage) bool

MutatesRepo reports whether a call of tool with args changes the working tree or history: a git action from gitRepoActions, `branch switch`, or a shell command matching mutatingGit. Near-miss spellings ("cherry-pick", "Commit") are accepted, since models write them that way.

func NewProjectCheck

func NewProjectCheck(jobs *Jobs) tools.Tool

NewProjectCheck returns the read-only project check tool. It runs the same commands as the project tool, under the same command gate and timeouts.

func ProjectCommandsLine

func ProjectCommandsLine(dir string) string

ProjectCommandsLine returns the "Project commands" line for the system prompt: the detected lint, typecheck, test and build commands for dir, or "" when the project has none.

func Register

func Register(r *tools.Registry, jobs *Jobs)

Register adds the shell, shell_output, shell_kill, project and git tools to r. jobs holds background processes and the command rules; nil means no rules and a fresh job table.

func ScrubEnv

func ScrubEnv(environ []string) []string

ScrubEnv returns environ with credentials removed, plus GIT_TERMINAL_PROMPT=0 so git never blocks on an interactive credential prompt.

func Sensitive

func Sensitive(path string) (string, bool)

Sensitive reports whether path's base name matches a secret-file pattern (the pattern that matched is returned too). Other packages use it to keep secret-looking files out of commits.

func Status

func Status(dir string) (branch string, dirty bool, ahead, behind int, err error)

Status reports the repository state at dir for the TUI: the current branch (or a detached/unborn marker), whether anything is modified, staged or untracked, and commits ahead of and behind the upstream. A directory that is not a repository returns an error. A branch with no upstream reports 0 ahead and 0 behind.

Types

type Diagnostic

type Diagnostic struct {
	File string `json:"file"`
	Line int    `json:"line"`
	Msg  string `json:"msg"`
}

Diagnostic is one error or failure location found in tool output.

type DispatchGuard

type DispatchGuard interface {
	DispatchActive() bool
}

DispatchGuard is what the agent publishes under Services["dispatch"] while subagents may be editing the project. Git commands that change the repository are refused while it reports true.

type Job

type Job struct {
	ID      string
	Command string
	Dir     string
	Start   time.Time
	// contains filtered or unexported fields
}

Job is one background process.

func (*Job) Done

func (job *Job) Done() <-chan struct{}

Done returns a channel closed when the job has finished.

func (*Job) Read

func (job *Job) Read(since int) (lines []string, next, dropped int, status string, exitCode int)

Read returns the lines at or after since (an absolute line index), the cursor to pass next time, how many older lines were dropped from the ring, and the current status.

type JobInfo

type JobInfo struct {
	ID       string
	Command  string
	Dir      string
	Start    time.Time
	Status   string
	ExitCode int // meaningful once Status is not running
	Lines    int // lines produced so far
}

JobInfo is a snapshot of a Job for listings.

type Jobs

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

Jobs tracks background shell processes started by the shell tool. One Jobs value is shared by the shell, shell_output and shell_kill tools and by the UI, which reads it through List.

func NewJobs

func NewJobs(opts Options) *Jobs

NewJobs returns an empty job table that applies opts to shell commands.

func (*Jobs) Get

func (j *Jobs) Get(id string) (*Job, bool)

Get returns the job with id.

func (*Jobs) Kill

func (j *Jobs) Kill(id string) error

Kill stops the job with id and waits up to 3 s for it to exit.

func (*Jobs) KillAll

func (j *Jobs) KillAll()

KillAll stops every running job. Call it when the agent exits.

func (*Jobs) List

func (j *Jobs) List() []JobInfo

List returns a snapshot of every job in start order.

type Options

type Options struct {
	Allow       []string
	Deny        []string
	ToolTimeout time.Duration
	// StateDir, when set, is where running background jobs are recorded so a
	// later Scribe process can stop them if this one dies without KillAll.
	StateDir string
}

Options are the config-supplied command rules.

  • Deny: a command containing any entry (case-insensitive substring) is refused outright, in every mode.
  • Allow: a command that starts with an entry, on a word boundary, and contains no shell control operators, skips the destructive-command prompt. It never skips the refusals below or Deny.
  • ToolTimeout: the limit for a shell or project command that sets no timeout_ms (config tool_timeout, see config.ClampToolTimeout). Zero keeps the built-in default. Forbidden paths are not an option here: the shell reads them from fs.Patterns, the same list the file tools use.

type Profile

type Profile struct {
	// Ecosystem names the first matching row of the detection table, e.g. "go".
	// Empty when nothing matched.
	Ecosystem string
	// Manager is the JavaScript package manager (npm, pnpm, yarn, bun) for
	// node-based ecosystems; empty otherwise.
	Manager string
	// Commands maps an action (test, lint, typecheck, build, format, run) to
	// the shell command that performs it. Missing actions are absent.
	Commands map[string]string
}

Profile is the toolchain detected for a project directory.

func Detect

func Detect(dir string) Profile

Detect returns the toolchain profile for dir. It looks only at files in dir itself (plus the JavaScript lockfile search). An unknown directory yields a Profile with an empty Ecosystem and no commands.

Jump to

Keyboard shortcuts

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