From be7b8278c54ca97192e12fe5a633df220083d7ba Mon Sep 17 00:00:00 2001 From: iamtoruk Date: Sat, 30 May 2026 00:10:29 -0700 Subject: [PATCH] feat(menubar): add CodeburnCLI.scriptEnvironment for shell-script embedding Exposes the validated argv and augmented PATH so the LaunchAgent runner script can be generated without re-resolving the binary or PATH. --- mac/Sources/CodeBurnMenubar/CodeBurnApp.swift | 8 ++------ .../CodeBurnMenubar/Security/CodeburnCLI.swift | 7 +++++++ .../MenubarRefreshScriptTests.swift | 16 ++++++++++++++++ 3 files changed, 25 insertions(+), 6 deletions(-) create mode 100644 mac/Tests/CodeBurnMenubarTests/MenubarRefreshScriptTests.swift diff --git a/mac/Sources/CodeBurnMenubar/CodeBurnApp.swift b/mac/Sources/CodeBurnMenubar/CodeBurnApp.swift index 25cbba51..3e2c475e 100644 --- a/mac/Sources/CodeBurnMenubar/CodeBurnApp.swift +++ b/mac/Sources/CodeBurnMenubar/CodeBurnApp.swift @@ -161,12 +161,8 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSPopoverDelegate { } private func prepareRefreshPipelineForSleep() { - // Cancel only in-flight work so a fetch started before sleep cannot - // apply a stale result after wake. The DispatchSource timer is paused - // by the kernel during sleep and fires normally on wake, so we leave - // it running — tearing it down here was the stranding bug: a missed - // wake notification left refreshTimer nil forever. The 5s rate limiter - // and single-flight forceRefreshTask guard absorb the wake burst. + // Leave the timer running: the kernel pauses it during sleep, and tearing + // it down stranded the loop whenever a wake notification was missed. forceRefreshTask?.cancel() forceRefreshTask = nil forceRefreshStartedAt = nil diff --git a/mac/Sources/CodeBurnMenubar/Security/CodeburnCLI.swift b/mac/Sources/CodeBurnMenubar/Security/CodeburnCLI.swift index befa3b1b..13a3e6c9 100644 --- a/mac/Sources/CodeBurnMenubar/Security/CodeburnCLI.swift +++ b/mac/Sources/CodeBurnMenubar/Security/CodeburnCLI.swift @@ -99,6 +99,13 @@ enum CodeburnCLI { return process } + // argv tokens are `isSafe`-validated and PATH entries are constants, so the + // result is safe to interpolate directly into the LaunchAgent shell script. + static func scriptEnvironment() -> (argv: [String], path: String) { + let basePath = ProcessInfo.processInfo.environment["PATH"] ?? "" + return (baseArgv(), augmentedPath(basePath)) + } + static func isSafe(_ s: String) -> Bool { let range = NSRange(s.startIndex..