coding

package
v1.13.0 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package coding assembles the reusable local coding-agent tool bundle.

The package is intentionally a thin SDK layer over the lower-level filesystem, shell, git, and executor primitives. Products such as Peggy should configure this package instead of owning coding-agent tool wiring directly.

Index

Constants

View Source
const PromptVariantTerse = "terse"

PromptVariantTerse selects the minimal system-prompt flavor for frontier models that need little steering. The empty string selects the default (more explicit) variant for open-weight models.

Variables

View Source
var DefaultAllowedBinaries = []string{"go", "git", "make", "node", "npm", "python", "python3"}

DefaultAllowedBinaries is the conservative shell_exec allowlist used when Options.AllowedBinaries is empty.

Functions

func ExpandPath

func ExpandPath(path string) (string, error)

ExpandPath resolves leading "~" plus "$HOME" and "${HOME}" placeholders. Other environment variables are deliberately left untouched.

func NormalizeAllowedBinaries

func NormalizeAllowedBinaries(in []string) []string

NormalizeAllowedBinaries trims, drops empties, and deduplicates a shell binary allowlist while preserving first-seen order.

func SystemPrompt added in v1.13.0

func SystemPrompt(tools []glue.Tool, variant string) string

SystemPrompt assembles a coding system prompt from the active toolset: one line per tool (from each tool's PromptSnippet) plus the deduplicated union of their PromptGuidelines. The prompt therefore can never drift from the tools actually registered — pi's tool-owned-prompt pattern. Tools without a snippet are omitted.

variant selects the intro flavor: PromptVariantTerse for frontier models, "" for the default explicit variant (open-weight models benefit from the extra structure). Pick via providers.CapabilitiesFor(name).PromptVariant.

Types

type Options

type Options struct {
	// Enabled gates the whole bundle. Disabled returns no tools and does
	// not validate the rest of the options.
	Enabled bool

	// WorkDir is the workspace root for every tool. Empty uses the
	// process working directory. Leading ~ and $HOME are expanded.
	WorkDir string

	// AllowedBinaries is the shell_exec basename allowlist. Empty falls
	// back to DefaultAllowedBinaries.
	AllowedBinaries []string

	// AllowOverwrite is the host-level write_file overwrite policy.
	AllowOverwrite bool

	// Executor runs shell_exec commands. Nil uses glue.LocalExecutor.
	Executor glue.Executor

	// Env is the exact child process environment for shell_exec. Nil
	// means the child inherits no environment.
	Env []string

	// Blocklist refuses secret-shaped paths for read_file and write_file.
	// Nil uses tools/fs.Default().
	Blocklist toolsfs.Blocklist

	// ReadMaxBytes caps read_file output. Zero uses the fs package default.
	ReadMaxBytes int

	// WriteMaxBytes caps write_file content. Zero uses the fs package default.
	WriteMaxBytes int

	// ShellTimeout caps shell_exec calls. Zero uses the shell package default.
	ShellTimeout time.Duration

	// ShellMaxOutputBytes caps shell_exec stdout and stderr independently.
	// Zero uses the glue executor default.
	ShellMaxOutputBytes int

	// GitDefaultBase is the default base ref for git_diff_branch and
	// git_log_branch. Empty uses the git package default.
	GitDefaultBase string

	// GitDiffMaxBytes caps git_diff_branch output. Zero uses the git
	// package default.
	GitDiffMaxBytes int

	// GitLogLimit caps git_log_branch commit count. Zero uses the git
	// package default.
	GitLogLimit int

	// GitTimeout caps each git invocation. Zero uses the git package default.
	GitTimeout time.Duration
}

Options configures the reusable coding-agent tool bundle.

func ResolveOptions

func ResolveOptions(opts Options) (Options, error)

ResolveOptions validates and fills defaults for enabled coding tools.

func Tools

func Tools(opts Options) ([]glue.Tool, Options, error)

Tools builds the standard local coding tool bundle: read_file, write_file, edit_file, list_dir, find_files, grep, shell_exec, git_diff_branch, and git_log_branch.

The returned Options contain the resolved absolute WorkDir, normalized AllowedBinaries, copied Env, and effective Blocklist.

Jump to

Keyboard shortcuts

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