k0ntext 3.3.1 → 3.6.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.
Files changed (221) hide show
  1. package/README.md +225 -26
  2. package/dist/agents/cleanup-agent.d.ts.map +1 -1
  3. package/dist/agents/cleanup-agent.js +18 -6
  4. package/dist/agents/cleanup-agent.js.map +1 -1
  5. package/dist/agents/drift-agent.d.ts +7 -0
  6. package/dist/agents/drift-agent.d.ts.map +1 -1
  7. package/dist/agents/drift-agent.js +29 -8
  8. package/dist/agents/drift-agent.js.map +1 -1
  9. package/dist/cli/commands/cleanup.d.ts.map +1 -1
  10. package/dist/cli/commands/cleanup.js +8 -1
  11. package/dist/cli/commands/cleanup.js.map +1 -1
  12. package/dist/cli/commands/drift-detect.d.ts.map +1 -1
  13. package/dist/cli/commands/drift-detect.js +21 -1
  14. package/dist/cli/commands/drift-detect.js.map +1 -1
  15. package/dist/cli/commands/embeddings-refresh.d.ts +11 -0
  16. package/dist/cli/commands/embeddings-refresh.d.ts.map +1 -0
  17. package/dist/cli/commands/embeddings-refresh.js +114 -0
  18. package/dist/cli/commands/embeddings-refresh.js.map +1 -0
  19. package/dist/cli/commands/migrate.d.ts +11 -0
  20. package/dist/cli/commands/migrate.d.ts.map +1 -0
  21. package/dist/cli/commands/migrate.js +195 -0
  22. package/dist/cli/commands/migrate.js.map +1 -0
  23. package/dist/cli/commands/restore.d.ts +12 -0
  24. package/dist/cli/commands/restore.d.ts.map +1 -0
  25. package/dist/cli/commands/restore.js +261 -0
  26. package/dist/cli/commands/restore.js.map +1 -0
  27. package/dist/cli/commands/sync-templates.d.ts +15 -0
  28. package/dist/cli/commands/sync-templates.d.ts.map +1 -0
  29. package/dist/cli/commands/sync-templates.js +181 -0
  30. package/dist/cli/commands/sync-templates.js.map +1 -0
  31. package/dist/cli/commands/version-check.d.ts +12 -0
  32. package/dist/cli/commands/version-check.d.ts.map +1 -0
  33. package/dist/cli/commands/version-check.js +133 -0
  34. package/dist/cli/commands/version-check.js.map +1 -0
  35. package/dist/cli/generate.d.ts +5 -0
  36. package/dist/cli/generate.d.ts.map +1 -1
  37. package/dist/cli/generate.js +80 -16
  38. package/dist/cli/generate.js.map +1 -1
  39. package/dist/cli/index.js +215 -1
  40. package/dist/cli/index.js.map +1 -1
  41. package/dist/cli/repl/index.d.ts +1 -0
  42. package/dist/cli/repl/index.d.ts.map +1 -1
  43. package/dist/cli/repl/index.js +18 -6
  44. package/dist/cli/repl/index.js.map +1 -1
  45. package/dist/cli/utils/backup-manager.d.ts +94 -0
  46. package/dist/cli/utils/backup-manager.d.ts.map +1 -0
  47. package/dist/cli/utils/backup-manager.js +230 -0
  48. package/dist/cli/utils/backup-manager.js.map +1 -0
  49. package/dist/cli/utils/db-backup-manager.d.ts +55 -0
  50. package/dist/cli/utils/db-backup-manager.d.ts.map +1 -0
  51. package/dist/cli/utils/db-backup-manager.js +115 -0
  52. package/dist/cli/utils/db-backup-manager.js.map +1 -0
  53. package/dist/cli/utils/file-detector.d.ts +87 -0
  54. package/dist/cli/utils/file-detector.d.ts.map +1 -0
  55. package/dist/cli/utils/file-detector.js +131 -0
  56. package/dist/cli/utils/file-detector.js.map +1 -0
  57. package/dist/cli/utils/index.d.ts +9 -0
  58. package/dist/cli/utils/index.d.ts.map +1 -0
  59. package/dist/cli/utils/index.js +9 -0
  60. package/dist/cli/utils/index.js.map +1 -0
  61. package/dist/cli/utils/modification-prompt.d.ts +41 -0
  62. package/dist/cli/utils/modification-prompt.d.ts.map +1 -0
  63. package/dist/cli/utils/modification-prompt.js +84 -0
  64. package/dist/cli/utils/modification-prompt.js.map +1 -0
  65. package/dist/cli/version/checker.d.ts +47 -0
  66. package/dist/cli/version/checker.d.ts.map +1 -0
  67. package/dist/cli/version/checker.js +143 -0
  68. package/dist/cli/version/checker.js.map +1 -0
  69. package/dist/cli/version/comparator.d.ts +46 -0
  70. package/dist/cli/version/comparator.d.ts.map +1 -0
  71. package/dist/cli/version/comparator.js +99 -0
  72. package/dist/cli/version/comparator.js.map +1 -0
  73. package/dist/cli/version/index.d.ts +11 -0
  74. package/dist/cli/version/index.d.ts.map +1 -0
  75. package/dist/cli/version/index.js +11 -0
  76. package/dist/cli/version/index.js.map +1 -0
  77. package/dist/cli/version/parser.d.ts +38 -0
  78. package/dist/cli/version/parser.d.ts.map +1 -0
  79. package/dist/cli/version/parser.js +90 -0
  80. package/dist/cli/version/parser.js.map +1 -0
  81. package/dist/cli/version/prompt.d.ts +40 -0
  82. package/dist/cli/version/prompt.d.ts.map +1 -0
  83. package/dist/cli/version/prompt.js +162 -0
  84. package/dist/cli/version/prompt.js.map +1 -0
  85. package/dist/cli/version/types.d.ts +89 -0
  86. package/dist/cli/version/types.d.ts.map +1 -0
  87. package/dist/cli/version/types.js +7 -0
  88. package/dist/cli/version/types.js.map +1 -0
  89. package/dist/db/client.d.ts +79 -4
  90. package/dist/db/client.d.ts.map +1 -1
  91. package/dist/db/client.js +207 -12
  92. package/dist/db/client.js.map +1 -1
  93. package/dist/db/migrations/files/0014_add_schema_migrations_table.d.ts +14 -0
  94. package/dist/db/migrations/files/0014_add_schema_migrations_table.d.ts.map +1 -0
  95. package/dist/db/migrations/files/0014_add_schema_migrations_table.js +25 -0
  96. package/dist/db/migrations/files/0014_add_schema_migrations_table.js.map +1 -0
  97. package/dist/db/migrations/index.d.ts +9 -0
  98. package/dist/db/migrations/index.d.ts.map +1 -0
  99. package/dist/db/migrations/index.js +9 -0
  100. package/dist/db/migrations/index.js.map +1 -0
  101. package/dist/db/migrations/loader.d.ts +27 -0
  102. package/dist/db/migrations/loader.d.ts.map +1 -0
  103. package/dist/db/migrations/loader.js +106 -0
  104. package/dist/db/migrations/loader.js.map +1 -0
  105. package/dist/db/migrations/runner.d.ts +56 -0
  106. package/dist/db/migrations/runner.d.ts.map +1 -0
  107. package/dist/db/migrations/runner.js +266 -0
  108. package/dist/db/migrations/runner.js.map +1 -0
  109. package/dist/db/migrations/types.d.ts +71 -0
  110. package/dist/db/migrations/types.d.ts.map +1 -0
  111. package/dist/db/migrations/types.js +7 -0
  112. package/dist/db/migrations/types.js.map +1 -0
  113. package/dist/db/schema.d.ts +41 -2
  114. package/dist/db/schema.d.ts.map +1 -1
  115. package/dist/db/schema.js +77 -2
  116. package/dist/db/schema.js.map +1 -1
  117. package/dist/mcp.js +2 -2
  118. package/dist/mcp.js.map +1 -1
  119. package/dist/template-engine/data-transformer.d.ts +17 -0
  120. package/dist/template-engine/data-transformer.d.ts.map +1 -0
  121. package/dist/template-engine/data-transformer.js +343 -0
  122. package/dist/template-engine/data-transformer.js.map +1 -0
  123. package/dist/template-engine/engine.d.ts +74 -0
  124. package/dist/template-engine/engine.d.ts.map +1 -0
  125. package/dist/template-engine/engine.js +183 -0
  126. package/dist/template-engine/engine.js.map +1 -0
  127. package/dist/template-engine/helpers.d.ts +81 -0
  128. package/dist/template-engine/helpers.d.ts.map +1 -0
  129. package/dist/template-engine/helpers.js +153 -0
  130. package/dist/template-engine/helpers.js.map +1 -0
  131. package/dist/template-engine/index.d.ts +10 -0
  132. package/dist/template-engine/index.d.ts.map +1 -0
  133. package/dist/template-engine/index.js +10 -0
  134. package/dist/template-engine/index.js.map +1 -0
  135. package/dist/template-engine/types.d.ts +147 -0
  136. package/dist/template-engine/types.d.ts.map +1 -0
  137. package/dist/template-engine/types.js +7 -0
  138. package/dist/template-engine/types.js.map +1 -0
  139. package/dist/template-sync/comparator.d.ts +138 -0
  140. package/dist/template-sync/comparator.d.ts.map +1 -0
  141. package/dist/template-sync/comparator.js +353 -0
  142. package/dist/template-sync/comparator.js.map +1 -0
  143. package/dist/template-sync/conflict-resolver.d.ts +112 -0
  144. package/dist/template-sync/conflict-resolver.d.ts.map +1 -0
  145. package/dist/template-sync/conflict-resolver.js +328 -0
  146. package/dist/template-sync/conflict-resolver.js.map +1 -0
  147. package/dist/template-sync/engine.d.ts +93 -0
  148. package/dist/template-sync/engine.d.ts.map +1 -0
  149. package/dist/template-sync/engine.js +350 -0
  150. package/dist/template-sync/engine.js.map +1 -0
  151. package/dist/template-sync/hasher.d.ts +67 -0
  152. package/dist/template-sync/hasher.d.ts.map +1 -0
  153. package/dist/template-sync/hasher.js +94 -0
  154. package/dist/template-sync/hasher.js.map +1 -0
  155. package/dist/template-sync/index.d.ts +20 -0
  156. package/dist/template-sync/index.d.ts.map +1 -0
  157. package/dist/template-sync/index.js +14 -0
  158. package/dist/template-sync/index.js.map +1 -0
  159. package/dist/template-sync/manifest.d.ts +131 -0
  160. package/dist/template-sync/manifest.d.ts.map +1 -0
  161. package/dist/template-sync/manifest.js +309 -0
  162. package/dist/template-sync/manifest.js.map +1 -0
  163. package/dist/template-sync/merger.d.ts +125 -0
  164. package/dist/template-sync/merger.d.ts.map +1 -0
  165. package/dist/template-sync/merger.js +371 -0
  166. package/dist/template-sync/merger.js.map +1 -0
  167. package/dist/template-sync/scanner.d.ts +106 -0
  168. package/dist/template-sync/scanner.d.ts.map +1 -0
  169. package/dist/template-sync/scanner.js +196 -0
  170. package/dist/template-sync/scanner.js.map +1 -0
  171. package/dist/template-sync/types.d.ts +199 -0
  172. package/dist/template-sync/types.d.ts.map +1 -0
  173. package/dist/template-sync/types.js +30 -0
  174. package/dist/template-sync/types.js.map +1 -0
  175. package/package.json +2 -1
  176. package/src/agents/cleanup-agent.ts +21 -6
  177. package/src/agents/drift-agent.ts +31 -8
  178. package/src/cli/commands/cleanup.ts +9 -1
  179. package/src/cli/commands/drift-detect.ts +24 -1
  180. package/src/cli/commands/embeddings-refresh.ts +135 -0
  181. package/src/cli/commands/migrate.ts +231 -0
  182. package/src/cli/commands/restore.ts +318 -0
  183. package/src/cli/commands/sync-templates.ts +210 -0
  184. package/src/cli/commands/version-check.ts +158 -0
  185. package/src/cli/generate.ts +99 -17
  186. package/src/cli/index.ts +246 -1
  187. package/src/cli/repl/index.ts +16 -6
  188. package/src/cli/utils/backup-manager.ts +275 -0
  189. package/src/cli/utils/db-backup-manager.ts +146 -0
  190. package/src/cli/utils/file-detector.ts +181 -0
  191. package/src/cli/utils/index.ts +9 -0
  192. package/src/cli/utils/modification-prompt.ts +112 -0
  193. package/src/cli/version/checker.ts +172 -0
  194. package/src/cli/version/comparator.ts +106 -0
  195. package/src/cli/version/index.ts +11 -0
  196. package/src/cli/version/parser.ts +101 -0
  197. package/src/cli/version/prompt.ts +208 -0
  198. package/src/cli/version/types.ts +95 -0
  199. package/src/db/client.ts +285 -18
  200. package/src/db/migrations/files/0014_add_schema_migrations_table.sql +19 -0
  201. package/src/db/migrations/files/0014_add_schema_migrations_table.ts +30 -0
  202. package/src/db/migrations/index.ts +9 -0
  203. package/src/db/migrations/loader.ts +129 -0
  204. package/src/db/migrations/runner.ts +316 -0
  205. package/src/db/migrations/types.ts +71 -0
  206. package/src/db/schema.ts +109 -2
  207. package/src/mcp.ts +2 -2
  208. package/src/template-engine/data-transformer.ts +367 -0
  209. package/src/template-engine/engine.ts +213 -0
  210. package/src/template-engine/helpers.ts +163 -0
  211. package/src/template-engine/index.ts +10 -0
  212. package/src/template-engine/types.ts +158 -0
  213. package/src/template-sync/comparator.ts +452 -0
  214. package/src/template-sync/conflict-resolver.ts +401 -0
  215. package/src/template-sync/engine.ts +417 -0
  216. package/src/template-sync/hasher.ts +104 -0
  217. package/src/template-sync/index.ts +60 -0
  218. package/src/template-sync/manifest.ts +358 -0
  219. package/src/template-sync/merger.ts +454 -0
  220. package/src/template-sync/scanner.ts +254 -0
  221. package/src/template-sync/types.ts +247 -0
