cc-pets 2.4.0 → 2.6.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CC_BRIDGE.md +93 -14
- package/CC_BRIDGE.zh-CN.md +71 -11
- package/CHANGELOG.md +55 -0
- package/CHANGELOG.zh-CN.md +56 -1
- package/CONTRIBUTING.md +1 -1
- package/CONTRIBUTING.zh-CN.md +1 -1
- package/PROVIDER_PROTOCOL.md +5 -1
- package/PROVIDER_PROTOCOL.zh-CN.md +4 -1
- package/README.md +116 -34
- package/README.zh-CN.md +99 -35
- package/Resources/AgentIcons/antigravity.icns +0 -0
- package/Resources/zh-Hans.lproj/Localizable.strings +99 -26
- package/Sources/CCPets/App/CCPetsAppDelegate+AgentEvents.m +51 -4
- package/Sources/CCPets/App/CCPetsAppDelegate+AgentStatus.m +120 -17
- package/Sources/CCPets/App/CCPetsAppDelegate+Bridge.m +24 -11
- package/Sources/CCPets/App/CCPetsAppDelegate+MenuBar.m +86 -0
- package/Sources/CCPets/App/CCPetsAppDelegate+Private.h +24 -1
- package/Sources/CCPets/App/CCPetsAppDelegate+Profiles.m +21 -11
- package/Sources/CCPets/App/CCPetsAppDelegate+Quota.m +33 -17
- package/Sources/CCPets/App/CCPetsAppDelegate+Settings.m +43 -7
- package/Sources/CCPets/App/CCPetsAppDelegate+Speech.m +7 -4
- package/Sources/CCPets/App/CCPetsAppDelegate+Update.m +7 -4
- package/Sources/CCPets/App/CCPetsAppDelegate+Workbench.m +24 -22
- package/Sources/CCPets/App/CCPetsAppDelegate.h +10 -0
- package/Sources/CCPets/App/CCPetsAppDelegate.m +18 -8
- package/Sources/CCPets/App/CCPetsVersion.h +4 -0
- package/Sources/CCPets/App/CCPetsVersion.m +34 -0
- package/Sources/CCPets/App/main.m +11 -0
- package/Sources/CCPets/Bridge/CCPetsBridge.m +41 -17
- package/Sources/CCPets/Bridge/CCPetsBridgeAntigravityApp.h +4 -0
- package/Sources/CCPets/Bridge/CCPetsBridgeAntigravityApp.m +119 -0
- package/Sources/CCPets/Bridge/CCPetsBridgeCLI.h +3 -1
- package/Sources/CCPets/Bridge/CCPetsBridgeCLI.m +272 -50
- package/Sources/CCPets/Bridge/CCPetsBridgeCore.h +12 -3
- package/Sources/CCPets/Bridge/CCPetsBridgeCore.m +341 -95
- package/Sources/CCPets/Bridge/CCPetsBridgeSetup.h +0 -2
- package/Sources/CCPets/Bridge/CCPetsBridgeSetup.m +227 -95
- package/Sources/CCPets/Bridge/CCPetsBridgeStore.h +35 -5
- package/Sources/CCPets/Bridge/CCPetsBridgeStore.m +310 -42
- package/Sources/CCPets/Bridge/CCPetsBridgeTerminalTitle.h +12 -0
- package/Sources/CCPets/Bridge/CCPetsBridgeTerminalTitle.m +105 -0
- package/Sources/CCPets/Integrations/CCPetsAntigravityConfig.h +17 -0
- package/Sources/CCPets/Integrations/CCPetsAntigravityConfig.m +462 -0
- package/Sources/CCPets/Integrations/CCPetsAntigravityEvents.h +5 -0
- package/Sources/CCPets/Integrations/CCPetsAntigravityEvents.m +180 -0
- package/Sources/CCPets/Integrations/CCPetsBridgeTitleRelay.h +3 -0
- package/Sources/CCPets/Integrations/CCPetsBridgeTitleRelay.m +463 -0
- package/Sources/CCPets/Integrations/CCPetsEvents.h +5 -0
- package/Sources/CCPets/Integrations/CCPetsEvents.m +68 -12
- package/Sources/CCPets/Integrations/CCPetsIntegrations.h +1 -1
- package/Sources/CCPets/Integrations/CCPetsIntegrations.m +38 -8
- package/Sources/CCPets/Integrations/CCPetsLaunchPreflight.m +15 -5
- package/Sources/CCPets/Integrations/CCPetsProfiles.h +2 -1
- package/Sources/CCPets/Integrations/CCPetsProfiles.m +112 -81
- package/Sources/CCPets/Integrations/CCPetsTerminalFocus.h +11 -1
- package/Sources/CCPets/Integrations/CCPetsTerminalFocus.m +217 -45
- package/Sources/CCPets/Pet/CCPetsPhrasesEditor.m +7 -0
- package/Sources/CCPets/Pet/CCPetsPreviews.m +16 -8
- package/Sources/CCPets/Pet/PetView+Menu.m +64 -5
- package/Sources/CCPets/Pet/PetView.h +7 -0
- package/Sources/CCPets/Pet/PetView.m +12 -1
- package/Sources/CCPets/Support/CCPetsDoctor.m +126 -37
- package/Sources/CCPets/Support/CCPetsPaths.h +5 -0
- package/Sources/CCPets/Support/CCPetsPaths.m +15 -0
- package/Sources/CCPets/Support/CCPetsPreferences.h +14 -1
- package/Sources/CCPets/Support/CCPetsPreferences.m +36 -0
- package/Sources/CCPets/UI/CCPetsMenuBarIcon.h +16 -0
- package/Sources/CCPets/UI/CCPetsMenuBarIcon.m +70 -0
- package/Sources/CCPets/UI/CCPetsMenuBarPanel.h +18 -0
- package/Sources/CCPets/UI/CCPetsMenuBarPanel.m +533 -0
- package/Sources/CCPets/UI/CCPetsMenuBarSummary.h +51 -0
- package/Sources/CCPets/UI/CCPetsMenuBarSummary.m +98 -0
- package/Sources/CCPets/UI/CCPetsSettingsPage.h +7 -1
- package/Sources/CCPets/UI/CCPetsSettingsPage.m +205 -8
- package/Sources/CCPets/UI/CCPetsStatusItem.h +28 -0
- package/Sources/CCPets/UI/CCPetsStatusItem.m +147 -0
- package/Sources/CCPets/UI/CCPetsUIStyle.m +3 -1
- package/Sources/CCPets/UI/CCPetsUsagePage.h +4 -3
- package/Sources/CCPets/UI/CCPetsUsagePage.m +69 -43
- package/Sources/CCPets/UI/CCPetsUsageStore.m +11 -1
- package/Sources/CCPets/UI/CCPetsWorkbenchPages.m +6 -4
- package/Sources/CCPets/Usage/CCPetsAntigravityQuota.m +115 -0
- package/Sources/CCPets/Usage/CCPetsNormalizedUsage.h +5 -0
- package/Sources/CCPets/Usage/CCPetsNormalizedUsage.m +43 -0
- package/Sources/CCPets/Usage/CCPetsProviderRegistry+Testing.h +13 -0
- package/Sources/CCPets/Usage/CCPetsProviderRegistry.h +25 -0
- package/Sources/CCPets/Usage/CCPetsProviderRegistry.m +94 -0
- package/Sources/CCPets/Usage/CCPetsQuotaHistory.h +1 -1
- package/Sources/CCPets/Usage/CCPetsQuotaHistory.m +11 -8
- package/Sources/CCPets/Usage/CCPetsUsage+Internal.h +2 -0
- package/Sources/CCPets/Usage/CCPetsUsage+Models.m +206 -14
- package/Sources/CCPets/Usage/CCPetsUsage+TokenTotals.m +4 -4
- package/Sources/CCPets/Usage/CCPetsUsage.h +7 -2
- package/Sources/CCPets/Usage/CCPetsUsageMode.h +2 -0
- package/Sources/CCPets/Usage/CCPetsUsageMode.m +29 -4
- package/Sources/CCPets/Usage/CCPetsUsageMonitor.h +4 -4
- package/Sources/CCPets/Usage/CCPetsUsageMonitor.m +90 -7
- package/Sources/CCPets/Usage/QuotaDashboardView+CompactRow.m +81 -0
- package/Sources/CCPets/Usage/QuotaDashboardView+Primitives.m +5 -8
- package/Sources/CCPets/Usage/QuotaDashboardView+Private.h +26 -4
- package/Sources/CCPets/Usage/QuotaDashboardView+Rendering.m +99 -99
- package/Sources/CCPets/Usage/QuotaDashboardView.h +9 -10
- package/Sources/CCPets/Usage/QuotaDashboardView.m +232 -79
- package/THIRD_PARTY_NOTICES.md +5 -4
- package/THIRD_PARTY_NOTICES.zh-CN.md +6 -5
- package/bin/agy-with-pet +82 -0
- package/bin/cc-pets +1 -1
- package/bin/claude-with-pet +15 -0
- package/bin/codex-with-pet +17 -2
- package/package.json +5 -3
- package/scripts/install-shell-integration.sh +5 -0
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
#import "CCPetsBridge.h"
|
|
2
|
+
#import "CCPetsBridgeStore.h"
|
|
2
3
|
#import "CCPetsPaths.h"
|
|
3
|
-
#import <errno.h>
|
|
4
|
-
#import <signal.h>
|
|
5
4
|
#import <unistd.h>
|
|
6
5
|
|
|
7
6
|
NSString *const BridgeBadgeEnabledKey = @"CCPetsBridgeBadgeEnabled";
|
|
8
7
|
NSString *const BridgeNotificationKey = @"CCPetsBridgeNotification";
|
|
9
8
|
|
|
10
|
-
//
|
|
9
|
+
// 一次最多读这么多文件。回执保留 48 小时,正常使用远到不了这个量;
|
|
11
10
|
// 真到了说明有东西在刷消息,宁可少显示几条也不让桌宠主线程卡在读盘上。
|
|
12
11
|
static const NSUInteger BridgeFileScanLimit = 500;
|
|
13
12
|
|
|
@@ -87,6 +86,29 @@ static NSArray<NSString *> *JSONFilesInDirectory(NSString *directory) {
|
|
|
87
86
|
return files;
|
|
88
87
|
}
|
|
89
88
|
|
|
89
|
+
// 回执每次状态变化都是"临时文件 + rename",修改时间就是最后一次更新的时间,比 ID(创建时间)更准:
|
|
90
|
+
// 排了很久的消息也可能刚刚送达。比 since 早的文件里不可能有新送达,不用打开;
|
|
91
|
+
// 其余的按新到旧取,文件数超过上限时丢掉的才是最旧的。
|
|
92
|
+
static NSArray<NSString *> *ReceiptFilesUpdatedSince(NSString *directory, NSTimeInterval since) {
|
|
93
|
+
NSArray<NSURL *> *entries = [NSFileManager.defaultManager contentsOfDirectoryAtURL:[NSURL fileURLWithPath:directory]
|
|
94
|
+
includingPropertiesForKeys:@[NSURLContentModificationDateKey] options:0 error:nil];
|
|
95
|
+
NSMutableArray<NSDictionary *> *candidates = [NSMutableArray array];
|
|
96
|
+
for (NSURL *entry in entries) {
|
|
97
|
+
if (![entry.lastPathComponent hasSuffix:@".json"]) continue;
|
|
98
|
+
NSDate *modified = nil;
|
|
99
|
+
[entry getResourceValue:&modified forKey:NSURLContentModificationDateKey error:nil];
|
|
100
|
+
if (modified.timeIntervalSince1970 < since) continue;
|
|
101
|
+
[candidates addObject:@{@"path": entry.path, @"modified": modified}];
|
|
102
|
+
}
|
|
103
|
+
[candidates sortUsingComparator:^NSComparisonResult(NSDictionary *left, NSDictionary *right) {
|
|
104
|
+
return [right[@"modified"] compare:left[@"modified"]];
|
|
105
|
+
}];
|
|
106
|
+
if (candidates.count > BridgeFileScanLimit) {
|
|
107
|
+
[candidates removeObjectsInRange:NSMakeRange(BridgeFileScanLimit, candidates.count - BridgeFileScanLimit)];
|
|
108
|
+
}
|
|
109
|
+
return [candidates valueForKey:@"path"];
|
|
110
|
+
}
|
|
111
|
+
|
|
90
112
|
static NSDictionary *ReadJSONObject(NSString *path) {
|
|
91
113
|
NSData *data = [NSData dataWithContentsOfFile:path];
|
|
92
114
|
if (data.length == 0) return nil;
|
|
@@ -94,10 +116,9 @@ static NSDictionary *ReadJSONObject(NSString *path) {
|
|
|
94
116
|
return [object isKindOfClass:NSDictionary.class] ? object : nil;
|
|
95
117
|
}
|
|
96
118
|
|
|
97
|
-
|
|
98
|
-
static BOOL IsJSONFalse(id value) {
|
|
119
|
+
static BOOL IsJSONBoolean(id value, BOOL expected) {
|
|
99
120
|
return [value isKindOfClass:NSNumber.class] &&
|
|
100
|
-
CFGetTypeID((__bridge CFTypeRef)value) == CFBooleanGetTypeID() &&
|
|
121
|
+
CFGetTypeID((__bridge CFTypeRef)value) == CFBooleanGetTypeID() && [value boolValue] == expected;
|
|
101
122
|
}
|
|
102
123
|
|
|
103
124
|
NSDictionary *CCBridgeNormalizeOptions(NSDictionary *raw) {
|
|
@@ -105,9 +126,12 @@ NSDictionary *CCBridgeNormalizeOptions(NSDictionary *raw) {
|
|
|
105
126
|
return @{
|
|
106
127
|
@"codexApprove": KnownTools(raw[@"codexApprove"]),
|
|
107
128
|
@"claudeAllow": KnownTools(raw[@"claudeAllow"]),
|
|
129
|
+
@"antigravityAllow": KnownTools(raw[@"antigravityAllow"]),
|
|
130
|
+
@"antigravityApp": IsJSONBoolean(raw[@"antigravityApp"], YES) ? @YES : @NO,
|
|
131
|
+
@"tabTitle": IsJSONBoolean(raw[@"tabTitle"], YES) ? @YES : @NO,
|
|
108
132
|
// 必须是 @YES / @NO(CFBoolean):写回开关文件时要落成 JSON 的 true / false,而不是 1 / 0。
|
|
109
|
-
@"wake":
|
|
110
|
-
@"editGuard":
|
|
133
|
+
@"wake": IsJSONBoolean(raw[@"wake"], NO) ? @NO : @YES,
|
|
134
|
+
@"editGuard": IsJSONBoolean(raw[@"editGuard"], NO) ? @NO : @YES
|
|
111
135
|
};
|
|
112
136
|
}
|
|
113
137
|
|
|
@@ -140,13 +164,6 @@ NSUInteger CCBridgeActiveReservationCount(NSSet<NSString *> *sessionIds) {
|
|
|
140
164
|
return count;
|
|
141
165
|
}
|
|
142
166
|
|
|
143
|
-
static BOOL ProcessAlive(id pidValue) {
|
|
144
|
-
if (![pidValue isKindOfClass:NSNumber.class]) return YES; // 没记 pid 的会话交给 bridge 端判定
|
|
145
|
-
pid_t pid = [pidValue intValue];
|
|
146
|
-
if (pid <= 1) return YES;
|
|
147
|
-
return kill(pid, 0) == 0 || errno == EPERM;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
167
|
NSDictionary<NSString *, NSDictionary *> *CCBridgeSessions(void) {
|
|
151
168
|
NSString *directory = [CCBridgeStateDirectory() stringByAppendingPathComponent:@"sessions"];
|
|
152
169
|
NSMutableDictionary<NSString *, NSDictionary *> *sessions = [NSMutableDictionary dictionary];
|
|
@@ -154,12 +171,17 @@ NSDictionary<NSString *, NSDictionary *> *CCBridgeSessions(void) {
|
|
|
154
171
|
NSDictionary *record = ReadJSONObject(path);
|
|
155
172
|
NSString *session = BridgeSafeString(record[@"session"], 128);
|
|
156
173
|
NSString *name = BridgeSafeString(record[@"name"], 40);
|
|
157
|
-
|
|
174
|
+
// 与 CLI 用同一条规则,否则菜单里的在线会话和 list_agents 对不上。
|
|
175
|
+
if (session.length == 0 || name.length == 0 || !CCBridgeSessionLive(record)) continue;
|
|
158
176
|
NSMutableDictionary *entry = [@{
|
|
159
177
|
@"name": name,
|
|
160
178
|
@"ref": BridgeSafeString(record[@"ref"], 6),
|
|
161
179
|
@"provider": BridgeSafeString(record[@"provider"], 16)
|
|
162
180
|
} mutableCopy];
|
|
181
|
+
NSString *nameSource = [record[@"nameSource"] isKindOfClass:NSString.class] ? record[@"nameSource"] : nil;
|
|
182
|
+
if ([nameSource isEqualToString:@"generated"] || [nameSource isEqualToString:@"custom"]) {
|
|
183
|
+
entry[@"nameSource"] = nameSource;
|
|
184
|
+
}
|
|
163
185
|
NSString *profileID = BridgeSafeString(record[@"profileId"], 128);
|
|
164
186
|
if (profileID.length > 0) entry[@"profileId"] = profileID;
|
|
165
187
|
NSString *tty = BridgeSafeString(record[@"tty"], 32);
|
|
@@ -172,7 +194,7 @@ NSDictionary<NSString *, NSDictionary *> *CCBridgeSessions(void) {
|
|
|
172
194
|
NSArray<NSDictionary *> *CCBridgeRecentDeliveries(NSTimeInterval since, NSUInteger limit) {
|
|
173
195
|
NSString *directory = [CCBridgeStateDirectory() stringByAppendingPathComponent:@"sent"];
|
|
174
196
|
NSMutableArray<NSDictionary *> *deliveries = [NSMutableArray array];
|
|
175
|
-
for (NSString *path in
|
|
197
|
+
for (NSString *path in ReceiptFilesUpdatedSince(directory, since)) {
|
|
176
198
|
NSDictionary *receipt = ReadJSONObject(path);
|
|
177
199
|
if (![receipt[@"status"] isEqual:@"delivered"]) continue;
|
|
178
200
|
NSDictionary *from = [receipt[@"from"] isKindOfClass:NSDictionary.class] ? receipt[@"from"] : nil;
|
|
@@ -191,6 +213,8 @@ NSArray<NSDictionary *> *CCBridgeRecentDeliveries(NSTimeInterval since, NSUInteg
|
|
|
191
213
|
@"id": BridgeSafeString(receipt[@"id"], 64),
|
|
192
214
|
@"from": fromName,
|
|
193
215
|
@"to": toName,
|
|
216
|
+
@"fromIdentity": @{@"name": fromName, @"nameSource": BridgeSafeString(from[@"nameSource"], 16)},
|
|
217
|
+
@"toIdentity": @{@"name": toName, @"nameSource": BridgeSafeString(to[@"nameSource"], 16)},
|
|
194
218
|
@"toSession": toSession,
|
|
195
219
|
@"fromSession": BridgeSafeString(from[@"session"], 128),
|
|
196
220
|
@"at": @(at)
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
#import "CCPetsBridgeAntigravityApp.h"
|
|
2
|
+
|
|
3
|
+
#import "CCPetsBridge.h"
|
|
4
|
+
#import "CCPetsBridgeStore.h"
|
|
5
|
+
#import "CCPetsCLISupport.h"
|
|
6
|
+
#import <signal.h>
|
|
7
|
+
#import <stdio.h>
|
|
8
|
+
#import <unistd.h>
|
|
9
|
+
|
|
10
|
+
NSString *const CCBridgeAntigravityAppWakePrompt = @"[cc-bridge inbox] A teammate message is waiting in the local CC Bridge inbox. Read the message context supplied by the hook and handle it within this session’s permissions. If there is no supplied message, stop without taking any action.";
|
|
11
|
+
|
|
12
|
+
static volatile sig_atomic_t SidecarStopping;
|
|
13
|
+
|
|
14
|
+
static void StopSidecar(int signalNumber) {
|
|
15
|
+
(void)signalNumber;
|
|
16
|
+
SidecarStopping = 1;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
static BOOL WakeEnabled(void) {
|
|
20
|
+
NSDictionary *options = CCBridgeOptions();
|
|
21
|
+
return [options[@"antigravityApp"] boolValue] && [options[@"wake"] boolValue];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
static BOOL IsHostedConversation(NSDictionary *session, NSNumber *hostPID) {
|
|
25
|
+
return [session[@"provider"] isEqual:CCBridgeAntigravityAppProvider] &&
|
|
26
|
+
[CCBridgeSessionHostPID(session) isEqual:hostPID] && ![session[@"status"] isEqual:@"gone"];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// The oldest pending ID remains unchanged as later messages arrive. After Antigravity
|
|
30
|
+
// accepts a nudge, leave that batch to its hook and allow a new nudge only after it advances.
|
|
31
|
+
static void WakeIdleConversations(NSString *agentAPI, NSNumber *hostPID,
|
|
32
|
+
NSMutableDictionary<NSString *, NSDictionary *> *attempts) {
|
|
33
|
+
NSMutableSet<NSString *> *active = [NSMutableSet set];
|
|
34
|
+
for (NSDictionary *session in CCBridgeListSessions()) {
|
|
35
|
+
if (SidecarStopping) return;
|
|
36
|
+
if (!IsHostedConversation(session, hostPID)) continue;
|
|
37
|
+
NSString *sessionID = CCBridgeSafeSessionId(session[@"session"]);
|
|
38
|
+
if (!sessionID || ![[NSUUID alloc] initWithUUIDString:sessionID]) continue;
|
|
39
|
+
|
|
40
|
+
NSString *firstPending = CCBridgeOldestPendingMessageName(sessionID);
|
|
41
|
+
if (!firstPending) continue;
|
|
42
|
+
[active addObject:sessionID];
|
|
43
|
+
if (![session[@"status"] isEqual:@"idle"]) continue;
|
|
44
|
+
|
|
45
|
+
NSDictionary *previous = attempts[sessionID];
|
|
46
|
+
BOOL sameBatch = [firstPending isEqual:previous[@"firstPending"]];
|
|
47
|
+
if (sameBatch && [previous[@"accepted"] boolValue]) continue;
|
|
48
|
+
NSTimeInterval now = NSProcessInfo.processInfo.systemUptime;
|
|
49
|
+
if (sameBatch && now < [previous[@"retryAt"] doubleValue]) continue;
|
|
50
|
+
|
|
51
|
+
// A human prompt may have started after listing sessions. Recheck immediately
|
|
52
|
+
// before calling App's transport and leave inbox claims to PreInvocation.
|
|
53
|
+
NSDictionary *target = CCBridgeReadSession(sessionID);
|
|
54
|
+
if (!IsHostedConversation(target, hostPID) || ![target[@"status"] isEqual:@"idle"] ||
|
|
55
|
+
!CCBridgeSessionLive(target) || ![firstPending isEqual:CCBridgeOldestPendingMessageName(sessionID)] ||
|
|
56
|
+
SidecarStopping || !WakeEnabled()) continue;
|
|
57
|
+
|
|
58
|
+
int status = CCPetsRun(agentAPI, @[@"send-message", sessionID, CCBridgeAntigravityAppWakePrompt],
|
|
59
|
+
nil, nil, 5, nil, nil);
|
|
60
|
+
if (status == 0) {
|
|
61
|
+
attempts[sessionID] = @{@"firstPending": firstPending, @"accepted": @YES};
|
|
62
|
+
} else {
|
|
63
|
+
NSTimeInterval delay = sameBatch ? MIN(60, 2 * [previous[@"delay"] doubleValue]) : 2;
|
|
64
|
+
// A timeout may have happened after acceptance. Give the hook time to
|
|
65
|
+
// consume the batch before retrying an unconfirmed call.
|
|
66
|
+
if (status == CCPetsRunTimedOut) delay = 60;
|
|
67
|
+
attempts[sessionID] = @{@"firstPending": firstPending, @"delay": @(delay),
|
|
68
|
+
@"retryAt": @(NSProcessInfo.processInfo.systemUptime + delay)};
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
for (NSString *sessionID in attempts.allKeys) {
|
|
72
|
+
if (![active containsObject:sessionID]) [attempts removeObjectForKey:sessionID];
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
int CCBridgeRunAntigravityAppSidecar(void) {
|
|
77
|
+
pid_t parent = getppid();
|
|
78
|
+
NSDictionary *ancestor = CCBridgeFindAgentAncestor(parent);
|
|
79
|
+
NSNumber *hostPID = ancestor[@"pid"];
|
|
80
|
+
NSString *dataDirectory = CCPetsEnvironmentValue(@"ANTIGRAVITY_EXECUTABLE_DATA_DIR");
|
|
81
|
+
NSString *agentAPI = CCPetsFindRealExecutable(@"agentapi", nil);
|
|
82
|
+
if (![ancestor[@"provider"] isEqual:CCBridgeAntigravityAppProvider] || hostPID.intValue <= 1 ||
|
|
83
|
+
!dataDirectory.isAbsolutePath || !agentAPI.isAbsolutePath) {
|
|
84
|
+
fputs("cc-pets: agy-app-sidecar requires an Antigravity App-managed Sidecar and agentapi.\n", stderr);
|
|
85
|
+
return 0;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
NSString *lock = nil;
|
|
89
|
+
struct sigaction action = {0};
|
|
90
|
+
struct sigaction previousInterrupt = {0}, previousTerminate = {0}, previousHangup = {0};
|
|
91
|
+
action.sa_handler = StopSidecar;
|
|
92
|
+
sigemptyset(&action.sa_mask);
|
|
93
|
+
SidecarStopping = 0;
|
|
94
|
+
sigaction(SIGINT, &action, &previousInterrupt);
|
|
95
|
+
sigaction(SIGTERM, &action, &previousTerminate);
|
|
96
|
+
sigaction(SIGHUP, &action, &previousHangup);
|
|
97
|
+
@try {
|
|
98
|
+
NSString *lockName = [NSString stringWithFormat:@"agy-app-sidecar-%@", hostPID];
|
|
99
|
+
NSMutableDictionary<NSString *, NSDictionary *> *attempts = [NSMutableDictionary dictionary];
|
|
100
|
+
while (!SidecarStopping && getppid() == parent && CCBridgeProcessAlive(hostPID.intValue)) {
|
|
101
|
+
@autoreleasepool {
|
|
102
|
+
if (WakeEnabled()) {
|
|
103
|
+
if (!lock) lock = CCBridgeAcquireLock(lockName);
|
|
104
|
+
if (lock) WakeIdleConversations(agentAPI, hostPID, attempts);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if (!SidecarStopping) sleep(1);
|
|
108
|
+
}
|
|
109
|
+
return 0;
|
|
110
|
+
} @catch (NSException *exception) {
|
|
111
|
+
fputs("cc-pets: Antigravity App Sidecar could not access the CC Bridge state.\n", stderr);
|
|
112
|
+
return 1;
|
|
113
|
+
} @finally {
|
|
114
|
+
CCBridgeReleaseLock(lock);
|
|
115
|
+
sigaction(SIGINT, &previousInterrupt, NULL);
|
|
116
|
+
sigaction(SIGTERM, &previousTerminate, NULL);
|
|
117
|
+
sigaction(SIGHUP, &previousHangup, NULL);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
// `cc-pets bridge <子命令>` 的入口。
|
|
4
4
|
//
|
|
5
|
-
// 面向用户:enable / configure / disable / status / list / send / name / inbox
|
|
5
|
+
// 面向用户:enable / configure / disable / status / list / send / name / inbox / agy
|
|
6
6
|
// 面向 CLI 集成(由 hooks / MCP 配置调用):hook / watch / mcp / notify-idle
|
|
7
7
|
// 面向安装流程:refresh / teardown
|
|
8
8
|
//
|
|
9
9
|
// arguments 不含 "bridge" 本身。返回进程退出码。
|
|
10
10
|
int CCBridgeCommandMain(NSArray<NSString *> *arguments);
|
|
11
|
+
NSDictionary *CCBridgeHandleAntigravityHook(NSString *event, NSDictionary *payload);
|
|
12
|
+
void CCBridgeFinishAntigravityHook(BOOL written);
|