Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
fix(macos): escape LaunchAgent paths
Samir Hanna Verza1f265a8b2f82
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex d7569b73..80a7a9de 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -11,6 +11,10 @@ version in [`docs/changelog/`](docs/changelog/):## [Unreleased]+### Fixed++- Fixed the macOS menu app’s LaunchAgent installation and restart checks for app and home-directory paths containing XML characters such as `&`. (#PR)+## [3.2.10] - 2026-10-29### Changeddiff --git a/companions/ai-memory-macos/README.md b/companions/ai-memory-macos/README.mdindex 1dddf60f..d64c9c02 100644--- a/companions/ai-memory-macos/README.md+++ b/companions/ai-memory-macos/README.md@@ -44,7 +44,7 @@ Drag the `.app` to `/Applications` for a stable LaunchAgent path. Notarization,3. The status item turns green when `GET /admin/status` succeeds.4. **Open Web UI**, **Show Status…** (bundled `ai-memory status`), **Open Config**, **Open Data Directory**, **Open Logs**.-Updates: replace `/Applications/AI Memory.app`. The data dir is untouched. If the helper path inside the bundle changed, **Restart Server** re-renders the plist.+Updates: replace `/Applications/AI Memory.app`. The data dir is untouched. If the helper path inside the bundle changed, **Restart Server** re-renders the plist. App and home-directory paths preserve spaces and XML characters such as `&` in the generated LaunchAgent.## Testsdiff --git a/companions/ai-memory-macos/Sources/AIMemoryMenuCore/LaunchdController.swift b/companions/ai-memory-macos/Sources/AIMemoryMenuCore/LaunchdController.swiftindex 76f731bc..55c4fd90 100644--- a/companions/ai-memory-macos/Sources/AIMemoryMenuCore/LaunchdController.swift+++ b/companions/ai-memory-macos/Sources/AIMemoryMenuCore/LaunchdController.swift@@ -34,8 +34,8 @@ public struct LaunchdController: Sendable {dataDir: URL?) -> String {var rendered = template- .replacingOccurrences(of: "__AI_MEMORY_BIN__", with: binary.path)- .replacingOccurrences(of: "__HOME__", with: home.path)+ .replacingOccurrences(of: "__AI_MEMORY_BIN__", with: xmlEscape(binary.path))+ .replacingOccurrences(of: "__HOME__", with: xmlEscape(home.path))if let dataDir {let env = """<key>EnvironmentVariables</key>@@ -53,19 +53,14 @@ public struct LaunchdController: Sendable {}public static func programArgumentsBinary(inPlist plist: String) -> String? {- // First <string> after ProgramArguments is the executable.- guard let argsRange = plist.range(of: "<key>ProgramArguments</key>") else {+ guard let values = try? PropertyListSerialization.propertyList(+ from: Data(plist.utf8), format: nil+ ) as? [String: Any],+ let arguments = values["ProgramArguments"] as? [String]+ else {return nil}- let rest = plist[argsRange.upperBound...]- guard let start = rest.range(of: "<string>") else {- return nil- }- let after = rest[start.upperBound...]- guard let end = after.range(of: "</string>") else {- return nil- }- return String(after[..<end.lowerBound])+ return arguments.first}public func writePlist(template: String, binary: URL, dataDir: URL?) throws {diff --git a/companions/ai-memory-macos/Tests/AIMemoryMenuTests/LaunchdControllerTests.swift b/companions/ai-memory-macos/Tests/AIMemoryMenuTests/LaunchdControllerTests.swiftindex 164b8479..7358da05 100644--- a/companions/ai-memory-macos/Tests/AIMemoryMenuTests/LaunchdControllerTests.swift+++ b/companions/ai-memory-macos/Tests/AIMemoryMenuTests/LaunchdControllerTests.swift@@ -62,6 +62,42 @@ struct LaunchdControllerTests {)#expect(rendered.contains("/tmp/a&b<c>"))}++ @Test func pathsRoundTripThroughTheInstalledPlist() throws {+ let templateURL = repoRoot()+ .appending(path: "packaging/launchd/com.github.akitaonrails.ai-memory.plist")+ let template = try String(contentsOf: templateURL, encoding: .utf8)+ let root = FileManager.default.temporaryDirectory+ .appending(path: "ai-memory-plist-\(UUID().uuidString)")+ defer { try? FileManager.default.removeItem(at: root) }+ let home = root.appending(path: "Ada & Bob <home>")+ let binary = root.appending(path: "R&D/AI Memory.app/Contents/Resources/runtime/ai-memory")+ let dataDir = home.appending(path: "Memory & Notes")+ let controller = LaunchdController(home: home)++ try controller.writePlist(template: template, binary: binary, dataDir: dataDir)++ let data = try Data(contentsOf: controller.plistDestination)+ let plist = try #require(+ PropertyListSerialization.propertyList(from: data, format: nil) as? [String: Any]+ )+ #expect(plist["ProgramArguments"] as? [String] == [binary.path, "serve", "--transport", "http", "--enable-web"])+ #expect(plist["StandardOutPath"] as? String == home.appending(path: "Library/Logs/ai-memory/stdout.log").path)+ #expect(plist["StandardErrorPath"] as? String == home.appending(path: "Library/Logs/ai-memory/stderr.log").path)+ #expect(plist["EnvironmentVariables"] as? [String: String] == ["AI_MEMORY_DATA_DIR": dataDir.path])+ #expect(LaunchdController.programArgumentsBinary(inPlist: String(decoding: data, as: UTF8.self)) == binary.path)+ }++ @Test func readsDecodedProgramArgumentsFromPlist() {+ let plist = """+ <plist version="1.0"><dict><key>ProgramArguments</key><array>+ <string>/Applications/R&D/AI Memory.app/ai-memory</string><string>serve</string>+ </array></dict></plist>+ """+ #expect(LaunchdController.programArgumentsBinary(inPlist: plist) == "/Applications/R&D/AI Memory.app/ai-memory")+ #expect(LaunchdController.programArgumentsBinary(inPlist: "not a plist") == nil)+ #expect(LaunchdController.programArgumentsBinary(inPlist: "<plist version=\"1.0\"><dict/></plist>") == nil)+ }}private func repoRoot(file: String = #filePath) -> URL {