env

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: MIT Imports: 9 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 env reads and writes agent-vm's env files, ~/.agent-vm/env and a project's .agent-vm.env, which the VM's shell sources: without ever running a shell on the host, since the VM can write the project's.

Index

Constants

View Source
const (
	Found    = 0
	NotFound = 1
	// Refused: the file uses syntax this reader does not interpret, and no
	// key can be answered.
	Refused = 3
)

Status of a read.

Variables

View Source
var (
	// ErrNoFile: the file is not there (Read only).
	ErrNoFile = errors.New("no such file")
	// ErrUnsafe: a symlink, or something other than a folder or a regular
	// file, is on the way.
	ErrUnsafe = errors.New("a symlink, or not a regular file or folder, on the way")
)

The ways a NoFollow call fails.

Functions

func Drop

func Drop(content, key string) string

Drop is content without key's assignments, whole: a value Set wrote over several lines goes with its first line. Each line keeps its newline.

func InProject

func InProject(dir, target string) bool

InProject reports whether target is inside the project dir (see ProjectRel).

func Lookup

func Lookup(content, key string) (string, int)

Lookup is the value content assigns to key, as a shell sourcing it would, without a shell. Accepted: an optional `export `, then single-quoted parts (which may span lines, as Set writes a value with a newline), double-quoted parts with nothing to expand, and bare characters other than $ ` \ ; & | < > ( ) ~, then an optional `# comment`. The last assignment wins. One line refused, and no key is answered: a quote left open or a trailing backslash makes the shell read the next lines into that value, and other syntax can run anything, an assignment to any key included. A line that is not an assignment, a comment or blank counts as refused.

func MkdirIn

func MkdirIn(top, rel string) error

MkdirIn makes the folder top/rel and those above it.

func Names

func Names(content string) []string

Names is every name content assigns, once per assignment, in order.

func Payload

func Payload(shared, dir string) string

Payload is what is pushed into the VM of the project dir: the shared file first, the project's next, so the project's value wins (the guest sources it). The project's file is only in here when AGENT_VM_PROJECT_ENV puts it outside the project; inside, the VM reads it itself (see ProjectRel).

func ProjectEnvFile

func ProjectEnvFile(dir string) string

ProjectEnvFile is the project dir's env file: in the project, so it follows a clone, a move and a delete.

func ProjectPath

func ProjectPath(dir, p string) string

ProjectPath is a project file's path: p relative to the project dir unless absolute. An integrator moves the env file and the runtime script into a folder of its own (".mytool/env") with AGENT_VM_PROJECT_ENV and AGENT_VM_PROJECT_RUNTIME.

func ProjectRel

func ProjectRel(dir, target string) (string, bool)

ProjectRel is target relative to the project dir, when it is inside it, where the VM can write. The host must not read such a file by its path: the VM can make it a symlink, and the host would follow it to any file of the user's and hand the content over. It is read in the VM, or with NoFollow.

Inside by its spelling, or by where it leads: the project reached through a link of the user's, the other spelling of a linked folder (/tmp and /private/tmp on macOS), another case where the file system ignores it. So target is resolved one component at a time, links followed one hop at a time, and the first step that reaches the project decides, before anything in it is followed. Before that point, every link is outside the project, where the VM cannot change it.

func ReadIn

func ReadIn(top, rel string) ([]byte, error)

ReadIn is the content of top/rel.

func SQEscape

func SQEscape(s string) string

SQEscape makes s safe inside a single-quoted shell literal: ' becomes '"'"'.

func StripCR

func StripCR(content string) string

StripCR is content with a CR ending a line removed, each line ending with a newline: a CRLF file (Windows) would put a CR at the end of every value in the guest.

func TouchIn

func TouchIn(top, rel string) error

TouchIn makes top/rel an empty file unless it is a regular file already.

func WriteIn

func WriteIn(top, rel string, data []byte) error

WriteIn replaces top/rel with data.

Types

This section is empty.

Jump to

Keyboard shortcuts

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