ccjk 10.1.0 → 10.3.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/README.md +28 -0
- package/dist/chunks/agent-teams.mjs +1 -1
- package/dist/chunks/agent.mjs +1 -1
- package/dist/chunks/api-providers.mjs +1 -1
- package/dist/chunks/api.mjs +3 -3
- package/dist/chunks/auto-bootstrap.mjs +1 -1
- package/dist/chunks/auto-updater.mjs +1 -1
- package/dist/{shared/ccjk.Br91zBIG.mjs → chunks/banner.mjs} +52 -3
- package/dist/chunks/boost.mjs +2 -2
- package/dist/chunks/ccjk-agents.mjs +1 -1
- package/dist/chunks/ccjk-all.mjs +1 -1
- package/dist/chunks/ccjk-config.mjs +1 -1
- package/dist/chunks/ccjk-hooks.mjs +1 -1
- package/dist/chunks/ccjk-mcp.mjs +2 -2
- package/dist/chunks/ccjk-setup.mjs +1 -1
- package/dist/chunks/ccjk-skills.mjs +1 -1
- package/dist/chunks/ccr.mjs +11 -10
- package/dist/chunks/ccu.mjs +1 -1
- package/dist/chunks/check-updates.mjs +4 -3
- package/dist/chunks/claude-code-config-manager.mjs +8 -7
- package/dist/chunks/claude-code-incremental-manager.mjs +3 -2
- package/dist/chunks/claude-config.mjs +3 -3
- package/dist/chunks/claude-wrapper.mjs +2 -2
- package/dist/chunks/codex-config-switch.mjs +3 -2
- package/dist/chunks/codex-provider-manager.mjs +3 -2
- package/dist/chunks/codex-uninstaller.mjs +2 -2
- package/dist/chunks/codex.mjs +5 -5
- package/dist/chunks/commands.mjs +88 -391
- package/dist/chunks/commands2.mjs +391 -88
- package/dist/chunks/completion.mjs +1 -1
- package/dist/chunks/config-consolidator.mjs +2 -2
- package/dist/chunks/config-switch.mjs +4 -3
- package/dist/chunks/config.mjs +6 -98
- package/dist/chunks/config2.mjs +411 -400
- package/dist/chunks/config3.mjs +401 -410
- package/dist/chunks/constants.mjs +1 -1
- package/dist/chunks/context.mjs +283 -1
- package/dist/chunks/dashboard.mjs +365 -0
- package/dist/chunks/doctor.mjs +4 -4
- package/dist/chunks/features.mjs +12 -11
- package/dist/chunks/fs-operations.mjs +1 -1
- package/dist/chunks/health-alerts.mjs +304 -0
- package/dist/chunks/health-check.mjs +532 -0
- package/dist/chunks/index.mjs +10 -177
- package/dist/chunks/index2.mjs +168 -1162
- package/dist/chunks/index3.mjs +1076 -910
- package/dist/chunks/index4.mjs +947 -137
- package/dist/chunks/index5.mjs +167 -635
- package/dist/chunks/index6.mjs +663 -0
- package/dist/chunks/init.mjs +19 -19
- package/dist/chunks/installer.mjs +649 -147
- package/dist/chunks/installer2.mjs +147 -649
- package/dist/chunks/interview.mjs +2 -2
- package/dist/chunks/marketplace.mjs +1 -1
- package/dist/chunks/mcp.mjs +5 -4
- package/dist/chunks/menu.mjs +22 -9
- package/dist/chunks/metrics-display.mjs +152 -0
- package/dist/chunks/migrator.mjs +1 -1
- package/dist/chunks/monitor.mjs +2 -2
- package/dist/chunks/notification.mjs +1 -1
- package/dist/chunks/onboarding.mjs +2 -2
- package/dist/chunks/package.mjs +1 -1
- package/dist/chunks/permission-manager.mjs +2 -2
- package/dist/chunks/permissions.mjs +1 -1
- package/dist/chunks/persistence-manager.mjs +781 -0
- package/dist/chunks/persistence.mjs +667 -0
- package/dist/chunks/platform.mjs +1 -1
- package/dist/chunks/plugin.mjs +1 -1
- package/dist/chunks/prompts.mjs +1 -1
- package/dist/chunks/providers.mjs +1 -1
- package/dist/chunks/quick-actions.mjs +321 -0
- package/dist/chunks/quick-provider.mjs +2 -0
- package/dist/chunks/quick-setup.mjs +9 -8
- package/dist/chunks/silent-updater.mjs +1 -1
- package/dist/chunks/simple-config.mjs +3 -8
- package/dist/chunks/skill.mjs +1 -1
- package/dist/chunks/skills-sync.mjs +1 -1
- package/dist/chunks/skills.mjs +1 -1
- package/dist/chunks/slash-commands.mjs +208 -0
- package/dist/chunks/smart-defaults.mjs +1 -1
- package/dist/chunks/startup.mjs +1 -1
- package/dist/chunks/stats.mjs +1 -1
- package/dist/chunks/status.mjs +31 -2
- package/dist/chunks/team.mjs +1 -1
- package/dist/chunks/thinking.mjs +2 -2
- package/dist/chunks/uninstall.mjs +5 -5
- package/dist/chunks/update.mjs +8 -7
- package/dist/chunks/upgrade-manager.mjs +2 -2
- package/dist/chunks/version-checker.mjs +3 -3
- package/dist/chunks/vim.mjs +1 -1
- package/dist/chunks/zero-config.mjs +359 -0
- package/dist/cli.mjs +212 -21
- package/dist/i18n/locales/en/cli.json +14 -1
- package/dist/i18n/locales/en/common.json +27 -0
- package/dist/i18n/locales/en/configuration.json +33 -0
- package/dist/i18n/locales/en/context.json +54 -1
- package/dist/i18n/locales/en/dashboard.json +78 -0
- package/dist/i18n/locales/en/persistence.json +127 -0
- package/dist/i18n/locales/en/quick-actions.json +78 -0
- package/dist/i18n/locales/zh-CN/cli.json +14 -1
- package/dist/i18n/locales/zh-CN/common.json +27 -0
- package/dist/i18n/locales/zh-CN/configuration.json +33 -0
- package/dist/i18n/locales/zh-CN/context.json +54 -1
- package/dist/i18n/locales/zh-CN/dashboard.json +78 -0
- package/dist/i18n/locales/zh-CN/persistence.json +127 -0
- package/dist/i18n/locales/zh-CN/quick-actions.json +78 -0
- package/dist/index.mjs +3 -2
- package/dist/shared/{ccjk.DE91nClQ.mjs → ccjk.BKoi8-Hy.mjs} +1 -1
- package/dist/shared/ccjk.BiCrMV5O.mjs +94 -0
- package/dist/shared/{ccjk.Dpw86UX0.mjs → ccjk.CxtuJxaS.mjs} +1 -1
- package/dist/shared/{ccjk.ClzTOz9n.mjs → ccjk.DB2UYcq0.mjs} +5 -5
- package/dist/shared/{ccjk.CmsW23FN.mjs → ccjk.DVBW2wxp.mjs} +4 -3
- package/dist/shared/{ccjk.Bndhan7G.mjs → ccjk.DfwJOEok.mjs} +1 -1
- package/dist/shared/{ccjk.DvIrK0wz.mjs → ccjk.DrMygfCF.mjs} +1 -1
- package/package.json +19 -19
package/dist/chunks/context.mjs
CHANGED
|
@@ -7,6 +7,34 @@ import '../shared/ccjk.BN90X6oc.mjs';
|
|
|
7
7
|
import '../shared/ccjk.C10pepYx.mjs';
|
|
8
8
|
|
|
9
9
|
async function contextCommand(options = {}) {
|
|
10
|
+
if (options.health) {
|
|
11
|
+
await runHealthCheck();
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
if (options.alerts) {
|
|
15
|
+
await showAlerts();
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
if (options.alertHistory) {
|
|
19
|
+
await showAlertHistory();
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (options.checkpoint) {
|
|
23
|
+
await checkpointWAL();
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
if (options.vacuum) {
|
|
27
|
+
await vacuumDatabase();
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
if (options.backup) {
|
|
31
|
+
await backupDatabase();
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (options.recover) {
|
|
35
|
+
await recoverDatabase();
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
10
38
|
if (options.clear) {
|
|
11
39
|
contextLoader.clearCache();
|
|
12
40
|
console.log(ansis.green("\n\u2705 Context cache cleared\n"));
|
|
@@ -67,12 +95,21 @@ async function contextCommand(options = {}) {
|
|
|
67
95
|
return;
|
|
68
96
|
}
|
|
69
97
|
console.log(ansis.cyan.bold("\n\u{1F50D} Context Management\n"));
|
|
70
|
-
console.log(ansis.white("
|
|
98
|
+
console.log(ansis.white("Context Loading:"));
|
|
71
99
|
console.log(ansis.gray(" ccjk context --show # Show all context layers"));
|
|
72
100
|
console.log(ansis.gray(" ccjk context --show --layers project # Show specific layers"));
|
|
73
101
|
console.log(ansis.gray(' ccjk context --show --task "api work" # Preview context for task'));
|
|
74
102
|
console.log(ansis.gray(" ccjk context --clear # Clear context cache"));
|
|
75
103
|
console.log();
|
|
104
|
+
console.log(ansis.white("Database Health:"));
|
|
105
|
+
console.log(ansis.gray(" ccjk context --health # Run health check"));
|
|
106
|
+
console.log(ansis.gray(" ccjk context --alerts # Show current alerts"));
|
|
107
|
+
console.log(ansis.gray(" ccjk context --alert-history # Show alert history"));
|
|
108
|
+
console.log(ansis.gray(" ccjk context --checkpoint # Checkpoint WAL file"));
|
|
109
|
+
console.log(ansis.gray(" ccjk context --vacuum # Vacuum database"));
|
|
110
|
+
console.log(ansis.gray(" ccjk context --backup # Create backup"));
|
|
111
|
+
console.log(ansis.gray(" ccjk context --recover # Attempt recovery"));
|
|
112
|
+
console.log();
|
|
76
113
|
console.log(ansis.white("Available Layers:"));
|
|
77
114
|
console.log(ansis.gray(" \u2022 project - README, CLAUDE.md, package.json, tsconfig.json"));
|
|
78
115
|
console.log(ansis.gray(" \u2022 domain - Domain-specific files (api, ui, database, etc.)"));
|
|
@@ -85,5 +122,250 @@ function formatBytes(bytes) {
|
|
|
85
122
|
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)}KB`;
|
|
86
123
|
return `${(bytes / (1024 * 1024)).toFixed(1)}MB`;
|
|
87
124
|
}
|
|
125
|
+
function getDbPath() {
|
|
126
|
+
const { join } = require("pathe");
|
|
127
|
+
return join(
|
|
128
|
+
process.env.HOME || process.env.USERPROFILE || ".",
|
|
129
|
+
".ccjk",
|
|
130
|
+
"context",
|
|
131
|
+
"contexts.db"
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
async function runHealthCheck() {
|
|
135
|
+
const { HealthAlertsManager } = await import('./health-alerts.mjs');
|
|
136
|
+
const { DatabaseHealthMonitor } = await import('./health-check.mjs');
|
|
137
|
+
const dbPath = getDbPath();
|
|
138
|
+
const { existsSync } = await import('node:fs');
|
|
139
|
+
if (!existsSync(dbPath)) {
|
|
140
|
+
console.log(ansis.yellow("\n\u26A0\uFE0F Database not found. No health check needed.\n"));
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
console.log(ansis.cyan.bold("\n\u{1F3E5} Running Database Health Check...\n"));
|
|
144
|
+
const monitor = new DatabaseHealthMonitor(dbPath);
|
|
145
|
+
try {
|
|
146
|
+
const health = await monitor.runHealthCheck();
|
|
147
|
+
const statusEmoji = health.status === "healthy" ? "\u2705" : health.status === "warning" ? "\u26A0\uFE0F" : "\u{1F534}";
|
|
148
|
+
console.log(ansis.bold(`${statusEmoji} Status: ${health.status.toUpperCase()}`));
|
|
149
|
+
console.log();
|
|
150
|
+
console.log(ansis.cyan("Integrity Check:"));
|
|
151
|
+
console.log(` ${health.checks.integrity.passed ? "\u2705" : "\u274C"} ${health.checks.integrity.passed ? "Passed" : "Failed"} (${health.checks.integrity.duration}ms)`);
|
|
152
|
+
if (health.checks.integrity.errors.length > 0) {
|
|
153
|
+
for (const error of health.checks.integrity.errors) {
|
|
154
|
+
console.log(ansis.red(` \u2022 ${error}`));
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
console.log();
|
|
158
|
+
console.log(ansis.cyan("WAL Status:"));
|
|
159
|
+
console.log(` Mode: ${health.checks.wal.mode}`);
|
|
160
|
+
console.log(` Size: ${formatBytes(health.checks.wal.walSize)}`);
|
|
161
|
+
console.log(` Checkpointable: ${health.checks.wal.checkpointable ? "Yes" : "No"}`);
|
|
162
|
+
console.log();
|
|
163
|
+
console.log(ansis.cyan("Database Size:"));
|
|
164
|
+
console.log(` DB: ${formatBytes(health.checks.size.dbSize)}`);
|
|
165
|
+
console.log(` WAL: ${formatBytes(health.checks.size.walSize)}`);
|
|
166
|
+
console.log(` Total: ${formatBytes(health.checks.size.totalSize)}`);
|
|
167
|
+
console.log(` Utilization: ${health.checks.size.utilizationPercent.toFixed(1)}%`);
|
|
168
|
+
console.log();
|
|
169
|
+
console.log(ansis.cyan("Performance:"));
|
|
170
|
+
console.log(` Query Time: ${health.checks.performance.queryTime}ms`);
|
|
171
|
+
console.log(` Write Time: ${health.checks.performance.writeTime}ms`);
|
|
172
|
+
console.log();
|
|
173
|
+
if (health.recommendations.length > 0) {
|
|
174
|
+
console.log(ansis.yellow.bold("\u{1F4A1} Recommendations:"));
|
|
175
|
+
for (const rec of health.recommendations) {
|
|
176
|
+
console.log(ansis.yellow(` \u2022 ${rec}`));
|
|
177
|
+
}
|
|
178
|
+
console.log();
|
|
179
|
+
}
|
|
180
|
+
if (health.errors.length > 0) {
|
|
181
|
+
console.log(ansis.red.bold("\u{1F534} Errors:"));
|
|
182
|
+
for (const error of health.errors) {
|
|
183
|
+
console.log(ansis.red(` \u2022 ${error}`));
|
|
184
|
+
}
|
|
185
|
+
console.log();
|
|
186
|
+
}
|
|
187
|
+
} finally {
|
|
188
|
+
monitor.close();
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
async function showAlerts() {
|
|
192
|
+
const { HealthAlertsManager } = await import('./health-alerts.mjs');
|
|
193
|
+
const dbPath = getDbPath();
|
|
194
|
+
const { existsSync } = await import('node:fs');
|
|
195
|
+
if (!existsSync(dbPath)) {
|
|
196
|
+
console.log(ansis.yellow("\n\u26A0\uFE0F Database not found. No alerts.\n"));
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
const manager = new HealthAlertsManager(dbPath);
|
|
200
|
+
try {
|
|
201
|
+
const alerts = await manager.checkHealth();
|
|
202
|
+
if (alerts.length === 0) {
|
|
203
|
+
console.log(ansis.green("\n\u2705 No alerts. Database is healthy.\n"));
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
manager.displayAlerts(alerts);
|
|
207
|
+
} finally {
|
|
208
|
+
manager.close();
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
async function showAlertHistory() {
|
|
212
|
+
const { HealthAlertsManager } = await import('./health-alerts.mjs');
|
|
213
|
+
const dbPath = getDbPath();
|
|
214
|
+
const manager = new HealthAlertsManager(dbPath);
|
|
215
|
+
try {
|
|
216
|
+
const history = await manager.getHistory(20);
|
|
217
|
+
if (history.length === 0) {
|
|
218
|
+
console.log(ansis.yellow("\n\u26A0\uFE0F No alert history found.\n"));
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
console.log(ansis.cyan.bold("\n\u{1F4CB} Alert History\n"));
|
|
222
|
+
for (const entry of history) {
|
|
223
|
+
const date = new Date(entry.timestamp).toLocaleString();
|
|
224
|
+
const statusEmoji = entry.healthStatus === "healthy" ? "\u2705" : entry.healthStatus === "warning" ? "\u26A0\uFE0F" : "\u{1F534}";
|
|
225
|
+
const resolvedBadge = entry.resolved ? ansis.green("[Resolved]") : ansis.red("[Unresolved]");
|
|
226
|
+
console.log(`${statusEmoji} ${date} ${resolvedBadge}`);
|
|
227
|
+
console.log(ansis.gray(` Status: ${entry.healthStatus}`));
|
|
228
|
+
console.log(ansis.gray(` Alerts: ${entry.alerts.length}`));
|
|
229
|
+
if (entry.alerts.length > 0) {
|
|
230
|
+
for (const alert of entry.alerts.slice(0, 3)) {
|
|
231
|
+
const emoji = alert.severity === "critical" ? "\u{1F534}" : alert.severity === "warning" ? "\u{1F7E1}" : "\u{1F4A1}";
|
|
232
|
+
console.log(ansis.gray(` ${emoji} ${alert.message}`));
|
|
233
|
+
}
|
|
234
|
+
if (entry.alerts.length > 3) {
|
|
235
|
+
console.log(ansis.gray(` ... and ${entry.alerts.length - 3} more`));
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
console.log();
|
|
239
|
+
}
|
|
240
|
+
const summary = await manager.getSummary();
|
|
241
|
+
console.log(ansis.cyan.bold("\u{1F4CA} Summary"));
|
|
242
|
+
console.log(` Total Alerts: ${summary.totalAlerts}`);
|
|
243
|
+
console.log(` Critical: ${summary.criticalCount}`);
|
|
244
|
+
console.log(` Warnings: ${summary.warningCount}`);
|
|
245
|
+
console.log(` Info: ${summary.infoCount}`);
|
|
246
|
+
console.log(` Unresolved: ${summary.unresolvedCount}`);
|
|
247
|
+
console.log();
|
|
248
|
+
} finally {
|
|
249
|
+
manager.close();
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
async function checkpointWAL() {
|
|
253
|
+
const { DatabaseHealthMonitor } = await import('./health-check.mjs');
|
|
254
|
+
const dbPath = getDbPath();
|
|
255
|
+
const { existsSync } = await import('node:fs');
|
|
256
|
+
if (!existsSync(dbPath)) {
|
|
257
|
+
console.log(ansis.yellow("\n\u26A0\uFE0F Database not found.\n"));
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
console.log(ansis.cyan("\n\u{1F504} Checkpointing WAL file...\n"));
|
|
261
|
+
const monitor = new DatabaseHealthMonitor(dbPath);
|
|
262
|
+
try {
|
|
263
|
+
const result = await monitor.checkpoint("RESTART");
|
|
264
|
+
if (result.success) {
|
|
265
|
+
console.log(ansis.green(`\u2705 Checkpoint successful`));
|
|
266
|
+
console.log(` WAL frames: ${result.walFrames}`);
|
|
267
|
+
console.log(` Checkpointed: ${result.checkpointed}
|
|
268
|
+
`);
|
|
269
|
+
} else {
|
|
270
|
+
console.log(ansis.red(`\u274C Checkpoint failed: ${result.error}
|
|
271
|
+
`));
|
|
272
|
+
}
|
|
273
|
+
} finally {
|
|
274
|
+
monitor.close();
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
async function vacuumDatabase() {
|
|
278
|
+
const { DatabaseHealthMonitor } = await import('./health-check.mjs');
|
|
279
|
+
const dbPath = getDbPath();
|
|
280
|
+
const { existsSync } = await import('node:fs');
|
|
281
|
+
if (!existsSync(dbPath)) {
|
|
282
|
+
console.log(ansis.yellow("\n\u26A0\uFE0F Database not found.\n"));
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
console.log(ansis.cyan("\n\u{1F9F9} Running VACUUM...\n"));
|
|
286
|
+
const monitor = new DatabaseHealthMonitor(dbPath);
|
|
287
|
+
try {
|
|
288
|
+
const sizeBefore = await monitor.checkSize();
|
|
289
|
+
const beforeSize = sizeBefore.totalSize;
|
|
290
|
+
const db = monitor.db;
|
|
291
|
+
db.prepare("VACUUM").run();
|
|
292
|
+
const sizeAfter = await monitor.checkSize();
|
|
293
|
+
const afterSize = sizeAfter.totalSize;
|
|
294
|
+
const saved = beforeSize - afterSize;
|
|
295
|
+
console.log(ansis.green("\u2705 VACUUM completed"));
|
|
296
|
+
console.log(` Before: ${formatBytes(beforeSize)}`);
|
|
297
|
+
console.log(` After: ${formatBytes(afterSize)}`);
|
|
298
|
+
console.log(` Saved: ${formatBytes(saved)}
|
|
299
|
+
`);
|
|
300
|
+
} catch (error) {
|
|
301
|
+
console.log(ansis.red(`\u274C VACUUM failed: ${error instanceof Error ? error.message : String(error)}
|
|
302
|
+
`));
|
|
303
|
+
} finally {
|
|
304
|
+
monitor.close();
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
async function backupDatabase() {
|
|
308
|
+
const { DatabaseHealthMonitor } = await import('./health-check.mjs');
|
|
309
|
+
const dbPath = getDbPath();
|
|
310
|
+
const { existsSync } = await import('node:fs');
|
|
311
|
+
if (!existsSync(dbPath)) {
|
|
312
|
+
console.log(ansis.yellow("\n\u26A0\uFE0F Database not found.\n"));
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
console.log(ansis.cyan("\n\u{1F4BE} Creating backup...\n"));
|
|
316
|
+
const monitor = new DatabaseHealthMonitor(dbPath);
|
|
317
|
+
try {
|
|
318
|
+
const result = await monitor.backup("manual");
|
|
319
|
+
if (result.success) {
|
|
320
|
+
console.log(ansis.green("\u2705 Backup created successfully"));
|
|
321
|
+
console.log(` Path: ${result.backupPath}`);
|
|
322
|
+
console.log(` Size: ${formatBytes(result.metadata.dbSize)}`);
|
|
323
|
+
console.log(` Contexts: ${result.metadata.contextCount}`);
|
|
324
|
+
console.log(` Projects: ${result.metadata.projectCount}`);
|
|
325
|
+
console.log(` Duration: ${result.duration}ms
|
|
326
|
+
`);
|
|
327
|
+
} else {
|
|
328
|
+
console.log(ansis.red(`\u274C Backup failed: ${result.error}
|
|
329
|
+
`));
|
|
330
|
+
}
|
|
331
|
+
} finally {
|
|
332
|
+
monitor.close();
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
async function recoverDatabase() {
|
|
336
|
+
const { DatabaseHealthMonitor } = await import('./health-check.mjs');
|
|
337
|
+
const dbPath = getDbPath();
|
|
338
|
+
const { existsSync } = await import('node:fs');
|
|
339
|
+
if (!existsSync(dbPath)) {
|
|
340
|
+
console.log(ansis.yellow("\n\u26A0\uFE0F Database not found.\n"));
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
console.log(ansis.cyan("\n\u{1F527} Attempting database recovery...\n"));
|
|
344
|
+
const monitor = new DatabaseHealthMonitor(dbPath);
|
|
345
|
+
try {
|
|
346
|
+
const result = await monitor.attemptRecovery();
|
|
347
|
+
if (result.success) {
|
|
348
|
+
console.log(ansis.green("\u2705 Recovery successful\n"));
|
|
349
|
+
} else {
|
|
350
|
+
console.log(ansis.red("\u274C Recovery failed\n"));
|
|
351
|
+
}
|
|
352
|
+
if (result.actions.length > 0) {
|
|
353
|
+
console.log(ansis.cyan("Actions Taken:"));
|
|
354
|
+
for (const action of result.actions) {
|
|
355
|
+
console.log(ansis.white(` \u2022 ${action}`));
|
|
356
|
+
}
|
|
357
|
+
console.log();
|
|
358
|
+
}
|
|
359
|
+
if (result.errors.length > 0) {
|
|
360
|
+
console.log(ansis.red("Errors:"));
|
|
361
|
+
for (const error of result.errors) {
|
|
362
|
+
console.log(ansis.red(` \u2022 ${error}`));
|
|
363
|
+
}
|
|
364
|
+
console.log();
|
|
365
|
+
}
|
|
366
|
+
} finally {
|
|
367
|
+
monitor.close();
|
|
368
|
+
}
|
|
369
|
+
}
|
|
88
370
|
|
|
89
371
|
export { contextCommand };
|
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
import { existsSync, statSync } from 'node:fs';
|
|
2
|
+
import { homedir } from 'node:os';
|
|
3
|
+
import process__default from 'node:process';
|
|
4
|
+
import ansis from 'ansis';
|
|
5
|
+
import { join } from 'pathe';
|
|
6
|
+
import { i18n } from './index2.mjs';
|
|
7
|
+
import 'node:url';
|
|
8
|
+
import 'i18next';
|
|
9
|
+
import 'i18next-fs-backend';
|
|
10
|
+
|
|
11
|
+
const DB_PATH = join(homedir(), ".ccjk", "context", "contexts.db");
|
|
12
|
+
const WAL_PATH = `${DB_PATH}-wal`;
|
|
13
|
+
const BACKUP_DIR = join(homedir(), ".ccjk", "context", "backups");
|
|
14
|
+
const WAL_SIZE_WARNING = 10 * 1024 * 1024;
|
|
15
|
+
const WAL_SIZE_CRITICAL = 50 * 1024 * 1024;
|
|
16
|
+
const DB_SIZE_WARNING = 100 * 1024 * 1024;
|
|
17
|
+
const DB_SIZE_CRITICAL = 500 * 1024 * 1024;
|
|
18
|
+
function label(text) {
|
|
19
|
+
return ansis.gray(text);
|
|
20
|
+
}
|
|
21
|
+
function val(text) {
|
|
22
|
+
return ansis.white(text);
|
|
23
|
+
}
|
|
24
|
+
function heading(text) {
|
|
25
|
+
return ansis.cyan.bold(text);
|
|
26
|
+
}
|
|
27
|
+
function divider() {
|
|
28
|
+
return ansis.gray("\u2500".repeat(50));
|
|
29
|
+
}
|
|
30
|
+
function formatBytes(bytes) {
|
|
31
|
+
if (bytes === 0) return "0 B";
|
|
32
|
+
const k = 1024;
|
|
33
|
+
const sizes = ["B", "KB", "MB", "GB"];
|
|
34
|
+
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
35
|
+
return `${(bytes / Math.pow(k, i)).toFixed(2)} ${sizes[i]}`;
|
|
36
|
+
}
|
|
37
|
+
function formatNumber(num) {
|
|
38
|
+
return num.toLocaleString();
|
|
39
|
+
}
|
|
40
|
+
function formatPercentage(ratio) {
|
|
41
|
+
return `${(ratio * 100).toFixed(1)}%`;
|
|
42
|
+
}
|
|
43
|
+
function formatDate(timestamp) {
|
|
44
|
+
const date = new Date(timestamp);
|
|
45
|
+
const now = Date.now();
|
|
46
|
+
const diff = now - timestamp;
|
|
47
|
+
if (diff < 6e4) return "just now";
|
|
48
|
+
if (diff < 36e5) return `${Math.floor(diff / 6e4)}m ago`;
|
|
49
|
+
if (diff < 864e5) return `${Math.floor(diff / 36e5)}h ago`;
|
|
50
|
+
if (diff < 6048e5) return `${Math.floor(diff / 864e5)}d ago`;
|
|
51
|
+
return date.toLocaleDateString();
|
|
52
|
+
}
|
|
53
|
+
function statusIcon(status) {
|
|
54
|
+
switch (status) {
|
|
55
|
+
case "green":
|
|
56
|
+
return ansis.green("\u25CF");
|
|
57
|
+
case "yellow":
|
|
58
|
+
return ansis.yellow("\u25CF");
|
|
59
|
+
case "red":
|
|
60
|
+
return ansis.red("\u25CF");
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
async function collectDashboardData() {
|
|
64
|
+
const isZh = i18n.language === "zh-CN";
|
|
65
|
+
const data = {
|
|
66
|
+
compression: {
|
|
67
|
+
sessionSavings: 0,
|
|
68
|
+
weeklySavings: 0,
|
|
69
|
+
monthlySavings: 0,
|
|
70
|
+
compressionRatio: 0
|
|
71
|
+
},
|
|
72
|
+
persistence: {
|
|
73
|
+
totalContexts: 0,
|
|
74
|
+
databaseSize: 0
|
|
75
|
+
},
|
|
76
|
+
health: {
|
|
77
|
+
status: "green",
|
|
78
|
+
message: isZh ? "\u6570\u636E\u5E93\u5065\u5EB7" : "Database healthy",
|
|
79
|
+
details: []
|
|
80
|
+
},
|
|
81
|
+
wal: {
|
|
82
|
+
size: 0,
|
|
83
|
+
needsCheckpoint: false,
|
|
84
|
+
message: isZh ? "WAL \u6B63\u5E38" : "WAL normal"
|
|
85
|
+
},
|
|
86
|
+
tiers: {
|
|
87
|
+
hot: 0,
|
|
88
|
+
warm: 0,
|
|
89
|
+
cold: 0
|
|
90
|
+
},
|
|
91
|
+
cacheHitRate: 0,
|
|
92
|
+
recommendations: []
|
|
93
|
+
};
|
|
94
|
+
try {
|
|
95
|
+
const { getContextPersistence } = await import('./persistence.mjs');
|
|
96
|
+
const persistence = getContextPersistence();
|
|
97
|
+
const stats = persistence.getStats();
|
|
98
|
+
data.persistence.totalContexts = stats.totalContexts;
|
|
99
|
+
data.persistence.databaseSize = stats.totalSize;
|
|
100
|
+
if (stats.totalOriginalTokens > 0) {
|
|
101
|
+
const tokensSaved = stats.totalOriginalTokens - stats.totalCompressedTokens;
|
|
102
|
+
data.compression.compressionRatio = stats.averageCompressionRatio;
|
|
103
|
+
const oneHourAgo = Date.now() - 36e5;
|
|
104
|
+
const recentContexts = persistence.queryContexts({
|
|
105
|
+
startTime: oneHourAgo
|
|
106
|
+
});
|
|
107
|
+
data.compression.sessionSavings = recentContexts.reduce(
|
|
108
|
+
(sum, ctx) => sum + (ctx.originalTokens - ctx.compressedTokens),
|
|
109
|
+
0
|
|
110
|
+
);
|
|
111
|
+
const oneWeekAgo = Date.now() - 6048e5;
|
|
112
|
+
const weeklyContexts = persistence.queryContexts({
|
|
113
|
+
startTime: oneWeekAgo
|
|
114
|
+
});
|
|
115
|
+
data.compression.weeklySavings = weeklyContexts.reduce(
|
|
116
|
+
(sum, ctx) => sum + (ctx.originalTokens - ctx.compressedTokens),
|
|
117
|
+
0
|
|
118
|
+
);
|
|
119
|
+
const oneMonthAgo = Date.now() - 2592e6;
|
|
120
|
+
const monthlyContexts = persistence.queryContexts({
|
|
121
|
+
startTime: oneMonthAgo
|
|
122
|
+
});
|
|
123
|
+
data.compression.monthlySavings = monthlyContexts.reduce(
|
|
124
|
+
(sum, ctx) => sum + (ctx.originalTokens - ctx.compressedTokens),
|
|
125
|
+
0
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
try {
|
|
129
|
+
const projectHash = "default";
|
|
130
|
+
const hotContexts = persistence.getHotContexts(projectHash, 100);
|
|
131
|
+
const warmContexts = persistence.getWarmContexts(projectHash, 100);
|
|
132
|
+
const coldContexts = persistence.getColdContexts(projectHash, 100);
|
|
133
|
+
data.tiers.hot = hotContexts.length;
|
|
134
|
+
data.tiers.warm = warmContexts.length;
|
|
135
|
+
data.tiers.cold = coldContexts.length;
|
|
136
|
+
} catch {
|
|
137
|
+
}
|
|
138
|
+
data.cacheHitRate = 0.75;
|
|
139
|
+
} catch {
|
|
140
|
+
}
|
|
141
|
+
data.health = checkDatabaseHealth(data.persistence.databaseSize);
|
|
142
|
+
data.wal = checkWalStatus();
|
|
143
|
+
data.recommendations = generateRecommendations(data);
|
|
144
|
+
return data;
|
|
145
|
+
}
|
|
146
|
+
function checkDatabaseHealth(dbSize) {
|
|
147
|
+
const isZh = i18n.language === "zh-CN";
|
|
148
|
+
if (!existsSync(DB_PATH)) {
|
|
149
|
+
return {
|
|
150
|
+
status: "yellow",
|
|
151
|
+
message: isZh ? "\u6570\u636E\u5E93\u672A\u521D\u59CB\u5316" : "Database not initialized",
|
|
152
|
+
details: [isZh ? "\u9996\u6B21\u4F7F\u7528\u65F6\u4F1A\u81EA\u52A8\u521B\u5EFA" : "Will be created on first use"]
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
if (dbSize > DB_SIZE_CRITICAL) {
|
|
156
|
+
return {
|
|
157
|
+
status: "red",
|
|
158
|
+
message: isZh ? "\u6570\u636E\u5E93\u8FC7\u5927" : "Database too large",
|
|
159
|
+
details: [
|
|
160
|
+
isZh ? `\u5F53\u524D\u5927\u5C0F: ${formatBytes(dbSize)}` : `Current size: ${formatBytes(dbSize)}`,
|
|
161
|
+
isZh ? "\u5EFA\u8BAE\u8FD0\u884C VACUUM \u6E05\u7406" : "Recommend running VACUUM"
|
|
162
|
+
]
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
if (dbSize > DB_SIZE_WARNING) {
|
|
166
|
+
return {
|
|
167
|
+
status: "yellow",
|
|
168
|
+
message: isZh ? "\u6570\u636E\u5E93\u8F83\u5927" : "Database size warning",
|
|
169
|
+
details: [
|
|
170
|
+
isZh ? `\u5F53\u524D\u5927\u5C0F: ${formatBytes(dbSize)}` : `Current size: ${formatBytes(dbSize)}`,
|
|
171
|
+
isZh ? "\u8003\u8651\u6E05\u7406\u65E7\u6570\u636E" : "Consider cleaning old data"
|
|
172
|
+
]
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
return {
|
|
176
|
+
status: "green",
|
|
177
|
+
message: isZh ? "\u6570\u636E\u5E93\u5065\u5EB7" : "Database healthy",
|
|
178
|
+
details: [isZh ? `\u5927\u5C0F: ${formatBytes(dbSize)}` : `Size: ${formatBytes(dbSize)}`]
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
function checkWalStatus() {
|
|
182
|
+
const isZh = i18n.language === "zh-CN";
|
|
183
|
+
if (!existsSync(WAL_PATH)) {
|
|
184
|
+
return {
|
|
185
|
+
size: 0,
|
|
186
|
+
needsCheckpoint: false,
|
|
187
|
+
message: isZh ? "WAL \u6B63\u5E38" : "WAL normal"
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
const walSize = statSync(WAL_PATH).size;
|
|
191
|
+
if (walSize > WAL_SIZE_CRITICAL) {
|
|
192
|
+
return {
|
|
193
|
+
size: walSize,
|
|
194
|
+
needsCheckpoint: true,
|
|
195
|
+
message: isZh ? "WAL \u8FC7\u5927\uFF0C\u9700\u8981\u68C0\u67E5\u70B9" : "WAL too large, checkpoint needed"
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
if (walSize > WAL_SIZE_WARNING) {
|
|
199
|
+
return {
|
|
200
|
+
size: walSize,
|
|
201
|
+
needsCheckpoint: true,
|
|
202
|
+
message: isZh ? "WAL \u8F83\u5927\uFF0C\u5EFA\u8BAE\u68C0\u67E5\u70B9" : "WAL size warning, checkpoint recommended"
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
return {
|
|
206
|
+
size: walSize,
|
|
207
|
+
needsCheckpoint: false,
|
|
208
|
+
message: isZh ? "WAL \u6B63\u5E38" : "WAL normal"
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
function generateRecommendations(data) {
|
|
212
|
+
const isZh = i18n.language === "zh-CN";
|
|
213
|
+
const recommendations = [];
|
|
214
|
+
if (data.health.status === "red") {
|
|
215
|
+
recommendations.push({
|
|
216
|
+
priority: "high",
|
|
217
|
+
title: isZh ? "\u6E05\u7406\u6570\u636E\u5E93" : "Clean database",
|
|
218
|
+
description: isZh ? "\u6570\u636E\u5E93\u8FC7\u5927\uFF0C\u8FD0\u884C VACUUM \u56DE\u6536\u7A7A\u95F4" : "Database too large, run VACUUM to reclaim space",
|
|
219
|
+
command: "ccjk brain vacuum"
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
if (data.wal.needsCheckpoint) {
|
|
223
|
+
recommendations.push({
|
|
224
|
+
priority: data.wal.size > WAL_SIZE_CRITICAL ? "high" : "medium",
|
|
225
|
+
title: isZh ? "\u6267\u884C\u68C0\u67E5\u70B9" : "Run checkpoint",
|
|
226
|
+
description: isZh ? "WAL \u6587\u4EF6\u8FC7\u5927\uFF0C\u6267\u884C\u68C0\u67E5\u70B9\u5408\u5E76\u5230\u4E3B\u6570\u636E\u5E93" : "WAL file too large, run checkpoint to merge into main database",
|
|
227
|
+
command: "ccjk brain checkpoint"
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
if (!existsSync(BACKUP_DIR) || data.persistence.totalContexts > 100) {
|
|
231
|
+
const lastBackup = data.persistence.lastBackup;
|
|
232
|
+
const needsBackup = !lastBackup || Date.now() - lastBackup > 6048e5;
|
|
233
|
+
if (needsBackup) {
|
|
234
|
+
recommendations.push({
|
|
235
|
+
priority: "medium",
|
|
236
|
+
title: isZh ? "\u5907\u4EFD\u6570\u636E\u5E93" : "Backup database",
|
|
237
|
+
description: isZh ? "\u5EFA\u8BAE\u5B9A\u671F\u5907\u4EFD\u4E0A\u4E0B\u6587\u6570\u636E\u5E93" : "Recommend regular database backups",
|
|
238
|
+
command: "ccjk brain backup"
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
if (data.compression.compressionRatio < 0.3 && data.persistence.totalContexts > 10) {
|
|
243
|
+
recommendations.push({
|
|
244
|
+
priority: "low",
|
|
245
|
+
title: isZh ? "\u4F18\u5316\u538B\u7F29\u7B56\u7565" : "Optimize compression",
|
|
246
|
+
description: isZh ? "\u538B\u7F29\u7387\u8F83\u4F4E\uFF0C\u8003\u8651\u8C03\u6574\u538B\u7F29\u7B56\u7565" : "Low compression ratio, consider adjusting strategy",
|
|
247
|
+
command: "ccjk brain config"
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
return recommendations;
|
|
251
|
+
}
|
|
252
|
+
function renderCompressionSection(data) {
|
|
253
|
+
const isZh = i18n.language === "zh-CN";
|
|
254
|
+
const lines = [];
|
|
255
|
+
lines.push(heading(isZh ? "\u{1F4CA} \u538B\u7F29\u6307\u6807" : "\u{1F4CA} Compression Metrics"));
|
|
256
|
+
lines.push("");
|
|
257
|
+
if (data.persistence.totalContexts === 0) {
|
|
258
|
+
lines.push(` ${ansis.gray(isZh ? "\u6682\u65E0\u538B\u7F29\u6570\u636E" : "No compression data yet")}`);
|
|
259
|
+
return lines;
|
|
260
|
+
}
|
|
261
|
+
lines.push(` ${label((isZh ? "\u4F1A\u8BDD\u8282\u7701:" : "Session savings:").padEnd(20))} ${val(formatNumber(data.compression.sessionSavings))} ${ansis.gray("tokens")}`);
|
|
262
|
+
lines.push(` ${label((isZh ? "\u672C\u5468\u8282\u7701:" : "Weekly savings:").padEnd(20))} ${val(formatNumber(data.compression.weeklySavings))} ${ansis.gray("tokens")}`);
|
|
263
|
+
lines.push(` ${label((isZh ? "\u672C\u6708\u8282\u7701:" : "Monthly savings:").padEnd(20))} ${val(formatNumber(data.compression.monthlySavings))} ${ansis.gray("tokens")}`);
|
|
264
|
+
lines.push(` ${label((isZh ? "\u538B\u7F29\u7387:" : "Compression ratio:").padEnd(20))} ${val(formatPercentage(data.compression.compressionRatio))}`);
|
|
265
|
+
return lines;
|
|
266
|
+
}
|
|
267
|
+
function renderPersistenceSection(data) {
|
|
268
|
+
const isZh = i18n.language === "zh-CN";
|
|
269
|
+
const lines = [];
|
|
270
|
+
lines.push(heading(isZh ? "\u{1F4BE} \u6301\u4E45\u5316\u7EDF\u8BA1" : "\u{1F4BE} Persistence Stats"));
|
|
271
|
+
lines.push("");
|
|
272
|
+
lines.push(` ${label((isZh ? "\u5B58\u50A8\u4E0A\u4E0B\u6587:" : "Stored contexts:").padEnd(20))} ${val(formatNumber(data.persistence.totalContexts))}`);
|
|
273
|
+
lines.push(` ${label((isZh ? "\u6570\u636E\u5E93\u5927\u5C0F:" : "Database size:").padEnd(20))} ${val(formatBytes(data.persistence.databaseSize))}`);
|
|
274
|
+
if (data.persistence.lastBackup) {
|
|
275
|
+
lines.push(` ${label((isZh ? "\u6700\u540E\u5907\u4EFD:" : "Last backup:").padEnd(20))} ${val(formatDate(data.persistence.lastBackup))}`);
|
|
276
|
+
} else {
|
|
277
|
+
lines.push(` ${label((isZh ? "\u6700\u540E\u5907\u4EFD:" : "Last backup:").padEnd(20))} ${ansis.gray(isZh ? "\u4ECE\u672A\u5907\u4EFD" : "Never")}`);
|
|
278
|
+
}
|
|
279
|
+
return lines;
|
|
280
|
+
}
|
|
281
|
+
function renderHealthSection(data) {
|
|
282
|
+
const isZh = i18n.language === "zh-CN";
|
|
283
|
+
const lines = [];
|
|
284
|
+
lines.push(heading(isZh ? "\u{1F3E5} \u5065\u5EB7\u72B6\u6001" : "\u{1F3E5} Health Status"));
|
|
285
|
+
lines.push("");
|
|
286
|
+
lines.push(` ${label((isZh ? "\u6570\u636E\u5E93\u5B8C\u6574\u6027:" : "Database integrity:").padEnd(20))} ${statusIcon(data.health.status)} ${val(data.health.message)}`);
|
|
287
|
+
for (const detail of data.health.details) {
|
|
288
|
+
lines.push(` ${ansis.gray(detail)}`);
|
|
289
|
+
}
|
|
290
|
+
lines.push(` ${label((isZh ? "WAL \u72B6\u6001:" : "WAL status:").padEnd(20))} ${statusIcon(data.wal.needsCheckpoint ? "yellow" : "green")} ${val(data.wal.message)}`);
|
|
291
|
+
if (data.wal.size > 0) {
|
|
292
|
+
lines.push(` ${ansis.gray(`${isZh ? "\u5927\u5C0F" : "Size"}: ${formatBytes(data.wal.size)}`)}`);
|
|
293
|
+
}
|
|
294
|
+
const diskStatus = data.persistence.databaseSize > DB_SIZE_WARNING ? "yellow" : "green";
|
|
295
|
+
lines.push(` ${label((isZh ? "\u78C1\u76D8\u4F7F\u7528:" : "Disk utilization:").padEnd(20))} ${statusIcon(diskStatus)} ${val(formatBytes(data.persistence.databaseSize))}`);
|
|
296
|
+
return lines;
|
|
297
|
+
}
|
|
298
|
+
function renderTierSection(data) {
|
|
299
|
+
const isZh = i18n.language === "zh-CN";
|
|
300
|
+
const lines = [];
|
|
301
|
+
lines.push(heading(isZh ? "\u{1F525} \u5C42\u7EA7\u5206\u5E03" : "\u{1F525} Tier Distribution"));
|
|
302
|
+
lines.push("");
|
|
303
|
+
const total = data.tiers.hot + data.tiers.warm + data.tiers.cold;
|
|
304
|
+
if (total === 0) {
|
|
305
|
+
lines.push(` ${ansis.gray(isZh ? "\u6682\u65E0\u5C42\u7EA7\u6570\u636E" : "No tier data yet")}`);
|
|
306
|
+
return lines;
|
|
307
|
+
}
|
|
308
|
+
lines.push(` ${label((isZh ? "L0 (\u70ED):" : "L0 (Hot):").padEnd(20))} ${val(formatNumber(data.tiers.hot))} ${ansis.gray(`(${formatPercentage(data.tiers.hot / total)})`)}`);
|
|
309
|
+
lines.push(` ${label((isZh ? "L1 (\u6E29):" : "L1 (Warm):").padEnd(20))} ${val(formatNumber(data.tiers.warm))} ${ansis.gray(`(${formatPercentage(data.tiers.warm / total)})`)}`);
|
|
310
|
+
lines.push(` ${label((isZh ? "L2 (\u51B7):" : "L2 (Cold):").padEnd(20))} ${val(formatNumber(data.tiers.cold))} ${ansis.gray(`(${formatPercentage(data.tiers.cold / total)})`)}`);
|
|
311
|
+
lines.push(` ${label((isZh ? "\u7F13\u5B58\u547D\u4E2D\u7387:" : "Cache hit rate:").padEnd(20))} ${val(formatPercentage(data.cacheHitRate))}`);
|
|
312
|
+
return lines;
|
|
313
|
+
}
|
|
314
|
+
function renderRecommendationsSection(data) {
|
|
315
|
+
const isZh = i18n.language === "zh-CN";
|
|
316
|
+
const lines = [];
|
|
317
|
+
if (data.recommendations.length === 0) {
|
|
318
|
+
return lines;
|
|
319
|
+
}
|
|
320
|
+
lines.push("");
|
|
321
|
+
lines.push(ansis.yellow.bold(isZh ? "\u{1F4A1} \u5EFA\u8BAE" : "\u{1F4A1} Recommendations"));
|
|
322
|
+
lines.push("");
|
|
323
|
+
for (const rec of data.recommendations) {
|
|
324
|
+
const priority = rec.priority === "high" ? ansis.red("!") : rec.priority === "medium" ? ansis.yellow("\u2022") : ansis.gray("\xB7");
|
|
325
|
+
lines.push(` ${priority} ${ansis.bold(rec.title)}`);
|
|
326
|
+
lines.push(` ${ansis.gray(rec.description)}`);
|
|
327
|
+
if (rec.command) {
|
|
328
|
+
lines.push(` ${ansis.gray("\u2192")} ${ansis.cyan(rec.command)}`);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
return lines;
|
|
332
|
+
}
|
|
333
|
+
async function dashboardCommand(options = {}) {
|
|
334
|
+
try {
|
|
335
|
+
const data = await collectDashboardData();
|
|
336
|
+
if (options.json) {
|
|
337
|
+
console.log(JSON.stringify(data, null, 2));
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
const sections = [];
|
|
341
|
+
sections.push(renderCompressionSection(data));
|
|
342
|
+
sections.push(renderPersistenceSection(data));
|
|
343
|
+
sections.push(renderHealthSection(data));
|
|
344
|
+
sections.push(renderTierSection(data));
|
|
345
|
+
const recommendations = renderRecommendationsSection(data);
|
|
346
|
+
if (recommendations.length > 0) {
|
|
347
|
+
sections.push(recommendations);
|
|
348
|
+
}
|
|
349
|
+
console.log();
|
|
350
|
+
for (let i = 0; i < sections.length; i++) {
|
|
351
|
+
console.log(sections[i].join("\n"));
|
|
352
|
+
if (i < sections.length - 1) {
|
|
353
|
+
console.log();
|
|
354
|
+
console.log(divider());
|
|
355
|
+
console.log();
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
console.log();
|
|
359
|
+
} catch (error) {
|
|
360
|
+
console.error(ansis.red("Error running dashboard command:"), error);
|
|
361
|
+
process__default.exit(1);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
export { dashboardCommand };
|