ccjk 12.0.7 → 12.0.8

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 (299) hide show
  1. package/package.json +1 -1
  2. package/dist/chunks/agent-teams.mjs +0 -136
  3. package/dist/chunks/agent.mjs +0 -1439
  4. package/dist/chunks/agents.mjs +0 -3778
  5. package/dist/chunks/api-cli.mjs +0 -132
  6. package/dist/chunks/api-providers.mjs +0 -129
  7. package/dist/chunks/api.mjs +0 -112
  8. package/dist/chunks/auto-bootstrap.mjs +0 -358
  9. package/dist/chunks/auto-init.mjs +0 -7584
  10. package/dist/chunks/auto-updater.mjs +0 -410
  11. package/dist/chunks/banner.mjs +0 -188
  12. package/dist/chunks/bash.mjs +0 -187
  13. package/dist/chunks/boost.mjs +0 -397
  14. package/dist/chunks/ccjk-agents.mjs +0 -414
  15. package/dist/chunks/ccjk-all.mjs +0 -1028
  16. package/dist/chunks/ccjk-config.mjs +0 -261
  17. package/dist/chunks/ccjk-hooks.mjs +0 -1074
  18. package/dist/chunks/ccjk-mcp.mjs +0 -761
  19. package/dist/chunks/ccjk-setup.mjs +0 -763
  20. package/dist/chunks/ccjk-skills.mjs +0 -514
  21. package/dist/chunks/ccr.mjs +0 -98
  22. package/dist/chunks/ccu.mjs +0 -40
  23. package/dist/chunks/check-updates.mjs +0 -108
  24. package/dist/chunks/claude-code-config-manager.mjs +0 -750
  25. package/dist/chunks/claude-code-incremental-manager.mjs +0 -623
  26. package/dist/chunks/claude-config.mjs +0 -236
  27. package/dist/chunks/claude-wrapper.mjs +0 -85
  28. package/dist/chunks/cleanup-migration.mjs +0 -20
  29. package/dist/chunks/cli-hook.mjs +0 -2285
  30. package/dist/chunks/cloud-sync.mjs +0 -29
  31. package/dist/chunks/codex-config-switch.mjs +0 -451
  32. package/dist/chunks/codex-provider-manager.mjs +0 -236
  33. package/dist/chunks/codex-uninstaller.mjs +0 -404
  34. package/dist/chunks/codex.mjs +0 -2077
  35. package/dist/chunks/commands.mjs +0 -108
  36. package/dist/chunks/commands2.mjs +0 -413
  37. package/dist/chunks/commit.mjs +0 -138
  38. package/dist/chunks/completion.mjs +0 -515
  39. package/dist/chunks/config-consolidator.mjs +0 -172
  40. package/dist/chunks/config-switch.mjs +0 -317
  41. package/dist/chunks/config.mjs +0 -379
  42. package/dist/chunks/config2.mjs +0 -477
  43. package/dist/chunks/config3.mjs +0 -470
  44. package/dist/chunks/constants.mjs +0 -133
  45. package/dist/chunks/context-loader.mjs +0 -343
  46. package/dist/chunks/context.mjs +0 -372
  47. package/dist/chunks/convoy-manager.mjs +0 -880
  48. package/dist/chunks/dashboard.mjs +0 -476
  49. package/dist/chunks/doctor.mjs +0 -964
  50. package/dist/chunks/evolution.mjs +0 -382
  51. package/dist/chunks/features.mjs +0 -698
  52. package/dist/chunks/fish.mjs +0 -181
  53. package/dist/chunks/fs-operations.mjs +0 -192
  54. package/dist/chunks/health-alerts.mjs +0 -304
  55. package/dist/chunks/health-check.mjs +0 -532
  56. package/dist/chunks/help.mjs +0 -340
  57. package/dist/chunks/hook-installer.mjs +0 -45
  58. package/dist/chunks/index.mjs +0 -24
  59. package/dist/chunks/index10.mjs +0 -1171
  60. package/dist/chunks/index11.mjs +0 -1008
  61. package/dist/chunks/index12.mjs +0 -193
  62. package/dist/chunks/index13.mjs +0 -218
  63. package/dist/chunks/index14.mjs +0 -663
  64. package/dist/chunks/index2.mjs +0 -19
  65. package/dist/chunks/index3.mjs +0 -19092
  66. package/dist/chunks/index4.mjs +0 -8
  67. package/dist/chunks/index5.mjs +0 -7600
  68. package/dist/chunks/index6.mjs +0 -171
  69. package/dist/chunks/index7.mjs +0 -3583
  70. package/dist/chunks/index8.mjs +0 -19
  71. package/dist/chunks/index9.mjs +0 -616
  72. package/dist/chunks/init.mjs +0 -1606
  73. package/dist/chunks/installer.mjs +0 -690
  74. package/dist/chunks/installer2.mjs +0 -179
  75. package/dist/chunks/interview.mjs +0 -2927
  76. package/dist/chunks/json-config.mjs +0 -60
  77. package/dist/chunks/linux.mjs +0 -3863
  78. package/dist/chunks/macos.mjs +0 -69
  79. package/dist/chunks/main.mjs +0 -635
  80. package/dist/chunks/manager.mjs +0 -1048
  81. package/dist/chunks/marketplace.mjs +0 -949
  82. package/dist/chunks/mcp-cli.mjs +0 -204
  83. package/dist/chunks/mcp-performance.mjs +0 -187
  84. package/dist/chunks/mcp.mjs +0 -1231
  85. package/dist/chunks/menu.mjs +0 -652
  86. package/dist/chunks/metrics-display.mjs +0 -153
  87. package/dist/chunks/migrator.mjs +0 -178
  88. package/dist/chunks/monitor.mjs +0 -1856
  89. package/dist/chunks/notification.mjs +0 -1864
  90. package/dist/chunks/onboarding.mjs +0 -385
  91. package/dist/chunks/package.mjs +0 -3
  92. package/dist/chunks/paradigm.mjs +0 -74
  93. package/dist/chunks/permission-manager.mjs +0 -132
  94. package/dist/chunks/permissions.mjs +0 -265
  95. package/dist/chunks/persistence-manager.mjs +0 -794
  96. package/dist/chunks/persistence.mjs +0 -667
  97. package/dist/chunks/platform.mjs +0 -391
  98. package/dist/chunks/plugin.mjs +0 -1936
  99. package/dist/chunks/powershell.mjs +0 -213
  100. package/dist/chunks/prompts.mjs +0 -241
  101. package/dist/chunks/providers.mjs +0 -260
  102. package/dist/chunks/quick-actions.mjs +0 -320
  103. package/dist/chunks/quick-provider.mjs +0 -682
  104. package/dist/chunks/quick-setup.mjs +0 -412
  105. package/dist/chunks/remote.mjs +0 -497
  106. package/dist/chunks/session.mjs +0 -878
  107. package/dist/chunks/sessions.mjs +0 -106
  108. package/dist/chunks/silent-updater.mjs +0 -396
  109. package/dist/chunks/simple-config.mjs +0 -98
  110. package/dist/chunks/skill.mjs +0 -117
  111. package/dist/chunks/skill2.mjs +0 -9003
  112. package/dist/chunks/skills-sync.mjs +0 -6460
  113. package/dist/chunks/skills.mjs +0 -567
  114. package/dist/chunks/slash-commands.mjs +0 -207
  115. package/dist/chunks/smart-defaults.mjs +0 -412
  116. package/dist/chunks/smart-guide.mjs +0 -194
  117. package/dist/chunks/startup.mjs +0 -487
  118. package/dist/chunks/stats.mjs +0 -410
  119. package/dist/chunks/status.mjs +0 -289
  120. package/dist/chunks/team.mjs +0 -63
  121. package/dist/chunks/thinking.mjs +0 -626
  122. package/dist/chunks/trace.mjs +0 -57
  123. package/dist/chunks/uninstall.mjs +0 -849
  124. package/dist/chunks/update.mjs +0 -167
  125. package/dist/chunks/upgrade-manager.mjs +0 -204
  126. package/dist/chunks/version-checker.mjs +0 -881
  127. package/dist/chunks/vim.mjs +0 -903
  128. package/dist/chunks/windows.mjs +0 -14
  129. package/dist/chunks/workflows.mjs +0 -633
  130. package/dist/chunks/wsl.mjs +0 -129
  131. package/dist/chunks/zero-config.mjs +0 -374
  132. package/dist/chunks/zsh.mjs +0 -182
  133. package/dist/cli.d.mts +0 -1
  134. package/dist/cli.d.ts +0 -1
  135. package/dist/cli.mjs +0 -2199
  136. package/dist/i18n/locales/en/agent-teams.json +0 -18
  137. package/dist/i18n/locales/en/agentBrowser.json +0 -79
  138. package/dist/i18n/locales/en/agents.json +0 -135
  139. package/dist/i18n/locales/en/api.json +0 -63
  140. package/dist/i18n/locales/en/ccjk-agents.json +0 -33
  141. package/dist/i18n/locales/en/ccjk-all.json +0 -23
  142. package/dist/i18n/locales/en/ccjk-skills.json +0 -22
  143. package/dist/i18n/locales/en/ccjk.json +0 -276
  144. package/dist/i18n/locales/en/ccr.json +0 -65
  145. package/dist/i18n/locales/en/claude-md.json +0 -73
  146. package/dist/i18n/locales/en/cli.json +0 -152
  147. package/dist/i18n/locales/en/cloud-setup.json +0 -31
  148. package/dist/i18n/locales/en/cloud-sync.json +0 -147
  149. package/dist/i18n/locales/en/cloud.json +0 -40
  150. package/dist/i18n/locales/en/cloudPlugins.json +0 -118
  151. package/dist/i18n/locales/en/codex.json +0 -127
  152. package/dist/i18n/locales/en/cometix.json +0 -29
  153. package/dist/i18n/locales/en/common.json +0 -68
  154. package/dist/i18n/locales/en/config.json +0 -108
  155. package/dist/i18n/locales/en/configuration.json +0 -226
  156. package/dist/i18n/locales/en/context.json +0 -85
  157. package/dist/i18n/locales/en/dashboard.json +0 -78
  158. package/dist/i18n/locales/en/errors.json +0 -26
  159. package/dist/i18n/locales/en/evolution.json +0 -54
  160. package/dist/i18n/locales/en/hooks.json +0 -74
  161. package/dist/i18n/locales/en/hooksSync.json +0 -133
  162. package/dist/i18n/locales/en/installation.json +0 -83
  163. package/dist/i18n/locales/en/interview.json +0 -104
  164. package/dist/i18n/locales/en/language.json +0 -19
  165. package/dist/i18n/locales/en/lsp.json +0 -78
  166. package/dist/i18n/locales/en/marketplace.json +0 -116
  167. package/dist/i18n/locales/en/mcp.json +0 -178
  168. package/dist/i18n/locales/en/memory.json +0 -92
  169. package/dist/i18n/locales/en/menu.json +0 -143
  170. package/dist/i18n/locales/en/multi-config.json +0 -79
  171. package/dist/i18n/locales/en/notification.json +0 -307
  172. package/dist/i18n/locales/en/permissions.json +0 -95
  173. package/dist/i18n/locales/en/persistence.json +0 -127
  174. package/dist/i18n/locales/en/plugins.json +0 -146
  175. package/dist/i18n/locales/en/quick-actions.json +0 -78
  176. package/dist/i18n/locales/en/registry.json +0 -54
  177. package/dist/i18n/locales/en/remote.json +0 -93
  178. package/dist/i18n/locales/en/sandbox.json +0 -44
  179. package/dist/i18n/locales/en/setup.json +0 -44
  180. package/dist/i18n/locales/en/shencha.json +0 -14
  181. package/dist/i18n/locales/en/skills.json +0 -100
  182. package/dist/i18n/locales/en/skillsSync.json +0 -74
  183. package/dist/i18n/locales/en/smartGuide.json +0 -49
  184. package/dist/i18n/locales/en/stats.json +0 -20
  185. package/dist/i18n/locales/en/subagent.json +0 -69
  186. package/dist/i18n/locales/en/superpowers.json +0 -117
  187. package/dist/i18n/locales/en/team.json +0 -7
  188. package/dist/i18n/locales/en/thinking.json +0 -65
  189. package/dist/i18n/locales/en/tools.json +0 -42
  190. package/dist/i18n/locales/en/uninstall.json +0 -56
  191. package/dist/i18n/locales/en/updater.json +0 -29
  192. package/dist/i18n/locales/en/vim.json +0 -169
  193. package/dist/i18n/locales/en/workflow.json +0 -55
  194. package/dist/i18n/locales/en/workspace.json +0 -108
  195. package/dist/i18n/locales/zh-CN/agent-teams.json +0 -18
  196. package/dist/i18n/locales/zh-CN/agentBrowser.json +0 -79
  197. package/dist/i18n/locales/zh-CN/agents.json +0 -135
  198. package/dist/i18n/locales/zh-CN/api.json +0 -63
  199. package/dist/i18n/locales/zh-CN/ccjk-agents.json +0 -33
  200. package/dist/i18n/locales/zh-CN/ccjk-all.json +0 -23
  201. package/dist/i18n/locales/zh-CN/ccjk-skills.json +0 -22
  202. package/dist/i18n/locales/zh-CN/ccjk.json +0 -276
  203. package/dist/i18n/locales/zh-CN/ccr.json +0 -65
  204. package/dist/i18n/locales/zh-CN/claude-md.json +0 -73
  205. package/dist/i18n/locales/zh-CN/cli.json +0 -152
  206. package/dist/i18n/locales/zh-CN/cloud-setup.json +0 -31
  207. package/dist/i18n/locales/zh-CN/cloud-sync.json +0 -147
  208. package/dist/i18n/locales/zh-CN/cloud.json +0 -40
  209. package/dist/i18n/locales/zh-CN/cloudPlugins.json +0 -118
  210. package/dist/i18n/locales/zh-CN/codex.json +0 -127
  211. package/dist/i18n/locales/zh-CN/cometix.json +0 -29
  212. package/dist/i18n/locales/zh-CN/common.json +0 -68
  213. package/dist/i18n/locales/zh-CN/config.json +0 -108
  214. package/dist/i18n/locales/zh-CN/configuration.json +0 -224
  215. package/dist/i18n/locales/zh-CN/context.json +0 -85
  216. package/dist/i18n/locales/zh-CN/dashboard.json +0 -78
  217. package/dist/i18n/locales/zh-CN/errors.json +0 -26
  218. package/dist/i18n/locales/zh-CN/evolution.json +0 -54
  219. package/dist/i18n/locales/zh-CN/hooks.json +0 -74
  220. package/dist/i18n/locales/zh-CN/hooksSync.json +0 -133
  221. package/dist/i18n/locales/zh-CN/installation.json +0 -83
  222. package/dist/i18n/locales/zh-CN/interview.json +0 -104
  223. package/dist/i18n/locales/zh-CN/language.json +0 -19
  224. package/dist/i18n/locales/zh-CN/lsp.json +0 -78
  225. package/dist/i18n/locales/zh-CN/marketplace.json +0 -116
  226. package/dist/i18n/locales/zh-CN/mcp.json +0 -178
  227. package/dist/i18n/locales/zh-CN/memory.json +0 -92
  228. package/dist/i18n/locales/zh-CN/menu.json +0 -143
  229. package/dist/i18n/locales/zh-CN/multi-config.json +0 -79
  230. package/dist/i18n/locales/zh-CN/notification.json +0 -307
  231. package/dist/i18n/locales/zh-CN/permissions.json +0 -95
  232. package/dist/i18n/locales/zh-CN/persistence.json +0 -127
  233. package/dist/i18n/locales/zh-CN/plugins.json +0 -146
  234. package/dist/i18n/locales/zh-CN/quick-actions.json +0 -78
  235. package/dist/i18n/locales/zh-CN/registry.json +0 -54
  236. package/dist/i18n/locales/zh-CN/remote.json +0 -93
  237. package/dist/i18n/locales/zh-CN/sandbox.json +0 -44
  238. package/dist/i18n/locales/zh-CN/setup.json +0 -44
  239. package/dist/i18n/locales/zh-CN/shencha.json +0 -14
  240. package/dist/i18n/locales/zh-CN/skills.json +0 -100
  241. package/dist/i18n/locales/zh-CN/skillsSync.json +0 -74
  242. package/dist/i18n/locales/zh-CN/smartGuide.json +0 -49
  243. package/dist/i18n/locales/zh-CN/stats.json +0 -20
  244. package/dist/i18n/locales/zh-CN/subagent.json +0 -69
  245. package/dist/i18n/locales/zh-CN/superpowers.json +0 -117
  246. package/dist/i18n/locales/zh-CN/team.json +0 -7
  247. package/dist/i18n/locales/zh-CN/thinking.json +0 -65
  248. package/dist/i18n/locales/zh-CN/tools.json +0 -42
  249. package/dist/i18n/locales/zh-CN/uninstall.json +0 -56
  250. package/dist/i18n/locales/zh-CN/updater.json +0 -29
  251. package/dist/i18n/locales/zh-CN/vim.json +0 -169
  252. package/dist/i18n/locales/zh-CN/workflow.json +0 -55
  253. package/dist/i18n/locales/zh-CN/workspace.json +0 -108
  254. package/dist/index.d.mts +0 -5295
  255. package/dist/index.d.ts +0 -5295
  256. package/dist/index.mjs +0 -4941
  257. package/dist/shared/ccjk.B364Fu0N.mjs +0 -1819
  258. package/dist/shared/ccjk.BAGoDD49.mjs +0 -36
  259. package/dist/shared/ccjk.BBtCGd_g.mjs +0 -899
  260. package/dist/shared/ccjk.BFQ7yr5S.mjs +0 -16
  261. package/dist/shared/ccjk.BFxsJM0k.mjs +0 -599
  262. package/dist/shared/ccjk.BIxuVL3_.mjs +0 -25
  263. package/dist/shared/ccjk.BRZ9ww8S.mjs +0 -142
  264. package/dist/shared/ccjk.BoApaI4j.mjs +0 -28
  265. package/dist/shared/ccjk.BrPUmTqm.mjs +0 -266
  266. package/dist/shared/ccjk.BtB1e5jm.mjs +0 -171
  267. package/dist/shared/ccjk.BwfbSKN2.mjs +0 -1051
  268. package/dist/shared/ccjk.BxSmJ8B7.mjs +0 -243
  269. package/dist/shared/ccjk.Bx_rmYfN.mjs +0 -69
  270. package/dist/shared/ccjk.C2jHOZVP.mjs +0 -52
  271. package/dist/shared/ccjk.CL4Yat0G.mjs +0 -303
  272. package/dist/shared/ccjk.COweQ1RR.mjs +0 -5
  273. package/dist/shared/ccjk.CePkJq2S.mjs +0 -223
  274. package/dist/shared/ccjk.CfKKcvWy.mjs +0 -126
  275. package/dist/shared/ccjk.Cjgrln_h.mjs +0 -297
  276. package/dist/shared/ccjk.Cjj8SVrn.mjs +0 -54
  277. package/dist/shared/ccjk.CxpGa6MC.mjs +0 -2724
  278. package/dist/shared/ccjk.D5MFQT7w.mjs +0 -400
  279. package/dist/shared/ccjk.D6ycHbak.mjs +0 -270
  280. package/dist/shared/ccjk.D8ZLYSZZ.mjs +0 -299
  281. package/dist/shared/ccjk.DG_o24cZ.mjs +0 -88
  282. package/dist/shared/ccjk.DLLw-h4Y.mjs +0 -460
  283. package/dist/shared/ccjk.DOwtZMk8.mjs +0 -4019
  284. package/dist/shared/ccjk.DS7UESmF.mjs +0 -2451
  285. package/dist/shared/ccjk.DTdjs-qK.mjs +0 -1447
  286. package/dist/shared/ccjk.DXRAZcix.mjs +0 -66
  287. package/dist/shared/ccjk.DsYaCCx4.mjs +0 -317
  288. package/dist/shared/ccjk.J8YiPsOw.mjs +0 -259
  289. package/dist/shared/ccjk.KfSWcGlE.mjs +0 -38
  290. package/dist/shared/ccjk.RyizuzOI.mjs +0 -21
  291. package/dist/shared/ccjk.SPoXMvZD.mjs +0 -1242
  292. package/dist/shared/ccjk.T_cX87dY.mjs +0 -15
  293. package/dist/shared/ccjk.UIvifqNE.mjs +0 -1486
  294. package/dist/shared/ccjk._dESH4Rk.mjs +0 -111
  295. package/dist/shared/ccjk.bQ7Dh1g4.mjs +0 -249
  296. package/dist/shared/ccjk.c-ETfBZ_.mjs +0 -617
  297. package/dist/shared/ccjk.gDEDGD_t.mjs +0 -38
  298. package/dist/shared/ccjk.hoqrwWdN.mjs +0 -333
  299. package/dist/shared/ccjk.waa2ikKJ.mjs +0 -351
