The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu
Go agent-ai-cliagent-harnessesagent-securitybrowser-extensionciclaude-codecloudcodexcursordetection-engineeringjevknowledge-basememorymobile-device-managementobservabilitysecuritysecurity-information-and-event-managementsecurity-toolstelemetrytraces
Give the user-mode inventory job its own launchd log files
shukieshahc1c1023198bd
diff --git a/cli/beacon/internal/endpoint/service/inventory.go b/cli/beacon/internal/endpoint/service/inventory.goindex 9ec0571a..3c1e7960 100644--- a/cli/beacon/internal/endpoint/service/inventory.go+++ b/cli/beacon/internal/endpoint/service/inventory.go@@ -181,7 +181,7 @@ func (m InventoryManager) WriteUnit(program, logPath string) (string, error) {}return path, nil}- content := inventoryPlist(InventoryLabel, program, args, InventoryInterval())+ content := inventoryPlist(InventoryLabel, program, args, InventoryInterval(), inventoryJobLogPrefix(m.UserMode))if err := os.WriteFile(path, []byte(content), 0o644); err != nil {return "", err}@@ -309,9 +309,20 @@ WantedBy=timers.target`, int(interval.Seconds()), InventoryServiceUnit)}+// inventoryJobLogPrefix is where launchd sends the job's stdout and stderr. The user-mode path+// carries the uid: a machine that also has (or once had) the system-mode job owns+// /tmp/<label>.out as root, and a LaunchAgent that cannot open its own log files is refused by+// launchd with EX_CONFIG before it ever runs.+func inventoryJobLogPrefix(userMode bool) string {+ if userMode {+ return fmt.Sprintf("/tmp/%s.%d", InventoryLabel, os.Getuid())+ }+ return "/tmp/" + InventoryLabel+}+// inventoryPlist renders the launchd job: one shot at load, then every interval. No KeepAlive,// so launchd does not restart a job that exited normally.-func inventoryPlist(label, program string, args []string, interval time.Duration) string {+func inventoryPlist(label, program string, args []string, interval time.Duration, logPrefix string) string {var argv strings.Builderfmt.Fprintf(&argv, " <string>%s</string>\n", xmlEscape(program))for _, arg := range args {@@ -331,10 +342,10 @@ func inventoryPlist(label, program string, args []string, interval time.Duration<key>StartInterval</key><integer>%d</integer><key>StandardOutPath</key>- <string>/tmp/%s.out</string>+ <string>%s.out</string><key>StandardErrorPath</key>- <string>/tmp/%s.err</string>+ <string>%s.err</string></dict></plist>-`, xmlEscape(label), argv.String(), int(interval.Seconds()), xmlEscape(label), xmlEscape(label))+`, xmlEscape(label), argv.String(), int(interval.Seconds()), xmlEscape(logPrefix), xmlEscape(logPrefix))}diff --git a/cli/beacon/internal/endpoint/service/inventory_test.go b/cli/beacon/internal/endpoint/service/inventory_test.goindex 73256bf2..2469bcf8 100644--- a/cli/beacon/internal/endpoint/service/inventory_test.go+++ b/cli/beacon/internal/endpoint/service/inventory_test.go@@ -13,7 +13,7 @@ import (func TestInventoryPlistIsAOneShotIntervalJob(t *testing.T) {args := inventoryJobArgs(false, "")- got := inventoryPlist(InventoryLabel, "/opt/beacon/bin/beacon", args, 6*time.Hour)+ got := inventoryPlist(InventoryLabel, "/opt/beacon/bin/beacon", args, 6*time.Hour, inventoryJobLogPrefix(false))for _, want := range []string{"<string>com.beacon.endpoint.inventory</string>","<string>/opt/beacon/bin/beacon</string>",@@ -31,14 +31,20 @@ func TestInventoryPlistIsAOneShotIntervalJob(t *testing.T) {t.Fatalf("plist must not contain %q:\n%s", forbidden, got)}}- user := inventoryPlist(InventoryLabel, "/usr/local/bin/beacon", inventoryJobArgs(true, "/Users/me/.beacon/endpoint/logs/runtime.jsonl"), time.Hour)+ user := inventoryPlist(InventoryLabel, "/usr/local/bin/beacon", inventoryJobArgs(true, "/Users/me/.beacon/endpoint/logs/runtime.jsonl"), time.Hour, inventoryJobLogPrefix(true))if !strings.Contains(user, "<string>--user</string>") || strings.Contains(user, "<string>--system</string>") {t.Fatalf("user-mode plist must carry --user:\n%s", user)}if !strings.Contains(user, "<string>--log-path</string>\n <string>/Users/me/.beacon/endpoint/logs/runtime.jsonl</string>") {t.Fatalf("plist must pass the pinned log path:\n%s", user)}- escaped := inventoryPlist("l", "/tmp/a&b", []string{"--log-path", "/tmp/<c>.jsonl"}, time.Hour)+ // A user agent must not share the system daemon's root-owned /tmp log files, or launchd+ // refuses to spawn it (EX_CONFIG). Seen live on a Mac with both modes installed.+ uidSuffixed := fmt.Sprintf("/tmp/%s.%d.err", InventoryLabel, os.Getuid())+ if !strings.Contains(user, uidSuffixed) || strings.Contains(user, "/tmp/"+InventoryLabel+".err") {+ t.Fatalf("user-mode plist must log to a per-user path, got:\n%s", user)+ }+ escaped := inventoryPlist("l", "/tmp/a&b", []string{"--log-path", "/tmp/<c>.jsonl"}, time.Hour, "/tmp/l")if !strings.Contains(escaped, "/tmp/a&b") || !strings.Contains(escaped, "<c>") {t.Fatalf("plist must XML-escape program and arguments:\n%s", escaped)}@@ -53,7 +59,7 @@ func TestInventoryIntervalEnvOverride(t *testing.T) {if got := InventoryInterval(); got != time.Minute {t.Fatalf("overridden interval = %s, want 1m", got)}- plist := inventoryPlist(InventoryLabel, "/opt/beacon/bin/beacon", inventoryJobArgs(false, ""), InventoryInterval())+ plist := inventoryPlist(InventoryLabel, "/opt/beacon/bin/beacon", inventoryJobArgs(false, ""), InventoryInterval(), inventoryJobLogPrefix(false))if !strings.Contains(plist, "<key>StartInterval</key>\n <integer>60</integer>") {t.Fatalf("plist should use the overridden interval:\n%s", plist)}