context-vault 2.4.1 → 2.5.1
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/README.md +438 -0
- package/app-dist/assets/index-DjXoWapE.css +1 -0
- package/app-dist/assets/index-R4n9Qz4U.js +380 -0
- package/app-dist/index.html +16 -0
- package/bin/cli.js +869 -75
- package/node_modules/@context-vault/core/package.json +18 -12
- package/node_modules/@context-vault/core/src/capture/import-pipeline.js +85 -0
- package/node_modules/@context-vault/core/src/capture/importers.js +360 -0
- package/node_modules/@context-vault/core/src/capture/ingest-url.js +216 -0
- package/node_modules/@context-vault/core/src/core/config.js +20 -10
- package/node_modules/@context-vault/core/src/index/db.js +23 -13
- package/node_modules/@context-vault/core/src/index/embed.js +14 -10
- package/node_modules/@context-vault/core/src/retrieve/index.js +12 -7
- package/node_modules/@context-vault/core/src/server/tools.js +122 -33
- package/node_modules/@context-vault/core/src/sync/sync.js +230 -0
- package/package.json +36 -8
- package/scripts/local-server.js +587 -0
- package/scripts/postinstall.js +35 -2
- package/scripts/prepack.js +31 -6
- package/src/server/index.js +53 -18
package/scripts/prepack.js
CHANGED
|
@@ -7,20 +7,24 @@
|
|
|
7
7
|
* Replaces the Unix shell script in package.json "prepack".
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import { cpSync, rmSync, mkdirSync } from "node:fs";
|
|
10
|
+
import { cpSync, rmSync, mkdirSync, readFileSync, writeFileSync, existsSync } from "node:fs";
|
|
11
11
|
import { join, dirname } from "node:path";
|
|
12
12
|
import { fileURLToPath } from "node:url";
|
|
13
13
|
|
|
14
14
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
15
15
|
const LOCAL_ROOT = join(__dirname, "..");
|
|
16
|
+
const NODE_MODULES = join(LOCAL_ROOT, "node_modules");
|
|
16
17
|
const CORE_SRC = join(LOCAL_ROOT, "..", "core");
|
|
17
|
-
const CORE_DEST = join(
|
|
18
|
+
const CORE_DEST = join(NODE_MODULES, "@context-vault", "core");
|
|
19
|
+
const APP_SRC = join(LOCAL_ROOT, "..", "app", "dist");
|
|
20
|
+
const APP_DEST = join(LOCAL_ROOT, "app-dist");
|
|
18
21
|
|
|
19
|
-
//
|
|
20
|
-
|
|
22
|
+
// Clean node_modules to prevent workspace deps from leaking into the tarball.
|
|
23
|
+
// Only @context-vault/core should be bundled.
|
|
24
|
+
rmSync(NODE_MODULES, { recursive: true, force: true });
|
|
21
25
|
|
|
22
|
-
//
|
|
23
|
-
|
|
26
|
+
// Ensure target directory exists
|
|
27
|
+
mkdirSync(join(NODE_MODULES, "@context-vault"), { recursive: true });
|
|
24
28
|
|
|
25
29
|
// Copy core package (dereference symlinks)
|
|
26
30
|
cpSync(CORE_SRC, CORE_DEST, { recursive: true, dereference: true });
|
|
@@ -28,4 +32,25 @@ cpSync(CORE_SRC, CORE_DEST, { recursive: true, dereference: true });
|
|
|
28
32
|
// Remove nested node_modules from the copy
|
|
29
33
|
rmSync(join(CORE_DEST, "node_modules"), { recursive: true, force: true });
|
|
30
34
|
|
|
35
|
+
// Strip all dependencies from the bundled core's package.json.
|
|
36
|
+
// Core's deps (better-sqlite3, sqlite-vec, MCP SDK) are hoisted to
|
|
37
|
+
// context-vault's own dependencies. @huggingface/transformers is
|
|
38
|
+
// dynamically imported and installed via postinstall. Leaving them
|
|
39
|
+
// in the bundled core causes duplicate resolution that breaks native
|
|
40
|
+
// module install scripts in global npm contexts.
|
|
41
|
+
const corePkgPath = join(CORE_DEST, "package.json");
|
|
42
|
+
const corePkg = JSON.parse(readFileSync(corePkgPath, "utf8"));
|
|
43
|
+
delete corePkg.dependencies;
|
|
44
|
+
writeFileSync(corePkgPath, JSON.stringify(corePkg, null, 2) + "\n");
|
|
45
|
+
|
|
31
46
|
console.log("[prepack] Bundled @context-vault/core into node_modules");
|
|
47
|
+
|
|
48
|
+
// Copy pre-built web dashboard into app-dist/
|
|
49
|
+
if (!existsSync(join(APP_SRC, "index.html"))) {
|
|
50
|
+
console.error("[prepack] ERROR: Web dashboard not built. Run: npm run build --workspace=packages/app");
|
|
51
|
+
process.exit(1);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
rmSync(APP_DEST, { recursive: true, force: true });
|
|
55
|
+
cpSync(APP_SRC, APP_DEST, { recursive: true });
|
|
56
|
+
console.log("[prepack] Bundled web dashboard into app-dist/");
|
package/src/server/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
4
4
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
5
|
-
import { existsSync, mkdirSync, writeFileSync, readFileSync } from "node:fs";
|
|
5
|
+
import { existsSync, mkdirSync, writeFileSync, readFileSync, unlinkSync } from "node:fs";
|
|
6
6
|
import { join, dirname } from "node:path";
|
|
7
7
|
import { fileURLToPath } from "node:url";
|
|
8
8
|
|
|
@@ -19,33 +19,46 @@ import { registerTools } from "@context-vault/core/server/tools";
|
|
|
19
19
|
async function main() {
|
|
20
20
|
let phase = "CONFIG";
|
|
21
21
|
let db;
|
|
22
|
+
let config;
|
|
22
23
|
|
|
23
24
|
try {
|
|
24
25
|
// ── Phase: CONFIG ────────────────────────────────────────────────────────
|
|
25
|
-
|
|
26
|
+
config = resolveConfig();
|
|
26
27
|
|
|
27
28
|
// ── Phase: DIRS ──────────────────────────────────────────────────────────
|
|
28
29
|
phase = "DIRS";
|
|
29
30
|
mkdirSync(config.dataDir, { recursive: true });
|
|
30
31
|
mkdirSync(config.vaultDir, { recursive: true });
|
|
31
32
|
|
|
33
|
+
// Verify vault directory is writable (catch permission issues early)
|
|
34
|
+
try {
|
|
35
|
+
const probe = join(config.vaultDir, ".write-probe");
|
|
36
|
+
writeFileSync(probe, "");
|
|
37
|
+
unlinkSync(probe);
|
|
38
|
+
} catch (writeErr) {
|
|
39
|
+
console.error(`[context-vault] FATAL: Vault directory is not writable: ${config.vaultDir}`);
|
|
40
|
+
console.error(`[context-vault] ${writeErr.message}`);
|
|
41
|
+
console.error(`[context-vault] Fix permissions: chmod u+w "${config.vaultDir}"`);
|
|
42
|
+
process.exit(1);
|
|
43
|
+
}
|
|
44
|
+
|
|
32
45
|
// Write .context-mcp marker (non-fatal)
|
|
33
46
|
try {
|
|
34
47
|
const markerPath = join(config.vaultDir, ".context-mcp");
|
|
35
48
|
const markerData = existsSync(markerPath) ? JSON.parse(readFileSync(markerPath, "utf-8")) : {};
|
|
36
49
|
writeFileSync(markerPath, JSON.stringify({ created: markerData.created || new Date().toISOString(), version: pkg.version }, null, 2) + "\n");
|
|
37
50
|
} catch (markerErr) {
|
|
38
|
-
console.error(`[context-
|
|
51
|
+
console.error(`[context-vault] Warning: could not write marker file: ${markerErr.message}`);
|
|
39
52
|
}
|
|
40
53
|
|
|
41
54
|
config.vaultDirExists = existsSync(config.vaultDir);
|
|
42
55
|
|
|
43
56
|
// Startup diagnostics
|
|
44
|
-
console.error(`[context-
|
|
45
|
-
console.error(`[context-
|
|
46
|
-
console.error(`[context-
|
|
57
|
+
console.error(`[context-vault] Vault: ${config.vaultDir}`);
|
|
58
|
+
console.error(`[context-vault] Database: ${config.dbPath}`);
|
|
59
|
+
console.error(`[context-vault] Dev dir: ${config.devDir}`);
|
|
47
60
|
if (!config.vaultDirExists) {
|
|
48
|
-
console.error(`[context-
|
|
61
|
+
console.error(`[context-vault] WARNING: Vault directory not found!`);
|
|
49
62
|
}
|
|
50
63
|
|
|
51
64
|
// ── Phase: DB ────────────────────────────────────────────────────────────
|
|
@@ -60,33 +73,55 @@ async function main() {
|
|
|
60
73
|
embed,
|
|
61
74
|
insertVec: (rowid, embedding) => insertVec(stmts, rowid, embedding),
|
|
62
75
|
deleteVec: (rowid) => deleteVec(stmts, rowid),
|
|
76
|
+
activeOps: { count: 0 },
|
|
63
77
|
};
|
|
64
78
|
|
|
65
79
|
// ── Phase: SERVER ────────────────────────────────────────────────────────
|
|
66
80
|
phase = "SERVER";
|
|
67
81
|
const server = new McpServer(
|
|
68
|
-
{ name: "context-
|
|
82
|
+
{ name: "context-vault", version: pkg.version },
|
|
69
83
|
{ capabilities: { tools: {} } }
|
|
70
84
|
);
|
|
71
85
|
|
|
72
86
|
registerTools(server, ctx);
|
|
73
87
|
|
|
74
88
|
// ── Graceful Shutdown ────────────────────────────────────────────────────
|
|
75
|
-
function
|
|
76
|
-
console.error(`[context-mcp] Received ${signal}, shutting down...`);
|
|
89
|
+
function closeDb() {
|
|
77
90
|
try {
|
|
78
91
|
if (db.inTransaction) {
|
|
79
|
-
console.error("[context-
|
|
92
|
+
console.error("[context-vault] Rolling back active transaction...");
|
|
80
93
|
db.exec("ROLLBACK");
|
|
81
94
|
}
|
|
82
95
|
db.pragma("wal_checkpoint(TRUNCATE)");
|
|
83
96
|
db.close();
|
|
84
|
-
console.error("[context-
|
|
97
|
+
console.error("[context-vault] Database closed cleanly.");
|
|
85
98
|
} catch (shutdownErr) {
|
|
86
|
-
console.error(`[context-
|
|
99
|
+
console.error(`[context-vault] Shutdown error: ${shutdownErr.message}`);
|
|
87
100
|
}
|
|
88
101
|
process.exit(0);
|
|
89
102
|
}
|
|
103
|
+
|
|
104
|
+
function shutdown(signal) {
|
|
105
|
+
console.error(`[context-vault] Received ${signal}, shutting down...`);
|
|
106
|
+
|
|
107
|
+
if (ctx.activeOps.count > 0) {
|
|
108
|
+
console.error(`[context-vault] Waiting for ${ctx.activeOps.count} in-flight operation(s)...`);
|
|
109
|
+
const check = setInterval(() => {
|
|
110
|
+
if (ctx.activeOps.count === 0) {
|
|
111
|
+
clearInterval(check);
|
|
112
|
+
closeDb();
|
|
113
|
+
}
|
|
114
|
+
}, 100);
|
|
115
|
+
// Force shutdown after 5 seconds even if ops are still running
|
|
116
|
+
setTimeout(() => {
|
|
117
|
+
clearInterval(check);
|
|
118
|
+
console.error(`[context-vault] Force shutdown — ${ctx.activeOps.count} operation(s) still running`);
|
|
119
|
+
closeDb();
|
|
120
|
+
}, 5000);
|
|
121
|
+
} else {
|
|
122
|
+
closeDb();
|
|
123
|
+
}
|
|
124
|
+
}
|
|
90
125
|
process.on("SIGINT", () => shutdown("SIGINT"));
|
|
91
126
|
process.on("SIGTERM", () => shutdown("SIGTERM"));
|
|
92
127
|
|
|
@@ -105,7 +140,7 @@ async function main() {
|
|
|
105
140
|
stdio: ["pipe", "pipe", "pipe"],
|
|
106
141
|
}).trim();
|
|
107
142
|
if (latest && latest !== pkg.version) {
|
|
108
|
-
console.error(`[context-
|
|
143
|
+
console.error(`[context-vault] Update available: v${pkg.version} → v${latest}. Run: context-vault update`);
|
|
109
144
|
}
|
|
110
145
|
} catch {}
|
|
111
146
|
}).catch(() => {});
|
|
@@ -116,7 +151,7 @@ async function main() {
|
|
|
116
151
|
// Boxed diagnostic for native module mismatch
|
|
117
152
|
console.error("");
|
|
118
153
|
console.error("╔══════════════════════════════════════════════════════════════╗");
|
|
119
|
-
console.error("║ context-
|
|
154
|
+
console.error("║ context-vault: Native Module Error ║");
|
|
120
155
|
console.error("╚══════════════════════════════════════════════════════════════╝");
|
|
121
156
|
console.error("");
|
|
122
157
|
console.error(err.message);
|
|
@@ -127,15 +162,15 @@ async function main() {
|
|
|
127
162
|
process.exit(78); // EX_CONFIG
|
|
128
163
|
}
|
|
129
164
|
|
|
130
|
-
console.error(`[context-
|
|
165
|
+
console.error(`[context-vault] Fatal error during ${phase} phase: ${err.message}`);
|
|
131
166
|
if (phase === "DB") {
|
|
132
|
-
console.error(`[context-
|
|
167
|
+
console.error(`[context-vault] Try deleting the DB file and restarting: rm "${config?.dbPath || "vault.db"}"`);
|
|
133
168
|
}
|
|
134
169
|
process.exit(1);
|
|
135
170
|
}
|
|
136
171
|
}
|
|
137
172
|
|
|
138
173
|
main().catch((err) => {
|
|
139
|
-
console.error(`[context-
|
|
174
|
+
console.error(`[context-vault] Unexpected fatal error: ${err.message}`);
|
|
140
175
|
process.exit(1);
|
|
141
176
|
});
|