cc-pets 2.2.0 → 2.3.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 +5 -2
- package/CC_BRIDGE.zh-CN.md +4 -2
- package/CHANGELOG.md +85 -0
- package/CHANGELOG.zh-CN.md +85 -0
- package/CONTRIBUTING.md +28 -11
- package/CONTRIBUTING.zh-CN.md +23 -11
- package/README.md +127 -27
- package/README.zh-CN.md +104 -30
- package/Resources/zh-Hans.lproj/Localizable.strings +573 -17
- package/Sources/CCPets/{CCPetsAppDelegate+AgentEvents.m → App/CCPetsAppDelegate+AgentEvents.m} +15 -5
- package/Sources/CCPets/{CCPetsAppDelegate+AgentStatus.m → App/CCPetsAppDelegate+AgentStatus.m} +89 -31
- package/Sources/CCPets/{CCPetsAppDelegate+Bridge.m → App/CCPetsAppDelegate+Bridge.m} +35 -24
- package/Sources/CCPets/{CCPetsAppDelegate+Pets.m → App/CCPetsAppDelegate+Pets.m} +18 -4
- package/Sources/CCPets/{CCPetsAppDelegate+Private.h → App/CCPetsAppDelegate+Private.h} +90 -21
- package/Sources/CCPets/App/CCPetsAppDelegate+Profiles.m +238 -0
- package/Sources/CCPets/{CCPetsAppDelegate+Quota.m → App/CCPetsAppDelegate+Quota.m} +47 -32
- package/Sources/CCPets/App/CCPetsAppDelegate+Settings.m +269 -0
- package/Sources/CCPets/{CCPetsAppDelegate+Speech.m → App/CCPetsAppDelegate+Speech.m} +13 -7
- package/Sources/CCPets/{CCPetsAppDelegate+Update.m → App/CCPetsAppDelegate+Update.m} +71 -47
- package/Sources/CCPets/App/CCPetsAppDelegate+Workbench.m +139 -0
- package/Sources/CCPets/{CCPetsAppDelegate.h → App/CCPetsAppDelegate.h} +16 -2
- package/Sources/CCPets/{CCPetsAppDelegate.m → App/CCPetsAppDelegate.m} +110 -12
- package/Sources/CCPets/App/CCPetsOpenCommand.h +13 -0
- package/Sources/CCPets/App/CCPetsOpenCommand.m +99 -0
- package/Sources/CCPets/{main.m → App/main.m} +68 -1
- package/Sources/CCPets/{CCPetsBridge.h → Bridge/CCPetsBridge.h} +17 -4
- package/Sources/CCPets/{CCPetsBridge.m → Bridge/CCPetsBridge.m} +32 -17
- package/Sources/CCPets/Bridge/CCPetsBridgeCLI.h +10 -0
- package/Sources/CCPets/Bridge/CCPetsBridgeCLI.m +792 -0
- package/Sources/CCPets/Bridge/CCPetsBridgeCore.h +60 -0
- package/Sources/CCPets/Bridge/CCPetsBridgeCore.m +558 -0
- package/Sources/CCPets/Bridge/CCPetsBridgeSetup.h +24 -0
- package/Sources/CCPets/Bridge/CCPetsBridgeSetup.m +501 -0
- package/Sources/CCPets/Bridge/CCPetsBridgeStore.h +103 -0
- package/Sources/CCPets/Bridge/CCPetsBridgeStore.m +779 -0
- package/Sources/CCPets/Integrations/CCPetsCLISupport.h +75 -0
- package/Sources/CCPets/Integrations/CCPetsCLISupport.m +342 -0
- package/Sources/CCPets/Integrations/CCPetsEvents.h +15 -0
- package/Sources/CCPets/{CCPetsEvents.m → Integrations/CCPetsEvents.m} +23 -0
- package/Sources/CCPets/Integrations/CCPetsIntegrations.h +51 -0
- package/Sources/CCPets/Integrations/CCPetsIntegrations.m +662 -0
- package/Sources/CCPets/Integrations/CCPetsProfiles.h +38 -0
- package/Sources/CCPets/Integrations/CCPetsProfiles.m +516 -0
- package/Sources/CCPets/{CCPetsTerminalFocus.m → Integrations/CCPetsTerminalFocus.m} +42 -12
- package/Sources/CCPets/Pet/CCPetsImageLoader.h +5 -0
- package/Sources/CCPets/{CCPetsImageLoader.m → Pet/CCPetsImageLoader.m} +10 -2
- package/Sources/CCPets/Pet/CCPetsPetSize.h +10 -0
- package/Sources/CCPets/Pet/CCPetsPetSize.m +21 -0
- package/Sources/CCPets/Pet/CCPetsPetStore.h +12 -0
- package/Sources/CCPets/Pet/CCPetsPetStore.m +476 -0
- package/Sources/CCPets/{CCPetsPhrases.h → Pet/CCPetsPhrases.h} +18 -2
- package/Sources/CCPets/{CCPetsPhrases.m → Pet/CCPetsPhrases.m} +53 -22
- package/Sources/CCPets/{CCPetsPhrasesEditor.m → Pet/CCPetsPhrasesEditor.m} +42 -2
- package/Sources/CCPets/Pet/PetView+Interaction.m +207 -0
- package/Sources/CCPets/Pet/PetView+Menu.m +598 -0
- package/Sources/CCPets/Pet/PetView+MicroBehavior.m +234 -0
- package/Sources/CCPets/Pet/PetView+Private.h +81 -0
- package/Sources/CCPets/{PetView.h → Pet/PetView.h} +3 -5
- package/Sources/CCPets/Pet/PetView.m +635 -0
- package/Sources/CCPets/Support/CCPetsDoctor.h +25 -0
- package/Sources/CCPets/Support/CCPetsDoctor.m +632 -0
- package/Sources/CCPets/Support/CCPetsJSON.h +27 -0
- package/Sources/CCPets/Support/CCPetsJSON.m +397 -0
- package/Sources/CCPets/{CCPetsL10n.h → Support/CCPetsL10n.h} +3 -1
- package/Sources/CCPets/{CCPetsL10n.m → Support/CCPetsL10n.m} +30 -1
- package/Sources/CCPets/Support/CCPetsPreferences.h +31 -0
- package/Sources/CCPets/Support/CCPetsPreferences.m +85 -0
- package/Sources/CCPets/UI/CCPetsDiagnosticsPage.h +25 -0
- package/Sources/CCPets/UI/CCPetsDiagnosticsPage.m +440 -0
- package/Sources/CCPets/UI/CCPetsFormBuilder.h +42 -0
- package/Sources/CCPets/UI/CCPetsFormBuilder.m +268 -0
- package/Sources/CCPets/{CCPetsGlassView.h → UI/CCPetsGlassView.h} +5 -1
- package/Sources/CCPets/{CCPetsGlassView.m → UI/CCPetsGlassView.m} +25 -7
- package/Sources/CCPets/UI/CCPetsMainWindow.h +55 -0
- package/Sources/CCPets/UI/CCPetsMainWindow.m +730 -0
- package/Sources/CCPets/UI/CCPetsSettingsPage.h +62 -0
- package/Sources/CCPets/UI/CCPetsSettingsPage.m +917 -0
- package/Sources/CCPets/UI/CCPetsUIStyle.h +132 -0
- package/Sources/CCPets/UI/CCPetsUIStyle.m +816 -0
- package/Sources/CCPets/UI/CCPetsUsageChartView.h +15 -0
- package/Sources/CCPets/UI/CCPetsUsageChartView.m +284 -0
- package/Sources/CCPets/UI/CCPetsUsagePage.h +32 -0
- package/Sources/CCPets/UI/CCPetsUsagePage.m +717 -0
- package/Sources/CCPets/UI/CCPetsUsageShared.h +53 -0
- package/Sources/CCPets/UI/CCPetsUsageStore.m +120 -0
- package/Sources/CCPets/UI/CCPetsUsageWidgets.h +30 -0
- package/Sources/CCPets/UI/CCPetsUsageWidgets.m +201 -0
- package/Sources/CCPets/UI/CCPetsWorkbench.h +40 -0
- package/Sources/CCPets/UI/CCPetsWorkbenchPages.h +13 -0
- package/Sources/CCPets/UI/CCPetsWorkbenchPages.m +783 -0
- package/Sources/CCPets/{MenuChoiceRow.m → UI/MenuChoiceRow.m} +3 -0
- package/Sources/CCPets/UI/MenuPetSizeView.h +5 -0
- package/Sources/CCPets/UI/MenuPetSizeView.m +73 -0
- package/Sources/CCPets/{MenuToggleSwitch.m → UI/MenuToggleSwitch.m} +1 -0
- package/Sources/CCPets/{CCPetsCodexRateLimits.h → Usage/CCPetsCodexRateLimits.h} +1 -0
- package/Sources/CCPets/{CCPetsCodexRateLimits.m → Usage/CCPetsCodexRateLimits.m} +10 -3
- package/Sources/CCPets/{CCPetsQuotaHistory.h → Usage/CCPetsQuotaHistory.h} +3 -0
- package/Sources/CCPets/{CCPetsQuotaHistory.m → Usage/CCPetsQuotaHistory.m} +58 -0
- package/Sources/CCPets/Usage/CCPetsUsage+ClaudeReader.m +436 -0
- package/Sources/CCPets/Usage/CCPetsUsage+CodexReader.m +392 -0
- package/Sources/CCPets/Usage/CCPetsUsage+CodexSessions.m +484 -0
- package/Sources/CCPets/Usage/CCPetsUsage+Internal.h +96 -0
- package/Sources/CCPets/Usage/CCPetsUsage+Models.m +285 -0
- package/Sources/CCPets/Usage/CCPetsUsage+TokenTotals.m +655 -0
- package/Sources/CCPets/Usage/CCPetsUsage.h +57 -0
- package/Sources/CCPets/Usage/CCPetsUsage.m +225 -0
- package/Sources/CCPets/Usage/CCPetsUsageMode.h +10 -0
- package/Sources/CCPets/Usage/CCPetsUsageMode.m +163 -0
- package/Sources/CCPets/{CCPetsUsageMonitor.h → Usage/CCPetsUsageMonitor.h} +3 -0
- package/Sources/CCPets/{CCPetsUsageMonitor.m → Usage/CCPetsUsageMonitor.m} +163 -6
- package/Sources/CCPets/Usage/QuotaDashboardView+Primitives.m +328 -0
- package/Sources/CCPets/Usage/QuotaDashboardView+Private.h +103 -0
- package/Sources/CCPets/Usage/QuotaDashboardView+Rendering.m +616 -0
- package/Sources/CCPets/{QuotaDashboardView.h → Usage/QuotaDashboardView.h} +17 -0
- package/Sources/CCPets/Usage/QuotaDashboardView.m +587 -0
- package/THIRD_PARTY_NOTICES.md +1 -1
- package/THIRD_PARTY_NOTICES.zh-CN.md +1 -1
- package/bin/cc-pets +8 -6
- package/bin/claude-with-pet +10 -2
- package/bin/codex-with-pet +13 -5
- package/package.json +1 -1
- package/scripts/build.sh +7 -3
- package/scripts/i18n.zsh +9 -52
- package/scripts/install-app.sh +4 -0
- package/scripts/install-shell-integration.sh +17 -10
- package/scripts/uninstall-shell-integration.sh +6 -1
- package/Sources/CCPets/CCPetsAppDelegate+Settings.m +0 -226
- package/Sources/CCPets/CCPetsEvents.h +0 -10
- package/Sources/CCPets/CCPetsImageLoader.h +0 -4
- package/Sources/CCPets/CCPetsUsage.h +0 -36
- package/Sources/CCPets/CCPetsUsage.m +0 -2069
- package/Sources/CCPets/PetView.m +0 -1806
- package/Sources/CCPets/QuotaDashboardView.m +0 -1145
- package/scripts/bridge/cli.mjs +0 -237
- package/scripts/bridge/core.mjs +0 -228
- package/scripts/bridge/hook.mjs +0 -150
- package/scripts/bridge/install.mjs +0 -311
- package/scripts/bridge/mcp-server.mjs +0 -308
- package/scripts/bridge/options.mjs +0 -87
- package/scripts/bridge/process.mjs +0 -151
- package/scripts/bridge/reservations.mjs +0 -248
- package/scripts/bridge/store.mjs +0 -433
- package/scripts/bridge/watch.mjs +0 -69
- package/scripts/check-l10n.mjs +0 -168
- package/scripts/configure-updater.mjs +0 -43
- package/scripts/detect-cli.mjs +0 -68
- package/scripts/doctor.mjs +0 -470
- package/scripts/i18n.mjs +0 -122
- package/scripts/install-claude-hooks.mjs +0 -253
- package/scripts/install-codex-hooks.mjs +0 -78
- package/scripts/integration-markers.mjs +0 -51
- package/scripts/locales/zh-Hans.json +0 -366
- package/scripts/pet-store.mjs +0 -415
- package/scripts/uninstall-integrations.mjs +0 -205
- /package/Sources/CCPets/{CCPetsVersion.h → App/CCPetsVersion.h} +0 -0
- /package/Sources/CCPets/{CCPetsVersion.m → App/CCPetsVersion.m} +0 -0
- /package/Sources/CCPets/{CCPetsTerminalFocus.h → Integrations/CCPetsTerminalFocus.h} +0 -0
- /package/Sources/CCPets/{CCPetsPhrasesEditor.h → Pet/CCPetsPhrasesEditor.h} +0 -0
- /package/Sources/CCPets/{CCPetsPreviews.h → Pet/CCPetsPreviews.h} +0 -0
- /package/Sources/CCPets/{CCPetsPreviews.m → Pet/CCPetsPreviews.m} +0 -0
- /package/Sources/CCPets/Resources/{/351/273/230/350/256/244.webp" → ByteMochi.webp} +0 -0
- /package/Sources/CCPets/{CCPetsCleanup.h → Support/CCPetsCleanup.h} +0 -0
- /package/Sources/CCPets/{CCPetsCleanup.m → Support/CCPetsCleanup.m} +0 -0
- /package/Sources/CCPets/{CCPetsPaths.h → Support/CCPetsPaths.h} +0 -0
- /package/Sources/CCPets/{CCPetsPaths.m → Support/CCPetsPaths.m} +0 -0
- /package/Sources/CCPets/{CCPetsSystemMonitor.h → Support/CCPetsSystemMonitor.h} +0 -0
- /package/Sources/CCPets/{CCPetsSystemMonitor.m → Support/CCPetsSystemMonitor.m} +0 -0
- /package/Sources/CCPets/{CCPetsGlassMenu.h → UI/CCPetsGlassMenu.h} +0 -0
- /package/Sources/CCPets/{CCPetsGlassMenu.m → UI/CCPetsGlassMenu.m} +0 -0
- /package/Sources/CCPets/{MenuChoiceRow.h → UI/MenuChoiceRow.h} +0 -0
- /package/Sources/CCPets/{MenuHintView.h → UI/MenuHintView.h} +0 -0
- /package/Sources/CCPets/{MenuHintView.m → UI/MenuHintView.m} +0 -0
- /package/Sources/CCPets/{MenuToggleSwitch.h → UI/MenuToggleSwitch.h} +0 -0
|
@@ -6,6 +6,9 @@
|
|
|
6
6
|
target:(id)target action:(SEL)action width:(CGFloat)width {
|
|
7
7
|
// item 要有 action 才会被菜单高亮。鼠标点击由行视图自己处理(菜单不关);
|
|
8
8
|
// 用键盘选中后按回车走的是这个 action,行为与点击一致,菜单照常关闭。
|
|
9
|
+
// 所有设置单选行统一按文案撑宽,避免英文标题被截断。
|
|
10
|
+
width = MAX(width, ceil([title sizeWithAttributes:
|
|
11
|
+
@{NSFontAttributeName: [NSFont menuFontOfSize:13]}].width) + 42);
|
|
9
12
|
NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:title action:@selector(chooseFromMenuItem:)
|
|
10
13
|
keyEquivalent:@""];
|
|
11
14
|
MenuChoiceRowView *row = [[MenuChoiceRowView alloc] initWithFrame:NSMakeRect(0, 0, width, 24)];
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
#import "MenuPetSizeView.h"
|
|
2
|
+
#import "CCPetsPetSize.h"
|
|
3
|
+
#import "CCPetsL10n.h"
|
|
4
|
+
|
|
5
|
+
@interface MenuPetSizeView ()
|
|
6
|
+
@property NSSlider *slider;
|
|
7
|
+
@property NSTextField *percentage;
|
|
8
|
+
@property(weak) id target;
|
|
9
|
+
@property SEL action;
|
|
10
|
+
@end
|
|
11
|
+
|
|
12
|
+
@implementation MenuPetSizeView
|
|
13
|
+
- (instancetype)initWithScale:(CGFloat)scale target:(id)target action:(SEL)action {
|
|
14
|
+
CGFloat resetWidth = ceil([L(@"Reset Size") sizeWithAttributes:
|
|
15
|
+
@{NSFontAttributeName: [NSFont menuFontOfSize:12]}].width) + 24;
|
|
16
|
+
CGFloat width = MAX(220, resetWidth + 94);
|
|
17
|
+
self = [super initWithFrame:NSMakeRect(0, 0, width, 92)];
|
|
18
|
+
if (!self) return nil;
|
|
19
|
+
self.autoresizingMask = NSViewWidthSizable;
|
|
20
|
+
self.target = target;
|
|
21
|
+
self.action = action;
|
|
22
|
+
|
|
23
|
+
self.percentage = [NSTextField labelWithString:@""];
|
|
24
|
+
self.percentage.frame = NSMakeRect(14, 65, width - 28, 18);
|
|
25
|
+
self.percentage.font = [NSFont monospacedDigitSystemFontOfSize:13 weight:NSFontWeightMedium];
|
|
26
|
+
self.percentage.alignment = NSTextAlignmentCenter;
|
|
27
|
+
self.percentage.autoresizingMask = NSViewWidthSizable;
|
|
28
|
+
[self addSubview:self.percentage];
|
|
29
|
+
|
|
30
|
+
self.slider = [NSSlider sliderWithValue:scale minValue:CCPetsPetMinimumScale
|
|
31
|
+
maxValue:CCPetsPetMaximumScale target:self action:@selector(sliderChanged:)];
|
|
32
|
+
self.slider.frame = NSMakeRect(14, 37, width - 28, 24);
|
|
33
|
+
self.slider.continuous = YES;
|
|
34
|
+
self.slider.autoresizingMask = NSViewWidthSizable;
|
|
35
|
+
self.slider.accessibilityLabel = L(@"Pet Size");
|
|
36
|
+
[self addSubview:self.slider];
|
|
37
|
+
|
|
38
|
+
NSTextField *minimum = [NSTextField labelWithString:@"50%"];
|
|
39
|
+
minimum.frame = NSMakeRect(14, 10, 44, 16);
|
|
40
|
+
minimum.font = [NSFont menuFontOfSize:11];
|
|
41
|
+
minimum.textColor = NSColor.secondaryLabelColor;
|
|
42
|
+
[self addSubview:minimum];
|
|
43
|
+
NSTextField *maximum = [NSTextField labelWithString:@"200%"];
|
|
44
|
+
maximum.frame = NSMakeRect(width - 58, 10, 44, 16);
|
|
45
|
+
maximum.font = minimum.font;
|
|
46
|
+
maximum.textColor = minimum.textColor;
|
|
47
|
+
maximum.alignment = NSTextAlignmentRight;
|
|
48
|
+
maximum.autoresizingMask = NSViewMinXMargin;
|
|
49
|
+
[self addSubview:maximum];
|
|
50
|
+
|
|
51
|
+
NSButton *reset = [NSButton buttonWithTitle:L(@"Reset Size") target:self action:@selector(resetSize:)];
|
|
52
|
+
reset.bezelStyle = NSBezelStyleRounded;
|
|
53
|
+
reset.font = [NSFont menuFontOfSize:12];
|
|
54
|
+
reset.frame = NSMakeRect((width - resetWidth) / 2, 5, resetWidth, 26);
|
|
55
|
+
reset.autoresizingMask = NSViewMinXMargin | NSViewMaxXMargin;
|
|
56
|
+
[self addSubview:reset];
|
|
57
|
+
[self updatePercentage];
|
|
58
|
+
return self;
|
|
59
|
+
}
|
|
60
|
+
- (void)updatePercentage {
|
|
61
|
+
self.percentage.stringValue = [NSString stringWithFormat:@"%.0f%%", self.slider.doubleValue * 100];
|
|
62
|
+
}
|
|
63
|
+
- (void)sliderChanged:(NSSlider *)sender {
|
|
64
|
+
[NSApp sendAction:self.action to:self.target from:sender];
|
|
65
|
+
[self updatePercentage];
|
|
66
|
+
}
|
|
67
|
+
- (void)resetSize:(id)sender {
|
|
68
|
+
self.slider.doubleValue = 1.0;
|
|
69
|
+
[self sliderChanged:self.slider];
|
|
70
|
+
}
|
|
71
|
+
// 消费行内空白处的点击,菜单保持打开以便继续调整。
|
|
72
|
+
- (void)mouseDown:(NSEvent *)event {}
|
|
73
|
+
@end
|
|
@@ -73,6 +73,7 @@
|
|
|
73
73
|
NSColor *pillColor = usesAPI
|
|
74
74
|
? [NSColor colorWithRed:0.12 green:0.52 blue:0.96 alpha:self.highlighted ? 0.78 : 0.96]
|
|
75
75
|
: [NSColor colorWithRed:0.20 green:0.68 blue:0.36 alpha:self.highlighted ? 0.78 : 0.96];
|
|
76
|
+
if (!self.enabled) pillColor = [pillColor colorWithAlphaComponent:0.45];
|
|
76
77
|
[pillColor setFill];
|
|
77
78
|
NSBezierPath *pillPath = [NSBezierPath bezierPathWithRoundedRect:pill
|
|
78
79
|
xRadius:NSHeight(pill) / 2.0 yRadius:NSHeight(pill) / 2.0];
|
|
@@ -138,7 +138,8 @@ static NSString *CodexAppServerExecutablePath(void) {
|
|
|
138
138
|
return nil;
|
|
139
139
|
}
|
|
140
140
|
|
|
141
|
-
static NSDictionary<NSString *, NSString *> *CodexAppServerEnvironment(NSString *executablePath
|
|
141
|
+
static NSDictionary<NSString *, NSString *> *CodexAppServerEnvironment(NSString *executablePath,
|
|
142
|
+
NSString *codexHome) {
|
|
142
143
|
NSMutableDictionary<NSString *, NSString *> *environment =
|
|
143
144
|
[NSProcessInfo.processInfo.environment mutableCopy];
|
|
144
145
|
NSMutableOrderedSet<NSString *> *paths = [NSMutableOrderedSet orderedSet];
|
|
@@ -151,7 +152,7 @@ static NSDictionary<NSString *, NSString *> *CodexAppServerEnvironment(NSString
|
|
|
151
152
|
}
|
|
152
153
|
environment[@"PATH"] = [paths.array componentsJoinedByString:@":"];
|
|
153
154
|
// 与会话扫描使用同一份配置目录,避免备用 CODEX_HOME 下的账号被错读成默认账号。
|
|
154
|
-
environment[@"CODEX_HOME"] = DefaultCodexHomeDirectory();
|
|
155
|
+
environment[@"CODEX_HOME"] = codexHome.length > 0 ? codexHome : DefaultCodexHomeDirectory();
|
|
155
156
|
return environment;
|
|
156
157
|
}
|
|
157
158
|
|
|
@@ -164,17 +165,23 @@ static NSDictionary<NSString *, NSString *> *CodexAppServerEnvironment(NSString
|
|
|
164
165
|
@property NSInteger nextRequestID;
|
|
165
166
|
@property NSInteger pendingRequestID;
|
|
166
167
|
@property BOOL stopped;
|
|
168
|
+
@property(copy) NSString *codexHome;
|
|
167
169
|
@end
|
|
168
170
|
|
|
169
171
|
@implementation CCPetsCodexRateLimitsReader
|
|
170
172
|
|
|
171
173
|
- (instancetype)init {
|
|
174
|
+
return [self initWithCodexHome:DefaultCodexHomeDirectory()];
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
- (instancetype)initWithCodexHome:(NSString *)codexHome {
|
|
172
178
|
if ((self = [super init])) {
|
|
173
179
|
_queue = dispatch_queue_create("com.universewang.cc-pets.codex-rate-limits",
|
|
174
180
|
DISPATCH_QUEUE_SERIAL);
|
|
175
181
|
dispatch_queue_set_specific(_queue, &CodexRateLimitsQueueKey, (__bridge void *)self, NULL);
|
|
176
182
|
_partialOutput = [NSMutableData data];
|
|
177
183
|
_nextRequestID = 2; // 1 留给 initialize。
|
|
184
|
+
_codexHome = [codexHome.stringByStandardizingPath copy];
|
|
178
185
|
}
|
|
179
186
|
return self;
|
|
180
187
|
}
|
|
@@ -220,7 +227,7 @@ static NSDictionary<NSString *, NSString *> *CodexAppServerEnvironment(NSString
|
|
|
220
227
|
NSPipe *outputPipe = [NSPipe pipe];
|
|
221
228
|
task.executableURL = [NSURL fileURLWithPath:path];
|
|
222
229
|
task.arguments = @[@"app-server", @"--stdio"];
|
|
223
|
-
task.environment = CodexAppServerEnvironment(path);
|
|
230
|
+
task.environment = CodexAppServerEnvironment(path, self.codexHome);
|
|
224
231
|
task.currentDirectoryURL = [NSURL fileURLWithPath:NSHomeDirectory()];
|
|
225
232
|
task.standardInput = inputPipe;
|
|
226
233
|
task.standardOutput = outputPipe;
|
|
@@ -6,3 +6,6 @@ NSDictionary *QuotaHistoryDocument(void);
|
|
|
6
6
|
NSDictionary *RecordQuotaHistory(NSDictionary *codexUsage, NSDictionary *claudeUsage);
|
|
7
7
|
// 每个点保留 timestamp 与 weekRemaining,绘图层才能按真实时间轴展示缺口和重置。
|
|
8
8
|
NSArray<NSDictionary *> *QuotaHistorySeries(NSDictionary *document, NSString *provider);
|
|
9
|
+
NSDictionary *RecordProfileQuotaHistory(NSDictionary<NSString *, NSDictionary *> *profileUsages,
|
|
10
|
+
NSArray<NSDictionary *> *profiles);
|
|
11
|
+
NSArray<NSDictionary *> *QuotaHistorySeriesForProfile(NSDictionary *document, NSString *profileID);
|
|
@@ -97,3 +97,61 @@ NSArray<NSDictionary *> *QuotaHistorySeries(NSDictionary *document, NSString *pr
|
|
|
97
97
|
}
|
|
98
98
|
return series;
|
|
99
99
|
}
|
|
100
|
+
|
|
101
|
+
NSDictionary *RecordProfileQuotaHistory(NSDictionary<NSString *, NSDictionary *> *profileUsages,
|
|
102
|
+
NSArray<NSDictionary *> *profiles) {
|
|
103
|
+
if (profileUsages.count == 0 || profiles.count == 0) return QuotaHistoryDocument();
|
|
104
|
+
NSDictionary *document = QuotaHistoryDocument();
|
|
105
|
+
NSTimeInterval now = NSDate.date.timeIntervalSince1970;
|
|
106
|
+
NSTimeInterval cutoff = now - 7 * 24 * 60 * 60;
|
|
107
|
+
NSMutableArray *samples = [NSMutableArray array];
|
|
108
|
+
for (NSDictionary *sample in document[@"samples"]) {
|
|
109
|
+
if ([sample isKindOfClass:NSDictionary.class] && [sample[@"timestamp"] doubleValue] >= cutoff) {
|
|
110
|
+
[samples addObject:[sample mutableCopy]];
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
NSMutableDictionary *profileSamples = [NSMutableDictionary dictionary];
|
|
114
|
+
for (NSDictionary *profile in profiles) {
|
|
115
|
+
NSString *profileID = profile[@"id"];
|
|
116
|
+
NSDictionary *usage = profileUsages[profileID];
|
|
117
|
+
NSString *usedKey = [profile[@"provider"] isEqualToString:@"codex"]
|
|
118
|
+
? @"used_percent" : @"used_percentage";
|
|
119
|
+
NSDictionary *sample = HistoryProviderSample(usage, usedKey);
|
|
120
|
+
if (profileID.length > 0 && sample.count > 0) profileSamples[profileID] = sample;
|
|
121
|
+
}
|
|
122
|
+
if (profileSamples.count == 0) return document;
|
|
123
|
+
NSMutableDictionary *last = [samples.lastObject isKindOfClass:NSDictionary.class]
|
|
124
|
+
? [samples.lastObject mutableCopy] : nil;
|
|
125
|
+
if (last && now - [last[@"timestamp"] doubleValue] < 15 * 60) {
|
|
126
|
+
NSMutableDictionary *merged = [last[@"profiles"] isKindOfClass:NSDictionary.class]
|
|
127
|
+
? [last[@"profiles"] mutableCopy] : [NSMutableDictionary dictionary];
|
|
128
|
+
[merged addEntriesFromDictionary:profileSamples];
|
|
129
|
+
last[@"profiles"] = merged;
|
|
130
|
+
samples[samples.count - 1] = last;
|
|
131
|
+
} else {
|
|
132
|
+
[samples addObject:[@{@"timestamp": @(now), @"profiles": profileSamples} mutableCopy]];
|
|
133
|
+
}
|
|
134
|
+
if (samples.count > 672) [samples removeObjectsInRange:NSMakeRange(0, samples.count - 672)];
|
|
135
|
+
NSDictionary *updated = @{@"schemaVersion": @1, @"samples": samples};
|
|
136
|
+
NSData *json = [NSJSONSerialization dataWithJSONObject:updated options:NSJSONWritingPrettyPrinted error:nil];
|
|
137
|
+
if ([json writeToFile:QuotaHistoryPath() options:NSDataWritingAtomic error:nil]) {
|
|
138
|
+
chmod(QuotaHistoryPath().fileSystemRepresentation, S_IRUSR | S_IWUSR);
|
|
139
|
+
}
|
|
140
|
+
return updated;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
NSArray<NSDictionary *> *QuotaHistorySeriesForProfile(NSDictionary *document, NSString *profileID) {
|
|
144
|
+
NSMutableArray<NSDictionary *> *series = [NSMutableArray array];
|
|
145
|
+
for (NSDictionary *sample in document[@"samples"]) {
|
|
146
|
+
NSDictionary *profiles = [sample[@"profiles"] isKindOfClass:NSDictionary.class]
|
|
147
|
+
? sample[@"profiles"] : nil;
|
|
148
|
+
NSDictionary *profile = [profiles[profileID] isKindOfClass:NSDictionary.class]
|
|
149
|
+
? profiles[profileID] : nil;
|
|
150
|
+
NSNumber *timestamp = [sample[@"timestamp"] isKindOfClass:NSNumber.class]
|
|
151
|
+
? sample[@"timestamp"] : nil;
|
|
152
|
+
NSNumber *remaining = [profile[@"weekRemaining"] isKindOfClass:NSNumber.class]
|
|
153
|
+
? profile[@"weekRemaining"] : nil;
|
|
154
|
+
if (timestamp && remaining) [series addObject:@{@"timestamp": timestamp, @"remaining": remaining}];
|
|
155
|
+
}
|
|
156
|
+
return series;
|
|
157
|
+
}
|