mirror of
https://github.com/AgentSeal/codeburn.git
synced 2026-11-29 10:43:47 +00:00
Some checks are pending
CI / semgrep (push) Waiting to run
macOS Menubar CI / test (push) Waiting to run
Tests / desktop (push) Waiting to run
Tests / test (22) (push) Waiting to run
Tests / test (22.13.0) (push) Waiting to run
Tests / test (24) (push) Waiting to run
Tests / test (26) (push) Waiting to run
Tests / test-platforms (macos-latest) (push) Waiting to run
Tests / test-platforms (windows-latest) (push) Waiting to run
Windows Menubar CI / check (windows-latest) (push) Waiting to run
Windows Menubar CI / check (ubuntu-latest) (push) Waiting to run
* fix: open menu bar Settings centered on the active screen
The window was positioned at a 520x380 placeholder while SwiftUI's own
minimum is 880x620, so the grown window kept its top-left corner and ran
off the bottom-right edge. Size the window from the view's minimum, place
it with a tested pure function, and honour a saved frame only while it
still fits on one of today's screens.
* fix: say where the telemetry toggle is managed when the desktop app owns it
A desktop telemetry.v1.json with enabled:false locks the menu bar toggle
off, so clicking it does nothing. Name the desktop app's Privacy & data
pane in the caption, and pin the four desktop/veto combinations plus the
standalone case in tests.
* fix(desktop): export the provider id, and never swallow a rejected setter
The export pane built its provider list from `current.providers`, which is
keyed on the lowercased display name. Five of the seventeen providers on a
real corpus ("cursor agent", "grok build", "kimi code", "hermes agent",
"grok bot") are not valid ids, so vProvider rejected them as bad-args.
`exportNow` had a try/finally and no catch, so the rejection produced no
toast and no file: the button did nothing. Use detectedProviders, which
already resolves ids from providerDetails, and toast on rejection.
The telemetry consent toggle swallowed its rejection the same way.
* fix(desktop): warm only the selected period, and only while visible
The post-paint sweep warmed all six standard periods x seven reports plus
the provider overviews: up to 48 serve-routed queries, ~18 CPU-seconds a
minute for five minutes and 2.79 GB peak RSS on a real corpus, and it ran
with the window hidden. It now warms the selected period's reports (its
own overview is already under that memo key from the visible poll) and
the other providers' headlines for that same period, holding before every
request while a user fetch is in flight or the window is hidden. Other
periods take the ordinary on-demand path.
Also corrects two comments that claimed background priority lets a click
jump ahead: spawnCli takes the serve fast path before priority is read,
and the resident child answers FIFO.
* fix(desktop): answer the click, report the write, tell the truth about the Claude login
Nine bridge setters in Settings attached only .then(), so a rejected
envelope produced no toast and the control read as if it had ignored the
click. One shared helper toasts the rejection, per pane fallback wording.
Telemetry save() swallowed write errors while setEnabled returned the
in-memory status, so the UI could show ON while the file the macOS menu
bar app reads still said OFF. The setters now carry persisted:boolean and
the renderer toasts when it is false; the write goes through the existing
atomic writeFileAtomic (temp file, rename) so a crash cannot tear it.
The Claude card called a logged-in Claude Code 2.x user "disconnected"
forever, because the credential lives only in the keychain and the first
poll never reads it. A new darwin-only keychainUnchecked state says we
have not looked yet and offers the forced read, keeping the login
instructions for the genuinely-logged-out case. ConnectAffordance's
toggle is renamed to what it does: it discloses instructions.
* fix: retry tax is the cost of retried edit turns, not a multiple of spend
* stop the change guard watching a Warp path it can never stat
* apply a menu bar language change in place instead of relaunching
* keep honoring WARP_DB_PATH in the change guard
* restart a menu bar too old to watch AppleLanguages
* one rebuild per language change, and no global bundle in tests
* fix(desktop): a forced quota refresh must not join the poll it just aborted
Check now / Refresh / ⌘R invalidated the quota service and then handed the
caller the background fetch it had just aborted, so every provider failed
its generation check and resolved disconnected: the click repainted every
card as logged out without ever reading the keychain, and Claude showed
"Not connected. Log in with the Claude CLI." A call now joins an in-flight
run only when that run is at least as privileged, so a keychain-allowed
call starts its own; a second forced click still joins the first, which
keeps the single macOS prompt. A superseded run hands its caller the run
that replaced it instead of its own abort artefacts.
retainOnFailure also holds accessDenied through a keychainUnchecked poll,
so the "Allow in keychain" guidance is not replaced by "Check now" one
cycle after the user denied the prompt.
* fix(desktop): stop the sweep churning, and never spend a query on an abandoned one
The prefetch effect depended on the detected-provider entries, whose costs
move on every overview poll, so it was torn down and restarted each cadence
tick: a warm slower than the interval was discarded and re-issued forever.
It now depends on the provider ids alone, and a finished warm is kept for
its own period/provider key even if the effect was torn down meanwhile —
only a config-generation change makes a result wrong.
Both loops re-test cancellation and the memo after the hold, which has no
bound, so an abandoned sweep issues nothing and a section the user visited
meanwhile is not parsed again. The hidden half of the hold waits on
visibilitychange instead of waking the renderer every two seconds for a
window nobody is looking at.
* fix(desktop): never offer a provider id the CLI will reject, and keep the keychain note
detectedProviders applied the round-trip filter only to the legacy
providers map; a providerDetails id with a space reached the picker and the
export as a --provider value the main process rejects.
The Plans settings row showed the "not read your login yet" line without
the note that macOS may ask once for keychain access, which the Plans card
does show.
197 lines
13 KiB
Swift
197 lines
13 KiB
Swift
import Foundation
|
|
|
|
struct UsageDataSnapshot: Equatable, Sendable {
|
|
let modificationDates: [String: Date]
|
|
}
|
|
|
|
/// Cheap change detection for the background menubar usage refresh. This is
|
|
/// deliberately not a recursive session scan: a 30s timer must not replace a
|
|
/// full Node parse with a full Swift walk of the same corpus.
|
|
enum UsageDataChangeGuard {
|
|
/// Unchanged-skips are honored for at most this long after the last
|
|
/// successful fetch. The snapshot below stats directories, so a session
|
|
/// appending to an existing transcript looks unchanged for as long as the
|
|
/// skip lasts; five minutes matches the resident serve child's own reuse
|
|
/// cap, which is what makes the refresh it forces cheap.
|
|
static let maxSkipIntervalSeconds: TimeInterval = 5 * 60
|
|
|
|
static func shouldSkip(
|
|
current: UsageDataSnapshot,
|
|
lastSuccessful: UsageDataSnapshot?,
|
|
lastSuccessAt: Date?,
|
|
now: Date = Date(),
|
|
force: Bool
|
|
) -> Bool {
|
|
guard !force, let lastSuccessful, let lastSuccessAt else { return false }
|
|
guard now.timeIntervalSince(lastSuccessAt) < maxSkipIntervalSeconds else { return false }
|
|
return current == lastSuccessful
|
|
}
|
|
|
|
static func snapshot(
|
|
fileManager: FileManager = .default,
|
|
environment: [String: String] = ProcessInfo.processInfo.environment,
|
|
homeDirectory: String = NSHomeDirectory()
|
|
) -> UsageDataSnapshot {
|
|
var dates: [String: Date] = [:]
|
|
var roots: [UsageDataRoot] = []
|
|
|
|
func add(_ path: String, scanFirstLevelDirectories: Bool = true) {
|
|
let root = UsageDataRoot(path: path, scanFirstLevelDirectories: scanFirstLevelDirectories)
|
|
guard !path.isEmpty, !roots.contains(root) else { return }
|
|
roots.append(root)
|
|
}
|
|
|
|
// These are the exact configurable roots used by the menubar's CLI
|
|
// payload path. Claude's projects directories are the normal session
|
|
// roots; the desktop root is included because its project directories
|
|
// are discovered below a Claude-managed workspace hierarchy.
|
|
for configDir in claudeConfigDirectories(environment: environment, homeDirectory: homeDirectory) {
|
|
add(path(configDir, "projects"))
|
|
}
|
|
add(environment["CODEBURN_DESKTOP_SESSIONS_DIR"] ?? path(homeDirectory, "Library", "Application Support", "Claude", "local-agent-mode-sessions"))
|
|
|
|
let codexHome = expand(environment["CODEX_HOME"] ?? path(homeDirectory, ".codex"), homeDirectory: homeDirectory)
|
|
add(path(codexHome, "sessions"))
|
|
add(path(codexHome, "archived_sessions"))
|
|
|
|
let cursorUser = path(homeDirectory, "Library", "Application Support", "Cursor", "User")
|
|
add(path(cursorUser, "globalStorage", "state.vscdb"), scanFirstLevelDirectories: false)
|
|
add(path(cursorUser, "workspaceStorage"))
|
|
let cursorAgentHome = path(homeDirectory, ".cursor")
|
|
add(path(cursorAgentHome, "projects"))
|
|
add(path(cursorAgentHome, "ai-tracking", "ai-code-tracking.db"), scanFirstLevelDirectories: false)
|
|
|
|
let xdgData = environment["XDG_DATA_HOME"] ?? path(homeDirectory, ".local", "share")
|
|
let xdgConfig = environment["XDG_CONFIG_HOME"] ?? path(homeDirectory, ".config")
|
|
let applicationSupport = path(homeDirectory, "Library", "Application Support")
|
|
|
|
// Several providers use nested workspace/session layouts or SQLite
|
|
// files. Their stable top directories/files are cheap to stat, but this
|
|
// intentionally does not descend to individual transcript files; an
|
|
// in-place edit can therefore wait for the next directory-entry change
|
|
// or an interactive refresh. The tradeoff avoids a deep idle walk.
|
|
add(expand(environment["CODEWHALE_HOME"] ?? path(homeDirectory, ".codewhale"), homeDirectory: homeDirectory), scanFirstLevelDirectories: false)
|
|
add(path(homeDirectory, ".deepseek", "sessions"), scanFirstLevelDirectories: false)
|
|
add(path(homeDirectory, ".cline", "data"), scanFirstLevelDirectories: false)
|
|
let dshHome = expand(environment["DSH_HOME"] ?? path(homeDirectory, ".dsh"), homeDirectory: homeDirectory)
|
|
add(path(dshHome, "sessions"))
|
|
add(expand(environment["CODEBUFF_DATA_DIR"] ?? path(xdgConfig, "manicode"), homeDirectory: homeDirectory), scanFirstLevelDirectories: false)
|
|
let factoryHome = expand(environment["FACTORY_DIR"] ?? path(homeDirectory, ".factory"), homeDirectory: homeDirectory)
|
|
add(path(factoryHome, "sessions"), scanFirstLevelDirectories: false)
|
|
add(path(homeDirectory, ".gemini", "tmp"), scanFirstLevelDirectories: false)
|
|
add(path(homeDirectory, ".gemini", "antigravity", "conversations"), scanFirstLevelDirectories: false)
|
|
add(path(homeDirectory, ".gemini", "antigravity-cli", "conversations"), scanFirstLevelDirectories: false)
|
|
add(path(homeDirectory, ".gemini", "antigravity-cli", "implicit"), scanFirstLevelDirectories: false)
|
|
add(path(homeDirectory, ".gemini", "antigravity-ide", "conversations"), scanFirstLevelDirectories: false)
|
|
add(path(homeDirectory, ".gemini", "antigravity-ide", "implicit"), scanFirstLevelDirectories: false)
|
|
let hermesHome = expand(environment["HERMES_HOME"] ?? path(homeDirectory, ".hermes"), homeDirectory: homeDirectory)
|
|
add(hermesHome, scanFirstLevelDirectories: false)
|
|
add(path(applicationSupport, "IBM Bob", "User", "globalStorage", "ibm.bob-code"), scanFirstLevelDirectories: false)
|
|
add(path(applicationSupport, "Bob-IDE", "User", "globalStorage", "ibm.bob-code"), scanFirstLevelDirectories: false)
|
|
add(path(homeDirectory, ".kiro"), scanFirstLevelDirectories: false)
|
|
add(path(applicationSupport, "Kiro", "User", "globalStorage", "kiro.kiroagent"), scanFirstLevelDirectories: false)
|
|
add(path(applicationSupport, "Kiro", "User", "workspaceStorage"), scanFirstLevelDirectories: false)
|
|
let kimiHome = expand(environment["KIMI_SHARE_DIR"] ?? path(homeDirectory, ".kimi"), homeDirectory: homeDirectory)
|
|
add(path(kimiHome, "sessions"), scanFirstLevelDirectories: false)
|
|
let kimiCodeHome = expand(environment["KIMI_CODE_HOME"] ?? path(homeDirectory, ".kimi-code"), homeDirectory: homeDirectory)
|
|
add(path(kimiCodeHome, "sessions"))
|
|
add(path(homeDirectory, ".lingtai"), scanFirstLevelDirectories: false)
|
|
add(path(homeDirectory, ".lingtai-tui"), scanFirstLevelDirectories: false)
|
|
let vibeHome = expand(environment["VIBE_HOME"] ?? path(homeDirectory, ".vibe"), homeDirectory: homeDirectory)
|
|
add(path(vibeHome, "logs", "session"), scanFirstLevelDirectories: false)
|
|
let muxHome = expand(environment["CODEBURN_MUX_DIR"] ?? environment["MUX_ROOT"] ?? path(homeDirectory, ".mux"), homeDirectory: homeDirectory)
|
|
add(muxHome, scanFirstLevelDirectories: false)
|
|
for name in [".openclaw", ".clawdbot", ".moltbot", ".moldbot"] {
|
|
add(path(homeDirectory, name, "agents"), scanFirstLevelDirectories: false)
|
|
}
|
|
let openClaudeRoot = expand(environment["CODEBURN_OPENCLAUDE_DIR"] ?? path(homeDirectory, ".openclaude"), homeDirectory: homeDirectory)
|
|
add(path(openClaudeRoot, "projects"), scanFirstLevelDirectories: true)
|
|
add(path(applicationSupport, "Open Design"), scanFirstLevelDirectories: false)
|
|
add(path(homeDirectory, ".pi", "agent", "sessions"), scanFirstLevelDirectories: false)
|
|
add(path(homeDirectory, ".omp", "agent", "sessions"), scanFirstLevelDirectories: false)
|
|
add(expand(environment["QWEN_DATA_DIR"] ?? path(homeDirectory, ".qwen", "projects"), homeDirectory: homeDirectory), scanFirstLevelDirectories: false)
|
|
let grokHome = expand(environment["GROK_HOME"] ?? path(homeDirectory, ".grok"), homeDirectory: homeDirectory)
|
|
add(path(grokHome, "sessions"), scanFirstLevelDirectories: false)
|
|
add(expand(environment["ZS_DATA_DIR"] ?? path(applicationSupport, "zerostack"), homeDirectory: homeDirectory), scanFirstLevelDirectories: false)
|
|
add(expand(environment["OPENCODE_DATA_DIR"] ?? path(xdgData, "opencode"), homeDirectory: homeDirectory), scanFirstLevelDirectories: false)
|
|
add(path(xdgData, "kilo"), scanFirstLevelDirectories: false)
|
|
add(expand(environment["GOOSE_PATH_ROOT"] ?? path(xdgData, "goose"), homeDirectory: homeDirectory), scanFirstLevelDirectories: false)
|
|
add(expand(environment["CRUSH_GLOBAL_DATA"] ?? path(xdgData, "crush"), homeDirectory: homeDirectory), scanFirstLevelDirectories: false)
|
|
// Warp's default location is never watched. Its database lives in
|
|
// ~/Library/Group Containers/2BBY89MBSN.dev.warp (src/providers/warp.ts),
|
|
// and that tree is behind the "access data from other apps" consent: a
|
|
// process without it blocks in the kernel rather than failing, on a bare
|
|
// access(2) as much as on open() (see the TCC probe in src/sqlite.ts).
|
|
// Stat-ing it from the 30s refresh would hang the refresh and re-ask for
|
|
// consent. Without it, Warp-only writes can be skipped for at most
|
|
// maxSkipIntervalSeconds, the same staleness the in-place-edit case above
|
|
// already accepts. (The entry here used to name group.warp, a path that
|
|
// has never existed, so it watched nothing either way.)
|
|
//
|
|
// WARP_DB_PATH is the exception, because it is a path the person named
|
|
// themselves — the CLI (src/providers/warp.ts) and the Windows guard both
|
|
// honour it, and a copy kept outside the group container is exactly what
|
|
// it is for. Pointed back at the group container it carries that tree's
|
|
// risk, which is the caller's to take.
|
|
if let warpDB = environment["WARP_DB_PATH"], !warpDB.isEmpty {
|
|
add(expand(warpDB, homeDirectory: homeDirectory), scanFirstLevelDirectories: false)
|
|
}
|
|
add(path(homeDirectory, ".forge", ".forge.db"), scanFirstLevelDirectories: false)
|
|
add(path(homeDirectory, ".zcode", "cli", "db", "db.sqlite"), scanFirstLevelDirectories: false)
|
|
add(path(applicationSupport, "Zed", "threads", "threads.db"), scanFirstLevelDirectories: false)
|
|
add(path(xdgConfig, "github-copilot"), scanFirstLevelDirectories: false)
|
|
add(path(homeDirectory, ".copilot", "session-state"), scanFirstLevelDirectories: false)
|
|
add(path(applicationSupport, "Code", "User", "globalStorage", "github.copilot-chat", "agent-traces.db"), scanFirstLevelDirectories: false)
|
|
add(path(applicationSupport, "Code - Insiders", "User", "globalStorage", "github.copilot-chat", "agent-traces.db"), scanFirstLevelDirectories: false)
|
|
add(path(applicationSupport, "VSCodium", "User", "globalStorage", "github.copilot-chat", "agent-traces.db"), scanFirstLevelDirectories: false)
|
|
|
|
// A changed menubar config can change the roots above, so keep its
|
|
// mtime in the snapshot even when the configured directory list is the
|
|
// same. Network-only providers have no local data root to fingerprint.
|
|
add(path(homeDirectory, ".config", "codeburn", "config.json"), scanFirstLevelDirectories: false)
|
|
|
|
for root in roots {
|
|
dates[root.path] = modificationDate(atPath: root.path, fileManager: fileManager)
|
|
guard root.scanFirstLevelDirectories,
|
|
dates[root.path] != nil,
|
|
let entries = try? fileManager.contentsOfDirectory(atPath: root.path) else { continue }
|
|
for entry in entries {
|
|
let child = path(root.path, entry)
|
|
var isDirectory = ObjCBool(false)
|
|
guard fileManager.fileExists(atPath: child, isDirectory: &isDirectory), isDirectory.boolValue else { continue }
|
|
dates[child] = modificationDate(atPath: child, fileManager: fileManager)
|
|
}
|
|
}
|
|
return UsageDataSnapshot(modificationDates: dates)
|
|
}
|
|
|
|
private struct UsageDataRoot: Hashable {
|
|
let path: String
|
|
let scanFirstLevelDirectories: Bool
|
|
}
|
|
|
|
private static func modificationDate(atPath path: String, fileManager: FileManager) -> Date? {
|
|
guard let attributes = try? fileManager.attributesOfItem(atPath: path) else { return nil }
|
|
return attributes[.modificationDate] as? Date
|
|
}
|
|
|
|
static func claudeConfigDirectories(environment: [String: String], homeDirectory: String) -> [String] {
|
|
if let multi = environment["CLAUDE_CONFIG_DIRS"], !multi.isEmpty {
|
|
return multi.split(separator: ":").map { expand(String($0), homeDirectory: homeDirectory) }
|
|
}
|
|
if let single = environment["CLAUDE_CONFIG_DIR"], !single.isEmpty {
|
|
return [expand(single, homeDirectory: homeDirectory)]
|
|
}
|
|
let configured = CLIClaudeConfig.load()
|
|
return configured.isEmpty ? [path(homeDirectory, ".claude")] : configured.map { expand($0, homeDirectory: homeDirectory) }
|
|
}
|
|
|
|
private static func expand(_ value: String, homeDirectory: String) -> String {
|
|
guard value == "~" || value.hasPrefix("~/") else { return value }
|
|
return value == "~" ? homeDirectory : path(homeDirectory, String(value.dropFirst(2)))
|
|
}
|
|
|
|
private static func path(_ base: String, _ components: String...) -> String {
|
|
components.reduce(base) { ($0 as NSString).appendingPathComponent($1) }
|
|
}
|
|
}
|