@uncarved/jade 0.3.1 → 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 (199) hide show
  1. package/dist/api.d.ts +1 -1
  2. package/dist/api.js +1 -1
  3. package/dist/host.d.ts +2 -0
  4. package/dist/host.js +39 -5
  5. package/dist/host.js.map +1 -1
  6. package/dist/remote.js +5 -0
  7. package/dist/remote.js.map +1 -1
  8. package/dist/session.d.ts +7 -0
  9. package/dist/session.js +482 -27
  10. package/dist/session.js.map +1 -1
  11. package/package.json +4 -4
  12. package/plugins/approval/index.ts +36 -14
  13. package/plugins/approval/policy.ts +15 -10
  14. package/plugins/approval/review.ts +9 -5
  15. package/plugins/checks/checks.ts +10 -7
  16. package/plugins/checks/index.ts +13 -13
  17. package/plugins/checks/plugin.json +1 -1
  18. package/plugins/checks/project.ts +37 -38
  19. package/plugins/commands/index.ts +27 -3
  20. package/plugins/compact/compact.ts +13 -5
  21. package/plugins/compact/index.ts +20 -3
  22. package/plugins/compact/style.ts +13 -14
  23. package/plugins/completions/index.ts +35 -0
  24. package/plugins/completions/plugin.json +7 -0
  25. package/plugins/copy/index.ts +46 -0
  26. package/plugins/copy/plugin.json +7 -0
  27. package/plugins/editor/index.ts +10 -4
  28. package/plugins/fs/diff.ts +7 -6
  29. package/plugins/fs/fs.ts +8 -4
  30. package/plugins/fs/grep.ts +42 -9
  31. package/plugins/fs/index.ts +2 -7
  32. package/plugins/fs/plugin.json +1 -1
  33. package/plugins/fs/renderers.ts +16 -15
  34. package/plugins/fs/style.ts +16 -15
  35. package/plugins/hooks/index.ts +3 -2
  36. package/plugins/keys/index.ts +5 -1
  37. package/plugins/mcp/index.ts +197 -78
  38. package/plugins/mcp/install.ts +5 -3
  39. package/plugins/mcp/mcp.ts +163 -11
  40. package/plugins/mcp/plugin.json +2 -1
  41. package/plugins/mcp/project.ts +47 -50
  42. package/plugins/memory/index.ts +4 -4
  43. package/plugins/memory/style.ts +13 -14
  44. package/plugins/mentions/candidates.ts +67 -0
  45. package/plugins/mentions/index.ts +12 -5
  46. package/plugins/mentions/plugin.json +1 -1
  47. package/plugins/mentions/style.ts +13 -14
  48. package/plugins/models/configure.ts +10 -9
  49. package/plugins/models/index.ts +27 -1
  50. package/plugins/modes/index.ts +13 -2
  51. package/plugins/print/index.ts +7 -4
  52. package/plugins/prompts/index.ts +0 -0
  53. package/plugins/renderers/index.ts +10 -5
  54. package/plugins/repeats/index.ts +8 -8
  55. package/plugins/schedule/index.ts +2 -0
  56. package/plugins/screenshot/browser.ts +10 -0
  57. package/plugins/sessions/index.ts +48 -2
  58. package/plugins/shell/index.ts +20 -25
  59. package/plugins/shell/plugin.json +1 -2
  60. package/plugins/shell/renderers.ts +9 -7
  61. package/plugins/shell/shell.ts +3 -1
  62. package/plugins/skills/index.ts +28 -19
  63. package/plugins/skills/project.ts +12 -7
  64. package/plugins/steer/index.ts +5 -4
  65. package/plugins/task/index.ts +80 -50
  66. package/plugins/task/plugin.json +6 -2
  67. package/plugins/task/style.ts +13 -14
  68. package/plugins/task/subagent.ts +67 -184
  69. package/plugins/todo/index.ts +39 -9
  70. package/plugins/tools/index.ts +9 -2
  71. package/plugins/tui/frontend.ts +139 -89
  72. package/plugins/tui/index.ts +2 -3
  73. package/plugins/tui/mentions.ts +11 -80
  74. package/plugins/tui/plugin.json +1 -1
  75. package/plugins/tui/screen.ts +55 -5
  76. package/plugins/tui/transcript.ts +17 -7
  77. package/plugins/tui/tui.ts +337 -101
  78. package/plugins/tui/vendor.ts +1 -1
  79. package/plugins/undo/checkpoint.ts +5 -3
  80. package/plugins/undo/index.ts +43 -14
  81. package/plugins/undo/style.ts +13 -14
  82. package/plugins/web/index.ts +7 -18
  83. package/plugins/web/plugin.json +1 -1
  84. package/plugins-dist/approval/index.js +363 -418
  85. package/plugins-dist/approval/policy.js +391 -508
  86. package/plugins-dist/approval/review.js +132 -158
  87. package/plugins-dist/approval/schema.js +50 -55
  88. package/plugins-dist/ask/index.js +115 -129
  89. package/plugins-dist/budget/index.js +27 -31
  90. package/plugins-dist/checks/checks.js +293 -329
  91. package/plugins-dist/checks/index.js +119 -139
  92. package/plugins-dist/checks/plugin.json +2 -1
  93. package/plugins-dist/checks/project.js +57 -65
  94. package/plugins-dist/commands/index.js +47 -29
  95. package/plugins-dist/compact/compact.js +233 -249
  96. package/plugins-dist/compact/index.js +98 -95
  97. package/plugins-dist/compact/style.js +9 -14
  98. package/plugins-dist/completions/index.js +30 -0
  99. package/plugins-dist/completions/plugin.json +9 -0
  100. package/plugins-dist/continue/index.js +40 -52
  101. package/plugins-dist/copy/index.js +40 -0
  102. package/plugins-dist/copy/plugin.json +9 -0
  103. package/plugins-dist/cost/index.js +98 -115
  104. package/plugins-dist/custom-commands/index.js +55 -72
  105. package/plugins-dist/editor/index.js +64 -72
  106. package/plugins-dist/fs/diff.js +111 -124
  107. package/plugins-dist/fs/fs.js +426 -469
  108. package/plugins-dist/fs/grep.js +262 -253
  109. package/plugins-dist/fs/index.js +20 -34
  110. package/plugins-dist/fs/plugin.json +1 -2
  111. package/plugins-dist/fs/renderers.js +100 -112
  112. package/plugins-dist/fs/style.js +11 -15
  113. package/plugins-dist/fs/sys.js +31 -43
  114. package/plugins-dist/hooks/index.js +107 -127
  115. package/plugins-dist/keys/index.js +27 -31
  116. package/plugins-dist/mcp/index.js +271 -199
  117. package/plugins-dist/mcp/install.js +123 -137
  118. package/plugins-dist/mcp/mcp.js +638 -577
  119. package/plugins-dist/mcp/plugin.json +3 -1
  120. package/plugins-dist/mcp/project.js +98 -115
  121. package/plugins-dist/memory/index.js +83 -88
  122. package/plugins-dist/memory/memory.js +111 -128
  123. package/plugins-dist/memory/style.js +9 -14
  124. package/plugins-dist/mentions/attach.js +91 -99
  125. package/plugins-dist/mentions/candidates.js +49 -0
  126. package/plugins-dist/mentions/index.js +71 -81
  127. package/plugins-dist/mentions/plugin.json +2 -1
  128. package/plugins-dist/mentions/style.js +9 -14
  129. package/plugins-dist/models/config.js +29 -43
  130. package/plugins-dist/models/configure.js +392 -473
  131. package/plugins-dist/models/context.js +14 -22
  132. package/plugins-dist/models/index.js +182 -189
  133. package/plugins-dist/models/provider.js +243 -307
  134. package/plugins-dist/models/saved.js +59 -71
  135. package/plugins-dist/modes/index.js +138 -165
  136. package/plugins-dist/plugins/index.js +34 -34
  137. package/plugins-dist/print/index.js +192 -175
  138. package/plugins-dist/prompts/index.js +81 -89
  139. package/plugins-dist/prompts/notes.js +31 -37
  140. package/plugins-dist/prompts/prompts.js +155 -193
  141. package/plugins-dist/prompts/results.js +40 -53
  142. package/plugins-dist/prompts/sys.js +39 -50
  143. package/plugins-dist/renderers/index.js +32 -32
  144. package/plugins-dist/repeats/index.js +131 -174
  145. package/plugins-dist/schedule/cron.js +49 -56
  146. package/plugins-dist/schedule/index.js +229 -247
  147. package/plugins-dist/schedule/store.js +93 -109
  148. package/plugins-dist/scratch/index.js +12 -18
  149. package/plugins-dist/screenshot/browser.js +136 -154
  150. package/plugins-dist/screenshot/index.js +37 -46
  151. package/plugins-dist/screenshot/sys.js +53 -65
  152. package/plugins-dist/screenshot/tool.js +98 -126
  153. package/plugins-dist/sessions/index.js +149 -117
  154. package/plugins-dist/shell/index.js +115 -135
  155. package/plugins-dist/shell/plugin.json +1 -2
  156. package/plugins-dist/shell/renderers.js +28 -33
  157. package/plugins-dist/shell/service.js +17 -23
  158. package/plugins-dist/shell/shell.js +307 -362
  159. package/plugins-dist/shell/sys.js +64 -79
  160. package/plugins-dist/skills/index.js +193 -211
  161. package/plugins-dist/skills/install.js +122 -149
  162. package/plugins-dist/skills/project.js +65 -73
  163. package/plugins-dist/skills/skills.js +135 -171
  164. package/plugins-dist/steer/index.js +108 -125
  165. package/plugins-dist/suggest/index.js +235 -259
  166. package/plugins-dist/task/index.js +130 -117
  167. package/plugins-dist/task/plugin.json +5 -2
  168. package/plugins-dist/task/style.js +9 -14
  169. package/plugins-dist/task/subagent.js +156 -279
  170. package/plugins-dist/todo/index.js +79 -63
  171. package/plugins-dist/tools/index.js +36 -42
  172. package/plugins-dist/tui/editor.js +145 -160
  173. package/plugins-dist/tui/frontend.js +639 -678
  174. package/plugins-dist/tui/history.js +34 -37
  175. package/plugins-dist/tui/index.js +16 -18
  176. package/plugins-dist/tui/markdown.js +203 -247
  177. package/plugins-dist/tui/mascot.js +266 -355
  178. package/plugins-dist/tui/mentions.js +67 -144
  179. package/plugins-dist/tui/plugin.json +1 -2
  180. package/plugins-dist/tui/render.js +35 -45
  181. package/plugins-dist/tui/screen.js +197 -180
  182. package/plugins-dist/tui/transcript.js +436 -468
  183. package/plugins-dist/tui/tui.js +1554 -1656
  184. package/plugins-dist/undo/checkpoint.js +95 -118
  185. package/plugins-dist/undo/index.js +185 -192
  186. package/plugins-dist/undo/snapshot.js +83 -99
  187. package/plugins-dist/undo/style.js +9 -14
  188. package/plugins-dist/update/index.js +26 -28
  189. package/plugins-dist/web/env.js +55 -68
  190. package/plugins-dist/web/index.js +80 -110
  191. package/plugins-dist/web/plugin.json +1 -2
  192. package/plugins-dist/web/renderers.js +4 -5
  193. package/plugins-dist/web/web.js +514 -593
  194. package/sdk/python/__pycache__/jade_plugin.cpython-312.pyc +0 -0
  195. package/sdk/python/jade_plugin.py +9 -2
  196. package/src/api.ts +1 -1
  197. package/src/host.ts +39 -4
  198. package/src/remote.ts +6 -1
  199. package/src/session.ts +489 -34
