ccjk 2.3.1 → 2.4.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.
Files changed (37) hide show
  1. package/README.md +270 -444
  2. package/README.zh-CN.md +273 -447
  3. package/dist/chunks/auto-bootstrap.mjs +358 -0
  4. package/dist/chunks/ccr.mjs +5 -2
  5. package/dist/chunks/claude-wrapper.mjs +442 -0
  6. package/dist/chunks/cloud-sync.mjs +29 -0
  7. package/dist/chunks/constants.mjs +1 -1
  8. package/dist/chunks/context-manager.mjs +641 -0
  9. package/dist/chunks/context.mjs +248 -0
  10. package/dist/chunks/index2.mjs +2 -0
  11. package/dist/chunks/index3.mjs +19 -19
  12. package/dist/chunks/init.mjs +18 -8
  13. package/dist/chunks/marketplace.mjs +6 -2
  14. package/dist/chunks/mcp.mjs +1 -1
  15. package/dist/chunks/menu.mjs +3 -3
  16. package/dist/chunks/notification.mjs +27 -27
  17. package/dist/chunks/package.mjs +1 -1
  18. package/dist/chunks/platform.mjs +70 -21
  19. package/dist/chunks/silent-updater.mjs +396 -0
  20. package/dist/chunks/skills-sync.mjs +1 -1
  21. package/dist/chunks/version-checker.mjs +31 -31
  22. package/dist/cli.mjs +67 -5
  23. package/dist/i18n/locales/en/context.json +32 -0
  24. package/dist/i18n/locales/en/marketplace.json +1 -0
  25. package/dist/i18n/locales/en/mcp.json +12 -1
  26. package/dist/i18n/locales/en/superpowers.json +46 -0
  27. package/dist/i18n/locales/zh-CN/context.json +32 -0
  28. package/dist/i18n/locales/zh-CN/marketplace.json +1 -0
  29. package/dist/i18n/locales/zh-CN/mcp.json +12 -1
  30. package/dist/i18n/locales/zh-CN/superpowers.json +46 -0
  31. package/dist/index.d.mts +2 -2
  32. package/dist/index.d.ts +2 -2
  33. package/dist/shared/ccjk.QbS8EAOd.mjs +1019 -0
  34. package/dist/shared/ccjk.RR9TS76h.mjs +698 -0
  35. package/package.json +4 -1
  36. package/dist/shared/ccjk.Bi-m3LKY.mjs +0 -357
  37. package/dist/shared/ccjk.D-RZS4E2.mjs +0 -416
