cc-pets 2.0.1 → 2.1.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 +239 -0
- package/CC_BRIDGE.zh-CN.md +210 -0
- package/CHANGELOG.md +39 -0
- package/CHANGELOG.zh-CN.md +39 -0
- package/PROVIDER_PROTOCOL.md +6 -0
- package/PROVIDER_PROTOCOL.zh-CN.md +5 -0
- package/README.md +26 -0
- package/README.zh-CN.md +25 -2
- package/Resources/Info.plist +2 -0
- package/Sources/CCPets/CCPetsAppDelegate.h +25 -0
- package/Sources/CCPets/CCPetsAppDelegate.m +751 -29
- package/Sources/CCPets/CCPetsBridge.h +43 -0
- package/Sources/CCPets/CCPetsBridge.m +198 -0
- package/Sources/CCPets/CCPetsEvents.m +7 -2
- package/Sources/CCPets/CCPetsPaths.h +4 -0
- package/Sources/CCPets/CCPetsPaths.m +6 -0
- package/Sources/CCPets/CCPetsQuotaHistory.m +9 -2
- package/Sources/CCPets/CCPetsTerminalFocus.h +11 -0
- package/Sources/CCPets/CCPetsTerminalFocus.m +150 -0
- package/Sources/CCPets/PetView.m +86 -1
- package/Sources/CCPets/QuotaDashboardView.m +17 -4
- package/Sources/CCPets/main.m +5 -0
- package/bin/cc-pets +5 -0
- package/bin/claude-with-pet +8 -2
- package/bin/codex-with-pet +8 -3
- package/package.json +3 -1
- package/scripts/bridge/cli.mjs +229 -0
- package/scripts/bridge/core.mjs +227 -0
- package/scripts/bridge/hook.mjs +149 -0
- package/scripts/bridge/install.mjs +288 -0
- package/scripts/bridge/mcp-server.mjs +300 -0
- package/scripts/bridge/options.mjs +86 -0
- package/scripts/bridge/process.mjs +129 -0
- package/scripts/bridge/reservations.mjs +247 -0
- package/scripts/bridge/store.mjs +432 -0
- package/scripts/bridge/watch.mjs +69 -0
- package/scripts/install-shell-integration.sh +3 -0
- package/scripts/uninstall-integrations.mjs +10 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// Claude 端的投递者:以 asyncRewake hook 运行,等信箱来消息后 exit 2 唤醒会话。
|
|
2
|
+
//
|
|
3
|
+
// 实测(Claude Code 2.1.281):
|
|
4
|
+
// - asyncRewake hook 以 exit 2 退出时,stderr 作为系统提醒进入会话;会话空闲会被唤醒,
|
|
5
|
+
// 忙碌则注入当前回合;
|
|
6
|
+
// - hook 的 timeout 会被强制执行,所以 watcher 在超时前主动退出,下一次 SessionStart /
|
|
7
|
+
// UserPromptSubmit / Stop 事件再重新挂上;
|
|
8
|
+
// - 会话退出时 hook 子进程会被清理。
|
|
9
|
+
//
|
|
10
|
+
// 每个会话只保留一个 watcher(锁文件),否则多个 watcher 会抢同一个信箱、重复唤醒。
|
|
11
|
+
|
|
12
|
+
import fs from "node:fs";
|
|
13
|
+
import { formatEnvelope } from "./core.mjs";
|
|
14
|
+
import { currentOptions } from "./options.mjs";
|
|
15
|
+
import { isProcessAlive } from "./process.mjs";
|
|
16
|
+
import { acquireLock, claimInbox, isBridgeEnabled, safeSessionId, updateReceipt } from "./store.mjs";
|
|
17
|
+
|
|
18
|
+
// 安装时 hook 的 timeout 是 3600 秒,这里留 5 分钟余量主动退出,保证锁由自己释放。
|
|
19
|
+
const DEFAULT_WATCH_SECONDS = 3300;
|
|
20
|
+
const DEFAULT_POLL_MS = 1000;
|
|
21
|
+
|
|
22
|
+
const sleep = (milliseconds) => new Promise((resolve) => setTimeout(resolve, milliseconds));
|
|
23
|
+
|
|
24
|
+
export const runWatch = async (rawInput, environment = process.env) => {
|
|
25
|
+
// 关闭"自动唤醒"后 watcher 本不会被安装;配置还没刷新到对方 CLI 时在这里兜底。
|
|
26
|
+
if (!isBridgeEnabled() || !currentOptions().wake) return 0;
|
|
27
|
+
let payload;
|
|
28
|
+
try {
|
|
29
|
+
payload = JSON.parse(rawInput);
|
|
30
|
+
} catch {
|
|
31
|
+
return 0;
|
|
32
|
+
}
|
|
33
|
+
const sessionId = safeSessionId(payload?.session_id);
|
|
34
|
+
if (!sessionId) return 0;
|
|
35
|
+
|
|
36
|
+
const release = acquireLock(`watch-${sessionId}`, isProcessAlive);
|
|
37
|
+
if (!release) return 0;
|
|
38
|
+
|
|
39
|
+
const seconds = Number(environment.CC_BRIDGE_WATCH_SECONDS) || DEFAULT_WATCH_SECONDS;
|
|
40
|
+
const pollMs = Number(environment.CC_BRIDGE_POLL_MS) || DEFAULT_POLL_MS;
|
|
41
|
+
const deadline = Date.now() + seconds * 1000;
|
|
42
|
+
const parent = process.ppid;
|
|
43
|
+
try {
|
|
44
|
+
while (Date.now() < deadline) {
|
|
45
|
+
// 宿主会话已经没了(被 kill -9 等,没来得及清理子进程)就别再占着锁。
|
|
46
|
+
if (!isProcessAlive(parent)) return 0;
|
|
47
|
+
const messages = claimInbox(sessionId);
|
|
48
|
+
if (messages.length > 0) {
|
|
49
|
+
for (const message of messages) {
|
|
50
|
+
updateReceipt(message.id, { status: "delivered", transport: { kind: "claude-rewake" } });
|
|
51
|
+
}
|
|
52
|
+
process.stderr.write(`${messages.map(formatEnvelope).join("\n\n")}\n`);
|
|
53
|
+
return 2;
|
|
54
|
+
}
|
|
55
|
+
await sleep(pollMs);
|
|
56
|
+
}
|
|
57
|
+
return 0;
|
|
58
|
+
} finally {
|
|
59
|
+
release();
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export const main = async () => {
|
|
64
|
+
try {
|
|
65
|
+
return await runWatch(fs.readFileSync(0, "utf8"));
|
|
66
|
+
} catch {
|
|
67
|
+
return 0;
|
|
68
|
+
}
|
|
69
|
+
};
|
|
@@ -27,6 +27,9 @@ export PATH="${NODE_EXECUTABLE:h}:${PATH:-/usr/bin:/bin:/usr/sbin:/sbin}"
|
|
|
27
27
|
"${NODE_EXECUTABLE}" "${PROJECT_DIR}/scripts/install-claude-hooks.mjs" \
|
|
28
28
|
"${PROJECT_DIR}/.build/release/cc-pets"
|
|
29
29
|
"${NODE_EXECUTABLE}" "${PROJECT_DIR}/scripts/configure-updater.mjs"
|
|
30
|
+
# CC Bridge 默认关闭;用户开启过的话,包路径可能随升级变化,按原选项重写一遍集成。
|
|
31
|
+
"${NODE_EXECUTABLE}" "${PROJECT_DIR}/scripts/bridge/cli.mjs" refresh || \
|
|
32
|
+
print -u2 "CC Bridge 集成刷新失败,可稍后执行 cc-pets bridge enable 重试。"
|
|
30
33
|
|
|
31
34
|
PET_APP="${PROJECT_DIR}/.build/release/CC Pets.app"
|
|
32
35
|
PET_APP_EXECUTABLE="${PET_APP}/Contents/MacOS/cc-pets"
|
|
@@ -212,6 +212,16 @@ if (!preparingInstall && fs.existsSync(shimDirectory)) {
|
|
|
212
212
|
if (fs.readdirSync(shimDirectory).length === 0) fs.rmdirSync(shimDirectory);
|
|
213
213
|
}
|
|
214
214
|
|
|
215
|
+
// CC Bridge 只在真正卸载时移除;重装时由 install-shell-integration.sh 的 bridge refresh 接管。
|
|
216
|
+
// MCP 注册只在确实开启过时才去调用 claude / codex 注销,避免卸载时无谓地拉起它们的 CLI。
|
|
217
|
+
if (!preparingInstall) {
|
|
218
|
+
const bridge = await import("./bridge/install.mjs");
|
|
219
|
+
const bridgeStore = await import("./bridge/store.mjs");
|
|
220
|
+
bridgeStore.migrateLegacyFlag();
|
|
221
|
+
for (const line of bridge.uninstall({ unregisterMcp: bridgeStore.isBridgeEnabled() })) console.log(line);
|
|
222
|
+
bridgeStore.setBridgeEnabled(false);
|
|
223
|
+
}
|
|
224
|
+
|
|
215
225
|
const action = preparingInstall ? "已迁移" : "已移除";
|
|
216
226
|
if (codexChanged) console.log(`${action} ${codexHooksPath} 中的 CC Pets Hooks。`);
|
|
217
227
|
if (claudeChanged) console.log(`${action} ${claudeSettingsPath} 中的 CC Pets Hooks,并恢复原 status line。`);
|