cc-pets 0.2.0 → 0.2.2
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 +1 -0
- package/README.md +11 -14
- package/Resources/AppIcon.icns +0 -0
- package/Resources/Info.plist +2 -0
- package/package.json +3 -2
- package/scripts/build.sh +1 -0
- package/scripts/install-claude-hooks.mjs +15 -5
- package/scripts/install-codex-hooks.mjs +9 -3
- package/scripts/install-shell-integration.sh +1 -1
- package/scripts/uninstall-integrations.mjs +43 -12
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
- 项目和 npm 包更名为 CC Pets。
|
|
8
8
|
- 新版安装器会自动清理旧版 `codex-pet` Hooks、Claude status line 包装和 shell aliases。
|
|
9
|
+
- 旧版迁移只匹配 CC Pets 的完整命令签名,避免误删复用相似标记的其他工具配置。
|
|
9
10
|
- 新增原创默认桌宠 ByteMochi,移除公开包中的第三方角色素材。
|
|
10
11
|
- 新增 Codex CLI 与 Claude Code CLI 共存、Agent 动画和额度面板。
|
|
11
12
|
- 新增 PetDex 外部素材动态扫描与桌宠切换。
|
package/README.md
CHANGED
|
@@ -36,8 +36,8 @@ 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
|
-
|
|
40
|
-
|
|
39
|
+
通过 npm 安装或升级时会自动重新构建应用、安装或更新两套 Hooks,并配置 shell alias;如果旧版桌宠正在运行,
|
|
40
|
+
安装器会自动重启桌宠,使新版本生效。`cc-pets install` 保留为手动修复和重新初始化命令。
|
|
41
41
|
|
|
42
42
|
### 鼠标互动
|
|
43
43
|
|
|
@@ -90,9 +90,8 @@ Claude Code Hook 会合并到 `~/.claude/settings.json`,现有的 `env`、`mod
|
|
|
90
90
|
### npm 安装
|
|
91
91
|
|
|
92
92
|
```bash
|
|
93
|
-
npm install -g cc-pets
|
|
94
|
-
|
|
95
|
-
source ~/.zshrc
|
|
93
|
+
npm install -g cc-pets@latest
|
|
94
|
+
# 首次安装后新开一个终端
|
|
96
95
|
codex
|
|
97
96
|
# 或
|
|
98
97
|
claude
|
|
@@ -104,29 +103,27 @@ claude
|
|
|
104
103
|
git clone https://gitee.com/wangxinyusqn/cc-pets.git
|
|
105
104
|
cd cc-pets
|
|
106
105
|
npm install -g .
|
|
107
|
-
|
|
108
|
-
source ~/.zshrc
|
|
106
|
+
# 首次安装后新开一个终端
|
|
109
107
|
codex
|
|
110
108
|
# 或
|
|
111
109
|
claude
|
|
112
110
|
```
|
|
113
111
|
|
|
114
112
|
两种方式都会安装 `cc-pets`、`codex-with-pet` 和 `claude-with-pet`。
|
|
115
|
-
|
|
116
|
-
`codex` 与 `claude` alias,不会覆盖真实的 CLI
|
|
113
|
+
npm 的安装后脚本会自动构建原生应用、安装两套 Agent Hooks,并向 `~/.zshrc` 追加带明确标记的
|
|
114
|
+
`codex` 与 `claude` alias,不会覆盖真实的 CLI 二进制。首次安装需要新开终端让 alias 生效;以后升级只需执行 npm 命令。
|
|
117
115
|
|
|
118
116
|
### 从旧版升级
|
|
119
117
|
|
|
120
|
-
从使用 `codex-pet`
|
|
118
|
+
从使用 `codex-pet` 命令的旧版升级时,直接安装新版即可:
|
|
121
119
|
|
|
122
120
|
```bash
|
|
123
121
|
npm install -g cc-pets@latest
|
|
124
|
-
cc-pets install
|
|
125
|
-
source ~/.zshrc
|
|
126
122
|
```
|
|
127
123
|
|
|
128
124
|
新版安装器会自动移除旧版 Hooks、恢复并重新接入 Claude status line,同时替换旧的 shell alias 标记,
|
|
129
|
-
不需要先运行已经移除的 `codex-pet uninstall
|
|
125
|
+
不需要先运行已经移除的 `codex-pet uninstall`。迁移仅识别 CC Pets 的完整命令签名,不会按
|
|
126
|
+
`codex`、`claude` 或单个环境变量名称泛化删除其他工具配置。
|
|
130
127
|
|
|
131
128
|
如果真实 Codex CLI 不在当前 `PATH`,可以显式指定:
|
|
132
129
|
|
|
@@ -158,7 +155,7 @@ cc-pets --foreground
|
|
|
158
155
|
# 查看当前解析到的 Codex 额度
|
|
159
156
|
cc-pets --status
|
|
160
157
|
|
|
161
|
-
#
|
|
158
|
+
# 手动修复或重新初始化 Hooks、shell alias,并让已运行桌宠加载当前版本
|
|
162
159
|
cc-pets install
|
|
163
160
|
|
|
164
161
|
# 安全移除 Hooks、恢复 Claude status line,并清理 shell alias
|
|
Binary file
|
package/Resources/Info.plist
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cc-pets",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "A native macOS desktop pet for Codex CLI and Claude Code",
|
|
5
5
|
"author": "wangxinyusqn",
|
|
6
6
|
"license": "MIT",
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
"bin",
|
|
31
31
|
"scripts",
|
|
32
32
|
"Resources/Info.plist",
|
|
33
|
+
"Resources/AppIcon.icns",
|
|
33
34
|
"Sources/CCPets/main.m",
|
|
34
35
|
"Sources/CCPets/Resources",
|
|
35
36
|
"README.md",
|
|
@@ -47,7 +48,7 @@
|
|
|
47
48
|
"scripts": {
|
|
48
49
|
"build": "./scripts/build.sh",
|
|
49
50
|
"test": "./tests/test.sh",
|
|
50
|
-
"postinstall": "./scripts/
|
|
51
|
+
"postinstall": "./scripts/install-shell-integration.sh",
|
|
51
52
|
"prepack": "npm test"
|
|
52
53
|
},
|
|
53
54
|
"publishConfig": {
|
package/scripts/build.sh
CHANGED
|
@@ -28,5 +28,6 @@ if (( ${#SPRITES[@]} > 0 )); then
|
|
|
28
28
|
fi
|
|
29
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
|
+
cp "${PROJECT_DIR}/Resources/AppIcon.icns" "${APP_RESOURCES_DIR}/AppIcon.icns"
|
|
31
32
|
print "构建完成: ${BUILD_DIR}/cc-pets"
|
|
32
33
|
print "应用完成: ${APP_DIR}"
|
|
@@ -15,8 +15,19 @@ const claudeHome = process.env.CLAUDE_CONFIG_DIR || path.join(os.homedir(), ".cl
|
|
|
15
15
|
const settingsPath = path.join(claudeHome, "settings.json");
|
|
16
16
|
const marker = "CC_PETS_CLAUDE_AGENT_HOOK=1";
|
|
17
17
|
const statusLineMarker = "CC_PETS_CLAUDE_STATUS_LINE=1";
|
|
18
|
-
const
|
|
19
|
-
|
|
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);
|
|
20
31
|
const shellQuote = (value) => `'${value.replaceAll("'", `'\\''`)}'`;
|
|
21
32
|
const command = `${marker} ${shellQuote(path.resolve(binary))} --hook`;
|
|
22
33
|
const events = [
|
|
@@ -54,8 +65,7 @@ for (const [event, groups] of Object.entries(config.hooks)) {
|
|
|
54
65
|
config.hooks[event] = groups.flatMap((group) => {
|
|
55
66
|
if (!group || !Array.isArray(group.hooks)) return [group];
|
|
56
67
|
const handlers = group.hooks.filter((handler) => {
|
|
57
|
-
|
|
58
|
-
return ![marker, ...obsoleteHookMarkers].some((value) => handler.command.includes(value));
|
|
68
|
+
return !managedHookSignatures.some((signature) => isManagedHookCommand(handler?.command, signature));
|
|
59
69
|
});
|
|
60
70
|
return handlers.length > 0 ? [{ ...group, hooks: handlers }] : [];
|
|
61
71
|
});
|
|
@@ -71,7 +81,7 @@ for (const event of events) {
|
|
|
71
81
|
let originalStatusLineCommand = "";
|
|
72
82
|
if (config.statusLine && typeof config.statusLine === "object" && !Array.isArray(config.statusLine)) {
|
|
73
83
|
const currentCommand = typeof config.statusLine.command === "string" ? config.statusLine.command : "";
|
|
74
|
-
if (
|
|
84
|
+
if (managedStatusLineMarkers.some((value) => isManagedStatusLine(currentCommand, value))) {
|
|
75
85
|
const match = currentCommand.match(/'([A-Za-z0-9+/=]*)'\s*$/);
|
|
76
86
|
if (match) originalStatusLineCommand = Buffer.from(match[1], "base64").toString("utf8");
|
|
77
87
|
} else {
|
|
@@ -13,7 +13,14 @@ if (!binary) {
|
|
|
13
13
|
const codexHome = process.env.CODEX_HOME || path.join(os.homedir(), ".codex");
|
|
14
14
|
const hooksPath = path.join(codexHome, "hooks.json");
|
|
15
15
|
const marker = "CC_PETS_CODEX_AGENT_HOOK=1";
|
|
16
|
-
const
|
|
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`);
|
|
17
24
|
const shellQuote = (value) => `'${value.replaceAll("'", `'\\''`)}'`;
|
|
18
25
|
const command = `${marker} ${shellQuote(path.resolve(binary))} --hook`;
|
|
19
26
|
const events = [
|
|
@@ -45,8 +52,7 @@ for (const [event, groups] of Object.entries(config.hooks)) {
|
|
|
45
52
|
config.hooks[event] = groups.flatMap((group) => {
|
|
46
53
|
if (!group || !Array.isArray(group.hooks)) return [group];
|
|
47
54
|
const handlers = group.hooks.filter((handler) => {
|
|
48
|
-
|
|
49
|
-
return ![marker, ...obsoleteMarkers].some((value) => handler.command.includes(value));
|
|
55
|
+
return !managedSignatures.some((signature) => isManagedHookCommand(handler?.command, signature));
|
|
50
56
|
});
|
|
51
57
|
return handlers.length > 0 ? [{ ...group, hooks: handlers }] : [];
|
|
52
58
|
});
|
|
@@ -11,7 +11,7 @@ END_MARKER="# <<< cc-pets-codex <<<"
|
|
|
11
11
|
CLAUDE_START_MARKER="# >>> cc-pets-claude >>>"
|
|
12
12
|
CLAUDE_END_MARKER="# <<< cc-pets-claude <<<"
|
|
13
13
|
|
|
14
|
-
node "${PROJECT_DIR}/scripts/uninstall-integrations.mjs" "${SHELL_RC}"
|
|
14
|
+
node "${PROJECT_DIR}/scripts/uninstall-integrations.mjs" --prepare-install "${SHELL_RC}"
|
|
15
15
|
"${PROJECT_DIR}/scripts/build.sh"
|
|
16
16
|
node "${PROJECT_DIR}/scripts/install-codex-hooks.mjs" "${PROJECT_DIR}/.build/release/cc-pets"
|
|
17
17
|
node "${PROJECT_DIR}/scripts/install-claude-hooks.mjs" \
|
|
@@ -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`;
|
|
@@ -22,10 +42,9 @@ function removeHookHandlers(config, markers) {
|
|
|
22
42
|
if (!Array.isArray(groups)) continue;
|
|
23
43
|
const filteredGroups = groups.flatMap((group) => {
|
|
24
44
|
if (!group || !Array.isArray(group.hooks)) return [group];
|
|
25
|
-
const handlers = group.hooks.filter((handler) =>
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
});
|
|
45
|
+
const handlers = group.hooks.filter((handler) =>
|
|
46
|
+
!markers.some((signature) => isManagedHookCommand(handler?.command, signature))
|
|
47
|
+
);
|
|
29
48
|
if (handlers.length !== group.hooks.length) changed = true;
|
|
30
49
|
return handlers.length > 0 ? [{ ...group, hooks: handlers }] : [];
|
|
31
50
|
});
|
|
@@ -53,15 +72,24 @@ function updateJSON(filePath, updater) {
|
|
|
53
72
|
}
|
|
54
73
|
|
|
55
74
|
const codexHooksPath = path.join(codexHome, "hooks.json");
|
|
75
|
+
const codexSignatures = preparingInstall
|
|
76
|
+
? [legacyCodexHook]
|
|
77
|
+
: [currentCodexHook, legacyCodexHook];
|
|
56
78
|
const codexChanged = updateJSON(codexHooksPath, (config) =>
|
|
57
|
-
removeHookHandlers(config,
|
|
79
|
+
removeHookHandlers(config, codexSignatures)
|
|
58
80
|
);
|
|
59
81
|
|
|
60
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];
|
|
61
89
|
const claudeChanged = updateJSON(claudeSettingsPath, (config) => {
|
|
62
|
-
let changed = removeHookHandlers(config,
|
|
90
|
+
let changed = removeHookHandlers(config, claudeSignatures);
|
|
63
91
|
const command = typeof config.statusLine?.command === "string" ? config.statusLine.command : "";
|
|
64
|
-
if (
|
|
92
|
+
if (statusLineMarkers.some((marker) => isManagedStatusLine(command, marker))) {
|
|
65
93
|
const match = command.match(/'([A-Za-z0-9+/=]*)'\s*$/);
|
|
66
94
|
const originalCommand = match ? Buffer.from(match[1], "base64").toString("utf8") : "";
|
|
67
95
|
if (originalCommand) config.statusLine = { ...config.statusLine, command: originalCommand };
|
|
@@ -100,7 +128,10 @@ if (shellRC && fs.existsSync(shellRC)) {
|
|
|
100
128
|
}
|
|
101
129
|
}
|
|
102
130
|
|
|
103
|
-
|
|
104
|
-
if (
|
|
105
|
-
if (
|
|
106
|
-
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
|
+
}
|