util

package
v0.5.2-rc.1 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2026 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Overview

Eager per-write git checkpoint

Error formatting

Filesystem helpers

Git workflow-artifact exclusion

Local context: typed values carried on an explicit context.Context, the native propagation mechanism across goroutines.

Named schema error

Process helpers

Record predicate.

Index

Constants

View Source
const (
	CommitterName  = gitidentity.EngineName
	CommitterEmail = gitidentity.EngineEmail
)

The values live in internal/gitidentity, which codeaf's own side of a run reads on every platform.

View Source
const GeneratedRunPaths = gitidentity.GeneratedRunPaths

GeneratedRunPaths and GeneratedRunPath are internal/gitidentity's, where codeaf's own side of a run reads them on every platform.

Variables

View Source
var ExcludedPaths = []string{
	".senior-dev/",
}

Functions

func CaptureStack

func CaptureStack() string

CaptureStack provides a convenient StackError stack for callers that need ErrorFormat's stack branch.

func Contains

func Contains(parent, child string) bool

func DisableEagerCommit

func DisableEagerCommit()

DisableEagerCommit turns off the per-write checkpoint for the rest of the process. A run whose recorder keeps its own snapshots does not want commits in the workspace -- under --in-place that workspace may be a repository the run has no business writing history into. Call it before the run starts.

func EagerCommit

func EagerCommit(ctx context.Context, options EagerCommitOptions)

func EnsureSeniorDevExcluded

func EnsureSeniorDevExcluded(ctx context.Context, workspace string) (bool, error)

EnsureSeniorDevExcluded adds senior-dev's own folder to the exclude file git reads for workspace, once.

THE FILE IS THE ONE GIT READS, which is not always <git-dir>/info/exclude. In a linked worktree the git dir is .git/worktrees/<name>, and git ignores an info/ folder there in favour of the common dir's. An exclude written beside the git dir changed nothing: `.senior-dev/` stayed untracked, and a commit of the tree's own status would have taken senior-dev's database, spec and tool logs with it. `rev-parse --git-path` names the file git actually consults, which for a linked worktree is the repository's shared one.

func ErrorData

func ErrorData(value any) map[string]any

func ErrorFormat

func ErrorFormat(value any) string

func ErrorMessage

func ErrorMessage(value any) string

func Exists

func Exists(path string) bool

func FileMimeType

func FileMimeType(path string) string

func FindUp

func FindUp(targets []string, start string, stop string, options ...FindUpOptions) []string

func GeneratedRunPath

func GeneratedRunPath(path string) bool

func GitArgv

func GitArgv(args ...string) []string

GitArgv is a git command line that carries senior-dev's commit identity.

func GlobUp

func GlobUp(pattern, start, stop string) []string

func IgnoredAtStart

func IgnoredAtStart(path string) bool

IgnoredAtStart reads the parent's frozen ignore list. It is a small file in the run record, since ignored directories can contain thousands of files.

func InitialIgnoredPaths

func InitialIgnoredPaths() ([]string, error)

InitialIgnoredPaths reads the one list codeaf captured before the run.

func InitialInputs

func InitialInputs() (gitidentity.Inputs, error)

InitialInputs reads the list of inputs codeaf copied into the run's copy, with their fingerprints; none for a run started any other way.

func InputLeftAlone

func InputLeftAlone(root, relative string) bool

