cc-pets 2.2.1 → 2.4.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 +24 -2
- package/CC_BRIDGE.zh-CN.md +19 -2
- package/CHANGELOG.md +111 -0
- package/CHANGELOG.zh-CN.md +111 -0
- package/CONTRIBUTING.md +35 -10
- package/CONTRIBUTING.zh-CN.md +28 -10
- package/README.md +212 -32
- package/README.zh-CN.md +167 -36
- package/Resources/AgentIcons/claude.png +0 -0
- package/Resources/AgentIcons/codex.icns +0 -0
- package/Resources/IDEPlugins/cc-pets-terminal.vsix +0 -0
- package/Resources/IDEPlugins/cc-pets-terminal.zip +0 -0
- package/Resources/zh-Hans.lproj/Localizable.strings +699 -20
- package/Sources/CCPets/{CCPetsAppDelegate+AgentEvents.m → App/CCPetsAppDelegate+AgentEvents.m} +15 -5
- package/Sources/CCPets/{CCPetsAppDelegate+AgentStatus.m → App/CCPetsAppDelegate+AgentStatus.m} +90 -25
- package/Sources/CCPets/{CCPetsAppDelegate+Bridge.m → App/CCPetsAppDelegate+Bridge.m} +35 -24
- package/Sources/CCPets/{CCPetsAppDelegate+Pets.m → App/CCPetsAppDelegate+Pets.m} +17 -3
- package/Sources/CCPets/{CCPetsAppDelegate+Private.h → App/CCPetsAppDelegate+Private.h} +71 -23
- package/Sources/CCPets/App/CCPetsAppDelegate+Profiles.m +238 -0
- package/Sources/CCPets/{CCPetsAppDelegate+Quota.m → App/CCPetsAppDelegate+Quota.m} +47 -32
- package/Sources/CCPets/{CCPetsAppDelegate+Settings.m → App/CCPetsAppDelegate+Settings.m} +87 -102
- package/Sources/CCPets/{CCPetsAppDelegate+Speech.m → App/CCPetsAppDelegate+Speech.m} +121 -51
- package/Sources/CCPets/App/CCPetsAppDelegate+Workbench.m +139 -0
- package/Sources/CCPets/{CCPetsAppDelegate.h → App/CCPetsAppDelegate.h} +17 -2
- package/Sources/CCPets/{CCPetsAppDelegate.m → App/CCPetsAppDelegate.m} +107 -11
- package/Sources/CCPets/App/CCPetsOpenCommand.h +13 -0
- package/Sources/CCPets/App/CCPetsOpenCommand.m +99 -0
- package/Sources/CCPets/{main.m → App/main.m} +74 -1
- package/Sources/CCPets/{CCPetsBridge.h → Bridge/CCPetsBridge.h} +17 -4
- package/Sources/CCPets/{CCPetsBridge.m → Bridge/CCPetsBridge.m} +43 -23
- package/Sources/CCPets/Bridge/CCPetsBridgeCLI.h +10 -0
- package/Sources/CCPets/Bridge/CCPetsBridgeCLI.m +832 -0
- package/Sources/CCPets/Bridge/CCPetsBridgeCore.h +59 -0
- package/Sources/CCPets/Bridge/CCPetsBridgeCore.m +576 -0
- package/Sources/CCPets/Bridge/CCPetsBridgeSetup.h +24 -0
- package/Sources/CCPets/Bridge/CCPetsBridgeSetup.m +507 -0
- package/Sources/CCPets/Bridge/CCPetsBridgeStore.h +106 -0
- package/Sources/CCPets/Bridge/CCPetsBridgeStore.m +897 -0
- package/Sources/CCPets/Integrations/CCPetsCLISupport.h +75 -0
- package/Sources/CCPets/Integrations/CCPetsCLISupport.m +342 -0
- package/Sources/CCPets/Integrations/CCPetsEvents.h +15 -0
- package/Sources/CCPets/{CCPetsEvents.m → Integrations/CCPetsEvents.m} +23 -0
- package/Sources/CCPets/Integrations/CCPetsIDEIntegration.h +21 -0
- package/Sources/CCPets/Integrations/CCPetsIDEIntegration.m +503 -0
- package/Sources/CCPets/Integrations/CCPetsIntegrations.h +51 -0
- package/Sources/CCPets/Integrations/CCPetsIntegrations.m +662 -0
- package/Sources/CCPets/Integrations/CCPetsLaunchPreflight.h +5 -0
- package/Sources/CCPets/Integrations/CCPetsLaunchPreflight.m +367 -0
- package/Sources/CCPets/Integrations/CCPetsProfiles.h +38 -0
- package/Sources/CCPets/Integrations/CCPetsProfiles.m +516 -0
- package/Sources/CCPets/{CCPetsTerminalFocus.h → Integrations/CCPetsTerminalFocus.h} +2 -1
- package/Sources/CCPets/{CCPetsTerminalFocus.m → Integrations/CCPetsTerminalFocus.m} +148 -36
- package/Sources/CCPets/Integrations/CCPetsTerminalIntegration.h +17 -0
- package/Sources/CCPets/Integrations/CCPetsTerminalIntegration.m +64 -0
- package/Sources/CCPets/Integrations/CCPetsVSCodeIntegration.h +23 -0
- package/Sources/CCPets/Integrations/CCPetsVSCodeIntegration.m +475 -0
- package/Sources/CCPets/Pet/CCPetsPetStore.h +12 -0
- package/Sources/CCPets/Pet/CCPetsPetStore.m +476 -0
- package/Sources/CCPets/{CCPetsPhrases.h → Pet/CCPetsPhrases.h} +11 -2
- package/Sources/CCPets/{CCPetsPhrases.m → Pet/CCPetsPhrases.m} +19 -2
- package/Sources/CCPets/{CCPetsPhrasesEditor.m → Pet/CCPetsPhrasesEditor.m} +4 -1
- package/Sources/CCPets/Pet/PetView+Interaction.m +207 -0
- package/Sources/CCPets/Pet/PetView+Menu.m +598 -0
- package/Sources/CCPets/Pet/PetView+MicroBehavior.m +234 -0
- package/Sources/CCPets/Pet/PetView+Private.h +81 -0
- package/Sources/CCPets/{PetView.h → Pet/PetView.h} +3 -5
- package/Sources/CCPets/Pet/PetView.m +635 -0
- package/Sources/CCPets/Support/CCPetsDoctor.h +25 -0
- package/Sources/CCPets/Support/CCPetsDoctor.m +646 -0
- package/Sources/CCPets/Support/CCPetsJSON.h +27 -0
- package/Sources/CCPets/Support/CCPetsJSON.m +397 -0
- package/Sources/CCPets/{CCPetsL10n.h → Support/CCPetsL10n.h} +3 -1
- package/Sources/CCPets/{CCPetsL10n.m → Support/CCPetsL10n.m} +30 -1
- package/Sources/CCPets/Support/CCPetsPreferences.h +33 -0
- package/Sources/CCPets/Support/CCPetsPreferences.m +117 -0
- package/Sources/CCPets/UI/CCPetsDiagnosticsPage.h +25 -0
- package/Sources/CCPets/UI/CCPetsDiagnosticsPage.m +440 -0
- package/Sources/CCPets/UI/CCPetsFormBuilder.h +44 -0
- package/Sources/CCPets/UI/CCPetsFormBuilder.m +279 -0
- package/Sources/CCPets/UI/CCPetsGlassView.h +57 -0
- package/Sources/CCPets/{CCPetsGlassView.m → UI/CCPetsGlassView.m} +60 -11
- package/Sources/CCPets/UI/CCPetsMainWindow.h +55 -0
- package/Sources/CCPets/UI/CCPetsMainWindow.m +730 -0
- package/Sources/CCPets/UI/CCPetsSettingsPage.h +64 -0
- package/Sources/CCPets/UI/CCPetsSettingsPage.m +1412 -0
- package/Sources/CCPets/UI/CCPetsUIStyle.h +135 -0
- package/Sources/CCPets/UI/CCPetsUIStyle.m +865 -0
- package/Sources/CCPets/UI/CCPetsUsageChartView.h +15 -0
- package/Sources/CCPets/UI/CCPetsUsageChartView.m +288 -0
- package/Sources/CCPets/UI/CCPetsUsagePage.h +32 -0
- package/Sources/CCPets/UI/CCPetsUsagePage.m +712 -0
- package/Sources/CCPets/UI/CCPetsUsageShared.h +53 -0
- package/Sources/CCPets/UI/CCPetsUsageStore.m +120 -0
- package/Sources/CCPets/UI/CCPetsUsageWidgets.h +30 -0
- package/Sources/CCPets/UI/CCPetsUsageWidgets.m +201 -0
- package/Sources/CCPets/UI/CCPetsWorkbench.h +40 -0
- package/Sources/CCPets/UI/CCPetsWorkbenchPages.h +13 -0
- package/Sources/CCPets/UI/CCPetsWorkbenchPages.m +783 -0
- package/Sources/CCPets/{MenuToggleSwitch.m → UI/MenuToggleSwitch.m} +1 -0
- package/Sources/CCPets/{CCPetsCodexRateLimits.h → Usage/CCPetsCodexRateLimits.h} +1 -0
- package/Sources/CCPets/{CCPetsCodexRateLimits.m → Usage/CCPetsCodexRateLimits.m} +10 -3
- package/Sources/CCPets/{CCPetsQuotaHistory.h → Usage/CCPetsQuotaHistory.h} +3 -0
- package/Sources/CCPets/{CCPetsQuotaHistory.m → Usage/CCPetsQuotaHistory.m} +58 -0
- package/Sources/CCPets/Usage/CCPetsUsage+ClaudeReader.m +436 -0
- package/Sources/CCPets/Usage/CCPetsUsage+CodexBackground.m +193 -0
- package/Sources/CCPets/Usage/CCPetsUsage+CodexReader.m +392 -0
- package/Sources/CCPets/Usage/CCPetsUsage+CodexSessions.m +484 -0
- package/Sources/CCPets/Usage/CCPetsUsage+Internal.h +97 -0
- package/Sources/CCPets/Usage/CCPetsUsage+Models.m +323 -0
- package/Sources/CCPets/Usage/CCPetsUsage+TokenTotals.m +655 -0
- package/Sources/CCPets/Usage/CCPetsUsage.h +58 -0
- package/Sources/CCPets/Usage/CCPetsUsage.m +225 -0
- package/Sources/CCPets/Usage/CCPetsUsageMode.h +10 -0
- package/Sources/CCPets/Usage/CCPetsUsageMode.m +163 -0
- package/Sources/CCPets/{CCPetsUsageMonitor.h → Usage/CCPetsUsageMonitor.h} +3 -0
- package/Sources/CCPets/{CCPetsUsageMonitor.m → Usage/CCPetsUsageMonitor.m} +174 -19
- package/Sources/CCPets/Usage/QuotaDashboardView+Primitives.m +328 -0
- package/Sources/CCPets/Usage/QuotaDashboardView+Private.h +103 -0
- package/Sources/CCPets/Usage/QuotaDashboardView+Rendering.m +598 -0
- package/Sources/CCPets/{QuotaDashboardView.h → Usage/QuotaDashboardView.h} +17 -0
- package/Sources/CCPets/Usage/QuotaDashboardView.m +713 -0
- package/THIRD_PARTY_NOTICES.md +8 -4
- package/THIRD_PARTY_NOTICES.zh-CN.md +6 -2
- package/bin/cc-pets +8 -6
- package/bin/claude-with-pet +12 -2
- package/bin/codex-with-pet +15 -5
- package/package.json +5 -1
- package/plugins/jetbrains/README.md +62 -0
- package/plugins/jetbrains/src/main/java/com/ccpets/terminal/TerminalBridge.java +379 -0
- package/plugins/jetbrains/src/main/java/com/ccpets/terminal/TerminalIdentity.java +24 -0
- package/plugins/jetbrains/src/main/java/com/ccpets/terminal/TerminalStartup.java +12 -0
- package/plugins/jetbrains/src/main/resources/META-INF/plugin.xml +23 -0
- package/plugins/jetbrains/src/main/resources/META-INF/pluginIcon.svg +380 -0
- package/plugins/vscode/README.md +63 -0
- package/plugins/vscode/extension.js +210 -0
- package/plugins/vscode/package.json +18 -0
- package/scripts/build-idea-plugin.sh +101 -0
- package/scripts/build-vscode-extension.sh +112 -0
- package/scripts/build.sh +31 -5
- package/scripts/compile-cached.zsh +133 -0
- package/scripts/i18n.zsh +9 -52
- package/scripts/install-app.sh +4 -0
- package/scripts/install-shell-integration.sh +17 -10
- package/scripts/uninstall-shell-integration.sh +6 -1
- package/Sources/CCPets/CCPetsEvents.h +0 -10
- package/Sources/CCPets/CCPetsGlassView.h +0 -31
- package/Sources/CCPets/CCPetsUsage.h +0 -36
- package/Sources/CCPets/CCPetsUsage.m +0 -2069
- package/Sources/CCPets/PetView.m +0 -1839
- package/Sources/CCPets/QuotaDashboardView.m +0 -1145
- package/scripts/bridge/cli.mjs +0 -237
- package/scripts/bridge/core.mjs +0 -228
- package/scripts/bridge/hook.mjs +0 -150
- package/scripts/bridge/install.mjs +0 -311
- package/scripts/bridge/mcp-server.mjs +0 -308
- package/scripts/bridge/options.mjs +0 -87
- package/scripts/bridge/process.mjs +0 -151
- package/scripts/bridge/reservations.mjs +0 -248
- package/scripts/bridge/store.mjs +0 -433
- package/scripts/bridge/watch.mjs +0 -69
- package/scripts/check-l10n.mjs +0 -168
- package/scripts/configure-updater.mjs +0 -43
- package/scripts/detect-cli.mjs +0 -68
- package/scripts/doctor.mjs +0 -470
- package/scripts/i18n.mjs +0 -122
- package/scripts/install-claude-hooks.mjs +0 -253
- package/scripts/install-codex-hooks.mjs +0 -78
- package/scripts/integration-markers.mjs +0 -51
- package/scripts/locales/zh-Hans.json +0 -366
- package/scripts/pet-store.mjs +0 -415
- package/scripts/uninstall-integrations.mjs +0 -205
- /package/Sources/CCPets/{CCPetsAppDelegate+Update.m → App/CCPetsAppDelegate+Update.m} +0 -0
- /package/Sources/CCPets/{CCPetsVersion.h → App/CCPetsVersion.h} +0 -0
- /package/Sources/CCPets/{CCPetsVersion.m → App/CCPetsVersion.m} +0 -0
- /package/Sources/CCPets/{CCPetsImageLoader.h → Pet/CCPetsImageLoader.h} +0 -0
- /package/Sources/CCPets/{CCPetsImageLoader.m → Pet/CCPetsImageLoader.m} +0 -0
- /package/Sources/CCPets/{CCPetsPetSize.h → Pet/CCPetsPetSize.h} +0 -0
- /package/Sources/CCPets/{CCPetsPetSize.m → Pet/CCPetsPetSize.m} +0 -0
- /package/Sources/CCPets/{CCPetsPhrasesEditor.h → Pet/CCPetsPhrasesEditor.h} +0 -0
- /package/Sources/CCPets/{CCPetsPreviews.h → Pet/CCPetsPreviews.h} +0 -0
- /package/Sources/CCPets/{CCPetsPreviews.m → Pet/CCPetsPreviews.m} +0 -0
- /package/Sources/CCPets/Resources/{/351/273/230/350/256/244.webp" → ByteMochi.webp} +0 -0
- /package/Sources/CCPets/{CCPetsCleanup.h → Support/CCPetsCleanup.h} +0 -0
- /package/Sources/CCPets/{CCPetsCleanup.m → Support/CCPetsCleanup.m} +0 -0
- /package/Sources/CCPets/{CCPetsPaths.h → Support/CCPetsPaths.h} +0 -0
- /package/Sources/CCPets/{CCPetsPaths.m → Support/CCPetsPaths.m} +0 -0
- /package/Sources/CCPets/{CCPetsSystemMonitor.h → Support/CCPetsSystemMonitor.h} +0 -0
- /package/Sources/CCPets/{CCPetsSystemMonitor.m → Support/CCPetsSystemMonitor.m} +0 -0
- /package/Sources/CCPets/{CCPetsGlassMenu.h → UI/CCPetsGlassMenu.h} +0 -0
- /package/Sources/CCPets/{CCPetsGlassMenu.m → UI/CCPetsGlassMenu.m} +0 -0
- /package/Sources/CCPets/{MenuChoiceRow.h → UI/MenuChoiceRow.h} +0 -0
- /package/Sources/CCPets/{MenuChoiceRow.m → UI/MenuChoiceRow.m} +0 -0
- /package/Sources/CCPets/{MenuHintView.h → UI/MenuHintView.h} +0 -0
- /package/Sources/CCPets/{MenuHintView.m → UI/MenuHintView.m} +0 -0
- /package/Sources/CCPets/{MenuPetSizeView.h → UI/MenuPetSizeView.h} +0 -0
- /package/Sources/CCPets/{MenuPetSizeView.m → UI/MenuPetSizeView.m} +0 -0
- /package/Sources/CCPets/{MenuToggleSwitch.h → UI/MenuToggleSwitch.h} +0 -0
|
@@ -1,43 +0,0 @@
|
|
|
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
|
-
import { t } from "./i18n.mjs";
|
|
7
|
-
|
|
8
|
-
const nodeCandidate = process.env.npm_node_execpath || process.execPath;
|
|
9
|
-
const npmCandidate = process.env.npm_execpath;
|
|
10
|
-
|
|
11
|
-
if (!nodeCandidate || !npmCandidate) {
|
|
12
|
-
console.warn(t("Auto-update config not saved: npm didn't provide the node/npm-cli paths."));
|
|
13
|
-
process.exit(0);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
let nodePath;
|
|
17
|
-
let npmCliPath;
|
|
18
|
-
try {
|
|
19
|
-
nodePath = fs.realpathSync(nodeCandidate);
|
|
20
|
-
npmCliPath = fs.realpathSync(npmCandidate);
|
|
21
|
-
} catch {
|
|
22
|
-
console.warn(t("Auto-update config not saved: the node/npm-cli paths don't exist."));
|
|
23
|
-
process.exit(0);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
if (!path.isAbsolute(nodePath) || !path.isAbsolute(npmCliPath)) {
|
|
27
|
-
console.warn(t("Auto-update config not saved: the node/npm-cli paths aren't absolute."));
|
|
28
|
-
process.exit(0);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const supportDirectory = process.env.CC_PETS_APPLICATION_SUPPORT_DIR ||
|
|
32
|
-
path.join(os.homedir(), "Library", "Application Support", "CC Pets");
|
|
33
|
-
const applicationsDirectory = process.env.CC_PETS_APPLICATIONS_DIR ||
|
|
34
|
-
path.join(os.homedir(), "Applications");
|
|
35
|
-
const configPath = path.join(supportDirectory, "updater.json");
|
|
36
|
-
fs.mkdirSync(supportDirectory, {recursive: true, mode: 0o700});
|
|
37
|
-
fs.writeFileSync(configPath, `${JSON.stringify({
|
|
38
|
-
schemaVersion: 2,
|
|
39
|
-
nodePath,
|
|
40
|
-
npmCliPath,
|
|
41
|
-
appPath: path.join(applicationsDirectory, "CC Pets.app")
|
|
42
|
-
}, null, 2)}\n`, {mode: 0o600});
|
|
43
|
-
fs.chmodSync(configPath, 0o600);
|
package/scripts/detect-cli.mjs
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
// "这台机器上到底装没装 Codex / Claude Code CLI"。安装器据此决定是否写它们的配置:
|
|
2
|
-
// 以前无条件 mkdir + 写 hooks.json / settings.json,没装的用户会被凭空造出 ~/.codex、
|
|
3
|
-
// ~/.claude,甚至被接管一个他还没有的 status line。
|
|
4
|
-
//
|
|
5
|
-
// 判据是"配置目录已存在"或"PATH 里有真二进制",两者取或:
|
|
6
|
-
// - 装了但从没跑过 → 没有配置目录,靠 PATH 认出来;
|
|
7
|
-
// - 装在非标准位置或用别的启动方式 → PATH 里找不到,靠配置目录认出来。
|
|
8
|
-
// 安装器自己不再创建这两个目录,所以"目录存在"是一个干净的信号,不会自证。
|
|
9
|
-
|
|
10
|
-
import fs from "node:fs";
|
|
11
|
-
import os from "node:os";
|
|
12
|
-
import path from "node:path";
|
|
13
|
-
|
|
14
|
-
const shimDirectory = () => path.resolve(
|
|
15
|
-
process.env.CC_PETS_SHIM_DIR || path.join(os.homedir(), ".cc-pets/shims"));
|
|
16
|
-
|
|
17
|
-
const isDirectory = (target) => {
|
|
18
|
-
try {
|
|
19
|
-
return fs.statSync(target).isDirectory();
|
|
20
|
-
} catch {
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
// 不能直接用 `which codex`:安装完成后 shim 目录就排在 PATH 最前面,命中的是我们自己的
|
|
26
|
-
// 包装器,等于自己证明自己。这里跳过 shim 目录,并且对解析后落在包装器上的候选再兜一层
|
|
27
|
-
// (复制而非软链安装时,shim 可能不在 CC_PETS_SHIM_DIR 里)。
|
|
28
|
-
const hasRealExecutable = (name) => {
|
|
29
|
-
const shim = shimDirectory();
|
|
30
|
-
const wrapperNames = new Set([`${name}-with-pet`, "codex-with-pet", "claude-with-pet"]);
|
|
31
|
-
for (const entry of (process.env.PATH || "").split(path.delimiter)) {
|
|
32
|
-
if (!entry) continue;
|
|
33
|
-
let resolvedEntry;
|
|
34
|
-
try {
|
|
35
|
-
resolvedEntry = fs.realpathSync(entry);
|
|
36
|
-
} catch {
|
|
37
|
-
resolvedEntry = path.resolve(entry);
|
|
38
|
-
}
|
|
39
|
-
if (resolvedEntry === shim) continue;
|
|
40
|
-
const candidate = path.join(entry, name);
|
|
41
|
-
try {
|
|
42
|
-
const stats = fs.statSync(candidate);
|
|
43
|
-
if (!stats.isFile() || (stats.mode & 0o111) === 0) continue;
|
|
44
|
-
const real = fs.realpathSync(candidate);
|
|
45
|
-
if (path.dirname(real) === shim) continue;
|
|
46
|
-
if (wrapperNames.has(path.basename(real))) continue;
|
|
47
|
-
return true;
|
|
48
|
-
} catch {
|
|
49
|
-
// 断链或没权限的候选直接跳过,继续看 PATH 里的下一个。
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
return false;
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
// 逃生舱:探测漏判时(装在容器里、PATH 被裁剪过、CI 造假环境)用户可以强制安装。
|
|
56
|
-
// CODEX_REAL_BIN / CLAUDE_REAL_BIN 沿用 bin/*-with-pet 已有的约定。
|
|
57
|
-
const forced = (realBinVariable) =>
|
|
58
|
-
process.env.CC_PETS_ASSUME_CLI === "1" || (process.env[realBinVariable] || "").length > 0;
|
|
59
|
-
|
|
60
|
-
export const detectCodexCLI = () =>
|
|
61
|
-
forced("CODEX_REAL_BIN") ||
|
|
62
|
-
isDirectory(process.env.CODEX_HOME || path.join(os.homedir(), ".codex")) ||
|
|
63
|
-
hasRealExecutable("codex");
|
|
64
|
-
|
|
65
|
-
export const detectClaudeCLI = () =>
|
|
66
|
-
forced("CLAUDE_REAL_BIN") ||
|
|
67
|
-
isDirectory(process.env.CLAUDE_CONFIG_DIR || path.join(os.homedir(), ".claude")) ||
|
|
68
|
-
hasRealExecutable("claude");
|
package/scripts/doctor.mjs
DELETED
|
@@ -1,470 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
// `cc-pets paths` 与 `cc-pets doctor`。
|
|
3
|
-
//
|
|
4
|
-
// 两者都只读:不改任何配置、不拉起桌宠。输出常被贴进 issue,所以 home 一律显示成 `~`,
|
|
5
|
-
// 不打印 status line 原命令、会话内容或 token。
|
|
6
|
-
// 桌宠自己的数据路径以原生程序 `--paths` 为准(与运行时同一套函数、同样认环境变量覆盖),
|
|
7
|
-
// 这里只补上 Node 侧才知道的部分(CC Bridge、shim、各 CLI 的配置文件)。
|
|
8
|
-
|
|
9
|
-
import { execFileSync } from "node:child_process";
|
|
10
|
-
import fs from "node:fs";
|
|
11
|
-
import os from "node:os";
|
|
12
|
-
import path from "node:path";
|
|
13
|
-
import { fileURLToPath } from "node:url";
|
|
14
|
-
import { detectClaudeCLI, detectCodexCLI } from "./detect-cli.mjs";
|
|
15
|
-
import {
|
|
16
|
-
CLAUDE_HOOK, CODEX_HOOK, LEGACY_CLAUDE_HOOK, LEGACY_CODEX_HOOK, SHIM_START_MARKER,
|
|
17
|
-
STATUS_LINE_MARKER, STATUS_LINE_START_MARKER, isManagedHookCommand, isManagedStatusLine,
|
|
18
|
-
resolveStatusLineScript
|
|
19
|
-
} from "./integration-markers.mjs";
|
|
20
|
-
import { HOOK_MARKER, describeCodexQueue } from "./bridge/install.mjs";
|
|
21
|
-
import { currentOptions } from "./bridge/options.mjs";
|
|
22
|
-
import { probeCodexQueue, resolveRealExecutable } from "./bridge/process.mjs";
|
|
23
|
-
import { bridgeDirectory, bridgeHomeDirectory, isBridgeEnabled } from "./bridge/store.mjs";
|
|
24
|
-
import { t } from "./i18n.mjs";
|
|
25
|
-
|
|
26
|
-
const projectDir = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
|
|
27
|
-
const petBinary = path.join(projectDir, ".build/release/cc-pets");
|
|
28
|
-
const packageVersion = JSON.parse(fs.readFileSync(path.join(projectDir, "package.json"), "utf8")).version;
|
|
29
|
-
const home = os.homedir();
|
|
30
|
-
const claudeHome = process.env.CLAUDE_CONFIG_DIR || path.join(home, ".claude");
|
|
31
|
-
const codexHome = process.env.CODEX_HOME || path.join(home, ".codex");
|
|
32
|
-
const shimDirectory = path.resolve(process.env.CC_PETS_SHIM_DIR || path.join(home, ".cc-pets/shims"));
|
|
33
|
-
const shellRC = path.join(process.env.ZDOTDIR || home, ".zshrc");
|
|
34
|
-
const installedApp = path.join(process.env.CC_PETS_APPLICATIONS_DIR || path.join(home, "Applications"), "CC Pets.app");
|
|
35
|
-
|
|
36
|
-
const tilde = (value) => {
|
|
37
|
-
if (typeof value !== "string") return value;
|
|
38
|
-
if (value === home) return "~";
|
|
39
|
-
return value.startsWith(`${home}/`) ? `~${value.slice(home.length)}` : value;
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
const run = (executable, args) => {
|
|
43
|
-
try {
|
|
44
|
-
return execFileSync(executable, args, { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"], timeout: 10_000 });
|
|
45
|
-
} catch {
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
const nativePaths = () => {
|
|
51
|
-
const output = fs.existsSync(petBinary) ? run(petBinary, ["--paths"]) : null;
|
|
52
|
-
try {
|
|
53
|
-
return output ? JSON.parse(output) : null;
|
|
54
|
-
} catch {
|
|
55
|
-
return null;
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
const sizeOf = (target) => {
|
|
60
|
-
let stats;
|
|
61
|
-
try {
|
|
62
|
-
stats = fs.lstatSync(target);
|
|
63
|
-
} catch {
|
|
64
|
-
return null;
|
|
65
|
-
}
|
|
66
|
-
if (!stats.isDirectory()) return stats.size;
|
|
67
|
-
let total = 0;
|
|
68
|
-
for (const entry of fs.readdirSync(target)) total += sizeOf(path.join(target, entry)) ?? 0;
|
|
69
|
-
return total;
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
const formatSize = (bytes) => {
|
|
73
|
-
if (bytes === null) return t("missing");
|
|
74
|
-
if (bytes < 1024) return `${bytes} B`;
|
|
75
|
-
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
|
|
76
|
-
return `${(bytes / 1024 / 1024).toFixed(1)} MB`;
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
// 终端里中文占两列,按 length 对齐会错位。
|
|
80
|
-
const displayWidth = (text) => [...text].reduce((width, character) =>
|
|
81
|
-
width + (/[\u1100-\u115f\u2e80-\ua4cf\uac00-\ud7a3\uf900-\ufaff\ufe30-\ufe4f\uff00-\uff60\uffe0-\uffe6]/.test(character) ? 2 : 1), 0);
|
|
82
|
-
|
|
83
|
-
const readJson = (file) => {
|
|
84
|
-
try {
|
|
85
|
-
return { value: JSON.parse(fs.readFileSync(file, "utf8")) };
|
|
86
|
-
} catch (error) {
|
|
87
|
-
return { error: error.code === "ENOENT" ? "missing" : "invalid" };
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
// ---------------------------------------------------------------------------
|
|
92
|
-
// cc-pets paths
|
|
93
|
-
|
|
94
|
-
const pathGroups = (native) => {
|
|
95
|
-
const ccPetsHome = bridgeHomeDirectory();
|
|
96
|
-
const groups = [
|
|
97
|
-
{
|
|
98
|
-
title: t("Settings (removed by --purge)"),
|
|
99
|
-
items: native ? [[t("Preferences"), native.preferences]] : []
|
|
100
|
-
},
|
|
101
|
-
{
|
|
102
|
-
title: t("Your content (kept by both clean and --purge)"),
|
|
103
|
-
items: [
|
|
104
|
-
...(native ? [
|
|
105
|
-
[t("Pet sprites"), native.pets],
|
|
106
|
-
[t("Shared lines"), native.phrases],
|
|
107
|
-
[t("Per-pet lines"), native.petPhrases]
|
|
108
|
-
] : []),
|
|
109
|
-
[t("CC Bridge switch"), path.join(ccPetsHome, "bridge-enabled")],
|
|
110
|
-
["codex / claude shim", shimDirectory]
|
|
111
|
-
]
|
|
112
|
-
},
|
|
113
|
-
{
|
|
114
|
-
title: t("App data (removed by --purge; clean only clears the token cache and update log)"),
|
|
115
|
-
items: native ? [
|
|
116
|
-
[t("App data directory"), native.applicationSupport],
|
|
117
|
-
[t("Quota history"), native.quotaHistory],
|
|
118
|
-
[t("Auto-update config"), path.join(native.applicationSupport, "updater.json")]
|
|
119
|
-
] : []
|
|
120
|
-
},
|
|
121
|
-
{
|
|
122
|
-
title: t("Caches and runtime state (cleared by clean; safe to lose)"),
|
|
123
|
-
items: [
|
|
124
|
-
...(native ? [
|
|
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]
|
|
131
|
-
] : []),
|
|
132
|
-
[t("CC Bridge state directory"), bridgeDirectory()]
|
|
133
|
-
]
|
|
134
|
-
},
|
|
135
|
-
{
|
|
136
|
-
title: t("Program and integrations"),
|
|
137
|
-
items: [
|
|
138
|
-
[t("npm package"), projectDir],
|
|
139
|
-
[t("Installed app"), installedApp],
|
|
140
|
-
[t("Claude Code settings"), path.join(claudeHome, "settings.json")],
|
|
141
|
-
["Codex Hooks", path.join(codexHome, "hooks.json")],
|
|
142
|
-
[t("Shell config"), shellRC]
|
|
143
|
-
]
|
|
144
|
-
}
|
|
145
|
-
];
|
|
146
|
-
return groups.filter((group) => group.items.length > 0);
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
const printPaths = (asJson) => {
|
|
150
|
-
const native = nativePaths();
|
|
151
|
-
const groups = pathGroups(native);
|
|
152
|
-
if (asJson) {
|
|
153
|
-
const document = {
|
|
154
|
-
version: packageVersion,
|
|
155
|
-
running: native?.running ?? null,
|
|
156
|
-
groups: groups.map((group) => ({
|
|
157
|
-
title: group.title,
|
|
158
|
-
items: group.items.map(([label, target]) => ({ label, path: tilde(target), bytes: sizeOf(target) }))
|
|
159
|
-
}))
|
|
160
|
-
};
|
|
161
|
-
console.log(JSON.stringify(document, null, 2));
|
|
162
|
-
return 0;
|
|
163
|
-
}
|
|
164
|
-
if (!native) {
|
|
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
|
-
`));
|
|
167
|
-
}
|
|
168
|
-
const width = Math.max(...groups.flatMap((group) => group.items.map(([label]) => displayWidth(label))));
|
|
169
|
-
groups.forEach((group, index) => {
|
|
170
|
-
if (index > 0) console.log("");
|
|
171
|
-
console.log(group.title);
|
|
172
|
-
for (const [label, target] of group.items) {
|
|
173
|
-
console.log(` ${label}${" ".repeat(width - displayWidth(label) + 2)}${tilde(target)} (${formatSize(sizeOf(target))})`);
|
|
174
|
-
}
|
|
175
|
-
});
|
|
176
|
-
return 0;
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
// ---------------------------------------------------------------------------
|
|
180
|
-
// cc-pets doctor
|
|
181
|
-
|
|
182
|
-
const ICONS = { ok: "✅", warn: "⚠️ ", fail: "❌", info: "ℹ️ " };
|
|
183
|
-
|
|
184
|
-
const versionOfApp = (appPath) => {
|
|
185
|
-
const plist = path.join(appPath, "Contents/Info.plist");
|
|
186
|
-
if (!fs.existsSync(plist)) return null;
|
|
187
|
-
return (run("/usr/bin/plutil", ["-extract", "CFBundleShortVersionString", "raw", "-o", "-", plist]) || "").trim() || null;
|
|
188
|
-
};
|
|
189
|
-
|
|
190
|
-
// 认出配置里属于 CC Pets 的 hook,并区分"指向当前安装"和"指向别处"(包被挪走、换了 node 版本重装后
|
|
191
|
-
// 常见,hook 每次触发都会失败)。
|
|
192
|
-
const inspectHooks = (configFile, signature, legacySignature) => {
|
|
193
|
-
const { value, error } = readJson(configFile);
|
|
194
|
-
if (error === "invalid") return { error: "invalid" };
|
|
195
|
-
const commands = Object.values(value?.hooks ?? {})
|
|
196
|
-
.filter(Array.isArray).flat()
|
|
197
|
-
.flatMap((group) => (Array.isArray(group?.hooks) ? group.hooks : []))
|
|
198
|
-
.map((handler) => handler?.command);
|
|
199
|
-
const managed = commands.filter((command) => isManagedHookCommand(command, signature));
|
|
200
|
-
const current = managed.filter((command) => command.includes(`'${petBinary}'`));
|
|
201
|
-
return {
|
|
202
|
-
total: managed.length,
|
|
203
|
-
stale: managed.length - current.length,
|
|
204
|
-
legacy: commands.filter((command) => isManagedHookCommand(command, legacySignature)).length,
|
|
205
|
-
bridge: commands.filter((command) => typeof command === "string" && command.startsWith(HOOK_MARKER)).length
|
|
206
|
-
};
|
|
207
|
-
};
|
|
208
|
-
|
|
209
|
-
const hookChecks = (name, configFile, signature, legacySignature) => {
|
|
210
|
-
const hooks = inspectHooks(configFile, signature, legacySignature);
|
|
211
|
-
if (hooks.error) {
|
|
212
|
-
return {
|
|
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") }],
|
|
214
|
-
bridgeHooks: 0
|
|
215
|
-
};
|
|
216
|
-
}
|
|
217
|
-
const results = [];
|
|
218
|
-
if (hooks.total === 0) {
|
|
219
|
-
results.push({ level: "fail", title: t("{name} hooks not installed", { name }), fix: "cc-pets install" });
|
|
220
|
-
} else if (hooks.stale > 0) {
|
|
221
|
-
results.push({
|
|
222
|
-
level: "warn",
|
|
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 }),
|
|
226
|
-
fix: "cc-pets install"
|
|
227
|
-
});
|
|
228
|
-
} else {
|
|
229
|
-
results.push({ level: "ok", title: t("{name} hooks installed ({total} events)", { name, total: hooks.total }) });
|
|
230
|
-
}
|
|
231
|
-
if (hooks.legacy > 0) {
|
|
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
|
-
});
|
|
239
|
-
}
|
|
240
|
-
return { results, bridgeHooks: hooks.bridge };
|
|
241
|
-
};
|
|
242
|
-
|
|
243
|
-
const statusLineCheck = () => {
|
|
244
|
-
const { value } = readJson(path.join(claudeHome, "settings.json"));
|
|
245
|
-
const command = typeof value?.statusLine?.command === "string" ? value.statusLine.command : "";
|
|
246
|
-
if (isManagedStatusLine(command, STATUS_LINE_MARKER)) {
|
|
247
|
-
return { level: "ok", title: t("Claude status line feeds quota data through the wrapper") };
|
|
248
|
-
}
|
|
249
|
-
const script = resolveStatusLineScript(command);
|
|
250
|
-
let content = "";
|
|
251
|
-
try {
|
|
252
|
-
content = script ? fs.readFileSync(script, "utf8") : "";
|
|
253
|
-
} catch {
|
|
254
|
-
content = "";
|
|
255
|
-
}
|
|
256
|
-
if (content.includes(STATUS_LINE_START_MARKER)) {
|
|
257
|
-
return content.includes(`'${petBinary}'`)
|
|
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" };
|
|
260
|
-
}
|
|
261
|
-
return {
|
|
262
|
-
level: "warn",
|
|
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 %"),
|
|
264
|
-
fix: "cc-pets install"
|
|
265
|
-
};
|
|
266
|
-
};
|
|
267
|
-
|
|
268
|
-
const shimChecks = () => {
|
|
269
|
-
const results = [];
|
|
270
|
-
let rc = "";
|
|
271
|
-
try {
|
|
272
|
-
rc = fs.readFileSync(shellRC, "utf8");
|
|
273
|
-
} catch {
|
|
274
|
-
rc = "";
|
|
275
|
-
}
|
|
276
|
-
results.push(rc.includes(SHIM_START_MARKER)
|
|
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" });
|
|
279
|
-
|
|
280
|
-
const broken = [];
|
|
281
|
-
for (const name of ["codex", "claude"]) {
|
|
282
|
-
const shim = path.join(shimDirectory, name);
|
|
283
|
-
let link = null;
|
|
284
|
-
try {
|
|
285
|
-
link = fs.readlinkSync(shim);
|
|
286
|
-
} catch {
|
|
287
|
-
broken.push(t("{name} (missing)", { name }));
|
|
288
|
-
continue;
|
|
289
|
-
}
|
|
290
|
-
if (!fs.existsSync(path.resolve(shimDirectory, link))) broken.push(t("{name} (target doesn't exist)", { name }));
|
|
291
|
-
}
|
|
292
|
-
results.push(broken.length === 0
|
|
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" });
|
|
295
|
-
|
|
296
|
-
const entries = (process.env.PATH || "").split(path.delimiter).filter(Boolean).map((entry) => path.resolve(entry));
|
|
297
|
-
const index = entries.indexOf(shimDirectory);
|
|
298
|
-
if (index < 0) {
|
|
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) }) });
|
|
300
|
-
} else if (index > 0) {
|
|
301
|
-
const shadowing = entries.slice(0, index).find((entry) =>
|
|
302
|
-
["codex", "claude"].some((name) => fs.existsSync(path.join(entry, name))));
|
|
303
|
-
results.push(shadowing
|
|
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") });
|
|
306
|
-
} else {
|
|
307
|
-
results.push({ level: "ok", title: t("The shim directory is first in PATH") });
|
|
308
|
-
}
|
|
309
|
-
return results;
|
|
310
|
-
};
|
|
311
|
-
|
|
312
|
-
const realBinaryCheck = (name, variable) => {
|
|
313
|
-
const real = resolveRealExecutable(name, variable);
|
|
314
|
-
return real && fs.existsSync(real)
|
|
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}` };
|
|
317
|
-
};
|
|
318
|
-
|
|
319
|
-
const updaterCheck = (native) => {
|
|
320
|
-
if (!native) return null;
|
|
321
|
-
const file = path.join(native.applicationSupport, "updater.json");
|
|
322
|
-
const { value, error } = readJson(file);
|
|
323
|
-
if (error) {
|
|
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" };
|
|
325
|
-
}
|
|
326
|
-
const missing = ["nodePath", "npmCliPath"].filter((key) => !value?.[key] || !fs.existsSync(value[key]));
|
|
327
|
-
return missing.length === 0
|
|
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" };
|
|
330
|
-
};
|
|
331
|
-
|
|
332
|
-
const formatAge = (milliseconds) => {
|
|
333
|
-
const minutes = Math.round(milliseconds / 60_000);
|
|
334
|
-
if (minutes < 60) return t("{minutes} min ago", { minutes });
|
|
335
|
-
const hours = Math.round(minutes / 60);
|
|
336
|
-
return hours < 48 ? t("{hours} h ago", { hours }) : t("{days} days ago", { days: Math.round(hours / 24) });
|
|
337
|
-
};
|
|
338
|
-
|
|
339
|
-
const runDoctor = () => {
|
|
340
|
-
const native = nativePaths();
|
|
341
|
-
const sections = [];
|
|
342
|
-
const claudeDetected = detectClaudeCLI();
|
|
343
|
-
const codexDetected = detectCodexCLI();
|
|
344
|
-
|
|
345
|
-
const nodeMajor = Number(process.versions.node.split(".")[0]);
|
|
346
|
-
const program = [
|
|
347
|
-
nodeMajor >= 18
|
|
348
|
-
? { level: "ok", title: `Node.js ${process.versions.node}` }
|
|
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) }) }
|
|
351
|
-
];
|
|
352
|
-
const binaryVersion = fs.existsSync(petBinary) ? (run(petBinary, ["--version"]) || "").trim().replace(/^cc-pets\s+/, "") : null;
|
|
353
|
-
if (!binaryVersion) {
|
|
354
|
-
program.push({ level: "fail", title: t("Native binary isn't built or can't run"), fix: "cc-pets install" });
|
|
355
|
-
} else if (binaryVersion !== packageVersion) {
|
|
356
|
-
program.push({ level: "warn", title: t("Native binary {binaryVersion} doesn't match npm package {packageVersion}", { binaryVersion, packageVersion }), fix: "cc-pets install" });
|
|
357
|
-
} else {
|
|
358
|
-
program.push({ level: "ok", title: t("Native binary {binaryVersion}", { binaryVersion }) });
|
|
359
|
-
}
|
|
360
|
-
const appVersion = versionOfApp(installedApp);
|
|
361
|
-
if (!appVersion) {
|
|
362
|
-
program.push({ level: "warn", title: t("Installed app not found: {installedApp}", { installedApp: tilde(installedApp) }), fix: "cc-pets install" });
|
|
363
|
-
} else if (appVersion !== packageVersion) {
|
|
364
|
-
program.push({ level: "warn", title: t("Installed app {appVersion} doesn't match npm package {packageVersion}", { appVersion, packageVersion }), fix: "cc-pets install" });
|
|
365
|
-
} else {
|
|
366
|
-
program.push({ level: "ok", title: t("Installed app {appVersion}", { appVersion }) });
|
|
367
|
-
}
|
|
368
|
-
if (native) program.push({ level: "info", title: native.running ? t("The pet is running") : t("The pet isn't running") });
|
|
369
|
-
const updater = updaterCheck(native);
|
|
370
|
-
if (updater) program.push(updater);
|
|
371
|
-
sections.push({ title: t("Program"), results: program });
|
|
372
|
-
|
|
373
|
-
let claudeBridgeHooks = 0;
|
|
374
|
-
if (claudeDetected) {
|
|
375
|
-
const { results, bridgeHooks } = hookChecks("Claude Code", path.join(claudeHome, "settings.json"), CLAUDE_HOOK, LEGACY_CLAUDE_HOOK);
|
|
376
|
-
claudeBridgeHooks = bridgeHooks;
|
|
377
|
-
const claude = [...results, statusLineCheck()];
|
|
378
|
-
if (native) {
|
|
379
|
-
let modified = null;
|
|
380
|
-
try {
|
|
381
|
-
modified = fs.statSync(native.claudeUsage).mtimeMs;
|
|
382
|
-
} catch {
|
|
383
|
-
modified = null;
|
|
384
|
-
}
|
|
385
|
-
claude.push(modified
|
|
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)") });
|
|
388
|
-
}
|
|
389
|
-
sections.push({ title: "Claude Code", results: claude });
|
|
390
|
-
} else {
|
|
391
|
-
sections.push({ title: "Claude Code", results: [{ level: "info", title: t("Claude Code CLI not detected, skipped") }] });
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
let codexBridgeHooks = 0;
|
|
395
|
-
if (codexDetected) {
|
|
396
|
-
const { results, bridgeHooks } = hookChecks("Codex", path.join(codexHome, "hooks.json"), CODEX_HOOK, LEGACY_CODEX_HOOK);
|
|
397
|
-
codexBridgeHooks = bridgeHooks;
|
|
398
|
-
sections.push({
|
|
399
|
-
title: "Codex",
|
|
400
|
-
results: [
|
|
401
|
-
...results,
|
|
402
|
-
{ level: "info", title: t("Codex only runs CC Pets hooks after you trust them in /hooks (can't be checked automatically)") }
|
|
403
|
-
]
|
|
404
|
-
});
|
|
405
|
-
} else {
|
|
406
|
-
sections.push({ title: "Codex", results: [{ level: "info", title: t("Codex CLI not detected, skipped") }] });
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
sections.push({
|
|
410
|
-
title: t("Shell integration"),
|
|
411
|
-
results: [
|
|
412
|
-
...shimChecks(),
|
|
413
|
-
...(codexDetected ? [realBinaryCheck("codex", "CODEX_REAL_BIN")] : []),
|
|
414
|
-
...(claudeDetected ? [realBinaryCheck("claude", "CLAUDE_REAL_BIN")] : [])
|
|
415
|
-
]
|
|
416
|
-
});
|
|
417
|
-
|
|
418
|
-
if (!isBridgeEnabled()) {
|
|
419
|
-
sections.push({ title: "CC Bridge", results: [{ level: "info", title: t("Off (optional; turn on with cc-pets bridge enable)") }] });
|
|
420
|
-
} else {
|
|
421
|
-
const bridge = [{ level: "ok", title: t("Enabled") }];
|
|
422
|
-
if (claudeDetected) {
|
|
423
|
-
bridge.push(claudeBridgeHooks > 0
|
|
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" });
|
|
426
|
-
}
|
|
427
|
-
if (codexDetected) {
|
|
428
|
-
bridge.push(codexBridgeHooks > 0
|
|
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" });
|
|
431
|
-
if (currentOptions().wake) {
|
|
432
|
-
const notice = describeCodexQueue(probeCodexQueue());
|
|
433
|
-
bridge.push(notice
|
|
434
|
-
? { level: "warn", title: notice }
|
|
435
|
-
: { level: "ok", title: t("Codex supports codex queue, so it can be woken automatically") });
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
sections.push({ title: "CC Bridge", results: bridge });
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
console.log(t("CC Pets diagnostics (npm package {packageVersion}, {platform} {release})", { packageVersion, platform: os.platform(), release: os.release() }));
|
|
442
|
-
const counts = { ok: 0, warn: 0, fail: 0, info: 0 };
|
|
443
|
-
for (const section of sections) {
|
|
444
|
-
console.log(`\n${section.title}`);
|
|
445
|
-
for (const result of section.results) {
|
|
446
|
-
counts[result.level] += 1;
|
|
447
|
-
console.log(` ${ICONS[result.level]} ${result.title}`);
|
|
448
|
-
if (result.fix) console.log(` → ${result.fix}`);
|
|
449
|
-
}
|
|
450
|
-
}
|
|
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."));
|
|
457
|
-
return counts.fail > 0 ? 1 : 0;
|
|
458
|
-
};
|
|
459
|
-
|
|
460
|
-
// ---------------------------------------------------------------------------
|
|
461
|
-
|
|
462
|
-
const [command, ...args] = process.argv.slice(2);
|
|
463
|
-
if (command === "paths") {
|
|
464
|
-
process.exitCode = printPaths(args.includes("--json"));
|
|
465
|
-
} else if (command === "doctor") {
|
|
466
|
-
process.exitCode = runDoctor();
|
|
467
|
-
} else {
|
|
468
|
-
console.error(t("Usage: doctor.mjs paths [--json] | doctor"));
|
|
469
|
-
process.exitCode = 2;
|
|
470
|
-
}
|