ccjk 12.2.2 → 12.3.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 (135) hide show
  1. package/dist/chunks/agent-teams.mjs +3 -3
  2. package/dist/chunks/agent.mjs +2 -2
  3. package/dist/chunks/agents.mjs +4 -5
  4. package/dist/chunks/api-cli.mjs +5 -5
  5. package/dist/chunks/api-providers.mjs +1 -1
  6. package/dist/chunks/api.mjs +4 -4
  7. package/dist/chunks/auto-bootstrap.mjs +1 -1
  8. package/dist/chunks/auto-fixer.mjs +3 -3
  9. package/dist/chunks/auto-init.mjs +3 -3
  10. package/dist/chunks/auto-updater.mjs +9 -9
  11. package/dist/chunks/banner.mjs +2 -2
  12. package/dist/chunks/boost.mjs +4 -4
  13. package/dist/chunks/ccjk-agents.mjs +3 -3
  14. package/dist/chunks/ccjk-all.mjs +6 -6
  15. package/dist/chunks/ccjk-config.mjs +2 -2
  16. package/dist/chunks/ccjk-hooks.mjs +4 -4
  17. package/dist/chunks/ccjk-mcp.mjs +5 -5
  18. package/dist/chunks/ccjk-setup.mjs +5 -5
  19. package/dist/chunks/ccjk-skills.mjs +5 -5
  20. package/dist/chunks/ccr.mjs +14 -14
  21. package/dist/chunks/ccu.mjs +2 -2
  22. package/dist/chunks/check-updates.mjs +6 -6
  23. package/dist/chunks/claude-code-config-manager.mjs +5 -4
  24. package/dist/chunks/claude-code-incremental-manager.mjs +6 -6
  25. package/dist/chunks/claude-config.mjs +1 -1
  26. package/dist/chunks/claude-wrapper.mjs +1 -1
  27. package/dist/chunks/cli-hook.mjs +9 -10
  28. package/dist/chunks/codex-config-switch.mjs +6 -6
  29. package/dist/chunks/codex-provider-manager.mjs +6 -6
  30. package/dist/chunks/codex-uninstaller.mjs +2 -2
  31. package/dist/chunks/codex.mjs +5 -5
  32. package/dist/chunks/commands.mjs +2 -2
  33. package/dist/chunks/commands2.mjs +1 -1
  34. package/dist/chunks/commit.mjs +2 -2
  35. package/dist/chunks/completion.mjs +2 -2
  36. package/dist/chunks/config-consolidator.mjs +2 -2
  37. package/dist/chunks/config-switch.mjs +7 -7
  38. package/dist/chunks/config.mjs +3 -3
  39. package/dist/chunks/config2.mjs +4 -4
  40. package/dist/chunks/config3.mjs +3 -3
  41. package/dist/chunks/constants.mjs +1 -1
  42. package/dist/chunks/context-opt.mjs +442 -0
  43. package/dist/chunks/convoy-manager.mjs +355 -3
  44. package/dist/chunks/dashboard.mjs +2 -2
  45. package/dist/chunks/doctor.mjs +4 -4
  46. package/dist/chunks/evolution.mjs +2 -2
  47. package/dist/chunks/health-alerts.mjs +530 -4
  48. package/dist/chunks/help.mjs +1 -1
  49. package/dist/chunks/index.mjs +0 -23
  50. package/dist/chunks/index10.mjs +571 -634
  51. package/dist/chunks/index11.mjs +569 -1061
  52. package/dist/chunks/index12.mjs +1076 -914
  53. package/dist/chunks/index13.mjs +951 -135
  54. package/dist/chunks/index14.mjs +184 -209
  55. package/dist/chunks/index15.mjs +218 -0
  56. package/dist/chunks/index2.mjs +24 -19
  57. package/dist/chunks/index3.mjs +12 -19085
  58. package/dist/chunks/index4.mjs +19092 -16
  59. package/dist/chunks/index5.mjs +16 -7602
  60. package/dist/chunks/index6.mjs +7590 -159
  61. package/dist/chunks/index7.mjs +171 -1602
  62. package/dist/chunks/index8.mjs +1602 -19
  63. package/dist/chunks/index9.mjs +15 -612
  64. package/dist/chunks/init.mjs +13 -13
  65. package/dist/chunks/installer.mjs +5 -5
  66. package/dist/chunks/installer2.mjs +1 -1
  67. package/dist/chunks/interview.mjs +4 -4
  68. package/dist/chunks/manager.mjs +1 -1
  69. package/dist/chunks/marketplace.mjs +2 -2
  70. package/dist/chunks/mcp-cli.mjs +9 -9
  71. package/dist/chunks/mcp.mjs +7 -7
  72. package/dist/chunks/memory.mjs +3 -3
  73. package/dist/chunks/menu-hierarchical.mjs +14 -14
  74. package/dist/chunks/menu.mjs +12 -12
  75. package/dist/chunks/metrics-display.mjs +1 -1
  76. package/dist/chunks/migrator.mjs +1 -1
  77. package/dist/chunks/monitor.mjs +2 -2
  78. package/dist/chunks/notification.mjs +4 -4
  79. package/dist/chunks/onboarding-wizard.mjs +2 -2
  80. package/dist/chunks/onboarding.mjs +4 -4
  81. package/dist/chunks/package.mjs +1 -1
  82. package/dist/chunks/paradigm.mjs +1 -1
  83. package/dist/chunks/permission-manager.mjs +2 -2
  84. package/dist/chunks/permissions.mjs +3 -3
  85. package/dist/chunks/persistence-manager.mjs +3 -3
  86. package/dist/chunks/plugin.mjs +2 -2
  87. package/dist/chunks/prompts.mjs +5 -5
  88. package/dist/chunks/providers.mjs +2 -2
  89. package/dist/chunks/quick-actions.mjs +2 -2
  90. package/dist/chunks/quick-provider.mjs +6 -5
  91. package/dist/chunks/quick-setup.mjs +10 -10
  92. package/dist/chunks/remote.mjs +5 -5
  93. package/dist/chunks/session.mjs +2 -2
  94. package/dist/chunks/sessions.mjs +1 -1
  95. package/dist/chunks/silent-updater.mjs +1 -1
  96. package/dist/chunks/simple-config.mjs +1 -1
  97. package/dist/chunks/skill2.mjs +3 -3
  98. package/dist/chunks/skills-sync.mjs +4 -4
  99. package/dist/chunks/skills.mjs +3 -3
  100. package/dist/chunks/slash-commands.mjs +3 -3
  101. package/dist/chunks/startup.mjs +1 -1
  102. package/dist/chunks/stats.mjs +2 -2
  103. package/dist/chunks/status.mjs +2 -2
  104. package/dist/chunks/team.mjs +3 -3
  105. package/dist/chunks/thinking.mjs +4 -4
  106. package/dist/chunks/trace.mjs +2 -2
  107. package/dist/chunks/uninstall.mjs +8 -8
  108. package/dist/chunks/update.mjs +9 -9
  109. package/dist/chunks/upgrade-manager.mjs +3 -3
  110. package/dist/chunks/version-checker.mjs +4 -4
  111. package/dist/chunks/vim.mjs +3 -3
  112. package/dist/chunks/workflows.mjs +1 -1
  113. package/dist/chunks/wsl.mjs +1 -1
  114. package/dist/chunks/zero-config.mjs +3 -3
  115. package/dist/cli.mjs +56 -23
  116. package/dist/index.mjs +5 -5
  117. package/dist/shared/{ccjk.CCcQfbni.mjs → ccjk.B1TwPltj.mjs} +1 -1
  118. package/dist/shared/{ccjk.CePkJq2S.mjs → ccjk.BfIpomdz.mjs} +1 -1
  119. package/dist/shared/{ccjk.D8ZLYSZZ.mjs → ccjk.CXzjn01x.mjs} +1 -1
  120. package/dist/shared/{ccjk.Cjj8SVrn.mjs → ccjk.Cot9p9_n.mjs} +1 -1
  121. package/dist/shared/{ccjk.CvChMYvB.mjs → ccjk.DCw2WnZU.mjs} +1 -1
  122. package/dist/shared/{ccjk.DG_o24cZ.mjs → ccjk.DJdmgr2d.mjs} +1 -1
  123. package/dist/shared/{ccjk.BIxuVL3_.mjs → ccjk.DcKLglJQ.mjs} +2 -2
  124. package/dist/shared/{ccjk.DLLw-h4Y.mjs → ccjk.DfXjf8EC.mjs} +2 -2
  125. package/dist/shared/{ccjk.KpFl2RDA.mjs → ccjk.DpstNaeR.mjs} +3 -3
  126. package/dist/shared/{ccjk.DOBWBkFR.mjs → ccjk.XsJWJuQP.mjs} +5 -5
  127. package/dist/shared/{ccjk._dESH4Rk.mjs → ccjk.dYDLfmph.mjs} +1 -1
  128. package/dist/shared/{ccjk.DS7UESmF.mjs → ccjk.hrRv8G6j.mjs} +4 -4
  129. package/dist/shared/{ccjk.BWFpnOr3.mjs → ccjk.mJpVRDZ8.mjs} +1 -1
  130. package/dist/templates/claude-code/common/settings.json +3 -1
  131. package/package.json +20 -18
  132. package/templates/claude-code/common/settings.json +3 -1
  133. package/dist/chunks/context-loader.mjs +0 -351
  134. package/dist/chunks/context.mjs +0 -372
  135. package/dist/chunks/health-check.mjs +0 -532
