Skip to content

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(computer): let a Pi without jiti load the managed MCP extension

claude-opus-5-5-mediumb278c05f05b3
diff --git a/apps/computer/local-daemon/README.md b/apps/computer/local-daemon/README.md
index bae14b93..a2db925e 100644
--- a/apps/computer/local-daemon/README.md
+++ b/apps/computer/local-daemon/README.md
@@ -642,7 +642,13 @@ signed macOS application and `cua-driver.exe` for Windows x64 and ARM64. The
bundle includes every dependency resource and a per-file SHA-256 manifest; the
installer refuses files outside the manifest, damaged resources and symlinks. The
runtime never runs `npx latest` or downloads tool dependencies. Pi still uses its
-existing RPC executor, and images keep their native content types.
+existing RPC executor, and images keep their native content types. Pi loads
+every extension through jiti, which a Pi unpacked from its bare npm bundle (the
+managed runtime harness installs it so) lacks; the Daemon puts the bundle's
+`node_modules`, which carries jiti, on that Pi's `NODE_PATH`. A Pi installed
+with its dependencies resolves its own jiti first. Node reads `NODE_PATH` at
+startup, so the extension then restores the value Pi inherited, and the
+commands Pi starts never resolve a package from the bundle.
The compatibility probe of the pinned Playwright catalog is
`TestPinnedPlaywrightCatalog`; it needs `LINGER_PLAYWRIGHT_COMPAT_ENTRY` and
diff --git a/apps/computer/local-daemon/internal/provider/native/pi_fake_test.go b/apps/computer/local-daemon/internal/provider/native/pi_fake_test.go
index 25e8d6a2..f8ec96dd 100644
--- a/apps/computer/local-daemon/internal/provider/native/pi_fake_test.go
+++ b/apps/computer/local-daemon/internal/provider/native/pi_fake_test.go
@@ -96,6 +96,7 @@ func piFake(mode string, args []string) int {
}
if path := os.Getenv(piFakeArgvEnv); path != "" {
_ = os.WriteFile(path, []byte(strings.Join(args, "\n")), 0o600)
+ _ = os.WriteFile(path+".node_path", []byte(os.Getenv(piNodePathKey)), 0o600)
}
reader := bufio.NewReader(os.Stdin)
for {
diff --git a/apps/computer/local-daemon/internal/provider/native/pi_mcp.go b/apps/computer/local-daemon/internal/provider/native/pi_mcp.go
index d20be1f7..9dd92feb 100644
--- a/apps/computer/local-daemon/internal/provider/native/pi_mcp.go
+++ b/apps/computer/local-daemon/internal/provider/native/pi_mcp.go
@@ -6,9 +6,15 @@ import (
"fmt"
"os"
"path/filepath"
+ "strings"
)
-const piMCPConfigEnvKey = "LINGER_PI_MANAGED_MCP_CONFIG"
+const (
+ piMCPConfigEnvKey = "LINGER_PI_MANAGED_MCP_CONFIG"
+ piNodePathKey = "NODE_PATH"
+ // The NODE_PATH Pi would have had without the Computer tools.
+ piInheritedNodePathKey = "LINGER_PI_INHERITED_NODE_PATH"
+)
// piMCPWiring is the managed MCP set prepared for one Pi process. A zero
// value wires nothing.
@@ -47,6 +53,32 @@ func piPrepareMCP(raw json.RawMessage, extension, sessionDir string) (piMCPWirin
return piMCPWiring{extension: extension, configPath: path}, nil
}
+// piExtensionNodePath puts the Computer tools' node_modules on Pi's module
+// search path. Pi loads every extension through jiti, which its bare npm
+// bundle does not carry: a Pi unpacked without its dependencies, as the
+// managed runtime harness installs it, cannot load the extension otherwise.
+// The tools ship jiti beside the extension. CommonJS reads NODE_PATH only
+// after a package's own node_modules, so a Pi with its own jiti keeps it.
+// Node reads NODE_PATH once, at startup, so the extension puts back the
+// inherited value for the commands Pi starts (piInheritedNodePathKey).
+func piExtensionNodePath(env map[string]string, extension string) {
+ modules := filepath.Join(filepath.Dir(filepath.Dir(extension)), "node_modules")
+ key := piNodePathKey
+ if _, ok := env[key]; !ok {
+ for existing := range env {
+ if strings.EqualFold(existing, piNodePathKey) {
+ key = existing
+ }
+ }
+ }
+ current := env[key]
+ if current != "" {
+ modules += string(filepath.ListSeparator) + current
+ }
+ env[key] = modules
+ env[piInheritedNodePathKey] = current
+}
+
func (w piMCPWiring) remove() {
if w.configPath != "" {
_ = os.Remove(w.configPath)
diff --git a/apps/computer/local-daemon/internal/provider/native/pi_runtime.go b/apps/computer/local-daemon/internal/provider/native/pi_runtime.go
index db161883..04d6eb32 100644
--- a/apps/computer/local-daemon/internal/provider/native/pi_runtime.go
+++ b/apps/computer/local-daemon/internal/provider/native/pi_runtime.go
@@ -206,6 +206,7 @@ func (p *piRuntime) spawn(ctx context.Context, plan piLaunchPlan, lock *os.File)
}
if mcp.wired() {
env[piMCPConfigEnvKey] = mcp.configPath
+ piExtensionNodePath(env, mcp.extension)
}
if p.profile.RetainProcessTemp != nil {
if releaseTemp, err = p.profile.RetainProcessTemp(); err != nil {
diff --git a/apps/computer/local-daemon/internal/provider/native/pi_runtime_test.go b/apps/computer/local-daemon/internal/provider/native/pi_runtime_test.go
index d3854ff1..7a9d0b80 100644
--- a/apps/computer/local-daemon/internal/provider/native/pi_runtime_test.go
+++ b/apps/computer/local-daemon/internal/provider/native/pi_runtime_test.go
@@ -448,6 +448,9 @@ func TestPiLaunchArguments(t *testing.T) {
if got := strings.Split(string(data), "\n"); strings.Join(got, " ") != strings.Join(want, " ") {
t.Fatalf("argv\n got %q\nwant %q", got, want)
}
+ if nodePath, _ := os.ReadFile(argv + ".node_path"); string(nodePath) != filepath.Join(filepath.Dir(filepath.Dir(extension)), "node_modules") {
+ t.Fatalf("NODE_PATH = %q", nodePath)
+ }
instructions, err := os.ReadFile(filepath.Join(sessionDir, piInstructionsName))
if err != nil || string(instructions) != "be brief" {
t.Fatalf("instructions = %q, %v", instructions, err)
@@ -461,6 +464,24 @@ func TestPiLaunchArguments(t *testing.T) {
if outcome.Status != statusCompleted || strings.Contains(string(data), "--model") || strings.Contains(string(data), "--thinking") || !strings.HasSuffix(string(data), "--tools\n"+piBaseTools) {
t.Fatalf("default argv = %q (%+v)", data, outcome)
}
+ if nodePath, _ := os.ReadFile(argv + ".node_path"); len(nodePath) != 0 {
+ t.Fatalf("NODE_PATH without an extension = %q", nodePath)
+ }
+}
+
+func TestPiExtensionNodePath(t *testing.T) {
+ extension := filepath.Join("tools", "extensions", "pi-mcp.mjs")
+ modules := filepath.Join("tools", "node_modules")
+ env := map[string]string{}
+ piExtensionNodePath(env, extension)
+ if env[piNodePathKey] != modules || env[piInheritedNodePathKey] != "" || len(env) != 2 {
+ t.Fatalf("fresh env = %q", env)
+ }
+ env = map[string]string{"Node_Path": "own"}
+ piExtensionNodePath(env, extension)
+ if len(env) != 2 || env["Node_Path"] != modules+string(filepath.ListSeparator)+"own" || env[piInheritedNodePathKey] != "own" {
+ t.Fatalf("existing NODE_PATH = %q", env)
+ }
}
func TestPiThinkingLevels(t *testing.T) {
diff --git a/apps/computer/scripts/bundle-computer-tools.mjs b/apps/computer/scripts/bundle-computer-tools.mjs
index e3542558..a3f6bee6 100644
--- a/apps/computer/scripts/bundle-computer-tools.mjs
+++ b/apps/computer/scripts/bundle-computer-tools.mjs
@@ -322,6 +322,19 @@ async function assertPlaywrightPatched(root, packages) {
}
}
+// The daemon names this node_modules on Pi's module path, because a Pi
+// installed without its dependencies loads the extension through jiti only
+// from there.
+function assertPiExtensionLoader(packages) {
+ if (
+ !packages.some(
+ ({ name, path: relative }) =>
+ name === "jiti" && relative === "node_modules/jiti",
+ )
+ )
+ throw new Error("jiti was not staged at the top of node_modules");
+}
+
export async function stageComputerTools(
bundle,
{
@@ -334,6 +347,7 @@ export async function stageComputerTools(
await mkdir(root, { recursive: true });
const packages = await stagePackages(root);
await assertPlaywrightPatched(root, packages);
+ assertPiExtensionLoader(packages);
await mkdir(path.join(root, "extensions"), { recursive: true });
await cp(
path.join(computerRoot, "tools/pi-mcp.mjs"),
diff --git a/apps/computer/tests/computer-tools.test.ts b/apps/computer/tests/computer-tools.test.ts
index 80d47588..747a42aa 100644
--- a/apps/computer/tests/computer-tools.test.ts
+++ b/apps/computer/tests/computer-tools.test.ts
@@ -34,10 +34,19 @@ it("keeps Pi's public MCP extension bound to private Operation proxies", async (
]){write(server);assert.throws(()=>loadManagedMcpConfig(file));}
write({type:"http",url:"http://127.0.0.1:1234"});
if(process.platform!=="win32"){chmodSync(file,0o644);assert.throws(()=>loadManagedMcpConfig(file),/private/);}
+ assert.equal(process.env.NODE_PATH,"inherited");
+ assert.equal(process.env.LINGER_PI_INHERITED_NODE_PATH,undefined);
console.log("private immutable MCP configuration passed");
`,
],
- { timeout: 20_000 },
+ {
+ timeout: 20_000,
+ env: {
+ ...process.env,
+ NODE_PATH: path.join(root, "tools", "node_modules"),
+ LINGER_PI_INHERITED_NODE_PATH: "inherited",
+ },
+ },
);
expect(result.stdout).toContain(
"private immutable MCP configuration passed",
diff --git a/apps/computer/tools/pi-mcp.mjs b/apps/computer/tools/pi-mcp.mjs
index 888bfda3..701e1f8c 100644
--- a/apps/computer/tools/pi-mcp.mjs
+++ b/apps/computer/tools/pi-mcp.mjs
@@ -1,5 +1,14 @@
import { readFileSync, lstatSync } from "node:fs";
import { isAbsolute } from "node:path";
+// The Daemon puts the Computer tools on NODE_PATH so Pi can load this
+// extension. Node has read it by now; put back the value Pi inherited so the
+// commands Pi starts never resolve a package from the tools.
+if (process.env.LINGER_PI_INHERITED_NODE_PATH !== undefined) {
+ if (process.env.LINGER_PI_INHERITED_NODE_PATH)
+ process.env.NODE_PATH = process.env.LINGER_PI_INHERITED_NODE_PATH;
+ else delete process.env.NODE_PATH;
+ delete process.env.LINGER_PI_INHERITED_NODE_PATH;
+}
// An installed Pi may alias bare package imports to its own version. Resolve
// the pinned public entry by URL so this adapter keeps its shipped API.
const { createMcpExtension } = await import(