kodingo-cli 1.0.5 → 1.0.7
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 +16 -0
- package/dist/commands/aging.js +34 -0
- package/dist/commands/capture.js +13 -2
- package/dist/commands/sync.js +36 -0
- package/dist/utils/offline-queue.js +66 -0
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -15,6 +15,8 @@ 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
17
|
const update_1 = require("./commands/update");
|
|
18
|
+
const sync_1 = require("./commands/sync");
|
|
19
|
+
const aging_1 = require("./commands/aging");
|
|
18
20
|
const program = new commander_1.Command();
|
|
19
21
|
program.name("kodingo").description("Kodingo CLI").version("1.0.4");
|
|
20
22
|
// ── init ──────────────────────────────────────────────────────────────────────
|
|
@@ -26,6 +28,20 @@ program
|
|
|
26
28
|
.action(async () => {
|
|
27
29
|
await (0, update_1.updateCommand)();
|
|
28
30
|
});
|
|
31
|
+
// ── sync ──────────────────────────────────────────────────────────────────────
|
|
32
|
+
program
|
|
33
|
+
.command("sync")
|
|
34
|
+
.description("Sync queued offline captures to the cloud")
|
|
35
|
+
.action(async () => {
|
|
36
|
+
await (0, sync_1.syncCommand)();
|
|
37
|
+
});
|
|
38
|
+
// ── aging ─────────────────────────────────────────────────────────────────────
|
|
39
|
+
program
|
|
40
|
+
.command("aging")
|
|
41
|
+
.description("List stale memory records not updated in 90+ days")
|
|
42
|
+
.action(async () => {
|
|
43
|
+
await (0, aging_1.agingCommand)();
|
|
44
|
+
});
|
|
29
45
|
// ── capture ───────────────────────────────────────────────────────────────────
|
|
30
46
|
program
|
|
31
47
|
.command("capture")
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.agingCommand = agingCommand;
|
|
4
|
+
const persistence_config_1 = require("../utils/persistence-config");
|
|
5
|
+
async function agingCommand() {
|
|
6
|
+
const persistence = (0, persistence_config_1.getPersistence)();
|
|
7
|
+
await persistence.initDb();
|
|
8
|
+
const NINETY_DAYS_MS = 90 * 24 * 60 * 60 * 1000;
|
|
9
|
+
const cutoff = new Date(Date.now() - NINETY_DAYS_MS);
|
|
10
|
+
const results = await persistence.queryMemory("", 200, undefined, {
|
|
11
|
+
includeNonCanonical: true,
|
|
12
|
+
});
|
|
13
|
+
const stale = results.filter((r) => {
|
|
14
|
+
const updated = r.updatedAt instanceof Date ? r.updatedAt : new Date(r.updatedAt);
|
|
15
|
+
return ((r.status === "proposed" || r.status === "ignored") &&
|
|
16
|
+
updated < cutoff);
|
|
17
|
+
});
|
|
18
|
+
if (stale.length === 0) {
|
|
19
|
+
console.log("No stale memories found. Everything is fresh.");
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
console.log(`Found ${stale.length} stale memory record${stale.length === 1 ? "" : "s"} (not updated in 90+ days):\n`);
|
|
23
|
+
for (const r of stale) {
|
|
24
|
+
const updated = r.updatedAt instanceof Date ? r.updatedAt : new Date(r.updatedAt);
|
|
25
|
+
const daysAgo = Math.floor((Date.now() - updated.getTime()) / (1000 * 60 * 60 * 24));
|
|
26
|
+
const title = r.title || r.content.slice(0, 60);
|
|
27
|
+
console.log(` [${r.status.toUpperCase()}] ${title}`);
|
|
28
|
+
console.log(` ID: ${r.id}`);
|
|
29
|
+
console.log(` Symbol: ${r.symbol ?? "none"}`);
|
|
30
|
+
console.log(` Last updated: ${updated.toLocaleDateString()} (${daysAgo} days ago)`);
|
|
31
|
+
console.log(` Run: kodingo deny ${r.id} OR kodingo affirm ${r.id}\n`);
|
|
32
|
+
}
|
|
33
|
+
console.log(`Tip: review these records and affirm, deny, or ignore them to keep your memory base clean.`);
|
|
34
|
+
}
|
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)
|
|
@@ -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,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
|
+
}
|