Linger is An Open-Source Personal Agent That Runs Fully on Your PC. We aim to break Big Tech’s grip on AI by bringing powerful local AI to everyday computers through efficient model–harness co-design, so everyone can run their own.
fix(desktop): place Another Me on the runtime chosen at installation
chendongdong88a874ff1d7d
diff --git a/apps/computer/local-daemon/cmd/linger-computer-daemon/main.go b/apps/computer/local-daemon/cmd/linger-computer-daemon/main.goindex ffe11aaf..98dc884e 100644--- a/apps/computer/local-daemon/cmd/linger-computer-daemon/main.go+++ b/apps/computer/local-daemon/cmd/linger-computer-daemon/main.go@@ -130,10 +130,11 @@ func run(args []string) (resultErr error) {}providerEnvironment := runtimeProviderEnvironment(environment, computer.GatewayToken, computer.CodexAuthFile)discovered, err := provider.Discover(context.Background(), provider.DiscoveryOptions{- ConfiguredPaths: computer.RuntimePaths,- Runtimes: computer.EnabledRuntimes,- RuntimeHomeRoot: filepath.Join(computer.StateDirectory, "runtime-homes"),- Environment: providerEnvironment,+ ConfiguredPaths: computer.RuntimePaths,+ Runtimes: computer.EnabledRuntimes,+ PreferredRuntime: computer.PreferredRuntime,+ RuntimeHomeRoot: filepath.Join(computer.StateDirectory, "runtime-homes"),+ Environment: providerEnvironment,})if err != nil {return err@@ -362,10 +363,11 @@ func run(args []string) (resultErr error) {monitorDone <- provider.MonitorRuntimeDiagnostics(ctx, provider.RuntimeMonitorOptions{Initial: discovered,Discovery: provider.DiscoveryOptions{- ConfiguredPaths: computer.RuntimePaths,- Runtimes: computer.EnabledRuntimes,- RuntimeHomeRoot: filepath.Join(computer.StateDirectory, "runtime-homes"),- Environment: providerEnvironment,+ ConfiguredPaths: computer.RuntimePaths,+ Runtimes: computer.EnabledRuntimes,+ PreferredRuntime: computer.PreferredRuntime,+ RuntimeHomeRoot: filepath.Join(computer.StateDirectory, "runtime-homes"),+ Environment: providerEnvironment,},RefreshInterval: 15 * time.Second,FullRefreshEveryTicks: 4,diff --git a/apps/computer/local-daemon/internal/computerconfig/config.go b/apps/computer/local-daemon/internal/computerconfig/config.goindex 13a10c21..21ac9163 100644--- a/apps/computer/local-daemon/internal/computerconfig/config.go+++ b/apps/computer/local-daemon/internal/computerconfig/config.go@@ -9,6 +9,7 @@ import ("fmt""net/url""path/filepath"+ "slices""strings""github.com/simplexai-labs/linger/apps/computer/local-daemon/internal/platform/privatefs"@@ -26,8 +27,11 @@ type Config struct {MaxConcurrentOperations *intRuntimePaths map[string]stringEnabledRuntimes []string- WorkspaceGrants []WorkspaceGrant- Owners []Owner+ // PreferredRuntime is the Runtime the person chose at installation, or+ // empty when the installer chose none.+ PreferredRuntime string+ WorkspaceGrants []WorkspaceGrant+ Owners []Owner// Desktop is set when the Linger Desktop app runs this Daemon as its child.Desktop *Desktop}@@ -64,6 +68,7 @@ type encodedConfig struct {MaxConcurrentOperations *int `json:"max_concurrent_operations,omitempty"`RuntimePaths map[string]string `json:"runtime_paths,omitempty"`EnabledRuntimes json.RawMessage `json:"enabled_runtimes,omitempty"`+ PreferredRuntime string `json:"preferred_runtime,omitempty"`WorkspaceGrants []WorkspaceGrant `json:"workspace_grants"`CredentialExpiresAt string `json:"credential_expires_at,omitempty"`Codex *encodedCodex `json:"codex,omitempty"`@@ -153,6 +158,12 @@ func Load(path string, environment map[string]string) (Config, error) {if err := provider.ValidateRuntimeSelection(enabledRuntimes); err != nil {return Config{}, fmt.Errorf("enabled_runtimes: %w", err)}+ if value.PreferredRuntime != "" {+ if provider.ValidateRuntimeSelection([]string{value.PreferredRuntime}) != nil ||+ (enabledRuntimes != nil && !slices.Contains(enabledRuntimes, value.PreferredRuntime)) {+ return Config{}, errors.New("preferred_runtime must be an enabled supported Runtime")+ }+ }seenGrants := make(map[string]struct{})for index := range value.WorkspaceGrants {grant := &value.WorkspaceGrants[index]@@ -173,7 +184,7 @@ func Load(path string, environment map[string]string) (Config, error) {ComputerID: value.RunnerID, DisplayName: value.DisplayName,GatewayURL: value.Gateway.URL, GatewayToken: token, CodexAuthFile: codexAuthFile(value.Codex), StateDirectory: value.StateDirectory,MaxConcurrentOperations: value.MaxConcurrentOperations, RuntimePaths: value.RuntimePaths,- EnabledRuntimes: enabledRuntimes,+ EnabledRuntimes: enabledRuntimes, PreferredRuntime: value.PreferredRuntime,WorkspaceGrants: value.WorkspaceGrants, Owners: owners, Desktop: desktop,}, nil}diff --git a/apps/computer/local-daemon/internal/computerconfig/config_enabled_runtimes_test.go b/apps/computer/local-daemon/internal/computerconfig/config_enabled_runtimes_test.goindex 9c8d5e49..3c1c24c6 100644--- a/apps/computer/local-daemon/internal/computerconfig/config_enabled_runtimes_test.go+++ b/apps/computer/local-daemon/internal/computerconfig/config_enabled_runtimes_test.go@@ -9,16 +9,22 @@ import ()func enabledConfig(t *testing.T, selection string) (Config, error) {+ t.Helper()+ field := ""+ if selection != "" {+ field = `,"enabled_runtimes":` + selection+ }+ return loadConfigFields(t, field)+}++// loadConfigFields loads a minimal valid config with field appended to it.+func loadConfigFields(t *testing.T, field string) (Config, error) {t.Helper()root := t.TempDir()token := filepath.Join(root, "token")if err := os.WriteFile(token, []byte(testToken("computer-1", "tenant-1", "owner-1")), 0o600); err != nil {t.Fatal(err)}- field := ""- if selection != "" {- field = `,"enabled_runtimes":` + selection- }encoded := fmt.Sprintf(`{"runner_id":"computer-1","display_name":"Fixture","gateway":{"url":"wss://agent.example.test/v1/runner-gateway","token_file":%q},"state_directory":%q,"workspace_grants":[]%s}`, token, root, field)file := filepath.Join(root, "computer.json")if err := os.WriteFile(file, []byte(encoded), 0o600); err != nil {diff --git a/apps/computer/local-daemon/internal/computerconfig/config_preferred_runtime_test.go b/apps/computer/local-daemon/internal/computerconfig/config_preferred_runtime_test.gonew file mode 100644index 00000000..74d3b25b--- /dev/null+++ b/apps/computer/local-daemon/internal/computerconfig/config_preferred_runtime_test.go@@ -0,0 +1,31 @@+package computerconfig++import "testing"++func TestPreferredRuntimeConfigKeepsAnEnabledRuntime(t *testing.T) {+ for _, field := range []string{`,"preferred_runtime":"pi"`, `,"enabled_runtimes":["pi","claude"],"preferred_runtime":"pi"`} {+ t.Run(field, func(t *testing.T) {+ config, err := loadConfigFields(t, field)+ if err != nil || config.PreferredRuntime != "pi" {+ t.Fatalf("preferred=%q err=%v, want pi", config.PreferredRuntime, err)+ }+ })+ }+}++func TestPreferredRuntimeConfigOmissionPrefersNone(t *testing.T) {+ config, err := loadConfigFields(t, "")+ if err != nil || config.PreferredRuntime != "" {+ t.Fatalf("preferred=%q err=%v, want none", config.PreferredRuntime, err)+ }+}++func TestPreferredRuntimeConfigRejectsUnsupportedOrDisabledRuntime(t *testing.T) {+ for _, field := range []string{`,"preferred_runtime":"other"`, `,"enabled_runtimes":["codex"],"preferred_runtime":"pi"`} {+ t.Run(field, func(t *testing.T) {+ if _, err := loadConfigFields(t, field); err == nil {+ t.Fatal("invalid preferred Runtime accepted")+ }+ })+ }+}diff --git a/apps/computer/local-daemon/internal/provider/discovery.go b/apps/computer/local-daemon/internal/provider/discovery.goindex 64ae0a8a..9e600ccc 100644--- a/apps/computer/local-daemon/internal/provider/discovery.go+++ b/apps/computer/local-daemon/internal/provider/discovery.go@@ -18,17 +18,19 @@ import ()type RuntimeDiagnostic struct {- Type string `json:"type"`- Status string `json:"status"`- Protocol string `json:"protocol"`- CheckedAt time.Time `json:"checked_at"`- Version string `json:"version,omitempty"`- Models []RuntimeModel `json:"models"`- ModelCatalogError string `json:"model_catalog_error,omitempty"`- Error *DiagnosticError `json:"error,omitempty"`- ExecutablePath string `json:"-"`- EntryPath string `json:"-"`- ExecutionPath string `json:"-"`+ Type string `json:"type"`+ Status string `json:"status"`+ Protocol string `json:"protocol"`+ CheckedAt time.Time `json:"checked_at"`+ Version string `json:"version,omitempty"`+ Models []RuntimeModel `json:"models"`+ ModelCatalogError string `json:"model_catalog_error,omitempty"`+ // Preferred marks the Runtime the person chose at installation.+ Preferred bool `json:"preferred,omitempty"`+ Error *DiagnosticError `json:"error,omitempty"`+ ExecutablePath string `json:"-"`+ EntryPath string `json:"-"`+ ExecutionPath string `json:"-"`// Internal provenance: only an authentication probe failure may be// retried without rerunning version and protocol discovery.authProbeFailed bool@@ -67,6 +69,8 @@ type DiscoveryOptions struct {Timeout time.Duration// Runtimes limits discovery to these types; empty diagnoses every Runtime.Runtimes []string+ // PreferredRuntime is the type whose diagnostic is marked Preferred.+ PreferredRuntime string}type runtimeDefinition struct {@@ -125,6 +129,7 @@ func discoverResolved(ctx context.Context, options DiscoveryOptions) DiscoveryRefor index, definition := range definitions {workers.Go(func() {observations[index] = diagnose(ctx, definition.Type, definition.Command, definition.Protocol, options, budget)+ observations[index].Preferred = definition.Type == options.PreferredRuntime})}workers.Wait()diff --git a/apps/computer/local-daemon/internal/provider/discovery_preferred_test.go b/apps/computer/local-daemon/internal/provider/discovery_preferred_test.gonew file mode 100644index 00000000..6ee7ef79--- /dev/null+++ b/apps/computer/local-daemon/internal/provider/discovery_preferred_test.go@@ -0,0 +1,35 @@+package provider++import (+ "context"+ "encoding/json"+ "path/filepath"+ "testing"+)++func TestDiscoverMarksOnlyThePreferredRuntime(t *testing.T) {+ home := t.TempDir()+ discovered, err := Discover(context.Background(), DiscoveryOptions{+ Runtimes: []string{"codex", "pi"},+ PreferredRuntime: "pi",+ Environment: map[string]string{"HOME": home, "PATH": filepath.Join(home, "empty")},+ })+ if err != nil {+ t.Fatal(err)+ }+ encoded, err := DiagnosticsJSON(discovered.Diagnostics)+ if err != nil {+ t.Fatal(err)+ }+ var wire []map[string]any+ if err := json.Unmarshal(encoded, &wire); err != nil {+ t.Fatal(err)+ }+ marked := map[string]any{}+ for _, item := range wire {+ marked[item["type"].(string)] = item["preferred"]+ }+ if len(marked) != 2 || marked["pi"] != true || marked["codex"] != nil {+ t.Fatalf("preferred marks = %v, want only pi", marked)+ }+}diff --git a/apps/desktop/AGENTS.md b/apps/desktop/AGENTS.mdindex 69270d2f..351b88dd 100644--- a/apps/desktop/AGENTS.md+++ b/apps/desktop/AGENTS.md@@ -70,9 +70,13 @@ Gateway and runs Agents. The daemon exits with the app.that `setupChoice`). No secret passes through the page. Then it saves theinstalled runtime's executable and profile paths(`GET /api/instances/desktop/runtime`) as `runtimeEnvironment` in the- Desktop config, signs in with the local owner account, switches the window- to the server and enrolls this computer, so setup ends on "Linger is- ready". That screen shows the owner account from the instance's+ Desktop config, and the runtime its `setupChoice` runs (`local-models` runs+ on Pi) as `preferredRuntime`. The daemon config carries that as+ `preferred_runtime`, and the daemon marks that runtime's diagnostic+ `preferred`, so TeamHub creates Another Me and the starter Agents on it+ while it is ready instead of on the first ready runtime. Then it signs in+ with the local owner account, switches the window to the server and+ enrolls this computer, so setup ends on "Linger is ready". That screen shows the owner account from the instance'sowner-only `local-account.json` (`setup-account.ts`): the email, thepassword masked until Show, Copy (the main process writes the clipboardand clears it after 60 s if it still holds the password) and "Open accountdiff --git a/apps/desktop/src/main/computer-daemon.test.ts b/apps/desktop/src/main/computer-daemon.test.tsindex 71a1ae1e..6ff479b8 100644--- a/apps/desktop/src/main/computer-daemon.test.ts+++ b/apps/desktop/src/main/computer-daemon.test.ts@@ -195,6 +195,7 @@ describe("ComputerDaemonModule", () => {PI_CODING_AGENT_DIR: "/home/me/.linger/runtime/pi-agent",CODEX_HOME: "relative/is/ignored",},+ preferredRuntime: "pi",});bus.emit("computer.changed", "computer-1");await vi.waitFor(() => expect(children).toHaveLength(2));@@ -206,9 +207,12 @@ describe("ComputerDaemonModule", () => {PI_CODING_AGENT_DIR: "/home/me/.linger/runtime/pi-agent",[TOKEN_ENV]: TOKEN,});- expect(- JSON.parse(readFileSync(child.configFile, "utf8")).runtime_paths,- ).toEqual({ codex: "/opt/codex", pi: "/home/me/.linger/runtime/pi/pi" });+ const written = JSON.parse(readFileSync(child.configFile, "utf8"));+ expect(written.runtime_paths).toEqual({+ codex: "/opt/codex",+ pi: "/home/me/.linger/runtime/pi/pi",+ });+ expect(written.preferred_runtime).toBe("pi");});it("takes Windows runtime paths and replaces inherited names in any case", () => {diff --git a/apps/desktop/src/main/computer-daemon.ts b/apps/desktop/src/main/computer-daemon.tsindex 3cfffd81..bed05541 100644--- a/apps/desktop/src/main/computer-daemon.ts+++ b/apps/desktop/src/main/computer-daemon.ts@@ -164,6 +164,9 @@ export const daemonConfig = (...(Object.keys(runtimePaths).length > 0? { runtime_paths: runtimePaths }: {}),+ ...(config.preferredRuntime+ ? { preferred_runtime: config.preferredRuntime }+ : {}),workspace_grants: config.workspaceGrants.map((g) => ({grant_id: g.grantId,label: g.label,diff --git a/apps/desktop/src/main/config.ts b/apps/desktop/src/main/config.tsindex 7a3b56a1..3f09f97d 100644--- a/apps/desktop/src/main/config.ts+++ b/apps/desktop/src/main/config.ts@@ -31,6 +31,9 @@ const desktopConfig = z.object({// (LINGER_<RUNTIME>_PATH) and profiles (CODEX_HOME, CLAUDE_CONFIG_DIR,// PI_CODING_AGENT_DIR). The Computer daemon runs with them.runtimeEnvironment: z.record(z.string(), z.string()).optional(),+ // The runtime the person chose in that installation; the daemon marks it+ // so TeamHub places Another Me on it.+ preferredRuntime: z.enum(["codex", "claude", "pi"]).optional(),window: z.object({x: z.number().int(),diff --git a/apps/desktop/src/main/local-server.test.ts b/apps/desktop/src/main/local-server.test.tsindex c8398b39..b3b44cad 100644--- a/apps/desktop/src/main/local-server.test.ts+++ b/apps/desktop/src/main/local-server.test.ts@@ -718,6 +718,7 @@ describe("LocalServerModule", () => {expect(f.host.ctx.config.get().runtimeEnvironment).toEqual({LINGER_CODEX_PATH: "/opt/codex/codex",});+ expect(f.host.ctx.config.get().preferredRuntime).toBe("codex");await f.host.stop("quit");});@@ -1295,16 +1296,13 @@ describe("LocalServerModule", () => {});it("approves the deployment of the chosen local model", async () => {- const f = fixture(- withCheckout,- {},- checkout,- installerApi([], {- state: "waiting_user",- errorCode: "LOCAL_MODELS_APPROVAL_REQUIRED",- localModelsPlan: { planId: "a".repeat(64) },- }),- );+ const api = installerApi([], {+ state: "waiting_user",+ errorCode: "LOCAL_MODELS_APPROVAL_REQUIRED",+ localModelsPlan: { planId: "a".repeat(64) },+ });+ api.runtime.setupChoice = "local-models";+ const f = fixture(withCheckout, {}, checkout, api);await f.host.start();await f.module.begin({ runtime: "local" });expect(f.api.created).toEqual([@@ -1314,6 +1312,8 @@ describe("LocalServerModule", () => {]);expect(f.api.retried).toEqual([{ localModelsApproval: "a".repeat(64) }]);expect(f.module.status().phase).toBe("ready");+ // The local model runs on Pi, so the Computer prefers Pi.+ expect(f.host.ctx.config.get().preferredRuntime).toBe("pi");await f.host.stop("quit");});diff --git a/apps/desktop/src/main/local-server.ts b/apps/desktop/src/main/local-server.tsindex a5f4c451..a0e7762b 100644--- a/apps/desktop/src/main/local-server.ts+++ b/apps/desktop/src/main/local-server.ts@@ -686,7 +686,11 @@ export class LocalServerModule implements Module {// The desktop's Computer runs the runtime this installer set up, with// its profile, rather than whatever its PATH finds.const runtime = await installer.runtime();- this.#ctx?.config.update({ runtimeEnvironment: runtime.environment });+ const preferredRuntime = setupRuntime(runtime.setupChoice);+ this.#ctx?.config.update({+ runtimeEnvironment: runtime.environment,+ ...(preferredRuntime ? { preferredRuntime } : {}),+ });this.#ctx?.log.info("local_server.runtime", {runtime: runtime.setupChoice,keys: Object.keys(runtime.environment),@@ -745,9 +749,8 @@ export class LocalServerModule implements Module {installer: InstallerApi,signal: AbortSignal,): Promise<LocalRuntime | undefined> {- const choice = (await installer.runtime()).setupChoice;- const runtime: LocalRuntime =- choice === "codex" || choice === "claude" ? choice : "pi";+ const runtime =+ setupRuntime((await installer.runtime()).setupChoice) ?? "pi";this.#signInInstaller = installer;this.#switchTo = undefined;try {@@ -2371,6 +2374,14 @@ interface RuntimeLogin {readonly message?: string;}+// The runtime an installation's setup choice runs; local models run on pi.+const setupRuntime = (choice: string | undefined): LocalRuntime | undefined =>+ choice === "local-models"+ ? "pi"+ : choice === "codex" || choice === "claude" || choice === "pi"+ ? choice+ : undefined;+// The installer's own pick; local models stand for the pi runtime.const recommended = (report: { recommendation?: string }) =>report.recommendation === "local-models"diff --git a/apps/teamhub/internal/agentregistry/another_me.go b/apps/teamhub/internal/agentregistry/another_me.goindex 09b5983b..d1e2bb07 100644--- a/apps/teamhub/internal/agentregistry/another_me.go+++ b/apps/teamhub/internal/agentregistry/another_me.go@@ -99,7 +99,11 @@ func (s *Service) createAnotherMeTx(ctx context.Context, tx pgx.Tx, computer ageif err != nil || !listed {return err}- placement, err := chooseAnotherMeLocalPlacement([]httpapi.LocalComputer{projected})+ preferredRuntime, err := storedPreferredRuntime(row.RuntimeDiagnostics)+ if err != nil {+ return err+ }+ placement, err := chooseAnotherMeLocalPlacement([]httpapi.LocalComputer{projected}, preferredRuntime)if errors.Is(err, errAnotherMeComputerUnavailable) {return nil}diff --git a/apps/teamhub/internal/agentregistry/another_me_local_placement.go b/apps/teamhub/internal/agentregistry/another_me_local_placement.goindex c57c8d2e..1b4b1e94 100644--- a/apps/teamhub/internal/agentregistry/another_me_local_placement.go+++ b/apps/teamhub/internal/agentregistry/another_me_local_placement.go@@ -19,14 +19,22 @@ type anotherMeLocalPlacement struct {// chooseAnotherMeLocalPlacement chooses where a new Another Me runs: the first// online Computer with any ready Runtime, its first writable workspace grant,-// and the model that Runtime runs by default, else the first it reports.-func chooseAnotherMeLocalPlacement(computers []httpapi.LocalComputer) (anotherMeLocalPlacement, error) {+// and the model that Runtime runs by default, else the first it reports. The+// preferred Runtime, the one the person chose at installation, goes first+// while it is ready.+func chooseAnotherMeLocalPlacement(computers []httpapi.LocalComputer, preferredRuntime string) (anotherMeLocalPlacement, error) {for _, computer := range computers {grantID := writableWorkspaceGrant(computer.WorkspaceGrants)if computer.Status != httpapi.LocalComputerStatusOnline || computer.UpgradeRequired || grantID == "" {continue}- for _, runtime := range computer.Runtimes {+ runtimes := computer.Runtimes+ if index := slices.IndexFunc(runtimes, func(runtime httpapi.LocalComputerRuntime) bool {+ return string(runtime.Type) == preferredRuntime+ }); index > 0 {+ runtimes = slices.Concat(runtimes[index:index+1], runtimes[:index], runtimes[index+1:])+ }+ for _, runtime := range runtimes {if runtime.Status != httpapi.LocalRuntimeDiagnosticStatusReady || len(runtime.Models) == 0 {continue}diff --git a/apps/teamhub/internal/agentregistry/another_me_local_placement_test.go b/apps/teamhub/internal/agentregistry/another_me_local_placement_test.goindex b360aea2..b7373a9c 100644--- a/apps/teamhub/internal/agentregistry/another_me_local_placement_test.go+++ b/apps/teamhub/internal/agentregistry/another_me_local_placement_test.go@@ -13,9 +13,10 @@ func TestChooseAnotherMeLocalPlacementUsesAnyReadyRuntime(t *testing.T) {high := httpapi.AgentReasoningEffort("high")isDefault := truefor _, test := range []struct {- name string- runtimes []httpapi.LocalComputerRuntime- want anotherMeLocalPlacement+ name string+ runtimes []httpapi.LocalComputerRuntime+ preferred string+ want anotherMeLocalPlacement}{{name: "Claude model without a default effort",runtimes: []httpapi.LocalComputerRuntime{{Type: "claude", Status: "ready", Models: []httpapi.AgentModel{{@@ -41,11 +42,27 @@ func TestChooseAnotherMeLocalPlacementUsesAnyReadyRuntime(t *testing.T) {{Id: "gpt-mini"}, {Id: "gpt", IsDefault: &isDefault},}}},want: anotherMeLocalPlacement{ComputerID: "computer_1", RuntimeType: "codex", WorkspaceGrantID: "grant_files", Model: "gpt"},+ }, {+ name: "the Runtime chosen at installation",+ runtimes: []httpapi.LocalComputerRuntime{+ {Type: "claude", Status: "ready", Models: []httpapi.AgentModel{{Id: "default"}}},+ {Type: "pi", Status: "ready", Models: []httpapi.AgentModel{{Id: "localmodels/localmodels-agent"}}},+ },+ preferred: "pi",+ want: anotherMeLocalPlacement{ComputerID: "computer_1", RuntimeType: "pi", WorkspaceGrantID: "grant_files", Model: "localmodels/localmodels-agent"},+ }, {+ name: "another ready Runtime while the chosen one is not ready",+ runtimes: []httpapi.LocalComputerRuntime{+ {Type: "claude", Status: "ready", Models: []httpapi.AgentModel{{Id: "default"}}},+ {Type: "pi", Status: "authentication_required"},+ },+ preferred: "pi",+ want: anotherMeLocalPlacement{ComputerID: "computer_1", RuntimeType: "claude", WorkspaceGrantID: "grant_files", Model: "default"},}} {t.Run(test.name, func(t *testing.T) {got, err := chooseAnotherMeLocalPlacement([]httpapi.LocalComputer{{ComputerId: "computer_1", Status: httpapi.LocalComputerStatusOnline, Runtimes: test.runtimes, WorkspaceGrants: grants,- }})+ }}, test.preferred)if err != nil || got != test.want {t.Fatalf("placement=%+v err=%v, want %+v", got, err, test.want)}@@ -58,8 +75,20 @@ func TestChooseAnotherMeLocalPlacementWaitsForAnOnlineComputer(t *testing.T) {ComputerId: "computer_1", Status: httpapi.LocalComputerStatusOffline,WorkspaceGrants: []httpapi.LocalComputerWorkspaceGrant{{GrantId: "grant_files", Mode: httpapi.WorkspaceWrite}},Runtimes: []httpapi.LocalComputerRuntime{{Type: "codex", Status: "ready", Models: []httpapi.AgentModel{{Id: "codex-default"}}}},- }})+ }}, "")if !errors.Is(err, errAnotherMeComputerUnavailable) {t.Fatalf("err=%v, want %v", err, errAnotherMeComputerUnavailable)}}++func TestStoredPreferredRuntimeReadsTheMarkedDiagnostic(t *testing.T) {+ for _, test := range []struct{ raw, want string }{+ {`[{"type":"claude","status":"ready"},{"type":"pi","status":"ready","preferred":true}]`, "pi"},+ {`[{"type":"claude","status":"ready"},{"type":"pi","status":"ready"}]`, ""},+ } {+ got, err := storedPreferredRuntime([]byte(test.raw))+ if err != nil || got != test.want {+ t.Fatalf("preferred=%q err=%v, want %q", got, err, test.want)+ }+ }+}diff --git a/apps/teamhub/internal/agentregistry/local_computer_inventory.go b/apps/teamhub/internal/agentregistry/local_computer_inventory.goindex 8f651b72..88a3403a 100644--- a/apps/teamhub/internal/agentregistry/local_computer_inventory.go+++ b/apps/teamhub/internal/agentregistry/local_computer_inventory.go@@ -36,6 +36,7 @@ type storedRuntimeDiagnostic struct {IsDefault bool `json:"is_default"`} `json:"models"`ModelCatalogError json.RawMessage `json:"model_catalog_error"`+ Preferred bool `json:"preferred"`}type storedWorkspaceGrant struct {@@ -170,6 +171,25 @@ func projectStoredRuntimes(raw []byte) ([]httpapi.LocalComputerRuntime, error) {return runtimes, nil}+// storedPreferredRuntime is the Runtime the Computer reports as the one its+// person chose at installation, or "" when it reports none.+func storedPreferredRuntime(raw []byte) (string, error) {+ active, err := agentruntimestate.ActiveLocalRuntimeDiagnostics(raw)+ if err != nil {+ return "", err+ }+ var diagnostics []storedRuntimeDiagnostic+ if err := json.Unmarshal(active, &diagnostics); err != nil {+ return "", err+ }+ for _, diagnostic := range diagnostics {+ if diagnostic.Preferred {+ return diagnostic.Type, nil+ }+ }+ return "", nil+}+func storedRuntimeModels(diagnostic storedRuntimeDiagnostic) []httpapi.AgentModel {if len(diagnostic.ModelCatalogError) > 0 && string(diagnostic.ModelCatalogError) != "null" {return []httpapi.AgentModel{}diff --git a/contracts/generated/go/runnergateway/wire.gen.go b/contracts/generated/go/runnergateway/wire.gen.goindex 68b14b7c..172c24f9 100644--- a/contracts/generated/go/runnergateway/wire.gen.go+++ b/contracts/generated/go/runnergateway/wire.gen.go@@ -210,6 +210,7 @@ type RuntimeDiagnostic struct {Version string `json:"version,omitempty"`Models []RuntimeModel `json:"models"`ModelCatalogError string `json:"model_catalog_error,omitempty"`+ Preferred *bool `json:"preferred,omitempty"`Error *RuntimeDiagnosticError `json:"error,omitempty"`ManagedServices []ManagedService `json:"managed_services,omitempty"`}diff --git a/contracts/generated/typescript/src/generated/runner-gateway/schema.ts b/contracts/generated/typescript/src/generated/runner-gateway/schema.tsindex bb36be74..08a5cac3 100644--- a/contracts/generated/typescript/src/generated/runner-gateway/schema.ts+++ b/contracts/generated/typescript/src/generated/runner-gateway/schema.ts@@ -233,6 +233,11 @@ export const runnerGatewayEnvelopeSchema = {minLength: 1,maxLength: 240,},+ preferred: {+ type: "boolean",+ description:+ "Marks the Runtime the person chose when this Computer was installed; at most one diagnostic carries it. TeamHub places new template Agents on it while it is ready.",+ },error: {type: "object",additionalProperties: false,diff --git a/contracts/generated/typescript/src/generated/runner-gateway/types.ts b/contracts/generated/typescript/src/generated/runner-gateway/types.tsindex 981af12f..b714dca8 100644--- a/contracts/generated/typescript/src/generated/runner-gateway/types.ts+++ b/contracts/generated/typescript/src/generated/runner-gateway/types.ts@@ -1001,6 +1001,10 @@ export interface RuntimeDiagnostic {*/models: RuntimeModel[];model_catalog_error?: string;+ /**+ * Marks the Runtime the person chose when this Computer was installed; at most one diagnostic carries it. TeamHub places new template Agents on it while it is ready.+ */+ preferred?: boolean;error?: {code:| "RUNTIME_NOT_INSTALLED"diff --git a/contracts/runner-gateway/envelope.schema.json b/contracts/runner-gateway/envelope.schema.jsonindex 5a5f556c..d96d9354 100644--- a/contracts/runner-gateway/envelope.schema.json+++ b/contracts/runner-gateway/envelope.schema.json@@ -231,6 +231,10 @@"minLength": 1,"maxLength": 240},+ "preferred": {+ "type": "boolean",+ "description": "Marks the Runtime the person chose when this Computer was installed; at most one diagnostic carries it. TeamHub places new template Agents on it while it is ready."+ },"error": {"type": "object","additionalProperties": false,