cc-pets 2.1.0 → 2.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CC_BRIDGE.md +11 -6
- package/CC_BRIDGE.zh-CN.md +8 -4
- package/CHANGELOG.md +59 -1
- package/CHANGELOG.zh-CN.md +59 -1
- package/README.md +60 -12
- package/README.zh-CN.md +58 -13
- package/Sources/CCPets/CCPetsAppDelegate+AgentEvents.m +215 -0
- package/Sources/CCPets/CCPetsAppDelegate+AgentStatus.m +660 -0
- package/Sources/CCPets/CCPetsAppDelegate+Bridge.m +297 -0
- package/Sources/CCPets/CCPetsAppDelegate+Pets.m +187 -0
- package/Sources/CCPets/CCPetsAppDelegate+Private.h +322 -0
- package/Sources/CCPets/CCPetsAppDelegate+Quota.m +216 -0
- package/Sources/CCPets/CCPetsAppDelegate+Settings.m +205 -0
- package/Sources/CCPets/CCPetsAppDelegate+Speech.m +392 -0
- package/Sources/CCPets/CCPetsAppDelegate+Update.m +458 -0
- package/Sources/CCPets/CCPetsAppDelegate.h +17 -16
- package/Sources/CCPets/CCPetsAppDelegate.m +74 -2406
- package/Sources/CCPets/CCPetsCleanup.h +4 -0
- package/Sources/CCPets/CCPetsCleanup.m +35 -2
- package/Sources/CCPets/CCPetsCodexRateLimits.h +1 -0
- package/Sources/CCPets/CCPetsCodexRateLimits.m +7 -0
- package/Sources/CCPets/CCPetsEvents.m +1 -1
- package/Sources/CCPets/CCPetsGlassMenu.h +10 -0
- package/Sources/CCPets/CCPetsGlassMenu.m +196 -0
- package/Sources/CCPets/CCPetsGlassView.h +31 -0
- package/Sources/CCPets/CCPetsGlassView.m +246 -0
- package/Sources/CCPets/CCPetsPaths.h +7 -1
- package/Sources/CCPets/CCPetsPaths.m +14 -1
- package/Sources/CCPets/CCPetsTerminalFocus.h +15 -0
- package/Sources/CCPets/CCPetsTerminalFocus.m +306 -15
- package/Sources/CCPets/CCPetsUsage.h +2 -1
- package/Sources/CCPets/CCPetsUsage.m +69 -21
- package/Sources/CCPets/CCPetsUsageMonitor.m +43 -8
- package/Sources/CCPets/CCPetsVersion.h +7 -0
- package/Sources/CCPets/CCPetsVersion.m +82 -0
- package/Sources/CCPets/MenuChoiceRow.h +19 -0
- package/Sources/CCPets/MenuChoiceRow.m +96 -0
- package/Sources/CCPets/MenuHintView.h +15 -0
- package/Sources/CCPets/MenuHintView.m +128 -0
- package/Sources/CCPets/PetView.h +2 -0
- package/Sources/CCPets/PetView.m +121 -53
- package/Sources/CCPets/QuotaDashboardView.h +3 -4
- package/Sources/CCPets/QuotaDashboardView.m +222 -146
- package/Sources/CCPets/main.m +29 -0
- package/bin/cc-pets +39 -1
- package/bin/codex-with-pet +2 -0
- package/package.json +3 -2
- package/scripts/bridge/cli.mjs +9 -2
- package/scripts/bridge/core.mjs +1 -1
- package/scripts/bridge/install.mjs +23 -1
- package/scripts/bridge/process.mjs +22 -0
- package/scripts/doctor.mjs +456 -0
- package/scripts/install-claude-hooks.mjs +12 -18
- package/scripts/install-codex-hooks.mjs +3 -9
- package/scripts/integration-markers.mjs +51 -0
- package/scripts/pet-store.mjs +2 -1
- package/scripts/uninstall-integrations.mjs +16 -44
- package/scripts/uninstall-shell-integration.sh +3 -3
|
@@ -5,6 +5,11 @@ 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";
|
|
8
13
|
|
|
9
14
|
const binary = process.argv[2];
|
|
10
15
|
if (!binary) {
|
|
@@ -23,24 +28,13 @@ if (!detectClaudeCLI()) {
|
|
|
23
28
|
|
|
24
29
|
const claudeHome = process.env.CLAUDE_CONFIG_DIR || path.join(os.homedir(), ".claude");
|
|
25
30
|
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);
|
|
31
|
+
const marker = CLAUDE_HOOK.marker;
|
|
32
|
+
const statusLineMarker = STATUS_LINE_MARKER;
|
|
33
|
+
const managedHookSignatures = [CLAUDE_HOOK, LEGACY_CLAUDE_HOOK];
|
|
34
|
+
const managedStatusLineMarkers = [STATUS_LINE_MARKER, LEGACY_STATUS_LINE_MARKER];
|
|
35
|
+
const statusLineStartMarker = STATUS_LINE_START_MARKER;
|
|
36
|
+
const statusLineEndMarker = STATUS_LINE_END_MARKER;
|
|
37
|
+
const createdStatusLineMarker = CREATED_STATUS_LINE_MARKER;
|
|
44
38
|
const shellQuote = (value) => `'${value.replaceAll("'", `'\\''`)}'`;
|
|
45
39
|
const escapeRegExp = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
46
40
|
const statusLineBlockPattern = new RegExp(
|
|
@@ -4,6 +4,7 @@ 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";
|
|
7
8
|
|
|
8
9
|
const binary = process.argv[2];
|
|
9
10
|
if (!binary) {
|
|
@@ -22,15 +23,8 @@ if (!detectCodexCLI()) {
|
|
|
22
23
|
|
|
23
24
|
const codexHome = process.env.CODEX_HOME || path.join(os.homedir(), ".codex");
|
|
24
25
|
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`);
|
|
26
|
+
const marker = CODEX_HOOK.marker;
|
|
27
|
+
const managedSignatures = [CODEX_HOOK, LEGACY_CODEX_HOOK];
|
|
34
28
|
const shellQuote = (value) => `'${value.replaceAll("'", `'\\''`)}'`;
|
|
35
29
|
const command = `${marker} ${shellQuote(path.resolve(binary))} --hook`;
|
|
36
30
|
const events = [
|
|
@@ -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
|
+
};
|
package/scripts/pet-store.mjs
CHANGED
|
@@ -51,8 +51,9 @@ const petsRoot = () => {
|
|
|
51
51
|
if (override && override.length > 0) return path.resolve(untilde(override));
|
|
52
52
|
return path.join(os.homedir(), ".cc-pets", "pets");
|
|
53
53
|
};
|
|
54
|
+
// 与 CC Bridge、cc-pets clean 一致:CC_PETS_HOME 可覆盖 ~/.cc-pets。
|
|
54
55
|
const cachePath = (sourceName) =>
|
|
55
|
-
path.join(os.homedir(), ".cc-pets", "cache", `manifest-${sourceName}.json`);
|
|
56
|
+
path.join(process.env.CC_PETS_HOME || path.join(os.homedir(), ".cc-pets"), "cache", `manifest-${sourceName}.json`);
|
|
56
57
|
// 每个源都可以单独用环境变量改清单地址,主要给测试和自建源的本地联调用。
|
|
57
58
|
const manifestUrlFor = (sourceName) =>
|
|
58
59
|
process.env[`CC_PETS_MANIFEST_URL_${sourceName.toUpperCase()}`] || SOURCES[sourceName].manifestUrl;
|
|
@@ -3,55 +3,27 @@
|
|
|
3
3
|
import fs from "node:fs";
|
|
4
4
|
import os from "node:os";
|
|
5
5
|
import path from "node:path";
|
|
6
|
+
import {
|
|
7
|
+
CLAUDE_HOOK, CODEX_HOOK, CREATED_STATUS_LINE_MARKER, LEGACY_CLAUDE_HOOK, LEGACY_CODEX_HOOK,
|
|
8
|
+
LEGACY_STATUS_LINE_MARKER, SHIM_END_MARKER, SHIM_START_MARKER, STATUS_LINE_END_MARKER,
|
|
9
|
+
STATUS_LINE_MARKER, STATUS_LINE_START_MARKER, isManagedHookCommand, isManagedStatusLine,
|
|
10
|
+
resolveStatusLineScript
|
|
11
|
+
} from "./integration-markers.mjs";
|
|
6
12
|
|
|
7
13
|
const codexHome = process.env.CODEX_HOME || path.join(os.homedir(), ".codex");
|
|
8
14
|
const claudeHome = process.env.CLAUDE_CONFIG_DIR || path.join(os.homedir(), ".claude");
|
|
9
15
|
const preparingInstall = process.argv[2] === "--prepare-install";
|
|
10
16
|
const shellRC = process.argv[preparingInstall ? 3 : 2];
|
|
11
17
|
|
|
12
|
-
const currentCodexHook =
|
|
13
|
-
const legacyCodexHook =
|
|
14
|
-
const currentClaudeHook =
|
|
15
|
-
const legacyClaudeHook =
|
|
16
|
-
const currentStatusLineMarker =
|
|
17
|
-
const legacyStatusLineMarker =
|
|
18
|
-
const statusLineStartMarker =
|
|
19
|
-
const statusLineEndMarker =
|
|
20
|
-
const createdStatusLineMarker =
|
|
21
|
-
|
|
22
|
-
function isManagedHookCommand(value, signature) {
|
|
23
|
-
return typeof value === "string" &&
|
|
24
|
-
value.startsWith(`${signature.marker} `) &&
|
|
25
|
-
value.endsWith(`/.build/release/${signature.executable}' --hook`);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function isManagedStatusLine(value, marker) {
|
|
29
|
-
return typeof value === "string" &&
|
|
30
|
-
value.startsWith(`${marker} `) &&
|
|
31
|
-
/\/bin\/claude-statusline-with-pet' '[A-Za-z0-9+/=]*'$/.test(value);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// 与 install-claude-hooks.mjs 保持一致:`bash ~/x.sh` 这类带解释器前缀的命令同样指向一个
|
|
35
|
-
// 被就地注入过的脚本,卸载时也要能解析出来,否则 prelude 会残留在脚本里。
|
|
36
|
-
const interpreterPattern =
|
|
37
|
-
/^(?:\/usr\/bin\/env\s+)?(?:[^\s'"]*\/)?(?:ba|z|k|da)?sh((?:\s+-[A-Za-z]+)*)\s+(.+)$/s;
|
|
38
|
-
|
|
39
|
-
function unquote(value) {
|
|
40
|
-
const quoted = value.match(/^(['"])(.*)\1$/s);
|
|
41
|
-
return quoted ? quoted[2] : value;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function resolveStatusLineScript(value) {
|
|
45
|
-
if (typeof value !== "string") return null;
|
|
46
|
-
let candidate = unquote(value.trim());
|
|
47
|
-
const interpreted = candidate.match(interpreterPattern);
|
|
48
|
-
if (interpreted && !/-[A-Za-z]*c(?=\s|$)/.test(interpreted[1])) {
|
|
49
|
-
candidate = unquote(interpreted[2].trim());
|
|
50
|
-
}
|
|
51
|
-
if (candidate.startsWith("~/")) candidate = path.join(os.homedir(), candidate.slice(2));
|
|
52
|
-
if (!path.isAbsolute(candidate) || /[\s;&|<>`$()]/.test(candidate)) return null;
|
|
53
|
-
return path.resolve(candidate);
|
|
54
|
-
}
|
|
18
|
+
const currentCodexHook = CODEX_HOOK;
|
|
19
|
+
const legacyCodexHook = LEGACY_CODEX_HOOK;
|
|
20
|
+
const currentClaudeHook = CLAUDE_HOOK;
|
|
21
|
+
const legacyClaudeHook = LEGACY_CLAUDE_HOOK;
|
|
22
|
+
const currentStatusLineMarker = STATUS_LINE_MARKER;
|
|
23
|
+
const legacyStatusLineMarker = LEGACY_STATUS_LINE_MARKER;
|
|
24
|
+
const statusLineStartMarker = STATUS_LINE_START_MARKER;
|
|
25
|
+
const statusLineEndMarker = STATUS_LINE_END_MARKER;
|
|
26
|
+
const createdStatusLineMarker = CREATED_STATUS_LINE_MARKER;
|
|
55
27
|
|
|
56
28
|
function removeStatusLinePrelude(scriptPath) {
|
|
57
29
|
if (!scriptPath || !fs.existsSync(scriptPath)) return { changed: false, created: false };
|
|
@@ -175,7 +147,7 @@ if (shellRC && fs.existsSync(shellRC)) {
|
|
|
175
147
|
// cc-pets-codex / cc-pets-claude 是 alias 时代的段落。alias 区分大小写,挡不住
|
|
176
148
|
// Claude / CODEX 这类写法,已被 cc-pets-shims 的 PATH shim 取代;安装前的
|
|
177
149
|
// --prepare-install 会走到这里,顺带把老段落迁移掉。
|
|
178
|
-
let updated = removeMarkedBlock(original,
|
|
150
|
+
let updated = removeMarkedBlock(original, SHIM_START_MARKER, SHIM_END_MARKER);
|
|
179
151
|
updated = removeMarkedBlock(updated, "# >>> cc-pets-codex >>>", "# <<< cc-pets-codex <<<");
|
|
180
152
|
updated = removeMarkedBlock(updated, "# >>> cc-pets-claude >>>", "# <<< cc-pets-claude <<<");
|
|
181
153
|
updated = removeMarkedBlock(updated, "# >>> codex-pet >>>", "# <<< codex-pet <<<");
|
|
@@ -18,10 +18,10 @@ done
|
|
|
18
18
|
|
|
19
19
|
if (( PURGE && ! ASSUME_YES )); then
|
|
20
20
|
if [[ ! -t 0 ]]; then
|
|
21
|
-
print -u2 "
|
|
21
|
+
print -u2 "完整卸载会删除应用、额度历史、更新配置、日志和偏好(保留 ~/.cc-pets 的素材与台词)。非交互环境请显式添加 --yes。"
|
|
22
22
|
exit 2
|
|
23
23
|
fi
|
|
24
|
-
print -u2 "完整卸载会永久删除 CC Pets
|
|
24
|
+
print -u2 "完整卸载会永久删除 CC Pets 应用、额度历史、更新配置、日志和偏好;~/.cc-pets 下的桌宠素材与台词会保留。是否继续?[y/N] "
|
|
25
25
|
if ! read -r reply || [[ "${reply:l}" != "y" && "${reply:l}" != "yes" ]]; then
|
|
26
26
|
print "已取消完整卸载。"
|
|
27
27
|
exit 0
|
|
@@ -61,7 +61,7 @@ if (( PURGE )); then
|
|
|
61
61
|
fi
|
|
62
62
|
"${PET_BIN}" --purge-data
|
|
63
63
|
CC_PETS_SKIP_APP_STOP=1 "${PROJECT_DIR}/scripts/uninstall-app.sh"
|
|
64
|
-
print "
|
|
64
|
+
print "完整卸载完成;桌宠素材与台词保留在 ~/.cc-pets,不再需要可手动删除。npm 包本身如仍存在,可继续执行 npm uninstall -g cc-pets。"
|
|
65
65
|
exit 0
|
|
66
66
|
fi
|
|
67
67
|
|