mirror of
https://github.com/chenhg5/cc-connect.git
synced 2026-10-25 17:36:43 +08:00
sudo -i simulates a login and runs the command from the target user's HOME, silently overriding cmd.Dir. Under run_as_user the agent therefore ignored its (multi-workspace) working directory and started in HOME, so it couldn't see the bound workspace or its CLAUDE.md. Re-establish the intended cwd inside the spawn: when SpawnOptions.WorkDir is set, BuildSpawnCommand wraps the command to 'cd "$CC_RUNAS_CHDIR" && exec "$@"'. The path travels via the preserved env var (not argv) so non-ASCII/space paths survive sudo's command re-quoting. Fixes #1312
57 lines
1.7 KiB
Go
57 lines
1.7 KiB
Go
//go:build windows
|
|
|
|
package core
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"os/exec"
|
|
)
|
|
|
|
// RunAsChdirEnv is unused on Windows (run_as_user is not supported) but is
|
|
// defined so cross-platform callers referencing core.RunAsChdirEnv compile.
|
|
const RunAsChdirEnv = "CC_RUNAS_CHDIR"
|
|
|
|
// DefaultEnvAllowlist is a stub on Windows — run_as_user is not supported.
|
|
var DefaultEnvAllowlist = []string{}
|
|
|
|
// SpawnOptions is a stub on Windows.
|
|
type SpawnOptions struct {
|
|
RunAsUser string
|
|
EnvAllowlist []string
|
|
WorkDir string
|
|
}
|
|
|
|
// IsolationMode always returns false on Windows.
|
|
func (o SpawnOptions) IsolationMode() bool { return false }
|
|
|
|
// BuildSpawnCommand on Windows ignores RunAsUser (config validation rejects
|
|
// it before we get here) and delegates to exec.CommandContext.
|
|
func BuildSpawnCommand(ctx context.Context, _ SpawnOptions, name string, args ...string) *exec.Cmd {
|
|
return exec.CommandContext(ctx, name, args...)
|
|
}
|
|
|
|
// FilterEnvForSpawn on Windows is a no-op pass-through.
|
|
func FilterEnvForSpawn(env []string, _ SpawnOptions) []string { return env }
|
|
|
|
// SudoRunner is a stub interface on Windows for API compatibility.
|
|
type SudoRunner interface {
|
|
Run(ctx context.Context, args ...string) ([]byte, error)
|
|
}
|
|
|
|
// ExecSudoRunner is a stub on Windows.
|
|
type ExecSudoRunner struct{}
|
|
|
|
// Run always fails on Windows.
|
|
func (ExecSudoRunner) Run(ctx context.Context, args ...string) ([]byte, error) {
|
|
return nil, errors.New("sudo is not supported on Windows")
|
|
}
|
|
|
|
// VerifyRunAsUserCheap always fails on Windows.
|
|
func VerifyRunAsUserCheap(_ context.Context, _ SudoRunner, runAsUser string) error {
|
|
if runAsUser == "" {
|
|
return nil
|
|
}
|
|
return errors.New("run_as_user is not supported on Windows")
|
|
}
|