agentmap-cli 0.4.0

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/agentmap ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { runBinary } = require('../lib/index.js');
4
+
5
+ runBinary(process.argv.slice(2));
package/lib/index.js ADDED
@@ -0,0 +1,197 @@
1
+ const { spawn } = require("child_process");
2
+ const fs = require("fs");
3
+ const path = require("path");
4
+ const https = require("https");
5
+ const { createGunzip } = require("zlib");
6
+ const tar = require("tar");
7
+
8
+ const REPO = "nguyenphutrong/agentmap";
9
+ const BINARY_NAME = process.platform === "win32" ? "agentmap.exe" : "agentmap";
10
+
11
+ const PLATFORM_MAP = {
12
+ darwin: "darwin",
13
+ linux: "linux",
14
+ win32: "windows",
15
+ };
16
+
17
+ const ARCH_MAP = {
18
+ x64: "x86_64",
19
+ arm64: "aarch64",
20
+ };
21
+
22
+ function getBinDir() {
23
+ return path.join(__dirname, "..", "bin");
24
+ }
25
+
26
+ function getBinaryPath() {
27
+ return path.join(getBinDir(), BINARY_NAME);
28
+ }
29
+
30
+ function getPlatformInfo() {
31
+ const platform = PLATFORM_MAP[process.platform];
32
+ const arch = ARCH_MAP[process.arch];
33
+
34
+ if (!platform) {
35
+ throw new Error(`Unsupported platform: ${process.platform}`);
36
+ }
37
+ if (!arch) {
38
+ throw new Error(`Unsupported architecture: ${process.arch}`);
39
+ }
40
+
41
+ return { platform, arch };
42
+ }
43
+
44
+ function getDownloadUrl(version) {
45
+ const { platform, arch } = getPlatformInfo();
46
+ const filename = `agentmap-${platform}-${arch}.tar.gz`;
47
+ return `https://github.com/${REPO}/releases/download/${version}/${filename}`;
48
+ }
49
+
50
+ async function getLatestVersion() {
51
+ return new Promise((resolve, reject) => {
52
+ const options = {
53
+ hostname: "api.github.com",
54
+ path: `/repos/${REPO}/releases/latest`,
55
+ headers: {
56
+ "User-Agent": "agentmap-npm",
57
+ },
58
+ };
59
+
60
+ https
61
+ .get(options, (res) => {
62
+ let data = "";
63
+ res.on("data", (chunk) => {
64
+ data += chunk;
65
+ });
66
+ res.on("end", () => {
67
+ try {
68
+ const json = JSON.parse(data);
69
+ resolve(json.tag_name);
70
+ } catch (e) {
71
+ reject(new Error("Failed to parse GitHub API response"));
72
+ }
73
+ });
74
+ })
75
+ .on("error", reject);
76
+ });
77
+ }
78
+
79
+ function downloadFile(url) {
80
+ return new Promise((resolve, reject) => {
81
+ const request = (targetUrl) => {
82
+ https
83
+ .get(targetUrl, (res) => {
84
+ if (res.statusCode === 301 || res.statusCode === 302) {
85
+ request(res.headers.location);
86
+ return;
87
+ }
88
+
89
+ if (res.statusCode !== 200) {
90
+ reject(new Error(`Download failed with status ${res.statusCode}`));
91
+ return;
92
+ }
93
+
94
+ resolve(res);
95
+ })
96
+ .on("error", reject);
97
+ };
98
+
99
+ request(url);
100
+ });
101
+ }
102
+
103
+ async function downloadBinary(version) {
104
+ const url = getDownloadUrl(version);
105
+ const binDir = getBinDir();
106
+
107
+ if (!fs.existsSync(binDir)) {
108
+ fs.mkdirSync(binDir, { recursive: true });
109
+ }
110
+
111
+ console.log(`Downloading agentmap ${version}...`);
112
+
113
+ const response = await downloadFile(url);
114
+
115
+ await new Promise((resolve, reject) => {
116
+ const gunzip = createGunzip();
117
+ const extract = tar.extract({
118
+ cwd: binDir,
119
+ filter: (filePath) =>
120
+ filePath === BINARY_NAME || filePath === "agentmap",
121
+ });
122
+
123
+ response
124
+ .pipe(gunzip)
125
+ .pipe(extract)
126
+ .on("finish", resolve)
127
+ .on("error", reject);
128
+ });
129
+
130
+ if (process.platform !== "win32") {
131
+ fs.chmodSync(getBinaryPath(), 0o755);
132
+ }
133
+
134
+ fs.writeFileSync(path.join(binDir, ".version"), version);
135
+
136
+ console.log(`agentmap ${version} installed successfully!`);
137
+ }
138
+
139
+ function needsDownload(version) {
140
+ const binaryPath = getBinaryPath();
141
+ const versionFile = path.join(getBinDir(), ".version");
142
+
143
+ if (!fs.existsSync(binaryPath)) {
144
+ return true;
145
+ }
146
+
147
+ if (!fs.existsSync(versionFile)) {
148
+ return true;
149
+ }
150
+
151
+ const installedVersion = fs.readFileSync(versionFile, "utf-8").trim();
152
+ return installedVersion !== version;
153
+ }
154
+
155
+ async function ensureBinary() {
156
+ const version = await getLatestVersion();
157
+
158
+ if (needsDownload(version)) {
159
+ await downloadBinary(version);
160
+ }
161
+
162
+ return getBinaryPath();
163
+ }
164
+
165
+ function runBinary(args) {
166
+ const binaryPath = getBinaryPath();
167
+
168
+ if (!fs.existsSync(binaryPath)) {
169
+ console.error(
170
+ "Binary not found. Running postinstall to download binary..."
171
+ );
172
+ require("../scripts/postinstall.js");
173
+ return;
174
+ }
175
+
176
+ const child = spawn(binaryPath, args, {
177
+ stdio: "inherit",
178
+ env: process.env,
179
+ });
180
+
181
+ child.on("error", (err) => {
182
+ console.error(`Failed to start agentmap: ${err.message}`);
183
+ process.exit(1);
184
+ });
185
+
186
+ child.on("close", (code) => {
187
+ process.exit(code || 0);
188
+ });
189
+ }
190
+
191
+ module.exports = {
192
+ getBinaryPath,
193
+ ensureBinary,
194
+ runBinary,
195
+ getLatestVersion,
196
+ downloadBinary,
197
+ };
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "agentmap-cli",
3
+ "version": "0.4.0",
4
+ "description": "Prepare codebases for AI agents by generating hierarchical documentation",
5
+ "keywords": [
6
+ "ai",
7
+ "agents",
8
+ "code-analysis",
9
+ "documentation",
10
+ "mcp",
11
+ "model-context-protocol",
12
+ "claude",
13
+ "cursor",
14
+ "opencode"
15
+ ],
16
+ "author": "Trong Nguyen <nguyenphutrong.dev@gmail.com>",
17
+ "license": "MIT",
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/nguyenphutrong/agentmap.git"
21
+ },
22
+ "homepage": "https://github.com/nguyenphutrong/agentmap#readme",
23
+ "bugs": {
24
+ "url": "https://github.com/nguyenphutrong/agentmap/issues"
25
+ },
26
+ "bin": {
27
+ "agentmap": "bin/agentmap"
28
+ },
29
+ "main": "./lib/index.js",
30
+ "files": [
31
+ "bin",
32
+ "lib",
33
+ "scripts"
34
+ ],
35
+ "scripts": {
36
+ "postinstall": "node scripts/postinstall.js"
37
+ },
38
+ "dependencies": {
39
+ "tar": "^7.0.0"
40
+ },
41
+ "engines": {
42
+ "node": ">=16.0.0"
43
+ },
44
+ "os": [
45
+ "darwin",
46
+ "linux",
47
+ "win32"
48
+ ],
49
+ "cpu": [
50
+ "x64",
51
+ "arm64"
52
+ ]
53
+ }
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { ensureBinary } = require("../lib/index.js");
4
+
5
+ ensureBinary()
6
+ .then(() => {
7
+ console.log("agentmap is ready to use!");
8
+ })
9
+ .catch((err) => {
10
+ console.error("Failed to install agentmap binary:", err.message);
11
+ console.error("");
12
+ console.error("You can install manually:");
13
+ console.error(" cargo install agentmap");
14
+ console.error("");
15
+ console.error("Or download from:");
16
+ console.error(" https://github.com/nguyenphutrong/agentmap/releases");
17
+ process.exit(1);
18
+ });