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/pet-store.mjs
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
import fs from "node:fs";
|
|
12
12
|
import os from "node:os";
|
|
13
13
|
import path from "node:path";
|
|
14
|
+
import { t } from "./i18n.mjs";
|
|
14
15
|
|
|
15
16
|
// 一个源的完整定义就是这几项。以后接自建 registry 时在这里加一行即可,
|
|
16
17
|
// 命令、目录结构和桌宠端都不用动。
|
|
@@ -40,7 +41,7 @@ const USER_AGENT = (() => {
|
|
|
40
41
|
})();
|
|
41
42
|
|
|
42
43
|
// 不能 add、只会出现在已装素材里的来源。桌宠的"导入 Codex 素材"开关会写 source: "codex"。
|
|
43
|
-
const LOCAL_SOURCE_LABELS = { codex: "Codex
|
|
44
|
+
const LOCAL_SOURCE_LABELS = { codex: t("Codex (imported)") };
|
|
44
45
|
const DEFAULT_SOURCE = process.env.CC_PETS_SOURCE || "petdex";
|
|
45
46
|
const SIDECAR_NAME = ".source.json";
|
|
46
47
|
const MANIFEST_TTL_MS = 6 * 60 * 60 * 1000;
|
|
@@ -51,8 +52,9 @@ const petsRoot = () => {
|
|
|
51
52
|
if (override && override.length > 0) return path.resolve(untilde(override));
|
|
52
53
|
return path.join(os.homedir(), ".cc-pets", "pets");
|
|
53
54
|
};
|
|
55
|
+
// 与 CC Bridge、cc-pets clean 一致:CC_PETS_HOME 可覆盖 ~/.cc-pets。
|
|
54
56
|
const cachePath = (sourceName) =>
|
|
55
|
-
path.join(os.homedir(), ".cc-pets", "cache", `manifest-${sourceName}.json`);
|
|
57
|
+
path.join(process.env.CC_PETS_HOME || path.join(os.homedir(), ".cc-pets"), "cache", `manifest-${sourceName}.json`);
|
|
56
58
|
// 每个源都可以单独用环境变量改清单地址,主要给测试和自建源的本地联调用。
|
|
57
59
|
const manifestUrlFor = (sourceName) =>
|
|
58
60
|
process.env[`CC_PETS_MANIFEST_URL_${sourceName.toUpperCase()}`] || SOURCES[sourceName].manifestUrl;
|
|
@@ -85,7 +87,7 @@ function parseSpec(spec) {
|
|
|
85
87
|
const source = spec.slice(0, separator);
|
|
86
88
|
const slug = spec.slice(separator + 1);
|
|
87
89
|
if (!SOURCES[source]) {
|
|
88
|
-
fail(
|
|
90
|
+
fail(t('Unknown pet source "{source}". Available sources: {SOURCES}', { source, SOURCES: Object.keys(SOURCES).join(", ") }));
|
|
89
91
|
}
|
|
90
92
|
return { source, slug };
|
|
91
93
|
}
|
|
@@ -107,9 +109,9 @@ async function fetchManifest(sourceName, { refresh }) {
|
|
|
107
109
|
redirect: "follow",
|
|
108
110
|
headers: { "User-Agent": USER_AGENT }
|
|
109
111
|
});
|
|
110
|
-
if (!response.ok) fail(
|
|
112
|
+
if (!response.ok) fail(t("Failed to fetch the {label} pet list: HTTP {status}", { label: SOURCES[sourceName].label, status: response.status }));
|
|
111
113
|
const body = await response.json();
|
|
112
|
-
if (!Array.isArray(body?.pets)) fail(
|
|
114
|
+
if (!Array.isArray(body?.pets)) fail(t("The {label} pet list has an unexpected format", { label: SOURCES[sourceName].label }));
|
|
113
115
|
fs.mkdirSync(path.dirname(cache), { recursive: true });
|
|
114
116
|
fs.writeFileSync(cache, JSON.stringify(body));
|
|
115
117
|
return body.pets;
|
|
@@ -120,15 +122,15 @@ async function download(url, source) {
|
|
|
120
122
|
try {
|
|
121
123
|
parsed = new URL(url);
|
|
122
124
|
} catch {
|
|
123
|
-
throw new Error(
|
|
125
|
+
throw new Error(t("Invalid pet URL: {url}", { url }));
|
|
124
126
|
}
|
|
125
127
|
if (parsed.protocol !== "https:" || !source.assetHosts.includes(parsed.hostname)) {
|
|
126
|
-
throw new Error(
|
|
128
|
+
throw new Error(t("Untrusted pet source: {url}", { url: parsed.hostname || url }));
|
|
127
129
|
}
|
|
128
130
|
const response = await fetch(parsed, {
|
|
129
131
|
headers: { Referer: source.referer, "User-Agent": USER_AGENT }
|
|
130
132
|
});
|
|
131
|
-
if (!response.ok) throw new Error(
|
|
133
|
+
if (!response.ok) throw new Error(t("Download failed {pathname} -> HTTP {status}", { pathname: parsed.pathname, status: response.status }));
|
|
132
134
|
return Buffer.from(await response.arrayBuffer());
|
|
133
135
|
}
|
|
134
136
|
|
|
@@ -146,16 +148,16 @@ function assertInstallable(directory, sourceName, localName) {
|
|
|
146
148
|
if (!fs.existsSync(directory)) return;
|
|
147
149
|
const sidecar = readSidecar(directory);
|
|
148
150
|
if (sidecar?.source === sourceName) return;
|
|
149
|
-
const owner = sidecar ?
|
|
151
|
+
const owner = sidecar ? t("came from {source}", { source: sidecar.source }) : t("wasn't installed by cc-pets pet (no source record)");
|
|
150
152
|
throw new Error(
|
|
151
|
-
|
|
153
|
+
t("{localName} already exists and {owner}. Install it under another name: ", { localName, owner }) +
|
|
152
154
|
`cc-pets pet add ${sourceName}:${localName} --as ${localName}-${sourceName}`
|
|
153
155
|
);
|
|
154
156
|
}
|
|
155
157
|
|
|
156
158
|
async function installPet(pet, sourceName, localName) {
|
|
157
159
|
const source = SOURCES[sourceName];
|
|
158
|
-
if (!isSafeSlug(pet.slug)) throw new Error(
|
|
160
|
+
if (!isSafeSlug(pet.slug)) throw new Error(t("Invalid pet name: {slug}", { slug: pet.slug }));
|
|
159
161
|
const directory = path.join(petsRoot(), localName);
|
|
160
162
|
assertInstallable(directory, sourceName, localName);
|
|
161
163
|
|
|
@@ -200,16 +202,16 @@ async function commandAdd(args) {
|
|
|
200
202
|
const refresh = args.includes("--refresh");
|
|
201
203
|
const asIndex = args.indexOf("--as");
|
|
202
204
|
const alias = asIndex === -1 ? null : args[asIndex + 1];
|
|
203
|
-
if (asIndex !== -1 && (!alias || alias.startsWith("--"))) fail("--as
|
|
204
|
-
if (alias && !isSafeLocalName(alias)) fail(
|
|
205
|
+
if (asIndex !== -1 && (!alias || alias.startsWith("--"))) fail(t("--as needs a name after it."));
|
|
206
|
+
if (alias && !isSafeLocalName(alias)) fail(t("Invalid --as name: {alias}", { alias }));
|
|
205
207
|
|
|
206
208
|
// asIndex 为 -1 时 asIndex + 1 是 0,会把第一个位置参数当成 --as 的取值吃掉。
|
|
207
209
|
const aliasValueIndex = asIndex === -1 ? -1 : asIndex + 1;
|
|
208
210
|
const positional = args.filter(
|
|
209
211
|
(value, index) => !value.startsWith("--") && index !== aliasValueIndex);
|
|
210
212
|
const specs = [...new Set(positional)];
|
|
211
|
-
if (specs.length === 0) fail(
|
|
212
|
-
if (alias && specs.length > 1) fail("--as
|
|
213
|
+
if (specs.length === 0) fail(t("Usage: {cyan}", { cyan: cyan(t("cc-pets pet add [source:]<name> [name...] [--as <local-name>]")) }));
|
|
214
|
+
if (alias && specs.length > 1) fail(t("--as can only rename one pet at a time."));
|
|
213
215
|
|
|
214
216
|
// 按源分组,同一个源只拉一次清单。
|
|
215
217
|
const wanted = specs.map(parseSpec);
|
|
@@ -228,7 +230,7 @@ async function commandAdd(args) {
|
|
|
228
230
|
const pet = index.get(slug);
|
|
229
231
|
if (!pet) {
|
|
230
232
|
failed += 1;
|
|
231
|
-
console.error(
|
|
233
|
+
console.error(t("{red} {sourceName}:{slug}: not in the pet list", { red: red("×"), sourceName, slug }));
|
|
232
234
|
continue;
|
|
233
235
|
}
|
|
234
236
|
const localName = alias ?? slug;
|
|
@@ -245,8 +247,8 @@ async function commandAdd(args) {
|
|
|
245
247
|
}
|
|
246
248
|
|
|
247
249
|
if (installed > 0) {
|
|
248
|
-
console.log(dim(
|
|
249
|
-
console.log(dim("
|
|
250
|
+
console.log(dim(t("Pets directory: {petsRoot}", { petsRoot: petsRoot() })));
|
|
251
|
+
console.log(dim(t("Click “Rescan” in the pet menu or restart the pet to see new pets.")));
|
|
250
252
|
}
|
|
251
253
|
if (failed > 0) process.exit(1);
|
|
252
254
|
}
|
|
@@ -266,23 +268,23 @@ async function commandSearch(args) {
|
|
|
266
268
|
? pets
|
|
267
269
|
: pets.filter((pet) =>
|
|
268
270
|
`${pet.slug} ${pet.displayName ?? ""} ${pet.submittedBy ?? ""}`.toLowerCase().includes(keyword));
|
|
269
|
-
if (matched.length === 0) fail(
|
|
271
|
+
if (matched.length === 0) fail(t('No pets on {label} match "{keyword}".', { label: SOURCES[sourceName].label, keyword }));
|
|
270
272
|
const shown = matched.slice(0, 60);
|
|
271
273
|
for (const pet of shown) {
|
|
272
274
|
const author = pet.submittedBy ? dim(` by ${pet.submittedBy}`) : "";
|
|
273
275
|
console.log(` ${cyan(pet.slug)} ${pet.displayName ?? ""}${author}`);
|
|
274
276
|
}
|
|
275
277
|
if (matched.length > shown.length) {
|
|
276
|
-
console.log(dim(
|
|
278
|
+
console.log(dim(t(" … {length} results, showing the first {shown}.", { length: matched.length, shown: shown.length })));
|
|
277
279
|
}
|
|
278
|
-
console.log(dim(
|
|
280
|
+
console.log(dim(t("Install one: cc-pets pet add {sourceName}:{slug}", { sourceName, slug: shown[0].slug })));
|
|
279
281
|
}
|
|
280
282
|
|
|
281
283
|
function commandList() {
|
|
282
284
|
const pets = installedPets();
|
|
283
285
|
if (pets.length === 0) {
|
|
284
|
-
console.log(dim(
|
|
285
|
-
console.log(dim("
|
|
286
|
+
console.log(dim(t("No pets in {petsRoot} yet.", { petsRoot: petsRoot() })));
|
|
287
|
+
console.log(dim(t("Try: cc-pets pet add boba")));
|
|
286
288
|
return;
|
|
287
289
|
}
|
|
288
290
|
const groups = new Map();
|
|
@@ -299,7 +301,7 @@ function commandList() {
|
|
|
299
301
|
});
|
|
300
302
|
for (const key of keys) {
|
|
301
303
|
const label = key === "__unknown__"
|
|
302
|
-
? "
|
|
304
|
+
? t("Local pets (no source record)")
|
|
303
305
|
: SOURCES[key]?.label ?? LOCAL_SOURCE_LABELS[key] ?? key;
|
|
304
306
|
console.log(` ${label}`);
|
|
305
307
|
for (const pet of groups.get(key)) {
|
|
@@ -308,38 +310,38 @@ function commandList() {
|
|
|
308
310
|
console.log(` ${cyan(pet.name)}${origin}`);
|
|
309
311
|
}
|
|
310
312
|
}
|
|
311
|
-
console.log(dim(
|
|
313
|
+
console.log(dim(t("{length} in total, in {petsRoot}", { length: pets.length, petsRoot: petsRoot() })));
|
|
312
314
|
}
|
|
313
315
|
|
|
314
316
|
function commandRemove(args) {
|
|
315
317
|
const names = args.filter((value) => !value.startsWith("--"));
|
|
316
|
-
if (names.length === 0) fail(
|
|
318
|
+
if (names.length === 0) fail(t("Usage: {cyan}", { cyan: cyan(t("cc-pets pet remove <name> [name...]")) }));
|
|
317
319
|
const root = petsRoot();
|
|
318
320
|
let removed = 0;
|
|
319
321
|
for (const name of names) {
|
|
320
322
|
if (!isSafeLocalName(name)) {
|
|
321
|
-
console.error(
|
|
323
|
+
console.error(t("{red} {name}: invalid name", { red: red("×"), name }));
|
|
322
324
|
continue;
|
|
323
325
|
}
|
|
324
326
|
const directory = path.join(root, name);
|
|
325
327
|
if (!fs.existsSync(directory)) {
|
|
326
|
-
console.error(
|
|
328
|
+
console.error(t("{red} {name}: not installed", { red: red("×"), name }));
|
|
327
329
|
continue;
|
|
328
330
|
}
|
|
329
331
|
const sidecar = readSidecar(directory);
|
|
330
332
|
fs.rmSync(directory, { recursive: true, force: true });
|
|
331
333
|
removed += 1;
|
|
332
|
-
console.log(
|
|
334
|
+
console.log(t("{green} Removed {name}{source}", { green: green("✓"), name, source: sidecar ? dim(t(" (from {source})", { source: sidecar.source })) : "" }));
|
|
333
335
|
}
|
|
334
336
|
if (removed < names.length) process.exit(1);
|
|
335
337
|
}
|
|
336
338
|
|
|
337
339
|
function commandSource() {
|
|
338
340
|
for (const [name, source] of Object.entries(SOURCES)) {
|
|
339
|
-
const marker = name === DEFAULT_SOURCE ? green(" (
|
|
341
|
+
const marker = name === DEFAULT_SOURCE ? green(t(" (default)")) : "";
|
|
340
342
|
console.log(` ${cyan(name)}${marker} ${source.label} ${dim(source.homepage)}`);
|
|
341
343
|
}
|
|
342
|
-
console.log(dim("
|
|
344
|
+
console.log(dim(t("Change the default source with CC_PETS_SOURCE, or prefix a name with `source:`.")));
|
|
343
345
|
}
|
|
344
346
|
|
|
345
347
|
function commandDir() {
|
|
@@ -351,31 +353,31 @@ function commandDir() {
|
|
|
351
353
|
function usage() {
|
|
352
354
|
console.log([
|
|
353
355
|
"",
|
|
354
|
-
|
|
356
|
+
t(" {cyan} — install pets into cc-pets' own directory", { cyan: cyan("cc-pets pet") }),
|
|
355
357
|
"",
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
358
|
+
t(" {cyan} [source:]<name>... download pets to {petsRoot}", { cyan: cyan("add"), petsRoot: dim(petsRoot()) }),
|
|
359
|
+
t(" {cyan} [source:][keyword] search pets (no keyword lists all)", { cyan: cyan("search") }),
|
|
360
|
+
t(" {cyan} list installed pets, grouped by source", { cyan: cyan("list") }),
|
|
361
|
+
t(" {cyan} <name>... remove installed pets", { cyan: cyan("remove") }),
|
|
362
|
+
t(" {cyan} list available sources", { cyan: cyan("source") }),
|
|
363
|
+
t(" {cyan} print the pets directory", { cyan: cyan("dir") }),
|
|
362
364
|
"",
|
|
363
|
-
` ${dim("
|
|
364
|
-
` ${dim("--as
|
|
365
|
-
` ${dim("--refresh
|
|
366
|
-
` ${dim("CC_PETS_PETS_DIR
|
|
365
|
+
` ${dim(t("Names can have a source prefix (petdex:boba); otherwise the default source is used: ") + DEFAULT_SOURCE + t("."))}`,
|
|
366
|
+
` ${dim(t("--as <local-name> installs under another directory name (any language) to avoid name clashes."))}`,
|
|
367
|
+
` ${dim(t("--refresh forces a refresh of the pet list cache (cached for 6 hours by default)."))}`,
|
|
368
|
+
` ${dim(t("CC_PETS_PETS_DIR changes the pets directory; CC_PETS_SOURCE changes the default source."))}`,
|
|
367
369
|
"",
|
|
368
370
|
` ${dim("$")} cc-pets pet search otter`,
|
|
369
371
|
` ${dim("$")} cc-pets pet add boba`,
|
|
370
372
|
` ${dim("$")} cc-pets pet add petdex:boba --as boba-petdex`,
|
|
371
|
-
|
|
373
|
+
t(" {dim} cc-pets pet add boba --as bubble-tea", { dim: dim("$") }),
|
|
372
374
|
""
|
|
373
375
|
].join("\n"));
|
|
374
376
|
}
|
|
375
377
|
|
|
376
378
|
const [command, ...args] = process.argv.slice(2);
|
|
377
379
|
if (!SOURCES[DEFAULT_SOURCE]) {
|
|
378
|
-
fail(
|
|
380
|
+
fail(t('CC_PETS_SOURCE points to an unknown source "{DEFAULT_SOURCE}". Available sources: {SOURCES}', { DEFAULT_SOURCE, SOURCES: Object.keys(SOURCES).join(", ") }));
|
|
379
381
|
}
|
|
380
382
|
switch (command) {
|
|
381
383
|
case "add":
|
|
@@ -407,7 +409,7 @@ switch (command) {
|
|
|
407
409
|
usage();
|
|
408
410
|
break;
|
|
409
411
|
default:
|
|
410
|
-
console.error(red(
|
|
412
|
+
console.error(red(t("Unknown subcommand: {command}", { command })));
|
|
411
413
|
usage();
|
|
412
414
|
process.exit(2);
|
|
413
415
|
}
|
package/scripts/uninstall-app.sh
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#!/bin/zsh
|
|
2
2
|
set -eu
|
|
3
|
+
source "${0:A:h}/i18n.zsh"
|
|
3
4
|
|
|
4
5
|
APPLICATIONS_DIR="${CC_PETS_APPLICATIONS_DIR:-${HOME}/Applications}"
|
|
5
6
|
TARGET_APP="${APPLICATIONS_DIR}/CC Pets.app"
|
|
@@ -9,7 +10,7 @@ if [[ -e "${TARGET_APP}" ]]; then
|
|
|
9
10
|
BUNDLE_ID="$(/usr/libexec/PlistBuddy -c 'Print :CFBundleIdentifier' \
|
|
10
11
|
"${TARGET_APP}/Contents/Info.plist" 2>/dev/null || true)"
|
|
11
12
|
if [[ "${BUNDLE_ID}" != "com.universewang.cc-pets" ]]; then
|
|
12
|
-
print -u2 "
|
|
13
|
+
print -u2 "$(cc_pets_t "Refusing to delete: {targetApp} isn't the CC Pets app (bundle ID mismatch)." targetApp="${TARGET_APP}")"
|
|
13
14
|
exit 2
|
|
14
15
|
fi
|
|
15
16
|
fi
|
|
@@ -20,7 +21,7 @@ fi
|
|
|
20
21
|
|
|
21
22
|
if [[ -e "${TARGET_APP}" ]]; then
|
|
22
23
|
rm -rf "${TARGET_APP}"
|
|
23
|
-
print "
|
|
24
|
+
print "$(cc_pets_t "App removed: {targetApp}" targetApp="${TARGET_APP}")"
|
|
24
25
|
else
|
|
25
|
-
print "
|
|
26
|
+
print "$(cc_pets_t "App not installed: {targetApp}" targetApp="${TARGET_APP}")"
|
|
26
27
|
fi
|
|
@@ -3,55 +3,28 @@
|
|
|
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";
|
|
12
|
+
import { t } from "./i18n.mjs";
|
|
6
13
|
|
|
7
14
|
const codexHome = process.env.CODEX_HOME || path.join(os.homedir(), ".codex");
|
|
8
15
|
const claudeHome = process.env.CLAUDE_CONFIG_DIR || path.join(os.homedir(), ".claude");
|
|
9
16
|
const preparingInstall = process.argv[2] === "--prepare-install";
|
|
10
17
|
const shellRC = process.argv[preparingInstall ? 3 : 2];
|
|
11
18
|
|
|
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
|
-
}
|
|
19
|
+
const currentCodexHook = CODEX_HOOK;
|
|
20
|
+
const legacyCodexHook = LEGACY_CODEX_HOOK;
|
|
21
|
+
const currentClaudeHook = CLAUDE_HOOK;
|
|
22
|
+
const legacyClaudeHook = LEGACY_CLAUDE_HOOK;
|
|
23
|
+
const currentStatusLineMarker = STATUS_LINE_MARKER;
|
|
24
|
+
const legacyStatusLineMarker = LEGACY_STATUS_LINE_MARKER;
|
|
25
|
+
const statusLineStartMarker = STATUS_LINE_START_MARKER;
|
|
26
|
+
const statusLineEndMarker = STATUS_LINE_END_MARKER;
|
|
27
|
+
const createdStatusLineMarker = CREATED_STATUS_LINE_MARKER;
|
|
55
28
|
|
|
56
29
|
function removeStatusLinePrelude(scriptPath) {
|
|
57
30
|
if (!scriptPath || !fs.existsSync(scriptPath)) return { changed: false, created: false };
|
|
@@ -113,7 +86,7 @@ function updateJSON(filePath, updater) {
|
|
|
113
86
|
try {
|
|
114
87
|
config = JSON.parse(fs.readFileSync(filePath, "utf8"));
|
|
115
88
|
} catch (error) {
|
|
116
|
-
console.error(
|
|
89
|
+
console.error(t("Can't parse {filePath}, left unchanged: {message}", { filePath, message: error.message }));
|
|
117
90
|
process.exitCode = 1;
|
|
118
91
|
return false;
|
|
119
92
|
}
|
|
@@ -175,7 +148,7 @@ if (shellRC && fs.existsSync(shellRC)) {
|
|
|
175
148
|
// cc-pets-codex / cc-pets-claude 是 alias 时代的段落。alias 区分大小写,挡不住
|
|
176
149
|
// Claude / CODEX 这类写法,已被 cc-pets-shims 的 PATH shim 取代;安装前的
|
|
177
150
|
// --prepare-install 会走到这里,顺带把老段落迁移掉。
|
|
178
|
-
let updated = removeMarkedBlock(original,
|
|
151
|
+
let updated = removeMarkedBlock(original, SHIM_START_MARKER, SHIM_END_MARKER);
|
|
179
152
|
updated = removeMarkedBlock(updated, "# >>> cc-pets-codex >>>", "# <<< cc-pets-codex <<<");
|
|
180
153
|
updated = removeMarkedBlock(updated, "# >>> cc-pets-claude >>>", "# <<< cc-pets-claude <<<");
|
|
181
154
|
updated = removeMarkedBlock(updated, "# >>> codex-pet >>>", "# <<< codex-pet <<<");
|
|
@@ -222,11 +195,11 @@ if (!preparingInstall) {
|
|
|
222
195
|
bridgeStore.setBridgeEnabled(false);
|
|
223
196
|
}
|
|
224
197
|
|
|
225
|
-
const action = preparingInstall ? "
|
|
226
|
-
if (codexChanged) console.log(
|
|
227
|
-
if (claudeChanged) console.log(
|
|
228
|
-
if (shellChanged) console.log(
|
|
229
|
-
if (shimChanged) console.log(
|
|
198
|
+
const action = preparingInstall ? t("Migrated") : t("Removed");
|
|
199
|
+
if (codexChanged) console.log(t("{action} the CC Pets hooks in {codexHooksPath}.", { action, codexHooksPath }));
|
|
200
|
+
if (claudeChanged) console.log(t("{action} the CC Pets hooks in {claudeSettingsPath} and restored the original status line.", { action, claudeSettingsPath }));
|
|
201
|
+
if (shellChanged) console.log(t("{action} the CC Pets shell integration in {shellRC}.", { action, shellRC }));
|
|
202
|
+
if (shimChanged) console.log(t("{action} the codex / claude shims in {shimDirectory}.", { action, shimDirectory }));
|
|
230
203
|
if (!codexChanged && !claudeChanged && !shellChanged && !shimChanged && !preparingInstall) {
|
|
231
|
-
console.log("
|
|
204
|
+
console.log(t("No CC Pets integrations to remove. "));
|
|
232
205
|
}
|
|
@@ -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
|
SHELL_RC="${ZDOTDIR:-${HOME}}/.zshrc"
|
|
7
8
|
PET_BIN="${PROJECT_DIR}/.build/release/cc-pets"
|
|
8
9
|
PET_APP_EXECUTABLE="${PROJECT_DIR}/.build/release/CC Pets.app/Contents/MacOS/cc-pets"
|
|
@@ -18,12 +19,12 @@ done
|
|
|
18
19
|
|
|
19
20
|
if (( PURGE && ! ASSUME_YES )); then
|
|
20
21
|
if [[ ! -t 0 ]]; then
|
|
21
|
-
print -u2 "
|
|
22
|
+
print -u2 "$(cc_pets_t "A full uninstall removes the app, quota history, updater config, logs and preferences (keeping pets and lines in ~/.cc-pets). Add --yes when running non-interactively.")"
|
|
22
23
|
exit 2
|
|
23
24
|
fi
|
|
24
|
-
print -u2 "
|
|
25
|
+
print -u2 "$(cc_pets_t "A full uninstall permanently removes the CC Pets app, quota history, updater config, logs and preferences; pets and lines in ~/.cc-pets are kept. Continue? [y/N] ")"
|
|
25
26
|
if ! read -r reply || [[ "${reply:l}" != "y" && "${reply:l}" != "yes" ]]; then
|
|
26
|
-
print "
|
|
27
|
+
print "$(cc_pets_t "Full uninstall canceled.")"
|
|
27
28
|
exit 0
|
|
28
29
|
fi
|
|
29
30
|
fi
|
|
@@ -46,7 +47,7 @@ if [[ "${CC_PETS_SKIP_APP_STOP:-0}" != "1" ]]; then
|
|
|
46
47
|
sleep 0.1
|
|
47
48
|
done
|
|
48
49
|
if (( running != 0 )); then
|
|
49
|
-
print -u2 "
|
|
50
|
+
print -u2 "$(cc_pets_t "Full uninstall failed: CC Pets didn't quit, so no integrations or local data were removed.")"
|
|
50
51
|
exit 1
|
|
51
52
|
fi
|
|
52
53
|
fi
|
|
@@ -56,13 +57,13 @@ node "${PROJECT_DIR}/scripts/uninstall-integrations.mjs" "${SHELL_RC}"
|
|
|
56
57
|
|
|
57
58
|
if (( PURGE )); then
|
|
58
59
|
if [[ ! -x "${PET_BIN}" ]]; then
|
|
59
|
-
print -u2 "
|
|
60
|
+
print -u2 "$(cc_pets_t "Full uninstall failed: {petBin} not found, so local data wasn't removed." petBin="${PET_BIN}")"
|
|
60
61
|
exit 1
|
|
61
62
|
fi
|
|
62
63
|
"${PET_BIN}" --purge-data
|
|
63
64
|
CC_PETS_SKIP_APP_STOP=1 "${PROJECT_DIR}/scripts/uninstall-app.sh"
|
|
64
|
-
print "
|
|
65
|
+
print "$(cc_pets_t "Full uninstall done. Pets and lines remain in ~/.cc-pets; delete them manually if you no longer need them. If the npm package is still installed, run npm uninstall -g cc-pets.")"
|
|
65
66
|
exit 0
|
|
66
67
|
fi
|
|
67
68
|
|
|
68
|
-
print "
|
|
69
|
+
print "$(cc_pets_t "Integrations removed. Run source {shellRc} to update this terminal; to remove the npm package, run npm uninstall -g cc-pets." shellRc="${(q)SHELL_RC}")"
|
|
File without changes
|