@zhouzhanghao001111/flashmemory 0.0.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/bin/run.js ADDED
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * FlashMemory CLI wrapper - fm command
4
+ * Forwards to the Go binary
5
+ */
6
+ const { execFileSync } = require("child_process");
7
+ const path = require("path");
8
+ const fs = require("fs");
9
+
10
+ const vendorDir = path.join(__dirname, "..", "vendor");
11
+ const ext = process.platform === "win32" ? ".exe" : "";
12
+ const binPath = path.join(vendorDir, `fm${ext}`);
13
+
14
+ if (!fs.existsSync(binPath)) {
15
+ console.error("❌ FlashMemory 二进制未找到,请重新安装:");
16
+ console.error(" npm install -g flashmemory");
17
+ process.exit(1);
18
+ }
19
+
20
+ // Set FAISS_SERVICE_PATH if FAISSService exists alongside binary
21
+ const faissDir = path.join(vendorDir, "FAISSService");
22
+ if (fs.existsSync(faissDir)) {
23
+ process.env.FAISS_SERVICE_PATH = faissDir;
24
+ }
25
+
26
+ try {
27
+ execFileSync(binPath, process.argv.slice(2), { stdio: "inherit" });
28
+ } catch (e) {
29
+ process.exit(e.status || 1);
30
+ }
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * FlashMemory HTTP server wrapper - fm_http command
4
+ * Forwards to the Go binary
5
+ */
6
+ const { execFileSync } = require("child_process");
7
+ const path = require("path");
8
+ const fs = require("fs");
9
+
10
+ const vendorDir = path.join(__dirname, "..", "vendor");
11
+ const ext = process.platform === "win32" ? ".exe" : "";
12
+ const binPath = path.join(vendorDir, `fm_http${ext}`);
13
+
14
+ if (!fs.existsSync(binPath)) {
15
+ console.error("❌ FlashMemory HTTP 服务二进制未找到,请重新安装:");
16
+ console.error(" npm install -g flashmemory");
17
+ process.exit(1);
18
+ }
19
+
20
+ // Set FAISS_SERVICE_PATH if FAISSService exists alongside binary
21
+ const faissDir = path.join(vendorDir, "FAISSService");
22
+ if (fs.existsSync(faissDir)) {
23
+ process.env.FAISS_SERVICE_PATH = faissDir;
24
+ }
25
+
26
+ try {
27
+ execFileSync(binPath, process.argv.slice(2), { stdio: "inherit" });
28
+ } catch (e) {
29
+ process.exit(e.status || 1);
30
+ }
package/install.js ADDED
@@ -0,0 +1,200 @@
1
+ /**
2
+ * FlashMemory NPM 安装脚本
3
+ * 在 npm install 时自动下载对应平台的二进制文件
4
+ */
5
+ const https = require("https");
6
+ const fs = require("fs");
7
+ const path = require("path");
8
+ const { execSync } = require("child_process");
9
+ const os = require("os");
10
+
11
+ const REPO = "ZetaZeroHub/FlashMemory";
12
+ const VENDOR_DIR = path.join(__dirname, "vendor");
13
+
14
+ // 平台映射: Node.js -> Go
15
+ const PLATFORM_MAP = {
16
+ darwin: "darwin",
17
+ linux: "linux",
18
+ win32: "windows",
19
+ };
20
+
21
+ const ARCH_MAP = {
22
+ x64: "amd64",
23
+ arm64: "arm64",
24
+ };
25
+
26
+ function getPackageVersion() {
27
+ const pkg = JSON.parse(
28
+ fs.readFileSync(path.join(__dirname, "package.json"), "utf8")
29
+ );
30
+ return pkg.version;
31
+ }
32
+
33
+ function getPlatformInfo() {
34
+ const platform = PLATFORM_MAP[process.platform];
35
+ const arch = ARCH_MAP[process.arch];
36
+
37
+ if (!platform) {
38
+ console.error(`不支持的操作系统: ${process.platform}`);
39
+ process.exit(1);
40
+ }
41
+ if (!arch) {
42
+ console.error(`不支持的 CPU 架构: ${process.arch}`);
43
+ process.exit(1);
44
+ }
45
+
46
+ return { platform, arch };
47
+ }
48
+
49
+ function getLatestVersion() {
50
+ return new Promise((resolve, reject) => {
51
+ const options = {
52
+ hostname: "api.github.com",
53
+ path: `/repos/${REPO}/releases/latest`,
54
+ headers: { "User-Agent": "flashmemory-npm-installer" },
55
+ };
56
+
57
+ https
58
+ .get(options, (res) => {
59
+ let data = "";
60
+ res.on("data", (chunk) => (data += chunk));
61
+ res.on("end", () => {
62
+ try {
63
+ const json = JSON.parse(data);
64
+ const version = json.tag_name.replace(/^v/, "");
65
+ resolve(version);
66
+ } catch (e) {
67
+ reject(new Error("无法获取最新版本: " + e.message));
68
+ }
69
+ });
70
+ })
71
+ .on("error", reject);
72
+ });
73
+ }
74
+
75
+ function downloadFile(url, dest) {
76
+ return new Promise((resolve, reject) => {
77
+ const follow = (url) => {
78
+ const lib = url.startsWith("https") ? https : require("http");
79
+ lib
80
+ .get(url, { headers: { "User-Agent": "flashmemory-npm" } }, (res) => {
81
+ // Handle redirects (GitHub uses them)
82
+ if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
83
+ return follow(res.headers.location);
84
+ }
85
+ if (res.statusCode !== 200) {
86
+ return reject(new Error(`下载失败 HTTP ${res.statusCode}: ${url}`));
87
+ }
88
+ const file = fs.createWriteStream(dest);
89
+ res.pipe(file);
90
+ file.on("finish", () => {
91
+ file.close();
92
+ resolve();
93
+ });
94
+ })
95
+ .on("error", reject);
96
+ };
97
+ follow(url);
98
+ });
99
+ }
100
+
101
+ function extractArchive(archivePath, destDir) {
102
+ const ext = archivePath.endsWith(".zip") ? "zip" : "tar.gz";
103
+
104
+ if (ext === "zip") {
105
+ // Windows: use PowerShell unzip
106
+ if (process.platform === "win32") {
107
+ execSync(
108
+ `powershell -Command "Expand-Archive -Force '${archivePath}' '${destDir}'"`,
109
+ { stdio: "inherit" }
110
+ );
111
+ } else {
112
+ execSync(`unzip -qo "${archivePath}" -d "${destDir}"`, {
113
+ stdio: "inherit",
114
+ });
115
+ }
116
+ } else {
117
+ execSync(`tar xzf "${archivePath}" -C "${destDir}"`, { stdio: "inherit" });
118
+ }
119
+ }
120
+
121
+ async function main() {
122
+ const { platform, arch } = getPlatformInfo();
123
+
124
+ console.log(`\n📦 FlashMemory 安装器`);
125
+ console.log(` 平台: ${platform}/${arch}\n`);
126
+
127
+ // 获取版本
128
+ let version;
129
+ try {
130
+ version = await getLatestVersion();
131
+ console.log(` 版本: v${version}`);
132
+ } catch (e) {
133
+ console.error("⚠️ 无法获取最新版本:", e.message);
134
+ console.error(" 跳过二进制下载,稍后可手动安装");
135
+ process.exit(0); // Don't fail npm install
136
+ }
137
+
138
+ // 构造下载 URL
139
+ const ext = platform === "windows" ? "zip" : "tar.gz";
140
+ const archiveName = `flashmemory_${version}_${platform}_${arch}`;
141
+ const url = `https://github.com/${REPO}/releases/download/v${version}/${archiveName}.${ext}`;
142
+
143
+ // 创建目录
144
+ fs.mkdirSync(VENDOR_DIR, { recursive: true });
145
+ const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "flashmemory-"));
146
+ const archivePath = path.join(tmpDir, `flashmemory.${ext}`);
147
+
148
+ try {
149
+ // 下载
150
+ console.log(` 下载: ${url}`);
151
+ await downloadFile(url, archivePath);
152
+ console.log(` ✅ 下载完成`);
153
+
154
+ // 解压
155
+ extractArchive(archivePath, tmpDir);
156
+ console.log(` ✅ 解压完成`);
157
+
158
+ // 复制到 vendor 目录
159
+ const extractedDir = path.join(tmpDir, archiveName);
160
+ const files = fs.readdirSync(extractedDir);
161
+ for (const file of files) {
162
+ const src = path.join(extractedDir, file);
163
+ const dest = path.join(VENDOR_DIR, file);
164
+ if (fs.statSync(src).isDirectory()) {
165
+ // 递归复制目录
166
+ execSync(
167
+ process.platform === "win32"
168
+ ? `xcopy /E /I /Y "${src}" "${dest}"`
169
+ : `cp -r "${src}" "${dest}"`
170
+ );
171
+ } else {
172
+ fs.copyFileSync(src, dest);
173
+ }
174
+ }
175
+
176
+ // 设置执行权限 (非 Windows)
177
+ if (platform !== "windows") {
178
+ const bins = ["fm", "fm_http"];
179
+ for (const bin of bins) {
180
+ const binPath = path.join(VENDOR_DIR, bin);
181
+ if (fs.existsSync(binPath)) {
182
+ fs.chmodSync(binPath, 0o755);
183
+ }
184
+ }
185
+ }
186
+
187
+ console.log(` ✅ 安装完成: ${VENDOR_DIR}\n`);
188
+ } catch (e) {
189
+ console.error(`\n⚠️ 安装失败: ${e.message}`);
190
+ console.error(" 请检查网络连接或手动下载二进制文件\n");
191
+ process.exit(0); // Don't fail npm install
192
+ } finally {
193
+ // 清理临时文件
194
+ try {
195
+ fs.rmSync(tmpDir, { recursive: true, force: true });
196
+ } catch {}
197
+ }
198
+ }
199
+
200
+ main();
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@zhouzhanghao001111/flashmemory",
3
+ "version": "0.0.1",
4
+ "description": "FlashMemory - Cross-language code analysis and semantic search system. Supports Go, Python, JavaScript, Java, C++ code indexing with LLM-powered analysis.",
5
+ "keywords": [
6
+ "code-analysis",
7
+ "semantic-search",
8
+ "code-indexing",
9
+ "llm",
10
+ "faiss",
11
+ "knowledge-graph"
12
+ ],
13
+ "homepage": "https://github.com/ZetaZeroHub/FlashMemory",
14
+ "bugs": {
15
+ "url": "https://github.com/ZetaZeroHub/FlashMemory/issues"
16
+ },
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/ZetaZeroHub/FlashMemory.git"
20
+ },
21
+ "license": "MIT",
22
+ "author": "ZetaZeroHub",
23
+ "bin": {
24
+ "fm": "bin/run.js",
25
+ "fm_http": "bin/run_http.js"
26
+ },
27
+ "scripts": {
28
+ "postinstall": "node install.js"
29
+ },
30
+ "engines": {
31
+ "node": ">=14"
32
+ },
33
+ "os": [
34
+ "darwin",
35
+ "linux",
36
+ "win32"
37
+ ],
38
+ "cpu": [
39
+ "x64",
40
+ "arm64"
41
+ ]
42
+ }