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
4 changes: 3 additions & 1 deletion apps/computer/benchmarks/real-app-eval/lib/product_chain.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ function resolveTsxImportUrl(nodeServicesDir, repoRoot) {
export function exportNodeServicesDeveloperInstructions({
repoRoot = resolveLingerRepo(),
platform = "macos",
windowsGitBash = true,
instructionTier = "compact",
roomKind = "direct",
} = {}) {
Expand All @@ -255,7 +256,8 @@ export function exportNodeServicesDeveloperInstructions({
);
const useDist = fs.existsSync(distModule);
const targetUrl = pathToFileURL(useDist ? distModule : srcModule).href;
const shellDialect = platform === "windows" ? "windows-pi" : "posix";
const shellDialect =
platform === "windows" && !windowsGitBash ? "windows-pi" : "posix";

const exporterScript = `
import { assembleExecutionContextDeveloperInstructions } from ${JSON.stringify(targetUrl)};
Expand Down
26 changes: 17 additions & 9 deletions apps/computer/local-daemon/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -730,16 +730,24 @@ heredoc (`internal/permission/shell_text.go`). Named variables such as `"$id"`,
`pipefail`, a producer killed by `SIGPIPE` when a downstream reader closes
early (such as `| head`, exit `141`) or a non-zero upstream stage (such as
`grep` with no matches piped to `wc -l`) fails the pipeline; a command that
wants to ignore upstream failures can run `set +o pipefail`. On Windows, Pi
uses the built-in `powershell` tool instead of `bash`, so it skips `pipefail`
and the managed extension overrides `powershell` to set UTF-8
`$OutputEncoding` and console encodings. Windows Pi also passes
wants to ignore upstream failures can run `set +o pipefail`. On Windows, when
a non-WSL Git Bash runtime (bundled PortableGit or installed Git for Windows)
is available and the connected Agent Service advertises `windows_git_bash` in
`runner.welcome.service_features`, Pi exposes both `bash` (with `pipefail`,
explicit `shellPath` via `LINGER_PI_GIT_BASH_PATH`, `MSYS_NO_PATHCONV=1`,
`MSYS2_ARG_CONV_EXCL=*`, UTF-8 locale defaults, and `teamhub` → `teamhub.exe`
dispatch) and `powershell` (overridden to set UTF-8 `$OutputEncoding` and
console encodings); on bash-less hosts or older Agent Services, Windows Pi
falls back to `powershell` only (skipping `pipefail`). Windows Pi also passes
`LINGER_PI_SHELL_TEXT_HOOK` so the extension invokes
`linger-computer-daemon shell-text-hook` with `tool_name: "powershell"` and
`powershell_51` for `teamhub` commands containing `"` or `<<`, refusing POSIX
heredocs (`<<'EOF'`) on all PowerShell versions and embedded double quotes in
native `teamhub` arguments (outside PowerShell here-strings) on Windows
PowerShell 5.1 (`powershell.exe`). Across `bash`, `powershell`, and
`linger-computer-daemon shell-text-hook` for both `bash` and `powershell`
calls (`powershell` passes `tool_name: "powershell"` and `powershell_51` for
`teamhub` commands containing `"`, `<<`, or `$`), refusing
POSIX heredocs (`<<'EOF'`), unescaped numeric dollar amounts (`$6` in
`"$6.4M"`), and bash-escaped `\$` in double quotes, double-quoted
here-strings (`@"..."@`), or bare words on all PowerShell versions, plus
embedded double quotes in native `teamhub` arguments (outside PowerShell
here-strings) on Windows PowerShell 5.1 (`powershell.exe`). Across `bash`, `powershell`, and
`mcp__computer__ui_exec`, `pi-mcp.mjs` also runs a per-Run consecutive-failure
loop guard (reset on `before_agent_start`, exempting `--help`/`-h`/`--schema`
on shell tools and pure `ui.help(...)` on `ui_exec`, and never cleared by
Expand Down
75 changes: 64 additions & 11 deletions apps/computer/local-daemon/cmd/linger-computer-daemon/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,23 @@ func run(args []string) (resultErr error) {
if err != nil {
return err
}
var bundledGitBashPath string
if toolInstallation == nil {
// Agents on this computer then have no browser or computer-control
// tools; say so instead of leaving them silently missing.
slog.Warn("computer_tools.missing: browser and computer-control tools are disabled", "expected", localtools.ToolsDirectory(executable))
} else if toolInstallation.PowerShellPath != "" {
baseProviderEnvironment = withBundledPowerShellPath(baseProviderEnvironment, toolInstallation.PowerShellPath, runtime.GOOS)
} else {
if toolInstallation.PowerShellPath != "" {
baseProviderEnvironment = withBundledPowerShellPath(baseProviderEnvironment, toolInstallation.PowerShellPath, runtime.GOOS)
}
bundledGitBashPath = toolInstallation.GitBashPath
}
var resolvedGitBashPath string
if runtime.GOOS == "windows" {
resolvedGitBashPath = localtools.ResolveWindowsGitBash(bundledGitBashPath, baseProviderEnvironment)
if resolvedGitBashPath != "" {
baseProviderEnvironment = withBundledGitBashPath(baseProviderEnvironment, resolvedGitBashPath, runtime.GOOS)
}
}
localModelsStateDir := resolveLocalModelsStateDir(computer, environment)
currentProviderEnvironment := func() map[string]string {
Expand Down Expand Up @@ -377,12 +388,16 @@ func run(args []string) (resultErr error) {
if !filepath.IsAbs(teamhubCLINodePath) {
teamhubCLINodePath = ""
}
windowsGitBashEnabled := func() bool {
return localDaemon != nil && localDaemon.WindowsGitBashActive()
}
resolver := lingercontext.ExecutionResolver{
ServiceCommand: serviceCommand,
TeamHubCLIBin: teamhubBin,
TeamHubCLINodePath: teamhubCLINodePath,
HostEnvironmentGuide: hostEnvironmentGuide(runtime.GOOS),
ProviderLookup: providerCatalog.Lookup, WorkspaceGrants: workspaceGrants, Views: views,
ServiceCommand: serviceCommand,
TeamHubCLIBin: teamhubBin,
TeamHubCLINodePath: teamhubCLINodePath,
HostEnvironmentGuide: hostEnvironmentGuide(runtime.GOOS),
WindowsGitBashEnabled: windowsGitBashEnabled,
ProviderLookup: providerCatalog.Lookup, WorkspaceGrants: workspaceGrants, Views: views,
CLICredentials: cliCredentials,
RegistrationLookup: func(ctx context.Context, registrationID string) (lingercontext.RegistrationBinding, bool, error) {
items, err := registrationStore.List(ctx)
Expand Down Expand Up @@ -482,8 +497,15 @@ func run(args []string) (resultErr error) {
ToolGuide: resolver.ToolGuide,
HostEnvironmentGuide: resolver.HostEnvironmentGuide,
TeamHubCLI: teamhubBin != "",
TempBase: operationTempBase,
WarmupMCPServers: warmupMCPServers,
WindowsGitBashPath: resolvedGitBashPath,
WindowsGitBashReport: func() *bool {
if localDaemon == nil {
return nil
}
return localDaemon.WindowsGitBashReport()
},
TempBase: operationTempBase,
WarmupMCPServers: warmupMCPServers,
}).Warmup
localSpeech := localmodels.NewSpeech(localmodels.SpeechOptions{
ToolHandle: localModelsToolHandle,
Expand Down Expand Up @@ -539,6 +561,11 @@ func run(args []string) (resultErr error) {
if localModelsTool != nil {
downloadSourceFile = localmodels.RegionFile(localModelsTool.StateDirectory)
}
var daemonWindowsGitBash *bool
if runtime.GOOS == "windows" {
hasGitBash := resolvedGitBashPath != ""
daemonWindowsGitBash = &hasGitBash
}
localDaemon, err = daemon.New(daemon.Options{
ComputerID: computer.ComputerID, DisplayName: computer.DisplayName,
Runtimes: runtimes,
Expand All @@ -558,6 +585,8 @@ func run(args []string) (resultErr error) {
TempBase: operationTempBase, RuntimeHomeRoot: filepath.Join(computer.StateDirectory, "runtime-homes"),
CodexModelSessionHome: codexModelSessions.Home(),
PiMCPExtension: piExtension,
WindowsGitBashPath: resolvedGitBashPath,
WindowsGitBashEnabled: windowsGitBashEnabled,
ManagedPiRoots: managedPiRoots.Roots,
WithPiSettingsSync: withPiSettingsSync,
ShellTextHook: executable,
Expand All @@ -568,6 +597,7 @@ func run(args []string) (resultErr error) {
ComputerPermissions: localtools.NewComputerPermissions(permissionOptions),
CLICredentials: cliCredentials,
TeamHubCLIBin: teamhubBin,
WindowsGitBash: daemonWindowsGitBash,
LocalModels: localModels,
DownloadSourceFile: downloadSourceFile,
DownloadSourceEnv: baseProviderEnvironment,
Expand Down Expand Up @@ -1254,7 +1284,30 @@ func bundledRuntimePaths(installation *localtools.Installation) map[string]strin
}

func withBundledPowerShellPath(env map[string]string, powerShellPath, goos string) map[string]string {
if goos != "windows" || strings.TrimSpace(powerShellPath) == "" {
return withBundledWindowsRuntimeDir(env, powerShellPath, goos)
}

func setEnvFold(env map[string]string, name, value string) {
for key := range env {
if strings.EqualFold(key, name) {
delete(env, key)
}
}
env[name] = value
}

func withBundledGitBashPath(env map[string]string, gitBashPath, goos string) map[string]string {
if goos != "windows" || strings.TrimSpace(gitBashPath) == "" {
return env
}
updated := withBundledWindowsRuntimeDir(env, gitBashPath, goos)
setEnvFold(updated, "MSYS_NO_PATHCONV", "1")
setEnvFold(updated, "MSYS2_ARG_CONV_EXCL", "*")
return updated
}

func withBundledWindowsRuntimeDir(env map[string]string, executablePath, goos string) map[string]string {
if goos != "windows" || strings.TrimSpace(executablePath) == "" {
return env
}
cloned := maps.Clone(env)
Expand All @@ -1277,7 +1330,7 @@ func withBundledPowerShellPath(env map[string]string, powerShellPath, goos strin
existing = provider.AppendWindowsSearchPath(existing, cloned[key])
delete(cloned, key)
}
cloned["PATH"] = provider.AppendWindowsSearchPath(existing, filepath.Dir(powerShellPath))
cloned["PATH"] = provider.AppendWindowsSearchPath(existing, filepath.Dir(executablePath))
return cloned
}

Expand Down
41 changes: 41 additions & 0 deletions apps/computer/local-daemon/cmd/linger-computer-daemon/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2262,6 +2262,47 @@ func TestWithBundledPowerShellPath(t *testing.T) {
}
}

func TestWithBundledGitBashPath(t *testing.T) {
binDir := filepath.Join(t.TempDir(), "runtime", "git-bash", "bin")
bashPath := filepath.Join(binDir, "bash.exe")

env := map[string]string{"Path": `C:\Windows\System32;C:\Users\alice\bin`}
updated := withBundledGitBashPath(env, bashPath, "windows")
if got, want := updated["PATH"], `C:\Windows\System32;C:\Users\alice\bin;`+binDir; got != want {
t.Fatalf("updated Windows PATH = %q, want %q", got, want)
}
if updated["MSYS_NO_PATHCONV"] != "1" || updated["MSYS2_ARG_CONV_EXCL"] != "*" {
t.Fatalf("missing MSYS pathconv disable vars: %+v", updated)
}
if env["MSYS_NO_PATHCONV"] != "" {
t.Fatalf("caller environment map mutated: %+v", env)
}

// Inherited lowercase variants are replaced case-insensitively on Windows.
lowerEnv := map[string]string{
"Path": `C:\Windows\System32`,
"msys_no_pathconv": "0",
"msys2_arg_conv_excl": "",
}
overridden := withBundledGitBashPath(lowerEnv, bashPath, "windows")
if overridden["MSYS_NO_PATHCONV"] != "1" || overridden["MSYS2_ARG_CONV_EXCL"] != "*" {
t.Fatalf("case-insensitive override failed: %+v", overridden)
}
if _, dup := overridden["msys_no_pathconv"]; dup {
t.Fatalf("lowercase duplicate msys_no_pathconv survived: %+v", overridden)
}
if _, dup := overridden["msys2_arg_conv_excl"]; dup {
t.Fatalf("lowercase duplicate msys2_arg_conv_excl survived: %+v", overridden)
}

if got := withBundledGitBashPath(env, bashPath, "linux"); !reflect.DeepEqual(got, env) {
t.Fatalf("non-Windows modified env: %+v", got)
}
if got := withBundledGitBashPath(env, "", "windows"); !reflect.DeepEqual(got, env) {
t.Fatalf("empty git-bash path modified env: %+v", got)
}
}

func TestSyncManagedPiCompactionThresholdsUsesWithPiSettingsSync(t *testing.T) {
stateDir := filepath.Join(t.TempDir(), "localmodels", "state")
agentDir := filepath.Join(stateDir, "gateway-home", ".pi", "agent")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,11 @@ func TestComputerPermissionsCapabilityIsAlwaysAdvertised(t *testing.T) {
if got := d.capabilities(); len(got) != 2 || got[0] != "computer_permissions" || got[1] != "browser_connection" {
t.Fatalf("capabilities = %v", got)
}
// runner.hello.capabilities stays restricted to the closed legacy enum so
// older Agent Services never disconnect on an unknown capability.
enabled := true
dBash := &Daemon{browserConnections: &deadlineBrowserConnections{}, windowsGitBash: &enabled}
if got := dBash.capabilities(); len(got) != 2 || got[0] != "computer_permissions" || got[1] != "browser_connection" {
t.Fatalf("capabilities with windowsGitBash = %v, want legacy capability set only", got)
}
}
26 changes: 18 additions & 8 deletions apps/computer/local-daemon/internal/daemon/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,6 @@ func (d *Daemon) acceptRunnerWelcome(ctx, connectionCtx context.Context, stream
}
d.connectionEpoch = command.ConnectionEpoch
d.recordWelcomedEpoch(command.ConnectionEpoch)
contentURL := command.ContextContentURL
d.contentURL.Store(&contentURL)
d.welcomeSeen = true
d.welcomedAt = time.Now()
if d.selfUpdate != nil {
Expand Down Expand Up @@ -422,6 +420,7 @@ func (d *Daemon) acceptRunnerWelcome(ctx, connectionCtx context.Context, stream
d.runtimeFailureDetail.Store(slices.Contains(command.ServiceFeatures, serviceFeatureRuntimeFailureDetail))
d.operationBackgroundWait.Store(slices.Contains(command.ServiceFeatures, serviceFeatureOperationBackgroundWait))
d.dynamicReasoningEfforts.Store(slices.Contains(command.ServiceFeatures, serviceFeatureDynamicReasoningEfforts))
d.windowsGitBashFeature.Store(slices.Contains(command.ServiceFeatures, serviceFeatureWindowsGitBash))
d.antigravityHistory.Store(slices.Contains(command.ServiceFeatures, serviceFeatureAntigravityHistory))
d.antigravityUsageProvider.Store(slices.Contains(command.ServiceFeatures, serviceFeatureAntigravityUsageProvider))
d.piUsageProvider.Store(slices.Contains(command.ServiceFeatures, serviceFeaturePiUsageProvider))
Expand All @@ -434,6 +433,11 @@ func (d *Daemon) acceptRunnerWelcome(ctx, connectionCtx context.Context, stream
if err := d.activateStreamAndReplay(ctx, stream, command.ReconcileOperationIDs, localModels, helloRev); err != nil {
return err
}
// Publish contentURL only after welcome service_features and post-welcome
// diagnostics have been recorded and sent, so background prefix warm-up
// never observes a new contentURL with stale feature flags.
contentURL := command.ContextContentURL
d.contentURL.Store(&contentURL)
d.setLocalSpeechStream(stream, localVoiceAsr)
d.setLocalTtsStream(stream, localVoiceTts)
go d.heartbeatLoop(connectionCtx, stream, command.HeartbeatIntervalMs)
Expand Down Expand Up @@ -505,7 +509,8 @@ func (d *Daemon) UpdateRuntimeInventory(ctx context.Context, runtimes []string,
if err := d.diagnosticsStream.Send(ctx, protocol.Event{
Type: protocol.EventRuntimeDiagnostics, ProtocolVersion: d.protocolVersion,
RunnerID: d.computerID, Revision: revision, SentAt: time.Now().UTC(),
Payload: payload,
WindowsGitBash: d.WindowsGitBashReport(),
Payload: payload,
}); err != nil {
return err
}
Expand Down Expand Up @@ -609,6 +614,7 @@ func (d *Daemon) clearDiagnosticsStream(stream transport.Stream) {
d.runtimeFailureDetail.Store(false)
d.operationBackgroundWait.Store(false)
d.dynamicReasoningEfforts.Store(false)
d.windowsGitBashFeature.Store(false)
d.antigravityHistory.Store(false)
d.antigravityUsageProvider.Store(false)
d.piUsageProvider.Store(false)
Expand Down Expand Up @@ -775,9 +781,10 @@ func (d *Daemon) setLocalTtsStream(stream transport.Stream, enabled bool) {

// activateStreamAndReplay makes stream the live connection; localModels says
// whether its Agent Service accepts runner.local_models. It publishes the
// latest runtime diagnostics when inventory advanced after runner.hello or
// when the Agent Service advertises dynamic_reasoning_efforts and runner.hello
// filtered out non-legacy efforts.
// latest runtime diagnostics when inventory advanced after runner.hello, when
// the Agent Service advertises dynamic_reasoning_efforts and runner.hello
// filtered out non-legacy efforts, or when a Windows Computer reports
// negotiated windows_git_bash availability.
func (d *Daemon) activateStreamAndReplay(ctx context.Context, stream transport.Stream, operationIDs []string, localModels bool, helloRev uint64) error {
d.connectionMu.Lock()
defer d.connectionMu.Unlock()
Expand All @@ -792,14 +799,16 @@ func (d *Daemon) activateStreamAndReplay(ctx context.Context, stream transport.S
return err
}
allowDynamicEfforts := d.dynamicReasoningEfforts.Load()
reportWindowsGitBash := d.WindowsGitBashReport()
// Lock order is strictly connectionMu -> inventoryMu; never invert.
d.inventoryMu.Lock()
latestRev := d.diagnosticsRevision
latestDiag := append(json.RawMessage(nil), d.runtimeDiagnostics...)
_, filtered := filterLegacyReasoningEffortsJSON(d.runtimeDiagnostics)
needPublish := len(latestDiag) > 0 &&
((helloRev != 0 && latestRev > d.sentDiagnosticsRevision) ||
(allowDynamicEfforts && filtered))
(allowDynamicEfforts && filtered) ||
reportWindowsGitBash != nil)
if needPublish && latestRev <= d.sentDiagnosticsRevision {
d.diagnosticsRevision = nextRevisionAbove(saturatingIncrement(d.diagnosticsRevision), d.runtimeObservations)
latestRev = d.diagnosticsRevision
Expand All @@ -812,7 +821,8 @@ func (d *Daemon) activateStreamAndReplay(ctx context.Context, stream transport.S
if err := stream.Send(ctx, protocol.Event{
Type: protocol.EventRuntimeDiagnostics, ProtocolVersion: d.protocolVersion,
RunnerID: d.computerID, Revision: latestRev, SentAt: time.Now().UTC(),
Payload: latestDiag,
WindowsGitBash: reportWindowsGitBash,
Payload: latestDiag,
}); err != nil {
return err
}
Expand Down
Loading