@@ -0,0 +1,247 @@
1
+ /**
2
+ * Template Sync Types
3
+ *
4
+ * All type definitions for the template sync system.
5
+ */
6
+
7
+ /**
8
+ * Template file metadata
9
+ */
10
+ export interface TemplateFile {
11
+ /** Relative path from .claude/ or templates/base/.claude/ */
12
+ relativePath: string;
13
+ /** Content hash (SHA-256, 16 chars) */
14
+ hash: string;
15
+ /** File size in bytes */
16
+ size: number;
17
+ /** Last modified time */
18
+ mtime: Date;
19
+ }
20
+
21
+ /**
22
+ * Template manifest structure (stored in DB and .claude/.k0ntext-manifest.json)
23
+ */
24
+ export interface TemplateManifest {
25
+ /** k0ntext version that generated this manifest */
26
+ k0ntextVersion: string;
27
+ /** Template source version */
28
+ templateVersion: string;
29
+ /** Timestamp when manifest was created */
30
+ createdAt: string;
31
+ /** Timestamp when manifest was last updated */
32
+ updatedAt?: string;
33
+ /** All tracked template files keyed by relative path */
34
+ files: Record<string, TemplateFileEntry>;
35
+ }
36
+
37
+ /**
38
+ * Single file entry in manifest
39
+ */
40
+ export interface TemplateFileEntry {
41
+ /** Content hash */
42
+ hash: string;
43
+ /** Template version when file was last updated */
44
+ templateVersion: string;
45
+ /** Whether user has modified this file */
46
+ userModified: boolean;
47
+ /** Last sync timestamp */
48
+ lastSyncedAt?: string;
49
+ /** Original template hash (before user modification) */
50
+ originalHash?: string;
51
+ }
52
+
53
+ /**
54
+ * Comparison result for a single file
55
+ */
56
+ export interface FileComparison {
57
+ /** Relative path from .claude/ */
58
+ path: string;
59
+ /** Current state */
60
+ state: FileState;
61
+ /** Template hash (from package) */
62
+ templateHash: string;
63
+ /** Local hash (from .claude/) */
64
+ localHash: string;
65
+ /** Whether user has modified (from manifest) */
66
+ userModified: boolean;
67
+ /** Original template hash (if user modified) */
68
+ originalHash?: string;
69
+ }
70
+
71
+ /**
72
+ * File state after comparison
73
+ */
74
+ export type FileState =
75
+ | 'identical' // File matches template exactly
76
+ | 'safe-update' // Template changed, file not modified by user
77
+ | 'conflict' // Template changed AND user modified file
78
+ | 'new' // File exists in template but not locally
79
+ | 'deleted' // File exists locally but not in template (user-added)
80
+ | 'user-only'; // User-only file, not in template
81
+
82
+ /**
83
+ * Sync operation result
84
+ */
85
+ export interface SyncResult {
86
+ /** Total files processed */
87
+ total: number;
88
+ /** Files updated (safe merge) */
89
+ updated: number;
90
+ /** Files skipped (user modified/conflict) */
91
+ skipped: string[];
92
+ /** New files created */
93
+ created: number;
94
+ /** Files in conflict requiring resolution */
95
+ conflicts: FileComparison[];
96
+ /** User-only files (deleted from template) */
97
+ userOnly: string[];
98
+ /** Duration in milliseconds */
99
+ durationMs: number;
100
+ /** Whether this was a dry run */
101
+ dryRun?: boolean;
102
+ }
103
+
104
+ /**
105
+ * Sync options
106
+ */
107
+ export interface SyncOptions {
108
+ /** Dry run - don't make changes */
109
+ dryRun?: boolean;
110
+ /** Force update all files (skip prompts, overwrite user modifications) */
111
+ force?: boolean;
112
+ /** Specific subdirectories to sync */
113
+ subdirectories?: TemplateSubdir[];
114
+ /** Verbose output */
115
+ verbose?: boolean;
116
+ /** Whether to archive removed files */
117
+ archiveRemoved?: boolean;
118
+ }
119
+
120
+ /**
121
+ * Template subdirectories (synced from package)
122
+ */
123
+ export type TemplateSubdir =
124
+ | 'commands'
125
+ | 'agents'
126
+ | 'schemas'
127
+ | 'standards'
128
+ | 'tools'
129
+ | 'automation';
130
+
131
+ /**
132
+ * Excluded subdirectories (user-specific, not synced)
133
+ */
134
+ export type ExcludedSubdir = 'context' | 'indexes';
135
+
136
+ /**
137
+ * Template source configuration
138
+ */
139
+ export interface TemplateSource {
140
+ /** Root path to templates (e.g., templates/base/.claude/) */
141
+ rootPath: string;
142
+ /** Subdirectories to sync */
143
+ subdirectories: TemplateSubdir[];
144
+ }
145
+
146
+ /**
147
+ * Merge result for a single file
148
+ */
149
+ export interface MergeResult {
150
+ /** File path */
151
+ path: string;
152
+ /** Whether merge was successful */
153
+ success: boolean;
154
+ /** Merge method used */
155
+ method: MergeMethod;
156
+ /** Diff if available */
157
+ diff?: string;
158
+ /** Error message if failed */
159
+ error?: string;
160
+ }
161
+
162
+ /**
163
+ * Merge method used
164
+ */
165
+ export type MergeMethod =
166
+ | 'auto-safe' // Automatic safe update (no user changes)
167
+ | 'auto-create' // Automatic new file creation
168
+ | 'overwrite' // Forced overwrite (user confirmed or --force)
169
+ | 'skip' // Skipped (user chose to keep local)
170
+ | 'conflict'; // Conflict detected, requires resolution
171
+
172
+ /**
173
+ * Resolution choice for conflicts
174
+ */
175
+ export type ResolutionChoice = 'skip' | 'overwrite' | 'keep-local' | 'show-diff';
176
+
177
+ /**
178
+ * Resolution result for a single conflict
179
+ */
180
+ export interface ResolutionResult {
181
+ /** File path */
182
+ path: string;
183
+ /** User's choice */
184
+ choice: ResolutionChoice;
185
+ }
186
+
187
+ /**
188
+ * Archive result for removed files
189
+ */
190
+ export interface ArchiveResult {
191
+ /** Files that were archived */
192
+ archived: string[];
193
+ /** Archive path */
194
+ archivePath: string;
195
+ }
196
+
197
+ /**
198
+ * Template file record from database
199
+ */
200
+ export interface TemplateFileRecord {
201
+ id: string;
202
+ relativePath: string;
203
+ templateHash: string;
204
+ templateVersion: string;
205
+ userModified: boolean;
206
+ lastSyncedAt?: string;
207
+ syncedAt: string;
208
+ metadata?: Record<string, unknown>;
209
+ }
210
+
211
+ /**
212
+ * Template manifest record from database
213
+ */
214
+ export interface TemplateManifestRecord {
215
+ id: string;
216
+ k0ntextVersion: string;
217
+ templateVersion: string;
218
+ manifest: string;
219
+ createdAt: string;
220
+ }
221
+
222
+ /**
223
+ * All template subdirectories
224
+ */
225
+ export const TEMPLATE_SUBDIRS: TemplateSubdir[] = [
226
+ 'commands',
227
+ 'agents',
228
+ 'schemas',
229
+ 'standards',
230
+ 'tools',
231
+ 'automation'
232
+ ];
233
+
234
+ /**
235
+ * All excluded subdirectories
236
+ */
237
+ export const EXCLUDED_SUBDIRS: ExcludedSubdir[] = ['context', 'indexes'];
238
+
239
+ /**
240
+ * Default sync options
241
+ */
242
+ export const DEFAULT_SYNC_OPTIONS: SyncOptions = {
243
+ dryRun: false,
244
+ force: false,
245
+ verbose: false,
246
+ archiveRemoved: true
247
+ };