@uncarved/jade 0.3.0 → 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.
Files changed (207) hide show
  1. package/README.md +1 -0
  2. package/dist/api.d.ts +1 -1
  3. package/dist/api.js +1 -1
  4. package/dist/host.d.ts +2 -0
  5. package/dist/host.js +39 -5
  6. package/dist/host.js.map +1 -1
  7. package/dist/remote.js +5 -0
  8. package/dist/remote.js.map +1 -1
  9. package/dist/session.d.ts +7 -0
  10. package/dist/session.js +482 -27
  11. package/dist/session.js.map +1 -1
  12. package/package.json +4 -4
  13. package/plugins/approval/index.ts +49 -24
  14. package/plugins/approval/policy.ts +48 -25
  15. package/plugins/approval/review.ts +9 -5
  16. package/plugins/checks/checks.ts +10 -7
  17. package/plugins/checks/index.ts +13 -13
  18. package/plugins/checks/plugin.json +1 -1
  19. package/plugins/checks/project.ts +37 -38
  20. package/plugins/commands/index.ts +27 -3
  21. package/plugins/compact/compact.ts +13 -5
  22. package/plugins/compact/index.ts +20 -3
  23. package/plugins/compact/style.ts +13 -14
  24. package/plugins/completions/index.ts +35 -0
  25. package/plugins/completions/plugin.json +7 -0
  26. package/plugins/copy/index.ts +46 -0
  27. package/plugins/copy/plugin.json +7 -0
  28. package/plugins/editor/index.ts +10 -4
  29. package/plugins/fs/diff.ts +7 -6
  30. package/plugins/fs/fs.ts +8 -4
  31. package/plugins/fs/grep.ts +55 -12
  32. package/plugins/fs/index.ts +2 -7
  33. package/plugins/fs/plugin.json +1 -1
  34. package/plugins/fs/renderers.ts +16 -15
  35. package/plugins/fs/style.ts +16 -15
  36. package/plugins/hooks/index.ts +3 -2
  37. package/plugins/keys/index.ts +5 -1
  38. package/plugins/mcp/index.ts +197 -78
  39. package/plugins/mcp/install.ts +5 -3
  40. package/plugins/mcp/mcp.ts +163 -11
  41. package/plugins/mcp/plugin.json +2 -1
  42. package/plugins/mcp/project.ts +47 -50
  43. package/plugins/memory/index.ts +4 -4
  44. package/plugins/memory/style.ts +13 -14
  45. package/plugins/mentions/candidates.ts +67 -0
  46. package/plugins/mentions/index.ts +12 -5
  47. package/plugins/mentions/plugin.json +1 -1
  48. package/plugins/mentions/style.ts +13 -14
  49. package/plugins/models/configure.ts +10 -9
  50. package/plugins/models/index.ts +31 -4
  51. package/plugins/models/provider.ts +12 -1
  52. package/plugins/modes/index.ts +13 -2
  53. package/plugins/print/index.ts +7 -4
  54. package/plugins/prompts/index.ts +0 -0
  55. package/plugins/renderers/index.ts +10 -5
  56. package/plugins/repeats/index.ts +39 -9
  57. package/plugins/schedule/index.ts +2 -0
  58. package/plugins/screenshot/browser.ts +231 -0
  59. package/plugins/screenshot/index.ts +3 -2
  60. package/plugins/screenshot/tool.ts +27 -51
  61. package/plugins/sessions/index.ts +48 -2
  62. package/plugins/shell/index.ts +75 -22
  63. package/plugins/shell/plugin.json +1 -2
  64. package/plugins/shell/renderers.ts +9 -7
  65. package/plugins/shell/shell.ts +93 -34
  66. package/plugins/skills/index.ts +28 -19
  67. package/plugins/skills/project.ts +12 -7
  68. package/plugins/steer/index.ts +5 -4
  69. package/plugins/task/index.ts +81 -81
  70. package/plugins/task/plugin.json +5 -2
  71. package/plugins/task/style.ts +13 -14
  72. package/plugins/task/subagent.ts +67 -184
  73. package/plugins/todo/index.ts +39 -9
  74. package/plugins/tools/index.ts +57 -0
  75. package/plugins/tools/plugin.json +7 -0
  76. package/plugins/tui/frontend.ts +161 -87
  77. package/plugins/tui/index.ts +2 -3
  78. package/plugins/tui/mascot.ts +8 -7
  79. package/plugins/tui/mentions.ts +11 -80
  80. package/plugins/tui/plugin.json +1 -1
  81. package/plugins/tui/screen.ts +55 -5
  82. package/plugins/tui/transcript.ts +17 -7
  83. package/plugins/tui/tui.ts +356 -104
  84. package/plugins/tui/vendor.ts +1 -1
  85. package/plugins/undo/checkpoint.ts +5 -3
  86. package/plugins/undo/index.ts +43 -14
  87. package/plugins/undo/style.ts +13 -14
  88. package/plugins/web/index.ts +7 -18
  89. package/plugins/web/plugin.json +1 -1
  90. package/plugins-dist/approval/index.js +363 -414
  91. package/plugins-dist/approval/policy.js +395 -497
  92. package/plugins-dist/approval/review.js +132 -158
  93. package/plugins-dist/approval/schema.js +50 -55
  94. package/plugins-dist/ask/index.js +115 -129
  95. package/plugins-dist/budget/index.js +27 -31
  96. package/plugins-dist/checks/checks.js +293 -329
  97. package/plugins-dist/checks/index.js +119 -139
  98. package/plugins-dist/checks/plugin.json +2 -1
  99. package/plugins-dist/checks/project.js +57 -65
  100. package/plugins-dist/commands/index.js +47 -29
  101. package/plugins-dist/compact/compact.js +233 -249
  102. package/plugins-dist/compact/index.js +98 -95
  103. package/plugins-dist/compact/style.js +9 -14
  104. package/plugins-dist/completions/index.js +30 -0
  105. package/plugins-dist/completions/plugin.json +9 -0
  106. package/plugins-dist/continue/index.js +40 -52
  107. package/plugins-dist/copy/index.js +40 -0
  108. package/plugins-dist/copy/plugin.json +9 -0
  109. package/plugins-dist/cost/index.js +98 -115
  110. package/plugins-dist/custom-commands/index.js +55 -72
  111. package/plugins-dist/editor/index.js +64 -72
  112. package/plugins-dist/fs/diff.js +111 -124
  113. package/plugins-dist/fs/fs.js +426 -469
  114. package/plugins-dist/fs/grep.js +262 -244
  115. package/plugins-dist/fs/index.js +20 -34
  116. package/plugins-dist/fs/plugin.json +1 -2
  117. package/plugins-dist/fs/renderers.js +100 -112
  118. package/plugins-dist/fs/style.js +11 -15
  119. package/plugins-dist/fs/sys.js +31 -43
  120. package/plugins-dist/hooks/index.js +107 -127
  121. package/plugins-dist/keys/index.js +27 -31
  122. package/plugins-dist/mcp/index.js +271 -199
  123. package/plugins-dist/mcp/install.js +123 -137
  124. package/plugins-dist/mcp/mcp.js +638 -577
  125. package/plugins-dist/mcp/plugin.json +3 -1
  126. package/plugins-dist/mcp/project.js +98 -115
  127. package/plugins-dist/memory/index.js +83 -88
  128. package/plugins-dist/memory/memory.js +111 -128
  129. package/plugins-dist/memory/style.js +9 -14
  130. package/plugins-dist/mentions/attach.js +91 -99
  131. package/plugins-dist/mentions/candidates.js +49 -0
  132. package/plugins-dist/mentions/index.js +71 -81
  133. package/plugins-dist/mentions/plugin.json +2 -1
  134. package/plugins-dist/mentions/style.js +9 -14
  135. package/plugins-dist/models/config.js +29 -43
  136. package/plugins-dist/models/configure.js +392 -473
  137. package/plugins-dist/models/context.js +14 -22
  138. package/plugins-dist/models/index.js +182 -188
  139. package/plugins-dist/models/provider.js +243 -295
  140. package/plugins-dist/models/saved.js +59 -71
  141. package/plugins-dist/modes/index.js +138 -165
  142. package/plugins-dist/plugins/index.js +34 -34
  143. package/plugins-dist/print/index.js +192 -175
  144. package/plugins-dist/prompts/index.js +81 -89
  145. package/plugins-dist/prompts/notes.js +31 -37
  146. package/plugins-dist/prompts/prompts.js +155 -193
  147. package/plugins-dist/prompts/results.js +40 -53
  148. package/plugins-dist/prompts/sys.js +39 -50
  149. package/plugins-dist/renderers/index.js +32 -32
  150. package/plugins-dist/repeats/index.js +134 -151
  151. package/plugins-dist/schedule/cron.js +49 -56
  152. package/plugins-dist/schedule/index.js +229 -247
  153. package/plugins-dist/schedule/store.js +93 -109
  154. package/plugins-dist/scratch/index.js +12 -18
  155. package/plugins-dist/screenshot/browser.js +169 -0
  156. package/plugins-dist/screenshot/index.js +37 -45
  157. package/plugins-dist/screenshot/sys.js +53 -65
  158. package/plugins-dist/screenshot/tool.js +101 -151
  159. package/plugins-dist/sessions/index.js +149 -117
  160. package/plugins-dist/shell/index.js +117 -74
  161. package/plugins-dist/shell/plugin.json +1 -2
  162. package/plugins-dist/shell/renderers.js +28 -33
  163. package/plugins-dist/shell/service.js +17 -23
  164. package/plugins-dist/shell/shell.js +317 -320
  165. package/plugins-dist/shell/sys.js +64 -79
  166. package/plugins-dist/skills/index.js +193 -211
  167. package/plugins-dist/skills/install.js +122 -149
  168. package/plugins-dist/skills/project.js +65 -73
  169. package/plugins-dist/skills/skills.js +135 -171
  170. package/plugins-dist/steer/index.js +108 -125
  171. package/plugins-dist/suggest/index.js +235 -259
  172. package/plugins-dist/task/index.js +130 -148
  173. package/plugins-dist/task/plugin.json +5 -4
  174. package/plugins-dist/task/style.js +9 -14
  175. package/plugins-dist/task/subagent.js +156 -279
  176. package/plugins-dist/todo/index.js +79 -63
  177. package/plugins-dist/tools/index.js +43 -0
  178. package/plugins-dist/tools/plugin.json +9 -0
  179. package/plugins-dist/tui/editor.js +145 -160
  180. package/plugins-dist/tui/frontend.js +641 -655
  181. package/plugins-dist/tui/history.js +34 -37
  182. package/plugins-dist/tui/index.js +16 -18
  183. package/plugins-dist/tui/markdown.js +203 -247
  184. package/plugins-dist/tui/mascot.js +266 -353
  185. package/plugins-dist/tui/mentions.js +67 -144
  186. package/plugins-dist/tui/plugin.json +1 -2
  187. package/plugins-dist/tui/render.js +35 -45
  188. package/plugins-dist/tui/screen.js +197 -180
  189. package/plugins-dist/tui/transcript.js +436 -468
  190. package/plugins-dist/tui/tui.js +1554 -1645
  191. package/plugins-dist/tui/vendor.js +1388 -1088
  192. package/plugins-dist/undo/checkpoint.js +95 -118
  193. package/plugins-dist/undo/index.js +185 -192
  194. package/plugins-dist/undo/snapshot.js +83 -99
  195. package/plugins-dist/undo/style.js +9 -14
  196. package/plugins-dist/update/index.js +26 -28
  197. package/plugins-dist/web/env.js +55 -68
  198. package/plugins-dist/web/index.js +80 -110
  199. package/plugins-dist/web/plugin.json +1 -2
  200. package/plugins-dist/web/renderers.js +4 -5
  201. package/plugins-dist/web/web.js +514 -593
  202. package/sdk/python/__pycache__/jade_plugin.cpython-312.pyc +0 -0
  203. package/sdk/python/jade_plugin.py +9 -2
  204. package/src/api.ts +1 -1
  205. package/src/host.ts +39 -4
  206. package/src/remote.ts +6 -1
  207. package/src/session.ts +489 -34
