glm-mcp-copilot 1.0.0 → 1.1.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/README.md CHANGED
@@ -4,7 +4,7 @@ Use the **GLM** model (Zhipu / Z.ai) as a **~10× cheaper delegate** inside **Gi
4
4
  Chat** (VS Code agent mode). It's the **same GLM MCP server** used by the Claude Code version — Copilot
5
5
  calls `glm_agent` / `glm_delegate` / `glm_recommend` / `glm_status` to offload work to GLM.
6
6
 
7
- > Sibling package: **[glm-mcp-claude](../README.md)** (the Claude Code version). Same server, different host.
7
+ > Sibling package: **[glm-mcp-claude](../claude/README.md)** (the Claude Code version). Same server, different host.
8
8
 
9
9
  ## What you get
10
10
  - The **glm MCP server** registered in VS Code (agent mode) — tools:
@@ -34,6 +34,20 @@ Run it **from your project folder** (it sets up that workspace). It:
34
34
  3. registers the server in `.vscode/mcp.json` (VS Code's `servers` format),
35
35
  4. writes `.github/copilot-instructions.md` (the delegation policy).
36
36
 
37
+ ### Global (all projects)
38
+ Set it up once for **every** workspace with `--global`:
39
+ ```bash
40
+ npx glm-mcp-copilot --global --key YOUR_ZAI_API_KEY
41
+ ```
42
+ Global mode writes to VS Code's **user config** instead of one workspace:
43
+ - the `glm` server → the **user `mcp.json`** (available in all workspaces), and
44
+ - the delegation policy → **user `settings.json`** (`github.copilot.chat.codeGeneration.instructions`).
45
+
46
+ > The global **server** is reliable across VS Code versions. The global **instructions** setting is
47
+ > VS-Code-version-dependent (its exact key is evolving) — if Copilot ignores it in your version, the
48
+ > tools are still there; just nudge it ("use glm_agent to…"), or add a repo `.github/copilot-instructions.md`.
49
+ > Use `--vscode-user-dir PATH` if your VS Code User folder isn't auto-detected (Insiders/VSCodium/portable).
50
+
37
51
  Then in VS Code: **Reload Window → open Copilot Chat → Agent mode → start the `glm` server** (`MCP: List
38
52
  Servers`). Ask Copilot to do a coding task; it will call `glm_agent`.
39
53
 
@@ -6,8 +6,10 @@
6
6
  //
7
7
  // Usage:
8
8
  // node install-copilot.mjs --key YOUR_ZAI_KEY # set up in the current workspace
9
- // node install-copilot.mjs --workspace PATH # target another project folder
9
+ // node install-copilot.mjs --global --key YOUR_ZAI_KEY # set up for ALL workspaces (VS Code user config)
10
+ // node install-copilot.mjs --workspace PATH # target another project folder (workspace mode)
10
11
  // node install-copilot.mjs --server-dir PATH # where to install the server (default ~/.glm-mcp)
12
+ // node install-copilot.mjs --vscode-user-dir PATH # override VS Code User dir (for --global)
11
13
  // node install-copilot.mjs --skip-npm
12
14
 
13
15
  import { cpSync, mkdirSync, existsSync, readFileSync, writeFileSync, copyFileSync } from "node:fs";
@@ -25,13 +27,30 @@ const SERVER_HOME = getOpt("--server-dir") || join(homedir(), ".glm-mcp");
25
27
  const WORKSPACE = getOpt("--workspace") || process.cwd();
26
28
  const KEY = getOpt("--key") || process.env.GLM_API_KEY || "";
27
29
  const SKIP_NPM = getFlag("--skip-npm");
30
+ const GLOBAL = getFlag("--global");
28
31
 
29
32
  const log = (s) => console.log(s);
30
33
  const step = (s) => console.log("\n→ " + s);
31
34
 
32
- log("GLM-for-Copilot installer");
35
+ // Resolve the VS Code User config dir (for --global). Prefers stable "Code", falls back to Insiders.
36
+ function vscodeUserDir() {
37
+ const override = getOpt("--vscode-user-dir");
38
+ if (override) return override;
39
+ const home = homedir();
40
+ const roots =
41
+ process.platform === "win32"
42
+ ? [process.env.APPDATA || join(home, "AppData", "Roaming")]
43
+ : process.platform === "darwin"
44
+ ? [join(home, "Library", "Application Support")]
45
+ : [join(home, ".config")];
46
+ const cands = [];
47
+ for (const r of roots) for (const app of ["Code", "Code - Insiders", "VSCodium"]) cands.push(join(r, app, "User"));
48
+ return cands.find(existsSync) || cands[0];
49
+ }
50
+
51
+ log("GLM-for-Copilot installer" + (GLOBAL ? " (GLOBAL — all workspaces)" : ""));
33
52
  log(" server : " + join(SERVER_HOME, "glm-mcp"));
34
- log(" workspace : " + WORKSPACE);
53
+ log(GLOBAL ? " scope : all VS Code workspaces (user config)" : " workspace : " + WORKSPACE);
35
54
 
36
55
  // 1. Install the shared MCP server (skip node_modules/.env/usage.jsonl).
37
56
  step("Installing the GLM MCP server");
@@ -63,34 +82,67 @@ if (!SKIP_NPM) {
63
82
  execSync("npm install --no-audit --no-fund", { cwd: join(SERVER_HOME, "glm-mcp"), stdio: "inherit" });
64
83
  }
65
84
 
66
- // 4. Register the server in VS Code (workspace .vscode/mcp.json). VS Code uses the "servers" key.
67
- step("Registering the glm server in VS Code (.vscode/mcp.json)");
85
+ // 4 & 5. Register the server + delegation policy — globally (all workspaces) or in this workspace.
68
86
  const idx = join(SERVER_HOME, "glm-mcp", "src", "index.js").replace(/\\/g, "/");
69
- const vscodeDir = join(WORKSPACE, ".vscode");
70
- mkdirSync(vscodeDir, { recursive: true });
71
- const mcpPath = join(vscodeDir, "mcp.json");
72
- let mcp = {};
73
- if (existsSync(mcpPath)) {
74
- try { mcp = JSON.parse(readFileSync(mcpPath, "utf8")); } catch { mcp = {}; }
75
- writeFileSync(mcpPath + ".bak-" + Date.now(), readFileSync(mcpPath));
87
+
88
+ function mergeMcp(mcpPath) {
89
+ mkdirSync(dirname(mcpPath), { recursive: true });
90
+ let mcp = {};
91
+ if (existsSync(mcpPath)) {
92
+ try { mcp = JSON.parse(readFileSync(mcpPath, "utf8")); } catch { mcp = {}; }
93
+ writeFileSync(mcpPath + ".bak-" + Date.now(), readFileSync(mcpPath));
94
+ }
95
+ mcp.servers ||= {};
96
+ mcp.servers.glm = { type: "stdio", command: "node", args: [idx] };
97
+ writeFileSync(mcpPath, JSON.stringify(mcp, null, 2) + "\n");
98
+ return mcpPath;
76
99
  }
77
- mcp.servers ||= {};
78
- mcp.servers.glm = { type: "stdio", command: "node", args: [idx] };
79
- writeFileSync(mcpPath, JSON.stringify(mcp, null, 2) + "\n");
80
- log(" " + mcpPath);
81
-
82
- // 5. Copilot instructions (workspace .github/copilot-instructions.md).
83
- step("Adding delegation policy (.github/copilot-instructions.md)");
84
- const ghDir = join(WORKSPACE, ".github");
85
- mkdirSync(ghDir, { recursive: true });
86
- const ciPath = join(ghDir, "copilot-instructions.md");
87
- const policy = readFileSync(join(SELF, "copilot-instructions.md"), "utf8");
88
- const existing = existsSync(ciPath) ? readFileSync(ciPath, "utf8") : "";
89
- if (!existing.includes("glm_agent")) {
90
- writeFileSync(ciPath, existing + (existing ? "\n\n" : "") + policy);
91
- log(" " + ciPath);
100
+
101
+ const CONCISE_POLICY =
102
+ "GLM delegation: prefer the glm MCP tools. For any coding / edit / refactor / test / docs task, call " +
103
+ "glm_agent with the goal + the absolute repo path (workdir) so GLM does it end-to-end on GLM tokens " +
104
+ "(~10x cheaper) — don't do the file work yourself when GLM can. Use glm_delegate for pure text. Keep " +
105
+ "sensitive/secret code, vision, parallel work, >128K context, and heavy dependent tool-loops on the " +
106
+ "default model. Run glm_status for the GLM usage ledger.";
107
+
108
+ if (GLOBAL) {
109
+ const userDir = vscodeUserDir();
110
+ step("Registering glm GLOBALLY (VS Code user mcp.json) -> " + userDir);
111
+ log(" " + mergeMcp(join(userDir, "mcp.json")));
112
+
113
+ step("Adding GLOBAL Copilot instructions (VS Code user settings.json)");
114
+ const setPath = join(userDir, "settings.json");
115
+ let settings = {};
116
+ if (existsSync(setPath)) {
117
+ try { settings = JSON.parse(readFileSync(setPath, "utf8")); } catch { settings = {}; }
118
+ writeFileSync(setPath + ".bak-" + Date.now(), readFileSync(setPath));
119
+ }
120
+ const K = "github.copilot.chat.codeGeneration.instructions";
121
+ const arr = Array.isArray(settings[K]) ? settings[K] : [];
122
+ if (!arr.some((e) => e && typeof e.text === "string" && e.text.includes("glm_agent"))) {
123
+ arr.push({ text: CONCISE_POLICY });
124
+ settings[K] = arr;
125
+ writeFileSync(setPath, JSON.stringify(settings, null, 2) + "\n");
126
+ log(" added to " + setPath);
127
+ } else {
128
+ log(" policy already present");
129
+ }
92
130
  } else {
93
- log(" policy already present (left as-is)");
131
+ step("Registering the glm server in VS Code (workspace .vscode/mcp.json)");
132
+ log(" " + mergeMcp(join(WORKSPACE, ".vscode", "mcp.json")));
133
+
134
+ step("Adding delegation policy (workspace .github/copilot-instructions.md)");
135
+ const ghDir = join(WORKSPACE, ".github");
136
+ mkdirSync(ghDir, { recursive: true });
137
+ const ciPath = join(ghDir, "copilot-instructions.md");
138
+ const policy = readFileSync(join(SELF, "copilot-instructions.md"), "utf8");
139
+ const existing = existsSync(ciPath) ? readFileSync(ciPath, "utf8") : "";
140
+ if (!existing.includes("glm_agent")) {
141
+ writeFileSync(ciPath, existing + (existing ? "\n\n" : "") + policy);
142
+ log(" " + ciPath);
143
+ } else {
144
+ log(" policy already present (left as-is)");
145
+ }
94
146
  }
95
147
 
96
148
  log("\n✅ Done. Next steps:");
@@ -98,5 +150,8 @@ log(" 1. Ensure GLM_API_KEY is set in " + envPath);
98
150
  log(" 2. In VS Code: Reload Window, open Copilot Chat, switch to Agent mode.");
99
151
  log(" 3. Start the 'glm' server: run 'MCP: List Servers' (or VS Code will offer to start it).");
100
152
  log(" 4. Ask Copilot to do a coding task — it will call glm_agent. Run glm_status for the GLM usage ledger.");
101
- log("\nNote: this sets up the CURRENT workspace. For all projects, run 'MCP: Open User Configuration' in");
102
- log("VS Code and add the same 'glm' server block (see mcp.json.example).");
153
+ log(
154
+ GLOBAL
155
+ ? "\nGLOBAL mode: the glm server + delegation policy now apply to ALL your VS Code workspaces."
156
+ : "\nWorkspace mode: current project only. Re-run with --global to apply to every project."
157
+ );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "glm-mcp-copilot",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "GLM (Zhipu/Z.ai) as a cheap delegate for GitHub Copilot / Copilot Chat in VS Code — the same GLM MCP tools (glm_agent/glm_delegate/glm_recommend/glm_status) wired into VS Code agent mode.",
5
5
  "type": "module",
6
6
  "bin": {