Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ jobs:
# hold the Windows launcher, process Job, CLI and overlay path code.
- run: go test -run '^$' ./...
- run: go test ./cmd/linger-computer-launcher ./cmd/linger-pi-launcher ./cmd/linger-teamhub-launcher ./internal/computercli ./internal/computerconfig ./internal/localmodels ./internal/process
- run: go test -v ./internal/provider -run '^TestWindowsAntigravityProbeUsesPrivateTempBase$'
# A failed run saves unpruned; the next successful push prunes.
- if: success() && github.event_name == 'push'
run: |
Expand Down
13 changes: 10 additions & 3 deletions apps/computer/local-daemon/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -594,9 +594,16 @@ for a browser sign-in when signed out.

- Discovery runs `agy --version`, then an ACP `initialize`, then an empty
`session/new` in an isolated temporary directory seeded with the user's
`antigravity-oauth-token` and `settings.json`. ACP's authentication-required
error (`-32000`) on `session/new` means signed out. No prompt is sent, so a
probe stores no conversation.
`antigravity-oauth-token` and `settings.json`. The resident Daemon (and the
control CLI when a validated private state directory exists) allocates each
probe directory under `<state>/operation-tmp` (falling back to the OS
temporary directory when no private temp base is configured), and reports
local probe environment preparation failures as `RUNTIME_DIAGNOSTIC_FAILED`
(logging `runner.runtime_probe.prepare_failed`,
`runner.runtime_auth.prepare_failed`, or
`runner.runtime_models.prepare_failed`) rather than `RUNTIME_INCOMPATIBLE`.
ACP's authentication-required error (`-32000`) on `session/new` means signed
out. No prompt is sent, so a probe stores no conversation.
- When `session/new` needs authentication and the environment carries
`GEMINI_API_KEY` or `GOOGLE_API_KEY`, the adapter selects the
`gemini-api-key` method once and retries. A Google sign-in is never
Expand Down
9 changes: 7 additions & 2 deletions apps/computer/local-daemon/internal/computercli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type deps struct {
// interruptible derives a context that an interrupt arriving after the
// call cancels.
interruptible func(ctx context.Context) (context.Context, context.CancelFunc)
diagnoseRuntimes func(ctx context.Context, configuredPaths, environment map[string]string, enabled []string) ([]runtimeDiagnostic, error)
diagnoseRuntimes func(ctx context.Context, request runtimeRequest, enabled []string) ([]runtimeDiagnostic, error)
newClient func(stateDirectory string) controlClient
inspectDaemon func(ctx context.Context, stateDirectory string) doctorCheck
probeGateway func(ctx context.Context, gatewayURL string) doctorCheck
Expand Down Expand Up @@ -472,7 +472,12 @@ func (c *cli) executeLogin(ctx context.Context, parsed command) (int, error) {
if parsed.codexAuthFile != "" {
environment = withVariable(environment, "CODEX_HOME", filepath.Dir(parsed.codexAuthFile))
}
diagnostics, err := c.deps.diagnoseRuntimes(ctx, requested, environment, parsed.enabledRuntimes)
tempBase := validatedProbeTempBase(filepath.Join(filepath.Dir(parsed.configPath), "state"))
diagnostics, err := c.deps.diagnoseRuntimes(ctx, runtimeRequest{
configuredPaths: requested,
environment: environment,
tempBase: tempBase,
}, parsed.enabledRuntimes)
if err != nil {
return 0, wrapError(categoryCapabilityProbe, "Runtime capability probing failed: "+err.Error(), err)
}
Expand Down
122 changes: 113 additions & 9 deletions apps/computer/local-daemon/internal/computercli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import (
"os"
"path/filepath"
"reflect"
"runtime"
"strings"
"testing"

"github.com/simplexai-labs/linger/apps/computer/local-daemon/internal/linger/control"
"github.com/simplexai-labs/linger/apps/computer/local-daemon/internal/linger/transport"
"github.com/simplexai-labs/linger/apps/computer/local-daemon/internal/platform/privatefs"
"github.com/simplexai-labs/linger/apps/computer/local-daemon/internal/provider"
)

Expand Down Expand Up @@ -47,7 +49,7 @@ func TestLoginAcceptsRetiredConcurrencyFlags(t *testing.T) {
func TestLoginLimitsDiagnosticsAndSetupToTheEnabledRuntime(t *testing.T) {
f := newFixture(t)
var requested []string
f.deps.diagnoseRuntimes = func(_ context.Context, _, _ map[string]string, enabled []string) ([]runtimeDiagnostic, error) {
f.deps.diagnoseRuntimes = func(_ context.Context, _ runtimeRequest, enabled []string) ([]runtimeDiagnostic, error) {
requested = enabled
return onlyRuntime("codex"), nil
}
Expand All @@ -61,7 +63,7 @@ func TestLoginLimitsDiagnosticsAndSetupToTheEnabledRuntime(t *testing.T) {

func TestLoginConnectsWithOnlySelectedPiAbsent(t *testing.T) {
f := newFixture(t)
f.deps.diagnoseRuntimes = func(context.Context, map[string]string, map[string]string, []string) ([]runtimeDiagnostic, error) {
f.deps.diagnoseRuntimes = func(context.Context, runtimeRequest, []string) ([]runtimeDiagnostic, error) {
return onlyRuntime("pi"), nil
}
if code := f.run("login", "--enabled-runtime", "pi"); code != 0 {
Expand All @@ -74,7 +76,7 @@ func TestLoginConnectsWithOnlySelectedPiAbsent(t *testing.T) {

func TestLoginPreservesAnUnselectedExecutableOverride(t *testing.T) {
f := newFixture(t)
f.deps.diagnoseRuntimes = func(context.Context, map[string]string, map[string]string, []string) ([]runtimeDiagnostic, error) {
f.deps.diagnoseRuntimes = func(context.Context, runtimeRequest, []string) ([]runtimeDiagnostic, error) {
return onlyRuntime("codex"), nil
}
selected, other := filepath.Join(f.root, "selected-codex"), filepath.Join(f.root, "unselected-claude")
Expand All @@ -88,13 +90,13 @@ func TestLoginPreservesAnUnselectedExecutableOverride(t *testing.T) {

func TestLoginRejectsMissingSelectedExecutableAndEmptyDiscovery(t *testing.T) {
f := newFixture(t)
f.deps.diagnoseRuntimes = func(context.Context, map[string]string, map[string]string, []string) ([]runtimeDiagnostic, error) {
f.deps.diagnoseRuntimes = func(context.Context, runtimeRequest, []string) ([]runtimeDiagnostic, error) {
return onlyRuntime("pi"), nil
}
if code := f.run("login", "--enabled-runtime", "pi", "--pi-path", filepath.Join(f.root, "missing-pi")); code != 14 {
t.Fatalf("explicit missing executable exit=%d", code)
}
f.deps.diagnoseRuntimes = func(context.Context, map[string]string, map[string]string, []string) ([]runtimeDiagnostic, error) {
f.deps.diagnoseRuntimes = func(context.Context, runtimeRequest, []string) ([]runtimeDiagnostic, error) {
return nil, nil
}
if code := f.run("login", "--enabled-runtime", "pi"); code != 13 {
Expand All @@ -107,7 +109,7 @@ func TestLoginRejectsMissingSelectedExecutableAndEmptyDiscovery(t *testing.T) {

func TestLoginConnectsBeforeRuntimeInstallation(t *testing.T) {
f := newFixture(t)
f.deps.diagnoseRuntimes = func(context.Context, map[string]string, map[string]string, []string) ([]runtimeDiagnostic, error) {
f.deps.diagnoseRuntimes = func(context.Context, runtimeRequest, []string) ([]runtimeDiagnostic, error) {
var absent []runtimeDiagnostic
for _, runtimeType := range runtimeTypes {
absent = append(absent, runtimeDiagnostic{Type: runtimeType, Status: "not_installed", ErrorMessage: "Runtime executable not found"})
Expand Down Expand Up @@ -566,6 +568,108 @@ func TestRuntimeCheckUsesConfiguredPathsAndCodexHome(t *testing.T) {
}
}

func TestDoctorAndRuntimeCheckForwardValidatedStateTempBase(t *testing.T) {
t.Run("valid_private_state_directory", func(t *testing.T) {
f := newFixture(t)
stateDir := filepath.Join(f.root, "state")
if err := privatefs.EnsureDir(stateDir); err != nil {
t.Fatal(err)
}
wantTempBase := filepath.Join(stateDir, "operation-tmp")

var doctorReq runtimeRequest
f.deps.diagnoseRuntimes = func(_ context.Context, request runtimeRequest, _ []string) ([]runtimeDiagnostic, error) {
doctorReq = request
return runtimeFixtures(request.configuredPaths), nil
}
if code := f.run("doctor", "--json", "--config", f.configPath); code != 0 {
t.Fatalf("doctor exit=%d stdout=%s stderr=%s", code, f.stdout.String(), f.stderr.String())
}
if doctorReq.tempBase != wantTempBase {
t.Fatalf("doctor tempBase = %q, want %q", doctorReq.tempBase, wantTempBase)
}

var checkReq runtimeRequest
f.deps.checkRuntime = func(_ context.Context, runtimeType string, request runtimeRequest) (runtimeCheck, error) {
checkReq = request
return runtimeCheck{diagnostic: onlyRuntime(runtimeType)[0]}, nil
}
f.clear()
if code := f.run("runtime", "check", "codex", "--config", f.configPath); code != 0 {
t.Fatalf("runtime check exit=%d stdout=%s stderr=%s", code, f.stdout.String(), f.stderr.String())
}
if checkReq.tempBase != wantTempBase {
t.Fatalf("runtime check tempBase = %q, want %q", checkReq.tempBase, wantTempBase)
}
})

t.Run("missing_state_directory_omits_temp_base", func(t *testing.T) {
f := newFixture(t)
if err := os.RemoveAll(filepath.Join(f.root, "state")); err != nil {
t.Fatal(err)
}
doctorReq := runtimeRequest{tempBase: "sentinel"}
f.deps.diagnoseRuntimes = func(_ context.Context, request runtimeRequest, _ []string) ([]runtimeDiagnostic, error) {
doctorReq = request
return runtimeFixtures(request.configuredPaths), nil
}
_ = f.run("doctor", "--json", "--config", f.configPath)
if doctorReq.tempBase != "" {
t.Fatalf("doctor tempBase = %q, want empty when state directory is missing", doctorReq.tempBase)
}

checkReq := runtimeRequest{tempBase: "sentinel"}
f.deps.checkRuntime = func(_ context.Context, runtimeType string, request runtimeRequest) (runtimeCheck, error) {
checkReq = request
return runtimeCheck{diagnostic: onlyRuntime(runtimeType)[0]}, nil
}
f.clear()
_ = f.run("runtime", "check", "codex", "--config", f.configPath)
if checkReq.tempBase != "" {
t.Fatalf("runtime check tempBase = %q, want empty when state directory is missing", checkReq.tempBase)
}
})

t.Run("unsafe_state_directory_omits_temp_base", func(t *testing.T) {
f := newFixture(t)
stateDir := filepath.Join(f.root, "state")
if runtime.GOOS == "windows" {
// Replace the directory with a regular file so privatefs.CheckPath
// rejects it deterministically on Windows without touching ACLs.
if err := os.RemoveAll(stateDir); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(stateDir, []byte("not-a-dir"), 0o600); err != nil {
t.Fatal(err)
}
} else {
if err := os.Chmod(stateDir, 0o755); err != nil {
t.Fatal(err)
}
}
doctorReq := runtimeRequest{tempBase: "sentinel"}
f.deps.diagnoseRuntimes = func(_ context.Context, request runtimeRequest, _ []string) ([]runtimeDiagnostic, error) {
doctorReq = request
return runtimeFixtures(request.configuredPaths), nil
}
_ = f.run("doctor", "--json", "--config", f.configPath)
if doctorReq.tempBase != "" {
t.Fatalf("doctor tempBase = %q, want empty when state directory fails privatefs check", doctorReq.tempBase)
}

checkReq := runtimeRequest{tempBase: "sentinel"}
f.deps.checkRuntime = func(_ context.Context, runtimeType string, request runtimeRequest) (runtimeCheck, error) {
checkReq = request
return runtimeCheck{diagnostic: onlyRuntime(runtimeType)[0]}, nil
}
f.clear()
_ = f.run("runtime", "check", "codex", "--config", f.configPath)
if checkReq.tempBase != "" {
t.Fatalf("runtime check tempBase = %q, want empty when state directory fails privatefs check", checkReq.tempBase)
}
})
}

func TestAuthStatusShowsTheSavedAuthorization(t *testing.T) {
f := newFixture(t)
f.deps.environment["LINGER_WEB_URL"] = "https://app.example.test"
Expand Down Expand Up @@ -644,7 +748,7 @@ func TestDoctorFailures(t *testing.T) {
f = newFixture(t)
f.writeConfig(map[string]any{"enabled_runtimes": []any{}})
probed := false
f.deps.diagnoseRuntimes = func(context.Context, map[string]string, map[string]string, []string) ([]runtimeDiagnostic, error) {
f.deps.diagnoseRuntimes = func(context.Context, runtimeRequest, []string) ([]runtimeDiagnostic, error) {
probed = true
return nil, nil
}
Expand All @@ -656,8 +760,8 @@ func TestDoctorFailures(t *testing.T) {
codexHome := filepath.Join(f.root, "custom-codex")
f.writeConfig(map[string]any{"codex": map[string]any{"auth_file": filepath.Join(codexHome, "auth.json")}, "credential_expires_at": "2026-01-01T00:00:00.000Z"})
var environment map[string]string
f.deps.diagnoseRuntimes = func(_ context.Context, _ map[string]string, probeEnvironment map[string]string, _ []string) ([]runtimeDiagnostic, error) {
environment = probeEnvironment
f.deps.diagnoseRuntimes = func(_ context.Context, request runtimeRequest, _ []string) ([]runtimeDiagnostic, error) {
environment = request.environment
diagnostics := runtimeFixtures(nil)
diagnostics[0].Status, diagnostics[0].ErrorMessage = "authentication_required", "Codex authentication is required"
return diagnostics, nil
Expand Down
13 changes: 11 additions & 2 deletions apps/computer/local-daemon/internal/computercli/doctor.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ func (c *cli) runDoctor(ctx context.Context, parsed command) (doctorReport, erro
if config.configCheck.Status == "fail" {
return doctorReport{Version: 1, OK: false, Checks: checks}, nil
}
checks = append(checks, inspectStateDirectory(config.stateDirectory))
stateCheck := inspectStateDirectory(config.stateDirectory)
checks = append(checks, stateCheck)
checks = append(checks, c.deps.probeGateway(ctx, config.gatewayURL))
checks = append(checks, c.deps.inspectDaemon(ctx, config.stateDirectory))
configuredPaths := parsed.runtimePaths
Expand All @@ -54,7 +55,15 @@ func (c *cli) runDoctor(ctx context.Context, parsed command) (doctorReport, erro
if config.codexHome != "" {
environment = withVariable(environment, "CODEX_HOME", config.codexHome)
}
diagnostics, err := c.deps.diagnoseRuntimes(ctx, configuredPaths, environment, config.enabledRuntimes)
tempBase := ""
if stateCheck.Status == "pass" {
tempBase = filepath.Join(config.stateDirectory, "operation-tmp")
}
diagnostics, err := c.deps.diagnoseRuntimes(ctx, runtimeRequest{
configuredPaths: configuredPaths,
environment: environment,
tempBase: tempBase,
}, config.enabledRuntimes)
if err != nil {
return doctorReport{}, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ func newFixture(t *testing.T) *fixture {
}
return runtimeCheck{}, errors.New("missing fixture")
},
diagnoseRuntimes: func(_ context.Context, configuredPaths, _ map[string]string, _ []string) ([]runtimeDiagnostic, error) {
f.diagnoseInputs = append(f.diagnoseInputs, configuredPaths)
return runtimeFixtures(configuredPaths), nil
diagnoseRuntimes: func(_ context.Context, request runtimeRequest, _ []string) ([]runtimeDiagnostic, error) {
f.diagnoseInputs = append(f.diagnoseInputs, request.configuredPaths)
return runtimeFixtures(request.configuredPaths), nil
},
newClient: func(string) controlClient { return fakeClient{f: f} },
inspectDaemon: func(context.Context, string) doctorCheck {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ func (c *cli) runtimeRequest(parsed command) (runtimeRequest, error) {
}
configuredPaths := parsed.runtimePaths
environment := c.deps.environment
var tempBase string
if configured {
config := inspectComputerConfig(parsed.configPath, c.deps.environment, c.command)
if configuredPaths == nil {
Expand All @@ -90,8 +91,9 @@ func (c *cli) runtimeRequest(parsed command) (runtimeRequest, error) {
if config.codexHome != "" {
environment = withVariable(environment, "CODEX_HOME", config.codexHome)
}
tempBase = validatedProbeTempBase(config.stateDirectory)
}
return runtimeRequest{configuredPaths: configuredPaths, environment: environment}, nil
return runtimeRequest{configuredPaths: configuredPaths, environment: environment, tempBase: tempBase}, nil
}

// environmentList renders a Runtime environment for exec.Cmd, sorted so a
Expand Down
19 changes: 17 additions & 2 deletions apps/computer/local-daemon/internal/computercli/runtimes.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/simplexai-labs/linger/apps/computer/local-daemon/internal/computerconfig"
"github.com/simplexai-labs/linger/apps/computer/local-daemon/internal/linger/localtools"
"github.com/simplexai-labs/linger/apps/computer/local-daemon/internal/platform/privatefs"
"github.com/simplexai-labs/linger/apps/computer/local-daemon/internal/provider"
)

Expand Down Expand Up @@ -53,16 +54,29 @@ type runtimeCheck struct {
type runtimeRequest struct {
configuredPaths map[string]string
environment map[string]string
tempBase string
live bool
}

// validatedProbeTempBase returns <stateDirectory>/operation-tmp only when
// stateDirectory exists as a validated owner-only private directory.
func validatedProbeTempBase(stateDirectory string) string {
if stateDirectory == "" {
return ""
}
if err := privatefs.CheckPath(stateDirectory, "directory", true); err != nil {
return ""
}
return filepath.Join(stateDirectory, "operation-tmp")
}

// diagnoseRuntimes discovers the enabled Runtimes with the same discovery the
// Daemon uses.
func diagnoseRuntimes(ctx context.Context, configuredPaths, environment map[string]string, enabled []string) ([]runtimeDiagnostic, error) {
func diagnoseRuntimes(ctx context.Context, request runtimeRequest, enabled []string) ([]runtimeDiagnostic, error) {
if enabled == nil {
enabled = runtimeTypes
}
checks, err := requestRuntimeChecks(ctx, enabled, runtimeRequest{configuredPaths: configuredPaths, environment: environment})
checks, err := requestRuntimeChecks(ctx, enabled, request)
diagnostics := make([]runtimeDiagnostic, 0, len(checks))
for _, check := range checks {
diagnostics = append(diagnostics, check.diagnostic)
Expand Down Expand Up @@ -90,6 +104,7 @@ func requestRuntimeChecks(ctx context.Context, types []string, request runtimeRe
BundledPaths: resolveBundledRuntimePaths(),
Environment: request.environment,
Runtimes: selectedRuntimes,
TempBase: request.tempBase,
})
if err != nil {
return nil, err
Expand Down
11 changes: 6 additions & 5 deletions apps/computer/local-daemon/internal/computercli/runtimes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,12 @@ done

diagnostics, err := diagnoseRuntimes(
context.Background(),
nil,
map[string]string{
"PATH": emptyPath,
"HOME": home,
"SHELL": filepath.Join(root, "no-shell"),
runtimeRequest{
environment: map[string]string{
"PATH": emptyPath,
"HOME": home,
"SHELL": filepath.Join(root, "no-shell"),
},
},
[]string{"pi"},
)
Expand Down
Loading