@@ -1,14 +1,7 @@
1
- // /mcp add|remove(终端里是 jade mcp add|remove):往配置文件里加一个 MCP 服务或删掉它,不用手改 JSON。
2
- //
3
- // 不加 --project 写 $JADE_HOME/mcp.json,加了写 <工作目录>/.jade/mcp.json;文件里其他的内容原样保留。
4
- // 这里只写配置,不启动服务:进程里的服务只在第一个会话打开时连接,新加的重启 jade 后生效。
5
- // 项目层的服务照旧在第一次启动前请用户确认:命令不顺带记下确认。这个命令也有命令行的写法(jade mcp add),
6
- // 模型能经 shell 跑它;如果加了就算确认,模型就能绕过确认。
7
1
  import { mkdir, readFile, writeFile } from "node:fs/promises";
8
2
  import path from "node:path";
9
3
  import { checkConfig, describeServer } from "./mcp.js";
10
4
  import { display } from "./project.js";
11
- /** cmd 是 "/mcp" 或 "jade mcp" */
12
5
  export const manageUsage = (cmd) => `usage: ${cmd} add <name> [--project] [--env KEY=VALUE]… [--force] [--] <command> [args…]
13
6
  ${cmd} add <name> --url <url> [--project] [--header "Name: value"]… [--force]
14
7
  ${cmd} remove <name> [--project]
@@ -18,143 +11,136 @@ export const manageUsage = (cmd) => `usage: ${cmd} add <name> [--project] [--env
18
11
  --header an HTTP header for a --url server; values may use \${VAR}
19
12
  --force replace a server with the same name
20
13
  Everything after <command> is passed to it unchanged, e.g. ${cmd} add fs npx -y @modelcontextprotocol/server-filesystem .`;
21
- /** 不加 --project 写 $JADE_HOME/mcp.json,加了写 <工作目录>/.jade/mcp.json */
22
- export const mcpConfigFile = (home, cwd, project) => (project ? path.join(cwd, ".jade", "mcp.json") : path.join(home, "mcp.json"));
23
- /** add / remove,参数已经切好;返回给用户看的结果,用法错误或失败时抛错。cmd 用在提示里 */
14
+ export const mcpConfigFile = (home, cwd, project) => project ? path.join(cwd, ".jade", "mcp.json") : path.join(home, "mcp.json");
24
15
  export async function manageMcp(argv, env) {
25
- const usage = manageUsage(env.cmd);
26
- const [sub, ...tail] = argv;
27
- if (sub === "-h" || sub === "--help")
28
- return usage;
29
- if (sub === "add") {
30
- const { name, project, force, config } = parseAdd(tail, usage);
31
- const file = mcpConfigFile(env.home, env.cwd, project);
32
- await edit(file, (servers) => {
33
- if (servers[name] !== undefined && !force)
34
- throw new Error(`${display(env.cwd, file)} already has an MCP server named ${name}; add --force to replace it`);
35
- servers[name] = config;
36
- });
37
- return [
38
- `added MCP server ${name} to ${display(env.cwd, file)}: ${describeServer(config)}`,
39
- `restart jade to start it${project ? "; jade asks you to confirm it the first time" : ""}`,
40
- ].join("\n");
41
- }
42
- if (sub === "remove" || sub === "rm") {
43
- const project = tail.includes("--project");
44
- const rest = tail.filter((a) => a !== "--project");
45
- if (rest.length !== 1 || rest[0].startsWith("-"))
46
- throw new Error(usage);
47
- const name = rest[0];
48
- const file = mcpConfigFile(env.home, env.cwd, project);
49
- await edit(file, (servers) => {
50
- if (servers[name] === undefined)
51
- throw new Error(`${display(env.cwd, file)} has no MCP server named ${name}`);
52
- delete servers[name];
53
- });
54
- return `removed MCP server ${name} from ${display(env.cwd, file)}; restart jade to stop it`;
55
- }
56
- throw new Error(usage);
16
+ const usage = manageUsage(env.cmd);
17
+ const [sub, ...tail] = argv;
18
+ if (sub === "-h" || sub === "--help")
19
+ return usage;
20
+ if (sub === "add") {
21
+ const { name, project, force, config } = parseAdd(tail, usage);
22
+ const file = mcpConfigFile(env.home, env.cwd, project);
23
+ await edit(file, (servers) => {
24
+ if (servers[name] !== undefined && !force)
25
+ throw new Error(`${display(env.cwd, file)} already has an MCP server named ${name}; add --force to replace it`);
26
+ servers[name] = config;
27
+ });
28
+ return [
29
+ `added MCP server ${name} to ${display(env.cwd, file)}: ${describeServer(config)}`,
30
+ env.live ? `jade starts it now${project ? " (after you confirm it)" : ""}; its tools are available from the next turn` : `restart jade to start it${project ? "; jade asks you to confirm it the first time" : ""}`
31
+ ].join(`
32
+ `);
33
+ }
34
+ if (sub === "remove" || sub === "rm") {
35
+ const project = tail.includes("--project");
36
+ const rest = tail.filter((a) => a !== "--project");
37
+ if (rest.length !== 1 || rest[0].startsWith("-"))
38
+ throw new Error(usage);
39
+ const name = rest[0];
40
+ const file = mcpConfigFile(env.home, env.cwd, project);
41
+ await edit(file, (servers) => {
42
+ if (servers[name] === undefined)
43
+ throw new Error(`${display(env.cwd, file)} has no MCP server named ${name}`);
44
+ delete servers[name];
45
+ });
46
+ return `removed MCP server ${name} from ${display(env.cwd, file)}; ${env.live ? "jade stops it and its tools go away from the next turn" : "restart jade to stop it"}`;
47
+ }
48
+ throw new Error(usage);
57
49
  }
58
50
  function parseAdd(tail, usage) {
59
- let name;
60
- let project = false;
61
- let force = false;
62
- let url;
63
- const envVars = {};
64
- const headers = {};
65
- let command;
66
- for (let i = 0; i < tail.length; i++) {
67
- const a = tail[i];
68
- const value = () => {
69
- const v = tail[++i];
70
- if (v === undefined)
71
- throw new Error(`${a} needs a value\n${usage}`);
72
- return v;
73
- };
74
- if (a === "--") {
75
- command = tail.slice(i + 1);
76
- break;
77
- }
78
- else if (a === "--project")
79
- project = true;
80
- else if (a === "--force" || a === "-f")
81
- force = true;
82
- else if (a === "--url")
83
- url = value();
84
- else if (a === "--env" || a === "-e") {
85
- const v = value();
86
- const eq = v.indexOf("=");
87
- if (eq <= 0)
88
- throw new Error(`--env needs KEY=VALUE, got ${JSON.stringify(v)}`);
89
- envVars[v.slice(0, eq)] = v.slice(eq + 1);
90
- }
91
- else if (a === "--header" || a === "-H") {
92
- const v = value();
93
- const colon = v.indexOf(":");
94
- if (colon <= 0)
95
- throw new Error(`--header needs "Name: value", got ${JSON.stringify(v)}`);
96
- headers[v.slice(0, colon).trim()] = v.slice(colon + 1).trim();
97
- }
98
- else if (a.startsWith("-"))
99
- throw new Error(`unknown option ${a}\n${usage}`);
100
- else if (name === undefined)
101
- name = a;
102
- else {
103
- // 名字之后第一个不是选项的参数是服务的命令,后面的都原样交给它(npx -y … 里的 -y 不是 jade 的选项)
104
- command = tail.slice(i);
105
- break;
106
- }
107
- }
108
- if (name === undefined)
109
- throw new Error(usage);
110
- if (url !== undefined && command?.length)
111
- throw new Error(`give either --url or a command, not both\n${usage}`);
112
- if (url === undefined && !command?.length)
113
- throw new Error(`give a command or --url\n${usage}`);
114
- let config;
115
- if (url !== undefined) {
116
- // 含 ${VAR} 的地址要到读配置时才知道展开后是什么,那时再检查
117
- if (!/^https?:\/\//.test(url) && !url.includes("${"))
118
- throw new Error(`--url must start with http:// or https://`);
119
- if (Object.keys(envVars).length)
120
- throw new Error("--env is for servers started with a command; a --url server takes --header");
121
- config = { type: "http", url, ...(Object.keys(headers).length ? { headers } : {}) };
122
- }
51
+ let name;
52
+ let project = false;
53
+ let force = false;
54
+ let url;
55
+ const envVars = {};
56
+ const headers = {};
57
+ let command;
58
+ for (let i = 0;i < tail.length; i++) {
59
+ const a = tail[i];
60
+ const value = () => {
61
+ const v = tail[++i];
62
+ if (v === undefined)
63
+ throw new Error(`${a} needs a value
64
+ ${usage}`);
65
+ return v;
66
+ };
67
+ if (a === "--") {
68
+ command = tail.slice(i + 1);
69
+ break;
70
+ } else if (a === "--project")
71
+ project = true;
72
+ else if (a === "--force" || a === "-f")
73
+ force = true;
74
+ else if (a === "--url")
75
+ url = value();
76
+ else if (a === "--env" || a === "-e") {
77
+ const v = value();
78
+ const eq = v.indexOf("=");
79
+ if (eq <= 0)
80
+ throw new Error(`--env needs KEY=VALUE, got ${JSON.stringify(v)}`);
81
+ envVars[v.slice(0, eq)] = v.slice(eq + 1);
82
+ } else if (a === "--header" || a === "-H") {
83
+ const v = value();
84
+ const colon = v.indexOf(":");
85
+ if (colon <= 0)
86
+ throw new Error(`--header needs "Name: value", got ${JSON.stringify(v)}`);
87
+ headers[v.slice(0, colon).trim()] = v.slice(colon + 1).trim();
88
+ } else if (a.startsWith("-"))
89
+ throw new Error(`unknown option ${a}
90
+ ${usage}`);
91
+ else if (name === undefined)
92
+ name = a;
123
93
  else {
124
- if (Object.keys(headers).length)
125
- throw new Error("--header is for --url servers; a command takes --env");
126
- const [cmd, ...args] = command;
127
- config = { command: cmd, ...(args.length ? { args } : {}), ...(Object.keys(envVars).length ? { env: envVars } : {}) };
94
+ command = tail.slice(i);
95
+ break;
128
96
  }
129
- const problem = checkConfig(name, config);
130
- if (problem)
131
- throw new Error(`MCP server ${JSON.stringify(name)}: ${problem}`);
132
- return { name, project, force, config };
97
+ }
98
+ if (name === undefined)
99
+ throw new Error(usage);
100
+ if (url !== undefined && command?.length)
101
+ throw new Error(`give either --url or a command, not both
102
+ ${usage}`);
103
+ if (url === undefined && !command?.length)
104
+ throw new Error(`give a command or --url
105
+ ${usage}`);
106
+ let config;
107
+ if (url !== undefined) {
108
+ if (!/^https?:\/\//.test(url) && !url.includes("${"))
109
+ throw new Error(`--url must start with http:// or https://`);
110
+ if (Object.keys(envVars).length)
111
+ throw new Error("--env is for servers started with a command; a --url server takes --header");
112
+ config = { type: "http", url, ...Object.keys(headers).length ? { headers } : {} };
113
+ } else {
114
+ if (Object.keys(headers).length)
115
+ throw new Error("--header is for --url servers; a command takes --env");
116
+ const [cmd, ...args] = command;
117
+ config = { command: cmd, ...args.length ? { args } : {}, ...Object.keys(envVars).length ? { env: envVars } : {} };
118
+ }
119
+ const problem = checkConfig(name, config);
120
+ if (problem)
121
+ throw new Error(`MCP server ${JSON.stringify(name)}: ${problem}`);
122
+ return { name, project, force, config };
133
123
  }
