kontexted 0.1.13 → 0.1.14
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.
|
@@ -6,6 +6,7 @@ import { ApiClient } from "../../lib/api-client.js";
|
|
|
6
6
|
import { sha256 } from "../../lib/sync/crypto.js";
|
|
7
7
|
import { updateGitignore, formatMarkdown, ensureDirectoryExists } from "../../lib/sync/utils.js";
|
|
8
8
|
import { logDebug } from "../../lib/logger.js";
|
|
9
|
+
import Database from "better-sqlite3";
|
|
9
10
|
// ============ Yargs Command Module ============
|
|
10
11
|
export const command = "init";
|
|
11
12
|
export const desc = "Initialize sync in current directory";
|
|
@@ -80,7 +81,7 @@ export const handler = async (argv) => {
|
|
|
80
81
|
await ensureDirectoryExists(conflictsDir);
|
|
81
82
|
// Step 5: Initialize SQLite queue database
|
|
82
83
|
console.log("Initializing queue database...");
|
|
83
|
-
|
|
84
|
+
initializeQueueDatabase(queueDbPath);
|
|
84
85
|
// Step 6: Create API client and fetch workspace data
|
|
85
86
|
console.log("Fetching workspace data from server...");
|
|
86
87
|
const apiClient = new ApiClient(profile.serverUrl, profile.oauth, async () => {
|
|
@@ -211,9 +212,7 @@ export const handler = async (argv) => {
|
|
|
211
212
|
/**
|
|
212
213
|
* Initialize the SQLite queue database with the pending_changes table.
|
|
213
214
|
*/
|
|
214
|
-
|
|
215
|
-
// Use Bun's SQLite driver
|
|
216
|
-
const { Database } = await import("bun:sqlite");
|
|
215
|
+
function initializeQueueDatabase(dbPath) {
|
|
217
216
|
// Create database (this will also create the file)
|
|
218
217
|
const db = new Database(dbPath);
|
|
219
218
|
// Create pending_changes table
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import Database from "better-sqlite3";
|
|
2
2
|
import fs from "node:fs/promises";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { findSyncDir, loadSyncConfig, loadSyncState, isDaemonRunning, isPaused, } from "../../lib/sync/command-utils.js";
|
|
@@ -9,7 +9,9 @@ function countPendingChanges(syncDir) {
|
|
|
9
9
|
const queuePath = path.join(syncDir, ".sync", "queue.db");
|
|
10
10
|
try {
|
|
11
11
|
const db = new Database(queuePath, { readonly: true });
|
|
12
|
-
const result = db
|
|
12
|
+
const result = db
|
|
13
|
+
.prepare("SELECT COUNT(*) as count FROM pending_changes")
|
|
14
|
+
.get();
|
|
13
15
|
db.close();
|
|
14
16
|
return result?.count ?? 0;
|
|
15
17
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import fs from "node:fs/promises";
|
|
2
2
|
import path from "node:path";
|
|
3
|
+
import { spawn } from "node:child_process";
|
|
3
4
|
import { profileExists, getProfile } from "../../lib/profile.js";
|
|
4
5
|
/**
|
|
5
6
|
* Centralized utilities for sync command operations
|
|
@@ -194,11 +195,9 @@ export async function daemonize(syncDir) {
|
|
|
194
195
|
await logFile.write(`[${timestamp}] === Daemon starting ===\n`);
|
|
195
196
|
// Spawn child process with detached: true
|
|
196
197
|
// The child will have SYNC_DAEMON_CHILD=1 in its environment
|
|
197
|
-
const child =
|
|
198
|
+
const child = spawn(process.argv[0], process.argv.slice(1), {
|
|
198
199
|
detached: true,
|
|
199
|
-
|
|
200
|
-
stdout: logFile.fd,
|
|
201
|
-
stderr: logFile.fd,
|
|
200
|
+
stdio: ["ignore", logFile.fd, logFile.fd],
|
|
202
201
|
env: {
|
|
203
202
|
...process.env,
|
|
204
203
|
SYNC_DAEMON_CHILD: "1",
|
package/dist/lib/sync/queue.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Queue management for pending file changes
|
|
3
3
|
* @packageDocumentation
|
|
4
4
|
*/
|
|
5
|
-
import
|
|
5
|
+
import Database from "better-sqlite3";
|
|
6
6
|
/**
|
|
7
7
|
* Queue for managing pending file changes to be synced
|
|
8
8
|
*/
|
|
@@ -13,7 +13,7 @@ export class Queue {
|
|
|
13
13
|
this.init();
|
|
14
14
|
}
|
|
15
15
|
init() {
|
|
16
|
-
this.db.
|
|
16
|
+
this.db.exec(`
|
|
17
17
|
CREATE TABLE IF NOT EXISTS pending_changes (
|
|
18
18
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
19
19
|
file_path TEXT NOT NULL,
|
|
@@ -42,7 +42,7 @@ export class Queue {
|
|
|
42
42
|
* @returns Array of pending changes ordered by detection time
|
|
43
43
|
*/
|
|
44
44
|
getAll() {
|
|
45
|
-
return this.db.
|
|
45
|
+
return this.db.prepare(`
|
|
46
46
|
SELECT
|
|
47
47
|
id,
|
|
48
48
|
file_path AS filePath,
|
|
@@ -60,7 +60,7 @@ export class Queue {
|
|
|
60
60
|
* @param id - The ID of the pending change to remove
|
|
61
61
|
*/
|
|
62
62
|
remove(id) {
|
|
63
|
-
this.db.
|
|
63
|
+
this.db.prepare(`DELETE FROM pending_changes WHERE id = ?`).run(id);
|
|
64
64
|
}
|
|
65
65
|
/**
|
|
66
66
|
* Increment the retry count for a pending change and record the error
|
|
@@ -68,14 +68,14 @@ export class Queue {
|
|
|
68
68
|
* @param error - The error message to record
|
|
69
69
|
*/
|
|
70
70
|
incrementRetry(id, error) {
|
|
71
|
-
this.db.
|
|
71
|
+
this.db.prepare(`UPDATE pending_changes SET retry_count = retry_count + 1, last_error = ? WHERE id = ?`).run(error, id);
|
|
72
72
|
}
|
|
73
73
|
/**
|
|
74
74
|
* Get the count of pending changes in the queue
|
|
75
75
|
* @returns Number of pending changes
|
|
76
76
|
*/
|
|
77
77
|
getCount() {
|
|
78
|
-
const result = this.db.
|
|
78
|
+
const result = this.db.prepare(`SELECT COUNT(*) as count FROM pending_changes`).get();
|
|
79
79
|
return result?.count ?? 0;
|
|
80
80
|
}
|
|
81
81
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kontexted",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.14",
|
|
4
4
|
"description": "CLI tool for Kontexted - MCP proxy, workspaces management, and local server",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@modelcontextprotocol/sdk": "^1.25.3",
|
|
33
|
+
"better-sqlite3": "^11.0.0",
|
|
33
34
|
"chokidar": "^5.0.0",
|
|
34
35
|
"commander": "^12.1.0",
|
|
35
36
|
"eventsource": "^4.1.0",
|
|
@@ -37,6 +38,7 @@
|
|
|
37
38
|
"zod": "^3.23.8"
|
|
38
39
|
},
|
|
39
40
|
"devDependencies": {
|
|
41
|
+
"@types/better-sqlite3": "^7.6.11",
|
|
40
42
|
"@types/node": "^20.0.0",
|
|
41
43
|
"@types/yargs": "^17.0.35",
|
|
42
44
|
"bun-types": "^1.3.9",
|
|
@@ -46,8 +48,8 @@
|
|
|
46
48
|
"typescript": "^5.6.0"
|
|
47
49
|
},
|
|
48
50
|
"optionalDependencies": {
|
|
49
|
-
"@kontexted/darwin-arm64": "0.1.
|
|
50
|
-
"@kontexted/linux-x64": "0.1.
|
|
51
|
-
"@kontexted/windows-x64": "0.1.
|
|
51
|
+
"@kontexted/darwin-arm64": "0.1.14",
|
|
52
|
+
"@kontexted/linux-x64": "0.1.14",
|
|
53
|
+
"@kontexted/windows-x64": "0.1.14"
|
|
52
54
|
}
|
|
53
55
|
}
|