@@ -0,0 +1,442 @@
1
+ import initSqlJs from 'sql.js';
2
+ import { existsSync, readFileSync, writeFileSync } from 'node:fs';
3
+ import { homedir } from 'os';
4
+ import { existsSync as existsSync$1, mkdirSync } from 'fs';
5
+ import { j as join } from '../shared/ccjk.bQ7Dh1g4.mjs';
6
+ import cron from 'node-cron';
7
+
8
+ let SQL = null;
9
+ async function initSQL() {
10
+ if (!SQL) {
11
+ SQL = await initSqlJs();
12
+ }
13
+ return SQL;
14
+ }
15
+ async function createDatabase(path) {
16
+ const sql = await initSQL();
17
+ if (existsSync(path)) {
18
+ const buffer = readFileSync(path);
19
+ return new sql.Database(buffer);
20
+ }
21
+ return new sql.Database();
22
+ }
23
+ function saveDatabase(db, path) {
24
+ const data = db.export();
25
+ writeFileSync(path, data);
26
+ }
27
+
28
+ class MemoryTree {
29
+ db;
30
+ dbPath;
31
+ initialized = false;
32
+ constructor(dbPath) {
33
+ this.dbPath = dbPath || this.getDefaultDbPath();
34
+ this.ensureDbDirectory();
35
+ }
36
+ async init() {
37
+ if (!this.initialized) {
38
+ this.db = await createDatabase(this.dbPath);
39
+ this.initSchema();
40
+ this.initialized = true;
41
+ }
42
+ }
43
+ getDefaultDbPath() {
44
+ const ccjkDir = process.env.ZCF_CONFIG_DIR || join(homedir(), ".ccjk");
45
+ return join(ccjkDir, "memory.db");
46
+ }
47
+ ensureDbDirectory() {
48
+ const dir = this.dbPath.substring(0, this.dbPath.lastIndexOf("/"));
49
+ if (!existsSync$1(dir)) {
50
+ mkdirSync(dir, { recursive: true });
51
+ }
52
+ }
53
+ initSchema() {
54
+ this.db.run(`
55
+ CREATE TABLE IF NOT EXISTS memory_nodes (
56
+ id TEXT PRIMARY KEY,
57
+ content TEXT NOT NULL,
58
+ summary TEXT NOT NULL,
59
+ confidence REAL NOT NULL,
60
+ priority TEXT NOT NULL,
61
+ last_accessed INTEGER NOT NULL,
62
+ access_count INTEGER NOT NULL,
63
+ created_at INTEGER NOT NULL,
64
+ metadata TEXT
65
+ );
66
+ `);
67
+ this.db.run(`CREATE INDEX IF NOT EXISTS idx_confidence ON memory_nodes(confidence);`);
68
+ this.db.run(`CREATE INDEX IF NOT EXISTS idx_priority ON memory_nodes(priority);`);
69
+ this.db.run(`CREATE INDEX IF NOT EXISTS idx_last_accessed ON memory_nodes(last_accessed);`);
70
+ this.save();
71
+ }
72
+ async addNode(node) {
73
+ await this.init();
74
+ const id = `mem_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
75
+ const now = Date.now();
76
+ this.db.run(
77
+ `INSERT INTO memory_nodes (id, content, summary, confidence, priority, last_accessed, access_count, created_at, metadata)
78
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`,
79
+ [id, node.content, node.summary, node.confidence, node.priority, now, 0, now, JSON.stringify(node.metadata || {})]
80
+ );
81
+ this.save();
82
+ return id;
83
+ }
84
+ async getNode(id) {
85
+ await this.init();
86
+ const results = this.db.exec(`SELECT * FROM memory_nodes WHERE id = ?`, [id]);
87
+ if (!results.length || !results[0].values.length) return null;
88
+ const row = results[0].values[0];
89
+ return this.rowToNode(results[0].columns, row);
90
+ }
91
+ async search(query, options = {}) {
92
+ await this.init();
93
+ const { limit = 10, minConfidence = 0.3, priorities = ["P0", "P1", "P2"] } = options;
94
+ const priorityFilter = priorities.map(() => "?").join(",");
95
+ const pattern = `%${query}%`;
96
+ const sql = `
97
+ SELECT *,
98
+ (CASE
99
+ WHEN content LIKE ? THEN 1
100
+ WHEN summary LIKE ? THEN 2
101
+ ELSE 3
102
+ END) as score
103
+ FROM memory_nodes
104
+ WHERE (content LIKE ? OR summary LIKE ?)
105
+ AND confidence >= ?
106
+ AND priority IN (${priorityFilter})
107
+ ORDER BY score, confidence DESC
108
+ LIMIT ?
109
+ `;
110
+ const results = this.db.exec(sql, [pattern, pattern, pattern, pattern, minConfidence, ...priorities, limit]);
111
+ if (!results.length || !results[0].values.length) return [];
112
+ return results[0].values.map((row) => {
113
+ const node = this.rowToNode(results[0].columns, row);
114
+ return { ...node, score: row[results[0].columns.indexOf("score")] };
115
+ });
116
+ }
117
+ async updateConfidence(id, delta) {
118
+ await this.init();
119
+ this.db.run(
120
+ `UPDATE memory_nodes
121
+ SET confidence = CASE
122
+ WHEN confidence + ? > 1.0 THEN 1.0
123
+ WHEN confidence + ? < 0.0 THEN 0.0
124
+ ELSE confidence + ?
125
+ END
126
+ WHERE id = ?`,
127
+ [delta, delta, delta, id]
128
+ );
129
+ this.save();
130
+ }
131
+ async recordAccess(id) {
132
+ await this.init();
133
+ const now = Date.now();
134
+ this.db.run(
135
+ `UPDATE memory_nodes
136
+ SET last_accessed = ?,
137
+ access_count = access_count + 1,
138
+ confidence = CASE
139
+ WHEN confidence + 0.05 > 1.0 THEN 1.0
140
+ ELSE confidence + 0.05
141
+ END
142
+ WHERE id = ?`,
143
+ [now, id]
144
+ );
145
+ this.save();
146
+ }
147
+ async applyDecay(decayRate = 0.01) {
148
+ await this.init();
149
+ const before = this.db.exec(`SELECT COUNT(*) FROM memory_nodes`);
150
+ const countBefore = before[0]?.values[0]?.[0] || 0;
151
+ this.db.run(
152
+ `UPDATE memory_nodes
153
+ SET confidence = CASE
154
+ WHEN confidence - ? < 0.0 THEN 0.0
155
+ ELSE confidence - ?
156
+ END`,
157
+ [decayRate, decayRate]
158
+ );
159
+ this.save();
160
+ return countBefore;
161
+ }
162
+ async archiveLowConfidence(threshold = 0.3) {
163
+ await this.init();
164
+ const before = this.db.exec(`SELECT COUNT(*) FROM memory_nodes WHERE confidence < ?`, [threshold]);
165
+ const count = before[0]?.values[0]?.[0] || 0;
166
+ this.db.run(`DELETE FROM memory_nodes WHERE confidence < ?`, [threshold]);
167
+ this.save();
168
+ return count;
169
+ }
170
+ async getStats() {
171
+ await this.init();
172
+ const results = this.db.exec(`
173
+ SELECT
174
+ COUNT(*) as total,
175
+ SUM(CASE WHEN confidence >= 0.8 THEN 1 ELSE 0 END) as green,
176
+ SUM(CASE WHEN confidence >= 0.5 AND confidence < 0.8 THEN 1 ELSE 0 END) as yellow,
177
+ SUM(CASE WHEN confidence >= 0.3 AND confidence < 0.5 THEN 1 ELSE 0 END) as brown,
178
+ SUM(CASE WHEN confidence < 0.3 THEN 1 ELSE 0 END) as archived,
179
+ AVG(confidence) as avg_confidence
180
+ FROM memory_nodes
181
+ `);
182
+ const priorityResults = this.db.exec(`
183
+ SELECT priority, COUNT(*) as count
184
+ FROM memory_nodes
185
+ GROUP BY priority
186
+ `);
187
+ const row = results[0]?.values[0] || [];
188
+ const byPriority = {};
189
+ if (priorityResults.length && priorityResults[0].values.length) {
190
+ for (const pRow of priorityResults[0].values) {
191
+ byPriority[pRow[0]] = pRow[1];
192
+ }
193
+ }
194
+ return {
195
+ totalNodes: row[0] || 0,
196
+ greenLeaves: row[1] || 0,
197
+ yellowLeaves: row[2] || 0,
198
+ brownLeaves: row[3] || 0,
199
+ archived: row[4] || 0,
200
+ avgConfidence: row[5] || 0,
201
+ byPriority
202
+ };
203
+ }
204
+ async getAllNodes(options = {}) {
205
+ await this.init();
206
+ const { minConfidence = 0, priorities = ["P0", "P1", "P2"], limit } = options;
207
+ const priorityFilter = priorities.map(() => "?").join(",");
208
+ let sql = `
209
+ SELECT * FROM memory_nodes
210
+ WHERE confidence >= ?
211
+ AND priority IN (${priorityFilter})
212
+ ORDER BY confidence DESC, last_accessed DESC
213
+ `;
214
+ const params = [minConfidence, ...priorities];
215
+ if (limit) {
216
+ sql += " LIMIT ?";
217
+ params.push(limit);
218
+ }
219
+ const results = this.db.exec(sql, params);
220
+ if (!results.length || !results[0].values.length) return [];
221
+ return results[0].values.map((row) => this.rowToNode(results[0].columns, row));
222
+ }
223
+ async deleteNode(id) {
224
+ await this.init();
225
+ this.db.run(`DELETE FROM memory_nodes WHERE id = ?`, [id]);
226
+ this.save();
227
+ const results = this.db.exec(`SELECT changes()`);
228
+ return (results[0]?.values[0]?.[0] || 0) > 0;
229
+ }
230
+ async clear() {
231
+ await this.init();
232
+ this.db.run(`DELETE FROM memory_nodes`);
233
+ this.save();
234
+ }
235
+ close() {
236
+ if (this.initialized) {
237
+ this.save();
238
+ this.db.close();
239
+ this.initialized = false;
240
+ }
241
+ }
242
+ save() {
243
+ if (this.initialized) {
244
+ saveDatabase(this.db, this.dbPath);
245
+ }
246
+ }
247
+ rowToNode(columns, row) {
248
+ const obj = {};
249
+ columns.forEach((col, i) => {
250
+ obj[col] = row[i];
251
+ });
252
+ return {
253
+ id: obj.id,
254
+ content: obj.content,
255
+ summary: obj.summary,
256
+ confidence: obj.confidence,
257
+ priority: obj.priority,
258
+ lastAccessed: new Date(obj.last_accessed),
259
+ accessCount: obj.access_count,
260
+ createdAt: new Date(obj.created_at),
261
+ metadata: obj.metadata ? JSON.parse(obj.metadata) : {}
262
+ };
263
+ }
264
+ }
265
+
266
+ class DecayScheduler {
267
+ memoryTree;
268
+ task = null;
269
+ archiveThreshold;
270
+ constructor(memoryTree, archiveThreshold = 0.3) {
271
+ this.memoryTree = memoryTree;
272
+ this.archiveThreshold = archiveThreshold;
273
+ }
274
+ /**
275
+ * Start scheduled decay (user must explicitly call this)
276
+ */
277
+ start(schedule = "0 2 * * *") {
278
+ if (this.task) {
279
+ console.warn("[CCJK Context] Decay scheduler already running");
280
+ return;
281
+ }
282
+ if (!cron.validate(schedule)) {
283
+ throw new Error(`Invalid cron expression: ${schedule}`);
284
+ }
285
+ console.log(`[CCJK Context] Starting decay scheduler: ${schedule}`);
286
+ console.log("[CCJK Context] This will run in the background. Use .stop() to disable.");
287
+ this.task = cron.schedule(schedule, async () => {
288
+ console.log("[CCJK Context] Running scheduled decay...");
289
+ try {
290
+ const result = await this.runDecay();
291
+ console.log(`[CCJK Context] Decayed ${result.decayed} nodes, archived ${result.archived} nodes`);
292
+ } catch (err) {
293
+ console.error("[CCJK Context] Decay error:", err);
294
+ }
295
+ });
296
+ }
297
+ /**
298
+ * Stop scheduled decay
299
+ */
300
+ stop() {
301
+ if (this.task) {
302
+ this.task.stop();
303
+ this.task = null;
304
+ console.log("[CCJK Context] Decay scheduler stopped");
305
+ }
306
+ }
307
+ /**
308
+ * Check if scheduler is running
309
+ */
310
+ isRunning() {
311
+ return this.task !== null;
312
+ }
313
+ /**
314
+ * Run decay manually
315
+ */
316
+ async runNow() {
317
+ return this.runDecay();
318
+ }
319
+ /**
320
+ * Preview what would be decayed (dry run)
321
+ */
322
+ async preview() {
323
+ const stats = this.memoryTree.getStats();
324
+ return {
325
+ wouldDecay: stats.totalNodes - stats.byPriority["P0"] || 0,
326
+ wouldArchive: stats.brownLeaves,
327
+ stats
328
+ };
329
+ }
330
+ /**
331
+ * Internal decay execution
332
+ */
333
+ async runDecay() {
334
+ const decayResult = this.memoryTree.decay();
335
+ const archived = this.memoryTree.archiveLowConfidence(this.archiveThreshold);
336
+ return {
337
+ decayed: decayResult.decayed,
338
+ archived,
339
+ details: decayResult.details
340
+ };
341
+ }
342
+ }
343
+
344
+ async function contextOptStats() {
345
+ if (process.env.CCJK_MEMORY_TREE !== "true") {
346
+ console.error("\u274C Memory tree not enabled. Set CCJK_MEMORY_TREE=true");
347
+ process.exit(1);
348
+ }
349
+ try {
350
+ const tree = new MemoryTree();
351
+ const stats = await tree.getStats();
352
+ console.log("\n\u{1F4CA} Memory Tree Statistics\n");
353
+ console.log(`Total Nodes: ${stats.totalNodes}`);
354
+ console.log(`Average Confidence: ${stats.avgConfidence.toFixed(2)}
355
+ `);
356
+ console.log("By Confidence:");
357
+ console.log(` \u{1F7E2} Green (\u22650.8): ${stats.greenLeaves}`);
358
+ console.log(` \u{1F7E1} Yellow (0.5-0.8): ${stats.yellowLeaves}`);
359
+ console.log(` \u{1F7E4} Brown (0.3-0.5): ${stats.brownLeaves}`);
360
+ console.log(` \u26AB Archived (<0.3): ${stats.archived}
361
+ `);
362
+ console.log("By Priority:");
363
+ console.log(` P0 (Critical): ${stats.byPriority["P0"] || 0}`);
364
+ console.log(` P1 (Important): ${stats.byPriority["P1"] || 0}`);
365
+ console.log(` P2 (Routine): ${stats.byPriority["P2"] || 0}`);
366
+ tree.close();
367
+ } catch (err) {
368
+ console.error("\u274C Failed to get stats:", err);
369
+ process.exit(1);
370
+ }
371
+ }
372
+ async function contextOptSearch(query, options = {}) {
373
+ if (process.env.CCJK_MEMORY_TREE !== "true") {
374
+ console.error("\u274C Memory tree not enabled. Set CCJK_MEMORY_TREE=true");
375
+ process.exit(1);
376
+ }
377
+ try {
378
+ const tree = new MemoryTree();
379
+ const topK = parseInt(options.topK || "5");
380
+ const results = await tree.search(query, { limit: topK });
381
+ if (results.length === 0) {
382
+ console.log("\n\u{1F50D} No results found\n");
383
+ tree.close();
384
+ return;
385
+ }
386
+ console.log(`
387
+ \u{1F50D} Found ${results.length} results:
388
+ `);
389
+ results.forEach((node, i) => {
390
+ console.log(`${i + 1}. [${node.priority}] Confidence: ${node.confidence.toFixed(2)} | Score: ${node.score.toFixed(2)}`);
391
+ console.log(` ${node.summary.slice(0, 100)}${node.summary.length > 100 ? "..." : ""}`);
392
+ console.log(` Accessed: ${node.accessCount} times | Last: ${node.lastAccessed.toISOString()}
393
+ `);
394
+ });
395
+ tree.close();
396
+ } catch (err) {
397
+ console.error("\u274C Search failed:", err);
398
+ process.exit(1);
399
+ }
400
+ }
401
+ async function contextOptDecay() {
402
+ if (process.env.CCJK_MEMORY_TREE !== "true") {
403
+ console.error("\u274C Memory tree not enabled. Set CCJK_MEMORY_TREE=true");
404
+ process.exit(1);
405
+ }
406
+ try {
407
+ const tree = new MemoryTree();
408
+ const threshold = 0.3;
409
+ const scheduler = new DecayScheduler(tree, threshold);
410
+ console.log("\n\u2699\uFE0F Running decay...\n");
411
+ const result = await scheduler.runNow();
412
+ console.log(`\u2705 Decayed: ${result.decayed} nodes`);
413
+ console.log(`\u{1F4E6} Archived: ${result.archived} nodes
414
+ `);
415
+ console.log("Details:");
416
+ Object.entries(result.details).forEach(([priority, count]) => {
417
+ console.log(` ${priority}: ${count} nodes`);
418
+ });
419
+ tree.close();
420
+ } catch (err) {
421
+ console.error("\u274C Decay failed:", err);
422
+ process.exit(1);
423
+ }
424
+ }
425
+ async function contextOptConfig() {
426
+ console.log("\n\u2699\uFE0F Context Optimization Configuration\n");
427
+ console.log(`CCJK_CONTEXT_OPTIMIZATION: ${process.env.CCJK_CONTEXT_OPTIMIZATION || "false"}`);
428
+ console.log(`CCJK_TOOL_COMPRESSION: ${process.env.CCJK_TOOL_COMPRESSION || "true"}`);
429
+ console.log(`CCJK_SEMANTIC_COMPRESSION: ${process.env.CCJK_SEMANTIC_COMPRESSION || "false"}`);
430
+ console.log(`CCJK_MEMORY_TREE: ${process.env.CCJK_MEMORY_TREE || "false"}`);
431
+ console.log(`CCJK_MAX_CONTEXT_TOKENS: ${process.env.CCJK_MAX_CONTEXT_TOKENS || "150000"}`);
432
+ console.log(`CCJK_COMPRESSION_TIMEOUT: ${process.env.CCJK_COMPRESSION_TIMEOUT || "50"}ms
433
+ `);
434
+ const ccjkDir = process.env.ZCF_CONFIG_DIR || join(homedir(), ".ccjk");
435
+ const dbPath = join(ccjkDir, "memory.db");
436
+ const dbExists = existsSync$1(dbPath);
437
+ console.log(`Memory DB: ${dbPath}`);
438
+ console.log(`DB Exists: ${dbExists ? "\u2705" : "\u274C"}
439
+ `);
440
+ }
441
+
442
+ export { contextOptConfig, contextOptDecay, contextOptSearch, contextOptStats };