kodingo-cli 1.0.4 → 1.0.6
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.js +17 -1
- package/dist/commands/capture.js +13 -2
- package/dist/commands/explain-symbol.js +7 -2
- package/dist/commands/sync.js +36 -0
- package/dist/commands/update.js +35 -0
- package/dist/utils/offline-queue.js +66 -0
- package/package.json +2 -2
package/dist/cli.js
CHANGED
|
@@ -14,10 +14,26 @@ const deny_1 = require("./commands/deny");
|
|
|
14
14
|
const scan_git_1 = require("./commands/scan-git");
|
|
15
15
|
const init_1 = require("./commands/init");
|
|
16
16
|
const install_hook_1 = require("./commands/install-hook");
|
|
17
|
+
const update_1 = require("./commands/update");
|
|
18
|
+
const sync_1 = require("./commands/sync");
|
|
17
19
|
const program = new commander_1.Command();
|
|
18
|
-
program.name("kodingo").description("Kodingo CLI").version("1.0.
|
|
20
|
+
program.name("kodingo").description("Kodingo CLI").version("1.0.4");
|
|
19
21
|
// ── init ──────────────────────────────────────────────────────────────────────
|
|
20
22
|
(0, init_1.registerInitCommand)(program);
|
|
23
|
+
// ── update ────────────────────────────────────────────────────────────────────
|
|
24
|
+
program
|
|
25
|
+
.command("update")
|
|
26
|
+
.description("Update kodingo-cli to the latest version")
|
|
27
|
+
.action(async () => {
|
|
28
|
+
await (0, update_1.updateCommand)();
|
|
29
|
+
});
|
|
30
|
+
// ── sync ──────────────────────────────────────────────────────────────────────
|
|
31
|
+
program
|
|
32
|
+
.command("sync")
|
|
33
|
+
.description("Sync queued offline captures to the cloud")
|
|
34
|
+
.action(async () => {
|
|
35
|
+
await (0, sync_1.syncCommand)();
|
|
36
|
+
});
|
|
21
37
|
// ── capture ───────────────────────────────────────────────────────────────────
|
|
22
38
|
program
|
|
23
39
|
.command("capture")
|
package/dist/commands/capture.js
CHANGED
|
@@ -7,6 +7,7 @@ exports.captureCommand = captureCommand;
|
|
|
7
7
|
const fs_1 = __importDefault(require("fs"));
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
9
|
const persistence_config_1 = require("../utils/persistence-config");
|
|
10
|
+
const offline_queue_1 = require("../utils/offline-queue");
|
|
10
11
|
async function captureCommand(options) {
|
|
11
12
|
const { initDb, saveMemory } = (0, persistence_config_1.getPersistence)();
|
|
12
13
|
await initDb();
|
|
@@ -25,8 +26,18 @@ async function captureCommand(options) {
|
|
|
25
26
|
input.title = options.title;
|
|
26
27
|
if (tags)
|
|
27
28
|
input.tags = tags;
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
try {
|
|
30
|
+
const record = await saveMemory(input);
|
|
31
|
+
console.log(`Saved memory: ${record.id} (type=${record.type})`);
|
|
32
|
+
}
|
|
33
|
+
catch (err) {
|
|
34
|
+
if ((0, offline_queue_1.isNetworkError)(err)) {
|
|
35
|
+
(0, offline_queue_1.enqueue)(input);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
throw err;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
30
41
|
}
|
|
31
42
|
function parseTags(tags) {
|
|
32
43
|
if (!tags)
|
|
@@ -85,6 +85,11 @@ function findRepoRoot(startPath) {
|
|
|
85
85
|
function testKodingoSaveWatcher() {
|
|
86
86
|
return false;
|
|
87
87
|
}
|
|
88
|
-
function
|
|
89
|
-
|
|
88
|
+
async function validateTokenExpiry(token, maxAgeMs) {
|
|
89
|
+
const parts = token.split('.');
|
|
90
|
+
if (parts.length !== 3)
|
|
91
|
+
return false;
|
|
92
|
+
const payload = JSON.parse(Buffer.from(parts[1], 'base64').toString());
|
|
93
|
+
const issuedAt = payload.iat * 1000;
|
|
94
|
+
return Date.now() - issuedAt < maxAgeMs;
|
|
90
95
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.syncCommand = syncCommand;
|
|
4
|
+
const persistence_config_1 = require("../utils/persistence-config");
|
|
5
|
+
const offline_queue_1 = require("../utils/offline-queue");
|
|
6
|
+
async function syncCommand() {
|
|
7
|
+
const queue = (0, offline_queue_1.readQueue)();
|
|
8
|
+
if (queue.length === 0) {
|
|
9
|
+
console.log("Queue is empty — nothing to sync.");
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
console.log(`Syncing ${queue.length} queued capture${queue.length === 1 ? "" : "s"}...`);
|
|
13
|
+
const { initDb, saveMemory } = (0, persistence_config_1.getPersistence)();
|
|
14
|
+
await initDb();
|
|
15
|
+
let synced = 0;
|
|
16
|
+
let failed = 0;
|
|
17
|
+
for (const item of queue) {
|
|
18
|
+
try {
|
|
19
|
+
await saveMemory(item.input);
|
|
20
|
+
(0, offline_queue_1.dequeue)(item.id);
|
|
21
|
+
synced++;
|
|
22
|
+
console.log(` Synced: ${item.input.title || item.input.type} (queued ${new Date(item.queuedAt).toLocaleString()})`);
|
|
23
|
+
}
|
|
24
|
+
catch (err) {
|
|
25
|
+
failed++;
|
|
26
|
+
// increment attempts
|
|
27
|
+
const updated = (0, offline_queue_1.readQueue)().map(q => q.id === item.id ? { ...q, attempts: q.attempts + 1 } : q);
|
|
28
|
+
(0, offline_queue_1.writeQueue)(updated);
|
|
29
|
+
console.error(` Failed: ${item.input.title || item.input.type} — ${err.message}`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
console.log(`\nSync complete: ${synced} synced, ${failed} failed.`);
|
|
33
|
+
if (failed > 0) {
|
|
34
|
+
console.log("Run kodingo sync again when the connection is restored.");
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.updateCommand = updateCommand;
|
|
4
|
+
const child_process_1 = require("child_process");
|
|
5
|
+
async function updateCommand() {
|
|
6
|
+
console.log("Checking for updates...");
|
|
7
|
+
let currentVersion;
|
|
8
|
+
let latestVersion;
|
|
9
|
+
try {
|
|
10
|
+
currentVersion = (0, child_process_1.execSync)("kodingo --version", { encoding: "utf-8" }).trim();
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
currentVersion = "unknown";
|
|
14
|
+
}
|
|
15
|
+
try {
|
|
16
|
+
latestVersion = (0, child_process_1.execSync)("npm view kodingo-cli version", { encoding: "utf-8" }).trim();
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
console.error("Could not fetch latest version. Check your internet connection.");
|
|
20
|
+
process.exit(1);
|
|
21
|
+
}
|
|
22
|
+
if (currentVersion === latestVersion) {
|
|
23
|
+
console.log(`Already on the latest version (${currentVersion}).`);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
console.log(`Updating from ${currentVersion} to ${latestVersion}...`);
|
|
27
|
+
try {
|
|
28
|
+
(0, child_process_1.execSync)("npm install -g kodingo-cli@latest", { stdio: "inherit" });
|
|
29
|
+
console.log(`Updated to ${latestVersion} successfully.`);
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
console.error("Update failed. Try running: npm install -g kodingo-cli@latest");
|
|
33
|
+
process.exit(1);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.readQueue = readQueue;
|
|
7
|
+
exports.writeQueue = writeQueue;
|
|
8
|
+
exports.enqueue = enqueue;
|
|
9
|
+
exports.dequeue = dequeue;
|
|
10
|
+
exports.queueSize = queueSize;
|
|
11
|
+
exports.isNetworkError = isNetworkError;
|
|
12
|
+
const fs_1 = __importDefault(require("fs"));
|
|
13
|
+
const os_1 = __importDefault(require("os"));
|
|
14
|
+
const path_1 = __importDefault(require("path"));
|
|
15
|
+
const QUEUE_PATH = path_1.default.join(os_1.default.homedir(), ".kodingo", "queue.json");
|
|
16
|
+
function readQueue() {
|
|
17
|
+
try {
|
|
18
|
+
if (!fs_1.default.existsSync(QUEUE_PATH))
|
|
19
|
+
return [];
|
|
20
|
+
const raw = fs_1.default.readFileSync(QUEUE_PATH, "utf-8");
|
|
21
|
+
return JSON.parse(raw);
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
return [];
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function writeQueue(items) {
|
|
28
|
+
const dir = path_1.default.dirname(QUEUE_PATH);
|
|
29
|
+
if (!fs_1.default.existsSync(dir))
|
|
30
|
+
fs_1.default.mkdirSync(dir, { recursive: true });
|
|
31
|
+
fs_1.default.writeFileSync(QUEUE_PATH, JSON.stringify(items, null, 2), "utf-8");
|
|
32
|
+
}
|
|
33
|
+
function enqueue(input) {
|
|
34
|
+
const queue = readQueue();
|
|
35
|
+
const item = {
|
|
36
|
+
id: `${Date.now()}-${Math.random().toString(36).slice(2, 8)}`,
|
|
37
|
+
input,
|
|
38
|
+
queuedAt: new Date().toISOString(),
|
|
39
|
+
attempts: 0,
|
|
40
|
+
};
|
|
41
|
+
queue.push(item);
|
|
42
|
+
writeQueue(queue);
|
|
43
|
+
console.log(`Offline: capture queued (${queue.length} item${queue.length === 1 ? "" : "s"} in queue). Run kodingo sync when online.`);
|
|
44
|
+
}
|
|
45
|
+
function dequeue(id) {
|
|
46
|
+
const queue = readQueue().filter(item => item.id !== id);
|
|
47
|
+
writeQueue(queue);
|
|
48
|
+
}
|
|
49
|
+
function queueSize() {
|
|
50
|
+
return readQueue().length;
|
|
51
|
+
}
|
|
52
|
+
function isNetworkError(err) {
|
|
53
|
+
if (!(err instanceof Error))
|
|
54
|
+
return false;
|
|
55
|
+
const msg = err.message.toLowerCase();
|
|
56
|
+
return (msg.includes("fetch failed") ||
|
|
57
|
+
msg.includes("econnrefused") ||
|
|
58
|
+
msg.includes("enotfound") ||
|
|
59
|
+
msg.includes("network") ||
|
|
60
|
+
msg.includes("etimedout") ||
|
|
61
|
+
msg.includes("econnreset") ||
|
|
62
|
+
msg.includes("socket") ||
|
|
63
|
+
msg.includes("503") ||
|
|
64
|
+
msg.includes("502") ||
|
|
65
|
+
msg.includes("504"));
|
|
66
|
+
}
|
package/package.json
CHANGED