cc-pets 0.1.1 → 0.2.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/CHANGELOG.md +4 -3
- package/README.md +29 -15
- package/Resources/AppIcon.icns +0 -0
- package/Resources/Info.plist +7 -5
- package/Sources/{CodexPet → CCPets}/main.m +17 -7
- package/bin/{codex-pet → cc-pets} +2 -2
- package/bin/claude-statusline-with-pet +1 -1
- package/bin/claude-with-pet +3 -3
- package/bin/codex-with-pet +3 -3
- package/package.json +5 -4
- package/scripts/build.sh +7 -6
- package/scripts/install-claude-hooks.mjs +21 -8
- package/scripts/install-codex-hooks.mjs +14 -6
- package/scripts/install-shell-integration.sh +22 -11
- package/scripts/uninstall-integrations.mjs +45 -11
- package/scripts/uninstall-shell-integration.sh +8 -3
- /package/Sources/{CodexPet → CCPets}/Resources/ByteMochi.png +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,17 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
本项目遵循语义化版本号。
|
|
4
4
|
|
|
5
|
-
## [
|
|
5
|
+
## [0.2.0] - 2026-07-22
|
|
6
6
|
|
|
7
7
|
- 项目和 npm 包更名为 CC Pets。
|
|
8
|
+
- 新版安装器会自动清理旧版 `codex-pet` Hooks、Claude status line 包装和 shell aliases。
|
|
9
|
+
- 旧版迁移只匹配 CC Pets 的完整命令签名,避免误删复用相似标记的其他工具配置。
|
|
8
10
|
- 新增原创默认桌宠 ByteMochi,移除公开包中的第三方角色素材。
|
|
9
11
|
- 新增 Codex CLI 与 Claude Code CLI 共存、Agent 动画和额度面板。
|
|
10
12
|
- 新增 PetDex 外部素材动态扫描与桌宠切换。
|
|
11
|
-
- 新增 `
|
|
13
|
+
- 新增 `cc-pets uninstall`,可移除本项目 Hooks、恢复 Claude status line 并清理 shell aliases。
|
|
12
14
|
- 构建支持 PNG、WebP 和空素材目录。
|
|
13
15
|
- 补充隐私、安全、贡献和第三方素材说明。
|
|
14
16
|
|
|
15
17
|
## [0.1.0] - 2026-07-21
|
|
16
18
|
|
|
17
19
|
- 首个可用版本。
|
|
18
|
-
|
package/README.md
CHANGED
|
@@ -36,7 +36,7 @@ Agent 动画分别由 Codex Hooks 和 Claude Code Hooks 驱动。首次安装或
|
|
|
36
36
|
Claude Code Hook 会合并到 `~/.claude/settings.json`,现有的 `env`、`model`、`statusLine`
|
|
37
37
|
以及其他 Hooks 都会保留。Claude status line 会通过透明转发器继续执行原命令,同时将官方
|
|
38
38
|
`rate_limits` 字段提供给桌宠。
|
|
39
|
-
执行 `
|
|
39
|
+
执行 `cc-pets install` 会重新构建应用、安装或更新两套 Hooks,并配置 shell alias;如果旧版桌宠正在运行,
|
|
40
40
|
安装器会自动重启桌宠,使新版本生效。
|
|
41
41
|
|
|
42
42
|
### 鼠标互动
|
|
@@ -91,7 +91,7 @@ Claude Code Hook 会合并到 `~/.claude/settings.json`,现有的 `env`、`mod
|
|
|
91
91
|
|
|
92
92
|
```bash
|
|
93
93
|
npm install -g cc-pets
|
|
94
|
-
|
|
94
|
+
cc-pets install
|
|
95
95
|
source ~/.zshrc
|
|
96
96
|
codex
|
|
97
97
|
# 或
|
|
@@ -104,17 +104,31 @@ claude
|
|
|
104
104
|
git clone https://gitee.com/wangxinyusqn/cc-pets.git
|
|
105
105
|
cd cc-pets
|
|
106
106
|
npm install -g .
|
|
107
|
-
|
|
107
|
+
cc-pets install
|
|
108
108
|
source ~/.zshrc
|
|
109
109
|
codex
|
|
110
110
|
# 或
|
|
111
111
|
claude
|
|
112
112
|
```
|
|
113
113
|
|
|
114
|
-
两种方式都会安装 `
|
|
115
|
-
`
|
|
114
|
+
两种方式都会安装 `cc-pets`、`codex-with-pet` 和 `claude-with-pet`。
|
|
115
|
+
`cc-pets install` 是桌宠初始化命令:它会构建原生应用、安装两套 Agent Hooks,并向 `~/.zshrc` 追加带明确标记的
|
|
116
116
|
`codex` 与 `claude` alias,不会覆盖真实的 CLI 二进制。
|
|
117
117
|
|
|
118
|
+
### 从旧版升级
|
|
119
|
+
|
|
120
|
+
从使用 `codex-pet` 命令的旧版升级时,直接安装新版并重新执行初始化即可:
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
npm install -g cc-pets@latest
|
|
124
|
+
cc-pets install
|
|
125
|
+
source ~/.zshrc
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
新版安装器会自动移除旧版 Hooks、恢复并重新接入 Claude status line,同时替换旧的 shell alias 标记,
|
|
129
|
+
不需要先运行已经移除的 `codex-pet uninstall`。迁移仅识别 CC Pets 的完整命令签名,不会按
|
|
130
|
+
`codex`、`claude` 或单个环境变量名称泛化删除其他工具配置。
|
|
131
|
+
|
|
118
132
|
如果真实 Codex CLI 不在当前 `PATH`,可以显式指定:
|
|
119
133
|
|
|
120
134
|
```bash
|
|
@@ -134,22 +148,22 @@ export CLAUDE_REAL_BIN=/absolute/path/to/claude
|
|
|
134
148
|
|
|
135
149
|
```bash
|
|
136
150
|
# 构建原生程序
|
|
137
|
-
|
|
151
|
+
cc-pets build
|
|
138
152
|
|
|
139
153
|
# 独立启动桌宠;独立启动时不会随 CLI 自动退出
|
|
140
|
-
|
|
154
|
+
cc-pets
|
|
141
155
|
|
|
142
156
|
# 前台运行,便于调试
|
|
143
|
-
|
|
157
|
+
cc-pets --foreground
|
|
144
158
|
|
|
145
159
|
# 查看当前解析到的 Codex 额度
|
|
146
|
-
|
|
160
|
+
cc-pets --status
|
|
147
161
|
|
|
148
162
|
# 安装/更新 Hooks、shell alias,并让已运行桌宠加载新版本
|
|
149
|
-
|
|
163
|
+
cc-pets install
|
|
150
164
|
|
|
151
165
|
# 安全移除 Hooks、恢复 Claude status line,并清理 shell alias
|
|
152
|
-
|
|
166
|
+
cc-pets uninstall
|
|
153
167
|
|
|
154
168
|
# 启动桌宠后进入 Codex CLI
|
|
155
169
|
codex-with-pet
|
|
@@ -184,12 +198,12 @@ Claude.ai Pro/Max 订阅账号,并在会话完成首次 API 响应后出现;
|
|
|
184
198
|
|
|
185
199
|
```bash
|
|
186
200
|
./scripts/build.sh
|
|
187
|
-
./.build/release/
|
|
201
|
+
./.build/release/cc-pets --status
|
|
188
202
|
```
|
|
189
203
|
|
|
190
204
|
## 素材与版权
|
|
191
205
|
|
|
192
|
-
桌宠素材统一放在 `Sources/
|
|
206
|
+
桌宠素材统一放在 `Sources/CCPets/Resources/`,程序会自动收集其中的 `.webp` 和 `.png` 文件。
|
|
193
207
|
素材需要使用 `1536×1872` 画布,按 `8×9` 网格切分为 `192×208` 单元格,并遵循相同的帧数和动作行协议。
|
|
194
208
|
角色可能属于受版权保护的作品;公开
|
|
195
209
|
发布本项目或 npm 包前,请确认已经获得素材的使用和分发授权,或替换为原创、可公开分发的素材。
|
|
@@ -211,14 +225,14 @@ npx petdex install <slug>
|
|
|
211
225
|
- Claude 额度只从 Claude Code 传给本机 status line 的 `rate_limits` 字段读取。
|
|
212
226
|
- Agent Hooks 只向当前用户的临时目录写入桌宠事件和额度缓存。
|
|
213
227
|
- 项目不上传会话内容、额度、凭据或使用统计,也不包含遥测服务。
|
|
214
|
-
- 右键“退出桌宠”或执行 `
|
|
228
|
+
- 右键“退出桌宠”或执行 `cc-pets uninstall` 后,不会继续运行后台守护进程。
|
|
215
229
|
|
|
216
230
|
## 卸载
|
|
217
231
|
|
|
218
232
|
先在 npm 包仍然存在时移除集成:
|
|
219
233
|
|
|
220
234
|
```bash
|
|
221
|
-
|
|
235
|
+
cc-pets uninstall
|
|
222
236
|
source ~/.zshrc
|
|
223
237
|
npm uninstall -g cc-pets
|
|
224
238
|
```
|
|
Binary file
|
package/Resources/Info.plist
CHANGED
|
@@ -5,19 +5,21 @@
|
|
|
5
5
|
<key>CFBundleDisplayName</key>
|
|
6
6
|
<string>CC Pets</string>
|
|
7
7
|
<key>CFBundleExecutable</key>
|
|
8
|
-
<string>
|
|
8
|
+
<string>cc-pets</string>
|
|
9
9
|
<key>CFBundleIdentifier</key>
|
|
10
|
-
<string>com.universewang.
|
|
10
|
+
<string>com.universewang.cc-pets</string>
|
|
11
|
+
<key>CFBundleIconFile</key>
|
|
12
|
+
<string>AppIcon</string>
|
|
11
13
|
<key>CFBundleInfoDictionaryVersion</key>
|
|
12
14
|
<string>6.0</string>
|
|
13
15
|
<key>CFBundleName</key>
|
|
14
|
-
<string>
|
|
16
|
+
<string>CC Pets</string>
|
|
15
17
|
<key>CFBundlePackageType</key>
|
|
16
18
|
<string>APPL</string>
|
|
17
19
|
<key>CFBundleShortVersionString</key>
|
|
18
|
-
<string>0.
|
|
20
|
+
<string>0.2.0</string>
|
|
19
21
|
<key>CFBundleVersion</key>
|
|
20
|
-
<string>
|
|
22
|
+
<string>2</string>
|
|
21
23
|
<key>LSMinimumSystemVersion</key>
|
|
22
24
|
<string>13.0</string>
|
|
23
25
|
<key>LSUIElement</key>
|
|
@@ -4,18 +4,18 @@
|
|
|
4
4
|
#import <signal.h>
|
|
5
5
|
|
|
6
6
|
static NSString *PetStateDirectory(void) {
|
|
7
|
-
NSString *override = NSProcessInfo.processInfo.environment[@"
|
|
7
|
+
NSString *override = NSProcessInfo.processInfo.environment[@"CC_PETS_STATE_DIR"];
|
|
8
8
|
if (override.length > 0) return override.stringByStandardizingPath;
|
|
9
9
|
return NSTemporaryDirectory();
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
static NSString *AgentEventPath(void) {
|
|
13
|
-
NSString *name = [NSString stringWithFormat:@"
|
|
13
|
+
NSString *name = [NSString stringWithFormat:@"cc-pets-%u-agent-events.ndjson", getuid()];
|
|
14
14
|
return [PetStateDirectory() stringByAppendingPathComponent:name];
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
static NSString *ClaudeUsagePath(void) {
|
|
18
|
-
NSString *name = [NSString stringWithFormat:@"
|
|
18
|
+
NSString *name = [NSString stringWithFormat:@"cc-pets-%u-claude-usage.json", getuid()];
|
|
19
19
|
return [PetStateDirectory() stringByAppendingPathComponent:name];
|
|
20
20
|
}
|
|
21
21
|
|
|
@@ -831,7 +831,17 @@ static int RenderQuotaDashboard(NSString *path) {
|
|
|
831
831
|
[NSApp terminate:nil];
|
|
832
832
|
return;
|
|
833
833
|
}
|
|
834
|
-
|
|
834
|
+
NSUserDefaults *defaults = NSUserDefaults.standardUserDefaults;
|
|
835
|
+
NSString *selected = [defaults stringForKey:@"CCPetsSelectedSprite"];
|
|
836
|
+
if (selected.length == 0) {
|
|
837
|
+
NSDictionary *legacyDefaults = [defaults persistentDomainForName:@"com.universewang.codex-pet"];
|
|
838
|
+
NSString *legacySelected = [legacyDefaults[@"CodexPetSelectedSprite"] isKindOfClass:NSString.class]
|
|
839
|
+
? legacyDefaults[@"CodexPetSelectedSprite"] : nil;
|
|
840
|
+
if (legacySelected.length > 0) {
|
|
841
|
+
selected = legacySelected;
|
|
842
|
+
[defaults setObject:selected forKey:@"CCPetsSelectedSprite"];
|
|
843
|
+
}
|
|
844
|
+
}
|
|
835
845
|
if (selected.length > 0 && ![selected containsString:@":"]) selected = [@"builtin:" stringByAppendingString:selected];
|
|
836
846
|
NSDictionary *selectedOption = [self petOptionWithID:selected inOptions:petOptions] ?: petOptions.firstObject;
|
|
837
847
|
selected = selectedOption[@"id"];
|
|
@@ -962,7 +972,7 @@ static int RenderQuotaDashboard(NSString *path) {
|
|
|
962
972
|
NSImage *image = [[NSImage alloc] initWithContentsOfFile:option[@"path"]];
|
|
963
973
|
if (!image) return;
|
|
964
974
|
[self.petView applySheet:image petID:petID];
|
|
965
|
-
[NSUserDefaults.standardUserDefaults setObject:petID forKey:@"
|
|
975
|
+
[NSUserDefaults.standardUserDefaults setObject:petID forKey:@"CCPetsSelectedSprite"];
|
|
966
976
|
}
|
|
967
977
|
- (void)prepareAgentEventReader {
|
|
968
978
|
NSString *path = AgentEventPath();
|
|
@@ -1012,7 +1022,7 @@ static int RenderQuotaDashboard(NSString *path) {
|
|
|
1012
1022
|
[self processAgentEventData:data ignoreFirstPartial:NO recentOnly:NO];
|
|
1013
1023
|
}
|
|
1014
1024
|
- (void)refreshClientLifecycle:(id)sender {
|
|
1015
|
-
NSString *clientName = [NSString stringWithFormat:@"
|
|
1025
|
+
NSString *clientName = [NSString stringWithFormat:@"cc-pets-%u-clients", getuid()];
|
|
1016
1026
|
NSString *clientDirectory = [PetStateDirectory() stringByAppendingPathComponent:clientName];
|
|
1017
1027
|
NSArray<NSString *> *entries = [NSFileManager.defaultManager contentsOfDirectoryAtPath:clientDirectory error:nil] ?: @[];
|
|
1018
1028
|
NSInteger liveClients = 0;
|
|
@@ -1057,7 +1067,7 @@ int main(int argc, const char *argv[]) {
|
|
|
1057
1067
|
return EXIT_SUCCESS;
|
|
1058
1068
|
}
|
|
1059
1069
|
|
|
1060
|
-
NSString *lockName = [NSString stringWithFormat:@"
|
|
1070
|
+
NSString *lockName = [NSString stringWithFormat:@"cc-pets-%u.lock", getuid()];
|
|
1061
1071
|
NSString *lockPath = [PetStateDirectory() stringByAppendingPathComponent:lockName];
|
|
1062
1072
|
int lock = open(lockPath.fileSystemRepresentation, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
|
|
1063
1073
|
if (lock < 0 || flock(lock, LOCK_EX | LOCK_NB) != 0) return EXIT_SUCCESS;
|
|
@@ -3,8 +3,8 @@ set -eu
|
|
|
3
3
|
|
|
4
4
|
SCRIPT_DIR="${0:A:h}"
|
|
5
5
|
PROJECT_DIR="${SCRIPT_DIR:h}"
|
|
6
|
-
PET_BIN="${PROJECT_DIR}/.build/release/
|
|
7
|
-
PET_APP="${PROJECT_DIR}/.build/release/
|
|
6
|
+
PET_BIN="${PROJECT_DIR}/.build/release/cc-pets"
|
|
7
|
+
PET_APP="${PROJECT_DIR}/.build/release/CC Pets.app"
|
|
8
8
|
|
|
9
9
|
if [[ "${1:-}" == "install" ]]; then
|
|
10
10
|
exec "${PROJECT_DIR}/scripts/install-shell-integration.sh"
|
package/bin/claude-with-pet
CHANGED
|
@@ -3,10 +3,10 @@ set -eu
|
|
|
3
3
|
|
|
4
4
|
SCRIPT_DIR="${0:A:h}"
|
|
5
5
|
PROJECT_DIR="${SCRIPT_DIR:h}"
|
|
6
|
-
PET_BIN="${PROJECT_DIR}/.build/release/
|
|
7
|
-
PET_APP="${PROJECT_DIR}/.build/release/
|
|
6
|
+
PET_BIN="${PROJECT_DIR}/.build/release/cc-pets"
|
|
7
|
+
PET_APP="${PROJECT_DIR}/.build/release/CC Pets.app"
|
|
8
8
|
REAL_CLAUDE="${CLAUDE_REAL_BIN:-}"
|
|
9
|
-
CLIENT_DIR="${${TMPDIR:-/tmp/}%/}/
|
|
9
|
+
CLIENT_DIR="${${TMPDIR:-/tmp/}%/}/cc-pets-$(id -u)-clients"
|
|
10
10
|
CLIENT_FILE="${CLIENT_DIR}/$$"
|
|
11
11
|
|
|
12
12
|
if [[ -z "${REAL_CLAUDE}" ]]; then
|
package/bin/codex-with-pet
CHANGED
|
@@ -3,10 +3,10 @@ set -eu
|
|
|
3
3
|
|
|
4
4
|
SCRIPT_DIR="${0:A:h}"
|
|
5
5
|
PROJECT_DIR="${SCRIPT_DIR:h}"
|
|
6
|
-
PET_BIN="${PROJECT_DIR}/.build/release/
|
|
7
|
-
PET_APP="${PROJECT_DIR}/.build/release/
|
|
6
|
+
PET_BIN="${PROJECT_DIR}/.build/release/cc-pets"
|
|
7
|
+
PET_APP="${PROJECT_DIR}/.build/release/CC Pets.app"
|
|
8
8
|
REAL_CODEX="${CODEX_REAL_BIN:-}"
|
|
9
|
-
CLIENT_DIR="${${TMPDIR:-/tmp/}%/}/
|
|
9
|
+
CLIENT_DIR="${${TMPDIR:-/tmp/}%/}/cc-pets-$(id -u)-clients"
|
|
10
10
|
CLIENT_FILE="${CLIENT_DIR}/$$"
|
|
11
11
|
|
|
12
12
|
if [[ -z "${REAL_CODEX}" ]]; then
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cc-pets",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "A native macOS desktop pet for Codex CLI and Claude Code",
|
|
5
5
|
"author": "wangxinyusqn",
|
|
6
6
|
"license": "MIT",
|
|
@@ -30,8 +30,9 @@
|
|
|
30
30
|
"bin",
|
|
31
31
|
"scripts",
|
|
32
32
|
"Resources/Info.plist",
|
|
33
|
-
"
|
|
34
|
-
"Sources/
|
|
33
|
+
"Resources/AppIcon.icns",
|
|
34
|
+
"Sources/CCPets/main.m",
|
|
35
|
+
"Sources/CCPets/Resources",
|
|
35
36
|
"README.md",
|
|
36
37
|
"CHANGELOG.md",
|
|
37
38
|
"CONTRIBUTING.md",
|
|
@@ -40,7 +41,7 @@
|
|
|
40
41
|
"LICENSE"
|
|
41
42
|
],
|
|
42
43
|
"bin": {
|
|
43
|
-
"
|
|
44
|
+
"cc-pets": "bin/cc-pets",
|
|
44
45
|
"codex-with-pet": "bin/codex-with-pet",
|
|
45
46
|
"claude-with-pet": "bin/claude-with-pet"
|
|
46
47
|
},
|
package/scripts/build.sh
CHANGED
|
@@ -5,10 +5,10 @@ SCRIPT_DIR="${0:A:h}"
|
|
|
5
5
|
PROJECT_DIR="${SCRIPT_DIR:h}"
|
|
6
6
|
BUILD_DIR="${PROJECT_DIR}/.build/release"
|
|
7
7
|
CACHE_DIR="${PROJECT_DIR}/.build/clang-cache"
|
|
8
|
-
APP_DIR="${BUILD_DIR}/
|
|
8
|
+
APP_DIR="${BUILD_DIR}/CC Pets.app"
|
|
9
9
|
APP_MACOS_DIR="${APP_DIR}/Contents/MacOS"
|
|
10
10
|
APP_RESOURCES_DIR="${APP_DIR}/Contents/Resources"
|
|
11
|
-
RESOURCE_DIR="${
|
|
11
|
+
RESOURCE_DIR="${CC_PETS_RESOURCE_DIR:-${PROJECT_DIR}/Sources/CCPets/Resources}"
|
|
12
12
|
mkdir -p "${BUILD_DIR}" "${CACHE_DIR}" "${APP_MACOS_DIR}" "${APP_RESOURCES_DIR}"
|
|
13
13
|
|
|
14
14
|
CLANG_MODULE_CACHE_PATH="${CACHE_DIR}" clang \
|
|
@@ -16,8 +16,8 @@ CLANG_MODULE_CACHE_PATH="${CACHE_DIR}" clang \
|
|
|
16
16
|
-fmodules-cache-path="${CACHE_DIR}" \
|
|
17
17
|
-mmacosx-version-min=13.0 \
|
|
18
18
|
-framework Cocoa \
|
|
19
|
-
"${PROJECT_DIR}/Sources/
|
|
20
|
-
-o "${BUILD_DIR}/
|
|
19
|
+
"${PROJECT_DIR}/Sources/CCPets/main.m" \
|
|
20
|
+
-o "${BUILD_DIR}/cc-pets"
|
|
21
21
|
|
|
22
22
|
find "${BUILD_DIR}" -maxdepth 1 -type f \( -name '*.webp' -o -name '*.png' \) -delete
|
|
23
23
|
find "${APP_MACOS_DIR}" -maxdepth 1 -type f \( -name '*.webp' -o -name '*.png' \) -delete
|
|
@@ -26,7 +26,8 @@ if (( ${#SPRITES[@]} > 0 )); then
|
|
|
26
26
|
cp "${SPRITES[@]}" "${BUILD_DIR}/"
|
|
27
27
|
cp "${SPRITES[@]}" "${APP_MACOS_DIR}/"
|
|
28
28
|
fi
|
|
29
|
-
cp "${BUILD_DIR}/
|
|
29
|
+
cp "${BUILD_DIR}/cc-pets" "${APP_MACOS_DIR}/cc-pets"
|
|
30
30
|
cp "${PROJECT_DIR}/Resources/Info.plist" "${APP_DIR}/Contents/Info.plist"
|
|
31
|
-
|
|
31
|
+
cp "${PROJECT_DIR}/Resources/AppIcon.icns" "${APP_RESOURCES_DIR}/AppIcon.icns"
|
|
32
|
+
print "构建完成: ${BUILD_DIR}/cc-pets"
|
|
32
33
|
print "应用完成: ${APP_DIR}"
|
|
@@ -7,14 +7,27 @@ import path from "node:path";
|
|
|
7
7
|
const binary = process.argv[2];
|
|
8
8
|
const statusLineProxy = process.argv[3];
|
|
9
9
|
if (!binary || !statusLineProxy) {
|
|
10
|
-
console.error("用法: install-claude-hooks.mjs /absolute/path/to/
|
|
10
|
+
console.error("用法: install-claude-hooks.mjs /absolute/path/to/cc-pets /absolute/path/to/claude-statusline-with-pet");
|
|
11
11
|
process.exit(2);
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
const claudeHome = process.env.CLAUDE_CONFIG_DIR || path.join(os.homedir(), ".claude");
|
|
15
15
|
const settingsPath = path.join(claudeHome, "settings.json");
|
|
16
|
-
const marker = "
|
|
17
|
-
const statusLineMarker = "
|
|
16
|
+
const marker = "CC_PETS_CLAUDE_AGENT_HOOK=1";
|
|
17
|
+
const statusLineMarker = "CC_PETS_CLAUDE_STATUS_LINE=1";
|
|
18
|
+
const managedHookSignatures = [
|
|
19
|
+
{ marker, executable: "cc-pets" },
|
|
20
|
+
{ marker: "CLAUDE_PET_AGENT_HOOK=1", executable: "codex-pet" }
|
|
21
|
+
];
|
|
22
|
+
const managedStatusLineMarkers = [statusLineMarker, "CLAUDE_PET_STATUS_LINE=1"];
|
|
23
|
+
const isManagedHookCommand = (value, signature) =>
|
|
24
|
+
typeof value === "string" &&
|
|
25
|
+
value.startsWith(`${signature.marker} `) &&
|
|
26
|
+
value.endsWith(`/.build/release/${signature.executable}' --hook`);
|
|
27
|
+
const isManagedStatusLine = (value, candidateMarker) =>
|
|
28
|
+
typeof value === "string" &&
|
|
29
|
+
value.startsWith(`${candidateMarker} `) &&
|
|
30
|
+
/\/bin\/claude-statusline-with-pet' '[A-Za-z0-9+/=]*'$/.test(value);
|
|
18
31
|
const shellQuote = (value) => `'${value.replaceAll("'", `'\\''`)}'`;
|
|
19
32
|
const command = `${marker} ${shellQuote(path.resolve(binary))} --hook`;
|
|
20
33
|
const events = [
|
|
@@ -51,9 +64,9 @@ for (const [event, groups] of Object.entries(config.hooks)) {
|
|
|
51
64
|
if (!Array.isArray(groups)) continue;
|
|
52
65
|
config.hooks[event] = groups.flatMap((group) => {
|
|
53
66
|
if (!group || !Array.isArray(group.hooks)) return [group];
|
|
54
|
-
const handlers = group.hooks.filter((handler) =>
|
|
55
|
-
|
|
56
|
-
);
|
|
67
|
+
const handlers = group.hooks.filter((handler) => {
|
|
68
|
+
return !managedHookSignatures.some((signature) => isManagedHookCommand(handler?.command, signature));
|
|
69
|
+
});
|
|
57
70
|
return handlers.length > 0 ? [{ ...group, hooks: handlers }] : [];
|
|
58
71
|
});
|
|
59
72
|
}
|
|
@@ -68,7 +81,7 @@ for (const event of events) {
|
|
|
68
81
|
let originalStatusLineCommand = "";
|
|
69
82
|
if (config.statusLine && typeof config.statusLine === "object" && !Array.isArray(config.statusLine)) {
|
|
70
83
|
const currentCommand = typeof config.statusLine.command === "string" ? config.statusLine.command : "";
|
|
71
|
-
if (
|
|
84
|
+
if (managedStatusLineMarkers.some((value) => isManagedStatusLine(currentCommand, value))) {
|
|
72
85
|
const match = currentCommand.match(/'([A-Za-z0-9+/=]*)'\s*$/);
|
|
73
86
|
if (match) originalStatusLineCommand = Buffer.from(match[1], "base64").toString("utf8");
|
|
74
87
|
} else {
|
|
@@ -84,7 +97,7 @@ config.statusLine = {
|
|
|
84
97
|
command: `${statusLineMarker} ${shellQuote(path.resolve(statusLineProxy))} ${shellQuote(encodedOriginal)}`
|
|
85
98
|
};
|
|
86
99
|
|
|
87
|
-
const temporaryPath = `${settingsPath}.
|
|
100
|
+
const temporaryPath = `${settingsPath}.cc-pets.tmp`;
|
|
88
101
|
fs.writeFileSync(temporaryPath, `${JSON.stringify(config, null, 2)}\n`, { mode: 0o600 });
|
|
89
102
|
fs.renameSync(temporaryPath, settingsPath);
|
|
90
103
|
fs.chmodSync(settingsPath, 0o600);
|
|
@@ -6,13 +6,21 @@ import path from "node:path";
|
|
|
6
6
|
|
|
7
7
|
const binary = process.argv[2];
|
|
8
8
|
if (!binary) {
|
|
9
|
-
console.error("用法: install-codex-hooks.mjs /absolute/path/to/
|
|
9
|
+
console.error("用法: install-codex-hooks.mjs /absolute/path/to/cc-pets");
|
|
10
10
|
process.exit(2);
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
const codexHome = process.env.CODEX_HOME || path.join(os.homedir(), ".codex");
|
|
14
14
|
const hooksPath = path.join(codexHome, "hooks.json");
|
|
15
|
-
const marker = "
|
|
15
|
+
const marker = "CC_PETS_CODEX_AGENT_HOOK=1";
|
|
16
|
+
const managedSignatures = [
|
|
17
|
+
{ marker, executable: "cc-pets" },
|
|
18
|
+
{ marker: "CODEX_PET_AGENT_HOOK=1", executable: "codex-pet" }
|
|
19
|
+
];
|
|
20
|
+
const isManagedHookCommand = (value, signature) =>
|
|
21
|
+
typeof value === "string" &&
|
|
22
|
+
value.startsWith(`${signature.marker} `) &&
|
|
23
|
+
value.endsWith(`/.build/release/${signature.executable}' --hook`);
|
|
16
24
|
const shellQuote = (value) => `'${value.replaceAll("'", `'\\''`)}'`;
|
|
17
25
|
const command = `${marker} ${shellQuote(path.resolve(binary))} --hook`;
|
|
18
26
|
const events = [
|
|
@@ -43,9 +51,9 @@ for (const [event, groups] of Object.entries(config.hooks)) {
|
|
|
43
51
|
if (!Array.isArray(groups)) continue;
|
|
44
52
|
config.hooks[event] = groups.flatMap((group) => {
|
|
45
53
|
if (!group || !Array.isArray(group.hooks)) return [group];
|
|
46
|
-
const handlers = group.hooks.filter((handler) =>
|
|
47
|
-
|
|
48
|
-
);
|
|
54
|
+
const handlers = group.hooks.filter((handler) => {
|
|
55
|
+
return !managedSignatures.some((signature) => isManagedHookCommand(handler?.command, signature));
|
|
56
|
+
});
|
|
49
57
|
return handlers.length > 0 ? [{ ...group, hooks: handlers }] : [];
|
|
50
58
|
});
|
|
51
59
|
}
|
|
@@ -57,7 +65,7 @@ for (const event of events) {
|
|
|
57
65
|
});
|
|
58
66
|
}
|
|
59
67
|
|
|
60
|
-
const temporaryPath = `${hooksPath}.
|
|
68
|
+
const temporaryPath = `${hooksPath}.cc-pets.tmp`;
|
|
61
69
|
fs.writeFileSync(temporaryPath, `${JSON.stringify(config, null, 2)}\n`, { mode: 0o600 });
|
|
62
70
|
fs.renameSync(temporaryPath, hooksPath);
|
|
63
71
|
fs.chmodSync(hooksPath, 0o600);
|
|
@@ -6,23 +6,34 @@ PROJECT_DIR="${SCRIPT_DIR:h}"
|
|
|
6
6
|
LAUNCHER="${PROJECT_DIR}/bin/codex-with-pet"
|
|
7
7
|
CLAUDE_LAUNCHER="${PROJECT_DIR}/bin/claude-with-pet"
|
|
8
8
|
SHELL_RC="${ZDOTDIR:-${HOME}}/.zshrc"
|
|
9
|
-
START_MARKER="# >>> codex
|
|
10
|
-
END_MARKER="# <<< codex
|
|
11
|
-
CLAUDE_START_MARKER="# >>> claude
|
|
12
|
-
CLAUDE_END_MARKER="# <<< claude
|
|
9
|
+
START_MARKER="# >>> cc-pets-codex >>>"
|
|
10
|
+
END_MARKER="# <<< cc-pets-codex <<<"
|
|
11
|
+
CLAUDE_START_MARKER="# >>> cc-pets-claude >>>"
|
|
12
|
+
CLAUDE_END_MARKER="# <<< cc-pets-claude <<<"
|
|
13
13
|
|
|
14
|
+
node "${PROJECT_DIR}/scripts/uninstall-integrations.mjs" --prepare-install "${SHELL_RC}"
|
|
14
15
|
"${PROJECT_DIR}/scripts/build.sh"
|
|
15
|
-
node "${PROJECT_DIR}/scripts/install-codex-hooks.mjs" "${PROJECT_DIR}/.build/release/
|
|
16
|
+
node "${PROJECT_DIR}/scripts/install-codex-hooks.mjs" "${PROJECT_DIR}/.build/release/cc-pets"
|
|
16
17
|
node "${PROJECT_DIR}/scripts/install-claude-hooks.mjs" \
|
|
17
|
-
"${PROJECT_DIR}/.build/release/
|
|
18
|
+
"${PROJECT_DIR}/.build/release/cc-pets" \
|
|
18
19
|
"${PROJECT_DIR}/bin/claude-statusline-with-pet"
|
|
19
20
|
|
|
20
|
-
PET_APP="${PROJECT_DIR}/.build/release/
|
|
21
|
-
PET_APP_EXECUTABLE="${PET_APP}/Contents/MacOS/
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
PET_APP="${PROJECT_DIR}/.build/release/CC Pets.app"
|
|
22
|
+
PET_APP_EXECUTABLE="${PET_APP}/Contents/MacOS/cc-pets"
|
|
23
|
+
LEGACY_PET_APP_EXECUTABLE="${PROJECT_DIR}/.build/release/CodexPet.app/Contents/MacOS/codex-pet"
|
|
24
|
+
PET_WAS_RUNNING=0
|
|
25
|
+
for executable in "${PET_APP_EXECUTABLE}" "${LEGACY_PET_APP_EXECUTABLE}"; do
|
|
26
|
+
if pgrep -f "${executable}" >/dev/null 2>&1; then
|
|
27
|
+
pkill -f "${executable}" || true
|
|
28
|
+
PET_WAS_RUNNING=1
|
|
29
|
+
fi
|
|
30
|
+
done
|
|
31
|
+
if (( PET_WAS_RUNNING )); then
|
|
24
32
|
for _ in {1..30}; do
|
|
25
|
-
pgrep -f "${PET_APP_EXECUTABLE}" >/dev/null 2>&1
|
|
33
|
+
if ! pgrep -f "${PET_APP_EXECUTABLE}" >/dev/null 2>&1 && \
|
|
34
|
+
! pgrep -f "${LEGACY_PET_APP_EXECUTABLE}" >/dev/null 2>&1; then
|
|
35
|
+
break
|
|
36
|
+
fi
|
|
26
37
|
sleep 0.1
|
|
27
38
|
done
|
|
28
39
|
open -g "${PET_APP}" --args --managed
|
|
@@ -6,7 +6,27 @@ import path from "node:path";
|
|
|
6
6
|
|
|
7
7
|
const codexHome = process.env.CODEX_HOME || path.join(os.homedir(), ".codex");
|
|
8
8
|
const claudeHome = process.env.CLAUDE_CONFIG_DIR || path.join(os.homedir(), ".claude");
|
|
9
|
-
const
|
|
9
|
+
const preparingInstall = process.argv[2] === "--prepare-install";
|
|
10
|
+
const shellRC = process.argv[preparingInstall ? 3 : 2];
|
|
11
|
+
|
|
12
|
+
const currentCodexHook = { marker: "CC_PETS_CODEX_AGENT_HOOK=1", executable: "cc-pets" };
|
|
13
|
+
const legacyCodexHook = { marker: "CODEX_PET_AGENT_HOOK=1", executable: "codex-pet" };
|
|
14
|
+
const currentClaudeHook = { marker: "CC_PETS_CLAUDE_AGENT_HOOK=1", executable: "cc-pets" };
|
|
15
|
+
const legacyClaudeHook = { marker: "CLAUDE_PET_AGENT_HOOK=1", executable: "codex-pet" };
|
|
16
|
+
const currentStatusLineMarker = "CC_PETS_CLAUDE_STATUS_LINE=1";
|
|
17
|
+
const legacyStatusLineMarker = "CLAUDE_PET_STATUS_LINE=1";
|
|
18
|
+
|
|
19
|
+
function isManagedHookCommand(value, signature) {
|
|
20
|
+
return typeof value === "string" &&
|
|
21
|
+
value.startsWith(`${signature.marker} `) &&
|
|
22
|
+
value.endsWith(`/.build/release/${signature.executable}' --hook`);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function isManagedStatusLine(value, marker) {
|
|
26
|
+
return typeof value === "string" &&
|
|
27
|
+
value.startsWith(`${marker} `) &&
|
|
28
|
+
/\/bin\/claude-statusline-with-pet' '[A-Za-z0-9+/=]*'$/.test(value);
|
|
29
|
+
}
|
|
10
30
|
|
|
11
31
|
function writeJSON(filePath, value) {
|
|
12
32
|
const temporaryPath = `${filePath}.cc-pets.tmp`;
|
|
@@ -15,7 +35,7 @@ function writeJSON(filePath, value) {
|
|
|
15
35
|
fs.chmodSync(filePath, 0o600);
|
|
16
36
|
}
|
|
17
37
|
|
|
18
|
-
function removeHookHandlers(config,
|
|
38
|
+
function removeHookHandlers(config, markers) {
|
|
19
39
|
if (!config?.hooks || typeof config.hooks !== "object" || Array.isArray(config.hooks)) return false;
|
|
20
40
|
let changed = false;
|
|
21
41
|
for (const [event, groups] of Object.entries(config.hooks)) {
|
|
@@ -23,7 +43,7 @@ function removeHookHandlers(config, marker) {
|
|
|
23
43
|
const filteredGroups = groups.flatMap((group) => {
|
|
24
44
|
if (!group || !Array.isArray(group.hooks)) return [group];
|
|
25
45
|
const handlers = group.hooks.filter((handler) =>
|
|
26
|
-
|
|
46
|
+
!markers.some((signature) => isManagedHookCommand(handler?.command, signature))
|
|
27
47
|
);
|
|
28
48
|
if (handlers.length !== group.hooks.length) changed = true;
|
|
29
49
|
return handlers.length > 0 ? [{ ...group, hooks: handlers }] : [];
|
|
@@ -52,15 +72,24 @@ function updateJSON(filePath, updater) {
|
|
|
52
72
|
}
|
|
53
73
|
|
|
54
74
|
const codexHooksPath = path.join(codexHome, "hooks.json");
|
|
75
|
+
const codexSignatures = preparingInstall
|
|
76
|
+
? [legacyCodexHook]
|
|
77
|
+
: [currentCodexHook, legacyCodexHook];
|
|
55
78
|
const codexChanged = updateJSON(codexHooksPath, (config) =>
|
|
56
|
-
removeHookHandlers(config,
|
|
79
|
+
removeHookHandlers(config, codexSignatures)
|
|
57
80
|
);
|
|
58
81
|
|
|
59
82
|
const claudeSettingsPath = path.join(claudeHome, "settings.json");
|
|
83
|
+
const claudeSignatures = preparingInstall
|
|
84
|
+
? [legacyClaudeHook]
|
|
85
|
+
: [currentClaudeHook, legacyClaudeHook];
|
|
86
|
+
const statusLineMarkers = preparingInstall
|
|
87
|
+
? [legacyStatusLineMarker]
|
|
88
|
+
: [currentStatusLineMarker, legacyStatusLineMarker];
|
|
60
89
|
const claudeChanged = updateJSON(claudeSettingsPath, (config) => {
|
|
61
|
-
let changed = removeHookHandlers(config,
|
|
90
|
+
let changed = removeHookHandlers(config, claudeSignatures);
|
|
62
91
|
const command = typeof config.statusLine?.command === "string" ? config.statusLine.command : "";
|
|
63
|
-
if (
|
|
92
|
+
if (statusLineMarkers.some((marker) => isManagedStatusLine(command, marker))) {
|
|
64
93
|
const match = command.match(/'([A-Za-z0-9+/=]*)'\s*$/);
|
|
65
94
|
const originalCommand = match ? Buffer.from(match[1], "base64").toString("utf8") : "";
|
|
66
95
|
if (originalCommand) config.statusLine = { ...config.statusLine, command: originalCommand };
|
|
@@ -85,7 +114,9 @@ function removeMarkedBlock(text, startMarker, endMarker) {
|
|
|
85
114
|
let shellChanged = false;
|
|
86
115
|
if (shellRC && fs.existsSync(shellRC)) {
|
|
87
116
|
const original = fs.readFileSync(shellRC, "utf8");
|
|
88
|
-
let updated = removeMarkedBlock(original, "# >>> codex
|
|
117
|
+
let updated = removeMarkedBlock(original, "# >>> cc-pets-codex >>>", "# <<< cc-pets-codex <<<");
|
|
118
|
+
updated = removeMarkedBlock(updated, "# >>> cc-pets-claude >>>", "# <<< cc-pets-claude <<<");
|
|
119
|
+
updated = removeMarkedBlock(updated, "# >>> codex-pet >>>", "# <<< codex-pet <<<");
|
|
89
120
|
updated = removeMarkedBlock(updated, "# >>> claude-pet >>>", "# <<< claude-pet <<<");
|
|
90
121
|
updated = updated.replace(/\n{3,}/g, "\n\n");
|
|
91
122
|
if (updated !== original) {
|
|
@@ -97,7 +128,10 @@ if (shellRC && fs.existsSync(shellRC)) {
|
|
|
97
128
|
}
|
|
98
129
|
}
|
|
99
130
|
|
|
100
|
-
|
|
101
|
-
if (
|
|
102
|
-
if (
|
|
103
|
-
if (
|
|
131
|
+
const action = preparingInstall ? "已迁移" : "已移除";
|
|
132
|
+
if (codexChanged) console.log(`${action} ${codexHooksPath} 中的 CC Pets Hooks。`);
|
|
133
|
+
if (claudeChanged) console.log(`${action} ${claudeSettingsPath} 中的 CC Pets Hooks,并恢复原 status line。`);
|
|
134
|
+
if (shellChanged) console.log(`${action} ${shellRC} 中的 CC Pets aliases。`);
|
|
135
|
+
if (!codexChanged && !claudeChanged && !shellChanged && !preparingInstall) {
|
|
136
|
+
console.log("未发现需要移除的 CC Pets 集成。 ");
|
|
137
|
+
}
|
|
@@ -4,12 +4,17 @@ set -eu
|
|
|
4
4
|
SCRIPT_DIR="${0:A:h}"
|
|
5
5
|
PROJECT_DIR="${SCRIPT_DIR:h}"
|
|
6
6
|
SHELL_RC="${ZDOTDIR:-${HOME}}/.zshrc"
|
|
7
|
-
PET_APP_EXECUTABLE="${PROJECT_DIR}/.build/release/
|
|
7
|
+
PET_APP_EXECUTABLE="${PROJECT_DIR}/.build/release/CC Pets.app/Contents/MacOS/cc-pets"
|
|
8
|
+
LEGACY_PET_APP_EXECUTABLE="${PROJECT_DIR}/.build/release/CodexPet.app/Contents/MacOS/codex-pet"
|
|
8
9
|
|
|
9
10
|
node "${PROJECT_DIR}/scripts/uninstall-integrations.mjs" "${SHELL_RC}"
|
|
10
11
|
|
|
11
|
-
if [[ "${
|
|
12
|
-
|
|
12
|
+
if [[ "${CC_PETS_SKIP_APP_STOP:-0}" != "1" ]]; then
|
|
13
|
+
for executable in "${PET_APP_EXECUTABLE}" "${LEGACY_PET_APP_EXECUTABLE}"; do
|
|
14
|
+
if pgrep -f "${executable}" >/dev/null 2>&1; then
|
|
15
|
+
pkill -f "${executable}" || true
|
|
16
|
+
fi
|
|
17
|
+
done
|
|
13
18
|
fi
|
|
14
19
|
|
|
15
20
|
print "卸载集成完成。执行 source ${(q)SHELL_RC} 更新当前终端;如需删除 npm 包,再执行 npm uninstall -g cc-pets。"
|
|
File without changes
|