agentcache 0.3.2 → 0.3.3
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/mcp.js +65 -2
- package/package.json +1 -1
package/dist/mcp.js
CHANGED
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
} from "./chunk-QVQJPJGX.js";
|
|
16
16
|
import {
|
|
17
17
|
findProjectRoot,
|
|
18
|
+
getDataDir,
|
|
18
19
|
getDbPath,
|
|
19
20
|
getProjectId,
|
|
20
21
|
isInitialized
|
|
@@ -28,7 +29,68 @@ import "./chunk-KFQGP6VL.js";
|
|
|
28
29
|
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
29
30
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
30
31
|
import { CallToolRequestSchema, ListToolsRequestSchema, RootsListChangedNotificationSchema } from "@modelcontextprotocol/sdk/types.js";
|
|
31
|
-
|
|
32
|
+
|
|
33
|
+
// src/utils/auto-update.ts
|
|
34
|
+
import { execSync, spawn } from "child_process";
|
|
35
|
+
import { readFileSync, writeFileSync, existsSync } from "fs";
|
|
36
|
+
import { join } from "path";
|
|
37
|
+
var CHECK_INTERVAL_MS = 4 * 60 * 60 * 1e3;
|
|
38
|
+
function getLastCheckPath() {
|
|
39
|
+
return join(getDataDir(), "last-update-check.json");
|
|
40
|
+
}
|
|
41
|
+
function shouldCheck() {
|
|
42
|
+
const path = getLastCheckPath();
|
|
43
|
+
if (!existsSync(path)) return true;
|
|
44
|
+
try {
|
|
45
|
+
const data = JSON.parse(readFileSync(path, "utf-8"));
|
|
46
|
+
return Date.now() - data.checkedAt > CHECK_INTERVAL_MS;
|
|
47
|
+
} catch {
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function markChecked() {
|
|
52
|
+
writeFileSync(getLastCheckPath(), JSON.stringify({ checkedAt: Date.now() }), "utf-8");
|
|
53
|
+
}
|
|
54
|
+
function getCurrentVersion() {
|
|
55
|
+
const pkgPath = new URL("../../package.json", import.meta.url);
|
|
56
|
+
const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
|
|
57
|
+
return pkg.version;
|
|
58
|
+
}
|
|
59
|
+
function getLatestVersion() {
|
|
60
|
+
try {
|
|
61
|
+
return execSync("npm view agentcache version", {
|
|
62
|
+
encoding: "utf-8",
|
|
63
|
+
timeout: 1e4,
|
|
64
|
+
stdio: ["pipe", "pipe", "pipe"]
|
|
65
|
+
}).trim();
|
|
66
|
+
} catch {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function isNewer(latest, current) {
|
|
71
|
+
const l = latest.split(".").map(Number);
|
|
72
|
+
const c = current.split(".").map(Number);
|
|
73
|
+
for (let i = 0; i < 3; i++) {
|
|
74
|
+
if ((l[i] || 0) > (c[i] || 0)) return true;
|
|
75
|
+
if ((l[i] || 0) < (c[i] || 0)) return false;
|
|
76
|
+
}
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
function checkForUpdates() {
|
|
80
|
+
if (!shouldCheck()) return;
|
|
81
|
+
markChecked();
|
|
82
|
+
const current = getCurrentVersion();
|
|
83
|
+
const latest = getLatestVersion();
|
|
84
|
+
if (!latest || !isNewer(latest, current)) return;
|
|
85
|
+
const child = spawn("npm", ["install", "-g", "agentcache@latest"], {
|
|
86
|
+
detached: true,
|
|
87
|
+
stdio: "ignore"
|
|
88
|
+
});
|
|
89
|
+
child.unref();
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// src/mcp.ts
|
|
93
|
+
import { existsSync as existsSync2 } from "fs";
|
|
32
94
|
import { randomUUID } from "crypto";
|
|
33
95
|
function defaultScope(type) {
|
|
34
96
|
return type === "rule" || type === "lesson" ? "global" : "project";
|
|
@@ -62,6 +124,7 @@ async function startMcpServer() {
|
|
|
62
124
|
);
|
|
63
125
|
server.oninitialized = async () => {
|
|
64
126
|
await resolveRoots(server);
|
|
127
|
+
checkForUpdates();
|
|
65
128
|
};
|
|
66
129
|
server.setNotificationHandler(RootsListChangedNotificationSchema, async () => {
|
|
67
130
|
await resolveRoots(server);
|
|
@@ -281,7 +344,7 @@ ${pendingCount} sessions pending compilation (background compiler already runnin
|
|
|
281
344
|
if (!entry) {
|
|
282
345
|
return { content: [{ type: "text", text: JSON.stringify({ message: "No pending sessions to compile." }) }] };
|
|
283
346
|
}
|
|
284
|
-
if (!
|
|
347
|
+
if (!existsSync2(entry.transcriptPath)) {
|
|
285
348
|
return { content: [{ type: "text", text: JSON.stringify({ message: `Transcript not found: ${entry.transcriptPath}, skipped.` }) }] };
|
|
286
349
|
}
|
|
287
350
|
const events = parseTranscript(entry.transcriptPath);
|