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.
refactor(local-installation): share the kit and controller paths
claude-opus-5-5-mediumd8ebc34b01e5
diff --git a/packages/local-installation/src/foundation-services.ts b/packages/local-installation/src/foundation-services.tsindex 74b9018c..5c5991a7 100644--- a/packages/local-installation/src/foundation-services.ts+++ b/packages/local-installation/src/foundation-services.ts@@ -1,7 +1,7 @@/** Schedule the owned model controller; its readiness never gates installation. */import path from "node:path";import { atomicPrivate, readPrivate, type Instance } from "./instance.js";-import { runLocalmodels } from "./localmodels-tool.js";+import { modelServicesRoot, runLocalmodels } from "./localmodels-tool.js";import type { InstallerEvent } from "./events.js";import type { SetupChoice } from "./setup-plan.js";import {@@ -63,7 +63,7 @@ export async function prepareFoundationServices(options.shareGpu ?? (await readGpuSharing(instance)) ?? DEFAULT_GPU_SHARING;if (options.shareGpu !== undefined)await writeGpuSharing(instance, options.shareGpu);- const root = path.join(path.resolve(options.home), "runtime/model-services");+ const root = modelServicesRoot(options.home);const file = path.join(instance.root, "model-services.json");try {const result = await (dependencies.run ?? runLocalmodels)(diff --git a/packages/local-installation/src/localmodels-tool.ts b/packages/local-installation/src/localmodels-tool.tsindex 02e612c3..9b7435ca 100644--- a/packages/local-installation/src/localmodels-tool.ts+++ b/packages/local-installation/src/localmodels-tool.ts@@ -269,19 +269,15 @@ async function prepareLocalmodelsTool(options: Options = {},dependencies: { source?: LocalmodelsToolSource; fetcher?: typeof fetch } = {},) {- let source = dependencies.source;- if (!source) {- const raw = process.env.LINGER_LOCALMODELS_TOOL_JSON;- if (!raw)- throw new Error(- "Upstream tool distribution metadata is unavailable. Download the current Linger installer.",- );- source = validateToolSource(JSON.parse(raw));- }- source = validateToolSource(source);- const base = path.join(path.resolve(home), "tools", "localmodels");+ const pinned = dependencies.source ?? pinnedToolSource();+ if (!pinned)+ throw new Error(+ "Upstream tool distribution metadata is unavailable. Download the current Linger installer.",+ );+ const source = validateToolSource(pinned);+ const directory = kitDirectory(home, source);+ const base = path.dirname(directory);await privateDirectory(base);- const directory = path.join(base, source.sha256);// Published kits are immutable and renamed into place only after validation.// Readers must not compete for the cross-process installation lock.try {@@ -516,7 +512,7 @@ export async function stopLocalmodels(} = {},): Promise<void> {if (!(await (dependencies.installed ?? hasPinnedTool)(home))) return;- const root = path.join(path.resolve(home), "runtime", "model-services");+ const root = modelServicesRoot(home);const failed: string[] = [];for (const args of [["foundations", "stop", "--root", root, "--json"],@@ -546,16 +542,23 @@ export async function stopLocalmodels(if (failed.length) throw new Error(failed.join("; "));}async function hasPinnedTool(home: string): Promise<boolean> {+ const source = pinnedToolSource();+ if (!source) return false;+ return !!(await installedKit(kitDirectory(home, source), source).catch(+ () => undefined,+ ));+}+/** The kit this release pins, from the installer's published metadata. */+function pinnedToolSource(): LocalmodelsToolSource | undefined {const raw = process.env.LINGER_LOCALMODELS_TOOL_JSON;- if (!raw) return false;- const source = validateToolSource(JSON.parse(raw));- const directory = path.join(- path.resolve(home),- "tools",- "localmodels",- source.sha256,- );- return !!(await installedKit(directory, source).catch(() => undefined));+ return raw ? validateToolSource(JSON.parse(raw)) : undefined;+}+function kitDirectory(home: string, source: LocalmodelsToolSource): string {+ return path.join(path.resolve(home), "tools", "localmodels", source.sha256);+}+/** Where the foundations controller of a home keeps its state. */+export function modelServicesRoot(home: string): string {+ return path.join(path.resolve(home), "runtime", "model-services");}export async function readPublishedTool(file: string,diff --git a/packages/local-installation/src/model-gateway.ts b/packages/local-installation/src/model-gateway.tsindex 2283b2c3..4e2995dc 100644--- a/packages/local-installation/src/model-gateway.ts+++ b/packages/local-installation/src/model-gateway.ts@@ -2,7 +2,7 @@import path from "node:path";import { lstat, rm } from "node:fs/promises";import { atomicPrivate, readPrivate, type Instance } from "./instance.js";-import { runLocalmodels } from "./localmodels-tool.js";+import { modelServicesRoot, runLocalmodels } from "./localmodels-tool.js";import { localmodelsFailure } from "./localmodels-failure.js";import {setupSelection,@@ -19,10 +19,7 @@ interface LocalGateway {}function validateLocal(instance: Instance, value: unknown): LocalGateway {const binding = value as LocalGateway;- const control = path.join(- path.resolve(instance.root, "../.."),- "runtime/model-services",- );+ const control = modelServicesRoot(path.resolve(instance.root, "../.."));if (!binding ||binding.schema !== "localmodels.service-controller-binding/v1" ||