@@ -1,667 +0,0 @@
1
- import Database from 'better-sqlite3';
2
- import { existsSync, mkdirSync } from 'node:fs';
3
- import { j as join, d as dirname } from '../shared/ccjk.bQ7Dh1g4.mjs';
4
-
5
- class ContextPersistence {
6
- db;
7
- dbPath;
8
- constructor(dbPath) {
9
- this.dbPath = dbPath || join(
10
- process.env.HOME || process.env.USERPROFILE || ".",
11
- ".ccjk",
12
- "context",
13
- "contexts.db"
14
- );
15
- const dir = dirname(this.dbPath);
16
- if (!existsSync(dir)) {
17
- mkdirSync(dir, { recursive: true });
18
- }
19
- this.db = new Database(this.dbPath);
20
- this.db.pragma("journal_mode = WAL");
21
- this.initSchema();
22
- }
23
- /**
24
- * Initialize database schema
25
- */
26
- initSchema() {
27
- this.db.exec(`
28
- CREATE TABLE IF NOT EXISTS contexts (
29
- id TEXT PRIMARY KEY,
30
- project_hash TEXT NOT NULL,
31
- content TEXT NOT NULL,
32
- compressed TEXT NOT NULL,
33
- algorithm TEXT NOT NULL,
34
- strategy TEXT NOT NULL,
35
- original_tokens INTEGER NOT NULL,
36
- compressed_tokens INTEGER NOT NULL,
37
- compression_ratio REAL NOT NULL,
38
- metadata TEXT NOT NULL DEFAULT '{}',
39
- timestamp INTEGER NOT NULL,
40
- last_accessed INTEGER NOT NULL,
41
- access_count INTEGER NOT NULL DEFAULT 1
42
- );
43
-
44
- CREATE INDEX IF NOT EXISTS idx_contexts_project ON contexts(project_hash);
45
- CREATE INDEX IF NOT EXISTS idx_contexts_timestamp ON contexts(timestamp);
46
- CREATE INDEX IF NOT EXISTS idx_contexts_last_accessed ON contexts(last_accessed);
47
- CREATE INDEX IF NOT EXISTS idx_contexts_access_count ON contexts(access_count);
48
-
49
- -- FTS5 virtual table for full-text search
50
- CREATE VIRTUAL TABLE IF NOT EXISTS contexts_fts USING fts5(
51
- id UNINDEXED,
52
- content,
53
- compressed,
54
- metadata,
55
- tokenize = 'porter unicode61'
56
- );
57
-
58
- -- Triggers to keep FTS5 in sync with main table
59
- CREATE TRIGGER IF NOT EXISTS contexts_ai AFTER INSERT ON contexts BEGIN
60
- INSERT INTO contexts_fts(id, content, compressed, metadata)
61
- VALUES (new.id, new.content, new.compressed, new.metadata);
62
- END;
63
-
64
- CREATE TRIGGER IF NOT EXISTS contexts_ad AFTER DELETE ON contexts BEGIN
65
- DELETE FROM contexts_fts WHERE id = old.id;
66
- END;
67
-
68
- CREATE TRIGGER IF NOT EXISTS contexts_au AFTER UPDATE ON contexts BEGIN
69
- UPDATE contexts_fts
70
- SET content = new.content,
71
- compressed = new.compressed,
72
- metadata = new.metadata
73
- WHERE id = old.id;
74
- END;
75
-
76
- CREATE TABLE IF NOT EXISTS projects (
77
- hash TEXT PRIMARY KEY,
78
- path TEXT NOT NULL,
79
- name TEXT,
80
- created_at INTEGER NOT NULL,
81
- updated_at INTEGER NOT NULL,
82
- context_count INTEGER NOT NULL DEFAULT 0,
83
- total_tokens INTEGER NOT NULL DEFAULT 0,
84
- metadata TEXT NOT NULL DEFAULT '{}'
85
- );
86
-
87
- CREATE INDEX IF NOT EXISTS idx_projects_created ON projects(created_at);
88
- CREATE INDEX IF NOT EXISTS idx_projects_updated ON projects(updated_at);
89
-
90
- -- Compression metrics table
91
- CREATE TABLE IF NOT EXISTS compression_metrics (
92
- id INTEGER PRIMARY KEY AUTOINCREMENT,
93
- project_hash TEXT NOT NULL,
94
- context_id TEXT NOT NULL,
95
- original_tokens INTEGER NOT NULL,
96
- compressed_tokens INTEGER NOT NULL,
97
- compression_ratio REAL NOT NULL,
98
- time_taken_ms INTEGER NOT NULL,
99
- algorithm TEXT NOT NULL,
100
- strategy TEXT NOT NULL,
101
- timestamp INTEGER NOT NULL,
102
- FOREIGN KEY (project_hash) REFERENCES projects(hash) ON DELETE CASCADE
103
- );
104
-
105
- CREATE INDEX IF NOT EXISTS idx_metrics_project ON compression_metrics(project_hash);
106
- CREATE INDEX IF NOT EXISTS idx_metrics_timestamp ON compression_metrics(timestamp);
107
- CREATE INDEX IF NOT EXISTS idx_metrics_context ON compression_metrics(context_id);
108
-
109
- -- Composite indexes for hot/warm/cold queries
110
- CREATE INDEX IF NOT EXISTS idx_contexts_hot ON contexts(project_hash, last_accessed DESC, access_count DESC);
111
- CREATE INDEX IF NOT EXISTS idx_contexts_warm ON contexts(project_hash, timestamp DESC) WHERE access_count > 1;
112
- CREATE INDEX IF NOT EXISTS idx_contexts_cold ON contexts(project_hash, timestamp ASC) WHERE access_count = 1;
113
- `);
114
- }
115
- /**
116
- * Save a compressed context
117
- */
118
- saveContext(context, projectHash, originalContent, timeTakenMs) {
119
- const stmt = this.db.prepare(`
120
- INSERT OR REPLACE INTO contexts (
121
- id, project_hash, content, compressed, algorithm, strategy,
122
- original_tokens, compressed_tokens, compression_ratio,
123
- metadata, timestamp, last_accessed, access_count
124
- ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
125
- `);
126
- const now = Date.now();
127
- const existingContext = this.getContext(context.id);
128
- const accessCount = existingContext ? existingContext.accessCount + 1 : 1;
129
- stmt.run(
130
- context.id,
131
- projectHash,
132
- originalContent || "",
133
- // Store original content if provided
134
- context.compressed,
135
- context.algorithm,
136
- context.strategy,
137
- context.originalTokens,
138
- context.compressedTokens,
139
- context.compressionRatio,
140
- JSON.stringify(context.metadata || {}),
141
- context.compressedAt || now,
142
- now,
143
- accessCount
144
- );
145
- if (timeTakenMs !== void 0) {
146
- this.saveCompressionMetric({
147
- projectHash,
148
- contextId: context.id,
149
- originalTokens: context.originalTokens,
150
- compressedTokens: context.compressedTokens,
151
- compressionRatio: context.compressionRatio,
152
- timeTakenMs,
153
- algorithm: context.algorithm,
154
- strategy: context.strategy,
155
- timestamp: now
156
- });
157
- }
158
- this.updateProjectStats(projectHash);
159
- }
160
- /**
161
- * Get context by ID
162
- */
163
- getContext(contextId) {
164
- const stmt = this.db.prepare(`
165
- SELECT * FROM contexts WHERE id = ?
166
- `);
167
- const row = stmt.get(contextId);
168
- if (!row) return null;
169
- this.updateLastAccessed(contextId);
170
- return this.rowToContext(row);
171
- }
172
- /**
173
- * Get contexts for a project
174
- */
175
- getProjectContexts(projectHash, options) {
176
- let query = "SELECT * FROM contexts WHERE project_hash = ?";
177
- const params = [projectHash];
178
- if (options?.startTime) {
179
- query += " AND timestamp >= ?";
180
- params.push(options.startTime);
181
- }
182
- if (options?.endTime) {
183
- query += " AND timestamp <= ?";
184
- params.push(options.endTime);
185
- }
186
- const sortBy = options?.sortBy || "timestamp";
187
- const sortOrder = options?.sortOrder || "desc";
188
- query += ` ORDER BY ${sortBy} ${sortOrder.toUpperCase()}`;
189
- if (options?.limit) {
190
- query += " LIMIT ?";
191
- params.push(options.limit);
192
- }
193
- const stmt = this.db.prepare(query);
194
- const rows = stmt.all(...params);
195
- return rows.map((row) => this.rowToContext(row));
196
- }
197
- /**
198
- * Query contexts with filters
199
- */
200
- queryContexts(options) {
201
- let query = "SELECT * FROM contexts WHERE 1=1";
202
- const params = [];
203
- if (options?.projectHash) {
204
- query += " AND project_hash = ?";
205
- params.push(options.projectHash);
206
- }
207
- if (options?.startTime) {
208
- query += " AND timestamp >= ?";
209
- params.push(options.startTime);
210
- }
211
- if (options?.endTime) {
212
- query += " AND timestamp <= ?";
213
- params.push(options.endTime);
214
- }
215
- const sortBy = options?.sortBy || "timestamp";
216
- const sortOrder = options?.sortOrder || "desc";
217
- query += ` ORDER BY ${sortBy} ${sortOrder.toUpperCase()}`;
218
- if (options?.limit) {
219
- query += " LIMIT ?";
220
- params.push(options.limit);
221
- }
222
- const stmt = this.db.prepare(query);
223
- const rows = stmt.all(...params);
224
- return rows.map((row) => this.rowToContext(row));
225
- }
226
- /**
227
- * Search contexts using FTS5 full-text search
228
- * @param searchQuery - Search query (supports FTS5 syntax: AND, OR, NOT, NEAR, "phrases")
229
- * @param options - Query options
230
- * @returns Search results with ranking
231
- */
232
- searchContexts(searchQuery, options) {
233
- if (!searchQuery || searchQuery.trim().length === 0) {
234
- return [];
235
- }
236
- let query = `
237
- SELECT
238
- c.*,
239
- bm25(contexts_fts) as rank,
240
- snippet(contexts_fts, 1, '<mark>', '</mark>', '...', 32) as snippet
241
- FROM contexts c
242
- INNER JOIN contexts_fts ON contexts_fts.id = c.id
243
- WHERE contexts_fts MATCH ?
244
- `;
245
- const params = [searchQuery];
246
- if (options?.projectHash) {
247
- query += " AND c.project_hash = ?";
248
- params.push(options.projectHash);
249
- }
250
- if (options?.startTime) {
251
- query += " AND c.timestamp >= ?";
252
- params.push(options.startTime);
253
- }
254
- if (options?.endTime) {
255
- query += " AND c.timestamp <= ?";
256
- params.push(options.endTime);
257
- }
258
- const sortBy = options?.sortBy || "relevance";
259
- const sortOrder = options?.sortOrder || "desc";
260
- if (sortBy === "relevance") {
261
- query += ` ORDER BY rank ${sortOrder === "asc" ? "DESC" : "ASC"}`;
262
- } else {
263
- query += ` ORDER BY c.${sortBy} ${sortOrder.toUpperCase()}`;
264
- }
265
- if (options?.limit) {
266
- query += " LIMIT ?";
267
- params.push(options.limit);
268
- }
269
- const stmt = this.db.prepare(query);
270
- const rows = stmt.all(...params);
271
- return rows.map((row) => ({
272
- ...this.rowToContext(row),
273
- rank: row.rank,
274
- snippet: row.snippet
275
- }));
276
- }
277
- /**
278
- * Get hot contexts (frequently accessed, recently used)
279
- * @param projectHash - Project hash
280
- * @param limit - Maximum number of results
281
- */
282
- getHotContexts(projectHash, limit = 10) {
283
- const stmt = this.db.prepare(`
284
- SELECT * FROM contexts
285
- WHERE project_hash = ?
286
- ORDER BY last_accessed DESC, access_count DESC
287
- LIMIT ?
288
- `);
289
- const rows = stmt.all(projectHash, limit);
290
- return rows.map((row) => this.rowToContext(row));
291
- }
292
- /**
293
- * Get warm contexts (accessed multiple times but not recently)
294
- * @param projectHash - Project hash
295
- * @param limit - Maximum number of results
296
- */
297
- getWarmContexts(projectHash, limit = 10) {
298
- const stmt = this.db.prepare(`
299
- SELECT * FROM contexts
300
- WHERE project_hash = ? AND access_count > 1
301
- ORDER BY timestamp DESC
302
- LIMIT ?
303
- `);
304
- const rows = stmt.all(projectHash, limit);
305
- return rows.map((row) => this.rowToContext(row));
306
- }
307
- /**
308
- * Get cold contexts (rarely accessed, older)
309
- * @param projectHash - Project hash
310
- * @param limit - Maximum number of results
311
- */
312
- getColdContexts(projectHash, limit = 10) {
313
- const stmt = this.db.prepare(`
314
- SELECT * FROM contexts
315
- WHERE project_hash = ? AND access_count = 1
316
- ORDER BY timestamp ASC
317
- LIMIT ?
318
- `);
319
- const rows = stmt.all(projectHash, limit);
320
- return rows.map((row) => this.rowToContext(row));
321
- }
322
- /**
323
- * Delete context by ID
324
- */
325
- deleteContext(contextId) {
326
- const context = this.getContext(contextId);
327
- if (!context) return false;
328
- const stmt = this.db.prepare("DELETE FROM contexts WHERE id = ?");
329
- const result = stmt.run(contextId);
330
- if (context.projectHash) {
331
- this.updateProjectStats(context.projectHash);
332
- }
333
- return result.changes > 0;
334
- }
335
- /**
336
- * Delete all contexts for a project
337
- */
338
- deleteProjectContexts(projectHash) {
339
- const stmt = this.db.prepare("DELETE FROM contexts WHERE project_hash = ?");
340
- const result = stmt.run(projectHash);
341
- this.updateProjectStats(projectHash);
342
- return result.changes;
343
- }
344
- /**
345
- * Register or update project
346
- */
347
- registerProject(projectHash, projectPath, projectName) {
348
- const stmt = this.db.prepare(`
349
- INSERT OR REPLACE INTO projects (hash, path, name, created_at, updated_at, context_count, total_tokens, metadata)
350
- VALUES (?, ?, ?, ?, ?, ?, ?, ?)
351
- `);
352
- const now = Date.now();
353
- const existing = this.getProject(projectHash);
354
- const createdAt = existing?.created_at || now;
355
- stmt.run(
356
- projectHash,
357
- projectPath,
358
- projectName || null,
359
- createdAt,
360
- now,
361
- existing?.context_count || 0,
362
- existing?.total_tokens || 0,
363
- JSON.stringify(existing?.metadata || {})
364
- );
365
- }
366
- /**
367
- * Get project info
368
- */
369
- getProject(projectHash) {
370
- const stmt = this.db.prepare("SELECT * FROM projects WHERE hash = ?");
371
- return stmt.get(projectHash);
372
- }
373
- /**
374
- * List all projects
375
- */
376
- listProjects() {
377
- const stmt = this.db.prepare("SELECT * FROM projects ORDER BY updated_at DESC");
378
- return stmt.all();
379
- }
380
- /**
381
- * Get context statistics
382
- */
383
- getStats(projectHash) {
384
- let query = "SELECT COUNT(*) as count, SUM(original_tokens) as orig, SUM(compressed_tokens) as comp, MIN(timestamp) as oldest, MAX(timestamp) as newest FROM contexts";
385
- const params = [];
386
- if (projectHash) {
387
- query += " WHERE project_hash = ?";
388
- params.push(projectHash);
389
- }
390
- const stmt = this.db.prepare(query);
391
- const row = stmt.get(...params);
392
- const totalProjects = projectHash ? 1 : this.db.prepare("SELECT COUNT(*) as count FROM projects").get().count;
393
- const avgRatio = row.orig > 0 ? (row.orig - row.comp) / row.orig : 0;
394
- return {
395
- totalContexts: row.count || 0,
396
- totalProjects,
397
- totalOriginalTokens: row.orig || 0,
398
- totalCompressedTokens: row.comp || 0,
399
- averageCompressionRatio: avgRatio,
400
- totalSize: this.getDatabaseSize(),
401
- oldestContext: row.oldest || void 0,
402
- newestContext: row.newest || void 0
403
- };
404
- }
405
- /**
406
- * Clean up old contexts
407
- */
408
- cleanup(maxAge) {
409
- const cutoff = Date.now() - maxAge;
410
- const stmt = this.db.prepare("DELETE FROM contexts WHERE timestamp < ?");
411
- const result = stmt.run(cutoff);
412
- const projects = this.listProjects();
413
- for (const project of projects) {
414
- this.updateProjectStats(project.hash);
415
- }
416
- return result.changes;
417
- }
418
- /**
419
- * Vacuum database to reclaim space
420
- */
421
- vacuum() {
422
- this.db.exec("VACUUM");
423
- }
424
- /**
425
- * Close database
426
- */
427
- close() {
428
- this.db.close();
429
- }
430
- /**
431
- * Get database size in bytes
432
- */
433
- getDatabaseSize() {
434
- try {
435
- const fs = require("node:fs");
436
- const stats = fs.statSync(this.dbPath);
437
- return stats.size;
438
- } catch {
439
- return 0;
440
- }
441
- }
442
- /**
443
- * Export contexts to JSON
444
- */
445
- exportContexts(projectHash) {
446
- return this.queryContexts({ projectHash });
447
- }
448
- /**
449
- * Import contexts from JSON
450
- */
451
- importContexts(contexts) {
452
- let imported = 0;
453
- const stmt = this.db.prepare(`
454
- INSERT OR REPLACE INTO contexts (
455
- id, project_hash, content, compressed, algorithm, strategy,
456
- original_tokens, compressed_tokens, compression_ratio,
457
- metadata, timestamp, last_accessed, access_count
458
- ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
459
- `);
460
- for (const context of contexts) {
461
- try {
462
- stmt.run(
463
- context.id,
464
- context.projectHash,
465
- context.content,
466
- context.compressed,
467
- context.algorithm,
468
- context.strategy,
469
- context.originalTokens,
470
- context.compressedTokens,
471
- context.compressionRatio,
472
- context.metadata,
473
- context.timestamp,
474
- context.lastAccessed,
475
- context.accessCount
476
- );
477
- imported++;
478
- } catch {
479
- }
480
- }
481
- return imported;
482
- }
483
- /**
484
- * Update last accessed time
485
- */
486
- updateLastAccessed(contextId) {
487
- const stmt = this.db.prepare(`
488
- UPDATE contexts
489
- SET last_accessed = ?, access_count = access_count + 1
490
- WHERE id = ?
491
- `);
492
- stmt.run(Date.now(), contextId);
493
- }
494
- /**
495
- * Update project statistics
496
- */
497
- updateProjectStats(projectHash) {
498
- const stmt = this.db.prepare(`
499
- UPDATE projects
500
- SET
501
- context_count = (SELECT COUNT(*) FROM contexts WHERE project_hash = ?),
502
- total_tokens = (SELECT COALESCE(SUM(original_tokens), 0) FROM contexts WHERE project_hash = ?),
503
- updated_at = ?
504
- WHERE hash = ?
505
- `);
506
- stmt.run(projectHash, projectHash, Date.now(), projectHash);
507
- }
508
- /**
509
- * Convert database row to PersistedContext
510
- */
511
- rowToContext(row) {
512
- return {
513
- id: row.id,
514
- projectHash: row.project_hash,
515
- content: row.content,
516
- compressed: row.compressed,
517
- algorithm: row.algorithm,
518
- strategy: row.strategy,
519
- originalTokens: row.original_tokens,
520
- compressedTokens: row.compressed_tokens,
521
- compressionRatio: row.compression_ratio,
522
- metadata: row.metadata,
523
- timestamp: row.timestamp,
524
- lastAccessed: row.last_accessed,
525
- accessCount: row.access_count
526
- };
527
- }
528
- /**
529
- * Save compression metric
530
- */
531
- saveCompressionMetric(metric) {
532
- const stmt = this.db.prepare(`
533
- INSERT INTO compression_metrics (
534
- project_hash, context_id, original_tokens, compressed_tokens,
535
- compression_ratio, time_taken_ms, algorithm, strategy, timestamp
536
- ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
537
- `);
538
- stmt.run(
539
- metric.projectHash,
540
- metric.contextId,
541
- metric.originalTokens,
542
- metric.compressedTokens,
543
- metric.compressionRatio,
544
- metric.timeTakenMs,
545
- metric.algorithm,
546
- metric.strategy,
547
- metric.timestamp
548
- );
549
- }
550
- /**
551
- * Get compression metrics statistics
552
- */
553
- getCompressionMetricsStats(projectHash, options) {
554
- const now = Date.now();
555
- const sessionStart = now - 24 * 60 * 60 * 1e3;
556
- const weekStart = now - 7 * 24 * 60 * 60 * 1e3;
557
- const monthStart = now - 30 * 24 * 60 * 60 * 1e3;
558
- let baseQuery = "SELECT * FROM compression_metrics WHERE 1=1";
559
- const params = [];
560
- if (projectHash) {
561
- baseQuery += " AND project_hash = ?";
562
- params.push(projectHash);
563
- }
564
- if (options?.startTime) {
565
- baseQuery += " AND timestamp >= ?";
566
- params.push(options.startTime);
567
- }
568
- if (options?.endTime) {
569
- baseQuery += " AND timestamp <= ?";
570
- params.push(options.endTime);
571
- }
572
- const stmt = this.db.prepare(baseQuery);
573
- const metrics = stmt.all(...params);
574
- const totalCompressions = metrics.length;
575
- const totalOriginalTokens = metrics.reduce((sum, m) => sum + m.original_tokens, 0);
576
- const totalCompressedTokens = metrics.reduce((sum, m) => sum + m.compressed_tokens, 0);
577
- const totalTokensSaved = totalOriginalTokens - totalCompressedTokens;
578
- const averageCompressionRatio = totalCompressions > 0 ? metrics.reduce((sum, m) => sum + m.compression_ratio, 0) / totalCompressions : 0;
579
- const averageTimeTakenMs = totalCompressions > 0 ? metrics.reduce((sum, m) => sum + m.time_taken_ms, 0) / totalCompressions : 0;
580
- const COST_PER_1K_TOKENS = 0.015;
581
- const estimatedCostSavings = totalTokensSaved / 1e3 * COST_PER_1K_TOKENS;
582
- const sessionMetrics = metrics.filter((m) => m.timestamp >= sessionStart);
583
- const sessionTokensSaved = sessionMetrics.reduce(
584
- (sum, m) => sum + (m.original_tokens - m.compressed_tokens),
585
- 0
586
- );
587
- const weeklyMetrics = metrics.filter((m) => m.timestamp >= weekStart);
588
- const weeklyTokensSaved = weeklyMetrics.reduce(
589
- (sum, m) => sum + (m.original_tokens - m.compressed_tokens),
590
- 0
591
- );
592
- const monthlyMetrics = metrics.filter((m) => m.timestamp >= monthStart);
593
- const monthlyTokensSaved = monthlyMetrics.reduce(
594
- (sum, m) => sum + (m.original_tokens - m.compressed_tokens),
595
- 0
596
- );
597
- return {
598
- totalCompressions,
599
- totalOriginalTokens,
600
- totalCompressedTokens,
601
- totalTokensSaved,
602
- averageCompressionRatio,
603
- averageTimeTakenMs,
604
- estimatedCostSavings,
605
- sessionStats: {
606
- compressions: sessionMetrics.length,
607
- tokensSaved: sessionTokensSaved,
608
- costSavings: sessionTokensSaved / 1e3 * COST_PER_1K_TOKENS
609
- },
610
- weeklyStats: {
611
- compressions: weeklyMetrics.length,
612
- tokensSaved: weeklyTokensSaved,
613
- costSavings: weeklyTokensSaved / 1e3 * COST_PER_1K_TOKENS
614
- },
615
- monthlyStats: {
616
- compressions: monthlyMetrics.length,
617
- tokensSaved: monthlyTokensSaved,
618
- costSavings: monthlyTokensSaved / 1e3 * COST_PER_1K_TOKENS
619
- }
620
- };
621
- }
622
- /**
623
- * Get recent compression metrics
624
- */
625
- getRecentCompressionMetrics(projectHash, limit = 10) {
626
- let query = "SELECT * FROM compression_metrics";
627
- const params = [];
628
- if (projectHash) {
629
- query += " WHERE project_hash = ?";
630
- params.push(projectHash);
631
- }
632
- query += " ORDER BY timestamp DESC LIMIT ?";
633
- params.push(limit);
634
- const stmt = this.db.prepare(query);
635
- const rows = stmt.all(...params);
636
- return rows.map((row) => ({
637
- id: row.id,
638
- projectHash: row.project_hash,
639
- contextId: row.context_id,
640
- originalTokens: row.original_tokens,
641
- compressedTokens: row.compressed_tokens,
642
- compressionRatio: row.compression_ratio,
643
- timeTakenMs: row.time_taken_ms,
644
- algorithm: row.algorithm,
645
- strategy: row.strategy,
646
- timestamp: row.timestamp
647
- }));
648
- }
649
- /**
650
- * Clean up old compression metrics
651
- */
652
- cleanupCompressionMetrics(maxAge) {
653
- const cutoff = Date.now() - maxAge;
654
- const stmt = this.db.prepare("DELETE FROM compression_metrics WHERE timestamp < ?");
655
- const result = stmt.run(cutoff);
656
- return result.changes;
657
- }
658
- }
659
- let globalContextPersistence = null;
660
- function getContextPersistence(dbPath) {
661
- if (!globalContextPersistence) {
662
- globalContextPersistence = new ContextPersistence(dbPath);
663
- }
664
- return globalContextPersistence;
665
- }
666
-
667
- export { ContextPersistence, getContextPersistence };