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
- Variables
- func ChangedFiles(dir string) ([]string, error)
- func Ecosystems() []string
- func FormatFile(ctx context.Context, dir, abs string, timeout time.Duration) error
- func GitContextBlock(dir string) string
- func MutatesRepo(tool string, args json.RawMessage) bool
- func NewProjectCheck(jobs *Jobs) tools.Tool
- func ProjectCommandsLine(dir string) string
- func Register(r *tools.Registry, jobs *Jobs)
- func ScrubEnv(environ []string) []string
- func Sensitive(path string) (string, bool)
- func Status(dir string) (branch string, dirty bool, ahead, behind int, err error)
- type Diagnostic
- type DispatchGuard
- type Job
- type JobInfo
- type Jobs
- type Options
- type Profile
Constants ¶
const ( StatusRunning = "running" StatusExited = "exited" StatusKilled = "killed" )
Job statuses.
const NoTimeout = 1000 * time.Hour
NoTimeout is the limit to pass as Options.ToolTimeout for "no limit".
Variables ¶
var Actions = []string{"test", "lint", "typecheck", "build", "format", "run"}
Actions lists the project actions in display order.
var ErrNoFormatter = errors.New("no format command detected for this project")
ErrNoFormatter means the project has no format command to run on a file.
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
ScrubEnv returns environ with credentials removed, plus GIT_TERMINAL_PROMPT=0 so git never blocks on an interactive credential prompt.
func Sensitive ¶
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 ¶
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 ¶
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.
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.
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.