InputLeftAlone says relative is one of the person's untracked files codeaf copied in as an input and this write left it as it was, so it is not the run's work and is never staged (gitidentity's inputs.go): staging it would write it into git's object store. An unreadable list never permits the commit, as an unreadable ignore list does not.

func IsDir

func IsDir(path string) bool

func IsRecord

func IsRecord(value any) bool

func NormalizePath

func NormalizePath(path string) string

func NormalizePathPattern

func NormalizePathPattern(path string) string

func Overlaps

func Overlaps(a, b string) bool

func PathIgnoredAtStart

func PathIgnoredAtStart(path string, paths []string) bool

PathIgnoredAtStart matches a file or a child of an ignored directory.

func ProcessLines

func ProcessLines(ctx context.Context, command []string, options ...RunOptions) ([]string, error)

func ReadBytes

func ReadBytes(path string) ([]byte, error)

func ReadJSON

func ReadJSON(path string, dst any) error

func ReadText

func ReadText(path string) (string, error)

func ResolvePath

func ResolvePath(path string) (string, error)

func Size

func Size(path string) int64

func Stat

func Stat(path string) (os.FileInfo, bool)

func StatAsync

func StatAsync(path string) (os.FileInfo, bool, error)

func StopProcess

func StopProcess(ctx context.Context, child *Child)

func Up

func Up(targets []string, start, stop string) []string

func WindowsPath

func WindowsPath(path string) string

func Write

func Write(path string, content []byte, mode ...fs.FileMode) error

func WriteJSON

func WriteJSON(path string, data any, mode ...fs.FileMode) error

func WriteStream

func WriteStream(path string, stream io.Reader, mode ...fs.FileMode) error

func WriteText

func WriteText(path, content string, mode ...fs.FileMode) error

Types

type Child

type Child struct {
	Cmd    *exec.Cmd
	Stdin  io.WriteCloser
	Stdout io.ReadCloser
	Stderr io.ReadCloser
	Exited <-chan int
	// contains filtered or unexported fields
}

func SpawnProcess

func SpawnProcess(ctx context.Context, command []string, options ...ProcessOptions) (*Child, error)

type ContextNotFound

type ContextNotFound struct{ Name string }

func (*ContextNotFound) Error

func (e *ContextNotFound) Error() string

type EagerCommitOptions

type EagerCommitOptions struct {
	Cwd      string
	FilePath string
	Label    string
}

type FindUpOptions

type FindUpOptions struct {
	RootFirst bool
}

type LocalContext

type LocalContext[T any] struct {
	Name string
	// contains filtered or unexported fields
}

func CreateLocalContext

func CreateLocalContext[T any](name string) *LocalContext[T]

func (*LocalContext[T]) MustUse

func (l *LocalContext[T]) MustUse(ctx context.Context) T

func (*LocalContext[T]) Provide

func (l *LocalContext[T]) Provide(ctx context.Context, value T) context.Context

func (*LocalContext[T]) Use

func (l *LocalContext[T]) Use(ctx context.Context) (T, error)

type NamedErrorFactory

type NamedErrorFactory struct {
	Tag string
}

func NamedSchemaErrorFactory

func NamedSchemaErrorFactory(tag string) NamedErrorFactory

func (NamedErrorFactory) IsInstance

func (f NamedErrorFactory) IsInstance(value any) bool

func (NamedErrorFactory) New

func (f NamedErrorFactory) New(data map[string]any, cause ...error) *NamedSchemaError

type NamedSchemaError

type NamedSchemaError struct {
	Name  string         `json:"name"`
	Data  map[string]any `json:"data"`
	Cause error          `json:"-"`
}

func (*NamedSchemaError) Error

func (e *NamedSchemaError) Error() string

func (*NamedSchemaError) ToObject

func (e *NamedSchemaError) ToObject() map[string]any

func (*NamedSchemaError) Unwrap

func (e *NamedSchemaError) Unwrap() error

type ProcessOptions

type ProcessOptions struct {
	Cwd string
	Env map[string]string
	// ClearEnv starts the child with an empty environment instead of
	// inheriting the parent's.
	ClearEnv bool
	Stdin    string
	Stdout   string
	Stderr   string
	Shell    string
	Kill     os.Signal
	Timeout  time.Duration
}

type ProcessResult

type ProcessResult struct {
	Code   int    `json:"code"`
	Stdout []byte `json:"-"`
	Stderr []byte `json:"-"`
}

func RunProcess

func RunProcess(ctx context.Context, command []string, options ...RunOptions) (ProcessResult, error)

type RunFailedError

type RunFailedError struct {
	Cmd    []string
	Code   int
	Stdout []byte
	Stderr []byte
}

func (*RunFailedError) Error

func (e *RunFailedError) Error() string

func (*RunFailedError) ErrorName

func (e *RunFailedError) ErrorName() string

type RunOptions

type RunOptions struct {
	ProcessOptions
	NoThrow bool
}

type StackError

type StackError interface {
	error
	Stack() string
}

StackError may supply a pre-recorded stack trace.

type TextResult

type TextResult struct {
	ProcessResult
	Text string `json:"text"`
}

func TextProcess

func TextProcess(ctx context.Context, command []string, options ...RunOptions) (TextResult, error)

Jump to

Keyboard shortcuts

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