A desktop coding agent with free access to frontier models.
TypeScript
fix: farm mode (stock) shims in login shells, one farm check for the plugin
ogsamratd3b9107bb1c8
diff --git a/apps/desktop/box/go/cmd/boxd/egress.go b/apps/desktop/box/go/cmd/boxd/egress.goindex 3afecb6f..29ad8634 100644--- a/apps/desktop/box/go/cmd/boxd/egress.go+++ b/apps/desktop/box/go/cmd/boxd/egress.go@@ -73,6 +73,10 @@ func offlineLine(host string) string {// offlineBin: the shims' folder, first on the commands' PATH (/opt/omnirush is left out of snapshots).var offlineBin = "/opt/omnirush/offline/bin"+// offlineProfile puts offlineBin back in front of PATH in login shells (/etc/profile resets PATH);+// left out of snapshots like offlineBin.+var offlineProfile = "/etc/profile.d/omnirush-offline.sh"+// unshareNet makes the calling thread's network namespace (a variable: tests make it fail).var unshareNet = func() error { return syscall.Unshare(syscall.CLONE_NEWNET) }@@ -126,6 +130,9 @@ func startEgress(mode string) error {if err := writeShims(offlineBin); err != nil {return fmt.Errorf("shims: %w", err)}+ if err := writeProfile(offlineProfile, offlineBin); err != nil {+ return fmt.Errorf("login shells: %w", err)+ }egressNS = m.nsegressPort.Store(int64(m.ln.Addr().(*net.TCPAddr).Port))go (&http.Server{Handler: http.HandlerFunc(proxy), ReadHeaderTimeout: 30 * time.Second}).Serve(m.ln)@@ -271,6 +278,22 @@ func netProc() string {return "/proc/thread-self/net/"}+// writeProfile writes the login shells' PATH line (sh, bash; Debian's /etc/profile reads profile.d).+func writeProfile(file, dir string) error {+ if err := os.MkdirAll(filepath.Dir(file), 0o755); err != nil {+ return err+ }+ text := "# OmniRush (farm runs; boxd egress.go): the offline shims first on PATH in login shells too.\n" ++ "case \":$PATH:\" in *:" + dir + ":*) ;; *) PATH=\"" + dir + ":$PATH\"; export PATH ;; esac\n"+ return os.WriteFile(file, []byte(text), 0o644)+}++// clearEgress removes what a farm start left in the box (a normal start after one).+func clearEgress() {+ _ = os.Remove(offlineProfile)+ _ = os.RemoveAll(filepath.Dir(offlineBin))+}+// writeShims puts git, curl and wget into dir: a call to a remote that is not a farm host (nor// this box's loopback) prints offlineLine and fails; every other call runs the real program.func writeShims(dir string) error {diff --git a/apps/desktop/box/go/cmd/boxd/egress_test.go b/apps/desktop/box/go/cmd/boxd/egress_test.goindex 75d8998d..49296d83 100644--- a/apps/desktop/box/go/cmd/boxd/egress_test.go+++ b/apps/desktop/box/go/cmd/boxd/egress_test.go@@ -176,3 +176,37 @@ func TestShims(t *testing.T) {}}}++func TestOfflineProfile(t *testing.T) {+ dir := t.TempDir()+ profile, bin := filepath.Join(dir, "profile.d", "omnirush-offline.sh"), filepath.Join(dir, "offline", "bin")+ if err := writeShims(bin); err != nil {+ t.Fatal(err)+ }+ if err := writeProfile(profile, bin); err != nil {+ t.Fatal(err)+ }+ for _, sh := range []string{"/bin/sh", "/bin/bash"} {+ // As /etc/profile leaves it (PATH reset), and when the shims are already first (no second copy).+ for _, path := range []string{"/usr/local/bin:/usr/bin:/bin", bin + ":/usr/bin:/bin"} {+ cmd := exec.Command(sh, "-c", `. "$1"; command -v git; echo "$PATH"`, "sh", profile)+ cmd.Env = []string{"PATH=" + path}+ out, err := cmd.Output()+ lines := strings.Split(strings.TrimSpace(string(out)), "\n")+ if err != nil || len(lines) != 2 || lines[0] != filepath.Join(bin, "git") || strings.Count(lines[1], bin) != 1 {+ t.Errorf("%s with PATH=%s: %q %v", sh, path, out, err)+ }+ }+ }+ old := offlineProfile+ offlineProfile = profile+ oldBin := offlineBin+ offlineBin = bin+ t.Cleanup(func() { offlineProfile, offlineBin = old, oldBin })+ clearEgress()+ for _, p := range []string{profile, bin} {+ if _, err := os.Stat(p); !os.IsNotExist(err) {+ t.Errorf("%s left after a normal start", p)+ }+ }+}diff --git a/apps/desktop/box/go/cmd/boxd/main.go b/apps/desktop/box/go/cmd/boxd/main.goindex 10065e5d..e4d986f6 100644--- a/apps/desktop/box/go/cmd/boxd/main.go+++ b/apps/desktop/box/go/cmd/boxd/main.go@@ -160,6 +160,9 @@ func main() {if err := startEgress(cfg.egress); err != nil {log.Fatalf("egress: %v", err)}+ } else {+ // A box that ran a farm session before keeps no offline shims for this one.+ clearEgress()}ln, err := net.Listen("tcp", cfg.listen)if err != nil {@@ -789,7 +792,7 @@ func walkPaths(roots []string, max int) ([]proto.StatEntry, bool) {const baselineFile = "/opt/omnirush/state/baseline.gz"// Folders never walked for changes: kernel and runtime state, our own files.-var walkSkip = []string{"/proc", "/sys", "/dev", "/run", "/opt/omnirush"}+var walkSkip = []string{"/proc", "/sys", "/dev", "/run", "/opt/omnirush", offlineProfile}type sig struct {Mt, Ct, Size int64diff --git a/apps/server/src/box/box.ts b/apps/server/src/box/box.tsindex 6d8ac4c5..99cd838a 100644--- a/apps/server/src/box/box.ts+++ b/apps/server/src/box/box.ts@@ -64,7 +64,7 @@ const H = HOME_IN_BOX;/** Never part of a turn's environment: runtime state, logs, download caches the ledger replays. */export const NOISE_PREFIXES = ["/run", "/proc", "/sys", "/dev", "/var/log", "/var/cache/apt", "/var/lib/apt/lists", "/var/cache/debconf/templates.dat-old",- "/opt/omnirush", "/usr/sbin/docker-init", "/sbin/docker-init", "/var/lib/dpkg/lock", "/var/lib/dpkg/lock-frontend", "/var/cache/ldconfig/aux-cache",+ "/opt/omnirush", "/etc/profile.d/omnirush-offline.sh", "/usr/sbin/docker-init", "/sbin/docker-init", "/var/lib/dpkg/lock", "/var/lib/dpkg/lock-frontend", "/var/cache/ldconfig/aux-cache",`${H}/.cache/pip`, `${H}/.cache/uv`, `${H}/.cache/pre-commit`, `${H}/.cache/yarn`, `${H}/.cache/go-build`, `${H}/.cache/pnpm`,`${H}/.npm/_cacache`, `${H}/.npm/_logs`, `${H}/.npm/_update-notifier-last-checked`, `${H}/.npm/_npx`,`${H}/.bun/install/cache`, `${H}/.yarn/berry/cache`, `${H}/.local/share/pnpm/store`, `${H}/.cargo/registry/cache`, "/usr/local/cargo/registry/cache",diff --git a/apps/server/src/opencode-plugins/omnirush-box-next.test.ts b/apps/server/src/opencode-plugins/omnirush-box-next.test.tsindex 16ce63a6..a2520e55 100644--- a/apps/server/src/opencode-plugins/omnirush-box-next.test.ts+++ b/apps/server/src/opencode-plugins/omnirush-box-next.test.ts@@ -71,10 +71,12 @@ test("farm runs: the prompt gets the offline line only (no box note); other runsconst hooks = await engine(root);const saved = process.env.OMNIRUSH_FARM;try {- process.env.OMNIRUSH_FARM = "1";- const farm = { sessionID: "ses_f", system: ["Platform: darwin"] as unknown[] };- await hooks.get("context")!(farm);- expect(farm.system).toEqual(["Platform: linux", { type: "text", text: OFFLINE_NOTE }]);+ for (const on of ["1", "true", "on", "yes"]) {+ process.env.OMNIRUSH_FARM = on;+ const farm = { sessionID: "ses_f", system: ["Platform: darwin"] as unknown[] };+ await hooks.get("context")!(farm);+ expect(farm.system).toEqual(["Platform: linux", { type: "text", text: OFFLINE_NOTE }]);+ }expect(OFFLINE_NOTE).toBe("This session is offline: the shell cannot reach the internet, except package installs (npm/pnpm/yarn, pip/uv, cargo, go, composer). Mock external services and APIs instead of calling them.");for (const off of [undefined, "0"]) {if (off === undefined) delete process.env.OMNIRUSH_FARM;diff --git a/apps/server/src/opencode-plugins/omnirush-box.ts b/apps/server/src/opencode-plugins/omnirush-box.tsindex 4fbb80cc..a3622f31 100644--- a/apps/server/src/opencode-plugins/omnirush-box.ts+++ b/apps/server/src/opencode-plugins/omnirush-box.ts@@ -25,6 +25,7 @@ import path from "node:path";import { BOX_HEADER } from "../model-modes/model-modes.mjs";import { BOX_NOTE, OFFLINE_NOTE, desktopProjects, engineDirs, FILE_TOOLS, keyOf, record, toolPaths, within } from "../box/plugin-lib.js";+import { stockMode } from "../stock-mode/stock-mode.mjs";/** The engine client's one call used here: a chat's parent (a sub-agent's chat has one). */type SessionReader = { session: { get: (options: { path: { id: string } }) => Promise<{ data?: { parentID?: string } | null } | undefined> } };@@ -91,7 +92,8 @@ export const OmniRushBox = async ({ directory, client }: { directory?: string; c}// Stock mode (stock-mode.mjs, the CLI's opencode-box-plugin.js): the system prompt stays stock apart from its environment lines,// and the one line that says the box is offline (farm runs' boxes are: boxd egress.go).- if (process.env.OMNIRUSH_FARM === "1") {+ // stockMode, as the box's egress (bwrap.ts boxEgress) reads it: the two never disagree.+ if (stockMode(process.env)) {output.system.push(OFFLINE_NOTE);return;}