@@ -0,0 +1,358 @@
1
+ import { randomUUID, createHash } from 'node:crypto';
2
+ import { existsSync, readFileSync, mkdirSync, writeFileSync } from 'node:fs';
3
+ import { release, platform, type, homedir, hostname } from 'node:os';
4
+ import { join } from 'pathe';
5
+ import { CCJK_CONFIG_DIR } from './constants.mjs';
6
+ import './index2.mjs';
7
+ import 'node:process';
8
+ import 'node:url';
9
+ import 'i18next';
10
+ import 'i18next-fs-backend';
11
+
12
+ const CLOUD_CONFIG_DIR = join(CCJK_CONFIG_DIR, "cloud");
13
+ const DEVICE_CONFIG_FILE = join(CLOUD_CONFIG_DIR, "device.json");
14
+ const CLOUD_STATE_FILE = join(CLOUD_CONFIG_DIR, "state.json");
15
+ const CLOUD_API_ENDPOINT = "https://api.api.claudehome.cn/v1";
16
+ const AUTO_SYNC_INTERVAL = 30 * 60 * 1e3;
17
+ const AUTO_UPGRADE_CHECK_INTERVAL = 6 * 60 * 60 * 1e3;
18
+ function generateDeviceFingerprint() {
19
+ const data = [
20
+ platform(),
21
+ type(),
22
+ homedir().split("/").length.toString(),
23
+ // 只用路径深度,不用实际路径
24
+ hostname().length.toString()
25
+ // 只用主机名长度,不用实际名称
26
+ ].join("|");
27
+ return createHash("sha256").update(data).digest("hex").substring(0, 32);
28
+ }
29
+ function getOrCreateDeviceInfo() {
30
+ ensureCloudConfigDir();
31
+ if (existsSync(DEVICE_CONFIG_FILE)) {
32
+ try {
33
+ const data = readFileSync(DEVICE_CONFIG_FILE, "utf-8");
34
+ const device2 = JSON.parse(data);
35
+ device2.lastActiveAt = (/* @__PURE__ */ new Date()).toISOString();
36
+ writeFileSync(DEVICE_CONFIG_FILE, JSON.stringify(device2, null, 2));
37
+ return device2;
38
+ } catch {
39
+ }
40
+ }
41
+ const device = {
42
+ deviceId: randomUUID(),
43
+ fingerprint: generateDeviceFingerprint(),
44
+ registeredAt: (/* @__PURE__ */ new Date()).toISOString(),
45
+ lastActiveAt: (/* @__PURE__ */ new Date()).toISOString(),
46
+ osType: platform(),
47
+ osVersion: release(),
48
+ ccjkVersion: getCcjkVersion()
49
+ };
50
+ writeFileSync(DEVICE_CONFIG_FILE, JSON.stringify(device, null, 2));
51
+ return device;
52
+ }
53
+ function getCcjkVersion() {
54
+ try {
55
+ const packagePath = join(__dirname, "../../../package.json");
56
+ if (existsSync(packagePath)) {
57
+ const pkg = JSON.parse(readFileSync(packagePath, "utf-8"));
58
+ return pkg.version || "unknown";
59
+ }
60
+ } catch {
61
+ }
62
+ return "unknown";
63
+ }
64
+ function ensureCloudConfigDir() {
65
+ if (!existsSync(CLOUD_CONFIG_DIR)) {
66
+ mkdirSync(CLOUD_CONFIG_DIR, { recursive: true });
67
+ }
68
+ }
69
+ function getCloudState() {
70
+ ensureCloudConfigDir();
71
+ if (existsSync(CLOUD_STATE_FILE)) {
72
+ try {
73
+ const data = readFileSync(CLOUD_STATE_FILE, "utf-8");
74
+ return JSON.parse(data);
75
+ } catch {
76
+ }
77
+ }
78
+ return {
79
+ initialized: false,
80
+ autoSyncEnabled: true,
81
+ silentUpgradeEnabled: true,
82
+ lastSyncAt: null,
83
+ lastUpgradeCheckAt: null,
84
+ lastUpgradedAt: null,
85
+ syncStats: {
86
+ totalSyncs: 0,
87
+ successfulSyncs: 0,
88
+ failedSyncs: 0
89
+ },
90
+ upgradeStats: {
91
+ totalChecks: 0,
92
+ upgradesApplied: 0,
93
+ upgradesFailed: 0
94
+ }
95
+ };
96
+ }
97
+ function saveCloudState(state) {
98
+ ensureCloudConfigDir();
99
+ writeFileSync(CLOUD_STATE_FILE, JSON.stringify(state, null, 2));
100
+ }
101
+ function updateCloudState(updates) {
102
+ const state = getCloudState();
103
+ const newState = { ...state, ...updates };
104
+ saveCloudState(newState);
105
+ return newState;
106
+ }
107
+ async function autoBootstrap() {
108
+ try {
109
+ const state = getCloudState();
110
+ if (!state.initialized) {
111
+ await initializeCloudServices();
112
+ }
113
+ await performHandshake();
114
+ if (state.silentUpgradeEnabled) {
115
+ await checkAndPerformSilentUpgrade();
116
+ }
117
+ if (state.autoSyncEnabled) {
118
+ await performAutoSync();
119
+ }
120
+ } catch {
121
+ }
122
+ }
123
+ async function initializeCloudServices() {
124
+ const device = getOrCreateDeviceInfo();
125
+ updateCloudState({
126
+ initialized: true,
127
+ autoSyncEnabled: true,
128
+ silentUpgradeEnabled: true
129
+ });
130
+ try {
131
+ await registerDevice(device);
132
+ } catch {
133
+ }
134
+ }
135
+ async function registerDevice(device) {
136
+ const controller = new AbortController();
137
+ const timeoutId = setTimeout(() => controller.abort(), 5e3);
138
+ try {
139
+ await fetch(`${CLOUD_API_ENDPOINT}/devices/register`, {
140
+ method: "POST",
141
+ headers: {
142
+ "Content-Type": "application/json",
143
+ "User-Agent": `CCJK/${device.ccjkVersion}`
144
+ },
145
+ body: JSON.stringify({
146
+ deviceId: device.deviceId,
147
+ fingerprint: device.fingerprint,
148
+ osType: device.osType,
149
+ osVersion: device.osVersion,
150
+ ccjkVersion: device.ccjkVersion
151
+ }),
152
+ signal: controller.signal
153
+ });
154
+ } finally {
155
+ clearTimeout(timeoutId);
156
+ }
157
+ }
158
+ async function performHandshake() {
159
+ const device = getOrCreateDeviceInfo();
160
+ const controller = new AbortController();
161
+ const timeoutId = setTimeout(() => controller.abort(), 5e3);
162
+ try {
163
+ const response = await fetch(`${CLOUD_API_ENDPOINT}/handshake`, {
164
+ method: "POST",
165
+ headers: {
166
+ "Content-Type": "application/json",
167
+ "User-Agent": `CCJK/${device.ccjkVersion}`,
168
+ "X-Device-ID": device.deviceId
169
+ },
170
+ body: JSON.stringify({
171
+ deviceId: device.deviceId,
172
+ ccjkVersion: device.ccjkVersion
173
+ }),
174
+ signal: controller.signal
175
+ });
176
+ if (response.ok) {
177
+ return await response.json();
178
+ }
179
+ } catch {
180
+ } finally {
181
+ clearTimeout(timeoutId);
182
+ }
183
+ return null;
184
+ }
185
+ async function checkAndPerformSilentUpgrade() {
186
+ const state = getCloudState();
187
+ const now = Date.now();
188
+ if (state.lastUpgradeCheckAt) {
189
+ const lastCheck = new Date(state.lastUpgradeCheckAt).getTime();
190
+ if (now - lastCheck < AUTO_UPGRADE_CHECK_INTERVAL) {
191
+ return { success: true, upgraded: false };
192
+ }
193
+ }
194
+ updateCloudState({
195
+ lastUpgradeCheckAt: (/* @__PURE__ */ new Date()).toISOString(),
196
+ upgradeStats: {
197
+ ...state.upgradeStats,
198
+ totalChecks: state.upgradeStats.totalChecks + 1
199
+ }
200
+ });
201
+ try {
202
+ const updateInfo = await checkForUpdates();
203
+ if (updateInfo.hasUpdate) {
204
+ const result = await performSilentUpgrade(updateInfo.latestVersion);
205
+ if (result.success && result.upgraded) {
206
+ updateCloudState({
207
+ lastUpgradedAt: (/* @__PURE__ */ new Date()).toISOString(),
208
+ upgradeStats: {
209
+ ...getCloudState().upgradeStats,
210
+ upgradesApplied: getCloudState().upgradeStats.upgradesApplied + 1
211
+ }
212
+ });
213
+ }
214
+ return result;
215
+ }
216
+ return { success: true, upgraded: false };
217
+ } catch (error) {
218
+ updateCloudState({
219
+ upgradeStats: {
220
+ ...getCloudState().upgradeStats,
221
+ upgradesFailed: getCloudState().upgradeStats.upgradesFailed + 1
222
+ }
223
+ });
224
+ return {
225
+ success: false,
226
+ upgraded: false,
227
+ error: error instanceof Error ? error.message : "Unknown error"
228
+ };
229
+ }
230
+ }
231
+ async function checkForUpdates() {
232
+ const currentVersion = getCcjkVersion();
233
+ const controller = new AbortController();
234
+ const timeoutId = setTimeout(() => controller.abort(), 1e4);
235
+ try {
236
+ const response = await fetch("https://registry.npmjs.org/ccjk/latest", {
237
+ signal: controller.signal
238
+ });
239
+ if (response.ok) {
240
+ const data = await response.json();
241
+ const latestVersion = data.version;
242
+ return {
243
+ hasUpdate: isNewerVersion(latestVersion, currentVersion),
244
+ latestVersion,
245
+ currentVersion
246
+ };
247
+ }
248
+ } catch {
249
+ } finally {
250
+ clearTimeout(timeoutId);
251
+ }
252
+ return { hasUpdate: false, latestVersion: currentVersion, currentVersion };
253
+ }
254
+ function isNewerVersion(latest, current) {
255
+ const latestParts = latest.split(".").map(Number);
256
+ const currentParts = current.split(".").map(Number);
257
+ for (let i = 0; i < 3; i++) {
258
+ const l = latestParts[i] || 0;
259
+ const c = currentParts[i] || 0;
260
+ if (l > c)
261
+ return true;
262
+ if (l < c)
263
+ return false;
264
+ }
265
+ return false;
266
+ }
267
+ async function performSilentUpgrade(targetVersion) {
268
+ const currentVersion = getCcjkVersion();
269
+ try {
270
+ const { exec } = await import('tinyexec');
271
+ const result = await exec("npm", ["update", "-g", "ccjk"], {
272
+ timeout: 6e4
273
+ // 60 秒超时
274
+ });
275
+ if (result.exitCode === 0) {
276
+ return {
277
+ success: true,
278
+ upgraded: true,
279
+ fromVersion: currentVersion,
280
+ toVersion: targetVersion
281
+ };
282
+ }
283
+ return {
284
+ success: false,
285
+ upgraded: false,
286
+ error: result.stderr || "Upgrade failed"
287
+ };
288
+ } catch (error) {
289
+ return {
290
+ success: false,
291
+ upgraded: false,
292
+ error: error instanceof Error ? error.message : "Unknown error"
293
+ };
294
+ }
295
+ }
296
+ async function performAutoSync() {
297
+ const state = getCloudState();
298
+ const now = Date.now();
299
+ if (state.lastSyncAt) {
300
+ const lastSync = new Date(state.lastSyncAt).getTime();
301
+ if (now - lastSync < AUTO_SYNC_INTERVAL) {
302
+ return;
303
+ }
304
+ }
305
+ try {
306
+ await syncToCloud();
307
+ updateCloudState({
308
+ lastSyncAt: (/* @__PURE__ */ new Date()).toISOString(),
309
+ syncStats: {
310
+ ...state.syncStats,
311
+ totalSyncs: state.syncStats.totalSyncs + 1,
312
+ successfulSyncs: state.syncStats.successfulSyncs + 1
313
+ }
314
+ });
315
+ } catch {
316
+ updateCloudState({
317
+ syncStats: {
318
+ ...state.syncStats,
319
+ totalSyncs: state.syncStats.totalSyncs + 1,
320
+ failedSyncs: state.syncStats.failedSyncs + 1
321
+ }
322
+ });
323
+ }
324
+ }
325
+ async function syncToCloud() {
326
+ const device = getOrCreateDeviceInfo();
327
+ const controller = new AbortController();
328
+ const timeoutId = setTimeout(() => controller.abort(), 3e4);
329
+ try {
330
+ const syncData = await collectSyncData();
331
+ await fetch(`${CLOUD_API_ENDPOINT}/sync`, {
332
+ method: "POST",
333
+ headers: {
334
+ "Content-Type": "application/json",
335
+ "User-Agent": `CCJK/${device.ccjkVersion}`,
336
+ "X-Device-ID": device.deviceId
337
+ },
338
+ body: JSON.stringify(syncData),
339
+ signal: controller.signal
340
+ });
341
+ } finally {
342
+ clearTimeout(timeoutId);
343
+ }
344
+ }
345
+ async function collectSyncData() {
346
+ const device = getOrCreateDeviceInfo();
347
+ return {
348
+ deviceId: device.deviceId,
349
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
350
+ // 只同步匿名化的使用统计
351
+ stats: {
352
+ osType: device.osType,
353
+ ccjkVersion: device.ccjkVersion
354
+ }
355
+ };
356
+ }
357
+
358
+ export { AUTO_SYNC_INTERVAL, AUTO_UPGRADE_CHECK_INTERVAL, CLOUD_API_ENDPOINT, CLOUD_CONFIG_DIR, CLOUD_STATE_FILE, DEVICE_CONFIG_FILE, autoBootstrap, autoBootstrap as bootstrap, checkAndPerformSilentUpgrade as checkUpgrade, getCloudState, getOrCreateDeviceInfo, saveCloudState, performAutoSync as sync, updateCloudState };
@@ -37,7 +37,10 @@ import './auto-updater.mjs';
37
37
  import './version-checker.mjs';
38
38
  import 'node:path';
39
39
  import '../shared/ccjk.ByTIGCUC.mjs';
40
- import '../shared/ccjk.Bi-m3LKY.mjs';
40
+ import '../shared/ccjk.RR9TS76h.mjs';
41
+ import 'node:stream';
42
+ import 'node:stream/promises';
43
+ import 'tar';
41
44
  import './smart-guide.mjs';
42
45
  import './ccu.mjs';
43
46
  import './commands2.mjs';
@@ -45,7 +48,7 @@ import './check-updates.mjs';
45
48
  import './config-switch.mjs';
46
49
  import './claude-code-config-manager.mjs';
47
50
  import './doctor.mjs';
48
- import '../shared/ccjk.D-RZS4E2.mjs';
51
+ import '../shared/ccjk.QbS8EAOd.mjs';
49
52
  import './notification.mjs';
50
53
  import 'node:buffer';
51
54
  import '@iarna/toml';