Pipeline runs use the workspace's directory environment

Resolve the run workspace's environment with workenv (direnv, parent
.envrc, mise; same account rule as Claude chats) at run start and resume,
and apply it to Pi stage processes, a per-environment Pipelines-owned
OpenCode stage service (keyed by a hash of the change, reused across runs,
idle ones stopped after PIPELINES_OPENCODE_STAGE_IDLE_TIMEOUT, revived per
registration), delivery-gate checks and merges, plain-stage opencode CLI
calls and file-change capture git reads. Record the directory, .envrc
files, sources and variable names (never values) on the run detail; a
blocked .envrc becomes a run warning.
This commit is contained in:
2026-11-04 18:08:42 +00:00
parent e0d7b720f5
commit cedfc22e45
26 changed files with 1173 additions and 84 deletions
+15 -6
View File
@@ -21,6 +21,7 @@ import (
"unicode/utf8"
"git.a-wan.net/alan/pipelines/internal/protocol"
"git.a-wan.net/alan/pipelines/internal/workenv"
"github.com/pmezard/go-difflib/difflib"
)
@@ -109,10 +110,18 @@ type Snapshot struct {
missing map[string]string
}
// gitCommand runs git for directory with the run's directory environment
// (workenv.WithEnvironment) when ctx carries one, as the stage's own git sees.
func gitCommand(ctx context.Context, directory string, args ...string) *exec.Cmd {
cmd := exec.CommandContext(ctx, "git", args...)
cmd.Env = workenv.CommandEnv(ctx, directory)
return cmd
}
// readGitIndex returns the stage-0 index object id of every tracked path in
// the run directory (paths relative to it, as ls-files prints them).
func readGitIndex(ctx context.Context, directory string) (map[string]string, bool) {
cmd := exec.CommandContext(ctx, "git", "-c", "core.fsmonitor=false", "-C", directory, "ls-files", "--stage", "-z", "--", ".")
cmd := gitCommand(ctx, directory, "-c", "core.fsmonitor=false", "-C", directory, "ls-files", "--stage", "-z", "--", ".")
out := &boundedOutput{limit: 8 << 20}
cmd.Stdout = out
if err := cmd.Run(); err != nil {
@@ -137,7 +146,7 @@ func readBlobs(ctx context.Context, directory string, ids []string) map[string][
if len(ids) == 0 {
return result
}
cmd := exec.CommandContext(ctx, "git", "-c", "core.fsmonitor=false", "-C", directory, "cat-file", "--batch")
cmd := gitCommand(ctx, directory, "-c", "core.fsmonitor=false", "-C", directory, "cat-file", "--batch")
cmd.Stdin = strings.NewReader(strings.Join(ids, "\n") + "\n")
pipe, err := cmd.StdoutPipe()
if err != nil {
@@ -181,12 +190,12 @@ func readBlobs(ctx context.Context, directory string, ids []string) map[string][
// returns its paths relative to that directory. It only reads: optional locks
// are disabled so the index is never refreshed or rewritten.
func readGitStatus(ctx context.Context, directory string) (map[string]string, bool) {
prefixOut, err := exec.CommandContext(ctx, "git", "-c", "core.fsmonitor=false", "-C", directory, "rev-parse", "--show-prefix").Output()
prefixOut, err := gitCommand(ctx, directory, "-c", "core.fsmonitor=false", "-C", directory, "rev-parse", "--show-prefix").Output()
if err != nil {
return nil, false
}
prefix := strings.TrimSpace(string(prefixOut))
cmd := exec.CommandContext(ctx, "git", "--no-optional-locks", "-c", "core.fsmonitor=false", "-C", directory, "status", "--porcelain=v1", "-z", "--no-renames", "--untracked-files=all", "--", ".")
cmd := gitCommand(ctx, directory, "--no-optional-locks", "-c", "core.fsmonitor=false", "-C", directory, "status", "--porcelain=v1", "-z", "--no-renames", "--untracked-files=all", "--", ".")
out := &boundedOutput{limit: 4 << 20}
cmd.Stdout = out
if err := cmd.Run(); err != nil {
@@ -255,9 +264,9 @@ func (b *boundedOutput) Write(p []byte) (int, error) {
// inventory lists the files to snapshot. Git is only read, never altered;
// the baseline is still stage-start content (see Capture and recoverBaselines).
func inventory(ctx context.Context, directory string, root *os.Root) ([]string, bool, error) {
probe := exec.CommandContext(ctx, "git", "-c", "core.fsmonitor=false", "-C", directory, "rev-parse", "--is-inside-work-tree")
probe := gitCommand(ctx, directory, "-c", "core.fsmonitor=false", "-C", directory, "rev-parse", "--is-inside-work-tree")
if data, err := probe.Output(); err == nil && strings.TrimSpace(string(data)) == "true" {
cmd := exec.CommandContext(ctx, "git", "-c", "core.fsmonitor=false", "-C", directory, "ls-files", "--cached", "--others", "--exclude-standard", "--deduplicate", "-z", "--", ".")
cmd := gitCommand(ctx, directory, "-c", "core.fsmonitor=false", "-C", directory, "ls-files", "--cached", "--others", "--exclude-standard", "--deduplicate", "-z", "--", ".")
out := &boundedOutput{limit: 2 << 20}
cmd.Stdout = out
if err := cmd.Run(); err != nil {