cc-pets 2.5.0 → 2.6.0-beta.1
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 +47 -5
- package/CC_BRIDGE.zh-CN.md +42 -5
- package/CONTRIBUTING.md +1 -1
- package/CONTRIBUTING.zh-CN.md +1 -1
- package/README.md +48 -19
- package/README.zh-CN.md +46 -17
- package/Resources/AgentIcons/antigravity.icns +0 -0
- package/Resources/zh-Hans.lproj/Localizable.strings +64 -15
- package/Sources/CCPets/App/CCPetsAppDelegate+AgentEvents.m +7 -3
- package/Sources/CCPets/App/CCPetsAppDelegate+AgentStatus.m +11 -3
- package/Sources/CCPets/App/CCPetsAppDelegate+Bridge.m +16 -5
- package/Sources/CCPets/App/CCPetsAppDelegate+Private.h +11 -1
- package/Sources/CCPets/App/CCPetsAppDelegate+Profiles.m +21 -11
- package/Sources/CCPets/App/CCPetsAppDelegate+Quota.m +27 -16
- package/Sources/CCPets/App/CCPetsAppDelegate+Settings.m +43 -7
- package/Sources/CCPets/App/CCPetsAppDelegate+Speech.m +2 -1
- package/Sources/CCPets/App/CCPetsAppDelegate+Update.m +3 -3
- package/Sources/CCPets/App/CCPetsAppDelegate+Workbench.m +20 -22
- package/Sources/CCPets/App/CCPetsAppDelegate.m +14 -6
- 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 +7 -5
- 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 +172 -17
- package/Sources/CCPets/Bridge/CCPetsBridgeCore.m +25 -7
- package/Sources/CCPets/Bridge/CCPetsBridgeSetup.m +17 -0
- package/Sources/CCPets/Bridge/CCPetsBridgeStore.h +7 -2
- package/Sources/CCPets/Bridge/CCPetsBridgeStore.m +92 -11
- 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/CCPetsIntegrations.h +1 -1
- package/Sources/CCPets/Integrations/CCPetsIntegrations.m +37 -7
- 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 +5 -1
- package/Sources/CCPets/Integrations/CCPetsTerminalFocus.m +163 -40
- package/Sources/CCPets/Pet/CCPetsPreviews.m +16 -8
- package/Sources/CCPets/Pet/PetView+Menu.m +56 -5
- 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 +4 -1
- package/Sources/CCPets/Support/CCPetsPreferences.m +18 -0
- package/Sources/CCPets/UI/CCPetsMenuBarPanel.m +10 -5
- package/Sources/CCPets/UI/CCPetsMenuBarSummary.m +9 -6
- package/Sources/CCPets/UI/CCPetsSettingsPage.h +3 -0
- package/Sources/CCPets/UI/CCPetsSettingsPage.m +189 -8
- 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 +1 -1
- 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
|
@@ -0,0 +1,463 @@
|
|
|
1
|
+
#import "CCPetsBridgeTitleRelay.h"
|
|
2
|
+
#import "CCPetsBridgeTerminalTitle.h"
|
|
3
|
+
#import "CCPetsCLISupport.h"
|
|
4
|
+
#import "CCPetsTerminalFocus.h"
|
|
5
|
+
#import <errno.h>
|
|
6
|
+
#import <fcntl.h>
|
|
7
|
+
#import <poll.h>
|
|
8
|
+
#import <signal.h>
|
|
9
|
+
#import <sys/ioctl.h>
|
|
10
|
+
#import <sys/stat.h>
|
|
11
|
+
#import <sys/wait.h>
|
|
12
|
+
#import <termios.h>
|
|
13
|
+
#import <unistd.h>
|
|
14
|
+
#import <util.h>
|
|
15
|
+
|
|
16
|
+
static const NSUInteger RelayBufferLimit = 64 * 1024;
|
|
17
|
+
static const NSUInteger RelayTitleLimit = 4096;
|
|
18
|
+
|
|
19
|
+
typedef NS_ENUM(NSUInteger, RelayOutputState) {
|
|
20
|
+
RelayPlain, RelayEscape, RelayCSI, RelayEscapeIntermediate, RelayOSCCode, RelayOSCSeparator, RelayTitle,
|
|
21
|
+
RelayTitleEscape, RelayControlString, RelayControlEscape
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
@interface CCPetsTerminalTitleOutput : NSObject
|
|
25
|
+
@property RelayOutputState state;
|
|
26
|
+
@property BOOL oscString;
|
|
27
|
+
@property NSUInteger utf8Remaining;
|
|
28
|
+
@property NSMutableData *frame;
|
|
29
|
+
@property NSData *lastTitle;
|
|
30
|
+
@property(copy) NSString *nickname;
|
|
31
|
+
- (void)appendBytes:(const uint8_t *)bytes length:(NSUInteger)length to:(NSMutableData *)output;
|
|
32
|
+
- (void)refreshNickname:(NSString *)nickname output:(NSMutableData *)output;
|
|
33
|
+
- (void)flushTo:(NSMutableData *)output;
|
|
34
|
+
@end
|
|
35
|
+
|
|
36
|
+
static NSUInteger RemainingUTF8Bytes(const uint8_t *bytes, NSUInteger length, NSUInteger previous) {
|
|
37
|
+
NSUInteger continuation = 0;
|
|
38
|
+
while (continuation < length && (bytes[length - continuation - 1] & 0xc0) == 0x80) continuation++;
|
|
39
|
+
if (continuation == length) return previous > length ? previous - length : 0;
|
|
40
|
+
uint8_t lead = bytes[length - continuation - 1];
|
|
41
|
+
NSUInteger expected = 0;
|
|
42
|
+
if (lead >= 0xc2 && lead <= 0xdf) expected = 1;
|
|
43
|
+
else if (lead >= 0xe0 && lead <= 0xef) expected = 2;
|
|
44
|
+
else if (lead >= 0xf0 && lead <= 0xf4) expected = 3;
|
|
45
|
+
return expected > continuation ? expected - continuation : 0;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
@implementation CCPetsTerminalTitleOutput
|
|
49
|
+
|
|
50
|
+
- (instancetype)init {
|
|
51
|
+
if ((self = [super init])) _frame = [NSMutableData data];
|
|
52
|
+
return self;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
- (void)appendTitleTo:(NSMutableData *)output {
|
|
56
|
+
NSData *title = self.lastTitle;
|
|
57
|
+
if (!title) return;
|
|
58
|
+
const uint8_t *bytes = title.bytes;
|
|
59
|
+
NSUInteger terminatorLength = bytes[title.length - 1] == '\a' ? 1 : 2;
|
|
60
|
+
NSUInteger baseLength = title.length - terminatorLength;
|
|
61
|
+
if (!self.nickname.length || baseLength <= 4) {
|
|
62
|
+
[output appendData:title];
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
static const char separator[] = " · ";
|
|
66
|
+
[output appendBytes:bytes length:baseLength];
|
|
67
|
+
[output appendBytes:separator length:sizeof(separator) - 1];
|
|
68
|
+
[output appendData:[self.nickname dataUsingEncoding:NSUTF8StringEncoding]];
|
|
69
|
+
[output appendBytes:bytes + baseLength length:terminatorLength];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
- (void)refreshNickname:(NSString *)nickname output:(NSMutableData *)output {
|
|
73
|
+
if (nickname == self.nickname || [nickname isEqualToString:self.nickname]) return;
|
|
74
|
+
self.nickname = nickname;
|
|
75
|
+
// Keep the title as emitted by the child. Never append a suffix to its empty reset sequence.
|
|
76
|
+
if (self.lastTitle.length > 0) {
|
|
77
|
+
const uint8_t *bytes = self.lastTitle.bytes;
|
|
78
|
+
NSUInteger terminatorLength = bytes[self.lastTitle.length - 1] == '\a' ? 1 : 2;
|
|
79
|
+
if (self.lastTitle.length > 4 + terminatorLength) [self appendTitleTo:output];
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
- (void)flushTo:(NSMutableData *)output {
|
|
84
|
+
[output appendData:self.frame];
|
|
85
|
+
[self.frame setLength:0];
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
- (void)finishTitleWithByte:(uint8_t)byte output:(NSMutableData *)output {
|
|
89
|
+
[self.frame appendBytes:&byte length:1];
|
|
90
|
+
self.lastTitle = [self.frame copy];
|
|
91
|
+
[self appendTitleTo:output];
|
|
92
|
+
[self.frame setLength:0];
|
|
93
|
+
self.state = RelayPlain;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
- (void)appendBytes:(const uint8_t *)bytes length:(NSUInteger)length to:(NSMutableData *)output {
|
|
97
|
+
for (NSUInteger index = 0; index < length;) {
|
|
98
|
+
uint8_t byte = bytes[index++];
|
|
99
|
+
switch (self.state) {
|
|
100
|
+
case RelayPlain: {
|
|
101
|
+
const uint8_t *start = bytes + index - 1;
|
|
102
|
+
const uint8_t *escape = memchr(start, '\033', length - index + 1);
|
|
103
|
+
NSUInteger run = escape ? (NSUInteger)(escape - start) : length - index + 1;
|
|
104
|
+
[output appendBytes:start length:run];
|
|
105
|
+
self.utf8Remaining = escape ? 0 : RemainingUTF8Bytes(start, run, self.utf8Remaining);
|
|
106
|
+
if (!escape) return;
|
|
107
|
+
index += run;
|
|
108
|
+
[self.frame appendBytes:escape length:1];
|
|
109
|
+
self.state = RelayEscape;
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
case RelayEscape:
|
|
113
|
+
if (byte == ']') {
|
|
114
|
+
[self.frame appendBytes:&byte length:1];
|
|
115
|
+
self.state = RelayOSCCode;
|
|
116
|
+
} else {
|
|
117
|
+
[self flushTo:output];
|
|
118
|
+
if (byte == '\033') {
|
|
119
|
+
[self.frame appendBytes:&byte length:1];
|
|
120
|
+
} else {
|
|
121
|
+
[output appendBytes:&byte length:1];
|
|
122
|
+
self.oscString = NO;
|
|
123
|
+
if (byte == 'P' || byte == 'X' || byte == '^' || byte == '_') self.state = RelayControlString;
|
|
124
|
+
else if (byte == '[') self.state = RelayCSI;
|
|
125
|
+
else if (byte >= 0x20 && byte <= 0x2f) self.state = RelayEscapeIntermediate;
|
|
126
|
+
else self.state = RelayPlain;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
break;
|
|
130
|
+
case RelayCSI:
|
|
131
|
+
case RelayEscapeIntermediate: {
|
|
132
|
+
uint8_t firstFinal = self.state == RelayCSI ? 0x40 : 0x30;
|
|
133
|
+
if (byte == '\033') {
|
|
134
|
+
[self.frame appendBytes:&byte length:1];
|
|
135
|
+
self.state = RelayEscape;
|
|
136
|
+
} else {
|
|
137
|
+
[output appendBytes:&byte length:1];
|
|
138
|
+
if ((byte >= firstFinal && byte <= 0x7e) || byte == 0x18 || byte == 0x1a) self.state = RelayPlain;
|
|
139
|
+
}
|
|
140
|
+
break;
|
|
141
|
+
}
|
|
142
|
+
case RelayOSCCode:
|
|
143
|
+
case RelayOSCSeparator: {
|
|
144
|
+
BOOL code = self.state == RelayOSCCode;
|
|
145
|
+
if (code ? (byte == '0' || byte == '2') : byte == ';') {
|
|
146
|
+
[self.frame appendBytes:&byte length:1];
|
|
147
|
+
self.state = code ? RelayOSCSeparator : RelayTitle;
|
|
148
|
+
} else {
|
|
149
|
+
[self flushTo:output];
|
|
150
|
+
[output appendBytes:&byte length:1];
|
|
151
|
+
self.oscString = YES;
|
|
152
|
+
self.state = byte == '\a' || byte == 0x18 || byte == 0x1a
|
|
153
|
+
? RelayPlain : (byte == '\033' ? RelayControlEscape : RelayControlString);
|
|
154
|
+
}
|
|
155
|
+
break;
|
|
156
|
+
}
|
|
157
|
+
case RelayTitle:
|
|
158
|
+
if (byte == '\a') {
|
|
159
|
+
[self finishTitleWithByte:byte output:output];
|
|
160
|
+
} else if (byte == 0x18 || byte == 0x1a) {
|
|
161
|
+
[self flushTo:output];
|
|
162
|
+
[output appendBytes:&byte length:1];
|
|
163
|
+
self.state = RelayPlain;
|
|
164
|
+
} else {
|
|
165
|
+
[self.frame appendBytes:&byte length:1];
|
|
166
|
+
self.state = byte == '\033' ? RelayTitleEscape : RelayTitle;
|
|
167
|
+
if (self.frame.length >= RelayTitleLimit) {
|
|
168
|
+
[self flushTo:output];
|
|
169
|
+
self.lastTitle = nil;
|
|
170
|
+
self.oscString = YES;
|
|
171
|
+
self.state = byte == '\033' ? RelayControlEscape : RelayControlString;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
break;
|
|
175
|
+
case RelayTitleEscape:
|
|
176
|
+
if (byte == '\\') {
|
|
177
|
+
[self finishTitleWithByte:byte output:output];
|
|
178
|
+
} else {
|
|
179
|
+
// An unexpected escape inside OSC cancels its rewrite. Reprocess it as a new escape.
|
|
180
|
+
NSUInteger prefix = self.frame.length - 1;
|
|
181
|
+
[output appendBytes:self.frame.bytes length:prefix];
|
|
182
|
+
[self.frame replaceBytesInRange:NSMakeRange(0, prefix) withBytes:NULL length:0];
|
|
183
|
+
self.lastTitle = nil;
|
|
184
|
+
self.state = RelayEscape;
|
|
185
|
+
index--;
|
|
186
|
+
}
|
|
187
|
+
break;
|
|
188
|
+
case RelayControlString:
|
|
189
|
+
case RelayControlEscape: {
|
|
190
|
+
BOOL escaped = self.state == RelayControlEscape;
|
|
191
|
+
[output appendBytes:&byte length:1];
|
|
192
|
+
if ((escaped && byte == '\\') || (self.oscString && byte == '\a') || byte == 0x18 || byte == 0x1a) {
|
|
193
|
+
self.state = RelayPlain;
|
|
194
|
+
}
|
|
195
|
+
else if (byte == '\033' && (!escaped || self.oscString)) self.state = RelayControlEscape;
|
|
196
|
+
else self.state = RelayControlString;
|
|
197
|
+
break;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
@end
|
|
204
|
+
|
|
205
|
+
static const int RelaySignals[] = {SIGWINCH, SIGINT, SIGTERM, SIGHUP, SIGQUIT, SIGTSTP};
|
|
206
|
+
static volatile sig_atomic_t RelayResize, RelayInterrupt, RelaySuspend;
|
|
207
|
+
|
|
208
|
+
static void HandleRelaySignal(int signalNumber) {
|
|
209
|
+
if (signalNumber == SIGWINCH) RelayResize = 1;
|
|
210
|
+
else if (signalNumber == SIGTSTP) RelaySuspend = 1;
|
|
211
|
+
else RelayInterrupt = signalNumber;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
static void RestoreRelaySignalActions(const struct sigaction *actions, NSUInteger count) {
|
|
215
|
+
for (NSUInteger index = 0; index < count; index++) sigaction(RelaySignals[index], &actions[index], NULL);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
static int ExecRelayChild(char **arguments) {
|
|
219
|
+
execvp(arguments[0], arguments);
|
|
220
|
+
int failure = errno;
|
|
221
|
+
perror(arguments[0]);
|
|
222
|
+
return failure == ENOENT ? 127 : 126;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
static void RegisterRelayCodexLaunch(NSString *provider, pid_t pid, NSTimeInterval launchedAt) {
|
|
226
|
+
if (![provider isEqual:@"Codex"]) return;
|
|
227
|
+
@try {
|
|
228
|
+
RegisterCodexLaunchForProcess(pid, NSFileManager.defaultManager.currentDirectoryPath,
|
|
229
|
+
TerminalFocusTargetFromEnvironment(), launchedAt);
|
|
230
|
+
} @catch (NSException *exception) {}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
static int ExecWithoutRelay(char **arguments, NSString *provider) {
|
|
234
|
+
unsetenv("CC_PETS_BRIDGE_TITLE_TOKEN");
|
|
235
|
+
RegisterRelayCodexLaunch(provider, getpid(), NSDate.date.timeIntervalSince1970);
|
|
236
|
+
return ExecRelayChild(arguments);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
static void SignalRelayChild(pid_t child, int signalNumber) {
|
|
240
|
+
if (kill(-child, signalNumber) != 0 && errno == ESRCH) kill(child, signalNumber);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
static BOOL IsForegroundTerminal(void) {
|
|
244
|
+
pid_t foreground = tcgetpgrp(STDIN_FILENO);
|
|
245
|
+
return foreground > 0 && foreground == getpgrp();
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
static void RestoreOuterTerminal(const struct termios *settings) {
|
|
249
|
+
if (IsForegroundTerminal()) tcsetattr(STDIN_FILENO, TCSANOW, settings);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
static BOOL WriteRelayData(int descriptor, NSMutableData *data) {
|
|
253
|
+
ssize_t written = write(descriptor, data.bytes, data.length);
|
|
254
|
+
if (written < 0) return errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK;
|
|
255
|
+
if (written > 0) [data replaceBytesInRange:NSMakeRange(0, (NSUInteger)written) withBytes:NULL length:0];
|
|
256
|
+
return YES;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
static int RunRelay(char **arguments, NSString *provider, NSString *launchToken) {
|
|
260
|
+
struct termios original;
|
|
261
|
+
if (!launchToken.length || !isatty(STDIN_FILENO) || !isatty(STDOUT_FILENO) ||
|
|
262
|
+
!IsForegroundTerminal() || tcgetattr(STDIN_FILENO, &original) != 0) return ExecWithoutRelay(arguments, provider);
|
|
263
|
+
|
|
264
|
+
struct stat inputStat, outputStat;
|
|
265
|
+
if (fstat(STDIN_FILENO, &inputStat) != 0 || fstat(STDOUT_FILENO, &outputStat) != 0 ||
|
|
266
|
+
inputStat.st_rdev != outputStat.st_rdev) return ExecWithoutRelay(arguments, provider);
|
|
267
|
+
// A separately opened descriptor doesn't change O_NONBLOCK for the invoking shell or its jobs.
|
|
268
|
+
const char *terminalPath = ttyname(STDOUT_FILENO);
|
|
269
|
+
int outerOutput = terminalPath ? open(terminalPath, O_WRONLY | O_NOCTTY | O_CLOEXEC | O_NONBLOCK) : -1;
|
|
270
|
+
if (outerOutput < 0) return ExecWithoutRelay(arguments, provider);
|
|
271
|
+
// forkpty joins all three descriptors to the PTY. Keep a separate stderr redirection intact.
|
|
272
|
+
BOOL relayStderr = isatty(STDERR_FILENO) && fstat(STDERR_FILENO, &outputStat) == 0 &&
|
|
273
|
+
inputStat.st_rdev == outputStat.st_rdev;
|
|
274
|
+
int savedStderr = relayStderr ? -1 : fcntl(STDERR_FILENO, F_DUPFD_CLOEXEC, 3);
|
|
275
|
+
int launchGate[2];
|
|
276
|
+
if ((!relayStderr && savedStderr < 0) || pipe(launchGate) != 0) {
|
|
277
|
+
if (savedStderr >= 0) close(savedStderr);
|
|
278
|
+
close(outerOutput);
|
|
279
|
+
return ExecWithoutRelay(arguments, provider);
|
|
280
|
+
}
|
|
281
|
+
struct termios raw = original;
|
|
282
|
+
cfmakeraw(&raw);
|
|
283
|
+
struct winsize size = {0};
|
|
284
|
+
ioctl(STDIN_FILENO, TIOCGWINSZ, &size);
|
|
285
|
+
|
|
286
|
+
RelayResize = RelayInterrupt = RelaySuspend = 0;
|
|
287
|
+
struct sigaction action = {0};
|
|
288
|
+
struct sigaction previous[sizeof(RelaySignals) / sizeof(*RelaySignals)];
|
|
289
|
+
action.sa_handler = HandleRelaySignal;
|
|
290
|
+
sigemptyset(&action.sa_mask);
|
|
291
|
+
NSUInteger actionCount = 0;
|
|
292
|
+
while (actionCount < sizeof(RelaySignals) / sizeof(*RelaySignals) &&
|
|
293
|
+
sigaction(RelaySignals[actionCount], &action, &previous[actionCount]) == 0) actionCount++;
|
|
294
|
+
if (actionCount != sizeof(RelaySignals) / sizeof(*RelaySignals) || tcsetattr(STDIN_FILENO, TCSANOW, &raw) != 0) {
|
|
295
|
+
close(launchGate[0]);
|
|
296
|
+
close(launchGate[1]);
|
|
297
|
+
if (savedStderr >= 0) close(savedStderr);
|
|
298
|
+
close(outerOutput);
|
|
299
|
+
RestoreRelaySignalActions(previous, actionCount);
|
|
300
|
+
return ExecWithoutRelay(arguments, provider);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
int master = -1;
|
|
304
|
+
NSTimeInterval launchedAt = NSDate.date.timeIntervalSince1970;
|
|
305
|
+
pid_t child = forkpty(&master, NULL, &original, &size);
|
|
306
|
+
if (child == 0) {
|
|
307
|
+
close(launchGate[1]);
|
|
308
|
+
RestoreRelaySignalActions(previous, actionCount);
|
|
309
|
+
char unused;
|
|
310
|
+
while (read(launchGate[0], &unused, 1) < 0 && errno == EINTR) {}
|
|
311
|
+
close(launchGate[0]);
|
|
312
|
+
if (savedStderr >= 0) {
|
|
313
|
+
if (dup2(savedStderr, STDERR_FILENO) < 0) _exit(126);
|
|
314
|
+
close(savedStderr);
|
|
315
|
+
}
|
|
316
|
+
_exit(ExecRelayChild(arguments));
|
|
317
|
+
}
|
|
318
|
+
close(launchGate[0]);
|
|
319
|
+
if (savedStderr >= 0) close(savedStderr);
|
|
320
|
+
// Register the actual child PID before a shared Codex host can emit SessionStart.
|
|
321
|
+
if (child > 0) RegisterRelayCodexLaunch(provider, child, launchedAt);
|
|
322
|
+
close(launchGate[1]);
|
|
323
|
+
if (child < 0) {
|
|
324
|
+
close(outerOutput);
|
|
325
|
+
RestoreOuterTerminal(&original);
|
|
326
|
+
RestoreRelaySignalActions(previous, actionCount);
|
|
327
|
+
return ExecWithoutRelay(arguments, provider);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
BOOL exited = NO;
|
|
331
|
+
int completion = 0;
|
|
332
|
+
@try {
|
|
333
|
+
fcntl(master, F_SETFD, FD_CLOEXEC);
|
|
334
|
+
int masterFlags = fcntl(master, F_GETFL);
|
|
335
|
+
if (masterFlags < 0 || fcntl(master, F_SETFL, masterFlags | O_NONBLOCK) != 0) return 1;
|
|
336
|
+
CCPetsTerminalTitleOutput *parser = [CCPetsTerminalTitleOutput new];
|
|
337
|
+
NSMutableData *pendingInput = [NSMutableData data];
|
|
338
|
+
NSMutableData *pendingOutput = [NSMutableData data];
|
|
339
|
+
BOOL masterOpen = YES;
|
|
340
|
+
NSTimeInterval nicknameRefresh = 0, stopDeadline = 0, drainDeadline = 0;
|
|
341
|
+
while (!exited || masterOpen || pendingOutput.length > 0) {
|
|
342
|
+
@autoreleasepool {
|
|
343
|
+
NSTimeInterval now = NSProcessInfo.processInfo.systemUptime;
|
|
344
|
+
BOOL childStopped = NO;
|
|
345
|
+
if (!exited) {
|
|
346
|
+
int status = 0;
|
|
347
|
+
if (waitpid(child, &status, WNOHANG | WUNTRACED) == child) {
|
|
348
|
+
if (WIFSTOPPED(status)) childStopped = YES;
|
|
349
|
+
else {
|
|
350
|
+
completion = status;
|
|
351
|
+
exited = YES;
|
|
352
|
+
drainDeadline = now + 0.5;
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
if ((RelaySuspend || childStopped) && !exited && !RelayInterrupt && !stopDeadline) {
|
|
357
|
+
RelaySuspend = 0;
|
|
358
|
+
if (!childStopped) SignalRelayChild(child, SIGSTOP);
|
|
359
|
+
RestoreOuterTerminal(&original);
|
|
360
|
+
do { raise(SIGSTOP); } while (!IsForegroundTerminal() && !RelayInterrupt);
|
|
361
|
+
if (!RelayInterrupt) {
|
|
362
|
+
tcsetattr(STDIN_FILENO, TCSANOW, &raw);
|
|
363
|
+
SignalRelayChild(child, SIGCONT);
|
|
364
|
+
RelayResize = 1;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
if (RelayResize) {
|
|
368
|
+
RelayResize = 0;
|
|
369
|
+
if (masterOpen && ioctl(STDIN_FILENO, TIOCGWINSZ, &size) == 0) ioctl(master, TIOCSWINSZ, &size);
|
|
370
|
+
}
|
|
371
|
+
if (RelayInterrupt) {
|
|
372
|
+
int signalNumber = RelayInterrupt;
|
|
373
|
+
RelayInterrupt = 0;
|
|
374
|
+
if (!exited) {
|
|
375
|
+
SignalRelayChild(child, signalNumber);
|
|
376
|
+
if (signalNumber != SIGINT || !IsForegroundTerminal()) stopDeadline = now + 2;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
if (stopDeadline && now >= stopDeadline && !exited) SignalRelayChild(child, SIGKILL);
|
|
380
|
+
if (masterOpen && !exited && now >= nicknameRefresh && pendingOutput.length < RelayBufferLimit &&
|
|
381
|
+
parser.state == RelayPlain && parser.utf8Remaining == 0) {
|
|
382
|
+
@try {
|
|
383
|
+
NSString *name = CCBridgeTerminalTitleName(provider, launchToken, child);
|
|
384
|
+
NSString *nickname = name.length > 0 ? CCBridgeComposeTerminalTitle(nil, name) : nil;
|
|
385
|
+
[parser refreshNickname:nickname output:pendingOutput];
|
|
386
|
+
} @catch (NSException *exception) {}
|
|
387
|
+
nicknameRefresh = now + 0.25;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
BOOL readInput = !exited && masterOpen && !stopDeadline && pendingInput.length < RelayBufferLimit;
|
|
391
|
+
BOOL readOutput = masterOpen && pendingOutput.length < RelayBufferLimit;
|
|
392
|
+
struct pollfd descriptors[] = {
|
|
393
|
+
{.fd = readInput ? STDIN_FILENO : -1, .events = POLLIN},
|
|
394
|
+
{.fd = masterOpen ? master : -1, .events = (readOutput ? POLLIN : 0) | (pendingInput.length > 0 ? POLLOUT : 0)},
|
|
395
|
+
{.fd = pendingOutput.length > 0 ? outerOutput : -1, .events = POLLOUT}
|
|
396
|
+
};
|
|
397
|
+
int ready = poll(descriptors, 3, 100);
|
|
398
|
+
if (ready < 0) {
|
|
399
|
+
if (errno == EINTR) continue;
|
|
400
|
+
return 1;
|
|
401
|
+
}
|
|
402
|
+
if (!ready && masterOpen && exited && pendingOutput.length == 0 && now >= drainDeadline) {
|
|
403
|
+
masterOpen = NO;
|
|
404
|
+
[parser flushTo:pendingOutput];
|
|
405
|
+
}
|
|
406
|
+
uint8_t bytes[8192];
|
|
407
|
+
if (descriptors[0].revents) {
|
|
408
|
+
ssize_t length = read(STDIN_FILENO, bytes, sizeof(bytes));
|
|
409
|
+
if (length > 0) [pendingInput appendBytes:bytes length:(NSUInteger)length];
|
|
410
|
+
else if (length == 0 || (errno != EINTR && errno != EAGAIN && errno != EWOULDBLOCK)) {
|
|
411
|
+
SignalRelayChild(child, SIGHUP);
|
|
412
|
+
stopDeadline = now + 2;
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
if (descriptors[1].revents & POLLOUT && pendingInput.length > 0 && !WriteRelayData(master, pendingInput)) {
|
|
416
|
+
[pendingInput setLength:0];
|
|
417
|
+
}
|
|
418
|
+
if (readOutput && (descriptors[1].revents & (POLLIN | POLLHUP | POLLERR | POLLNVAL))) {
|
|
419
|
+
ssize_t length = read(master, bytes, sizeof(bytes));
|
|
420
|
+
if (length > 0) {
|
|
421
|
+
[parser appendBytes:bytes length:(NSUInteger)length to:pendingOutput];
|
|
422
|
+
if (exited) drainDeadline = now + 0.5;
|
|
423
|
+
}
|
|
424
|
+
else if (length == 0 || (errno != EINTR && errno != EAGAIN && errno != EWOULDBLOCK)) {
|
|
425
|
+
masterOpen = NO;
|
|
426
|
+
[parser flushTo:pendingOutput];
|
|
427
|
+
if (!exited && !stopDeadline) stopDeadline = now + 2;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
if (descriptors[2].revents && pendingOutput.length > 0 && !WriteRelayData(outerOutput, pendingOutput)) return 1;
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
return WIFSIGNALED(completion) ? 128 + WTERMSIG(completion) : WEXITSTATUS(completion);
|
|
434
|
+
} @finally {
|
|
435
|
+
RestoreOuterTerminal(&original);
|
|
436
|
+
close(outerOutput);
|
|
437
|
+
close(master);
|
|
438
|
+
if (!exited) {
|
|
439
|
+
SignalRelayChild(child, SIGKILL);
|
|
440
|
+
while (waitpid(child, NULL, 0) < 0 && errno == EINTR) {}
|
|
441
|
+
}
|
|
442
|
+
RestoreRelaySignalActions(previous, actionCount);
|
|
443
|
+
@try { CCBridgeClearTerminalTitleBinding(launchToken); } @catch (NSException *exception) {}
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
int CCPetsRunBridgeTitleRelay(NSArray<NSString *> *arguments) {
|
|
448
|
+
if (arguments.count < 2 || ![@[@"Codex", @"Claude"] containsObject:arguments.firstObject]) return 2;
|
|
449
|
+
// Build argv before forkpty; its child must not call Foundation between fork and exec.
|
|
450
|
+
char **childArguments = calloc(arguments.count, sizeof(*childArguments));
|
|
451
|
+
if (!childArguments) return 1;
|
|
452
|
+
@try {
|
|
453
|
+
for (NSUInteger index = 1; index < arguments.count; index++) {
|
|
454
|
+
const char *argument = arguments[index].UTF8String;
|
|
455
|
+
childArguments[index - 1] = argument ? strdup(argument) : NULL;
|
|
456
|
+
if (!childArguments[index - 1]) return 1;
|
|
457
|
+
}
|
|
458
|
+
return RunRelay(childArguments, arguments.firstObject, CCPetsEnvironmentValue(@"CC_PETS_BRIDGE_TITLE_TOKEN"));
|
|
459
|
+
} @finally {
|
|
460
|
+
for (NSUInteger index = 0; index + 1 < arguments.count; index++) free(childArguments[index]);
|
|
461
|
+
free(childArguments);
|
|
462
|
+
}
|
|
463
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#import <Foundation/Foundation.h>
|
|
2
2
|
|
|
3
|
-
// CC Pets 在 Claude Code / Codex 配置和 shell 里留下的集成:Agent Hooks、Claude status line
|
|
3
|
+
// CC Pets 在 Claude Code / Codex / Antigravity CLI 配置和 shell 里留下的集成:Agent Hooks、Claude status line
|
|
4
4
|
// 额度采集、.zshrc 里的 shim 段落与 shim 软链。原先是 scripts/install-claude-hooks.mjs、
|
|
5
5
|
// install-codex-hooks.mjs 和 uninstall-integrations.mjs,改成原生实现后安装和卸载都不再依赖 Node。
|
|
6
6
|
// CC Bridge 的集成不在这里,仍由 scripts/bridge 负责。
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#import "CCPetsL10n.h"
|
|
2
2
|
#import "CCPetsIntegrations.h"
|
|
3
|
+
#import "CCPetsAntigravityConfig.h"
|
|
3
4
|
#import "CCPetsJSON.h"
|
|
4
5
|
#import "CCPetsProfiles.h"
|
|
5
6
|
#import "CCPetsCLISupport.h"
|
|
@@ -492,7 +493,7 @@ static BOOL RemoveShims(void) {
|
|
|
492
493
|
[CCPetsHomeDirectory() stringByAppendingPathComponent:@".cc-pets/shims"];
|
|
493
494
|
if (![NSFileManager.defaultManager fileExistsAtPath:directory]) return NO;
|
|
494
495
|
BOOL changed = NO;
|
|
495
|
-
for (NSString *name in @[@"codex", @"claude"]) {
|
|
496
|
+
for (NSString *name in @[@"codex", @"claude", @"agy"]) {
|
|
496
497
|
NSString *shim = [directory stringByAppendingPathComponent:name];
|
|
497
498
|
// lstat:目标包被 npm uninstall 删掉后软链是断的,但仍然要清掉。
|
|
498
499
|
struct stat info;
|
|
@@ -569,27 +570,53 @@ int UninstallCodexHooksAtHome(NSString *codexHome) {
|
|
|
569
570
|
return failed ? 1 : 0;
|
|
570
571
|
}
|
|
571
572
|
|
|
573
|
+
static BOOL RemoveAntigravityHooksForUninstall(NSDictionary *profile, BOOL *failed) {
|
|
574
|
+
BOOL installed = CCPetsAntigravityPetHooksInstalled(profile);
|
|
575
|
+
@try {
|
|
576
|
+
if (CCPetsRemoveAntigravityPetHooks(profile)) return installed;
|
|
577
|
+
} @catch (NSException *exception) {
|
|
578
|
+
CCPetsPrintLine(stderr, exception.reason ?: exception.name);
|
|
579
|
+
}
|
|
580
|
+
*failed = YES;
|
|
581
|
+
return NO;
|
|
582
|
+
}
|
|
583
|
+
|
|
572
584
|
int UninstallIntegrations(BOOL preparingInstall, NSString *shellRC) {
|
|
573
585
|
BOOL failed = NO;
|
|
574
586
|
// 安装/卸载的隐式范围只包含官方默认 Home;环境变量指向的自定义 Home 必须先显式登记。
|
|
575
587
|
NSString *defaultCodexHome = [CCPetsHomeDirectory() stringByAppendingPathComponent:@".codex"];
|
|
576
588
|
NSString *defaultClaudeHome = [CCPetsHomeDirectory() stringByAppendingPathComponent:@".claude"];
|
|
589
|
+
NSString *defaultAntigravityHome = [CCPetsHomeDirectory() stringByAppendingPathComponent:@".gemini"];
|
|
577
590
|
NSString *codexHooksPath = [defaultCodexHome stringByAppendingPathComponent:@"hooks.json"];
|
|
578
591
|
BOOL codexChanged = RemoveCodexHooksAtHome(defaultCodexHome, preparingInstall, &failed);
|
|
579
592
|
NSString *claudeSettingsPath = [defaultClaudeHome stringByAppendingPathComponent:@"settings.json"];
|
|
580
593
|
BOOL claudeChanged = RemoveClaudeHooksAtHome(defaultClaudeHome, preparingInstall, &failed);
|
|
594
|
+
BOOL antigravityChanged = NO;
|
|
595
|
+
if (!preparingInstall) {
|
|
596
|
+
NSDictionary *profile = CCPetsProfileForHome(CCPetsProfileProviderAntigravity, defaultAntigravityHome) ?:
|
|
597
|
+
@{@"provider": CCPetsProfileProviderAntigravity, @"home": defaultAntigravityHome,
|
|
598
|
+
@"id": CCPetsProfileID(CCPetsProfileProviderAntigravity, defaultAntigravityHome)};
|
|
599
|
+
antigravityChanged = RemoveAntigravityHooksForUninstall(profile, &failed);
|
|
600
|
+
}
|
|
581
601
|
BOOL profileChanged = NO;
|
|
582
602
|
|
|
583
603
|
// 显式登记的 Home 也属于安装范围。默认 Home 已迁移进注册表时按规范化路径去重。
|
|
584
604
|
NSMutableSet<NSString *> *handledHomes = [NSMutableSet setWithObjects:
|
|
585
|
-
CCPetsResolvePath(defaultCodexHome), CCPetsResolvePath(defaultClaudeHome),
|
|
605
|
+
CCPetsResolvePath(defaultCodexHome), CCPetsResolvePath(defaultClaudeHome),
|
|
606
|
+
CCPetsRealPath(defaultAntigravityHome) ?: CCPetsResolvePath(defaultAntigravityHome), nil];
|
|
586
607
|
for (NSDictionary *profile in CCPetsProfiles()) {
|
|
587
608
|
NSString *home = CCPetsResolvePath(profile[@"home"]);
|
|
588
609
|
if (home.length == 0 || [handledHomes containsObject:home]) continue;
|
|
589
610
|
[handledHomes addObject:home];
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
611
|
+
NSString *provider = profile[@"provider"];
|
|
612
|
+
BOOL changed;
|
|
613
|
+
if ([provider isEqualToString:CCPetsProfileProviderAntigravity]) {
|
|
614
|
+
changed = !preparingInstall && RemoveAntigravityHooksForUninstall(profile, &failed);
|
|
615
|
+
} else if ([provider isEqualToString:CCPetsProfileProviderClaude]) {
|
|
616
|
+
changed = RemoveClaudeHooksAtHome(home, preparingInstall, &failed);
|
|
617
|
+
} else {
|
|
618
|
+
changed = RemoveCodexHooksAtHome(home, preparingInstall, &failed);
|
|
619
|
+
}
|
|
593
620
|
if (changed) {
|
|
594
621
|
profileChanged = YES;
|
|
595
622
|
CCPetsPrintLine(stdout, [NSString stringWithFormat:L(@"%1$@ the CC Pets hooks in %2$@."),
|
|
@@ -609,15 +636,18 @@ int UninstallIntegrations(BOOL preparingInstall, NSString *shellRC) {
|
|
|
609
636
|
CCPetsPrintLine(stdout, [NSString stringWithFormat:L(@"%1$@ the CC Pets hooks in %2$@ and restored the original status line."),
|
|
610
637
|
action, claudeSettingsPath]);
|
|
611
638
|
}
|
|
639
|
+
if (antigravityChanged) {
|
|
640
|
+
CCPetsPrintLine(stdout, [NSString stringWithFormat:L(@"Removed the CC Pets hooks in %@."), defaultAntigravityHome]);
|
|
641
|
+
}
|
|
612
642
|
if (shellChanged) {
|
|
613
643
|
CCPetsPrintLine(stdout, [NSString stringWithFormat:L(@"%1$@ the CC Pets shell integration in %2$@."), action, shellRC]);
|
|
614
644
|
}
|
|
615
645
|
if (shimChanged) {
|
|
616
646
|
NSString *directory = CCPetsEnvironmentValue(@"CC_PETS_SHIM_DIR") ?:
|
|
617
647
|
[CCPetsHomeDirectory() stringByAppendingPathComponent:@".cc-pets/shims"];
|
|
618
|
-
CCPetsPrintLine(stdout, [NSString stringWithFormat:L(@"%1$@ the codex / claude shims in %2$@."), action, directory]);
|
|
648
|
+
CCPetsPrintLine(stdout, [NSString stringWithFormat:L(@"%1$@ the codex / claude / agy shims in %2$@."), action, directory]);
|
|
619
649
|
}
|
|
620
|
-
if (!codexChanged && !claudeChanged && !profileChanged && !shellChanged && !shimChanged && !preparingInstall) {
|
|
650
|
+
if (!codexChanged && !claudeChanged && !antigravityChanged && !profileChanged && !shellChanged && !shimChanged && !preparingInstall && !failed) {
|
|
621
651
|
CCPetsPrintLine(stdout, L(@"No CC Pets integrations to remove."));
|
|
622
652
|
}
|
|
623
653
|
return failed ? 1 : 0;
|
|
@@ -7,7 +7,10 @@
|
|
|
7
7
|
static int BlockLaunch(NSString *provider, NSString *reason) {
|
|
8
8
|
CCPetsPrintLine(stderr, CCPetsInterpolate(
|
|
9
9
|
L(@"CC Pets blocked {provider}: {reason}"), @{@"provider": provider, @"reason": reason}));
|
|
10
|
-
|
|
10
|
+
NSString *hint = [provider isEqualToString:@"Antigravity"]
|
|
11
|
+
? L(@"Connect Shadowrocket to continue. You can turn off this check in Main menu → Settings → Launch Protection.")
|
|
12
|
+
: L(@"Connect Shadowrocket and select an exit outside mainland China / Hong Kong, then check routing and DNS settings. You can turn off this check in Main menu → Settings → Launch Protection.");
|
|
13
|
+
CCPetsPrintLine(stderr, hint);
|
|
11
14
|
return 1;
|
|
12
15
|
}
|
|
13
16
|
|
|
@@ -333,14 +336,21 @@ static BOOL HasLocalNetworkOverrides(NSString *provider, NSString *directory) {
|
|
|
333
336
|
}
|
|
334
337
|
|
|
335
338
|
int CCPetsLaunchPreflight(NSString *provider, NSArray<NSString *> *arguments) {
|
|
336
|
-
if (![@[@"claude", @"codex"] containsObject:provider]) {
|
|
337
|
-
CCPetsPrintLine(stderr, L(@"Launch check expects claude or
|
|
339
|
+
if (![@[@"claude", @"codex", @"agy"] containsObject:provider]) {
|
|
340
|
+
CCPetsPrintLine(stderr, L(@"Launch check expects claude, codex or agy."));
|
|
338
341
|
return 2;
|
|
339
342
|
}
|
|
340
343
|
if (!CCPetsPrefBool(CCPetsShadowrocketLaunchCheckKey)) return 0;
|
|
341
|
-
NSString *name = [provider isEqualToString:@"claude"] ? @"Claude"
|
|
342
|
-
|
|
344
|
+
NSString *name = [provider isEqualToString:@"claude"] ? @"Claude"
|
|
345
|
+
: ([provider isEqualToString:@"codex"] ? @"Codex" : @"Antigravity");
|
|
343
346
|
NSString *reason = nil;
|
|
347
|
+
if ([provider isEqualToString:@"agy"]) {
|
|
348
|
+
CCPetsPrintLine(stderr, L(@"CC Pets: checking Shadowrocket ..."));
|
|
349
|
+
if (!ShadowrocketConnected(&reason)) return BlockLaunch(name, reason);
|
|
350
|
+
CCPetsPrintLine(stderr, L(@"CC Pets: Shadowrocket is connected."));
|
|
351
|
+
return 0;
|
|
352
|
+
}
|
|
353
|
+
CCPetsPrintLine(stderr, L(@"CC Pets: checking Shadowrocket and service exit regions ..."));
|
|
344
354
|
if (!ShadowrocketConnected(&reason)) return BlockLaunch(name, reason);
|
|
345
355
|
|
|
346
356
|
NSString *profile = nil, *directory = NSFileManager.defaultManager.currentDirectoryPath;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
extern NSString *const CCPetsProfileProviderClaude;
|
|
4
4
|
extern NSString *const CCPetsProfileProviderCodex;
|
|
5
|
+
extern NSString *const CCPetsProfileProviderAntigravity;
|
|
5
6
|
extern NSNotificationName const CCPetsProfilesDidChangeNotification;
|
|
6
7
|
|
|
7
8
|
NSString *CCPetsProfilesPath(void);
|
|
@@ -31,7 +32,7 @@ BOOL CCPetsSetProfileNeedsRepair(NSString *profileID, BOOL needsRepair, NSString
|
|
|
31
32
|
|
|
32
33
|
// 只迁移已经存在 CC Pets 管理标记的默认配置,不扫描任何其他目录。
|
|
33
34
|
BOOL CCPetsMigrateManagedDefaultProfiles(NSString **errorMessage);
|
|
34
|
-
// 自动发现官方
|
|
35
|
+
// 自动发现官方 Claude、Codex 和 Antigravity CLI 的默认目录;不发现任何自定义 Home。
|
|
35
36
|
BOOL CCPetsEnsureOfficialDefaultProfiles(NSString **errorMessage);
|
|
36
37
|
|
|
37
38
|
// profile CLI:list/ensure-defaults/add/repair/remove。add/repair 会执行实际集成适配。
|