diff --git a/macos/Resources/Localizations/en.lproj/Localizable.strings b/macos/Resources/Localizations/en.lproj/Localizable.strings index 48e20b4f..e82fe648 100644 --- a/macos/Resources/Localizations/en.lproj/Localizable.strings +++ b/macos/Resources/Localizations/en.lproj/Localizable.strings @@ -29,6 +29,7 @@ "移到废纸篓" = "Move to Trash"; "复制到剪贴板" = "Copy to Clipboard"; "发给 %@" = "Send to %@"; +"发给 Antigravity" = "Send to Antigravity"; "发给豆包" = "Send to Doubao"; "发给 WeSight" = "Send to WeSight"; "发给 DeepSeek Harness" = "Send to DeepSeek Harness"; @@ -43,6 +44,8 @@ "还没有添加自定义应用。" = "No custom apps added yet."; "已取消" = "Cancelled"; "这条转发没有指定目标 App。" = "This forward has no target app."; +"聊天记录过长已截断,完整内容见:%@" = "Transcript truncated; full text saved at: %@"; +"其余 %d 个附件已解压至:%@" = "%d additional attachments extracted to: %@"; "Codex" = "Codex"; "Claude" = "Claude"; "豆包" = "Doubao"; @@ -126,6 +129,7 @@ "只复制,不自动粘贴" = "Copies only; does not paste automatically"; "管理…" = "Manage…"; "入口没有出现在微信菜单里?" = "Entry missing from WeChat’s menu?"; +"激活 Antigravity 并直接粘贴到输入框。" = "Brings Antigravity forward and pastes straight into its input."; "激活 ChatGPT 并直接粘贴到输入框。" = "Brings ChatGPT forward and pastes straight into its input."; "激活 Claude 并直接粘贴到输入框。" = "Brings Claude forward and pastes straight into its input."; "激活豆包并直接粘贴到输入框。" = "Brings Doubao forward and pastes straight into its input."; diff --git a/macos/Resources/Localizations/zh-Hans.lproj/Localizable.strings b/macos/Resources/Localizations/zh-Hans.lproj/Localizable.strings index 9399d8d3..1a755543 100644 --- a/macos/Resources/Localizations/zh-Hans.lproj/Localizable.strings +++ b/macos/Resources/Localizations/zh-Hans.lproj/Localizable.strings @@ -29,6 +29,7 @@ "移到废纸篓" = "移到废纸篓"; "复制到剪贴板" = "复制到剪贴板"; "发给 %@" = "发给 %@"; +"发给 Antigravity" = "发给 Antigravity"; "发给豆包" = "发给豆包"; "发给 WeSight" = "发给 WeSight"; "发给 DeepSeek Harness" = "发给 DeepSeek Harness"; @@ -43,6 +44,8 @@ "还没有添加自定义应用。" = "还没有添加自定义应用。"; "已取消" = "已取消"; "这条转发没有指定目标 App。" = "这条转发没有指定目标 App。"; +"聊天记录过长已截断,完整内容见:%@" = "聊天记录过长已截断,完整内容见:%@"; +"其余 %d 个附件已解压至:%@" = "其余 %d 个附件已解压至:%@"; "Codex" = "Codex"; "Claude" = "Claude"; "豆包" = "豆包"; @@ -126,6 +129,7 @@ "只复制,不自动粘贴" = "只复制,不自动粘贴"; "管理…" = "管理…"; "入口没有出现在微信菜单里?" = "入口没有出现在微信菜单里?"; +"激活 Antigravity 并直接粘贴到输入框。" = "激活 Antigravity 并直接粘贴到输入框。"; "激活 ChatGPT 并直接粘贴到输入框。" = "激活 ChatGPT 并直接粘贴到输入框。"; "激活 Claude 并直接粘贴到输入框。" = "激活 Claude 并直接粘贴到输入框。"; "激活豆包并直接粘贴到输入框。" = "激活豆包并直接粘贴到输入框。"; diff --git a/macos/Resources/ShareLocalizations/Antigravity/en.lproj/InfoPlist.strings b/macos/Resources/ShareLocalizations/Antigravity/en.lproj/InfoPlist.strings new file mode 100644 index 00000000..75317a7c --- /dev/null +++ b/macos/Resources/ShareLocalizations/Antigravity/en.lproj/InfoPlist.strings @@ -0,0 +1 @@ +"CFBundleDisplayName" = "Send to Antigravity"; diff --git a/macos/Resources/ShareLocalizations/Antigravity/zh-Hans.lproj/InfoPlist.strings b/macos/Resources/ShareLocalizations/Antigravity/zh-Hans.lproj/InfoPlist.strings new file mode 100644 index 00000000..6bd4bf55 --- /dev/null +++ b/macos/Resources/ShareLocalizations/Antigravity/zh-Hans.lproj/InfoPlist.strings @@ -0,0 +1 @@ +"CFBundleDisplayName" = "发给 Antigravity"; diff --git a/macos/Scripts/check-release-config.sh b/macos/Scripts/check-release-config.sh index 9bd49e6a..62d32f4e 100755 --- a/macos/Scripts/check-release-config.sh +++ b/macos/Scripts/check-release-config.sh @@ -23,8 +23,8 @@ plutil -lint "$APP_INFO" "$SHARE_INFO" "$APP_ENTITLEMENTS" "$SHARE_ENTITLEMENTS" plutil -lint "$ROOT"/Resources/Localizations/*/*.strings "$ROOT"/Resources/ShareLocalizations/*/*/*.strings >/dev/null python3 -m json.tool "$SHARED/Skills/catalog.json" >/dev/null -if [ "${#SHARE_SLOTS[@]}" -ne 12 ]; then - echo "expected 12 Share-menu entries, found ${#SHARE_SLOTS[@]}" >&2 +if [ "${#SHARE_SLOTS[@]}" -ne 13 ]; then + echo "expected 13 Share-menu entries, found ${#SHARE_SLOTS[@]}" >&2 exit 1 fi diff --git a/macos/Scripts/share-slots.sh b/macos/Scripts/share-slots.sh index ead305f0..8d77fc4a 100644 --- a/macos/Scripts/share-slots.sh +++ b/macos/Scripts/share-slots.sh @@ -25,6 +25,7 @@ SHARE_SLOTS=( "WorkBuddy|WeChatBridgeShareWorkBuddy|ShareWorkBuddy|workBuddy|发给 WorkBuddy" "WeSight|WeChatBridgeShareWeSight|ShareWeSight|weSight|发给 WeSight" "DeepSeekHarness|WeChatBridgeShareDeepSeekHarness|ShareDeepSeekHarness|deepSeekHarness|发给 DeepSeek Harness" + "Antigravity|WeChatBridgeShareAntigravity|ShareAntigravity|antigravity|发给 Antigravity" "Obsidian|WeChatBridgeShareObsidian|ShareObsidian|obsidian|沉淀到 Obsidian" "Collection|WeChatBridgeShareCollection|ShareCollection|collect|分批收集到微信流" "Folder|WeChatBridgeShareFolder|ShareFolder|folder|沉淀到文件夹" @@ -42,6 +43,7 @@ share_logo_name() { QwenWork) printf '%s' "02-qwen.png" ;; WorkBuddy) printf '%s' "06-workbuddy.png" ;; WeSight) printf '%s' "07-wesight.png" ;; + Antigravity) printf '%s' "08-antigravity.png" ;; Obsidian) printf '%s' "05-obsidian.png" ;; esac } diff --git a/macos/Sources/WeChatBridgeApp/ActionRunner.swift b/macos/Sources/WeChatBridgeApp/ActionRunner.swift index c5264323..2b9be14c 100644 --- a/macos/Sources/WeChatBridgeApp/ActionRunner.swift +++ b/macos/Sources/WeChatBridgeApp/ActionRunner.swift @@ -95,7 +95,7 @@ final class ActionRunner { // Nothing is shown: the share sheet said 「已复制到剪贴板」 a moment // ago and is still on screen. A second capsule saying it again is // WeChatBridge talking over the system. - case .codex, .claude, .doubao, .qwen, .workBuddy, .weSight, .deepSeekHarness, .obsidian, .folder, .custom: + case .antigravity, .codex, .claude, .doubao, .qwen, .workBuddy, .weSight, .deepSeekHarness, .obsidian, .folder, .custom: // Shares and WeChat captures share the same clipboard queue. // // Read here rather than where the panel opens. This forward may wait @@ -432,19 +432,34 @@ final class ActionRunner { : skills.promptContext(agent: agent) ) } - let prompt = doubaoReadsLocalArchive - ? [ - L10n.text("请直接读取并解压以下本机文件,使用其中的内容完成场景要求。"), - scenePrompt, - ].compactMap { $0 }.joined(separator: "\n\n") - : scenePrompt - // The prompt, if 入口 attaches one: a first ⌘V before the files, or - // folded into the one line a terminal gets. See `PastePlan`. - let plan = PastePlan.make( - urls: promptURLs, - pathOnly: pathOnly, - prompt: prompt - ) + let plan: [PastePayload] + if bundleIdentifier == ShareAction.antigravity.targetBundleIdentifier, + !configuredPathOnly, + arrival.urls.contains(where: { $0.pathExtension.lowercased() == "zip" }) { + let urls = arrival.urls + let extractedPlan = await Task.detached(priority: .userInitiated) { + AntigravityPayload.buildPlan(urls: urls, scenePrompt: scenePrompt) + }.value + plan = extractedPlan ?? PastePlan.make( + urls: arrival.urls, + pathOnly: false, + prompt: scenePrompt + ) + } else { + let prompt = doubaoReadsLocalArchive + ? [ + L10n.text("请直接读取并解压以下本机文件,使用其中的内容完成场景要求。"), + scenePrompt, + ].compactMap { $0 }.joined(separator: "\n\n") + : scenePrompt + // The prompt, if 入口 attaches one: a first ⌘V before the files, or + // folded into the one line a terminal gets. See `PastePlan`. + plan = PastePlan.make( + urls: promptURLs, + pathOnly: pathOnly, + prompt: prompt + ) + } // Written again here, not just in the extension: this is the process // that is about to press ⌘V, so it owns what ⌘V will produce. writePasteboard(plan) diff --git a/macos/Sources/WeChatBridgeApp/AppModel.swift b/macos/Sources/WeChatBridgeApp/AppModel.swift index c981d16a..7d81e511 100644 --- a/macos/Sources/WeChatBridgeApp/AppModel.swift +++ b/macos/Sources/WeChatBridgeApp/AppModel.swift @@ -220,7 +220,7 @@ final class AppModel: ObservableObject { // Already copied, by the extension, and already recorded as // such by `BatchState.initial`. Nothing left to do. return false - case .codex, .claude, .doubao, .qwen, .workBuddy, .weSight, .deepSeekHarness, .obsidian, .folder, .custom: + case .antigravity, .codex, .claude, .doubao, .qwen, .workBuddy, .weSight, .deepSeekHarness, .obsidian, .folder, .custom: // A forward whose one-shot request is already gone: the file was // consumed by a run that then died before it could act, or the // extension never managed to write it. Either way nothing can be diff --git a/macos/Sources/WeChatBridgeApp/AutoPaste.swift b/macos/Sources/WeChatBridgeApp/AutoPaste.swift index a4d16b2f..2507a1c2 100644 --- a/macos/Sources/WeChatBridgeApp/AutoPaste.swift +++ b/macos/Sources/WeChatBridgeApp/AutoPaste.swift @@ -156,6 +156,15 @@ enum AutoPaste { let application = AXUIElementCreateApplication(pid) // The same one-second leash `restoreWindows` uses. AXUIElementSetMessagingTimeout(application, 1) + if let focusedRef = attribute(application, kAXFocusedUIElementAttribute), + CFGetTypeID(focusedRef) == AXUIElementGetTypeID() { + let focused = focusedRef as! AXUIElement + let role = attribute(focused, kAXRoleAttribute) as? String + if (role == kAXTextAreaRole || role == kAXTextFieldRole), + (attribute(focused, kAXEnabledAttribute) as? Bool) ?? true { + return + } + } guard let window = focusedWindow(of: application), let field = editableElements(in: window) .max(by: { $0.frame.maxY < $1.frame.maxY })?.element diff --git a/macos/Sources/WeChatBridgeApp/ForwardTargets.swift b/macos/Sources/WeChatBridgeApp/ForwardTargets.swift index 9e76b4f1..4f3595ba 100644 --- a/macos/Sources/WeChatBridgeApp/ForwardTargets.swift +++ b/macos/Sources/WeChatBridgeApp/ForwardTargets.swift @@ -167,6 +167,7 @@ final class ForwardTargets: ObservableObject { ForwardDestination(action: .workBuddy, target: nil), ForwardDestination(action: .weSight, target: nil), ForwardDestination(action: .deepSeekHarness, target: nil), + ForwardDestination(action: .antigravity, target: nil), ForwardDestination(action: .obsidian, target: nil), ] + targets.map { ForwardDestination(action: .custom, target: $0) } } diff --git a/macos/Sources/WeChatBridgeApp/Views/Settings/ShareEntryList.swift b/macos/Sources/WeChatBridgeApp/Views/Settings/ShareEntryList.swift index 8de51966..f639e824 100644 --- a/macos/Sources/WeChatBridgeApp/Views/Settings/ShareEntryList.swift +++ b/macos/Sources/WeChatBridgeApp/Views/Settings/ShareEntryList.swift @@ -166,6 +166,7 @@ struct ShareEntryList: View { private static func bundledLogo(for action: ShareAction) -> NSImage? { let file: String switch action { + case .antigravity: file = "08-antigravity.png" case .codex: file = "04-chatgpt.png" case .claude: file = "03-claude.png" case .doubao: file = "01-doubao.png" @@ -187,7 +188,7 @@ struct ShareEntryList: View { /// table of symbols would be a second answer to "which icon is this entry". static func symbol(for action: ShareAction) -> String { switch action { - case .codex, .claude, .doubao, .qwen, .workBuddy, .weSight, .deepSeekHarness: "paperplane" + case .antigravity, .codex, .claude, .doubao, .qwen, .workBuddy, .weSight, .deepSeekHarness: "paperplane" case .obsidian: "book.closed" case .collect: "tray.and.arrow.down" case .folder: "folder" @@ -199,7 +200,7 @@ struct ShareEntryList: View { private func detail(for action: ShareAction) -> String { if compactDetails { switch action { - case .codex, .claude, .doubao, .qwen, .workBuddy, .weSight, .deepSeekHarness: + case .antigravity, .codex, .claude, .doubao, .qwen, .workBuddy, .weSight, .deepSeekHarness: guard let bundleIdentifier = action.installedTargetBundleIdentifier else { return L10n.text("未安装") } @@ -224,6 +225,7 @@ struct ShareEntryList: View { } switch action { + case .antigravity: return L10n.text("激活 Antigravity 并直接粘贴到输入框。") case .codex: return L10n.text("激活 ChatGPT 并直接粘贴到输入框。") case .claude: return L10n.text("激活 Claude 并直接粘贴到输入框。") case .doubao: return L10n.text("激活豆包并直接粘贴到输入框。") @@ -242,7 +244,7 @@ struct ShareEntryList: View { private func detailIsWarning(for action: ShareAction) -> Bool { guard compactDetails else { return false } switch action { - case .codex, .claude, .doubao, .qwen, .workBuddy, .weSight, .deepSeekHarness: + case .antigravity, .codex, .claude, .doubao, .qwen, .workBuddy, .weSight, .deepSeekHarness: return action.installedTargetBundleIdentifier.map { !InstalledApp.lookup($0).isInstalled } ?? true diff --git a/macos/Sources/WeChatBridgeCore/AntigravityPayload.swift b/macos/Sources/WeChatBridgeCore/AntigravityPayload.swift new file mode 100644 index 00000000..1c235516 --- /dev/null +++ b/macos/Sources/WeChatBridgeCore/AntigravityPayload.swift @@ -0,0 +1,170 @@ +import Foundation +import UniformTypeIdentifiers + +/// Unpacks WeChat chat-archive ZIPs for Antigravity and produces a paste plan +/// with the chat transcript (and optional scene prompt) followed by the +/// extracted image files, so the user sees text + image attachments straight +/// inside the chat composer. +public enum AntigravityPayload { + public static let maxInlineImages = 10 + public static let maxInlineCharacters = 20_000 + private static let staleAge: TimeInterval = 24 * 60 * 60 + + public static func buildPlan( + urls: [URL], + scenePrompt: String?, + extractionRoot: URL = URL(fileURLWithPath: "/tmp/wxbridge/extracted", isDirectory: true), + maxInlineImages: Int = maxInlineImages, + maxInlineCharacters: Int = maxInlineCharacters + ) -> [PastePayload]? { + guard !urls.isEmpty else { return nil } + let fileManager = FileManager.default + pruneStaleExtractions(in: extractionRoot, fileManager: fileManager) + + let batchDir = makeBatchDirectory(for: urls, under: extractionRoot, fileManager: fileManager) + var transcripts: [String] = [] + var transcriptURLs: [URL] = [] + var imageURLs: [URL] = [] + var otherFiles: [URL] = [] + + for (index, url) in urls.enumerated() { + if url.pathExtension.lowercased() == "zip" { + let subDir = urls.count == 1 + ? batchDir + : batchDir.appendingPathComponent("batch-\(index + 1)", isDirectory: true) + do { + try fileManager.createDirectory(at: subDir, withIntermediateDirectories: true) + let data = try Data(contentsOf: url, options: .mappedIfSafe) + let transcript = try? WeChatNativeArchive.transcript(data) + let extractedNames = try WeChatNativeArchive.extract(data, to: subDir) + + if let transcript { + let trimmed = transcript.body.trimmingCharacters(in: .whitespacesAndNewlines) + if !trimmed.isEmpty { + transcripts.append(trimmed) + } + let txtURL = subDir.appendingPathComponent(transcript.path) + if fileManager.fileExists(atPath: txtURL.path) { + transcriptURLs.append(txtURL) + } + } + + var archiveImages: [(name: String, url: URL)] = [] + for name in extractedNames where name != transcript?.path { + let fileURL = subDir.appendingPathComponent(name) + if isImageFile(fileURL) { + archiveImages.append((name: name, url: fileURL)) + } else { + otherFiles.append(fileURL) + } + } + + let body = transcript?.body ?? "" + archiveImages.sort { lhs, rhs in + let lhsOrder = transcriptOrder(for: lhs.name, fileURL: lhs.url, in: body) + let rhsOrder = transcriptOrder(for: rhs.name, fileURL: rhs.url, in: body) + if lhsOrder != rhsOrder { return lhsOrder < rhsOrder } + return lhs.name < rhs.name + } + imageURLs.append(contentsOf: archiveImages.map(\.url)) + } catch { + otherFiles.append(url) + } + } else if isImageFile(url) { + imageURLs.append(url) + } else { + otherFiles.append(url) + } + } + + var textSections: [String] = [] + if let prompt = scenePrompt?.trimmingCharacters(in: .whitespacesAndNewlines), !prompt.isEmpty { + textSections.append(prompt) + } + + let combinedTranscript = transcripts.joined(separator: "\n\n---\n\n") + if !combinedTranscript.isEmpty { + if combinedTranscript.count > maxInlineCharacters { + textSections.append(String(combinedTranscript.prefix(maxInlineCharacters)) + "\n…") + if !transcriptURLs.isEmpty { + let paths = FilePasteboard.shellLine(for: transcriptURLs) + .trimmingCharacters(in: .whitespaces) + textSections.append(L10n.format("聊天记录过长已截断,完整内容见:%@", paths)) + } + } else { + textSections.append(combinedTranscript) + } + } + + let overflowImages = max(0, imageURLs.count - maxInlineImages) + let extraCount = overflowImages + otherFiles.count + if extraCount > 0 { + textSections.append( + L10n.format( + "其余 %d 个附件已解压至:%@", + extraCount, + FilePasteboard.shellQuoted(batchDir.path) + ) + ) + } + + var payloads: [PastePayload] = [] + let finalText = textSections.joined(separator: "\n\n") + if !finalText.isEmpty { + payloads.append(.text(finalText)) + } + let inlineImages = Array(imageURLs.prefix(maxInlineImages)) + if !inlineImages.isEmpty { + payloads.append(.files(inlineImages)) + } + return payloads.isEmpty ? nil : payloads + } + + private static func isImageFile(_ url: URL) -> Bool { + guard let type = UTType(filenameExtension: url.pathExtension) else { return false } + return type.conforms(to: .image) + } + + private static func transcriptOrder(for name: String, fileURL: URL, in body: String) -> Int { + guard !body.isEmpty else { return Int.max } + let fileName = fileURL.lastPathComponent + if let range = body.range(of: fileName) ?? body.range(of: name) { + return body.distance(from: body.startIndex, to: range.lowerBound) + } + return Int.max + } + + private static func makeBatchDirectory( + for urls: [URL], + under root: URL, + fileManager: FileManager + ) -> URL { + let readyPrefix = urls.lazy.compactMap { url -> String? in + let components = url.pathComponents + guard let readyIndex = components.lastIndex(of: "Ready"), + components.indices.contains(readyIndex + 1) else { return nil } + let raw = components[readyIndex + 1].replacingOccurrences(of: "-", with: "") + return raw.isEmpty ? nil : String(raw.prefix(8)) + }.first ?? "batch" + let unique = String(UUID().uuidString.replacingOccurrences(of: "-", with: "").prefix(6)) + let directory = root.appendingPathComponent("\(readyPrefix)-\(unique)", isDirectory: true) + try? fileManager.createDirectory(at: directory, withIntermediateDirectories: true) + return directory + } + + private static func pruneStaleExtractions(in root: URL, fileManager: FileManager) { + guard let children = try? fileManager.contentsOfDirectory( + at: root, + includingPropertiesForKeys: [.contentModificationDateKey], + options: [.skipsHiddenFiles] + ) else { return } + let cutoff = Date().addingTimeInterval(-staleAge) + for child in children { + let modified = (try? child.resourceValues(forKeys: [.contentModificationDateKey]))? + .contentModificationDate ?? .distantPast + if modified < cutoff { + try? fileManager.removeItem(at: child) + } + } + } +} diff --git a/macos/Sources/WeChatBridgeCore/BatchState.swift b/macos/Sources/WeChatBridgeCore/BatchState.swift index 08d50579..cbf22fb7 100644 --- a/macos/Sources/WeChatBridgeCore/BatchState.swift +++ b/macos/Sources/WeChatBridgeCore/BatchState.swift @@ -134,7 +134,7 @@ public struct BatchState: Codable, Sendable, Hashable { action: action, targetName: targetName ) - case .collect, .codex, .claude, .doubao, .qwen, .workBuddy, .weSight, .deepSeekHarness, .obsidian, .folder, .custom: + case .collect, .antigravity, .codex, .claude, .doubao, .qwen, .workBuddy, .weSight, .deepSeekHarness, .obsidian, .folder, .custom: return BatchState(outcome: nil, action: action, targetName: targetName) } } diff --git a/macos/Sources/WeChatBridgeCore/ShareAction.swift b/macos/Sources/WeChatBridgeCore/ShareAction.swift index cb14517a..118da898 100644 --- a/macos/Sources/WeChatBridgeCore/ShareAction.swift +++ b/macos/Sources/WeChatBridgeCore/ShareAction.swift @@ -23,6 +23,8 @@ public enum ShareAction: String, Codable, Sendable, CaseIterable { case weSight /// Paste into DeepSeek Harness. case deepSeekHarness + /// Paste into Antigravity. + case antigravity /// Write a Markdown note and its source archive into the configured vault. case obsidian /// Write a Markdown note and its attachments into the configured folder, @@ -94,6 +96,7 @@ public enum ShareAction: String, Codable, Sendable, CaseIterable { case .workBuddy: return ["com.tencent.workbuddy.mac", "com.workbuddy.workbuddy"] case .weSight: return ["ai.wesight.app"] case .deepSeekHarness: return ["com.deepseek.dsh"] + case .antigravity: return ["com.google.antigravity"] case .obsidian: return ["md.obsidian"] // `.custom` has no fixed destination and no destination in its intent // either. `ActionRunner` resolves one from the user's own list, or takes @@ -113,7 +116,7 @@ public enum ShareAction: String, Codable, Sendable, CaseIterable { public var needsIntent: Bool { switch self { case .collect, .clipboard: return false - case .codex, .claude, .doubao, .qwen, .workBuddy, .weSight, .deepSeekHarness, .obsidian, .folder, .custom: return true + case .antigravity, .codex, .claude, .doubao, .qwen, .workBuddy, .weSight, .deepSeekHarness, .obsidian, .folder, .custom: return true } } @@ -129,6 +132,7 @@ public enum ShareAction: String, Codable, Sendable, CaseIterable { case .workBuddy: return "WorkBuddy" case .weSight: return L10n.text("WeSight") case .deepSeekHarness: return "DeepSeek Harness" + case .antigravity: return "Antigravity" case .obsidian: return L10n.text("Obsidian") case .collect: return L10n.text("分批收集") case .folder: return L10n.text("文件夹") @@ -152,6 +156,7 @@ public enum ShareAction: String, Codable, Sendable, CaseIterable { case .workBuddy: return L10n.text("发给 WorkBuddy") case .weSight: return L10n.text("发给 WeSight") case .deepSeekHarness: return L10n.text("发给 DeepSeek Harness") + case .antigravity: return L10n.text("发给 Antigravity") case .obsidian: return L10n.text("沉淀到 Obsidian") case .collect: return L10n.text("分批收集到微信流") case .folder: return L10n.text("沉淀到文件夹") @@ -173,6 +178,7 @@ public enum ShareAction: String, Codable, Sendable, CaseIterable { case .workBuddy: return "ShareWorkBuddy" case .weSight: return "ShareWeSight" case .deepSeekHarness: return "ShareDeepSeekHarness" + case .antigravity: return "ShareAntigravity" case .obsidian: return "ShareObsidian" case .collect: return "ShareCollection" case .folder: return "ShareFolder" diff --git a/macos/Tests/WeChatBridgeCoreTests/AntigravityPayloadTests.swift b/macos/Tests/WeChatBridgeCoreTests/AntigravityPayloadTests.swift new file mode 100644 index 00000000..f0234221 --- /dev/null +++ b/macos/Tests/WeChatBridgeCoreTests/AntigravityPayloadTests.swift @@ -0,0 +1,241 @@ +import Foundation +import WeChatBridgeCore +import XCTest +import zlib + +final class AntigravityPayloadTests: XCTestCase { + private var temporaryRoot: URL! + + override func setUpWithError() throws { + try super.setUpWithError() + temporaryRoot = FileManager.default.temporaryDirectory + .appendingPathComponent("AntigravityPayloadTests-\(UUID().uuidString)", isDirectory: true) + try FileManager.default.createDirectory(at: temporaryRoot, withIntermediateDirectories: true) + } + + override func tearDownWithError() throws { + if let temporaryRoot { + try? FileManager.default.removeItem(at: temporaryRoot) + } + try super.tearDownWithError() + } + + func testSingleImageArchiveExtractsTranscriptAndImage() throws { + let imageBytes = Data([0xFF, 0xD8, 0xFF, 0xE0, 0x00, 0x10]) + let transcript = "·心安\n2026年12月2日 05:12\n[图片] 微信图片_1.jpg\n" + let zipURL = try writeStoredZIP( + named: "single.zip", + entries: [ + ("聊天记录.txt", Data(transcript.utf8)), + ("聊天记录内的图片、视频和文件/微信图片_1.jpg", imageBytes), + ] + ) + + let extractionRoot = temporaryRoot.appendingPathComponent("extracted", isDirectory: true) + let plan = try XCTUnwrap( + AntigravityPayload.buildPlan( + urls: [zipURL], + scenePrompt: "请总结关键信息", + extractionRoot: extractionRoot + ) + ) + + XCTAssertEqual(plan.count, 2) + guard case .text(let text) = plan[0] else { + return XCTFail("expected text payload first") + } + XCTAssertTrue(text.contains("请总结关键信息")) + XCTAssertTrue(text.contains("·心安")) + XCTAssertTrue(text.contains("微信图片_1.jpg")) + + guard case .files(let files) = plan[1] else { + return XCTFail("expected files payload second") + } + XCTAssertEqual(files.count, 1) + XCTAssertEqual(files[0].lastPathComponent, "微信图片_1.jpg") + XCTAssertEqual(try Data(contentsOf: files[0]), imageBytes) + } + + func testMultiImageArchivePreservesTranscriptAppearanceOrder() throws { + let transcript = """ + ·甲 + 2026年12月2日 05:10 + [图片] z_first.png + [图片] a_second.png + """ + let zipURL = try writeStoredZIP( + named: "ordered.zip", + entries: [ + ("聊天记录.txt", Data(transcript.utf8)), + ("images/a_second.png", Data([0x89, 0x50, 0x4E, 0x47, 0x02])), + ("images/z_first.png", Data([0x89, 0x50, 0x4E, 0x47, 0x01])), + ] + ) + + let extractionRoot = temporaryRoot.appendingPathComponent("extracted-order", isDirectory: true) + let plan = try XCTUnwrap( + AntigravityPayload.buildPlan( + urls: [zipURL], + scenePrompt: nil, + extractionRoot: extractionRoot + ) + ) + + XCTAssertEqual(plan.count, 2) + guard case .files(let files) = plan[1] else { + return XCTFail("expected files payload") + } + XCTAssertEqual(files.map(\.lastPathComponent), ["z_first.png", "a_second.png"]) + } + + func testTextOnlyArchiveProducesOnlyTextPayload() throws { + let transcript = "·甲\n2026年12月2日 05:10\n只有文字消息\n" + let zipURL = try writeStoredZIP( + named: "textonly.zip", + entries: [("聊天记录.txt", Data(transcript.utf8))] + ) + + let extractionRoot = temporaryRoot.appendingPathComponent("extracted-text", isDirectory: true) + let plan = try XCTUnwrap( + AntigravityPayload.buildPlan( + urls: [zipURL], + scenePrompt: nil, + extractionRoot: extractionRoot + ) + ) + + XCTAssertEqual(plan, [.text("·甲\n2026年12月2日 05:10\n只有文字消息")]) + } + + func testOverflowImagesAndOtherAttachmentsReportExtractedFolder() throws { + var entries: [(String, Data)] = [ + ("聊天记录.txt", Data("·甲\n2026年12月2日 05:10\n多附件测试\n".utf8)), + ("docs/report.pdf", Data("%PDF-1.4".utf8)), + ] + for index in 1...12 { + let name = String(format: "img_%02d.jpg", index) + entries.append(("images/\(name)", Data([0xFF, 0xD8, UInt8(index)]))) + } + let zipURL = try writeStoredZIP(named: "overflow.zip", entries: entries) + + let extractionRoot = temporaryRoot.appendingPathComponent("extracted-overflow", isDirectory: true) + let plan = try XCTUnwrap( + AntigravityPayload.buildPlan( + urls: [zipURL], + scenePrompt: nil, + extractionRoot: extractionRoot + ) + ) + + XCTAssertEqual(plan.count, 2) + guard case .text(let text) = plan[0], case .files(let files) = plan[1] else { + return XCTFail("expected text and files payloads") + } + XCTAssertEqual(files.count, AntigravityPayload.maxInlineImages) + // 2 overflow images + 1 PDF = 3 remaining attachments + XCTAssertTrue(text.contains("其余 3 个附件已解压至:")) + XCTAssertTrue(text.contains(extractionRoot.path)) + } + + func testLongTranscriptIsTruncatedWithFullFilePath() throws { + let longBody = "·甲\n2026年12月2日 05:10\n" + String(repeating: "长内容测试。", count: 30) + let zipURL = try writeStoredZIP( + named: "long.zip", + entries: [("聊天记录.txt", Data(longBody.utf8))] + ) + + let extractionRoot = temporaryRoot.appendingPathComponent("extracted-long", isDirectory: true) + let plan = try XCTUnwrap( + AntigravityPayload.buildPlan( + urls: [zipURL], + scenePrompt: nil, + extractionRoot: extractionRoot, + maxInlineCharacters: 40 + ) + ) + + XCTAssertEqual(plan.count, 1) + guard case .text(let text) = plan[0] else { + return XCTFail("expected text payload") + } + XCTAssertTrue(text.contains("…")) + XCTAssertTrue(text.contains("聊天记录过长已截断,完整内容见:")) + XCTAssertTrue(text.contains("聊天记录.txt")) + } + + // MARK: - Minimal uncompressed ZIP builder + + private func writeStoredZIP(named name: String, entries: [(String, Data)]) throws -> URL { + let zipURL = temporaryRoot.appendingPathComponent(name) + var archive = Data() + var centralDirectory = Data() + + for (entryName, payload) in entries { + let nameData = Data(entryName.utf8) + let crc = payload.withUnsafeBytes { buffer -> UInt32 in + guard let base = buffer.bindMemory(to: Bytef.self).baseAddress else { return 0 } + return UInt32(crc32(0, base, uInt(payload.count))) + } + let localHeaderOffset = UInt32(archive.count) + + appendUInt32(0x04034B50, to: &archive) + appendUInt16(20, to: &archive) + appendUInt16(0x0800, to: &archive) // UTF-8 + appendUInt16(0, to: &archive) // stored + appendUInt16(0, to: &archive) + appendUInt16(0, to: &archive) + appendUInt32(crc, to: &archive) + appendUInt32(UInt32(payload.count), to: &archive) + appendUInt32(UInt32(payload.count), to: &archive) + appendUInt16(UInt16(nameData.count), to: &archive) + appendUInt16(0, to: &archive) + archive.append(nameData) + archive.append(payload) + + appendUInt32(0x02014B50, to: ¢ralDirectory) + appendUInt16(20, to: ¢ralDirectory) + appendUInt16(20, to: ¢ralDirectory) + appendUInt16(0x0800, to: ¢ralDirectory) + appendUInt16(0, to: ¢ralDirectory) + appendUInt16(0, to: ¢ralDirectory) + appendUInt16(0, to: ¢ralDirectory) + appendUInt32(crc, to: ¢ralDirectory) + appendUInt32(UInt32(payload.count), to: ¢ralDirectory) + appendUInt32(UInt32(payload.count), to: ¢ralDirectory) + appendUInt16(UInt16(nameData.count), to: ¢ralDirectory) + appendUInt16(0, to: ¢ralDirectory) + appendUInt16(0, to: ¢ralDirectory) + appendUInt16(0, to: ¢ralDirectory) + appendUInt16(0, to: ¢ralDirectory) + appendUInt32(0, to: ¢ralDirectory) + appendUInt32(localHeaderOffset, to: ¢ralDirectory) + centralDirectory.append(nameData) + } + + let centralOffset = UInt32(archive.count) + let centralSize = UInt32(centralDirectory.count) + archive.append(centralDirectory) + + appendUInt32(0x06054B50, to: &archive) + appendUInt16(0, to: &archive) + appendUInt16(0, to: &archive) + appendUInt16(UInt16(entries.count), to: &archive) + appendUInt16(UInt16(entries.count), to: &archive) + appendUInt32(centralSize, to: &archive) + appendUInt32(centralOffset, to: &archive) + appendUInt16(0, to: &archive) + + try archive.write(to: zipURL) + return zipURL + } + + private func appendUInt16(_ value: UInt16, to data: inout Data) { + var le = value.littleEndian + withUnsafeBytes(of: &le) { data.append(contentsOf: $0) } + } + + private func appendUInt32(_ value: UInt32, to data: inout Data) { + var le = value.littleEndian + withUnsafeBytes(of: &le) { data.append(contentsOf: $0) } + } +} diff --git a/macos/Tests/WeChatBridgeCoreTests/SceneTests.swift b/macos/Tests/WeChatBridgeCoreTests/SceneTests.swift index d837c130..29ced988 100644 --- a/macos/Tests/WeChatBridgeCoreTests/SceneTests.swift +++ b/macos/Tests/WeChatBridgeCoreTests/SceneTests.swift @@ -84,6 +84,7 @@ final class SceneTests: XCTestCase { XCTAssertTrue(decodedV2.isOfficial) XCTAssertEqual(AgentID.matching(.weSight), .weSight) XCTAssertNil(AgentID.matching(.deepSeekHarness)) + XCTAssertNil(AgentID.matching(.antigravity)) } func testOfficialTaskCopiesToAnEditableUserTask() { diff --git a/macos/Tests/WeChatBridgeCoreTests/ShareActionTests.swift b/macos/Tests/WeChatBridgeCoreTests/ShareActionTests.swift index 2576d193..f06c6df5 100644 --- a/macos/Tests/WeChatBridgeCoreTests/ShareActionTests.swift +++ b/macos/Tests/WeChatBridgeCoreTests/ShareActionTests.swift @@ -16,7 +16,8 @@ final class ShareActionTests: XCTestCase { } func testOnlyForwardingActionsNameATargetApp() { - XCTAssertEqual(ShareAction.allCases.count, 12) + XCTAssertEqual(ShareAction.allCases.count, 13) + XCTAssertEqual(ShareAction.antigravity.targetBundleIdentifier, "com.google.antigravity") XCTAssertEqual(ShareAction.codex.targetBundleIdentifier, "com.openai.codex") XCTAssertEqual(ShareAction.claude.targetBundleIdentifier, "com.anthropic.claudefordesktop") XCTAssertEqual(ShareAction.doubao.targetBundleIdentifier, "com.bot.pc.doubao") @@ -95,7 +96,7 @@ final class ShareActionTests: XCTestCase { func testOnlyForwardsWriteAnIntent() { XCTAssertFalse(ShareAction.clipboard.needsIntent) for action in [ - ShareAction.codex, .claude, .doubao, .qwen, .workBuddy, + ShareAction.antigravity, .codex, .claude, .doubao, .qwen, .workBuddy, .weSight, .deepSeekHarness, .obsidian, .folder, .custom, ] { XCTAssertTrue(action.needsIntent, "\(action)") diff --git a/shared/AppLogos/08-antigravity.png b/shared/AppLogos/08-antigravity.png new file mode 100644 index 00000000..3cfc31d7 Binary files /dev/null and b/shared/AppLogos/08-antigravity.png differ diff --git a/shared/AppLogos/README.md b/shared/AppLogos/README.md index 205d24e3..d2f91cc8 100644 --- a/shared/AppLogos/README.md +++ b/shared/AppLogos/README.md @@ -9,6 +9,7 @@ Official 1024 x 1024 App Store artwork, ordered for the forwarding flow: 5. `05-obsidian.png` - [Obsidian](https://apps.apple.com/cn/app/id1557175442) 6. `06-workbuddy.png` - [WorkBuddy](https://apps.apple.com/cn/app/id6761374913) 7. `07-wesight.png` - WeSight +8. `08-antigravity.png` - Antigravity Doubao, Qwen, Obsidian, and WorkBuddy use the China App Store listing. Claude and ChatGPT have no China App Store listing, so their official