cc-pets 2.1.2 → 2.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 +42 -0
- package/CHANGELOG.zh-CN.md +42 -0
- package/CONTRIBUTING.md +68 -0
- package/CONTRIBUTING.zh-CN.md +56 -0
- package/README.md +47 -31
- package/README.zh-CN.md +39 -20
- 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 +337 -0
- package/Sources/CCPets/CCPetsAppDelegate+AgentStatus.m +35 -36
- package/Sources/CCPets/CCPetsAppDelegate+Bridge.m +16 -14
- package/Sources/CCPets/CCPetsAppDelegate+Pets.m +8 -10
- package/Sources/CCPets/CCPetsAppDelegate+Private.h +33 -9
- package/Sources/CCPets/CCPetsAppDelegate+Settings.m +84 -8
- package/Sources/CCPets/CCPetsAppDelegate+Speech.m +7 -5
- package/Sources/CCPets/CCPetsAppDelegate+Update.m +104 -79
- package/Sources/CCPets/CCPetsAppDelegate.h +1 -2
- package/Sources/CCPets/CCPetsAppDelegate.m +23 -15
- package/Sources/CCPets/CCPetsCleanup.m +9 -6
- package/Sources/CCPets/CCPetsEvents.m +4 -3
- package/Sources/CCPets/CCPetsImageLoader.h +2 -1
- package/Sources/CCPets/CCPetsImageLoader.m +10 -2
- package/Sources/CCPets/CCPetsL10n.h +55 -0
- package/Sources/CCPets/CCPetsL10n.m +219 -0
- package/Sources/CCPets/CCPetsPetSize.h +10 -0
- package/Sources/CCPets/CCPetsPetSize.m +21 -0
- package/Sources/CCPets/CCPetsPhrases.h +14 -1
- package/Sources/CCPets/CCPetsPhrases.m +107 -38
- package/Sources/CCPets/CCPetsPhrasesEditor.m +100 -65
- package/Sources/CCPets/CCPetsPreviews.m +7 -6
- package/Sources/CCPets/CCPetsVersion.h +7 -4
- package/Sources/CCPets/CCPetsVersion.m +14 -6
- package/Sources/CCPets/MenuChoiceRow.m +3 -0
- package/Sources/CCPets/MenuPetSizeView.h +5 -0
- package/Sources/CCPets/MenuPetSizeView.m +73 -0
- package/Sources/CCPets/MenuToggleSwitch.m +3 -2
- package/Sources/CCPets/PetView.m +156 -94
- package/Sources/CCPets/QuotaDashboardView.m +122 -85
- package/Sources/CCPets/main.m +3 -1
- package/bin/cc-pets +21 -22
- package/bin/claude-with-pet +2 -1
- package/bin/codex-with-pet +2 -1
- package/package.json +3 -2
- package/scripts/bridge/cli.mjs +39 -38
- package/scripts/bridge/core.mjs +27 -26
- package/scripts/bridge/hook.mjs +7 -6
- package/scripts/bridge/install.mjs +24 -23
- package/scripts/bridge/mcp-server.mjs +79 -71
- package/scripts/bridge/options.mjs +7 -6
- 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 +93 -79
- 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 +10 -9
- package/scripts/install-codex-hooks.mjs +7 -6
- package/scripts/install-shell-integration.sh +6 -5
- package/scripts/locales/zh-Hans.json +366 -0
- package/scripts/pet-store.mjs +45 -44
- package/scripts/uninstall-app.sh +4 -3
- package/scripts/uninstall-integrations.mjs +8 -7
- package/scripts/uninstall-shell-integration.sh +8 -7
- /package/Resources/{phrases.default.txt → phrases.default.zh-Hans.txt} +0 -0
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// 多语言自检。源码里写英文原文,它就是各语言表的 key:
|
|
3
|
+
// - App:L(@"…")(见 Sources/CCPets/CCPetsL10n.h)↔ Resources/<语言>.lproj/Localizable.strings
|
|
4
|
+
// - CLI:Node 的 t("…")(见 scripts/i18n.mjs)和 zsh 的 cc_pets_t "…"(见 scripts/i18n.zsh)
|
|
5
|
+
// ↔ scripts/locales/<语言>.json
|
|
6
|
+
// 改了英文原文却忘了改表,那种语言的界面就会漏出英文,而且不报任何错。这里把每种语言的表
|
|
7
|
+
// 都和源码逐条对上(有几张表就查几张,加语言不用改这里):
|
|
8
|
+
// - 缺翻译:代码里有、表里没有 → 失败
|
|
9
|
+
// - 多余:表里有、代码里已经没有 → 失败(多半是英文原文改过了,旧 key 成了孤儿)
|
|
10
|
+
// - 占位符对不上:%@ / %ld / {name} 的个数或名字不一致 → 失败
|
|
11
|
+
// - App 表缺元信息(语言名、Release 段落标题)→ 失败
|
|
12
|
+
// - App 和 CLI 支持的语言不一致 → 失败
|
|
13
|
+
//
|
|
14
|
+
// node scripts/check-l10n.mjs 检查,有问题时退出码 1
|
|
15
|
+
// node scripts/check-l10n.mjs --missing <语言> 只把这种语言缺的 key 按 JSON 打出来,方便补表
|
|
16
|
+
import fs from "node:fs";
|
|
17
|
+
import path from "node:path";
|
|
18
|
+
import { execFileSync } from "node:child_process";
|
|
19
|
+
import { fileURLToPath } from "node:url";
|
|
20
|
+
|
|
21
|
+
const projectDir = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
|
|
22
|
+
const sourceDir = path.join(projectDir, "Sources", "CCPets");
|
|
23
|
+
const resourcesDir = path.join(projectDir, "Resources");
|
|
24
|
+
const localesDir = path.join(projectDir, "scripts", "locales");
|
|
25
|
+
// 与 CCPetsL10n.h 里的 CCPetsLanguageNameKey / CCPetsReleaseNotesSectionKey 一致。
|
|
26
|
+
const APP_META_KEYS = ["Language Name", "Release Notes Section"];
|
|
27
|
+
const SKIPPED_SCRIPTS = new Set(["check-l10n.mjs", "i18n.mjs", "i18n.zsh"]);
|
|
28
|
+
|
|
29
|
+
function unescapeC(text) {
|
|
30
|
+
return text.replace(/\\(["\\nt])/g, (_, ch) => ({ n: "\n", t: "\t" })[ch] ?? ch);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function lineOf(text, index) {
|
|
34
|
+
return text.slice(0, index).split("\n").length;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// L(@"a" "b" @"c") 这类跨行拼接也算一个 key。
|
|
38
|
+
function objcKeys() {
|
|
39
|
+
const keys = new Map();
|
|
40
|
+
const call = /\bL\(\s*((?:@?"(?:[^"\\]|\\.)*"\s*)+)\)/g;
|
|
41
|
+
const piece = /@?"((?:[^"\\]|\\.)*)"/g;
|
|
42
|
+
for (const name of fs.readdirSync(sourceDir).filter((file) => file.endsWith(".m")).sort()) {
|
|
43
|
+
const text = fs.readFileSync(path.join(sourceDir, name), "utf8");
|
|
44
|
+
for (const match of text.matchAll(call)) {
|
|
45
|
+
const key = [...match[1].matchAll(piece)].map((part) => unescapeC(part[1])).join("");
|
|
46
|
+
if (!keys.has(key)) keys.set(key, `${name}:${lineOf(text, match.index)}`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return keys;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function walk(dir) {
|
|
53
|
+
return fs.readdirSync(dir, { withFileTypes: true }).flatMap((entry) => {
|
|
54
|
+
const full = path.join(dir, entry.name);
|
|
55
|
+
if (entry.isDirectory()) return entry.name === "locales" ? [] : walk(full);
|
|
56
|
+
return [full];
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Node 端只认 t("…") / t('…') / t(`…`)(模板串里不许有 ${}),第一个参数必须是字面量。
|
|
61
|
+
// zsh 端只认 cc_pets_t "…",第一个参数必须是不含变量的双引号字面量。
|
|
62
|
+
function cliKeys() {
|
|
63
|
+
const keys = new Map();
|
|
64
|
+
const nodeCall = /\bt\(\s*("(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|`(?:[^`\\$]|\\.)*`)/g;
|
|
65
|
+
const zshCall = /\bcc_pets_t\s+"((?:[^"\\$`]|\\.)*)"/g;
|
|
66
|
+
const files = [...walk(path.join(projectDir, "scripts")), ...walk(path.join(projectDir, "bin"))]
|
|
67
|
+
.filter((file) => !SKIPPED_SCRIPTS.has(path.basename(file)))
|
|
68
|
+
.sort();
|
|
69
|
+
for (const file of files) {
|
|
70
|
+
const text = fs.readFileSync(file, "utf8");
|
|
71
|
+
const relative = path.relative(projectDir, file);
|
|
72
|
+
const node = /\.(mjs|js)$/.test(file);
|
|
73
|
+
for (const match of text.matchAll(node ? nodeCall : zshCall)) {
|
|
74
|
+
const key = node
|
|
75
|
+
? unescapeC(match[1].slice(1, -1).replace(/\\'/g, "'").replace(/\\`/g, "`"))
|
|
76
|
+
: match[1].replace(/\\(["\\$`])/g, "$1");
|
|
77
|
+
if (!keys.has(key)) keys.set(key, `${relative}:${lineOf(text, match.index)}`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return keys;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function readStrings(file) {
|
|
84
|
+
return JSON.parse(execFileSync("/usr/bin/plutil", ["-convert", "json", "-o", "-", file], {
|
|
85
|
+
encoding: "utf8"
|
|
86
|
+
}));
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// %1$@ 和 %@ 视为同一个占位符,只比较类型的多重集合;{name} 比较名字的集合。
|
|
90
|
+
function placeholders(text) {
|
|
91
|
+
const printf = [...text.matchAll(/%(?:\d+\$)?(?:[-+ #0]*\d*(?:\.\d+)?)(l{0,2}[dufsx@]|%)/g)]
|
|
92
|
+
.map((match) => match[1]).filter((type) => type !== "%").sort();
|
|
93
|
+
const slots = [...text.matchAll(/\{([A-Za-z][A-Za-z0-9]*)\}/g)].map((match) => match[1]).sort();
|
|
94
|
+
return JSON.stringify([printf, [...new Set(slots)]]);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function check(label, keys, table, metaKeys = []) {
|
|
98
|
+
const problems = [];
|
|
99
|
+
const missing = {};
|
|
100
|
+
for (const key of metaKeys) {
|
|
101
|
+
if (!String(table[key] ?? "").trim()) problems.push(`${label} 缺元信息: ${JSON.stringify(key)}`);
|
|
102
|
+
}
|
|
103
|
+
for (const [key, where] of keys) {
|
|
104
|
+
if (!(key in table)) {
|
|
105
|
+
problems.push(`${label} 缺翻译 (${where}): ${JSON.stringify(key)}`);
|
|
106
|
+
missing[key] = "";
|
|
107
|
+
} else if (placeholders(key) !== placeholders(table[key])) {
|
|
108
|
+
problems.push(`${label} 占位符不一致 (${where}): ${JSON.stringify(key)} → ${JSON.stringify(table[key])}`);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
for (const key of Object.keys(table)) {
|
|
112
|
+
if (!keys.has(key) && !metaKeys.includes(key)) problems.push(`${label} 多余的条目: ${JSON.stringify(key)}`);
|
|
113
|
+
}
|
|
114
|
+
return { problems, missing };
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const appLanguages = fs.readdirSync(resourcesDir)
|
|
118
|
+
.filter((entry) => entry.endsWith(".lproj"))
|
|
119
|
+
.filter((entry) => fs.existsSync(path.join(resourcesDir, entry, "Localizable.strings")))
|
|
120
|
+
.map((entry) => entry.slice(0, -".lproj".length))
|
|
121
|
+
.sort();
|
|
122
|
+
const cliLanguages = fs.readdirSync(localesDir)
|
|
123
|
+
.filter((entry) => entry.endsWith(".json"))
|
|
124
|
+
.map((entry) => entry.slice(0, -".json".length))
|
|
125
|
+
.sort();
|
|
126
|
+
|
|
127
|
+
const appKeys = objcKeys();
|
|
128
|
+
const scriptKeys = cliKeys();
|
|
129
|
+
const results = {};
|
|
130
|
+
for (const language of appLanguages) {
|
|
131
|
+
results[`App ${language}`] = check(`App ${language}`, appKeys,
|
|
132
|
+
readStrings(path.join(resourcesDir, `${language}.lproj`, "Localizable.strings")), APP_META_KEYS);
|
|
133
|
+
}
|
|
134
|
+
for (const language of cliLanguages) {
|
|
135
|
+
results[`CLI ${language}`] = check(`CLI ${language}`, scriptKeys,
|
|
136
|
+
JSON.parse(fs.readFileSync(path.join(localesDir, `${language}.json`), "utf8")));
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const missingIndex = process.argv.indexOf("--missing");
|
|
140
|
+
if (missingIndex >= 0) {
|
|
141
|
+
const language = process.argv[missingIndex + 1];
|
|
142
|
+
if (!language) {
|
|
143
|
+
console.error("用法: check-l10n.mjs --missing <语言>");
|
|
144
|
+
process.exit(2);
|
|
145
|
+
}
|
|
146
|
+
// 还没建表的新语言:缺的就是全部 key。
|
|
147
|
+
const all = (keys) => Object.fromEntries([...keys.keys()].map((key) => [key, ""]));
|
|
148
|
+
const app = results[`App ${language}`]?.missing ?? all(appKeys);
|
|
149
|
+
const cli = results[`CLI ${language}`]?.missing ?? all(scriptKeys);
|
|
150
|
+
process.stdout.write(`${JSON.stringify({ app, cli }, null, 2)}\n`);
|
|
151
|
+
process.exit(0);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const problems = [];
|
|
155
|
+
// App 和 CLI 支持的语言要一致,否则切到某种语言后桌宠和终端各说各的。
|
|
156
|
+
for (const language of appLanguages) {
|
|
157
|
+
if (!cliLanguages.includes(language)) problems.push(`缺 scripts/locales/${language}.json(App 已支持 ${language})`);
|
|
158
|
+
}
|
|
159
|
+
for (const language of cliLanguages) {
|
|
160
|
+
if (!appLanguages.includes(language)) problems.push(`缺 Resources/${language}.lproj/Localizable.strings(CLI 已支持 ${language})`);
|
|
161
|
+
}
|
|
162
|
+
for (const result of Object.values(results)) problems.push(...result.problems);
|
|
163
|
+
if (problems.length > 0) {
|
|
164
|
+
for (const problem of problems) console.error(problem);
|
|
165
|
+
console.error(`\n共 ${problems.length} 处多语言问题。`);
|
|
166
|
+
process.exit(1);
|
|
167
|
+
}
|
|
168
|
+
console.log(`多语言检查通过(en 为源语言,另有 ${appLanguages.join("、")})。`);
|
|
@@ -3,12 +3,13 @@
|
|
|
3
3
|
import fs from "node:fs";
|
|
4
4
|
import os from "node:os";
|
|
5
5
|
import path from "node:path";
|
|
6
|
+
import { t } from "./i18n.mjs";
|
|
6
7
|
|
|
7
8
|
const nodeCandidate = process.env.npm_node_execpath || process.execPath;
|
|
8
9
|
const npmCandidate = process.env.npm_execpath;
|
|
9
10
|
|
|
10
11
|
if (!nodeCandidate || !npmCandidate) {
|
|
11
|
-
console.warn("
|
|
12
|
+
console.warn(t("Auto-update config not saved: npm didn't provide the node/npm-cli paths."));
|
|
12
13
|
process.exit(0);
|
|
13
14
|
}
|
|
14
15
|
|
|
@@ -18,12 +19,12 @@ try {
|
|
|
18
19
|
nodePath = fs.realpathSync(nodeCandidate);
|
|
19
20
|
npmCliPath = fs.realpathSync(npmCandidate);
|
|
20
21
|
} catch {
|
|
21
|
-
console.warn("
|
|
22
|
+
console.warn(t("Auto-update config not saved: the node/npm-cli paths don't exist."));
|
|
22
23
|
process.exit(0);
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
if (!path.isAbsolute(nodePath) || !path.isAbsolute(npmCliPath)) {
|
|
26
|
-
console.warn("
|
|
27
|
+
console.warn(t("Auto-update config not saved: the node/npm-cli paths aren't absolute."));
|
|
27
28
|
process.exit(0);
|
|
28
29
|
}
|
|
29
30
|
|
package/scripts/doctor.mjs
CHANGED
|
@@ -21,6 +21,7 @@ import { HOOK_MARKER, describeCodexQueue } from "./bridge/install.mjs";
|
|
|
21
21
|
import { currentOptions } from "./bridge/options.mjs";
|
|
22
22
|
import { probeCodexQueue, resolveRealExecutable } from "./bridge/process.mjs";
|
|
23
23
|
import { bridgeDirectory, bridgeHomeDirectory, isBridgeEnabled } from "./bridge/store.mjs";
|
|
24
|
+
import { t } from "./i18n.mjs";
|
|
24
25
|
|
|
25
26
|
const projectDir = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
|
|
26
27
|
const petBinary = path.join(projectDir, ".build/release/cc-pets");
|
|
@@ -69,7 +70,7 @@ const sizeOf = (target) => {
|
|
|
69
70
|
};
|
|
70
71
|
|
|
71
72
|
const formatSize = (bytes) => {
|
|
72
|
-
if (bytes === null) return "
|
|
73
|
+
if (bytes === null) return t("missing");
|
|
73
74
|
if (bytes < 1024) return `${bytes} B`;
|
|
74
75
|
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
|
|
75
76
|
return `${(bytes / 1024 / 1024).toFixed(1)} MB`;
|
|
@@ -94,51 +95,51 @@ const pathGroups = (native) => {
|
|
|
94
95
|
const ccPetsHome = bridgeHomeDirectory();
|
|
95
96
|
const groups = [
|
|
96
97
|
{
|
|
97
|
-
title: "
|
|
98
|
-
items: native ? [["
|
|
98
|
+
title: t("Settings (removed by --purge)"),
|
|
99
|
+
items: native ? [[t("Preferences"), native.preferences]] : []
|
|
99
100
|
},
|
|
100
101
|
{
|
|
101
|
-
title: "
|
|
102
|
+
title: t("Your content (kept by both clean and --purge)"),
|
|
102
103
|
items: [
|
|
103
104
|
...(native ? [
|
|
104
|
-
["
|
|
105
|
-
["
|
|
106
|
-
["
|
|
105
|
+
[t("Pet sprites"), native.pets],
|
|
106
|
+
[t("Shared lines"), native.phrases],
|
|
107
|
+
[t("Per-pet lines"), native.petPhrases]
|
|
107
108
|
] : []),
|
|
108
|
-
["CC Bridge
|
|
109
|
+
[t("CC Bridge switch"), path.join(ccPetsHome, "bridge-enabled")],
|
|
109
110
|
["codex / claude shim", shimDirectory]
|
|
110
111
|
]
|
|
111
112
|
},
|
|
112
113
|
{
|
|
113
|
-
title: "
|
|
114
|
+
title: t("App data (removed by --purge; clean only clears the token cache and update log)"),
|
|
114
115
|
items: native ? [
|
|
115
|
-
["
|
|
116
|
-
["
|
|
117
|
-
["
|
|
116
|
+
[t("App data directory"), native.applicationSupport],
|
|
117
|
+
[t("Quota history"), native.quotaHistory],
|
|
118
|
+
[t("Auto-update config"), path.join(native.applicationSupport, "updater.json")]
|
|
118
119
|
] : []
|
|
119
120
|
},
|
|
120
121
|
{
|
|
121
|
-
title: "
|
|
122
|
+
title: t("Caches and runtime state (cleared by clean; safe to lose)"),
|
|
122
123
|
items: [
|
|
123
124
|
...(native ? [
|
|
124
|
-
["
|
|
125
|
-
["Agent
|
|
126
|
-
["Claude
|
|
127
|
-
["Codex
|
|
128
|
-
["Codex
|
|
129
|
-
["
|
|
125
|
+
[t("Pet store manifest cache"), native.petStoreCache],
|
|
126
|
+
[t("Agent event stream"), native.agentEvents],
|
|
127
|
+
[t("Claude quota snapshot"), native.claudeUsage],
|
|
128
|
+
[t("Codex live quota"), native.codexLiveUsage],
|
|
129
|
+
[t("Codex launch records"), native.codexLaunches],
|
|
130
|
+
[t("Online client records"), native.clients]
|
|
130
131
|
] : []),
|
|
131
|
-
["CC Bridge
|
|
132
|
+
[t("CC Bridge state directory"), bridgeDirectory()]
|
|
132
133
|
]
|
|
133
134
|
},
|
|
134
135
|
{
|
|
135
|
-
title: "
|
|
136
|
+
title: t("Program and integrations"),
|
|
136
137
|
items: [
|
|
137
|
-
["npm
|
|
138
|
-
["
|
|
139
|
-
["Claude Code
|
|
138
|
+
[t("npm package"), projectDir],
|
|
139
|
+
[t("Installed app"), installedApp],
|
|
140
|
+
[t("Claude Code settings"), path.join(claudeHome, "settings.json")],
|
|
140
141
|
["Codex Hooks", path.join(codexHome, "hooks.json")],
|
|
141
|
-
["Shell
|
|
142
|
+
[t("Shell config"), shellRC]
|
|
142
143
|
]
|
|
143
144
|
}
|
|
144
145
|
];
|
|
@@ -161,7 +162,8 @@ const printPaths = (asJson) => {
|
|
|
161
162
|
return 0;
|
|
162
163
|
}
|
|
163
164
|
if (!native) {
|
|
164
|
-
console.log(
|
|
165
|
+
console.log(t(`⚠️ The native binary isn't built or can't run, so the pet's own data paths are unknown; run cc-pets install and try again.
|
|
166
|
+
`));
|
|
165
167
|
}
|
|
166
168
|
const width = Math.max(...groups.flatMap((group) => group.items.map(([label]) => displayWidth(label))));
|
|
167
169
|
groups.forEach((group, index) => {
|
|
@@ -208,24 +210,32 @@ const hookChecks = (name, configFile, signature, legacySignature) => {
|
|
|
208
210
|
const hooks = inspectHooks(configFile, signature, legacySignature);
|
|
209
211
|
if (hooks.error) {
|
|
210
212
|
return {
|
|
211
|
-
results: [{ level: "fail", title:
|
|
213
|
+
results: [{ level: "fail", title: t("Can't parse {name} config: {configFile}", { name, configFile: tilde(configFile) }), fix: t("Fix that JSON file, then run cc-pets install") }],
|
|
212
214
|
bridgeHooks: 0
|
|
213
215
|
};
|
|
214
216
|
}
|
|
215
217
|
const results = [];
|
|
216
218
|
if (hooks.total === 0) {
|
|
217
|
-
results.push({ level: "fail", title:
|
|
219
|
+
results.push({ level: "fail", title: t("{name} hooks not installed", { name }), fix: "cc-pets install" });
|
|
218
220
|
} else if (hooks.stale > 0) {
|
|
219
221
|
results.push({
|
|
220
222
|
level: "warn",
|
|
221
|
-
title:
|
|
223
|
+
title: hooks.stale !== 1
|
|
224
|
+
? t("{stale} {name} hooks point to cc-pets elsewhere (the package was moved or reinstalled)", { name, stale: hooks.stale })
|
|
225
|
+
: t("{stale} {name} hook points to cc-pets elsewhere (the package was moved or reinstalled)", { name, stale: hooks.stale }),
|
|
222
226
|
fix: "cc-pets install"
|
|
223
227
|
});
|
|
224
228
|
} else {
|
|
225
|
-
results.push({ level: "ok", title:
|
|
229
|
+
results.push({ level: "ok", title: t("{name} hooks installed ({total} events)", { name, total: hooks.total }) });
|
|
226
230
|
}
|
|
227
231
|
if (hooks.legacy > 0) {
|
|
228
|
-
results.push({
|
|
232
|
+
results.push({
|
|
233
|
+
level: "warn",
|
|
234
|
+
title: hooks.legacy !== 1
|
|
235
|
+
? t("{name} config still has {legacy} old codex-pet hooks", { name, legacy: hooks.legacy })
|
|
236
|
+
: t("{name} config still has {legacy} old codex-pet hook", { name, legacy: hooks.legacy }),
|
|
237
|
+
fix: "cc-pets install"
|
|
238
|
+
});
|
|
229
239
|
}
|
|
230
240
|
return { results, bridgeHooks: hooks.bridge };
|
|
231
241
|
};
|
|
@@ -234,7 +244,7 @@ const statusLineCheck = () => {
|
|
|
234
244
|
const { value } = readJson(path.join(claudeHome, "settings.json"));
|
|
235
245
|
const command = typeof value?.statusLine?.command === "string" ? value.statusLine.command : "";
|
|
236
246
|
if (isManagedStatusLine(command, STATUS_LINE_MARKER)) {
|
|
237
|
-
return { level: "ok", title: "Claude status line
|
|
247
|
+
return { level: "ok", title: t("Claude status line feeds quota data through the wrapper") };
|
|
238
248
|
}
|
|
239
249
|
const script = resolveStatusLineScript(command);
|
|
240
250
|
let content = "";
|
|
@@ -245,12 +255,12 @@ const statusLineCheck = () => {
|
|
|
245
255
|
}
|
|
246
256
|
if (content.includes(STATUS_LINE_START_MARKER)) {
|
|
247
257
|
return content.includes(`'${petBinary}'`)
|
|
248
|
-
? { level: "ok", title:
|
|
249
|
-
: { level: "warn", title: "Claude status line
|
|
258
|
+
? { level: "ok", title: t("Claude status line feeds quota data ({script})", { script: tilde(script) }) }
|
|
259
|
+
: { level: "warn", title: t("The quota hook in the Claude status line points to cc-pets elsewhere"), fix: "cc-pets install" };
|
|
250
260
|
}
|
|
251
261
|
return {
|
|
252
262
|
level: "warn",
|
|
253
|
-
title: command ? "Claude status line
|
|
263
|
+
title: command ? t("Claude status line doesn't feed quota data, so the pet can't show Claude quota %") : t("No Claude status line configured, so the pet can't show Claude quota %"),
|
|
254
264
|
fix: "cc-pets install"
|
|
255
265
|
};
|
|
256
266
|
};
|
|
@@ -264,8 +274,8 @@ const shimChecks = () => {
|
|
|
264
274
|
rc = "";
|
|
265
275
|
}
|
|
266
276
|
results.push(rc.includes(SHIM_START_MARKER)
|
|
267
|
-
? { level: "ok", title:
|
|
268
|
-
: { level: "fail", title:
|
|
277
|
+
? { level: "ok", title: t("{shellRC} adds the shim directory", { shellRC: tilde(shellRC) }) }
|
|
278
|
+
: { level: "fail", title: t("{shellRC} has no CC Pets shim setup", { shellRC: tilde(shellRC) }), fix: "cc-pets install" });
|
|
269
279
|
|
|
270
280
|
const broken = [];
|
|
271
281
|
for (const name of ["codex", "claude"]) {
|
|
@@ -274,27 +284,27 @@ const shimChecks = () => {
|
|
|
274
284
|
try {
|
|
275
285
|
link = fs.readlinkSync(shim);
|
|
276
286
|
} catch {
|
|
277
|
-
broken.push(
|
|
287
|
+
broken.push(t("{name} (missing)", { name }));
|
|
278
288
|
continue;
|
|
279
289
|
}
|
|
280
|
-
if (!fs.existsSync(path.resolve(shimDirectory, link))) broken.push(
|
|
290
|
+
if (!fs.existsSync(path.resolve(shimDirectory, link))) broken.push(t("{name} (target doesn't exist)", { name }));
|
|
281
291
|
}
|
|
282
292
|
results.push(broken.length === 0
|
|
283
|
-
? { level: "ok", title:
|
|
284
|
-
: { level: "warn", title:
|
|
293
|
+
? { level: "ok", title: t("Shims complete: {shimDirectory}", { shimDirectory: tilde(shimDirectory) }) }
|
|
294
|
+
: { level: "warn", title: t("Shim problems: {broken}", { broken: broken.join(t(", ")) }), fix: "cc-pets install" });
|
|
285
295
|
|
|
286
296
|
const entries = (process.env.PATH || "").split(path.delimiter).filter(Boolean).map((entry) => path.resolve(entry));
|
|
287
297
|
const index = entries.indexOf(shimDirectory);
|
|
288
298
|
if (index < 0) {
|
|
289
|
-
results.push({ level: "warn", title: "
|
|
299
|
+
results.push({ level: "warn", title: t("This terminal's PATH lacks the shim directory, so typing codex / claude won't start the pet"), fix: t("source {shellRC}, or open a new terminal", { shellRC: tilde(shellRC) }) });
|
|
290
300
|
} else if (index > 0) {
|
|
291
301
|
const shadowing = entries.slice(0, index).find((entry) =>
|
|
292
302
|
["codex", "claude"].some((name) => fs.existsSync(path.join(entry, name))));
|
|
293
303
|
results.push(shadowing
|
|
294
|
-
? { level: "warn", title:
|
|
295
|
-
: { level: "ok", title: "
|
|
304
|
+
? { level: "warn", title: t("{shadowing} comes before the shim directory in PATH and bypasses the pet", { shadowing: tilde(shadowing) }), fix: t("source {shellRC}, or open a new terminal", { shellRC: tilde(shellRC) }) }
|
|
305
|
+
: { level: "ok", title: t("The shim directory comes before the real codex / claude in PATH") });
|
|
296
306
|
} else {
|
|
297
|
-
results.push({ level: "ok", title: "
|
|
307
|
+
results.push({ level: "ok", title: t("The shim directory is first in PATH") });
|
|
298
308
|
}
|
|
299
309
|
return results;
|
|
300
310
|
};
|
|
@@ -302,8 +312,8 @@ const shimChecks = () => {
|
|
|
302
312
|
const realBinaryCheck = (name, variable) => {
|
|
303
313
|
const real = resolveRealExecutable(name, variable);
|
|
304
314
|
return real && fs.existsSync(real)
|
|
305
|
-
? { level: "ok", title:
|
|
306
|
-
: { level: "warn", title:
|
|
315
|
+
? { level: "ok", title: t("Found the real {name}: {real}", { name, real: tilde(real) }) }
|
|
316
|
+
: { level: "warn", title: t("The real {name} isn't in PATH, so the shim can't forward to it", { name }), fix: `export ${variable}=/absolute/path/to/${name}` };
|
|
307
317
|
};
|
|
308
318
|
|
|
309
319
|
const updaterCheck = (native) => {
|
|
@@ -311,19 +321,19 @@ const updaterCheck = (native) => {
|
|
|
311
321
|
const file = path.join(native.applicationSupport, "updater.json");
|
|
312
322
|
const { value, error } = readJson(file);
|
|
313
323
|
if (error) {
|
|
314
|
-
return { level: "warn", title: "
|
|
324
|
+
return { level: "warn", title: t("Auto-update isn't configured, so in-app updates won't work"), fix: "npm install -g cc-pets@latest --allow-scripts=cc-pets" };
|
|
315
325
|
}
|
|
316
326
|
const missing = ["nodePath", "npmCliPath"].filter((key) => !value?.[key] || !fs.existsSync(value[key]));
|
|
317
327
|
return missing.length === 0
|
|
318
|
-
? { level: "ok", title: "
|
|
319
|
-
: { level: "warn", title:
|
|
328
|
+
? { level: "ok", title: t("Auto-update config is valid") }
|
|
329
|
+
: { level: "warn", title: t("The {missing} recorded for auto-update no longer exist (changed Node versions?)", { missing: missing.join(t(", ")) }), fix: "npm install -g cc-pets@latest --allow-scripts=cc-pets" };
|
|
320
330
|
};
|
|
321
331
|
|
|
322
332
|
const formatAge = (milliseconds) => {
|
|
323
333
|
const minutes = Math.round(milliseconds / 60_000);
|
|
324
|
-
if (minutes < 60) return
|
|
334
|
+
if (minutes < 60) return t("{minutes} min ago", { minutes });
|
|
325
335
|
const hours = Math.round(minutes / 60);
|
|
326
|
-
return hours < 48 ?
|
|
336
|
+
return hours < 48 ? t("{hours} h ago", { hours }) : t("{days} days ago", { days: Math.round(hours / 24) });
|
|
327
337
|
};
|
|
328
338
|
|
|
329
339
|
const runDoctor = () => {
|
|
@@ -336,29 +346,29 @@ const runDoctor = () => {
|
|
|
336
346
|
const program = [
|
|
337
347
|
nodeMajor >= 18
|
|
338
348
|
? { level: "ok", title: `Node.js ${process.versions.node}` }
|
|
339
|
-
: { level: "fail", title:
|
|
340
|
-
{ level: "info", title:
|
|
349
|
+
: { level: "fail", title: t("Node.js {node} is too old; 18 or later is required", { node: process.versions.node }) },
|
|
350
|
+
{ level: "info", title: t("npm package {packageVersion}: {projectDir}", { packageVersion, projectDir: tilde(projectDir) }) }
|
|
341
351
|
];
|
|
342
352
|
const binaryVersion = fs.existsSync(petBinary) ? (run(petBinary, ["--version"]) || "").trim().replace(/^cc-pets\s+/, "") : null;
|
|
343
353
|
if (!binaryVersion) {
|
|
344
|
-
program.push({ level: "fail", title: "
|
|
354
|
+
program.push({ level: "fail", title: t("Native binary isn't built or can't run"), fix: "cc-pets install" });
|
|
345
355
|
} else if (binaryVersion !== packageVersion) {
|
|
346
|
-
program.push({ level: "warn", title:
|
|
356
|
+
program.push({ level: "warn", title: t("Native binary {binaryVersion} doesn't match npm package {packageVersion}", { binaryVersion, packageVersion }), fix: "cc-pets install" });
|
|
347
357
|
} else {
|
|
348
|
-
program.push({ level: "ok", title:
|
|
358
|
+
program.push({ level: "ok", title: t("Native binary {binaryVersion}", { binaryVersion }) });
|
|
349
359
|
}
|
|
350
360
|
const appVersion = versionOfApp(installedApp);
|
|
351
361
|
if (!appVersion) {
|
|
352
|
-
program.push({ level: "warn", title:
|
|
362
|
+
program.push({ level: "warn", title: t("Installed app not found: {installedApp}", { installedApp: tilde(installedApp) }), fix: "cc-pets install" });
|
|
353
363
|
} else if (appVersion !== packageVersion) {
|
|
354
|
-
program.push({ level: "warn", title:
|
|
364
|
+
program.push({ level: "warn", title: t("Installed app {appVersion} doesn't match npm package {packageVersion}", { appVersion, packageVersion }), fix: "cc-pets install" });
|
|
355
365
|
} else {
|
|
356
|
-
program.push({ level: "ok", title:
|
|
366
|
+
program.push({ level: "ok", title: t("Installed app {appVersion}", { appVersion }) });
|
|
357
367
|
}
|
|
358
|
-
if (native) program.push({ level: "info", title: native.running ? "
|
|
368
|
+
if (native) program.push({ level: "info", title: native.running ? t("The pet is running") : t("The pet isn't running") });
|
|
359
369
|
const updater = updaterCheck(native);
|
|
360
370
|
if (updater) program.push(updater);
|
|
361
|
-
sections.push({ title: "
|
|
371
|
+
sections.push({ title: t("Program"), results: program });
|
|
362
372
|
|
|
363
373
|
let claudeBridgeHooks = 0;
|
|
364
374
|
if (claudeDetected) {
|
|
@@ -373,12 +383,12 @@ const runDoctor = () => {
|
|
|
373
383
|
modified = null;
|
|
374
384
|
}
|
|
375
385
|
claude.push(modified
|
|
376
|
-
? { level: "info", title:
|
|
377
|
-
: { level: "info", title: "
|
|
386
|
+
? { level: "info", title: t("Claude quota snapshot updated {age}", { age: formatAge(Date.now() - modified) }) }
|
|
387
|
+
: { level: "info", title: t("No Claude quota snapshot yet (created after Claude Code's first API response)") });
|
|
378
388
|
}
|
|
379
389
|
sections.push({ title: "Claude Code", results: claude });
|
|
380
390
|
} else {
|
|
381
|
-
sections.push({ title: "Claude Code", results: [{ level: "info", title: "
|
|
391
|
+
sections.push({ title: "Claude Code", results: [{ level: "info", title: t("Claude Code CLI not detected, skipped") }] });
|
|
382
392
|
}
|
|
383
393
|
|
|
384
394
|
let codexBridgeHooks = 0;
|
|
@@ -389,15 +399,15 @@ const runDoctor = () => {
|
|
|
389
399
|
title: "Codex",
|
|
390
400
|
results: [
|
|
391
401
|
...results,
|
|
392
|
-
{ level: "info", title: "Codex
|
|
402
|
+
{ level: "info", title: t("Codex only runs CC Pets hooks after you trust them in /hooks (can't be checked automatically)") }
|
|
393
403
|
]
|
|
394
404
|
});
|
|
395
405
|
} else {
|
|
396
|
-
sections.push({ title: "Codex", results: [{ level: "info", title: "
|
|
406
|
+
sections.push({ title: "Codex", results: [{ level: "info", title: t("Codex CLI not detected, skipped") }] });
|
|
397
407
|
}
|
|
398
408
|
|
|
399
409
|
sections.push({
|
|
400
|
-
title: "Shell
|
|
410
|
+
title: t("Shell integration"),
|
|
401
411
|
results: [
|
|
402
412
|
...shimChecks(),
|
|
403
413
|
...(codexDetected ? [realBinaryCheck("codex", "CODEX_REAL_BIN")] : []),
|
|
@@ -406,29 +416,29 @@ const runDoctor = () => {
|
|
|
406
416
|
});
|
|
407
417
|
|
|
408
418
|
if (!isBridgeEnabled()) {
|
|
409
|
-
sections.push({ title: "CC Bridge", results: [{ level: "info", title: "
|
|
419
|
+
sections.push({ title: "CC Bridge", results: [{ level: "info", title: t("Off (optional; turn on with cc-pets bridge enable)") }] });
|
|
410
420
|
} else {
|
|
411
|
-
const bridge = [{ level: "ok", title: "
|
|
421
|
+
const bridge = [{ level: "ok", title: t("Enabled") }];
|
|
412
422
|
if (claudeDetected) {
|
|
413
423
|
bridge.push(claudeBridgeHooks > 0
|
|
414
|
-
? { level: "ok", title: "
|
|
415
|
-
: { level: "warn", title: "
|
|
424
|
+
? { level: "ok", title: t("CC Bridge hooks installed in Claude Code") }
|
|
425
|
+
: { level: "warn", title: t("CC Bridge hooks missing in Claude Code"), fix: "cc-pets bridge enable" });
|
|
416
426
|
}
|
|
417
427
|
if (codexDetected) {
|
|
418
428
|
bridge.push(codexBridgeHooks > 0
|
|
419
|
-
? { level: "ok", title: "
|
|
420
|
-
: { level: "warn", title: "
|
|
429
|
+
? { level: "ok", title: t("CC Bridge hooks installed in Codex") }
|
|
430
|
+
: { level: "warn", title: t("CC Bridge hooks missing in Codex"), fix: "cc-pets bridge enable" });
|
|
421
431
|
if (currentOptions().wake) {
|
|
422
432
|
const notice = describeCodexQueue(probeCodexQueue());
|
|
423
433
|
bridge.push(notice
|
|
424
434
|
? { level: "warn", title: notice }
|
|
425
|
-
: { level: "ok", title: "Codex
|
|
435
|
+
: { level: "ok", title: t("Codex supports codex queue, so it can be woken automatically") });
|
|
426
436
|
}
|
|
427
437
|
}
|
|
428
438
|
sections.push({ title: "CC Bridge", results: bridge });
|
|
429
439
|
}
|
|
430
440
|
|
|
431
|
-
console.log(
|
|
441
|
+
console.log(t("CC Pets diagnostics (npm package {packageVersion}, {platform} {release})", { packageVersion, platform: os.platform(), release: os.release() }));
|
|
432
442
|
const counts = { ok: 0, warn: 0, fail: 0, info: 0 };
|
|
433
443
|
for (const section of sections) {
|
|
434
444
|
console.log(`\n${section.title}`);
|
|
@@ -438,8 +448,12 @@ const runDoctor = () => {
|
|
|
438
448
|
if (result.fix) console.log(` → ${result.fix}`);
|
|
439
449
|
}
|
|
440
450
|
}
|
|
441
|
-
|
|
442
|
-
|
|
451
|
+
const warnings = counts.warn !== 1
|
|
452
|
+
? t("{count} warnings", { count: counts.warn }) : t("{count} warning", { count: counts.warn });
|
|
453
|
+
const errors = counts.fail !== 1
|
|
454
|
+
? t("{count} errors", { count: counts.fail }) : t("{count} error", { count: counts.fail });
|
|
455
|
+
console.log(t("\nResult: {ok} OK, {warnings}, {errors}.", { ok: counts.ok, warnings, errors }));
|
|
456
|
+
if (counts.fail + counts.warn > 0) console.log(t("Most problems are fixed by cc-pets install; see cc-pets paths for data locations."));
|
|
443
457
|
return counts.fail > 0 ? 1 : 0;
|
|
444
458
|
};
|
|
445
459
|
|
|
@@ -451,6 +465,6 @@ if (command === "paths") {
|
|
|
451
465
|
} else if (command === "doctor") {
|
|
452
466
|
process.exitCode = runDoctor();
|
|
453
467
|
} else {
|
|
454
|
-
console.error("
|
|
468
|
+
console.error(t("Usage: doctor.mjs paths [--json] | doctor"));
|
|
455
469
|
process.exitCode = 2;
|
|
456
470
|
}
|