@raymondchins/agentmap 0.5.0 → 0.6.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/agentmap.mjs +72 -2
- package/package.json +1 -1
package/agentmap.mjs
CHANGED
|
@@ -17,6 +17,9 @@ import { writeFileSync, readFileSync, existsSync, mkdirSync, renameSync, readdir
|
|
|
17
17
|
import { execSync, execFileSync } from "node:child_process";
|
|
18
18
|
import { createHash } from "node:crypto";
|
|
19
19
|
import { createRequire } from "node:module";
|
|
20
|
+
import { homedir } from "node:os";
|
|
21
|
+
import { fileURLToPath } from "node:url";
|
|
22
|
+
import { join, dirname } from "node:path";
|
|
20
23
|
|
|
21
24
|
// Lazy ts-morph: its ~105ms module init only fires on a COLD rebuild. Warm cache
|
|
22
25
|
// queries (the common case) never construct a Project, so they skip the load
|
|
@@ -724,7 +727,7 @@ function parseSettings(text, settingsPath) {
|
|
|
724
727
|
try { return JSON.parse(text) || {}; }
|
|
725
728
|
catch {
|
|
726
729
|
try { return JSON.parse(stripJsonComments(text)) || {}; }
|
|
727
|
-
catch { throw new Error(`${settingsPath} is not valid JSON — fix or remove it, then re-run
|
|
730
|
+
catch { throw new Error(`${settingsPath} is not valid JSON — fix or remove it, then re-run`); }
|
|
728
731
|
}
|
|
729
732
|
}
|
|
730
733
|
|
|
@@ -843,6 +846,65 @@ function installHooks({ dryRun = false } = {}) {
|
|
|
843
846
|
console.log("\nDone — the map auto-refreshes on commit, and greps are nudged to agentmap first.");
|
|
844
847
|
}
|
|
845
848
|
|
|
849
|
+
// ---------------------------------------------------------------------------
|
|
850
|
+
// --setup-mcp: register the agentmap MCP server in the global configs of
|
|
851
|
+
// MCP-capable IDEs that aren't Claude Code (which uses --install-hooks instead).
|
|
852
|
+
// Merge-safe + idempotent; with { dryRun:true } it prints the plan and writes
|
|
853
|
+
// nothing. Throws on the first malformed config so the caller can stderr+exit 1.
|
|
854
|
+
// ---------------------------------------------------------------------------
|
|
855
|
+
function setupMcp({ dryRun = false } = {}) {
|
|
856
|
+
const mcpPath = fileURLToPath(new URL("./mcp.mjs", import.meta.url));
|
|
857
|
+
|
|
858
|
+
// npx materializes the package under a `_npx` cache dir that gets garbage-
|
|
859
|
+
// collected, so a config pointing at that path would rot. When invoked via npx,
|
|
860
|
+
// pin to the published spec instead; otherwise reference the resolved file.
|
|
861
|
+
const isNpx = mcpPath.includes("_npx");
|
|
862
|
+
const command = isNpx ? "npx" : process.execPath;
|
|
863
|
+
const args = isNpx ? ["-y", "@raymondchins/agentmap", "--mcp"] : [mcpPath];
|
|
864
|
+
|
|
865
|
+
// Each target: a global config file + how to graft the agentmap entry into it.
|
|
866
|
+
// Antigravity is written to BOTH paths on purpose — older builds read only the
|
|
867
|
+
// IDE-specific ~/.gemini/antigravity path, newer unified builds read the shared
|
|
868
|
+
// ~/.gemini/config path, so writing both is version-proof.
|
|
869
|
+
const targets = [
|
|
870
|
+
{
|
|
871
|
+
label: "OpenCode",
|
|
872
|
+
path: join(homedir(), ".config", "opencode", "opencode.json"),
|
|
873
|
+
graft: (cfg) => { (cfg.mcp ??= {}).agentmap = { type: "stdio", command, args, enabled: true }; },
|
|
874
|
+
},
|
|
875
|
+
{
|
|
876
|
+
label: "Antigravity IDE",
|
|
877
|
+
path: join(homedir(), ".gemini", "antigravity", "mcp_config.json"),
|
|
878
|
+
graft: (cfg) => { (cfg.mcpServers ??= {}).agentmap = { command, args }; },
|
|
879
|
+
},
|
|
880
|
+
{
|
|
881
|
+
label: "Antigravity (shared)",
|
|
882
|
+
path: join(homedir(), ".gemini", "config", "mcp_config.json"),
|
|
883
|
+
graft: (cfg) => { (cfg.mcpServers ??= {}).agentmap = { command, args }; },
|
|
884
|
+
},
|
|
885
|
+
];
|
|
886
|
+
|
|
887
|
+
if (dryRun) console.log("--dry-run: would configure MCP server (no changes written):");
|
|
888
|
+
|
|
889
|
+
for (const { label, path, graft } of targets) {
|
|
890
|
+
// Reuse parseSettings so JSONC (comments) is tolerated and a malformed file
|
|
891
|
+
// throws a clear error WITHOUT clobbering the original (we never write on the
|
|
892
|
+
// failure path, so no .bak dance is needed).
|
|
893
|
+
let cfg = {};
|
|
894
|
+
if (existsSync(path)) cfg = parseSettings(readFileSync(path, "utf8"), path);
|
|
895
|
+
graft(cfg);
|
|
896
|
+
|
|
897
|
+
if (dryRun) {
|
|
898
|
+
console.log(` ${label}: would write to ${path}`);
|
|
899
|
+
} else {
|
|
900
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
901
|
+
writeFileSync(path, JSON.stringify(cfg, null, 2) + "\n");
|
|
902
|
+
console.log(`configured ${label} MCP server → ${path}`);
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
|
|
907
|
+
|
|
846
908
|
// ---------------------------------------------------------------------------
|
|
847
909
|
// CLI
|
|
848
910
|
// ---------------------------------------------------------------------------
|
|
@@ -865,7 +927,7 @@ const out = (obj, prose) => { if (wantJson) console.log(JSON.stringify(obj)); el
|
|
|
865
927
|
// NOT in this set is an unknown flag → usage error (exit 2), not a silent build.
|
|
866
928
|
const KNOWN = new Set([
|
|
867
929
|
"--json", "--print",
|
|
868
|
-
"--help", "-h", "--version", "-v", "--install-hooks", "--dry-run", "--mcp",
|
|
930
|
+
"--help", "-h", "--version", "-v", "--install-hooks", "--dry-run", "--setup-mcp", "--mcp",
|
|
869
931
|
"--any", "--find", "--relates", "--map", "--focus", "--tokens",
|
|
870
932
|
"--symbols", "--feature", "--features", "--hubs",
|
|
871
933
|
]);
|
|
@@ -902,6 +964,9 @@ Maintenance:
|
|
|
902
964
|
--install-hooks [--dry-run]
|
|
903
965
|
install git post-commit + copy the PreToolUse nudge +
|
|
904
966
|
wire .claude/settings.json (--dry-run = preview, no writes)
|
|
967
|
+
--setup-mcp [--dry-run]
|
|
968
|
+
configure MCP server for OpenCode & Antigravity IDE
|
|
969
|
+
(--dry-run = preview, no writes)
|
|
905
970
|
--mcp start a stdio MCP server (for MCP-capable agents)
|
|
906
971
|
--help, -h show this help
|
|
907
972
|
--version, -v print the version
|
|
@@ -937,6 +1002,11 @@ else if (has("--install-hooks")) {
|
|
|
937
1002
|
try { installHooks({ dryRun: has("--dry-run") }); process.exit(0); }
|
|
938
1003
|
catch (e) { console.error(`agentmap --install-hooks failed: ${e?.message || e}`); process.exit(1); }
|
|
939
1004
|
}
|
|
1005
|
+
// --setup-mcp: configure MCP server for OpenCode & Antigravity IDE.
|
|
1006
|
+
else if (has("--setup-mcp")) {
|
|
1007
|
+
try { setupMcp({ dryRun: has("--dry-run") }); process.exit(0); }
|
|
1008
|
+
catch (e) { console.error(`agentmap --setup-mcp failed: ${e?.message || e}`); process.exit(1); }
|
|
1009
|
+
}
|
|
940
1010
|
// Unknown-flag guard: any "-"-prefixed token not in KNOWN → usage error (exit
|
|
941
1011
|
// 2). Runs BEFORE the bare-build fallthrough so a typo never silently rebuilds.
|
|
942
1012
|
// Bare invocation with NO flags still builds (handled in the final else).
|