cc-pets 2.1.1 → 2.2.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 -0
- package/CC_BRIDGE.zh-CN.md +4 -0
- package/CHANGELOG.md +40 -1
- package/CHANGELOG.zh-CN.md +40 -1
- package/CONTRIBUTING.md +54 -0
- package/CONTRIBUTING.zh-CN.md +45 -0
- package/README.md +57 -14
- package/README.zh-CN.md +56 -14
- package/Resources/Info.plist +3 -1
- package/Resources/en.lproj/InfoPlist.strings +1 -0
- package/Resources/phrases.default.en.txt +182 -0
- package/Resources/zh-Hans.lproj/InfoPlist.strings +1 -0
- package/Resources/zh-Hans.lproj/Localizable.strings +332 -0
- package/Sources/CCPets/CCPetsAppDelegate+AgentEvents.m +215 -0
- package/Sources/CCPets/CCPetsAppDelegate+AgentStatus.m +660 -0
- package/Sources/CCPets/CCPetsAppDelegate+Bridge.m +299 -0
- package/Sources/CCPets/CCPetsAppDelegate+Pets.m +185 -0
- package/Sources/CCPets/CCPetsAppDelegate+Private.h +325 -0
- package/Sources/CCPets/CCPetsAppDelegate+Quota.m +216 -0
- package/Sources/CCPets/CCPetsAppDelegate+Settings.m +226 -0
- package/Sources/CCPets/CCPetsAppDelegate+Speech.m +392 -0
- package/Sources/CCPets/CCPetsAppDelegate+Update.m +459 -0
- package/Sources/CCPets/CCPetsAppDelegate.h +13 -14
- package/Sources/CCPets/CCPetsAppDelegate.m +68 -2466
- package/Sources/CCPets/CCPetsCleanup.h +4 -0
- package/Sources/CCPets/CCPetsCleanup.m +41 -7
- package/Sources/CCPets/CCPetsEvents.m +4 -3
- package/Sources/CCPets/CCPetsL10n.h +55 -0
- package/Sources/CCPets/CCPetsL10n.m +219 -0
- package/Sources/CCPets/CCPetsPaths.h +0 -1
- package/Sources/CCPets/CCPetsPaths.m +0 -1
- package/Sources/CCPets/CCPetsPhrases.h +7 -1
- package/Sources/CCPets/CCPetsPhrases.m +86 -31
- package/Sources/CCPets/CCPetsPhrasesEditor.m +62 -64
- package/Sources/CCPets/CCPetsPreviews.m +7 -6
- package/Sources/CCPets/CCPetsUsage.h +0 -1
- package/Sources/CCPets/CCPetsUsage.m +0 -3
- package/Sources/CCPets/CCPetsVersion.h +10 -0
- package/Sources/CCPets/CCPetsVersion.m +92 -2
- package/Sources/CCPets/MenuToggleSwitch.m +3 -2
- package/Sources/CCPets/PetView.h +2 -0
- package/Sources/CCPets/PetView.m +115 -74
- package/Sources/CCPets/QuotaDashboardView.m +122 -88
- package/Sources/CCPets/main.m +16 -1
- package/bin/cc-pets +25 -20
- package/bin/claude-with-pet +2 -1
- package/bin/codex-with-pet +2 -1
- package/package.json +5 -3
- package/scripts/bridge/cli.mjs +47 -39
- package/scripts/bridge/core.mjs +28 -27
- package/scripts/bridge/hook.mjs +7 -6
- package/scripts/bridge/install.mjs +42 -19
- package/scripts/bridge/mcp-server.mjs +79 -71
- package/scripts/bridge/options.mjs +7 -6
- package/scripts/bridge/process.mjs +22 -0
- package/scripts/bridge/reservations.mjs +6 -5
- package/scripts/bridge/store.mjs +10 -9
- package/scripts/build.sh +24 -5
- package/scripts/check-l10n.mjs +168 -0
- package/scripts/configure-updater.mjs +4 -3
- package/scripts/doctor.mjs +470 -0
- package/scripts/i18n.mjs +122 -0
- package/scripts/i18n.zsh +66 -0
- package/scripts/install-app.sh +3 -2
- package/scripts/install-claude-hooks.mjs +22 -27
- package/scripts/install-codex-hooks.mjs +10 -15
- package/scripts/install-shell-integration.sh +6 -5
- package/scripts/integration-markers.mjs +51 -0
- package/scripts/locales/zh-Hans.json +366 -0
- package/scripts/pet-store.mjs +47 -45
- package/scripts/uninstall-app.sh +4 -3
- package/scripts/uninstall-integrations.mjs +24 -51
- package/scripts/uninstall-shell-integration.sh +8 -7
- /package/Resources/{phrases.default.txt → phrases.default.zh-Hans.txt} +0 -0
package/scripts/i18n.mjs
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
// Node 端(cc-pets 子命令、hook、CC Bridge)的多语言,和 App 端 CCPetsL10n 同一套约定:
|
|
2
|
+
// 源码里写英文原文,它就是 scripts/locales/<语言>.json 的 key;英文直接原样输出。
|
|
3
|
+
// 参数用 {name} 占位,第二个参数传 { name: 值 }。
|
|
4
|
+
//
|
|
5
|
+
// 支持哪些语言不写在代码里:英文之外,scripts/locales 下有 <语言>.json 的就算支持。
|
|
6
|
+
//
|
|
7
|
+
// 语言的来源依次是:
|
|
8
|
+
// 1. CC_PETS_LANGUAGE(en / zh-Hans / zh…,测试和临时切换用)
|
|
9
|
+
// 2. ~/.cc-pets/language(可用 CC_PETS_HOME 覆盖):桌宠把右键菜单里选定的语言写在这里,
|
|
10
|
+
// 这样终端里的输出和桌宠界面是同一种语言
|
|
11
|
+
// 3. LC_ALL / LC_MESSAGES / LANG,再退到 Intl 的默认 locale
|
|
12
|
+
// 都匹配不上时用英文。匹配规则同 App:先比完整标识或前缀(zh-Hans-CN → zh-Hans),
|
|
13
|
+
// 再只比主语言(zh_CN → zh-Hans、ja_JP → ja)。
|
|
14
|
+
//
|
|
15
|
+
// zsh 脚本通过命令行入口用同一套表:node i18n.mjs <英文原文> [name=value …],见 i18n.zsh。
|
|
16
|
+
import fs from "node:fs";
|
|
17
|
+
import os from "node:os";
|
|
18
|
+
import path from "node:path";
|
|
19
|
+
import { fileURLToPath } from "node:url";
|
|
20
|
+
|
|
21
|
+
export const SOURCE_LANGUAGE = "en";
|
|
22
|
+
const localesDirectory = path.join(path.dirname(fileURLToPath(import.meta.url)), "locales");
|
|
23
|
+
|
|
24
|
+
let cachedSupported;
|
|
25
|
+
export function supportedLanguages() {
|
|
26
|
+
if (cachedSupported) return cachedSupported;
|
|
27
|
+
let found = [];
|
|
28
|
+
try {
|
|
29
|
+
found = fs.readdirSync(localesDirectory)
|
|
30
|
+
.filter((name) => name.endsWith(".json"))
|
|
31
|
+
.map((name) => name.slice(0, -".json".length))
|
|
32
|
+
.filter((language) => language !== SOURCE_LANGUAGE)
|
|
33
|
+
.sort();
|
|
34
|
+
} catch {
|
|
35
|
+
found = [];
|
|
36
|
+
}
|
|
37
|
+
cachedSupported = [SOURCE_LANGUAGE, ...found];
|
|
38
|
+
return cachedSupported;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// zh_CN.UTF-8 → zh-cn
|
|
42
|
+
function normalizedTag(value) {
|
|
43
|
+
return String(value || "").trim().toLowerCase().replace(/_/g, "-").split(".")[0];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function matchLanguage(value, supported = supportedLanguages()) {
|
|
47
|
+
const tag = normalizedTag(value);
|
|
48
|
+
if (!tag || tag === "c" || tag === "posix") return "";
|
|
49
|
+
const exact = supported.find((language) => {
|
|
50
|
+
const lower = language.toLowerCase();
|
|
51
|
+
return tag === lower || tag.startsWith(`${lower}-`);
|
|
52
|
+
});
|
|
53
|
+
if (exact) return exact;
|
|
54
|
+
const base = tag.split("-")[0];
|
|
55
|
+
return supported.find((language) => language.toLowerCase().split("-")[0] === base) || "";
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function languageFromFile() {
|
|
59
|
+
const home = process.env.CC_PETS_HOME || path.join(os.homedir(), ".cc-pets");
|
|
60
|
+
try {
|
|
61
|
+
return matchLanguage(fs.readFileSync(path.join(home, "language"), "utf8"));
|
|
62
|
+
} catch {
|
|
63
|
+
return "";
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function languageFromEnvironment() {
|
|
68
|
+
for (const name of ["LC_ALL", "LC_MESSAGES", "LANG"]) {
|
|
69
|
+
const language = matchLanguage(process.env[name]);
|
|
70
|
+
if (language) return language;
|
|
71
|
+
}
|
|
72
|
+
try {
|
|
73
|
+
return matchLanguage(Intl.DateTimeFormat().resolvedOptions().locale);
|
|
74
|
+
} catch {
|
|
75
|
+
return "";
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
let cachedLanguage;
|
|
80
|
+
export function currentLanguage() {
|
|
81
|
+
if (cachedLanguage) return cachedLanguage;
|
|
82
|
+
cachedLanguage = matchLanguage(process.env.CC_PETS_LANGUAGE) || languageFromFile() ||
|
|
83
|
+
languageFromEnvironment() || SOURCE_LANGUAGE;
|
|
84
|
+
return cachedLanguage;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const tables = new Map();
|
|
88
|
+
function table(language) {
|
|
89
|
+
if (!tables.has(language)) {
|
|
90
|
+
try {
|
|
91
|
+
tables.set(language, JSON.parse(fs.readFileSync(path.join(localesDirectory, `${language}.json`), "utf8")));
|
|
92
|
+
} catch {
|
|
93
|
+
tables.set(language, {});
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return tables.get(language);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function interpolate(text, values) {
|
|
100
|
+
if (!values) return text;
|
|
101
|
+
return text.replace(/\{([A-Za-z][A-Za-z0-9]*)\}/g, (match, name) =>
|
|
102
|
+
Object.prototype.hasOwnProperty.call(values, name) ? String(values[name]) : match);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function translate(language, text, values) {
|
|
106
|
+
const translated = language === SOURCE_LANGUAGE ? text : (table(language)[text] || text);
|
|
107
|
+
return interpolate(translated, values);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export function t(text, values) {
|
|
111
|
+
return translate(currentLanguage(), text, values);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// node i18n.mjs <英文原文> [name=value …]
|
|
115
|
+
if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
|
116
|
+
const [text = "", ...pairs] = process.argv.slice(2);
|
|
117
|
+
const values = Object.fromEntries(pairs.map((pair) => {
|
|
118
|
+
const index = pair.indexOf("=");
|
|
119
|
+
return index < 0 ? [pair, ""] : [pair.slice(0, index), pair.slice(index + 1)];
|
|
120
|
+
}));
|
|
121
|
+
process.stdout.write(`${t(text, values)}\n`);
|
|
122
|
+
}
|
package/scripts/i18n.zsh
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# zsh 脚本的多语言,和 scripts/i18n.mjs 共用 scripts/locales/<语言>.json 与同一套判定规则:
|
|
2
|
+
# CC_PETS_LANGUAGE → ~/.cc-pets/language(桌宠菜单里选的语言)→ LC_ALL / LC_MESSAGES / LANG → 英文。
|
|
3
|
+
#
|
|
4
|
+
# print "$(cc_pets_t "Built: {path}" path="${BUILD_DIR}/cc-pets")"
|
|
5
|
+
#
|
|
6
|
+
# 第一个参数是英文原文(也是表的 key),必须是字面量,scripts/check-l10n.mjs 会把它和表对上;
|
|
7
|
+
# 变量一律走 {name} 占位,不能直接写进原文,否则 key 每次都不一样,永远查不到。
|
|
8
|
+
# 英文直接在 zsh 里替换占位符;其他语言交给 node 查表。没有 node(比如正在报"找不到 Node.js")
|
|
9
|
+
# 时退回英文,总比什么都不说好。
|
|
10
|
+
|
|
11
|
+
typeset -g _CC_PETS_I18N_DIR="${${(%):-%x}:A:h}"
|
|
12
|
+
|
|
13
|
+
# 支持的语言:英文加上 locales 下的每个 <语言>.json。
|
|
14
|
+
_cc_pets_languages() {
|
|
15
|
+
print -r -- en "${_CC_PETS_I18N_DIR}"/locales/*.json(N:t:r)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
# 把 zh_CN.UTF-8、zh-Hans-CN 这类写法匹配到支持的语言上;匹配不上输出空。
|
|
19
|
+
_cc_pets_match_language() {
|
|
20
|
+
local tag="${${1:l}//_/-}" language
|
|
21
|
+
tag="${tag%%.*}"
|
|
22
|
+
[[ -z "${tag}" || "${tag}" == c || "${tag}" == posix ]] && return 0
|
|
23
|
+
local -a languages=(${=$(_cc_pets_languages)})
|
|
24
|
+
for language in "${languages[@]}"; do
|
|
25
|
+
if [[ "${tag}" == "${language:l}" || "${tag}" == "${language:l}"-* ]]; then
|
|
26
|
+
print -r -- "${language}"
|
|
27
|
+
return 0
|
|
28
|
+
fi
|
|
29
|
+
done
|
|
30
|
+
for language in "${languages[@]}"; do
|
|
31
|
+
if [[ "${tag%%-*}" == "${${language:l}%%-*}" ]]; then
|
|
32
|
+
print -r -- "${language}"
|
|
33
|
+
return 0
|
|
34
|
+
fi
|
|
35
|
+
done
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
cc_pets_language() {
|
|
39
|
+
local match="" value name
|
|
40
|
+
local language_file="${CC_PETS_HOME:-${HOME}/.cc-pets}/language"
|
|
41
|
+
match="$(_cc_pets_match_language "${CC_PETS_LANGUAGE:-}")"
|
|
42
|
+
if [[ -z "${match}" && -r "${language_file}" ]]; then
|
|
43
|
+
value="$(<"${language_file}")"
|
|
44
|
+
match="$(_cc_pets_match_language "${value}")"
|
|
45
|
+
fi
|
|
46
|
+
if [[ -z "${match}" ]]; then
|
|
47
|
+
for name in LC_ALL LC_MESSAGES LANG; do
|
|
48
|
+
match="$(_cc_pets_match_language "${(P)name:-}")"
|
|
49
|
+
[[ -n "${match}" ]] && break
|
|
50
|
+
done
|
|
51
|
+
fi
|
|
52
|
+
print -r -- "${match:-en}"
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
cc_pets_t() {
|
|
56
|
+
local text="$1" pair language
|
|
57
|
+
shift
|
|
58
|
+
language="$(cc_pets_language)"
|
|
59
|
+
if [[ "${language}" != en ]] && (( $+commands[node] )); then
|
|
60
|
+
CC_PETS_LANGUAGE="${language}" node "${_CC_PETS_I18N_DIR}/i18n.mjs" "${text}" "$@" && return 0
|
|
61
|
+
fi
|
|
62
|
+
for pair in "$@"; do
|
|
63
|
+
text="${text//"{${pair%%=*}}"/${pair#*=}}"
|
|
64
|
+
done
|
|
65
|
+
print -r -- "${text}"
|
|
66
|
+
}
|
package/scripts/install-app.sh
CHANGED
|
@@ -3,6 +3,7 @@ set -eu
|
|
|
3
3
|
|
|
4
4
|
SCRIPT_DIR="${0:A:h}"
|
|
5
5
|
PROJECT_DIR="${SCRIPT_DIR:h}"
|
|
6
|
+
source "${PROJECT_DIR}/scripts/i18n.zsh"
|
|
6
7
|
SOURCE_APP="${PROJECT_DIR}/.build/release/CC Pets.app"
|
|
7
8
|
APPLICATIONS_DIR="${CC_PETS_APPLICATIONS_DIR:-${HOME}/Applications}"
|
|
8
9
|
TARGET_APP="${APPLICATIONS_DIR}/CC Pets.app"
|
|
@@ -29,8 +30,8 @@ if ! mv "${STAGING_APP}" "${TARGET_APP}"; then
|
|
|
29
30
|
if [[ -e "${BACKUP_APP}" ]]; then
|
|
30
31
|
mv "${BACKUP_APP}" "${TARGET_APP}"
|
|
31
32
|
fi
|
|
32
|
-
print -u2 "
|
|
33
|
+
print -u2 "$(cc_pets_t "Failed to install CC Pets.app; the existing app was kept.")"
|
|
33
34
|
exit 1
|
|
34
35
|
fi
|
|
35
36
|
|
|
36
|
-
print "
|
|
37
|
+
print "$(cc_pets_t "App installed: {targetApp}" targetApp="${TARGET_APP}")"
|
|
@@ -5,10 +5,16 @@ import os from "node:os";
|
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import { fileURLToPath } from "node:url";
|
|
7
7
|
import { detectClaudeCLI } from "./detect-cli.mjs";
|
|
8
|
+
import {
|
|
9
|
+
CLAUDE_HOOK, CREATED_STATUS_LINE_MARKER, LEGACY_CLAUDE_HOOK, LEGACY_STATUS_LINE_MARKER,
|
|
10
|
+
STATUS_LINE_END_MARKER, STATUS_LINE_MARKER, STATUS_LINE_START_MARKER,
|
|
11
|
+
isManagedHookCommand, isManagedStatusLine
|
|
12
|
+
} from "./integration-markers.mjs";
|
|
13
|
+
import { t } from "./i18n.mjs";
|
|
8
14
|
|
|
9
15
|
const binary = process.argv[2];
|
|
10
16
|
if (!binary) {
|
|
11
|
-
console.error("
|
|
17
|
+
console.error(t("Usage: install-claude-hooks.mjs /absolute/path/to/cc-pets"));
|
|
12
18
|
process.exit(2);
|
|
13
19
|
}
|
|
14
20
|
|
|
@@ -16,31 +22,20 @@ if (!binary) {
|
|
|
16
22
|
// ~/.claude/statusline-command.sh 并把 settings.json 的 statusLine 指过去,
|
|
17
23
|
// 对还没装 Claude 的用户等于提前替他决定了状态栏。exit 0 的理由见 install-codex-hooks.mjs。
|
|
18
24
|
if (!detectClaudeCLI()) {
|
|
19
|
-
console.log("
|
|
20
|
-
console.log("
|
|
25
|
+
console.log(t("Claude Code CLI not detected; skipping Claude hooks and status line setup."));
|
|
26
|
+
console.log(t("If you install Claude Code later, run cc-pets install to set it up."));
|
|
21
27
|
process.exit(0);
|
|
22
28
|
}
|
|
23
29
|
|
|
24
30
|
const claudeHome = process.env.CLAUDE_CONFIG_DIR || path.join(os.homedir(), ".claude");
|
|
25
31
|
const settingsPath = path.join(claudeHome, "settings.json");
|
|
26
|
-
const marker =
|
|
27
|
-
const statusLineMarker =
|
|
28
|
-
const managedHookSignatures = [
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const
|
|
33
|
-
const statusLineStartMarker = "# >>> cc-pets-statusline >>>";
|
|
34
|
-
const statusLineEndMarker = "# <<< cc-pets-statusline <<<";
|
|
35
|
-
const createdStatusLineMarker = "# CC Pets created this status line script";
|
|
36
|
-
const isManagedHookCommand = (value, signature) =>
|
|
37
|
-
typeof value === "string" &&
|
|
38
|
-
value.startsWith(`${signature.marker} `) &&
|
|
39
|
-
value.endsWith(`/.build/release/${signature.executable}' --hook`);
|
|
40
|
-
const isManagedStatusLine = (value, candidateMarker) =>
|
|
41
|
-
typeof value === "string" &&
|
|
42
|
-
value.startsWith(`${candidateMarker} `) &&
|
|
43
|
-
/\/bin\/claude-statusline-with-pet' '[A-Za-z0-9+/=]*'$/.test(value);
|
|
32
|
+
const marker = CLAUDE_HOOK.marker;
|
|
33
|
+
const statusLineMarker = STATUS_LINE_MARKER;
|
|
34
|
+
const managedHookSignatures = [CLAUDE_HOOK, LEGACY_CLAUDE_HOOK];
|
|
35
|
+
const managedStatusLineMarkers = [STATUS_LINE_MARKER, LEGACY_STATUS_LINE_MARKER];
|
|
36
|
+
const statusLineStartMarker = STATUS_LINE_START_MARKER;
|
|
37
|
+
const statusLineEndMarker = STATUS_LINE_END_MARKER;
|
|
38
|
+
const createdStatusLineMarker = CREATED_STATUS_LINE_MARKER;
|
|
44
39
|
const shellQuote = (value) => `'${value.replaceAll("'", `'\\''`)}'`;
|
|
45
40
|
const escapeRegExp = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
46
41
|
const statusLineBlockPattern = new RegExp(
|
|
@@ -147,7 +142,7 @@ if (fs.existsSync(settingsPath)) {
|
|
|
147
142
|
try {
|
|
148
143
|
config = JSON.parse(fs.readFileSync(settingsPath, "utf8"));
|
|
149
144
|
} catch (error) {
|
|
150
|
-
console.error(
|
|
145
|
+
console.error(t("Can't parse {settingsPath}: {message}", { settingsPath, message: error.message }));
|
|
151
146
|
process.exit(1);
|
|
152
147
|
}
|
|
153
148
|
}
|
|
@@ -242,17 +237,17 @@ if (!statusLineInstalled && originalStatusLineCommand && fs.existsSync(statusLin
|
|
|
242
237
|
}
|
|
243
238
|
|
|
244
239
|
if (!statusLineInstalled && !statusLineWrapped) {
|
|
245
|
-
console.warn(
|
|
246
|
-
console.warn("Claude
|
|
240
|
+
console.warn(t("Claude status line not hooked up: {command}", { command: originalStatusLineCommand || t("(not configured)") }));
|
|
241
|
+
console.warn(t("Claude hooks still work, but the pet can't show Claude quota % (token usage is unaffected)."));
|
|
247
242
|
}
|
|
248
243
|
|
|
249
244
|
const temporaryPath = `${settingsPath}.cc-pets.tmp`;
|
|
250
245
|
fs.writeFileSync(temporaryPath, `${JSON.stringify(config, null, 2)}\n`, { mode: 0o600 });
|
|
251
246
|
fs.renameSync(temporaryPath, settingsPath);
|
|
252
247
|
fs.chmodSync(settingsPath, 0o600);
|
|
253
|
-
console.log(
|
|
248
|
+
console.log(t("Claude Code hooks installed in {settingsPath}", { settingsPath }));
|
|
254
249
|
if (statusLineInstalled) {
|
|
255
|
-
console.log("Claude
|
|
250
|
+
console.log(t("Claude quota tracking added to your existing status line. The pet shows quota after the first API response."));
|
|
256
251
|
} else if (statusLineWrapped) {
|
|
257
|
-
console.log("Claude
|
|
252
|
+
console.log(t("Claude quota tracking added to the status line through a wrapper; your original command still runs. The pet shows quota after the first API response."));
|
|
258
253
|
}
|
|
@@ -4,10 +4,12 @@ import fs from "node:fs";
|
|
|
4
4
|
import os from "node:os";
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import { detectCodexCLI } from "./detect-cli.mjs";
|
|
7
|
+
import { CODEX_HOOK, LEGACY_CODEX_HOOK, isManagedHookCommand } from "./integration-markers.mjs";
|
|
8
|
+
import { t } from "./i18n.mjs";
|
|
7
9
|
|
|
8
10
|
const binary = process.argv[2];
|
|
9
11
|
if (!binary) {
|
|
10
|
-
console.error("
|
|
12
|
+
console.error(t("Usage: install-codex-hooks.mjs /absolute/path/to/cc-pets"));
|
|
11
13
|
process.exit(2);
|
|
12
14
|
}
|
|
13
15
|
|
|
@@ -15,22 +17,15 @@ if (!binary) {
|
|
|
15
17
|
// 这里非零退出会把后面的 Claude Hooks、更新器、shim 和 .zshrc 全部带停,
|
|
16
18
|
// 用户会拿到一个装了一半的状态。
|
|
17
19
|
if (!detectCodexCLI()) {
|
|
18
|
-
console.log("
|
|
19
|
-
console.log("
|
|
20
|
+
console.log(t("Codex CLI not detected; skipping Codex hooks."));
|
|
21
|
+
console.log(t("If you install Codex later, run cc-pets install to set it up."));
|
|
20
22
|
process.exit(0);
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
const codexHome = process.env.CODEX_HOME || path.join(os.homedir(), ".codex");
|
|
24
26
|
const hooksPath = path.join(codexHome, "hooks.json");
|
|
25
|
-
const marker =
|
|
26
|
-
const managedSignatures = [
|
|
27
|
-
{ marker, executable: "cc-pets" },
|
|
28
|
-
{ marker: "CODEX_PET_AGENT_HOOK=1", executable: "codex-pet" }
|
|
29
|
-
];
|
|
30
|
-
const isManagedHookCommand = (value, signature) =>
|
|
31
|
-
typeof value === "string" &&
|
|
32
|
-
value.startsWith(`${signature.marker} `) &&
|
|
33
|
-
value.endsWith(`/.build/release/${signature.executable}' --hook`);
|
|
27
|
+
const marker = CODEX_HOOK.marker;
|
|
28
|
+
const managedSignatures = [CODEX_HOOK, LEGACY_CODEX_HOOK];
|
|
34
29
|
const shellQuote = (value) => `'${value.replaceAll("'", `'\\''`)}'`;
|
|
35
30
|
const command = `${marker} ${shellQuote(path.resolve(binary))} --hook`;
|
|
36
31
|
const events = [
|
|
@@ -50,7 +45,7 @@ if (fs.existsSync(hooksPath)) {
|
|
|
50
45
|
try {
|
|
51
46
|
config = JSON.parse(fs.readFileSync(hooksPath, "utf8"));
|
|
52
47
|
} catch (error) {
|
|
53
|
-
console.error(
|
|
48
|
+
console.error(t("Can't parse {hooksPath}: {message}", { hooksPath, message: error.message }));
|
|
54
49
|
process.exit(1);
|
|
55
50
|
}
|
|
56
51
|
}
|
|
@@ -79,5 +74,5 @@ const temporaryPath = `${hooksPath}.cc-pets.tmp`;
|
|
|
79
74
|
fs.writeFileSync(temporaryPath, `${JSON.stringify(config, null, 2)}\n`, { mode: 0o600 });
|
|
80
75
|
fs.renameSync(temporaryPath, hooksPath);
|
|
81
76
|
fs.chmodSync(hooksPath, 0o600);
|
|
82
|
-
console.log(
|
|
83
|
-
console.log("
|
|
77
|
+
console.log(t("Codex agent hooks installed in {hooksPath}", { hooksPath }));
|
|
78
|
+
console.log(t("Next time you start Codex, run /hooks and trust the CC Pets hooks."));
|
|
@@ -3,6 +3,7 @@ set -eu
|
|
|
3
3
|
|
|
4
4
|
SCRIPT_DIR="${0:A:h}"
|
|
5
5
|
PROJECT_DIR="${SCRIPT_DIR:h}"
|
|
6
|
+
source "${PROJECT_DIR}/scripts/i18n.zsh"
|
|
6
7
|
LAUNCHER="${PROJECT_DIR}/bin/codex-with-pet"
|
|
7
8
|
CLAUDE_LAUNCHER="${PROJECT_DIR}/bin/claude-with-pet"
|
|
8
9
|
SHELL_RC="${ZDOTDIR:-${HOME}}/.zshrc"
|
|
@@ -15,7 +16,7 @@ if [[ -z "${NODE_EXECUTABLE}" || ! -x "${NODE_EXECUTABLE}" ]]; then
|
|
|
15
16
|
NODE_EXECUTABLE="$(command -v node || true)"
|
|
16
17
|
fi
|
|
17
18
|
if [[ -z "${NODE_EXECUTABLE}" || ! -x "${NODE_EXECUTABLE}" ]]; then
|
|
18
|
-
print -u2 "
|
|
19
|
+
print -u2 "$(cc_pets_t "Install failed: no executable Node.js found.")"
|
|
19
20
|
exit 1
|
|
20
21
|
fi
|
|
21
22
|
export PATH="${NODE_EXECUTABLE:h}:${PATH:-/usr/bin:/bin:/usr/sbin:/sbin}"
|
|
@@ -29,7 +30,7 @@ export PATH="${NODE_EXECUTABLE:h}:${PATH:-/usr/bin:/bin:/usr/sbin:/sbin}"
|
|
|
29
30
|
"${NODE_EXECUTABLE}" "${PROJECT_DIR}/scripts/configure-updater.mjs"
|
|
30
31
|
# CC Bridge 默认关闭;用户开启过的话,包路径可能随升级变化,按原选项重写一遍集成。
|
|
31
32
|
"${NODE_EXECUTABLE}" "${PROJECT_DIR}/scripts/bridge/cli.mjs" refresh || \
|
|
32
|
-
print -u2 "CC Bridge
|
|
33
|
+
print -u2 "$(cc_pets_t "Failed to refresh the CC Bridge integration; retry later with cc-pets bridge enable.")"
|
|
33
34
|
|
|
34
35
|
PET_APP="${PROJECT_DIR}/.build/release/CC Pets.app"
|
|
35
36
|
PET_APP_EXECUTABLE="${PET_APP}/Contents/MacOS/cc-pets"
|
|
@@ -53,7 +54,7 @@ if (( PET_WAS_RUNNING )); then
|
|
|
53
54
|
sleep 0.1
|
|
54
55
|
done
|
|
55
56
|
open -g "${INSTALLED_PET_APP}" --args --managed
|
|
56
|
-
print "
|
|
57
|
+
print "$(cc_pets_t "Restarted the running pet so the new version takes effect now.")"
|
|
57
58
|
fi
|
|
58
59
|
|
|
59
60
|
# 早期版本用 alias 接管 codex / claude。alias 名区分大小写,而 macOS 文件系统默认不区分:
|
|
@@ -77,5 +78,5 @@ if ! grep -Fq "${SHIM_START_MARKER}" "${SHELL_RC}" 2>/dev/null; then
|
|
|
77
78
|
} >> "${SHELL_RC}"
|
|
78
79
|
fi
|
|
79
80
|
|
|
80
|
-
print "
|
|
81
|
-
print "
|
|
81
|
+
print "$(cc_pets_t "Installed. CC Pets was added to {installedPetApp}. Run source {shellRc}; after that, running codex or claude (in any capitalization) starts the pet automatically." installedPetApp="${(q)INSTALLED_PET_APP}" shellRc="${(q)SHELL_RC}")"
|
|
82
|
+
print "$(cc_pets_t "After the first launch, run /hooks and trust the CC Pets hooks to enable Agent animations.")"
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import os from "node:os";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
|
|
4
|
+
// CC Pets 写进 Claude Code / Codex 配置里的条目怎么认。安装、卸载、cc-pets doctor 共用这一份,
|
|
5
|
+
// 以免哪天改了写法,doctor 还按旧规则说"一切正常"。
|
|
6
|
+
|
|
7
|
+
export const CODEX_HOOK = { marker: "CC_PETS_CODEX_AGENT_HOOK=1", executable: "cc-pets" };
|
|
8
|
+
export const LEGACY_CODEX_HOOK = { marker: "CODEX_PET_AGENT_HOOK=1", executable: "codex-pet" };
|
|
9
|
+
export const CLAUDE_HOOK = { marker: "CC_PETS_CLAUDE_AGENT_HOOK=1", executable: "cc-pets" };
|
|
10
|
+
export const LEGACY_CLAUDE_HOOK = { marker: "CLAUDE_PET_AGENT_HOOK=1", executable: "codex-pet" };
|
|
11
|
+
|
|
12
|
+
export const STATUS_LINE_MARKER = "CC_PETS_CLAUDE_STATUS_LINE=1";
|
|
13
|
+
export const LEGACY_STATUS_LINE_MARKER = "CLAUDE_PET_STATUS_LINE=1";
|
|
14
|
+
export const STATUS_LINE_START_MARKER = "# >>> cc-pets-statusline >>>";
|
|
15
|
+
export const STATUS_LINE_END_MARKER = "# <<< cc-pets-statusline <<<";
|
|
16
|
+
export const CREATED_STATUS_LINE_MARKER = "# CC Pets created this status line script";
|
|
17
|
+
|
|
18
|
+
export const SHIM_START_MARKER = "# >>> cc-pets-shims >>>";
|
|
19
|
+
export const SHIM_END_MARKER = "# <<< cc-pets-shims <<<";
|
|
20
|
+
|
|
21
|
+
export const isManagedHookCommand = (value, signature) =>
|
|
22
|
+
typeof value === "string" &&
|
|
23
|
+
value.startsWith(`${signature.marker} `) &&
|
|
24
|
+
value.endsWith(`/.build/release/${signature.executable}' --hook`);
|
|
25
|
+
|
|
26
|
+
export const isManagedStatusLine = (value, marker) =>
|
|
27
|
+
typeof value === "string" &&
|
|
28
|
+
value.startsWith(`${marker} `) &&
|
|
29
|
+
/\/bin\/claude-statusline-with-pet' '[A-Za-z0-9+/=]*'$/.test(value);
|
|
30
|
+
|
|
31
|
+
// `bash ~/x.sh` 这类带解释器前缀的命令同样指向一个被就地注入过的脚本;带 -c 的不算,
|
|
32
|
+
// `-c` 后面是命令串而非脚本路径。install-claude-hooks.mjs 另有一份返回更多字段的解析,规则一致。
|
|
33
|
+
const interpreterPattern =
|
|
34
|
+
/^(?:\/usr\/bin\/env\s+)?(?:[^\s'"]*\/)?(?:ba|z|k|da)?sh((?:\s+-[A-Za-z]+)*)\s+(.+)$/s;
|
|
35
|
+
|
|
36
|
+
const unquote = (value) => {
|
|
37
|
+
const quoted = value.match(/^(['"])(.*)\1$/s);
|
|
38
|
+
return quoted ? quoted[2] : value;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export const resolveStatusLineScript = (value) => {
|
|
42
|
+
if (typeof value !== "string") return null;
|
|
43
|
+
let candidate = unquote(value.trim());
|
|
44
|
+
const interpreted = candidate.match(interpreterPattern);
|
|
45
|
+
if (interpreted && !/-[A-Za-z]*c(?=\s|$)/.test(interpreted[1])) {
|
|
46
|
+
candidate = unquote(interpreted[2].trim());
|
|
47
|
+
}
|
|
48
|
+
if (candidate.startsWith("~/")) candidate = path.join(os.homedir(), candidate.slice(2));
|
|
49
|
+
if (!path.isAbsolute(candidate) || /[\s;&|<>`$()]/.test(candidate)) return null;
|
|
50
|
+
return path.resolve(candidate);
|
|
51
|
+
};
|