Open source Grok Bot alternative, Bring your own agent and subscription: message Claude Code, Codex, Gemini CLI, Cursor, Copilot and 40+ AI agents as bots on your own computer, from iPhone, Mac, Windows, Linux or terminal. Agent-agnostic and free. Also a Muse and Dots alternative. Built in Rust.
Rust acpagent-client-protocolai-agentsai-assistantclaudeclaude-codecodexcoding-agentscursorgeminigemini-cligrok-bot-alternativeiosiphonelinuxmacosmcpopen-sourcerustself-hosted
fix: cache Worker JWT token to prevent APNs 429, show text instead of icons on Watch
libokaic4b2768e9b3e
diff --git a/Codync-macOS/Services/APNsPushService.swift b/Codync-macOS/Services/APNsPushService.swiftindex f10590bc..fccc08d9 100644--- a/Codync-macOS/Services/APNsPushService.swift+++ b/Codync-macOS/Services/APNsPushService.swift@@ -16,9 +16,6 @@ final class APNsPushService {var tokenCount: Int { pushTokens.count }private var isFetchingTokens = falseprivate var lastTokenFetch: Date = .distantPast- private var lastPushTime: [String: Date] = [:]- private let pushInterval: TimeInterval = 2 // minimum seconds between pushes per token-private init() {logger.info("APNs push service ready (Worker relay)")}@@ -27,9 +24,6 @@ final class APNsPushService {func sendUpdate(session: SessionState) async {guard let tokenHex = pushTokens[session.sessionId] else { return }- let key = session.sessionId- if let last = lastPushTime[key], Date().timeIntervalSince(last) < pushInterval { return }- lastPushTime[key] = Date()let contentState = Self.buildContentState(from: session)let payload: [String: Any] = [@@ -42,9 +36,6 @@ final class APNsPushService {func sendOverallUpdate(sessions: [SessionState], primarySessionId: String?) async {guard let tokenHex = pushTokens["__overall__"] else { return }- let key = "__overall__"- if let last = lastPushTime[key], Date().timeIntervalSince(last) < pushInterval { return }- lastPushTime[key] = Date()let summaries: [[String: Any]] = sessions.prefix(4).map { session inlet liveDuration = max(session.durationSec, Int(Date().timeIntervalSince(session.startedAt)))diff --git a/CodyncLiveActivity/CodyncLiveActivityWidget.swift b/CodyncLiveActivity/CodyncLiveActivityWidget.swiftindex 2dcfec5a..11117359 100644--- a/CodyncLiveActivity/CodyncLiveActivityWidget.swift+++ b/CodyncLiveActivity/CodyncLiveActivityWidget.swift@@ -856,18 +856,12 @@ struct WatchIndividualView: View {}if let task = watchNonEmpty(state.currentTask) {- HStack(spacing: 5) {- Image(systemName: watchToolIcon(for: task))- .font(.system(size: 10, weight: .semibold))- .foregroundStyle(.white.opacity(0.4))- .frame(width: 14)- Text(watchSimplifyTool(task) ?? task)- .font(.subheadline)- .foregroundStyle(.white.opacity(0.7))- .lineLimit(1)- }- .id(task)- .transition(.push(from: .bottom))+ Text(task)+ .font(.subheadline)+ .foregroundStyle(.white.opacity(0.7))+ .lineLimit(1)+ .id(task)+ .transition(.push(from: .bottom))} else {Text(watchStatusLabel(state.status)).font(.subheadline)@@ -1000,13 +994,13 @@ struct WatchOverallView: View {Spacer(minLength: 0)- if session.status == .working {- IslandSparkle(durationSec: session.durationSec, size: 9)- } else if let task = session.currentTask, !task.isEmpty {+ if let task = session.currentTask, !task.isEmpty {Text(task).font(.system(size: 10)).foregroundStyle(.white.opacity(0.35)).lineLimit(1)+ } else if session.status == .working {+ IslandSparkle(durationSec: session.durationSec, size: 9)}}.padding(.vertical, 5)diff --git a/worker/src/index.ts b/worker/src/index.tsindex 82e34920..1d247732 100644--- a/worker/src/index.ts+++ b/worker/src/index.ts@@ -17,6 +17,41 @@ interface PushRequest {body?: string;}+// Cache ApnsClient instances at module level — reuses JWT token across requests+// within the same Worker isolate (token valid 20-60 min per Apple docs)+let cachedAlertClient: ApnsClient | null = null;+let cachedLiveActivityClient: ApnsClient | null = null;+let cachedEnvHash: string | null = null;++function getClients(env: Env): { alertClient: ApnsClient; liveActivityClient: ApnsClient } {+ const envHash = `${env.APNS_TEAM_ID}:${env.APNS_KEY_ID}`;+ if (cachedAlertClient && cachedLiveActivityClient && cachedEnvHash === envHash) {+ return { alertClient: cachedAlertClient, liveActivityClient: cachedLiveActivityClient };+ }++ const signingKey = env.APNS_SIGNING_KEY.replace(/\\n/g, "\n");+ const bundleId = "com.pokai.Codync.ios";++ cachedAlertClient = new ApnsClient({+ team: env.APNS_TEAM_ID,+ keyId: env.APNS_KEY_ID,+ signingKey,+ defaultTopic: bundleId,+ host: "api.sandbox.push.apple.com",+ });++ cachedLiveActivityClient = new ApnsClient({+ team: env.APNS_TEAM_ID,+ keyId: env.APNS_KEY_ID,+ signingKey,+ defaultTopic: `${bundleId}.push-type.liveactivity`,+ host: "api.sandbox.push.apple.com",+ });++ cachedEnvHash = envHash;+ return { alertClient: cachedAlertClient, liveActivityClient: cachedLiveActivityClient };+}+export default {async fetch(request: Request, env: Env): Promise<Response> {if (request.method !== "POST") {@@ -39,20 +74,11 @@ export default {return new Response("Missing pushToken", { status: 400 });}- const signingKey = env.APNS_SIGNING_KEY.replace(/\\n/g, "\n");- const bundleId = "com.pokai.Codync.ios";+ const { alertClient, liveActivityClient } = getClients(env);const pushType = body.type ?? "liveactivity";if (pushType === "alert") {// Regular alert notification (e.g., session completed)- const client = new ApnsClient({- team: env.APNS_TEAM_ID,- keyId: env.APNS_KEY_ID,- signingKey,- defaultTopic: bundleId,- host: "api.sandbox.push.apple.com",- });-const notification = new Notification(body.pushToken, {type: PushType.alert,priority: Priority.immediate,@@ -66,7 +92,7 @@ export default {});try {- await client.send(notification);+ await alertClient.send(notification);return Response.json({ success: true });} catch (err: unknown) {const message = err instanceof Error ? err.message : String(err);@@ -78,14 +104,6 @@ export default {// Live Activity pushconst event = body.event ?? "update";- const client = new ApnsClient({- team: env.APNS_TEAM_ID,- keyId: env.APNS_KEY_ID,- signingKey,- defaultTopic: `${bundleId}.push-type.liveactivity`,- host: "api.sandbox.push.apple.com",- });-const aps: Record<string, unknown> = {timestamp: Math.floor(Date.now() / 1000),event,@@ -106,7 +124,7 @@ export default {});try {- await client.send(notification);+ await liveActivityClient.send(notification);return Response.json({ success: true });} catch (err: unknown) {const message = err instanceof Error ? err.message : String(err);