@@ -252,16 +252,17 @@ export function configurator(opts: ConfigureOptions): Configure {
252
252
  const same = kind === current?.kind;
253
253
 
254
254
  let baseURL: string | undefined = env[URL_KEY[kind]];
255
- if (kind !== "anthropic") {
256
- const fallback = kind === "openai" ? "https://api.openai.com/v1" : "";
257
- const answer = await ui.input({ title: "Base URL", initial: baseURL ?? fallback, placeholder: "https://example.com/v1" }, opts.signal);
258
- if (answer === undefined) return false;
259
- if (kind === "openai-compat" && !answer) {
260
- report("A base URL is required.");
261
- return false;
262
- }
263
- baseURL = answer || undefined;
255
+ // Anthropic 也能改地址(代理、兼容服务):留空用官方地址。不预填官方地址:预填了回车就会把它写进
256
+ // ANTHROPIC_BASE_URL,和以前没写地址时保存的同一个服务对不上(找不到保存过的密钥,models.json 里多出一份)
257
+ const fallback = kind === "openai" ? "https://api.openai.com/v1" : "";
258
+ const placeholder = kind === "anthropic" ? "empty for https://api.anthropic.com (SDK adds /v1)" : "https://example.com/v1";
259
+ const url = await ui.input({ title: "Base URL", initial: baseURL ?? fallback, placeholder }, opts.signal);
260
+ if (url === undefined) return false;
261
+ if (kind === "openai-compat" && !url) {
262
+ report("A base URL is required.");
263
+ return false;
264
264
  }
265
+ baseURL = url || undefined;
265
266
 
266
267
  // 已知的密钥:当前服务的,或者保存过的同一个地址的服务的(最近用过的那个)
267
268
  const sameAddress = (e: Env) => {
@@ -14,12 +14,19 @@ import { configurator } from "./configure.ts";
14
14
  import { isBuiltinKind, listModels, MODEL_KEY, providerFromEnv, providerInfo, providerKind, RateGate, rpmFromEnv, visionFromEnv, withRetry, type RetriedResponse } from "./provider.ts";
15
15
  import { MODEL_SETTINGS, readSavedServices, type Env } from "./saved.ts";
16
16
 
17
+ /** 进程级的配置交给会话里的提示用:有没有配好模型、有没有 /model、.env 在哪 */
18
+ let setup: { configured(): boolean; command: boolean; envFile: string } | undefined;
19
+ /** 没配模型的提示一个进程只说一次 */
20
+ let hinted = false;
21
+
17
22
  export default definePlugin({
18
23
  async process(ctx) {
19
24
  const envFile = path.join(ctx.home, ".env");
20
25
  const modelsFile = path.join(ctx.home, "models.json");
21
26
  // 当前的模型配置。改配置时整份换掉(updateEnvFile 改的是这一份,apply 再从文件读一遍)
22
27
  let env = await envWithFile(envFile);
28
+ hinted = false;
29
+ setup = { configured: () => hasProvider(env), command: false, envFile };
23
30
  // 用的时候再取:jade/tui 也依赖这个插件(models@1),它在这之后才激活,这里取到的是 undefined,重试的提示就没人显示
24
31
  const ui = () => ctx.service<UI>("ui@1");
25
32
  const watchers = new Set<() => void>();
@@ -157,7 +164,9 @@ export default definePlugin({
157
164
  notify();
158
165
  };
159
166
 
160
- ctx.service<Commands>("commands@1")?.register({
167
+ const commands = ctx.service<Commands>("commands@1");
168
+ setup.command = commands !== undefined;
169
+ commands?.register({
161
170
  name: "model",
162
171
  args: "[name]",
163
172
  description: "switch models, or add one with its provider, API key and limits",
@@ -179,6 +188,23 @@ export default definePlugin({
179
188
  },
180
189
 
181
190
  session(ctx) {
191
+ const ui = ctx.service<UI>("ui@1");
192
+ // 还没配模型:告诉用户怎么配。/model 当场就能配好,不用重启;没有这条命令时只能改文件
193
+ if (setup && !setup.configured() && !hinted && ui?.interactive) {
194
+ hinted = true;
195
+ const file = `put ANTHROPIC_API_KEY=... (or OPENAI_API_KEY=...) in ${setup.envFile}, then restart jade`;
196
+ ui.notify(setup.command ? `No model is configured yet. Type /model to set one up, or ${file}.` : `No model is configured yet. To set one up, ${file}.`, "warning");
197
+ }
198
+ // 回复被输出上限截断:上限是这里的配置(JADE_MAX_TOKENS),只有这里知道怎么改
199
+ ctx.kernel.hook({
200
+ kind: "observe",
201
+ point: "event",
202
+ fn: (e) => {
203
+ if (e.type === "turn.ended" && (e.data as { reason?: string }).reason === "max_tokens" && setup?.command) {
204
+ ui?.notify("if replies keep getting cut off, raise the output limit with /model", "info");
205
+ }
206
+ },
207
+ });
182
208
  // 重试过的请求:把每次失败写进会话日志,事后能查到为什么慢、为什么重新输出(插件事件,不进上下文)
183
209
  ctx.kernel.hook({
184
210
  kind: "observe",
@@ -181,7 +181,8 @@ export default definePlugin({
181
181
  }
182
182
 
183
183
  // 能问用户时才有 propose_plan;它只在 plan 模式下发给模型
184
- const canPropose = !!ui?.interactive;
184
+ // 子会话(子 Agent)不提交计划:计划由用户的会话提交
185
+ const canPropose = !!ui?.interactive && ctx.session.parent === undefined;
185
186
  if (canPropose) ctx.kernel.tool(proposePlanTool(approval, ui!));
186
187
  ctx.kernel.hook({
187
188
  kind: "transform",
@@ -199,8 +200,18 @@ export default definePlugin({
199
200
  note = undefined;
200
201
  }
201
202
  };
203
+ // 状态栏上的当前模式:窄的时候也留着(去掉 shift+tab 提示),颜色说明它放得多宽
204
+ const show = () => {
205
+ const mode = approval.mode();
206
+ const tone = mode === "yolo" ? "error" : mode === "auto" ? "warn" : mode === "plan" ? "accent" : "ok";
207
+ ctx.status?.({ text: `${mode} (shift+tab)`, short: mode, tone, keep: true });
208
+ };
202
209
  sync();
203
- const onChange = () => sync();
210
+ show();
211
+ const onChange = () => {
212
+ sync();
213
+ show();
214
+ };
204
215
  listeners.add(onChange);
205
216
  ctx.effect(() => () => void listeners.delete(onChange));
206
217
  },
@@ -1,6 +1,7 @@
1
1
  // jade/print:jade -p "<prompt>" 跑一轮就退出。模型的回复写到 stdout,工具调用和提示写到 stderr。
2
2
  // 不能向用户提问:ui@1 的 select 总是返回 undefined,要审批的调用由审批插件拒绝。
3
3
 
4
+ import { stripVTControlCharacters } from "node:util";
4
5
  import type { Block, LogEvent, RuntimeNotice, Usage } from "uncarved";
5
6
  import { definePlugin, type Frontend, type UI } from "@uncarved/jade-api";
6
7
  import type { SessionIndex } from "@uncarved/jade-api/services";
@@ -18,10 +19,12 @@ Runs one prompt and exits. The reply goes to stdout; tool calls and notices go t
18
19
  Exit code: 0 when the turn ends normally, 1 on an error, 130 when interrupted.
19
20
  jade's own commands (plugins, update, --safe): jade help`;
20
21
 
21
- const ui: UI = {
22
+ /** -p 的 ui@1(导出给测试) */
23
+ export const ui: UI = {
22
24
  interactive: false,
23
25
  notify(message, level = "info") {
24
- process.stderr.write(`${level === "info" ? "" : `[${level}] `}${message}\n`);
26
+ // 输出常常被重定向、交给别的程序:插件和工具带来的颜色、控制序列都去掉
27
+ process.stderr.write(`${level === "info" ? "" : `[${level}] `}${stripVTControlCharacters(String(message))}\n`);
25
28
  },
26
29
  select: async () => undefined,
27
30
  input: async () => undefined,
@@ -96,11 +99,11 @@ const frontend: Frontend = {
96
99
  }
97
100
  if (e.type === "tool.decided") {
98
101
  const d = e.data as { decision: string; reason?: string };
99
- if (d.decision === "deny") process.stderr.write(` denied${d.reason ? `: ${d.reason}` : ""}\n`);
102
+ if (d.decision === "deny") process.stderr.write(` denied${d.reason ? `: ${stripVTControlCharacters(d.reason)}` : ""}\n`);
100
103
  }
101
104
  if (e.type === "tool.completed") {
102
105
  const d = e.data as { isError: boolean; content: Block[] };
103
- if (d.isError) process.stderr.write(` failed: ${firstLine(d.content)}\n`);
106
+ if (d.isError) process.stderr.write(` failed: ${stripVTControlCharacters(firstLine(d.content))}\n`);
104
107
  }
105
108
  if (e.type === "turn.ended") ended = e.data as { reason: string; error?: string };
106
109
  });
Binary file
@@ -1,5 +1,6 @@
1
1
  // jade/renderers:工具调用和插件事件在对话里怎么显示的注册表。前端查这里;没有登记的用前端的默认显示。
2
- // 显示的文字可以带 ANSI 颜色,前端负责过滤掉颜色之外的控制序列。
2
+ // 显示的文字是 jade-api 的 Text(带语义样式的片段,也可以是普通字符串),怎么画由前端决定;
3
+ // 前端负责过滤掉字符串里颜色之外的控制序列。
3
4
 
4
5
  import { definePlugin } from "@uncarved/jade-api";
5
6
  import type { EventRenderer, Renderers, ToolRenderer } from "@uncarved/jade-api/services";
@@ -7,9 +8,13 @@ import type { EventRenderer, Renderers, ToolRenderer } from "@uncarved/jade-api/
7
8
  const tools = new Map<string, { renderer: ToolRenderer; plugin: string }>();
8
9
  const events = new Map<string, { renderer: EventRenderer; plugin: string }>();
9
10
 
10
- function add<T>(map: Map<string, { renderer: T; plugin: string }>, key: string, renderer: T, plugin: string, what: string, onDispose: (d: () => void) => void): () => void {
11
+ function add<T>(map: Map<string, { renderer: T; plugin: string }>, key: string, renderer: T, plugin: string, what: string, onDispose: (d: () => void) => void, report: (m: string) => void): () => void {
12
+ // 重名时先登记的留下,后来的跳过并报告(同 commands@1)
11
13
  const taken = map.get(key);
12
- if (taken) throw new Error(`${what} ${key} already has a renderer from ${taken.plugin}`);
14
+ if (taken) {
15
+ report(`the renderer for ${what} ${key} from ${plugin} was skipped: ${taken.plugin} already registered one`);
16
+ return () => {};
17
+ }
13
18
  const entry = { renderer, plugin };
14
19
  map.set(key, entry);
15
20
  const revoke = () => {
@@ -24,11 +29,11 @@ export default definePlugin({
24
29
  ctx.provide("renderers@1", (caller): Renderers => ({
25
30
  tool(renderer) {
26
31
  if (typeof renderer?.tool !== "string" || !renderer.tool) throw new Error("a tool renderer needs the tool name");
27
- return add(tools, renderer.tool, renderer, caller.plugin, "tool", caller.onDispose);
32
+ return add(tools, renderer.tool, renderer, caller.plugin, "tool", caller.onDispose, ctx.report);
28
33
  },
29
34
  event(renderer) {
30
35
  if (typeof renderer?.event !== "string" || !renderer.event || typeof renderer.render !== "function") throw new Error("an event renderer needs the event type and render");
31
- return add(events, `${caller.plugin}/${renderer.event}`, renderer, caller.plugin, "event", caller.onDispose);
36
+ return add(events, `${caller.plugin}/${renderer.event}`, renderer, caller.plugin, "event", caller.onDispose, ctx.report);
32
37
  },
33
38
  forTool: (tool) => tools.get(tool),
34
39
  forEvent: (type) => events.get(type),
@@ -25,10 +25,10 @@ export const COMPACT_KEY = "jade/compact";
25
25
  /** 只打开一个文件或网址的命令:start "" x、start x、xdg-open x、open x、explorer x */
26
26
  const OPEN = /^\s*(?:start\s+""|start|xdg-open|open|explorer(?:\.exe)?)\s+(?:"([^"]+)"|'([^']+)'|([^\s"'&|;<>]+))\s*$/i;
27
27
 
28
- /** bash 调用打开的目标(规范化后),不是打开命令时是 undefined */
29
- export function openTarget(call: { name: string; input: unknown }, cwd: string): string | undefined {
30
- if (call.name !== "bash") return undefined;
31
- const command = (call.input as { command?: unknown } | null)?.command;
28
+ /** 执行命令的调用(shell 是命令所在的字段,见工具的 meta.shell)打开的目标(规范化后),不是打开命令时是 undefined */
29
+ export function openTarget(call: { name: string; input: unknown }, cwd: string, shell: string | undefined): string | undefined {
30
+ if (shell === undefined) return undefined;
31
+ const command = (call.input as Record<string, unknown> | null)?.[shell];
32
32
  if (typeof command !== "string") return undefined;
33
33
  const m = OPEN.exec(command);
34
34
  const target = m && (m[1] ?? m[2] ?? m[3]);
@@ -56,7 +56,7 @@ function replacements(call: { name: string; input: unknown }): { old_string: str
56
56
  const hash = (content: Block[]) => createHash("sha1").update(JSON.stringify(content.map((b) => (b.kind === "text" ? b.text : b)))).digest("hex");
57
57
 
58
58
  /** 会话里的 hook:model.before 数回复次数,tool.gate 拒绝重复,tool.after 加提醒,event 在用户发消息、压缩后重新计 */
59
- export function repeatsHooks(opts: { cwd: string; id?: string }): LocalHookSpec[] {
59
+ export function repeatsHooks(opts: { cwd: string; id?: string; /** 执行命令的工具把命令放在哪个字段(ctx.session.tool 的 meta.shell) */ shell: (tool: string) => string | undefined }): LocalHookSpec[] {
60
60
  const id = opts.id ?? ID;
61
61
  const cwd = opts.cwd;
62
62
  /** 模型调用的次数,每次调用模型前加一 */
@@ -99,7 +99,7 @@ export function repeatsHooks(opts: { cwd: string; id?: string }): LocalHookSpec[
99
99
  return { decision: "deny", reason: "This call is identical to an earlier call in the same response and was not run; use that call's result." };
100
100
  }
101
101
  current.keys.add(k);
102
- const target = openTarget(call, cwd);
102
+ const target = openTarget(call, cwd, opts.shell(call.name));
103
103
  // 同一次回复里排在前面的调用可能改了它,还没执行,不拒绝
104
104
  if (target !== undefined && opened.get(target) === changes && !current.mutates) {
105
105
  return {
@@ -123,7 +123,7 @@ export function repeatsHooks(opts: { cwd: string; id?: string }): LocalHookSpec[
123
123
  readOnly.delete(outcome.call.toolUseId);
124
124
  if (!outcome.isError) {
125
125
  failures.delete(k);
126
- const target = openTarget(outcome.call, cwd);
126
+ const target = openTarget(outcome.call, cwd, opts.shell(outcome.call.name));
127
127
  if (target !== undefined) opened.set(target, changes);
128
128
  else if (!read) changes++;
129
129
  const file = (outcome.call.input as { path?: unknown } | null)?.path;
@@ -190,6 +190,6 @@ export function repeatsHooks(opts: { cwd: string; id?: string }): LocalHookSpec[
190
190
 
191
191
  export default definePlugin({
192
192
  session(ctx) {
193
- for (const h of repeatsHooks({ cwd: ctx.cwd, id: ctx.plugin })) ctx.kernel.hook(h);
193
+ for (const h of repeatsHooks({ cwd: ctx.cwd, id: ctx.plugin, shell: (t) => ctx.session.tool(t)?.meta?.shell })) ctx.kernel.hook(h);
194
194
  },
195
195
  });
@@ -249,6 +249,8 @@ export default definePlugin({
249
249
  },
250
250
 
251
251
  async session(ctx) {
252
+ // 子会话(子 Agent)不建定时任务,也不接收:到点的任务投到用户的会话里
253
+ if (ctx.session.parent) return;
252
254
  const store = new ScheduleStore(ctx.home);
253
255
  for (const t of tools(store, ctx.cwd)) ctx.kernel.tool(t);
254
256
 
@@ -18,6 +18,8 @@ const READY_MS = 10_000;
18
18
  const LOAD_MS = 15_000;
19
19
  /** load 之后等网络安静下来(脚本、图片、字体)的最长时间 */
20
20
  const SETTLE_MS = 3000;
21
+ /** 让浏览器自己关的最长时间,过了就直接结束进程 */
22
+ const CLOSE_MS = 5000;
21
23
  /** 滚动之后给懒加载的图片、滚动触发的动画的时间 */
22
24
  const SCROLL_SETTLE_MS = 400;
23
25
 
@@ -214,6 +216,14 @@ export const capture: Capture = async (browser, req, signal) => {
214
216
  return await Promise.race([work(), aborted]);
215
217
  } finally {
216
218
  signal.removeEventListener("abort", abort);
219
+ // 先让浏览器自己关:直接结束主进程时,Windows 上它的子进程还会占着 profile 好几秒,临时目录删不掉。
220
+ // 中止了(用户打断、超时)就不等它:马上结束,删不掉的临时目录留给系统清理
221
+ if (cdp && !signal.aborted) {
222
+ void cdp.send("Browser.close").catch(() => {});
223
+ let timer: ReturnType<typeof setTimeout> | undefined;
224
+ await Promise.race([proc.exited, new Promise((r) => (timer = setTimeout(r, CLOSE_MS)))]);
225
+ clearTimeout(timer);
226
+ }
217
227
  cdp?.close();
218
228
  proc.kill();
219
229
  await proc.exited;
@@ -1,11 +1,11 @@
1
- // jade/sessions:/clear、/resume、/retry,以及 /resume 用的会话索引。
1
+ // jade/sessions:/clear、/resume、/rewind、/retry,以及 /resume 用的会话索引。
2
2
  // 索引是 $JADE_HOME/state/sessions.jsonl,每行 { id, cwd, title, at }:会话在本进程里第一次收到消息时追加一行。
3
3
  // 读的时候按 id 合并:标题取最早的一行,时间取最晚的一行;目录按 cwdKey 比较。
4
4
 
5
5
  import { appendFile, mkdir, readFile } from "node:fs/promises";
6
6
  import path from "node:path";
7
7
  import type { UserInput } from "uncarved";
8
- import { definePlugin } from "@uncarved/jade-api";
8
+ import { definePlugin, type Draft } from "@uncarved/jade-api";
9
9
  import type { Commands, SessionIndex, SessionSummary } from "@uncarved/jade-api/services";
10
10
 
11
11
  const TITLE_CHARS = 80;
@@ -69,6 +69,20 @@ function titleOf(input: UserInput): string | undefined {
69
69
  return text.length > TITLE_CHARS ? `${text.slice(0, TITLE_CHARS)}…` : text;
70
70
  }
71
71
 
72
+ /** 用户自己写的那部分文字(插件附上的内容不算);不是消息、或者没有时为空 */
73
+ function userText(input: UserInput): string {
74
+ if (input.kind !== "message") return "";
75
+ return input.content.flatMap((b) => (b.kind === "text" && b.origin.by === "user" ? [b.text] : [])).join("\n").trim();
76
+ }
77
+
78
+ const oneLine = (text: string) => {
79
+ const one = text.replace(/\s+/g, " ");
80
+ return one.length > TITLE_CHARS ? `${one.slice(0, TITLE_CHARS)}…` : one;
81
+ };
82
+
83
+ /** 最近打开的会话的输入框(/rewind 把消息放回去);前端没有输入框时为 undefined */
84
+ let input: Draft | undefined;
85
+
72
86
  export default definePlugin({
73
87
  process(ctx) {
74
88
  const file = path.join(ctx.home, "state", "sessions.jsonl");
@@ -102,6 +116,35 @@ export default definePlugin({
102
116
  },
103
117
  });
104
118
 
119
+ commands.register({
120
+ name: "rewind",
121
+ description: "go back to before one of your messages, in a copy of this session (files stay as they are; to restore them, /undo in the session before rewinding)",
122
+ async run(_args, c) {
123
+ const s = c.sessions.current;
124
+ if (!s) return "There is no open session.";
125
+ const sent = (await s.history()).flatMap((e) => {
126
+ const text = e.type === "input.received" ? userText(e.data as UserInput) : "";
127
+ return text ? [{ seq: e.seq, text }] : [];
128
+ });
129
+ if (sent.length === 0) return "Nothing to rewind to: you have not sent a message in this session.";
130
+ const recent = sent.slice(-50).reverse();
131
+ const picked = await c.ui.select(
132
+ {
133
+ title: "Rewind to before which message?",
134
+ options: recent.map((m, i) => ({ label: oneLine(m.text), value: String(m.seq), hint: i === 0 ? "your last message" : `${i + 1} messages ago` })),
135
+ },
136
+ c.signal,
137
+ );
138
+ const to = recent.find((m) => String(m.seq) === picked);
139
+ if (!to) return;
140
+ // 原会话不动:复制出它在这条消息之前的部分,作为新会话打开。前端在会话换掉之后重新显示它的对话
141
+ await c.sessions.open({ fork: { session: s.id, before: to.seq } });
142
+ // 那条消息放回输入框,改一改再发
143
+ input?.set(to.text);
144
+ return `Rewound to before that message${input ? "; it is back in the input" : ""}. Files were not changed; to restore them, run /undo in the session before rewinding: jade --resume ${s.id}`;
145
+ },
146
+ });
147
+
105
148
  commands.register({
106
149
  name: "retry",
107
150
  description: "ask the model again after a failed request",
@@ -114,6 +157,9 @@ export default definePlugin({
114
157
  },
115
158
 
116
159
  session(ctx) {
160
+ // 子会话(子 Agent)不进 /resume 的列表,也没有输入框
161
+ if (ctx.session.parent) return;
162
+ input = ctx.input;
117
163
  const file = path.join(ctx.home, "state", "sessions.jsonl");
118
164
  let indexed = false;
119
165
  ctx.kernel.hook({
@@ -1,8 +1,8 @@
1
1
  // jade/shell:bash 工具,以及后台命令的 bash_output、kill_shell;shell@1 给其他插件执行命令。
2
2
  // 后台命令自己结束时告诉用户,并给模型留一句说明(不用它一直轮询);/shells 给用户看和停掉后台命令。
3
3
 
4
- import { definePlugin, type UI } from "@uncarved/jade-api";
5
- import type { Commands, Prompts, Renderers, Tools } from "@uncarved/jade-api/services";
4
+ import { definePlugin, type Span, type UI } from "@uncarved/jade-api";
5
+ import type { Commands, Prompts, Renderers } from "@uncarved/jade-api/services";
6
6
  import { shellRenderers } from "./renderers.ts";
7
7
  import { shellService } from "./service.ts";
8
8
  import { shellTools, type ShellTools } from "./shell.ts";
@@ -20,10 +20,8 @@ const SH_TIMEOUT_MS = 600_000;
20
20
  const SH_LIVE_CHARS = 4000;
21
21
  /** /sh 的结果收起时那一行最多这么多个字符 */
22
22
  const SH_SUMMARY = 160;
23
- // 设了 NO_COLOR(非空)或标准输出不是终端时不输出颜色
24
- const colors = Boolean(process.stdout.isTTY) && !process.env.NO_COLOR;
25
- /** 失败的红色,其余的灰色 */
26
- const shade = (failed: boolean, s: string) => (colors ? (failed ? `\x1b[31m${s}\x1b[39m` : `\x1b[2m${s}\x1b[22m`) : s);
23
+ /** 结果的一行:失败的是错误,成功的是次要的(带语义样式的文字,怎么画由前端决定) */
24
+ const shade = (failed: boolean, text: string): Span => ({ text, style: failed ? "error" : "dim" });
27
25
 
28
26
  export default definePlugin({
29
27
  process(ctx) {
@@ -41,6 +39,8 @@ export default definePlugin({
41
39
  name: "sh",
42
40
  args: "<command>",
43
41
  description: "run a shell command yourself (short form: !<command>); then the agent continues with its output",
42
+ prefix: "!",
43
+ prefixHint: "shell command · you run it, not the agent",
44
44
  // 不是 instant:和消息一样排队,前端才把它当作正在做的事(esc 能停掉它)
45
45
  async run(args, { sessions: manager, signal, print, progress }) {
46
46
  const command = args.trim();
@@ -107,25 +107,20 @@ export default definePlugin({
107
107
  },
108
108
  });
109
109
  sessions.set(id, { list, kill });
110
- // 嵌套 Agent 的 bash:只收命令和时限,不能在后台跑。它不是只读工具,哪些命令能执行由使用方把关
111
- // (jade/task 按审批规则只放行只读的命令,下面的说明文字是按这个写的)
112
- const bash = tools.find((t) => t.name === "bash");
113
- try {
114
- if (bash) {
115
- ctx.service<Tools>("tools@1")?.register({
116
- ...bash,
117
- description:
118
- "Run a read-only shell command in the working directory (for example git log, git diff, git status, ls, rg) and return its exit code and output. " +
119
- "Commands that could change anything, or that touch paths outside the working directory, are refused.",
120
- inputSchema: { type: "object", properties: { command: { type: "string" }, timeout_ms: { type: "integer" } }, required: ["command"], additionalProperties: false },
121
- execute: (input, c) => bash.execute({ command: (input as { command: string }).command, timeout_ms: (input as { timeout_ms?: number }).timeout_ms }, c),
122
- });
123
- }
124
- } catch {
125
- // jade/tools 被隔离时它的服务已失效:嵌套 Agent 没有 bash,主会话的照常
126
- }
127
- if (unavailable) ctx.service<UI>("ui@1")?.notify(unavailable, "warning");
128
- for (const tool of tools) ctx.kernel.tool(tool);
110
+ // 子会话(子 Agent)里的 bash 只收命令和时限,不能在后台跑:子 Agent 交了报告会话就结束,后台命令随之被杀掉
111
+ const child = ctx.session.parent !== undefined;
112
+ const foreground = (t: (typeof tools)[number]): (typeof tools)[number] =>
113
+ t.name !== "bash"
114
+ ? t
115
+ : {
116
+ ...t,
117
+ inputSchema: { type: "object", properties: { command: { type: "string" }, timeout_ms: { type: "integer" } }, required: ["command"], additionalProperties: false },
118
+ execute: (input, c) => t.execute({ command: (input as { command: string }).command, timeout_ms: (input as { timeout_ms?: number }).timeout_ms }, c),
119
+ };
120
+ // 主会话已经说过一次
121
+ if (unavailable && !child) ctx.service<UI>("ui@1")?.notify(unavailable, "warning");
122
+ // 管后台命令的工具(bash_output、kill_shell)子会话里用不上
123
+ for (const tool of tools) if (!(child && (tool.name === "bash_output" || tool.name === "kill_shell"))) ctx.kernel.tool(child ? foreground(tool) : tool);
129
124
  if (executable) {
130
125
  const lines = [`- Shell for the bash tool: ${executable} (POSIX syntax, also on Windows)`];
131
126
  // 模型常用 xdg-open、open 打开文件,Git Bash 里没有;start 是 Git 自带的 /usr/bin/start
@@ -8,8 +8,7 @@
8
8
  "ui@1",
9
9
  "prompts@1",
10
10
  "renderers@1",
11
- "commands@1",
12
- "tools@1"
11
+ "commands@1"
13
12
  ],
14
13
  "config": {
15
14
  "shell": {
@@ -4,12 +4,14 @@
4
4
  // 正是想要的;自己写 progress 反而只能把一次推送(可能是好几行、半行)显示成一行。
5
5
 
6
6
  import type { ToolRenderer } from "@uncarved/jade-api/services";
7
+ import type { Span, Text } from "@uncarved/jade-api";
7
8
 
8
9
  // 截断和颜色从旧 jade 的 ui/render.ts、ui/screen.ts 复制:插件之间不共享代码,fs 插件也有一份
9
10
  const clip = (s: string, n: number) => (s.length > n ? s.slice(0, n) + "…" : s);
10
- // 设了 NO_COLOR(非空)或标准输出不是终端时不输出颜色,见 https://no-color.org
11
- const colors = Boolean(process.stdout.isTTY) && !process.env.NO_COLOR;
12
- const dim = (s: string) => (colors ? `\x1b[2m${s.replaceAll("\x1b[22m", "\x1b[22m\x1b[2m")}\x1b[22m` : s);
11
+ // 带语义样式的文字(jade-api 的 Text):怎么画由前端决定
12
+ const dim = (text: string): Span => ({ text, style: "dim" });
13
+ /** 几行接成一段,行之间换行 */
14
+ const joinLines = (rows: readonly Text[]): Text => rows.flatMap((r, i) => (i ? ["\n", r] : [r]));
13
15
 
14
16
  type Args = Record<string, unknown>;
15
17
  const args = (input: unknown) => (input !== null && typeof input === "object" ? input : {}) as Args;
@@ -19,11 +21,11 @@ const command = (input: unknown) => String(args(input).command ?? "");
19
21
  const MAX_SUMMARY = 120;
20
22
 
21
23
  /** 预览里的多行文字:每行前面加上标记,最多 max 行 */
22
- function marked(s: string, mark: string, max = 30): string {
24
+ function marked(s: string, mark: string, max = 30): Text {
23
25
  const all = s.split("\n");
24
- const shown = all.slice(0, max).map((l) => `${mark} ${l}`);
26
+ const shown: Text[] = all.slice(0, max).map((l) => `${mark} ${l}`);
25
27
  if (all.length > max) shown.push(dim(` … ${all.length - max} more lines`));
26
- return shown.join("\n");
28
+ return joinLines(shown);
27
29
  }
28
30
 
29
31
  export const shellRenderers: ToolRenderer[] = [
@@ -36,7 +38,7 @@ export const shellRenderers: ToolRenderer[] = [
36
38
  if (lines.length === 1 && lines[0]!.length <= MAX_SUMMARY) return undefined;
37
39
  const shown = lines.slice(0, 200).map((l, i) => dim(`${i === 0 ? "$" : " "} ${l}`));
38
40
  if (lines.length > 200) shown.push(dim(`… ${lines.length - 200} more lines`));
39
- return shown.join("\n");
41
+ return joinLines(shown);
40
42
  },
41
43
  preview: (input) => marked(command(input), "$"),
42
44
  },
@@ -6,6 +6,7 @@
6
6
  import { existsSync } from "node:fs";
7
7
  import path from "node:path";
8
8
  import type { Tool } from "uncarved";
9
+ import type { ToolMeta } from "@uncarved/jade-api";
9
10
  import { runSync, spawn as spawnProc, which, type Proc } from "./sys.ts";
10
11
  import type { RunCommand, RunResult } from "@uncarved/jade-api/services";
11
12
 
@@ -104,8 +105,9 @@ export function shellTools(opts: ShellOptions): ShellTools {
104
105
  await bg.proc.exited;
105
106
  };
106
107
 
107
- const bash: Tool = {
108
+ const bash: Tool & { meta: ToolMeta } = {
108
109
  name: "bash",
110
+ meta: { shell: "command" },
109
111
  description:
110
112
  `Run a shell command with ${shell} -c in the working directory and return its exit code, stdout and stderr. ` +
111
113
  `Each call starts a fresh shell: cd and environment variables do not persist. ` +
@@ -5,10 +5,10 @@
5
5
  // 它只是给模型看的文字,不执行代码;和旧 jade 一样,列表里有项目层的 skill 时整段标为不可信。
6
6
 
7
7
  import path from "node:path";
8
- import { definePlugin, type Cli, type Sources, type UI } from "@uncarved/jade-api";
8
+ import { definePlugin, type Cli, type Sources, type Text, type UI } from "@uncarved/jade-api";
9
9
  import type { Approval, Commands, Prompts } from "@uncarved/jade-api/services";
10
10
  import { addSkill, removeSkill, skillsRoot, updateSkills } from "./install.ts";
11
- import { bold, clip, dim, display, estimateTokens, realPath, red, repoRoot, splitArgs } from "./project.ts";
11
+ import { bold, clip, dim, display, error, estimateTokens, lines as joinLines, plain, realPath, repoRoot, splitArgs } from "./project.ts";
12
12
  import { loadSkills, skillLine, skillsPrompt, skillTool, type Skill } from "./skills.ts";
13
13
 
14
14
  const ID = "jade/skills";
@@ -36,7 +36,7 @@ export const manageUsage = (cmd: string) => `usage: ${cmd} [list]
36
36
  export async function manageSkills(
37
37
  argv: readonly string[],
38
38
  env: { home: string; cwd: string; cmd: string; sources: Sources; log?: (text: string) => void; skills?: Skill[] },
39
- ): Promise<string> {
39
+ ): Promise<Text> {
40
40
  const usage = manageUsage(env.cmd);
41
41
  const [sub, ...tail] = argv;
42
42
  if (sub === "-h" || sub === "--help" || tail.includes("-h") || tail.includes("--help")) return usage;
@@ -50,10 +50,10 @@ export async function manageSkills(
50
50
  return dim(`(no skills) install one with ${env.cmd} add <source>, or put it in ${display(env.cwd, path.join(env.home, "skills"))}/<name>/SKILL.md or .jade/skills/<name>/SKILL.md\nthe skill tool itself takes ≈${toolTokens} tokens in every request`);
51
51
  }
52
52
  const total = toolTokens + estimateTokens(skillsPrompt(skills)!);
53
- return [
54
- ...skills.map((sk) => `${bold(sk.name)} ${dim(`${sk.layer} · ${display(env.cwd, sk.dir)} · ≈${estimateTokens(skillLine(sk))} tokens`)}\n ${clip(sk.description.replace(/\s+/g, " "), 300)}`),
53
+ return joinLines([
54
+ ...skills.map((sk): Text => [bold(sk.name), " ", dim(`${sk.layer} · ${display(env.cwd, sk.dir)} · ≈${estimateTokens(skillLine(sk))} tokens`), `\n ${clip(sk.description.replace(/\s+/g, " "), 300)}`]),
55
55
  dim(`≈${total} tokens in every request (the skill list and the skill tool); a skill's instructions are read only when it is used`),
56
- ].join("\n");
56
+ ]);
57
57
  }
58
58
  const positionals: string[] = [];
59
59
  let project = false;
@@ -124,19 +124,20 @@ export default definePlugin({
124
124
  try {
125
125
  argv = splitArgs(args);
126
126
  } catch (e) {
127
- return red(errorText(e));
127
+ return error(errorText(e));
128
128
  }
129
129
  try {
130
130
  return await manageSkills(argv, { home: ctx.home, cwd: ctx.cwd, cmd: "/skills", sources, log: (t) => cctx.print(dim(t)), ...(latest ? { skills: latest } : {}) });
131
131
  } catch (e) {
132
- return red(errorText(e));
132
+ return error(errorText(e));
133
133
  }
134
134
  },
135
135
  });
136
136
  // 同样的事也能在终端里做:jade skills add <source> [--project](cli@1,核心提供)
137
137
  ctx.service<Cli>("cli@1")?.register({
138
138
  name: "skills",
139
- run: (argv, cli) => manageSkills(argv, { home: ctx.home, cwd: ctx.cwd, cmd: "jade skills", sources, log: cli.log }),
139
+ // 终端里的命令输出到 stdout,常常被管道接走:只要文字
140
+ run: async (argv, cli) => plain(await manageSkills(argv, { home: ctx.home, cwd: ctx.cwd, cmd: "jade skills", sources, log: cli.log })),
140
141
  });
141
142
  },
142
143
 
@@ -154,17 +155,11 @@ export default definePlugin({
154
155
  /** 这个会话注册过的 /<skill> 命令 */
155
156
  const mine = new Set<string>();
156
157
 
157
- /** 用新找到的 skill 更新提示词里的列表、可读目录和 /<skill> 命令;没变时什么也不做(不让提示缓存失效) */
158
- const apply = (skills: Skill[], warnings: string[]) => {
159
- for (const w of warnings) {
160
- if (warned.has(w)) continue;
161
- warned.add(w);
162
- ui?.notify(`${ID}: ${w}`, "warning");
163
- }
164
- current = skills;
165
- latest = skills;
158
+ const child = ctx.session.parent !== undefined;
159
+ /** 更新提示词里的列表和可读目录;没变时什么也不做(不让提示缓存失效),返回 false */
160
+ const applyPrompt = (skills: Skill[]): boolean => {
166
161
  const key = JSON.stringify(skills.map((s) => [s.name, s.description, s.dir, s.layer]));
167
- if (key === shown) return;
162
+ if (key === shown) return false;
168
163
  shown = key;
169
164
 
170
165
  // 有随仓库分发的 skill 时整段不可信
@@ -175,6 +170,20 @@ export default definePlugin({
175
170
  const dirs = new Set(skills.map((s) => s.dir));
176
171
  for (const [dir, revoke] of readable) if (!dirs.has(dir)) (revoke(), readable.delete(dir));
177
172
  for (const dir of dirs) if (!readable.has(dir) && approval) readable.set(dir, approval.allowRead(dir));
173
+ return true;
174
+ };
175
+ /** 用新找到的 skill 更新提示词里的列表、可读目录和 /<skill> 命令;没变时什么也不做(不让提示缓存失效) */
176
+ const apply = (skills: Skill[], warnings: string[]) => {
177
+ for (const w of warnings) {
178
+ if (warned.has(w)) continue;
179
+ warned.add(w);
180
+ ui?.notify(`${ID}: ${w}`, "warning");
181
+ }
182
+ current = skills;
183
+ // 子会话(子 Agent)的 skill 和用户的会话一样,/skills、/<skill> 命令归用户的会话管:子会话关闭时不能把它们带走
184
+ if (child) return applyPrompt(skills);
185
+ latest = skills;
186
+ if (!applyPrompt(skills)) return;
178
187
 
179
188
  // skill 也可以当命令用:/<skill 名> [要做的事]。
180
189
  // 新会话在旧会话关闭之前打开:旧会话注册的同名命令先撤销,换成这个会话的。