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): keep the user's Codex instructions out of Agent runs
Ethanf448430a90d8
diff --git a/apps/computer/local-daemon/internal/workspace/codex_instructions_test.go b/apps/computer/local-daemon/internal/workspace/codex_instructions_test.goindex a0116ced..8267d718 100644--- a/apps/computer/local-daemon/internal/workspace/codex_instructions_test.go+++ b/apps/computer/local-daemon/internal/workspace/codex_instructions_test.go@@ -5,48 +5,67 @@ import ("os""path/filepath""testing"++ "github.com/pelletier/go-toml/v2")-func TestCodexPersonalInstructionsAreIsolatedAndRefreshed(t *testing.T) {+func TestCodexPersonalInstructionsStayOutOfAgentHomes(t *testing.T) {root := t.TempDir()shared, home := filepath.Join(root, ".codex"), filepath.Join(root, "runtime")- if err := os.MkdirAll(shared, 0700); err != nil {+ if err := os.MkdirAll(filepath.Join(shared, "rules"), 0700); err != nil {+ t.Fatal(err)+ }+ if err := os.MkdirAll(home, 0700); err != nil {t.Fatal(err)}opts := CodexHomeOptions{SharedHome: shared, UserHome: root, CodexVersion: "0.153.4"}- for _, name := range []string{"AGENTS.md", "AGENTS.override.md"} {+ // A home prepared before this rule still holds copies of the user's files.+ for _, name := range codexPersonalInstructionFiles {+ if err := os.WriteFile(filepath.Join(home, name), []byte("stale personal rule"), 0600); err != nil {+ t.Fatal(err)+ }if err := os.WriteFile(filepath.Join(shared, name), []byte("personal rule"), 0600); err != nil {t.Fatal(err)}}+ if err := os.WriteFile(filepath.Join(shared, "rules", "mine.md"), []byte("personal rule"), 0600); err != nil {+ t.Fatal(err)+ }+ config := "model = 'm'\ninstructions = 'be brief'\ndeveloper_instructions = 'be brief'\n" ++ "model_instructions_file = 'rules/mine.md'\nexperimental_instructions_file = 'rules/mine.md'\n" ++ "[profiles.work]\ndeveloper_instructions = 'be brief'\nmodel_instructions_file = 'rules/mine.md'\n"+ if err := os.WriteFile(filepath.Join(shared, "config.toml"), []byte(config), 0600); err != nil {+ t.Fatal(err)+ }if _, err := PrepareCodexHome(home, opts, slog.Default()); err != nil {t.Fatal(err)}- for _, name := range []string{"AGENTS.md", "AGENTS.override.md"} {- target := filepath.Join(home, name)- if data, err := os.ReadFile(target); err != nil || string(data) != "personal rule" {- t.Fatalf("missing inherited %s: %v", name, err)- }- if err := os.WriteFile(target, []byte("local edit"), 0600); err != nil {- t.Fatal(err)+ for _, name := range codexPersonalInstructionFiles {+ if _, err := os.Lstat(filepath.Join(home, name)); !os.IsNotExist(err) {+ t.Fatalf("%s reached the Agent home: %v", name, err)}if data, _ := os.ReadFile(filepath.Join(shared, name)); string(data) != "personal rule" {t.Fatal("modified personal source")}}- if err := os.Remove(filepath.Join(shared, "AGENTS.override.md")); err != nil {+ data, err := os.ReadFile(filepath.Join(home, "config.toml"))+ if err != nil {t.Fatal(err)}- if err := os.WriteFile(filepath.Join(shared, "AGENTS.md"), []byte("new rule"), 0600); err != nil {+ var settings map[string]any+ if err := toml.Unmarshal(data, &settings); err != nil {t.Fatal(err)}- if _, err := PrepareCodexHome(home, opts, slog.Default()); err != nil {- t.Fatal(err)- }- if data, _ := os.ReadFile(filepath.Join(home, "AGENTS.md")); string(data) != "new rule" {- t.Fatal("stale personal instructions")+ if settings["model"] != "m" {+ t.Fatalf("settings = %v", settings)}- if _, err := os.Lstat(filepath.Join(home, "AGENTS.override.md")); !os.IsNotExist(err) {- t.Fatal("stale override still masks AGENTS.md")+ profiles, _ := settings["profiles"].(map[string]any)+ profile, _ := profiles["work"].(map[string]any)+ for _, table := range []map[string]any{settings, profile} {+ for _, key := range []string{"instructions", "developer_instructions", "model_instructions_file", "experimental_instructions_file"} {+ if _, ok := table[key]; ok {+ t.Fatalf("%s reached the Agent home: %v", key, table)+ }+ }}}diff --git a/apps/computer/local-daemon/internal/workspace/codex_projection.go b/apps/computer/local-daemon/internal/workspace/codex_projection.goindex ef7d911f..01c462d6 100644--- a/apps/computer/local-daemon/internal/workspace/codex_projection.go+++ b/apps/computer/local-daemon/internal/workspace/codex_projection.go@@ -80,12 +80,24 @@ func PrepareCodexHome(home string, opts CodexHomeOptions, logger *slog.Logger) (args := []string{"-c", `sandbox_mode="danger-full-access"`}files := make(map[string][]byte)references := make(map[string][]byte)- for _, name := range []string{"config.json", "instructions.md", "AGENTS.md", "AGENTS.override.md"} {- data, err := readProjectionSource(filepath.Join(opts.SharedHome, name))- if err != nil {- return CodexProjection{}, err+ jsonConfig, err := readProjectionSource(filepath.Join(opts.SharedHome, "config.json"))+ if err != nil {+ return CodexProjection{}, err+ }+ files["config.json"] = jsonConfig+ // Agent instructions come only from the Daemon. The user's personal+ // instruction files stay out of the home, and a nil entry removes a copy+ // an earlier projection left there.+ for _, name := range codexPersonalInstructionFiles {+ files[name] = nil+ }+ stripCodexInstructionKeys(settings)+ if profiles, ok := settings["profiles"].(map[string]any); ok {+ for _, value := range profiles {+ if profile, ok := value.(map[string]any); ok {+ stripCodexInstructionKeys(profile)+ }}- files[name] = data}// Parse and serialize the tree once. Desktop Skill entries are regenerated// from discovered paths.@@ -287,8 +299,20 @@ func codexConfigDigest(settings map[string]any, files, references map[string][]breturn hex.EncodeToString(sum[:]), nil}+// codexPersonalInstructionFiles are the instruction files Codex reads from its+// home; the user's copies never reach an Agent's home.+var codexPersonalInstructionFiles = []string{"instructions.md", "AGENTS.md", "AGENTS.override.md"}++// stripCodexInstructionKeys drops the configuration keys that give Codex+// instructions, so the user's own cannot reach an Agent run.+func stripCodexInstructionKeys(table map[string]any) {+ for _, key := range []string{"instructions", "developer_instructions", "model_instructions_file", "experimental_instructions_file"} {+ delete(table, key)+ }+}+func collectConfigAssets(table map[string]any, home string, opts CodexHomeOptions, files map[string][]byte, references map[string][]byte, scope string) error {- for _, key := range []string{"model_catalog_json", "model_instructions_file", "experimental_instructions_file"} {+ for _, key := range []string{"model_catalog_json"} {value, exists := table[key]if !exists {continuediff --git a/apps/computer/local-daemon/internal/workspace/codex_projection_test.go b/apps/computer/local-daemon/internal/workspace/codex_projection_test.goindex 1ce13692..13234331 100644--- a/apps/computer/local-daemon/internal/workspace/codex_projection_test.go+++ b/apps/computer/local-daemon/internal/workspace/codex_projection_test.go@@ -86,18 +86,10 @@ func TestProjectionRefreshesReferencesAndInvalidatesOnlyUnboundCache(t *testing.home, opts := projectionFixture(t)catalog := filepath.Join(t.TempDir(), "catalog.json")projectionWrite(t, catalog, `{"models":[]}`)- config := "model_catalog_json='" + filepath.ToSlash(catalog) + "'\nmodel_instructions_file='nested/rules.md'\n"+ config := "model_catalog_json='" + filepath.ToSlash(catalog) + "'\n"projectionWrite(t, filepath.Join(opts.SharedHome, "config.toml"), config)- projectionWrite(t, filepath.Join(opts.SharedHome, "nested", "rules.md"), "first instructions")projectionWrite(t, filepath.Join(opts.SharedHome, "models_cache.json"), "unbound user cache")- settings := preparedSettings(t, home, opts)- projected := settings["model_instructions_file"].(string)- if !strings.HasPrefix(projected, filepath.Join(home, projectionAssets)+string(filepath.Separator)) {- t.Fatal(projected)- }- if projectionRead(t, projected) != "first instructions" {- t.Fatal("missing reference")- }+ preparedSettings(t, home, opts)cache := filepath.Join(home, "models_cache.json")if _, err := os.Stat(cache); !os.IsNotExist(err) {t.Fatal("imported unbound cache")@@ -112,14 +104,27 @@ func TestProjectionRefreshesReferencesAndInvalidatesOnlyUnboundCache(t *testing.if _, err := os.Stat(cache); !os.IsNotExist(err) {t.Fatal("reused cache after absolute catalog changed")}+}+func TestProjectionCopiesRelativeReferencesAndRetiresThem(t *testing.T) {+ home, opts := projectionFixture(t)+ projectionWrite(t, filepath.Join(opts.SharedHome, "config.toml"), "model_catalog_json='nested/catalog.json'\n")+ projectionWrite(t, filepath.Join(opts.SharedHome, "nested", "catalog.json"), `{"models":[]}`)+ settings := preparedSettings(t, home, opts)+ projected := settings["model_catalog_json"].(string)+ if !strings.HasPrefix(projected, filepath.Join(home, projectionAssets)+string(filepath.Separator)) {+ t.Fatal(projected)+ }+ if projectionRead(t, projected) != `{"models":[]}` {+ t.Fatal("missing reference")+ }projectionWrite(t, filepath.Join(opts.SharedHome, "config.toml"), "model='new-provider'\n")preparedSettings(t, home, opts)if _, err := os.Stat(projected); !os.IsNotExist(err) {- t.Fatal("retired instructions still stored")+ t.Fatal("retired reference still stored")}}func TestProjectionFailsBeforeLaunchOnInvalidConfiguration(t *testing.T) {- for _, config := range []string{"broken=[", "model_instructions_file='../outside'", "model_catalog_json='missing'"} {+ for _, config := range []string{"broken=[", "model_catalog_json='../outside'", "model_catalog_json='missing'"} {t.Run(config, func(t *testing.T) {home, opts := projectionFixture(t)projectionWrite(t, filepath.Join(opts.SharedHome, "config.toml"), config)diff --git a/apps/computer/local-daemon/internal/workspace/codex_skills_test.go b/apps/computer/local-daemon/internal/workspace/codex_skills_test.goindex 7cc55c21..139743fd 100644--- a/apps/computer/local-daemon/internal/workspace/codex_skills_test.go+++ b/apps/computer/local-daemon/internal/workspace/codex_skills_test.go@@ -252,8 +252,10 @@ func TestCodexProjectionDigestsFollowDeliveredInputs(t *testing.T) {if disabled := project(); disabled.SkillDigest == added.SkillDigest {t.Fatal("disabling a Skill kept the digest")}+ // The user's AGENTS.md never reaches the home, so editing it changes nothing.+ before := project()write(filepath.Join(shared, "AGENTS.md"), "Be brief.")- if got := project(); got.ConfigDigest == base.ConfigDigest {- t.Fatal("an AGENTS.md edit kept the configuration digest")+ if got := project(); got.ConfigDigest != before.ConfigDigest {+ t.Fatal("an AGENTS.md edit changed the configuration digest")}}