cc-pets 0.1.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.
@@ -0,0 +1,11 @@
1
+ # 第三方声明
2
+
3
+ CC Pets 发布包不捆绑 PetDex 下载的角色素材。内置的 `ByteMochi.png` 是专为本项目创建的
4
+ 原创默认素材,与任何现有动漫、游戏或商业吉祥物无关,并与项目代码一同按 MIT License 分发。
5
+
6
+ 程序会在运行时尝试读取用户本机已安装的 Codex/ChatGPT 和 Claude 应用图标,仅用于界面识别;
7
+ 这些图标不会复制进仓库或 npm 发布包,其商标和版权归各自权利人所有。
8
+
9
+ 用户通过 PetDex 或其他来源安装的素材由用户自行管理,不属于本项目发布内容。使用和再分发
10
+ 此类素材时,请遵守对应作者、平台和权利人的许可证及使用条款。
11
+
@@ -0,0 +1,19 @@
1
+ #!/bin/zsh
2
+ set -u
3
+
4
+ SCRIPT_DIR="${0:A:h}"
5
+ PROJECT_DIR="${SCRIPT_DIR:h}"
6
+ PET_BIN="${PROJECT_DIR}/.build/release/codex-pet"
7
+ ORIGINAL_COMMAND_BASE64="${1:-}"
8
+ INPUT="$(cat)"
9
+
10
+ if [[ -x "${PET_BIN}" ]]; then
11
+ print -rn -- "${INPUT}" | "${PET_BIN}" --claude-usage >/dev/null 2>&1 || true
12
+ fi
13
+
14
+ if [[ -n "${ORIGINAL_COMMAND_BASE64}" ]]; then
15
+ ORIGINAL_COMMAND="$(print -rn -- "${ORIGINAL_COMMAND_BASE64}" | /usr/bin/base64 -D 2>/dev/null)"
16
+ if [[ -n "${ORIGINAL_COMMAND}" ]]; then
17
+ print -rn -- "${INPUT}" | /bin/zsh -c "${ORIGINAL_COMMAND}"
18
+ fi
19
+ fi
@@ -0,0 +1,39 @@
1
+ #!/bin/zsh
2
+ set -eu
3
+
4
+ SCRIPT_DIR="${0:A:h}"
5
+ PROJECT_DIR="${SCRIPT_DIR:h}"
6
+ PET_BIN="${PROJECT_DIR}/.build/release/codex-pet"
7
+ PET_APP="${PROJECT_DIR}/.build/release/CodexPet.app"
8
+ REAL_CLAUDE="${CLAUDE_REAL_BIN:-}"
9
+ CLIENT_DIR="${${TMPDIR:-/tmp/}%/}/codex-pet-$(id -u)-clients"
10
+ CLIENT_FILE="${CLIENT_DIR}/$$"
11
+
12
+ if [[ -z "${REAL_CLAUDE}" ]]; then
13
+ REAL_CLAUDE="$(whence -p claude 2>/dev/null || true)"
14
+ fi
15
+ if [[ -z "${REAL_CLAUDE}" || ! -x "${REAL_CLAUDE}" ]]; then
16
+ print -u2 "未找到可执行的 Claude Code CLI。请先安装 claude,或通过 CLAUDE_REAL_BIN 指定真实路径。"
17
+ exit 127
18
+ fi
19
+
20
+ if [[ ! -x "${PET_BIN}" || ! -d "${PET_APP}" ]]; then
21
+ "${PROJECT_DIR}/scripts/build.sh" >/dev/null
22
+ fi
23
+
24
+ mkdir -p "${CLIENT_DIR}"
25
+ touch "${CLIENT_FILE}"
26
+ cleanup() {
27
+ rm -f "${CLIENT_FILE}"
28
+ }
29
+ trap cleanup EXIT
30
+ trap 'exit 129' HUP
31
+ trap 'exit 130' INT
32
+ trap 'exit 143' TERM
33
+
34
+ open -g "${PET_APP}" --args --managed
35
+ set +e
36
+ "${REAL_CLAUDE}" "$@"
37
+ CLAUDE_STATUS=$?
38
+ set -e
39
+ exit "${CLAUDE_STATUS}"
package/bin/codex-pet ADDED
@@ -0,0 +1,35 @@
1
+ #!/bin/zsh
2
+ set -eu
3
+
4
+ SCRIPT_DIR="${0:A:h}"
5
+ PROJECT_DIR="${SCRIPT_DIR:h}"
6
+ PET_BIN="${PROJECT_DIR}/.build/release/codex-pet"
7
+ PET_APP="${PROJECT_DIR}/.build/release/CodexPet.app"
8
+
9
+ if [[ "${1:-}" == "install" ]]; then
10
+ exec "${PROJECT_DIR}/scripts/install-shell-integration.sh"
11
+ fi
12
+
13
+ if [[ "${1:-}" == "uninstall" ]]; then
14
+ exec "${PROJECT_DIR}/scripts/uninstall-shell-integration.sh"
15
+ fi
16
+
17
+ if [[ "${1:-}" == "build" ]]; then
18
+ exec "${PROJECT_DIR}/scripts/build.sh"
19
+ fi
20
+
21
+ if [[ ! -x "${PET_BIN}" || ! -d "${PET_APP}" ]]; then
22
+ "${PROJECT_DIR}/scripts/build.sh" >/dev/null
23
+ fi
24
+
25
+ if [[ $# -eq 0 ]]; then
26
+ open -g "${PET_APP}"
27
+ exit 0
28
+ fi
29
+
30
+ if [[ "${1:-}" == "--foreground" ]]; then
31
+ shift
32
+ exec "${PET_BIN}" "$@"
33
+ fi
34
+
35
+ exec "${PET_BIN}" "$@"
@@ -0,0 +1,31 @@
1
+ #!/bin/zsh
2
+ set -eu
3
+
4
+ SCRIPT_DIR="${0:A:h}"
5
+ PROJECT_DIR="${SCRIPT_DIR:h}"
6
+ PET_BIN="${PROJECT_DIR}/.build/release/codex-pet"
7
+ PET_APP="${PROJECT_DIR}/.build/release/CodexPet.app"
8
+ REAL_CODEX="${CODEX_REAL_BIN:-$(whence -p codex)}"
9
+ CLIENT_DIR="${${TMPDIR:-/tmp/}%/}/codex-pet-$(id -u)-clients"
10
+ CLIENT_FILE="${CLIENT_DIR}/$$"
11
+
12
+ if [[ ! -x "${PET_BIN}" || ! -d "${PET_APP}" ]]; then
13
+ "${PROJECT_DIR}/scripts/build.sh" >/dev/null
14
+ fi
15
+
16
+ mkdir -p "${CLIENT_DIR}"
17
+ touch "${CLIENT_FILE}"
18
+ cleanup() {
19
+ rm -f "${CLIENT_FILE}"
20
+ }
21
+ trap cleanup EXIT
22
+ trap 'exit 129' HUP
23
+ trap 'exit 130' INT
24
+ trap 'exit 143' TERM
25
+
26
+ open -g "${PET_APP}" --args --managed
27
+ set +e
28
+ "${REAL_CODEX}" "$@"
29
+ CODEX_STATUS=$?
30
+ set -e
31
+ exit "${CODEX_STATUS}"
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "cc-pets",
3
+ "version": "0.1.0",
4
+ "description": "A native macOS desktop pet for Codex CLI and Claude Code",
5
+ "author": "wangxinyusqn",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://gitee.com/wangxinyusqn/cc-pets.git"
10
+ },
11
+ "homepage": "https://gitee.com/wangxinyusqn/cc-pets",
12
+ "bugs": {
13
+ "url": "https://gitee.com/wangxinyusqn/cc-pets/issues"
14
+ },
15
+ "keywords": [
16
+ "codex",
17
+ "claude-code",
18
+ "desktop-pet",
19
+ "macos",
20
+ "appkit"
21
+ ],
22
+ "os": [
23
+ "darwin"
24
+ ],
25
+ "cpu": [
26
+ "arm64",
27
+ "x64"
28
+ ],
29
+ "files": [
30
+ "bin",
31
+ "scripts",
32
+ "Resources/Info.plist",
33
+ "Sources/CodexPet/main.m",
34
+ "Sources/CodexPet/Resources",
35
+ "README.md",
36
+ "CHANGELOG.md",
37
+ "CONTRIBUTING.md",
38
+ "SECURITY.md",
39
+ "THIRD_PARTY_NOTICES.md",
40
+ "LICENSE"
41
+ ],
42
+ "bin": {
43
+ "codex-pet": "bin/codex-pet",
44
+ "codex-with-pet": "bin/codex-with-pet",
45
+ "claude-with-pet": "bin/claude-with-pet"
46
+ },
47
+ "scripts": {
48
+ "build": "./scripts/build.sh",
49
+ "test": "./tests/test.sh",
50
+ "postinstall": "./scripts/build.sh",
51
+ "prepack": "npm test"
52
+ },
53
+ "publishConfig": {
54
+ "access": "public"
55
+ },
56
+ "engines": {
57
+ "node": ">=18"
58
+ }
59
+ }
@@ -0,0 +1,32 @@
1
+ #!/bin/zsh
2
+ set -eu
3
+
4
+ SCRIPT_DIR="${0:A:h}"
5
+ PROJECT_DIR="${SCRIPT_DIR:h}"
6
+ BUILD_DIR="${PROJECT_DIR}/.build/release"
7
+ CACHE_DIR="${PROJECT_DIR}/.build/clang-cache"
8
+ APP_DIR="${BUILD_DIR}/CodexPet.app"
9
+ APP_MACOS_DIR="${APP_DIR}/Contents/MacOS"
10
+ APP_RESOURCES_DIR="${APP_DIR}/Contents/Resources"
11
+ RESOURCE_DIR="${PET_RESOURCE_DIR:-${PROJECT_DIR}/Sources/CodexPet/Resources}"
12
+ mkdir -p "${BUILD_DIR}" "${CACHE_DIR}" "${APP_MACOS_DIR}" "${APP_RESOURCES_DIR}"
13
+
14
+ CLANG_MODULE_CACHE_PATH="${CACHE_DIR}" clang \
15
+ -fobjc-arc \
16
+ -fmodules-cache-path="${CACHE_DIR}" \
17
+ -mmacosx-version-min=13.0 \
18
+ -framework Cocoa \
19
+ "${PROJECT_DIR}/Sources/CodexPet/main.m" \
20
+ -o "${BUILD_DIR}/codex-pet"
21
+
22
+ find "${BUILD_DIR}" -maxdepth 1 -type f \( -name '*.webp' -o -name '*.png' \) -delete
23
+ find "${APP_MACOS_DIR}" -maxdepth 1 -type f \( -name '*.webp' -o -name '*.png' \) -delete
24
+ SPRITES=("${RESOURCE_DIR}"/*.webp(N) "${RESOURCE_DIR}"/*.png(N))
25
+ if (( ${#SPRITES[@]} > 0 )); then
26
+ cp "${SPRITES[@]}" "${BUILD_DIR}/"
27
+ cp "${SPRITES[@]}" "${APP_MACOS_DIR}/"
28
+ fi
29
+ cp "${BUILD_DIR}/codex-pet" "${APP_MACOS_DIR}/codex-pet"
30
+ cp "${PROJECT_DIR}/Resources/Info.plist" "${APP_DIR}/Contents/Info.plist"
31
+ print "构建完成: ${BUILD_DIR}/codex-pet"
32
+ print "应用完成: ${APP_DIR}"
@@ -0,0 +1,92 @@
1
+ #!/usr/bin/env node
2
+
3
+ import fs from "node:fs";
4
+ import os from "node:os";
5
+ import path from "node:path";
6
+
7
+ const binary = process.argv[2];
8
+ const statusLineProxy = process.argv[3];
9
+ if (!binary || !statusLineProxy) {
10
+ console.error("用法: install-claude-hooks.mjs /absolute/path/to/codex-pet /absolute/path/to/claude-statusline-with-pet");
11
+ process.exit(2);
12
+ }
13
+
14
+ const claudeHome = process.env.CLAUDE_CONFIG_DIR || path.join(os.homedir(), ".claude");
15
+ const settingsPath = path.join(claudeHome, "settings.json");
16
+ const marker = "CLAUDE_PET_AGENT_HOOK=1";
17
+ const statusLineMarker = "CLAUDE_PET_STATUS_LINE=1";
18
+ const shellQuote = (value) => `'${value.replaceAll("'", `'\\''`)}'`;
19
+ const command = `${marker} ${shellQuote(path.resolve(binary))} --hook`;
20
+ const events = [
21
+ "SessionStart",
22
+ "UserPromptSubmit",
23
+ "PreToolUse",
24
+ "PermissionRequest",
25
+ "PostToolUse",
26
+ "PostToolUseFailure",
27
+ "Notification",
28
+ "SubagentStart",
29
+ "SubagentStop",
30
+ "TaskCreated",
31
+ "TaskCompleted",
32
+ "Stop",
33
+ "StopFailure",
34
+ "SessionEnd"
35
+ ];
36
+
37
+ fs.mkdirSync(claudeHome, { recursive: true });
38
+ let config = {};
39
+ if (fs.existsSync(settingsPath)) {
40
+ try {
41
+ config = JSON.parse(fs.readFileSync(settingsPath, "utf8"));
42
+ } catch (error) {
43
+ console.error(`无法解析 ${settingsPath}: ${error.message}`);
44
+ process.exit(1);
45
+ }
46
+ }
47
+ if (!config || typeof config !== "object" || Array.isArray(config)) config = {};
48
+ if (!config.hooks || typeof config.hooks !== "object" || Array.isArray(config.hooks)) config.hooks = {};
49
+
50
+ for (const [event, groups] of Object.entries(config.hooks)) {
51
+ if (!Array.isArray(groups)) continue;
52
+ config.hooks[event] = groups.flatMap((group) => {
53
+ if (!group || !Array.isArray(group.hooks)) return [group];
54
+ const handlers = group.hooks.filter((handler) =>
55
+ typeof handler?.command !== "string" || !handler.command.includes(marker)
56
+ );
57
+ return handlers.length > 0 ? [{ ...group, hooks: handlers }] : [];
58
+ });
59
+ }
60
+
61
+ for (const event of events) {
62
+ if (!Array.isArray(config.hooks[event])) config.hooks[event] = [];
63
+ config.hooks[event].push({
64
+ hooks: [{ type: "command", command, timeout: 3 }]
65
+ });
66
+ }
67
+
68
+ let originalStatusLineCommand = "";
69
+ if (config.statusLine && typeof config.statusLine === "object" && !Array.isArray(config.statusLine)) {
70
+ const currentCommand = typeof config.statusLine.command === "string" ? config.statusLine.command : "";
71
+ if (currentCommand.includes(statusLineMarker)) {
72
+ const match = currentCommand.match(/'([A-Za-z0-9+/=]*)'\s*$/);
73
+ if (match) originalStatusLineCommand = Buffer.from(match[1], "base64").toString("utf8");
74
+ } else {
75
+ originalStatusLineCommand = currentCommand;
76
+ }
77
+ } else {
78
+ config.statusLine = { type: "command" };
79
+ }
80
+ const encodedOriginal = Buffer.from(originalStatusLineCommand, "utf8").toString("base64");
81
+ config.statusLine = {
82
+ ...config.statusLine,
83
+ type: "command",
84
+ command: `${statusLineMarker} ${shellQuote(path.resolve(statusLineProxy))} ${shellQuote(encodedOriginal)}`
85
+ };
86
+
87
+ const temporaryPath = `${settingsPath}.codex-pet.tmp`;
88
+ fs.writeFileSync(temporaryPath, `${JSON.stringify(config, null, 2)}\n`, { mode: 0o600 });
89
+ fs.renameSync(temporaryPath, settingsPath);
90
+ fs.chmodSync(settingsPath, 0o600);
91
+ console.log(`Claude Code Hooks 已安装到 ${settingsPath}`);
92
+ console.log("Claude 额度采集已接入现有 status line。首次 API 响应后桌宠会显示额度。");
@@ -0,0 +1,65 @@
1
+ #!/usr/bin/env node
2
+
3
+ import fs from "node:fs";
4
+ import os from "node:os";
5
+ import path from "node:path";
6
+
7
+ const binary = process.argv[2];
8
+ if (!binary) {
9
+ console.error("用法: install-codex-hooks.mjs /absolute/path/to/codex-pet");
10
+ process.exit(2);
11
+ }
12
+
13
+ const codexHome = process.env.CODEX_HOME || path.join(os.homedir(), ".codex");
14
+ const hooksPath = path.join(codexHome, "hooks.json");
15
+ const marker = "CODEX_PET_AGENT_HOOK=1";
16
+ const shellQuote = (value) => `'${value.replaceAll("'", `'\\''`)}'`;
17
+ const command = `${marker} ${shellQuote(path.resolve(binary))} --hook`;
18
+ const events = [
19
+ "SessionStart",
20
+ "UserPromptSubmit",
21
+ "PreToolUse",
22
+ "PermissionRequest",
23
+ "PostToolUse",
24
+ "SubagentStart",
25
+ "SubagentStop",
26
+ "Stop"
27
+ ];
28
+
29
+ fs.mkdirSync(codexHome, { recursive: true });
30
+ let config = {};
31
+ if (fs.existsSync(hooksPath)) {
32
+ try {
33
+ config = JSON.parse(fs.readFileSync(hooksPath, "utf8"));
34
+ } catch (error) {
35
+ console.error(`无法解析 ${hooksPath}: ${error.message}`);
36
+ process.exit(1);
37
+ }
38
+ }
39
+ if (!config || typeof config !== "object" || Array.isArray(config)) config = {};
40
+ if (!config.hooks || typeof config.hooks !== "object" || Array.isArray(config.hooks)) config.hooks = {};
41
+
42
+ for (const [event, groups] of Object.entries(config.hooks)) {
43
+ if (!Array.isArray(groups)) continue;
44
+ config.hooks[event] = groups.flatMap((group) => {
45
+ if (!group || !Array.isArray(group.hooks)) return [group];
46
+ const handlers = group.hooks.filter((handler) =>
47
+ typeof handler?.command !== "string" || !handler.command.includes(marker)
48
+ );
49
+ return handlers.length > 0 ? [{ ...group, hooks: handlers }] : [];
50
+ });
51
+ }
52
+
53
+ for (const event of events) {
54
+ if (!Array.isArray(config.hooks[event])) config.hooks[event] = [];
55
+ config.hooks[event].push({
56
+ hooks: [{ type: "command", command, timeout: 3 }]
57
+ });
58
+ }
59
+
60
+ const temporaryPath = `${hooksPath}.codex-pet.tmp`;
61
+ fs.writeFileSync(temporaryPath, `${JSON.stringify(config, null, 2)}\n`, { mode: 0o600 });
62
+ fs.renameSync(temporaryPath, hooksPath);
63
+ fs.chmodSync(hooksPath, 0o600);
64
+ console.log(`Codex Agent Hooks 已安装到 ${hooksPath}`);
65
+ console.log("下次启动 Codex 后,请执行 /hooks 并信任 CC Pets Hooks。");
@@ -0,0 +1,51 @@
1
+ #!/bin/zsh
2
+ set -eu
3
+
4
+ SCRIPT_DIR="${0:A:h}"
5
+ PROJECT_DIR="${SCRIPT_DIR:h}"
6
+ LAUNCHER="${PROJECT_DIR}/bin/codex-with-pet"
7
+ CLAUDE_LAUNCHER="${PROJECT_DIR}/bin/claude-with-pet"
8
+ SHELL_RC="${ZDOTDIR:-${HOME}}/.zshrc"
9
+ START_MARKER="# >>> codex-pet >>>"
10
+ END_MARKER="# <<< codex-pet <<<"
11
+ CLAUDE_START_MARKER="# >>> claude-pet >>>"
12
+ CLAUDE_END_MARKER="# <<< claude-pet <<<"
13
+
14
+ "${PROJECT_DIR}/scripts/build.sh"
15
+ node "${PROJECT_DIR}/scripts/install-codex-hooks.mjs" "${PROJECT_DIR}/.build/release/codex-pet"
16
+ node "${PROJECT_DIR}/scripts/install-claude-hooks.mjs" \
17
+ "${PROJECT_DIR}/.build/release/codex-pet" \
18
+ "${PROJECT_DIR}/bin/claude-statusline-with-pet"
19
+
20
+ PET_APP="${PROJECT_DIR}/.build/release/CodexPet.app"
21
+ PET_APP_EXECUTABLE="${PET_APP}/Contents/MacOS/codex-pet"
22
+ if pgrep -f "${PET_APP_EXECUTABLE}" >/dev/null 2>&1; then
23
+ pkill -f "${PET_APP_EXECUTABLE}" || true
24
+ for _ in {1..30}; do
25
+ pgrep -f "${PET_APP_EXECUTABLE}" >/dev/null 2>&1 || break
26
+ sleep 0.1
27
+ done
28
+ open -g "${PET_APP}" --args --managed
29
+ print "已重启正在运行的桌宠,使新版本立即生效。"
30
+ fi
31
+
32
+ if ! grep -Fq "${START_MARKER}" "${SHELL_RC}" 2>/dev/null; then
33
+ {
34
+ print ""
35
+ print "${START_MARKER}"
36
+ print "alias codex=${(q)LAUNCHER}"
37
+ print "${END_MARKER}"
38
+ } >> "${SHELL_RC}"
39
+ fi
40
+
41
+ if ! grep -Fq "${CLAUDE_START_MARKER}" "${SHELL_RC}" 2>/dev/null; then
42
+ {
43
+ print ""
44
+ print "${CLAUDE_START_MARKER}"
45
+ print "alias claude=${(q)CLAUDE_LAUNCHER}"
46
+ print "${CLAUDE_END_MARKER}"
47
+ } >> "${SHELL_RC}"
48
+ fi
49
+
50
+ print "安装完成。执行 source ${(q)SHELL_RC},之后运行 codex 或 claude 会自动启动桌宠。"
51
+ print "首次启动后执行 /hooks,信任 CC Pets Hooks 以启用 Agent 工作动画。"
@@ -0,0 +1,103 @@
1
+ #!/usr/bin/env node
2
+
3
+ import fs from "node:fs";
4
+ import os from "node:os";
5
+ import path from "node:path";
6
+
7
+ const codexHome = process.env.CODEX_HOME || path.join(os.homedir(), ".codex");
8
+ const claudeHome = process.env.CLAUDE_CONFIG_DIR || path.join(os.homedir(), ".claude");
9
+ const shellRC = process.argv[2];
10
+
11
+ function writeJSON(filePath, value) {
12
+ const temporaryPath = `${filePath}.cc-pets.tmp`;
13
+ fs.writeFileSync(temporaryPath, `${JSON.stringify(value, null, 2)}\n`, { mode: 0o600 });
14
+ fs.renameSync(temporaryPath, filePath);
15
+ fs.chmodSync(filePath, 0o600);
16
+ }
17
+
18
+ function removeHookHandlers(config, marker) {
19
+ if (!config?.hooks || typeof config.hooks !== "object" || Array.isArray(config.hooks)) return false;
20
+ let changed = false;
21
+ for (const [event, groups] of Object.entries(config.hooks)) {
22
+ if (!Array.isArray(groups)) continue;
23
+ const filteredGroups = groups.flatMap((group) => {
24
+ if (!group || !Array.isArray(group.hooks)) return [group];
25
+ const handlers = group.hooks.filter((handler) =>
26
+ typeof handler?.command !== "string" || !handler.command.includes(marker)
27
+ );
28
+ if (handlers.length !== group.hooks.length) changed = true;
29
+ return handlers.length > 0 ? [{ ...group, hooks: handlers }] : [];
30
+ });
31
+ if (filteredGroups.length > 0) config.hooks[event] = filteredGroups;
32
+ else delete config.hooks[event];
33
+ }
34
+ if (Object.keys(config.hooks).length === 0) delete config.hooks;
35
+ return changed;
36
+ }
37
+
38
+ function updateJSON(filePath, updater) {
39
+ if (!fs.existsSync(filePath)) return false;
40
+ let config;
41
+ try {
42
+ config = JSON.parse(fs.readFileSync(filePath, "utf8"));
43
+ } catch (error) {
44
+ console.error(`无法解析 ${filePath},未做修改: ${error.message}`);
45
+ process.exitCode = 1;
46
+ return false;
47
+ }
48
+ if (!config || typeof config !== "object" || Array.isArray(config)) return false;
49
+ if (!updater(config)) return false;
50
+ writeJSON(filePath, config);
51
+ return true;
52
+ }
53
+
54
+ const codexHooksPath = path.join(codexHome, "hooks.json");
55
+ const codexChanged = updateJSON(codexHooksPath, (config) =>
56
+ removeHookHandlers(config, "CODEX_PET_AGENT_HOOK=1")
57
+ );
58
+
59
+ const claudeSettingsPath = path.join(claudeHome, "settings.json");
60
+ const claudeChanged = updateJSON(claudeSettingsPath, (config) => {
61
+ let changed = removeHookHandlers(config, "CLAUDE_PET_AGENT_HOOK=1");
62
+ const command = typeof config.statusLine?.command === "string" ? config.statusLine.command : "";
63
+ if (command.includes("CLAUDE_PET_STATUS_LINE=1")) {
64
+ const match = command.match(/'([A-Za-z0-9+/=]*)'\s*$/);
65
+ const originalCommand = match ? Buffer.from(match[1], "base64").toString("utf8") : "";
66
+ if (originalCommand) config.statusLine = { ...config.statusLine, command: originalCommand };
67
+ else delete config.statusLine;
68
+ changed = true;
69
+ }
70
+ return changed;
71
+ });
72
+
73
+ function escapeRegExp(value) {
74
+ return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
75
+ }
76
+
77
+ function removeMarkedBlock(text, startMarker, endMarker) {
78
+ const expression = new RegExp(
79
+ `(^|\\n)${escapeRegExp(startMarker)}\\n[\\s\\S]*?${escapeRegExp(endMarker)}(?=\\n|$)`,
80
+ "g"
81
+ );
82
+ return text.replace(expression, "");
83
+ }
84
+
85
+ let shellChanged = false;
86
+ if (shellRC && fs.existsSync(shellRC)) {
87
+ const original = fs.readFileSync(shellRC, "utf8");
88
+ let updated = removeMarkedBlock(original, "# >>> codex-pet >>>", "# <<< codex-pet <<<");
89
+ updated = removeMarkedBlock(updated, "# >>> claude-pet >>>", "# <<< claude-pet <<<");
90
+ updated = updated.replace(/\n{3,}/g, "\n\n");
91
+ if (updated !== original) {
92
+ const mode = fs.statSync(shellRC).mode;
93
+ const temporaryPath = `${shellRC}.cc-pets.tmp`;
94
+ fs.writeFileSync(temporaryPath, updated, { mode });
95
+ fs.renameSync(temporaryPath, shellRC);
96
+ shellChanged = true;
97
+ }
98
+ }
99
+
100
+ if (codexChanged) console.log(`已移除 ${codexHooksPath} 中的 CC Pets Hooks。`);
101
+ if (claudeChanged) console.log(`已移除 ${claudeSettingsPath} 中的 CC Pets Hooks,并恢复原 status line。`);
102
+ if (shellChanged) console.log(`已移除 ${shellRC} 中的 CC Pets aliases。`);
103
+ if (!codexChanged && !claudeChanged && !shellChanged) console.log("未发现需要移除的 CC Pets 集成。 ");
@@ -0,0 +1,15 @@
1
+ #!/bin/zsh
2
+ set -eu
3
+
4
+ SCRIPT_DIR="${0:A:h}"
5
+ PROJECT_DIR="${SCRIPT_DIR:h}"
6
+ SHELL_RC="${ZDOTDIR:-${HOME}}/.zshrc"
7
+ PET_APP_EXECUTABLE="${PROJECT_DIR}/.build/release/CodexPet.app/Contents/MacOS/codex-pet"
8
+
9
+ node "${PROJECT_DIR}/scripts/uninstall-integrations.mjs" "${SHELL_RC}"
10
+
11
+ if [[ "${CODEX_PET_SKIP_APP_STOP:-0}" != "1" ]] && pgrep -f "${PET_APP_EXECUTABLE}" >/dev/null 2>&1; then
12
+ pkill -f "${PET_APP_EXECUTABLE}" || true
13
+ fi
14
+
15
+ print "卸载集成完成。执行 source ${(q)SHELL_RC} 更新当前终端;如需删除 npm 包,再执行 npm uninstall -g cc-pets。"