k0ntext 3.2.1 ā 3.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/dist/cli/index.js +28 -2
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/repl/core/parser.d.ts +84 -0
- package/dist/cli/repl/core/parser.d.ts.map +1 -0
- package/dist/cli/repl/core/parser.js +309 -0
- package/dist/cli/repl/core/parser.js.map +1 -0
- package/dist/cli/repl/core/session.d.ts +124 -0
- package/dist/cli/repl/core/session.d.ts.map +1 -0
- package/dist/cli/repl/core/session.js +196 -0
- package/dist/cli/repl/core/session.js.map +1 -0
- package/dist/cli/repl/index.d.ts +56 -0
- package/dist/cli/repl/index.d.ts.map +1 -0
- package/dist/cli/repl/index.js +468 -0
- package/dist/cli/repl/index.js.map +1 -0
- package/dist/cli/repl/init/wizard.d.ts +61 -0
- package/dist/cli/repl/init/wizard.d.ts.map +1 -0
- package/dist/cli/repl/init/wizard.js +245 -0
- package/dist/cli/repl/init/wizard.js.map +1 -0
- package/dist/cli/repl/tui/theme.d.ts +109 -0
- package/dist/cli/repl/tui/theme.d.ts.map +1 -0
- package/dist/cli/repl/tui/theme.js +225 -0
- package/dist/cli/repl/tui/theme.js.map +1 -0
- package/dist/cli/repl/update/checker.d.ts +64 -0
- package/dist/cli/repl/update/checker.d.ts.map +1 -0
- package/dist/cli/repl/update/checker.js +166 -0
- package/dist/cli/repl/update/checker.js.map +1 -0
- package/dist/db/client.d.ts +1 -0
- package/dist/db/client.d.ts.map +1 -1
- package/dist/db/client.js +2 -1
- package/dist/db/client.js.map +1 -1
- package/package.json +4 -1
- package/src/cli/index.ts +28 -2
- package/src/cli/repl/core/parser.ts +373 -0
- package/src/cli/repl/core/session.ts +269 -0
- package/src/cli/repl/index.ts +554 -0
- package/src/cli/repl/init/wizard.ts +300 -0
- package/src/cli/repl/tui/theme.ts +276 -0
- package/src/cli/repl/update/checker.ts +209 -0
- package/src/db/client.ts +9 -7
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Update Checker
|
|
3
|
+
*
|
|
4
|
+
* Checks for new versions of k0ntext and notifies users
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import https from 'https';
|
|
8
|
+
import chalk from 'chalk';
|
|
9
|
+
import { K0NTEXT_THEME } from '../tui/theme.js';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Version comparison result
|
|
13
|
+
*/
|
|
14
|
+
export interface VersionCheckResult {
|
|
15
|
+
current: string;
|
|
16
|
+
latest: string;
|
|
17
|
+
hasUpdate: boolean;
|
|
18
|
+
type: 'major' | 'minor' | 'patch' | 'none';
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Update notification options
|
|
23
|
+
*/
|
|
24
|
+
export interface UpdateNotificationOptions {
|
|
25
|
+
showIfCurrent: boolean;
|
|
26
|
+
checkInterval: number; // milliseconds
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Update Checker
|
|
31
|
+
*/
|
|
32
|
+
export class UpdateChecker {
|
|
33
|
+
private currentVersion: string;
|
|
34
|
+
private lastCheck: number = 0;
|
|
35
|
+
private cachedResult: VersionCheckResult | null = null;
|
|
36
|
+
private checkInterval: number;
|
|
37
|
+
|
|
38
|
+
constructor(currentVersion: string, checkInterval = 24 * 60 * 60 * 1000) {
|
|
39
|
+
this.currentVersion = currentVersion;
|
|
40
|
+
this.checkInterval = checkInterval;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Check for updates (with caching)
|
|
45
|
+
*/
|
|
46
|
+
async check(force = false): Promise<VersionCheckResult> {
|
|
47
|
+
const now = Date.now();
|
|
48
|
+
|
|
49
|
+
// Return cached result if still valid
|
|
50
|
+
if (!force && this.cachedResult && (now - this.lastCheck) < this.checkInterval) {
|
|
51
|
+
return this.cachedResult;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
try {
|
|
55
|
+
const latest = await this.fetchLatestVersion();
|
|
56
|
+
const hasUpdate = this.needsUpdate(this.currentVersion, latest);
|
|
57
|
+
const type = this.getUpdateType(this.currentVersion, latest);
|
|
58
|
+
|
|
59
|
+
const result: VersionCheckResult = {
|
|
60
|
+
current: this.currentVersion,
|
|
61
|
+
latest,
|
|
62
|
+
hasUpdate,
|
|
63
|
+
type
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
this.cachedResult = result;
|
|
67
|
+
this.lastCheck = now;
|
|
68
|
+
|
|
69
|
+
return result;
|
|
70
|
+
} catch (error) {
|
|
71
|
+
// Return current version if check fails
|
|
72
|
+
return {
|
|
73
|
+
current: this.currentVersion,
|
|
74
|
+
latest: this.currentVersion,
|
|
75
|
+
hasUpdate: false,
|
|
76
|
+
type: 'none'
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Fetch latest version from npm registry
|
|
83
|
+
*/
|
|
84
|
+
private async fetchLatestVersion(): Promise<string> {
|
|
85
|
+
return new Promise((resolve, reject) => {
|
|
86
|
+
const options = {
|
|
87
|
+
hostname: 'registry.npmjs.org',
|
|
88
|
+
path: '/k0ntext',
|
|
89
|
+
timeout: 5000
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const req = https.get(options, (res) => {
|
|
93
|
+
let data = '';
|
|
94
|
+
|
|
95
|
+
res.on('data', (chunk) => {
|
|
96
|
+
data += chunk;
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
res.on('end', () => {
|
|
100
|
+
try {
|
|
101
|
+
const pkg = JSON.parse(data);
|
|
102
|
+
const latest = pkg['dist-tags'].latest;
|
|
103
|
+
resolve(latest);
|
|
104
|
+
} catch (e) {
|
|
105
|
+
reject(e);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
req.on('timeout', () => {
|
|
111
|
+
req.destroy();
|
|
112
|
+
reject(new Error('Request timeout'));
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
req.on('error', reject);
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Check if current version needs update
|
|
121
|
+
*/
|
|
122
|
+
private needsUpdate(current: string, latest: string): boolean {
|
|
123
|
+
return current !== latest;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Get update type
|
|
128
|
+
*/
|
|
129
|
+
private getUpdateType(current: string, latest: string): 'major' | 'minor' | 'patch' | 'none' {
|
|
130
|
+
if (current === latest) return 'none';
|
|
131
|
+
|
|
132
|
+
const [cMajor, cMinor, cPatch] = current.split('.').map(Number);
|
|
133
|
+
const [lMajor, lMinor, lPatch] = latest.split('.').map(Number);
|
|
134
|
+
|
|
135
|
+
if (lMajor > cMajor) return 'major';
|
|
136
|
+
if (lMinor > cMinor) return 'minor';
|
|
137
|
+
if (lPatch > cPatch) return 'patch';
|
|
138
|
+
|
|
139
|
+
return 'none';
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Get type emoji
|
|
144
|
+
*/
|
|
145
|
+
private getTypeEmoji(type: 'major' | 'minor' | 'patch' | 'none'): string {
|
|
146
|
+
const emojis = {
|
|
147
|
+
major: 'šØ',
|
|
148
|
+
minor: 'āØ',
|
|
149
|
+
patch: 'š§',
|
|
150
|
+
none: 'ā'
|
|
151
|
+
};
|
|
152
|
+
return emojis[type];
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Format update notification
|
|
157
|
+
*/
|
|
158
|
+
formatNotification(result: VersionCheckResult): string {
|
|
159
|
+
if (!result.hasUpdate) {
|
|
160
|
+
return K0NTEXT_THEME.success('ā You are on the latest version');
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const typeEmoji = this.getTypeEmoji(result.type);
|
|
164
|
+
|
|
165
|
+
const updateMessage = [
|
|
166
|
+
'',
|
|
167
|
+
`${typeEmoji} ${K0NTEXT_THEME.highlight('Update Available')}`,
|
|
168
|
+
'',
|
|
169
|
+
` ${K0NTEXT_THEME.primary('Current:')} ${result.current}`,
|
|
170
|
+
` ${K0NTEXT_THEME.success('Latest:')} ${result.latest}`,
|
|
171
|
+
'',
|
|
172
|
+
` Run ${K0NTEXT_THEME.highlight('npm update -g k0ntext')} to update`,
|
|
173
|
+
''
|
|
174
|
+
];
|
|
175
|
+
|
|
176
|
+
return updateMessage.join('\n');
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Show notification if update available
|
|
181
|
+
*/
|
|
182
|
+
async showNotification(options: UpdateNotificationOptions = { showIfCurrent: false, checkInterval: 24 * 60 * 60 * 1000 }): Promise<void> {
|
|
183
|
+
const { showIfCurrent = false } = options;
|
|
184
|
+
|
|
185
|
+
const result = await this.check();
|
|
186
|
+
|
|
187
|
+
if (result.hasUpdate) {
|
|
188
|
+
console.log(this.formatNotification(result));
|
|
189
|
+
} else if (showIfCurrent) {
|
|
190
|
+
console.log(K0NTEXT_THEME.success('\nā K0ntext is up to date'));
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Check and prompt for update
|
|
196
|
+
*/
|
|
197
|
+
async checkAndPrompt(): Promise<boolean> {
|
|
198
|
+
const result = await this.check();
|
|
199
|
+
|
|
200
|
+
if (!result.hasUpdate) {
|
|
201
|
+
return false;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
console.log('');
|
|
205
|
+
console.log(this.formatNotification(result));
|
|
206
|
+
|
|
207
|
+
return true;
|
|
208
|
+
}
|
|
209
|
+
}
|
package/src/db/client.ts
CHANGED
|
@@ -859,31 +859,33 @@ export class DatabaseClient {
|
|
|
859
859
|
/**
|
|
860
860
|
* Get database statistics
|
|
861
861
|
*/
|
|
862
|
-
getStats(): {
|
|
863
|
-
items: number;
|
|
864
|
-
relations: number;
|
|
865
|
-
commits: number;
|
|
862
|
+
getStats(): {
|
|
863
|
+
items: number;
|
|
864
|
+
relations: number;
|
|
865
|
+
commits: number;
|
|
866
866
|
embeddings: number;
|
|
867
867
|
toolConfigs: number;
|
|
868
|
+
path: string;
|
|
868
869
|
} {
|
|
869
870
|
const itemCount = (this.db.prepare('SELECT COUNT(*) as count FROM context_items').get() as { count: number }).count;
|
|
870
871
|
const relationCount = (this.db.prepare('SELECT COUNT(*) as count FROM knowledge_graph').get() as { count: number }).count;
|
|
871
872
|
const commitCount = (this.db.prepare('SELECT COUNT(*) as count FROM git_commits').get() as { count: number }).count;
|
|
872
873
|
const toolConfigCount = (this.db.prepare('SELECT COUNT(*) as count FROM ai_tool_configs').get() as { count: number }).count;
|
|
873
|
-
|
|
874
|
+
|
|
874
875
|
let embeddingCount = 0;
|
|
875
876
|
try {
|
|
876
877
|
embeddingCount = (this.db.prepare('SELECT COUNT(*) as count FROM embeddings').get() as { count: number }).count;
|
|
877
878
|
} catch {
|
|
878
879
|
// Vector table might not exist yet
|
|
879
880
|
}
|
|
880
|
-
|
|
881
|
+
|
|
881
882
|
return {
|
|
882
883
|
items: itemCount,
|
|
883
884
|
relations: relationCount,
|
|
884
885
|
commits: commitCount,
|
|
885
886
|
embeddings: embeddingCount,
|
|
886
|
-
toolConfigs: toolConfigCount
|
|
887
|
+
toolConfigs: toolConfigCount,
|
|
888
|
+
path: this.dbPath
|
|
887
889
|
};
|
|
888
890
|
}
|
|
889
891
|
|