mirror of
https://github.com/AgentSeal/codeburn.git
synced 2026-04-28 06:59:37 +00:00
Introduces mac/ with a native SwiftUI menubar app that replaces the previous SwiftBar plugin entirely. Install via `npx codeburn menubar`, which downloads the .app from GitHub Releases, strips Gatekeeper quarantine, and drops it into ~/Applications. Highlights - mac/ SwiftUI app: agent tabs, Today/7/30/Month/All period switcher, Trend/Forecast/Pulse/Stats/Plan insights, activity + model breakdowns, optimize findings, CSV/JSON export, Star-on-GitHub banner, live 60s refresh, instant currency switching with offline FX cache. - Security: CodeburnCLI argv-based spawn (no shell interpretation), SafeFile symlink guards + O_NOFOLLOW writes, FX rate clamping to [0.0001, 1_000_000], keychain filtered to account == "default", removed byte-window credential log, in-flight refresh guard, POSIX flock on config.json writes, TerminalLauncher validates argv before AppleScript interpolation. - Performance: shared static NumberFormatter (thousands of allocations per popover redraw eliminated), concurrent pipe drain with 20 MB cap + 60s timeout in DataClient, Observation-tracked reactive UI, 5-min payload cache keyed on (period, provider). - CLI: new `codeburn menubar` subcommand that downloads + installs + launches the .app (no clone, no build). New `status --format menubar-json` payload builder. `export` rewritten to produce a folder of one-table-per-file CSVs with a `.codeburn-export` marker so arbitrary -o paths cannot be silently deleted. - Removed: src/menubar.ts (SwiftBar plugin generator), install-menubar / uninstall-menubar subcommands, `status --format menubar` directive output, tests/menubar.test.ts, tests/security/menubar-injection.test.ts. - Release: .github/workflows/release-menubar.yml builds universal binary, assembles .app, ad-hoc signs, zips, uploads on mac-v* tag push. Runs on the free macos-latest runner. Tests - 230 TypeScript tests pass - 10 Swift CapacityEstimator tests pass - TypeScript typecheck clean - Swift release build clean
99 lines
3.2 KiB
Swift
99 lines
3.2 KiB
Swift
import SwiftUI
|
|
|
|
struct SparklineView: View {
|
|
let points: [Double]
|
|
|
|
var body: some View {
|
|
GeometryReader { geo in
|
|
let cgPoints = makePoints(in: geo.size)
|
|
let smooth = smoothPath(cgPoints)
|
|
|
|
ZStack {
|
|
// Gradient fill under the curve
|
|
let fill = closedPath(smooth, width: geo.size.width, height: geo.size.height)
|
|
fill.fill(
|
|
LinearGradient(
|
|
colors: [Theme.brandAccent.opacity(0.25), .clear],
|
|
startPoint: .top,
|
|
endPoint: .bottom
|
|
)
|
|
)
|
|
|
|
// Smooth accent stroke
|
|
smooth.stroke(
|
|
Theme.brandAccent.opacity(0.85),
|
|
style: StrokeStyle(lineWidth: 1.6, lineCap: .round, lineJoin: .round)
|
|
)
|
|
|
|
// Highlighted current-day point
|
|
if let last = cgPoints.last {
|
|
Circle()
|
|
.fill(Theme.brandAccent)
|
|
.frame(width: 6, height: 6)
|
|
.overlay(
|
|
Circle()
|
|
.stroke(Color(NSColor.windowBackgroundColor).opacity(0.9), lineWidth: 1.3)
|
|
)
|
|
.position(last)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// MARK: - Geometry
|
|
|
|
private func makePoints(in size: CGSize) -> [CGPoint] {
|
|
guard !points.isEmpty else { return [] }
|
|
let w = size.width
|
|
let h = size.height
|
|
let maxV = points.max() ?? 1
|
|
let minV = points.min() ?? 0
|
|
let range = max(maxV - minV, 1)
|
|
let count = max(points.count - 1, 1)
|
|
let topPad: CGFloat = 5
|
|
let bottomPad: CGFloat = 5
|
|
let usable = max(h - topPad - bottomPad, 1)
|
|
|
|
return points.enumerated().map { idx, v in
|
|
CGPoint(
|
|
x: w * CGFloat(idx) / CGFloat(count),
|
|
y: h - bottomPad - usable * CGFloat(v - minV) / CGFloat(range)
|
|
)
|
|
}
|
|
}
|
|
|
|
/// Catmull-Rom → cubic bezier. Standard smooth interpolation, no overshoot.
|
|
private func smoothPath(_ pts: [CGPoint]) -> Path {
|
|
var path = Path()
|
|
guard pts.count >= 2 else { return path }
|
|
path.move(to: pts[0])
|
|
|
|
let tension: CGFloat = 0.5
|
|
for i in 0..<(pts.count - 1) {
|
|
let p0 = i > 0 ? pts[i - 1] : pts[i]
|
|
let p1 = pts[i]
|
|
let p2 = pts[i + 1]
|
|
let p3 = i + 2 < pts.count ? pts[i + 2] : p2
|
|
|
|
let cp1 = CGPoint(
|
|
x: p1.x + (p2.x - p0.x) * tension / 3,
|
|
y: p1.y + (p2.y - p0.y) * tension / 3
|
|
)
|
|
let cp2 = CGPoint(
|
|
x: p2.x - (p3.x - p1.x) * tension / 3,
|
|
y: p2.y - (p3.y - p1.y) * tension / 3
|
|
)
|
|
path.addCurve(to: p2, control1: cp1, control2: cp2)
|
|
}
|
|
return path
|
|
}
|
|
|
|
/// Close the path along the bottom to form a fill region.
|
|
private func closedPath(_ line: Path, width: CGFloat, height: CGFloat) -> Path {
|
|
var p = line
|
|
p.addLine(to: CGPoint(x: width, y: height))
|
|
p.addLine(to: CGPoint(x: 0, y: height))
|
|
p.closeSubpath()
|
|
return p
|
|
}
|
|
}
|