@gramatr/mcp 0.8.0 → 0.8.2
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/gramatr +0 -0
- package/package.json +3 -1
- package/scripts/postinstall.mjs +115 -0
package/dist/gramatr
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gramatr/mcp",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.2",
|
|
4
4
|
"description": "grāmatr — Intelligence middleware for AI agents. Pre-classifies every request, injects relevant memory and behavioral context, enforces data quality, and maintains session continuity across Claude, ChatGPT, Codex, Cursor, Gemini, and any MCP-compatible client.",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"publishConfig": {
|
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
},
|
|
46
46
|
"files": [
|
|
47
47
|
"dist",
|
|
48
|
+
"scripts/postinstall.mjs",
|
|
48
49
|
"LICENSE"
|
|
49
50
|
],
|
|
50
51
|
"dependencies": {
|
|
@@ -58,6 +59,7 @@
|
|
|
58
59
|
"vitest": "^4.0.18"
|
|
59
60
|
},
|
|
60
61
|
"scripts": {
|
|
62
|
+
"postinstall": "node scripts/postinstall.mjs",
|
|
61
63
|
"build": "tsc --build && node ./scripts/build-binary.mjs",
|
|
62
64
|
"build:types": "tsc --build",
|
|
63
65
|
"build:binary": "bun build --compile src/bin/gramatr-mcp.ts --define __GRAMATR_VERSION__=\\\"${npm_package_version}\\\" --outfile dist/gramatr",
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* postinstall.mjs — Auto-download the pre-compiled gramatr binary for the user's platform.
|
|
3
|
+
*
|
|
4
|
+
* Runs on `npm install @gramatr/client`. Detects platform + arch, downloads
|
|
5
|
+
* the matching binary from the GitHub Release, and installs it to
|
|
6
|
+
* ~/.gramatr/bin/gramatr.
|
|
7
|
+
*
|
|
8
|
+
* Design constraints:
|
|
9
|
+
* - Pure Node.js (no external dependencies, no bun)
|
|
10
|
+
* - Node 18+ (native fetch)
|
|
11
|
+
* - Graceful failure: logs a warning but always exits 0
|
|
12
|
+
* - ISC-A: npm install must not fail if GitHub is unreachable
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { createWriteStream } from "node:fs";
|
|
16
|
+
import { chmod, mkdir, rename, unlink } from "node:fs/promises";
|
|
17
|
+
import { homedir } from "node:os";
|
|
18
|
+
import { dirname, join } from "node:path";
|
|
19
|
+
import { pipeline } from "node:stream/promises";
|
|
20
|
+
import { Readable } from "node:stream";
|
|
21
|
+
import { createRequire } from "node:module";
|
|
22
|
+
import { fileURLToPath } from "node:url";
|
|
23
|
+
|
|
24
|
+
// Download from the PUBLIC repo (gramatr/mcp), not the private monorepo (gramatr/gramatr).
|
|
25
|
+
const GITHUB_RELEASE_BASE =
|
|
26
|
+
"https://github.com/gramatr/mcp/releases/download";
|
|
27
|
+
|
|
28
|
+
/** Map (platform, arch) to the binary asset name. */
|
|
29
|
+
function getBinaryName(platform, arch) {
|
|
30
|
+
const map = {
|
|
31
|
+
"linux-x64": "gramatr-linux-x64",
|
|
32
|
+
"linux-arm64": "gramatr-linux-arm64",
|
|
33
|
+
"darwin-x64": "gramatr-darwin-x64",
|
|
34
|
+
"darwin-arm64": "gramatr-darwin-arm64",
|
|
35
|
+
"win32-x64": "gramatr-windows-x64.exe",
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const key = `${platform}-${arch}`;
|
|
39
|
+
return map[key] ?? null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Read version from the package's own package.json. */
|
|
43
|
+
function getVersion() {
|
|
44
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
45
|
+
const require = createRequire(import.meta.url);
|
|
46
|
+
const pkg = require(join(__dirname, "..", "package.json"));
|
|
47
|
+
return pkg.version;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Download a file from `url` to `dest`, following redirects (fetch handles them). */
|
|
51
|
+
async function downloadBinary(url, dest) {
|
|
52
|
+
const response = await fetch(url, { redirect: "follow" });
|
|
53
|
+
|
|
54
|
+
if (!response.ok) {
|
|
55
|
+
throw new Error(
|
|
56
|
+
`Download failed: HTTP ${response.status} ${response.statusText}`,
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const tempDest = `${dest}.tmp`;
|
|
61
|
+
const body = Readable.fromWeb(response.body);
|
|
62
|
+
const fileStream = createWriteStream(tempDest);
|
|
63
|
+
|
|
64
|
+
try {
|
|
65
|
+
await pipeline(body, fileStream);
|
|
66
|
+
await rename(tempDest, dest);
|
|
67
|
+
} catch (err) {
|
|
68
|
+
// Clean up partial download
|
|
69
|
+
await unlink(tempDest).catch(() => {});
|
|
70
|
+
throw err;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async function main() {
|
|
75
|
+
const platform = process.platform;
|
|
76
|
+
const arch = process.arch;
|
|
77
|
+
|
|
78
|
+
const binaryName = getBinaryName(platform, arch);
|
|
79
|
+
if (!binaryName) {
|
|
80
|
+
console.warn(
|
|
81
|
+
`[gramatr] Unsupported platform: ${platform}-${arch}. ` +
|
|
82
|
+
"Skipping binary download. You can install manually from " +
|
|
83
|
+
"https://github.com/gramatr/gramatr/releases",
|
|
84
|
+
);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const version = getVersion();
|
|
89
|
+
const url = `${GITHUB_RELEASE_BASE}/v${version}/${binaryName}`;
|
|
90
|
+
|
|
91
|
+
const installDir = join(homedir(), ".gramatr", "bin");
|
|
92
|
+
const isWindows = platform === "win32";
|
|
93
|
+
const installPath = join(installDir, isWindows ? "gramatr.exe" : "gramatr");
|
|
94
|
+
|
|
95
|
+
console.log(`[gramatr] Downloading ${binaryName} v${version}...`);
|
|
96
|
+
|
|
97
|
+
await mkdir(installDir, { recursive: true });
|
|
98
|
+
await downloadBinary(url, installPath);
|
|
99
|
+
|
|
100
|
+
if (!isWindows) {
|
|
101
|
+
await chmod(installPath, 0o755);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
console.log(`[gramatr] Installed to ${installPath}`);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
main().catch((err) => {
|
|
108
|
+
console.warn(
|
|
109
|
+
`[gramatr] Binary download failed: ${err.message}. ` +
|
|
110
|
+
"This is non-fatal — you can install manually from " +
|
|
111
|
+
"https://github.com/gramatr/gramatr/releases",
|
|
112
|
+
);
|
|
113
|
+
// Always exit 0 — never break npm install
|
|
114
|
+
process.exit(0);
|
|
115
|
+
});
|