glm-mcp-copilot 1.1.0 → 1.2.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 +20 -11
- package/glm.agent.md +22 -0
- package/glm.instructions.md +18 -0
- package/install-copilot.mjs +39 -24
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -12,7 +12,9 @@ calls `glm_agent` / `glm_delegate` / `glm_recommend` / `glm_status` to offload w
|
|
|
12
12
|
- **`glm_delegate`** — GLM drafts text you place.
|
|
13
13
|
- **`glm_recommend`** — free advisory: GLM vs the default model.
|
|
14
14
|
- **`glm_status`** — usage ledger (proof of GLM tokens spent) + config.
|
|
15
|
-
- A
|
|
15
|
+
- A **`GLM` custom agent (subagent)** — restricted to the `glm` tools, so it *must* delegate to GLM
|
|
16
|
+
(the Copilot analog of the Claude `glm` subagent). Pick it from the chat mode dropdown or hand off to it.
|
|
17
|
+
- A **delegation-policy instructions file** so Copilot offloads to GLM automatically.
|
|
16
18
|
|
|
17
19
|
## Prerequisites
|
|
18
20
|
- **VS Code** with **GitHub Copilot + Copilot Chat**, and **Agent mode** available (MCP support).
|
|
@@ -32,7 +34,8 @@ Run it **from your project folder** (it sets up that workspace). It:
|
|
|
32
34
|
1. installs the GLM MCP server to `~/.glm-mcp/glm-mcp/` and runs `npm install`,
|
|
33
35
|
2. writes your key to that server's `.env`,
|
|
34
36
|
3. registers the server in `.vscode/mcp.json` (VS Code's `servers` format),
|
|
35
|
-
4.
|
|
37
|
+
4. installs the **`GLM` custom agent** → `.github/agents/glm.agent.md`,
|
|
38
|
+
5. writes `.github/copilot-instructions.md` (the delegation policy).
|
|
36
39
|
|
|
37
40
|
### Global (all projects)
|
|
38
41
|
Set it up once for **every** workspace with `--global`:
|
|
@@ -40,22 +43,28 @@ Set it up once for **every** workspace with `--global`:
|
|
|
40
43
|
npx glm-mcp-copilot --global --key YOUR_ZAI_API_KEY
|
|
41
44
|
```
|
|
42
45
|
Global mode writes to VS Code's **user config** instead of one workspace:
|
|
43
|
-
- the `glm` server → the **user `mcp.json`** (
|
|
44
|
-
- the
|
|
46
|
+
- the `glm` server → the **user `mcp.json`** (all workspaces),
|
|
47
|
+
- the **`GLM` custom agent** → `~/.copilot/agents/glm.agent.md`,
|
|
48
|
+
- the delegation policy → `~/.copilot/instructions/glm.instructions.md` (with `applyTo: '**'`),
|
|
49
|
+
- and it registers those locations + enables agent mode in **user `settings.json`**
|
|
50
|
+
(`chat.agentFilesLocations`, `chat.instructionsFilesLocations`, `chat.agent.enabled`).
|
|
45
51
|
|
|
46
|
-
>
|
|
47
|
-
>
|
|
48
|
-
> tools are still there; just nudge it ("use glm_agent to…"), or add a repo `.github/copilot-instructions.md`.
|
|
52
|
+
> Uses the current (non-deprecated) instructions mechanism — `.instructions.md` files, **not** the old
|
|
53
|
+
> `codeGeneration.instructions` settings array (deprecated in VS Code 1.102; the installer migrates off it).
|
|
49
54
|
> Use `--vscode-user-dir PATH` if your VS Code User folder isn't auto-detected (Insiders/VSCodium/portable).
|
|
50
55
|
|
|
51
56
|
Then in VS Code: **Reload Window → open Copilot Chat → Agent mode → start the `glm` server** (`MCP: List
|
|
52
57
|
Servers`). Ask Copilot to do a coding task; it will call `glm_agent`.
|
|
53
58
|
|
|
54
59
|
## How it differs from the Claude Code version
|
|
55
|
-
Copilot
|
|
56
|
-
|
|
57
|
-
-
|
|
58
|
-
|
|
60
|
+
Near-parity — Copilot **does** have subagents (custom agents):
|
|
61
|
+
- **`glm_*` MCP tools** in **agent mode** (same server as the Claude edition).
|
|
62
|
+
- A **`GLM` custom agent (subagent)** restricted to the `glm` tools — the analog of the Claude `glm`
|
|
63
|
+
subagent (forced to delegate to GLM). Invoke it from the mode dropdown or via an agent handoff.
|
|
64
|
+
- **Instructions files** steer delegation (the CLAUDE.md equivalent).
|
|
65
|
+
|
|
66
|
+
The only thing Copilot lacks is Claude Code's **PreToolUse hook** (auto-routing on every subagent
|
|
67
|
+
spawn) — so in Copilot, delegation is driven by the subagent + instructions rather than a hook.
|
|
59
68
|
|
|
60
69
|
Everything else — the GLM agent loop, peak-aware model pick, cost bias, token cap, usage ledger,
|
|
61
70
|
`dry_run` oversight — is the **same server**, so it behaves identically once a tool is called.
|
package/glm.agent.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: GLM
|
|
3
|
+
description: Cheap GLM delegate — offloads coding/edit/refactor/test/docs work to the GLM model (~10x cheaper than the default) via the glm MCP server. Use for well-specified, self-contained tasks; keep sensitive/vision/parallel/huge-context/heavy-tool-loop work on the default model.
|
|
4
|
+
tools: ['glm/*']
|
|
5
|
+
user-invocable: true
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
You are the **GLM delegate**. You have ONLY the `glm` MCP server's tools — **you cannot edit files or
|
|
9
|
+
run commands yourself**, so you must route all real work through GLM (this keeps the work, and the
|
|
10
|
+
tokens, on GLM — ~10× cheaper than the default model).
|
|
11
|
+
|
|
12
|
+
## How you work
|
|
13
|
+
1. **Do the work via GLM.** For any coding / edit / refactor / test / docs task, call **`glm/glm_agent`**
|
|
14
|
+
with the goal + the **absolute repo path** (`workdir`). GLM reads, writes, edits, and runs the files
|
|
15
|
+
itself, end-to-end. For pure text, use **`glm/glm_delegate`**.
|
|
16
|
+
2. **Check fit when unsure.** Call **`glm/glm_recommend`**; if it says the task should stay on the
|
|
17
|
+
default model (sensitive, vision, parallel, >128K context, heavy dependent tool-loops), say so and stop.
|
|
18
|
+
3. **Report the GLM stats.** Surface the `=== GLM STATS ===` block `glm_agent` returns (model + tokens
|
|
19
|
+
delegated + cost) so it's clear GLM did the work and how much it spent. Run **`glm/glm_status`** for
|
|
20
|
+
the cumulative usage ledger.
|
|
21
|
+
|
|
22
|
+
Never claim to have done work you didn't route through GLM — you have no other tools.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
---
|
|
2
|
+
applyTo: '**'
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# GLM delegation
|
|
6
|
+
|
|
7
|
+
The **glm** MCP server is available in agent mode (`glm_agent`, `glm_delegate`, `glm_recommend`,
|
|
8
|
+
`glm_status`). GLM (Zhipu/Z.ai) is **~10× cheaper** than the default model — offload work to it.
|
|
9
|
+
|
|
10
|
+
- For any implementation / codegen / edit / refactor / test / docs task, call **`glm_agent`** with the
|
|
11
|
+
goal + the absolute repo path (`workdir`) so GLM does it end-to-end on **GLM tokens** — or hand it to
|
|
12
|
+
the **GLM** custom agent (subagent). Prefer this over doing the file work yourself.
|
|
13
|
+
- Use **`glm_delegate`** for pure text.
|
|
14
|
+
- **To actually spend GLM tokens (not the default model's), call the glm tools — don't do the work
|
|
15
|
+
inline yourself.**
|
|
16
|
+
- Keep on the default model: sensitive/secret code, vision/images, parallel work, very large context
|
|
17
|
+
(>128K), and heavy dependent tool-loops. Unsure? call **`glm_recommend`**.
|
|
18
|
+
- `glm_status` shows the GLM usage ledger — proof of GLM tokens spent.
|
package/install-copilot.mjs
CHANGED
|
@@ -82,8 +82,11 @@ if (!SKIP_NPM) {
|
|
|
82
82
|
execSync("npm install --no-audit --no-fund", { cwd: join(SERVER_HOME, "glm-mcp"), stdio: "inherit" });
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
-
// 4
|
|
85
|
+
// 4-6. Register the server, the `glm` custom agent (subagent), and the delegation policy —
|
|
86
|
+
// globally (all workspaces) or in this workspace.
|
|
86
87
|
const idx = join(SERVER_HOME, "glm-mcp", "src", "index.js").replace(/\\/g, "/");
|
|
88
|
+
const AGENTS_HOME = join(homedir(), ".copilot", "agents"); // global custom-agent location
|
|
89
|
+
const INSTR_HOME = join(homedir(), ".copilot", "instructions"); // global instructions location
|
|
87
90
|
|
|
88
91
|
function mergeMcp(mcpPath) {
|
|
89
92
|
mkdirSync(dirname(mcpPath), { recursive: true });
|
|
@@ -97,51 +100,62 @@ function mergeMcp(mcpPath) {
|
|
|
97
100
|
writeFileSync(mcpPath, JSON.stringify(mcp, null, 2) + "\n");
|
|
98
101
|
return mcpPath;
|
|
99
102
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
"default model. Run glm_status for the GLM usage ledger.";
|
|
103
|
+
function copyInto(dir, srcFile) {
|
|
104
|
+
mkdirSync(dir, { recursive: true });
|
|
105
|
+
const dest = join(dir, srcFile);
|
|
106
|
+
copyFileSync(join(SELF, srcFile), dest);
|
|
107
|
+
return dest;
|
|
108
|
+
}
|
|
107
109
|
|
|
108
110
|
if (GLOBAL) {
|
|
109
111
|
const userDir = vscodeUserDir();
|
|
110
112
|
step("Registering glm GLOBALLY (VS Code user mcp.json) -> " + userDir);
|
|
111
113
|
log(" " + mergeMcp(join(userDir, "mcp.json")));
|
|
112
114
|
|
|
113
|
-
step("
|
|
115
|
+
step("Installing the GLM custom agent (subagent) -> " + AGENTS_HOME);
|
|
116
|
+
log(" " + copyInto(AGENTS_HOME, "glm.agent.md"));
|
|
117
|
+
|
|
118
|
+
step("Installing GLOBAL Copilot instructions -> " + INSTR_HOME);
|
|
119
|
+
log(" " + copyInto(INSTR_HOME, "glm.instructions.md"));
|
|
120
|
+
|
|
121
|
+
step("Updating VS Code user settings.json (locations + toggles)");
|
|
114
122
|
const setPath = join(userDir, "settings.json");
|
|
115
123
|
let settings = {};
|
|
116
124
|
if (existsSync(setPath)) {
|
|
117
125
|
try { settings = JSON.parse(readFileSync(setPath, "utf8")); } catch { settings = {}; }
|
|
118
126
|
writeFileSync(setPath + ".bak-" + Date.now(), readFileSync(setPath));
|
|
119
127
|
}
|
|
120
|
-
const
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
128
|
+
const agentsGlob = AGENTS_HOME.replace(/\\/g, "/");
|
|
129
|
+
const instrGlob = INSTR_HOME.replace(/\\/g, "/");
|
|
130
|
+
settings["chat.agentFilesLocations"] = { ...(settings["chat.agentFilesLocations"] || {}), [agentsGlob]: true };
|
|
131
|
+
settings["chat.instructionsFilesLocations"] = { ...(settings["chat.instructionsFilesLocations"] || {}), [instrGlob]: true };
|
|
132
|
+
settings["github.copilot.chat.codeGeneration.useInstructionFiles"] = true;
|
|
133
|
+
settings["chat.agent.enabled"] = true;
|
|
134
|
+
// Migrate off the deprecated inline-instructions setting (remove our old entry if present).
|
|
135
|
+
const DEP = "github.copilot.chat.codeGeneration.instructions";
|
|
136
|
+
if (Array.isArray(settings[DEP])) {
|
|
137
|
+
settings[DEP] = settings[DEP].filter((e) => !(e && typeof e.text === "string" && e.text.includes("glm_agent")));
|
|
138
|
+
if (settings[DEP].length === 0) delete settings[DEP];
|
|
129
139
|
}
|
|
140
|
+
writeFileSync(setPath, JSON.stringify(settings, null, 2) + "\n");
|
|
141
|
+
log(" " + setPath);
|
|
130
142
|
} else {
|
|
131
143
|
step("Registering the glm server in VS Code (workspace .vscode/mcp.json)");
|
|
132
144
|
log(" " + mergeMcp(join(WORKSPACE, ".vscode", "mcp.json")));
|
|
133
145
|
|
|
146
|
+
step("Installing the GLM custom agent (subagent) -> .github/agents/");
|
|
147
|
+
log(" " + copyInto(join(WORKSPACE, ".github", "agents"), "glm.agent.md"));
|
|
148
|
+
|
|
134
149
|
step("Adding delegation policy (workspace .github/copilot-instructions.md)");
|
|
135
|
-
const
|
|
136
|
-
mkdirSync(
|
|
137
|
-
const ciPath = join(ghDir, "copilot-instructions.md");
|
|
150
|
+
const ciPath = join(WORKSPACE, ".github", "copilot-instructions.md");
|
|
151
|
+
mkdirSync(dirname(ciPath), { recursive: true });
|
|
138
152
|
const policy = readFileSync(join(SELF, "copilot-instructions.md"), "utf8");
|
|
139
153
|
const existing = existsSync(ciPath) ? readFileSync(ciPath, "utf8") : "";
|
|
140
154
|
if (!existing.includes("glm_agent")) {
|
|
141
155
|
writeFileSync(ciPath, existing + (existing ? "\n\n" : "") + policy);
|
|
142
156
|
log(" " + ciPath);
|
|
143
157
|
} else {
|
|
144
|
-
log("
|
|
158
|
+
log(" copilot-instructions.md already has the policy");
|
|
145
159
|
}
|
|
146
160
|
}
|
|
147
161
|
|
|
@@ -149,9 +163,10 @@ log("\n✅ Done. Next steps:");
|
|
|
149
163
|
log(" 1. Ensure GLM_API_KEY is set in " + envPath);
|
|
150
164
|
log(" 2. In VS Code: Reload Window, open Copilot Chat, switch to Agent mode.");
|
|
151
165
|
log(" 3. Start the 'glm' server: run 'MCP: List Servers' (or VS Code will offer to start it).");
|
|
152
|
-
log(" 4.
|
|
166
|
+
log(" 4. Use it: pick the 'GLM' agent in the chat mode dropdown, or ask the main agent to");
|
|
167
|
+
log(" 'use glm_agent to …'. Run glm_status for the GLM usage ledger.");
|
|
153
168
|
log(
|
|
154
169
|
GLOBAL
|
|
155
|
-
? "\nGLOBAL mode: the glm server
|
|
170
|
+
? "\nGLOBAL mode: the glm server, GLM subagent, and delegation policy now apply to ALL your VS Code workspaces."
|
|
156
171
|
: "\nWorkspace mode: current project only. Re-run with --global to apply to every project."
|
|
157
172
|
);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "glm-mcp-copilot",
|
|
3
|
-
"version": "1.
|
|
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.",
|
|
3
|
+
"version": "1.2.0",
|
|
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) plus a GLM custom agent (subagent), wired into VS Code agent mode, installable globally.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
7
|
"glm-mcp-copilot": "install-copilot.mjs"
|
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
"files": [
|
|
10
10
|
"glm-mcp/",
|
|
11
11
|
"install-copilot.mjs",
|
|
12
|
+
"glm.agent.md",
|
|
13
|
+
"glm.instructions.md",
|
|
12
14
|
"copilot-instructions.md",
|
|
13
15
|
"mcp.json.example",
|
|
14
16
|
"README.md",
|