134
- /** 读配置文件、改 mcpServers、写回;文件坏了时报错,不覆盖 */
135
124
  async function edit(file, change) {
136
- let json = {};
137
- let text;
125
+ let json = {};
126
+ let text;
127
+ try {
128
+ text = await readFile(file, "utf8");
129
+ } catch {}
130
+ if (text !== undefined && text.trim()) {
138
131
  try {
139
- text = await readFile(file, "utf8");
140
- }
141
- catch {
142
- // 还没有这个文件
143
- }
144
- if (text !== undefined && text.trim()) {
145
- try {
146
- json = JSON.parse(text);
147
- }
148
- catch (e) {
149
- throw new Error(`${file}: ${e instanceof Error ? e.message : String(e)}; fix it by hand first`);
150
- }
151
- if (typeof json !== "object" || json === null || Array.isArray(json))
152
- throw new Error(`${file}: expected { "mcpServers": { ... } }; fix it by hand first`);
132
+ json = JSON.parse(text);
133
+ } catch (e) {
134
+ throw new Error(`${file}: ${e instanceof Error ? e.message : String(e)}; fix it by hand first`);
153
135
  }
154
- const servers = (json.mcpServers ??= {});
155
- if (typeof servers !== "object" || servers === null || Array.isArray(servers))
156
- throw new Error(`${file}: "mcpServers" is not an object; fix it by hand first`);
157
- change(servers);
158
- await mkdir(path.dirname(file), { recursive: true });
159
- await writeFile(file, JSON.stringify(json, null, 2) + "\n");
136
+ if (typeof json !== "object" || json === null || Array.isArray(json))
137
+ throw new Error(`${file}: expected { "mcpServers": { ... } }; fix it by hand first`);
138
+ }
139
+ const servers = json.mcpServers ??= {};
140
+ if (typeof servers !== "object" || servers === null || Array.isArray(servers))
141
+ throw new Error(`${file}: "mcpServers" is not an object; fix it by hand first`);
142
+ change(servers);
143
+ await mkdir(path.dirname(file), { recursive: true });
144
+ await writeFile(file, JSON.stringify(json, null, 2) + `
145
+ `);
160
146
  }