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
+12 -2
View File
@@ -16,6 +16,8 @@ import (
"strings"
"syscall"
"time"
"git.a-wan.net/alan/pipelines/internal/workenv"
)
//go:embed pi_policy.mjs
@@ -165,7 +167,7 @@ func (c *PiClient) Generate(ctx context.Context, config ModelConfig, prompt stri
c.cmd = exec.Command(c.Executable, args...)
c.cmd.Dir = c.Directory
c.cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
c.cmd.Env = piEnvironment(c.Reference, c.ArtifactsDir)
c.cmd.Env = piEnvironmentFrom(workenv.CommandEnv(ctx, c.Directory), c.Reference, c.ArtifactsDir)
stderr, err := os.OpenFile(filepath.Join(c.Reference, "stderr.log"), os.O_CREATE|os.O_WRONLY, 0600)
if err != nil {
return "", err
@@ -382,7 +384,15 @@ func (c *PiClient) settleTurn(ctx context.Context) (string, error) {
// never silently replaced by an ambient one (for example Pipelines' own
// PIPELINES_ARTIFACTS_DIR when a stage runs inside another stage).
func piEnvironment(reference, artifactsDir string) []string {
inherited := os.Environ()
return piEnvironmentFrom(nil, reference, artifactsDir)
}
// piEnvironmentFrom builds the Pi environment over inherited (the run directory's
// environment), or over the server's own when inherited is nil.
func piEnvironmentFrom(inherited []string, reference, artifactsDir string) []string {
if inherited == nil {
inherited = os.Environ()
}
env := make([]string, 0, len(inherited)+4)
for _, entry := range inherited {
if strings.HasPrefix(entry, ArtifactsEnv+"=") {