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:
@@ -6,7 +6,6 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"slices"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -93,28 +92,11 @@ func SignedIn(ctx context.Context, binary string, env []string) (bool, string) {
|
||||
return false, ""
|
||||
}
|
||||
|
||||
// accountEnvKeys select which account Claude Code signs in with. When a chat
|
||||
// directory's own environment (direnv, mise) sets or unsets any of them, that
|
||||
// directory owns the account: the server's fallbacks (service token, login
|
||||
// file) are not added and inherited credentials are dropped, exactly as a
|
||||
// terminal opened in that directory would behave.
|
||||
var accountEnvKeys = []string{
|
||||
"CLAUDE_CONFIG_DIR", "CLAUDE_CODE_OAUTH_TOKEN", "ANTHROPIC_API_KEY", "ANTHROPIC_AUTH_TOKEN",
|
||||
secureStorageEnvKey, "CLAUDE_CODE_USE_BEDROCK", "CLAUDE_CODE_USE_VERTEX",
|
||||
}
|
||||
|
||||
// credentialEnvKeys are inherited server credentials a directory account
|
||||
// must not be overridden by. An inherited CLAUDE_CONFIG_DIR is kept.
|
||||
var credentialEnvKeys = []string{"CLAUDE_CODE_OAUTH_TOKEN", "ANTHROPIC_API_KEY", "ANTHROPIC_AUTH_TOKEN", secureStorageEnvKey}
|
||||
|
||||
func directoryOwnsAccount(dir workenv.Result) bool {
|
||||
for _, key := range accountEnvKeys {
|
||||
if dir.Touches(key) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
// A chat directory whose own environment (direnv, mise) sets or unsets any of
|
||||
// workenv.AccountEnvKeys owns the account: the server's fallbacks (service
|
||||
// token, login file) are not added and inherited credentials are dropped,
|
||||
// exactly as a terminal opened in that directory would behave. Pipeline stages
|
||||
// apply the same rule through workenv.Environment.
|
||||
|
||||
// processEnv is the environment for a CLI process started in directory: the
|
||||
// server's environment, then the directory's own environment, then the
|
||||
@@ -133,15 +115,8 @@ func (c *Chat) processEnvFrom(ctx context.Context, directory string, base []stri
|
||||
log.Printf("claude chat directory %s: %s", directory, warning)
|
||||
}
|
||||
var env []string
|
||||
if directoryOwnsAccount(dir) {
|
||||
kept := make([]string, 0, len(base))
|
||||
for _, item := range base {
|
||||
key, _, _ := strings.Cut(item, "=")
|
||||
if slices.Contains(credentialEnvKeys, key) && !dir.Touches(key) {
|
||||
continue
|
||||
}
|
||||
kept = append(kept, item)
|
||||
}
|
||||
if dir.OwnsAccount() {
|
||||
kept, _ := dir.WithoutInheritedCredentials(base)
|
||||
env = dir.Apply(kept)
|
||||
} else {
|
||||
env = c.auth.resolve(c.ctx, c.binary, withServiceToken(dir.Apply(base)))
|
||||
|
||||
Reference in New Issue
Block a user