@uncarved/jade 0.2.0 → 0.3.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 (224) hide show
  1. package/README.md +277 -0
  2. package/assets/logo.svg +1 -0
  3. package/bin/jade.js +15 -0
  4. package/dist/api.d.ts +5 -250
  5. package/dist/api.js +5 -7
  6. package/dist/api.js.map +1 -1
  7. package/dist/fetch.d.ts +8 -0
  8. package/dist/fetch.js +19 -17
  9. package/dist/fetch.js.map +1 -1
  10. package/dist/host.d.ts +12 -1
  11. package/dist/host.js +49 -1
  12. package/dist/host.js.map +1 -1
  13. package/dist/index.d.ts +1 -1
  14. package/dist/index.js +1 -1
  15. package/dist/index.js.map +1 -1
  16. package/dist/main.js +28 -5
  17. package/dist/main.js.map +1 -1
  18. package/dist/remote.js +4 -0
  19. package/dist/remote.js.map +1 -1
  20. package/dist/session.d.ts +2 -0
  21. package/dist/session.js +133 -13
  22. package/dist/session.js.map +1 -1
  23. package/dist/source.d.ts +2 -10
  24. package/dist/source.js.map +1 -1
  25. package/dist/update.d.ts +8 -20
  26. package/dist/update.js +12 -1
  27. package/dist/update.js.map +1 -1
  28. package/package.json +6 -4
  29. package/plugins/approval/index.ts +246 -84
  30. package/plugins/approval/plugin.json +5 -1
  31. package/plugins/approval/policy.ts +27 -6
  32. package/plugins/approval/review.ts +1 -1
  33. package/plugins/ask/index.ts +2 -2
  34. package/plugins/budget/index.ts +1 -1
  35. package/plugins/checks/checks.ts +3 -2
  36. package/plugins/checks/index.ts +2 -5
  37. package/plugins/commands/index.ts +2 -44
  38. package/plugins/compact/compact.ts +15 -4
  39. package/plugins/compact/index.ts +13 -16
  40. package/plugins/continue/index.ts +1 -1
  41. package/plugins/cost/index.ts +143 -0
  42. package/plugins/cost/plugin.json +13 -0
  43. package/plugins/custom-commands/index.ts +85 -0
  44. package/plugins/custom-commands/plugin.json +8 -0
  45. package/plugins/editor/index.ts +88 -0
  46. package/plugins/editor/plugin.json +17 -0
  47. package/plugins/fs/fs.ts +110 -17
  48. package/plugins/fs/grep.ts +41 -11
  49. package/plugins/fs/index.ts +9 -7
  50. package/plugins/fs/renderers.ts +1 -1
  51. package/plugins/hooks/index.ts +152 -0
  52. package/plugins/hooks/plugin.json +14 -0
  53. package/plugins/keys/index.ts +2 -18
  54. package/plugins/mcp/index.ts +40 -12
  55. package/plugins/mcp/install.ts +139 -0
  56. package/plugins/mcp/mcp.ts +2 -1
  57. package/plugins/mcp/plugin.json +1 -1
  58. package/plugins/mcp/project.ts +37 -1
  59. package/plugins/memory/index.ts +4 -9
  60. package/plugins/memory/plugin.json +1 -1
  61. package/plugins/mentions/index.ts +33 -13
  62. package/plugins/models/configure.ts +258 -150
  63. package/plugins/models/context.ts +2 -2
  64. package/plugins/models/index.ts +50 -42
  65. package/plugins/models/plugin.json +1 -1
  66. package/plugins/models/provider.ts +22 -4
  67. package/plugins/models/saved.ts +8 -4
  68. package/plugins/modes/index.ts +2 -17
  69. package/plugins/plugins/index.ts +2 -2
  70. package/plugins/print/index.ts +60 -12
  71. package/plugins/print/plugin.json +1 -0
  72. package/plugins/prompts/index.ts +50 -14
  73. package/plugins/{memory → prompts}/notes.ts +21 -9
  74. package/plugins/prompts/plugin.json +8 -2
  75. package/plugins/prompts/prompts.ts +14 -8
  76. package/plugins/prompts/results.ts +63 -0
  77. package/plugins/prompts/sys.ts +16 -4
  78. package/plugins/renderers/index.ts +2 -43
  79. package/plugins/repeats/index.ts +1 -1
  80. package/plugins/schedule/index.ts +2 -2
  81. package/plugins/scratch/index.ts +2 -3
  82. package/plugins/screenshot/index.ts +26 -13
  83. package/plugins/screenshot/plugin.json +1 -1
  84. package/plugins/sessions/index.ts +2 -17
  85. package/plugins/shell/index.ts +56 -6
  86. package/plugins/shell/plugin.json +3 -1
  87. package/plugins/shell/renderers.ts +1 -1
  88. package/plugins/shell/service.ts +2 -13
  89. package/plugins/shell/shell.ts +31 -16
  90. package/plugins/skills/index.ts +172 -37
  91. package/plugins/skills/install.ts +212 -0
  92. package/plugins/skills/plugin.json +3 -2
  93. package/plugins/skills/project.ts +38 -1
  94. package/plugins/skills/skills.ts +28 -9
  95. package/plugins/steer/index.ts +142 -0
  96. package/plugins/steer/plugin.json +8 -0
  97. package/plugins/suggest/index.ts +16 -11
  98. package/plugins/suggest/plugin.json +1 -1
  99. package/plugins/task/index.ts +8 -16
  100. package/plugins/task/plugin.json +9 -2
  101. package/plugins/task/subagent.ts +119 -15
  102. package/plugins/todo/index.ts +4 -4
  103. package/plugins/tui/editor.ts +10 -2
  104. package/plugins/tui/frontend.ts +130 -25
  105. package/plugins/tui/index.ts +3 -8
  106. package/plugins/tui/markdown.ts +51 -6
  107. package/plugins/tui/mascot.ts +505 -0
  108. package/plugins/tui/mentions.ts +48 -8
  109. package/plugins/tui/plugin.json +2 -2
  110. package/plugins/tui/screen.ts +6 -0
  111. package/plugins/tui/transcript.ts +22 -3
  112. package/plugins/tui/tui.ts +323 -95
  113. package/plugins/tui/vendor.ts +16 -0
  114. package/plugins/undo/checkpoint.ts +26 -2
  115. package/plugins/undo/index.ts +86 -24
  116. package/plugins/undo/plugin.json +8 -2
  117. package/plugins/undo/snapshot.ts +129 -0
  118. package/plugins/update/index.ts +11 -15
  119. package/plugins/update/plugin.json +2 -1
  120. package/plugins/web/index.ts +2 -5
  121. package/plugins/web/renderers.ts +1 -1
  122. package/plugins/web/web.ts +6 -5
  123. package/plugins-dist/approval/index.js +232 -50
  124. package/plugins-dist/approval/plugin.json +5 -1
  125. package/plugins-dist/approval/policy.js +27 -5
  126. package/plugins-dist/ask/index.js +1 -1
  127. package/plugins-dist/budget/index.js +1 -1
  128. package/plugins-dist/checks/checks.js +2 -1
  129. package/plugins-dist/checks/index.js +1 -1
  130. package/plugins-dist/commands/index.js +1 -1
  131. package/plugins-dist/compact/compact.js +13 -2
  132. package/plugins-dist/compact/index.js +12 -8
  133. package/plugins-dist/continue/index.js +1 -1
  134. package/plugins-dist/cost/index.js +135 -0
  135. package/plugins-dist/cost/plugin.json +16 -0
  136. package/plugins-dist/custom-commands/index.js +86 -0
  137. package/plugins-dist/custom-commands/plugin.json +12 -0
  138. package/plugins-dist/editor/index.js +89 -0
  139. package/plugins-dist/editor/plugin.json +21 -0
  140. package/plugins-dist/fs/fs.js +106 -17
  141. package/plugins-dist/fs/grep.js +40 -12
  142. package/plugins-dist/fs/index.js +8 -5
  143. package/plugins-dist/hooks/index.js +145 -0
  144. package/plugins-dist/hooks/plugin.json +19 -0
  145. package/plugins-dist/keys/index.js +1 -1
  146. package/plugins-dist/mcp/index.js +41 -9
  147. package/plugins-dist/mcp/install.js +160 -0
  148. package/plugins-dist/mcp/mcp.js +2 -1
  149. package/plugins-dist/mcp/plugin.json +2 -1
  150. package/plugins-dist/mcp/project.js +42 -1
  151. package/plugins-dist/memory/index.js +3 -5
  152. package/plugins-dist/memory/plugin.json +1 -1
  153. package/plugins-dist/mentions/index.js +29 -11
  154. package/plugins-dist/models/configure.js +252 -151
  155. package/plugins-dist/models/context.js +2 -2
  156. package/plugins-dist/models/index.js +53 -16
  157. package/plugins-dist/models/plugin.json +1 -1
  158. package/plugins-dist/models/provider.js +4 -2
  159. package/plugins-dist/models/saved.js +9 -4
  160. package/plugins-dist/modes/index.js +1 -1
  161. package/plugins-dist/plugins/index.js +1 -1
  162. package/plugins-dist/print/index.js +62 -9
  163. package/plugins-dist/print/plugin.json +3 -0
  164. package/plugins-dist/prompts/index.js +49 -2
  165. package/plugins-dist/{memory → prompts}/notes.js +10 -7
  166. package/plugins-dist/prompts/plugin.json +8 -2
  167. package/plugins-dist/prompts/prompts.js +13 -8
  168. package/plugins-dist/prompts/results.js +60 -0
  169. package/plugins-dist/prompts/sys.js +15 -3
  170. package/plugins-dist/renderers/index.js +1 -1
  171. package/plugins-dist/repeats/index.js +1 -1
  172. package/plugins-dist/schedule/index.js +1 -1
  173. package/plugins-dist/scratch/index.js +1 -1
  174. package/plugins-dist/screenshot/index.js +25 -11
  175. package/plugins-dist/screenshot/plugin.json +1 -1
  176. package/plugins-dist/sessions/index.js +1 -1
  177. package/plugins-dist/shell/index.js +55 -3
  178. package/plugins-dist/shell/plugin.json +3 -1
  179. package/plugins-dist/shell/shell.js +26 -8
  180. package/plugins-dist/skills/index.js +184 -35
  181. package/plugins-dist/skills/install.js +178 -0
  182. package/plugins-dist/skills/plugin.json +6 -2
  183. package/plugins-dist/skills/project.js +43 -1
  184. package/plugins-dist/skills/skills.js +27 -10
  185. package/plugins-dist/steer/index.js +135 -0
  186. package/plugins-dist/steer/plugin.json +12 -0
  187. package/plugins-dist/suggest/index.js +15 -9
  188. package/plugins-dist/suggest/plugin.json +1 -1
  189. package/plugins-dist/task/index.js +7 -4
  190. package/plugins-dist/task/plugin.json +10 -2
  191. package/plugins-dist/task/subagent.js +106 -15
  192. package/plugins-dist/todo/index.js +3 -3
  193. package/plugins-dist/tui/editor.js +7 -2
  194. package/plugins-dist/tui/frontend.js +135 -18
  195. package/plugins-dist/tui/index.js +2 -1
  196. package/plugins-dist/tui/markdown.js +48 -6
  197. package/plugins-dist/tui/mascot.js +439 -0
  198. package/plugins-dist/tui/mentions.js +44 -6
  199. package/plugins-dist/tui/plugin.json +3 -2
  200. package/plugins-dist/tui/screen.js +2 -0
  201. package/plugins-dist/tui/transcript.js +19 -2
  202. package/plugins-dist/tui/tui.js +303 -83
  203. package/plugins-dist/tui/vendor.js +13822 -0
  204. package/plugins-dist/undo/checkpoint.js +28 -1
  205. package/plugins-dist/undo/index.js +92 -22
  206. package/plugins-dist/undo/plugin.json +10 -3
  207. package/plugins-dist/undo/snapshot.js +111 -0
  208. package/plugins-dist/update/index.js +9 -10
  209. package/plugins-dist/update/plugin.json +4 -1
  210. package/plugins-dist/web/index.js +1 -1
  211. package/plugins-dist/web/web.js +6 -5
  212. package/sdk/python/__pycache__/jade_plugin.cpython-312.pyc +0 -0
  213. package/sdk/python/jade_plugin.py +8 -0
  214. package/src/api.ts +7 -262
  215. package/src/fetch.ts +18 -16
  216. package/src/host.ts +49 -1
  217. package/src/index.ts +1 -1
  218. package/src/main.ts +25 -6
  219. package/src/remote.ts +2 -0
  220. package/src/session.ts +134 -15
  221. package/src/source.ts +2 -11
  222. package/src/update.ts +16 -10
  223. package/plugins/undo/notes.ts +0 -43
  224. package/plugins-dist/undo/notes.js +0 -36
@@ -1,48 +1,32 @@
1
- // jade/approval:审批。tool.before 把路径统一成绝对路径,tool.gate 按模式和规则决定,要问时经 ui@1 问用户。
1
+ // jade/approval:审批。tool.before 把路径统一成绝对路径,tool.gate 按模式和规则决定:允许、拒绝,或者要问用户(ask)。
2
+ // 关卡不等用户:所有关卡合并的结果是 ask 时(日志里的 tool.decided),内核停下来等人工审批,这里才经 ui@1 问用户,
3
+ // 把回答作为 approval 输入交给会话。别的插件的关卡要问时也由这里问。谁回答的、选了什么记成 jade/approval/answered 事件。
2
4
  // auto 模式下规则判断不了、本来要问的调用先让模型审一次(review.ts):它只能放行或转给用户,不能替用户拒绝。
3
5
  //
4
6
  // 没有这个插件(停用、坏掉、被隔离)时,核心的兜底关卡拒绝所有非只读工具(第 7 节),所以这里出错不会放行。
5
- // 用户选的"总是允许"记进日志(derived),恢复会话后仍然有效;模式是进程级的,来自配置,可以经 approval@1 改。
7
+ // 用户选的"总是允许"记进日志(derived),恢复会话后仍然有效;选"在这个目录里总是允许"的记在
8
+ // $JADE_HOME/state/approvals.json(按工作目录),以后在这个目录里开的会话都有效。模式是进程级的,来自配置,可以经 approval@1 改。
6
9
 
10
+ import { mkdir, readFile, writeFile } from "node:fs/promises";
7
11
  import path from "node:path";
8
- import type { GatedToolCall, Message } from "uncarved";
9
- import { definePlugin, type Caller, type SelectRequest, type UI } from "../../src/api.ts";
10
- import type { Models } from "../models/index.ts";
11
- import type { Renderers } from "../renderers/index.ts";
12
+ import type { EventDataMap, GatedToolCall, Message } from "uncarved";
13
+ import { definePlugin, type Caller, type SelectRequest, type UI } from "@uncarved/jade-api";
14
+ import type { Answer, Approval, Approver, Models, Renderers } from "@uncarved/jade-api/services";
12
15
  import { describeRule, MODES, policy, type AllowRule, type Mode } from "./policy.ts";
13
16
  import { reviewer, type Review } from "./review.ts";
14
17
 
15
- /** approval@1 */
16
- export interface Approval {
17
- mode(): Mode;
18
- setMode(mode: Mode): void;
19
- /** 读这个目录(绝对路径)里的文件不用问,例如 skill 的目录。返回撤销函数,调用方的作用域关闭时自动撤销。项目层插件不能用 */
20
- allowRead(dir: string): () => void;
21
- /** 这个目录(绝对路径)和工作目录同样对待:auto 模式下在里面改文件不用问,例如会话的临时目录。返回撤销函数,调用方的作用域关闭时自动撤销。项目层插件不能用 */
22
- allowWrite(dir: string): () => void;
23
- /**
24
- * 登记一个审批渠道(例如聊天机器人):要问用户时,问题同时交给终端和所有渠道,先回答的算数,
25
- * 其余的经 signal 收到中止。渠道返回 undefined、不认识的值或出错,算它不回答,不算拒绝;
26
- * 终端里取消照旧算拒绝。有渠道时,不能提问的前端(-p)也会问。返回撤销函数,调用方的作用域关闭时自动撤销。
27
- * 项目层插件不能用
28
- */
29
- addApprover(approver: Approver): () => void;
30
- /**
31
- * 这个只读调用(例如子 Agent 的)在会话 session 里能不能不问就执行:按该会话"总是允许"的规则、
32
- * allowRead/allowWrite 登记的目录和 yolo 模式判断。会话不存在或不是只读调用时为 false
33
- */
34
- allows(session: string, call: GatedToolCall): boolean;
35
- }
36
-
37
- /** 审批的回答:允许一次、本会话里总是允许、拒绝 */
38
- export type Answer = "once" | "always" | "deny";
39
- export type Approver = (request: SelectRequest<Answer>, signal: AbortSignal) => Promise<Answer | undefined>;
40
- const ANSWERS: readonly string[] = ["once", "always", "deny"] satisfies Answer[];
18
+ const ANSWERS: readonly string[] = ["once", "always", "forever", "deny"] satisfies Answer[];
19
+ /** 只有终端里有的一项:拒绝,并写一句话告诉模型该怎么做 */
20
+ const EXPLAIN = "explain";
41
21
 
42
22
  /** derived 里保存"总是允许"规则的键 */
43
23
  const RULES_KEY = "jade/approval/rules";
44
- /** 等用户回答的时限:内核要求 hook 有有限的超时,超时按拒绝处理 */
24
+ /** 等用户回答的默认时限,过了按拒绝处理。配置 askTimeoutMinutes 可以改 */
45
25
  const ASK_TIMEOUT_MS = 24 * 60 * 60 * 1000;
26
+ /** askTimeoutMinutes 的上限:定时器最长约 24.8 天 */
27
+ const MAX_ASK_TIMEOUT_MINUTES = 7 * 24 * 60;
28
+ /** 关卡的时限:auto 模式的审查最长一分钟(review.ts),比 hook 默认的 30 秒长 */
29
+ const GATE_TIMEOUT_MS = 2 * 60_000;
46
30
  const MAX_DETAIL_CHARS = 2000;
47
31
  /** 等工具的审批预览的时限,过了就用默认的 detail */
48
32
  const PREVIEW_TIMEOUT_MS = 5000;
@@ -60,12 +44,15 @@ const reviewedKey = (call: GatedToolCall): string | undefined => {
60
44
  let mode: Mode = "ask";
61
45
  /** 配置里写错的模式:第一个会话打开时告诉用户(process 里可能还拿不到 ui@1:它的提供者可能排在后面激活) */
62
46
  let badMode: string | undefined;
47
+ let askTimeoutMs = ASK_TIMEOUT_MS;
48
+ /** 配置里写错的 askTimeoutMinutes,和 badMode 一样在第一个会话打开时告诉用户 */
49
+ let badTimeout: string | undefined;
63
50
  /** 经 allowRead 登记的目录;policy 每次判断时读它 */
64
51
  const readRoots: string[] = [];
65
52
  /** 经 allowWrite 登记的目录;policy 每次判断时读它 */
66
53
  const writeRoots: string[] = [];
67
- /** 经 addApprover 登记的审批渠道 */
68
- const approvers = new Set<Approver>();
54
+ /** 经 addApprover 登记的审批渠道 → 登记它的插件 */
55
+ const approvers = new Map<Approver, string>();
69
56
  /** 打开着的会话:会话 id → 判断只读调用能不能不问就执行(allows) */
70
57
  const sessionChecks = new Map<string, (call: GatedToolCall) => boolean>();
71
58
 
@@ -74,6 +61,11 @@ export default definePlugin({
74
61
  const configured = ctx.config.mode;
75
62
  if (typeof configured === "string" && (MODES as readonly string[]).includes(configured)) mode = configured as Mode;
76
63
  else if (configured !== undefined) badMode = JSON.stringify(configured);
64
+ const minutes = ctx.config.askTimeoutMinutes;
65
+ askTimeoutMs = ASK_TIMEOUT_MS;
66
+ badTimeout = undefined;
67
+ if (typeof minutes === "number" && Number.isFinite(minutes) && minutes > 0 && minutes <= MAX_ASK_TIMEOUT_MINUTES) askTimeoutMs = minutes * 60_000;
68
+ else if (minutes !== undefined) badTimeout = JSON.stringify(minutes);
77
69
  ctx.provide("approval@1", (caller): Approval => ({
78
70
  mode: () => mode,
79
71
  setMode(next: Mode) {
@@ -85,12 +77,12 @@ export default definePlugin({
85
77
  addApprover(approver: Approver) {
86
78
  if (caller.layer === "project") throw new Error("approval.addApprover: project plugins cannot answer approvals");
87
79
  if (typeof approver !== "function") throw new Error("approval.addApprover: approver must be a function");
88
- approvers.add(approver);
80
+ approvers.set(approver, caller.plugin);
89
81
  const remove = () => void approvers.delete(approver);
90
82
  caller.onDispose(remove);
91
83
  return remove;
92
84
  },
93
- allows: (session: string, call: GatedToolCall) => call.tool?.effect === "read" && (sessionChecks.get(session)?.(call) ?? false),
85
+ allows: (session: string, call: GatedToolCall) => call.tool !== undefined && (sessionChecks.get(session)?.(call) ?? false),
94
86
  }));
95
87
  },
96
88
 
@@ -101,6 +93,10 @@ export default definePlugin({
101
93
  ui?.notify(`jade/approval: mode must be one of ${MODES.join(", ")}, got ${badMode}; using ask`, "warning");
102
94
  badMode = undefined;
103
95
  }
96
+ if (badTimeout !== undefined) {
97
+ ui?.notify(`jade/approval: askTimeoutMinutes must be a number of minutes between 0 and ${MAX_ASK_TIMEOUT_MINUTES}, got ${badTimeout}; using 24 hours`, "warning");
98
+ badTimeout = undefined;
99
+ }
104
100
  const renderers = ctx.service<Renderers>("renderers@1");
105
101
  // auto 模式的审查用当前配置的模型;没有 models@1(模型插件被停用)或者配置里关掉时不做审查
106
102
  const models = ctx.service<Models>("models@1");
@@ -121,15 +117,31 @@ export default definePlugin({
121
117
  /** 本会话里审查过一次、放行了的调用 */
122
118
  const reviewedCalls = new Set<string>();
123
119
  let warned = false;
124
- /** 本进程里刚选的"总是允许":并发的关卡拿到的 derived 是各自开始时的快照,可能还没有它 */
120
+ /** 本进程里刚选的"总是允许":记进日志之前(要等看到那条 approval 输入)就要生效 */
125
121
  const added: AllowRule[] = [];
126
122
  /** 一次只问一个问题;排在后面的问之前重新判断,前面刚选的"总是允许"可能已经覆盖它 */
127
123
  let asking: Promise<unknown> = Promise.resolve();
128
124
  /** 日志里记下的"总是允许"规则,每次调用工具前取一次:子 Agent 在工具执行期间经 allows 用它 */
129
125
  let logged: AllowRule[] = [];
126
+ const merged = (from: readonly AllowRule[]) => [...from, ...added.filter((r) => !from.some((l) => JSON.stringify(l) === JSON.stringify(r)))];
127
+ /** "在这个目录里总是允许"的规则:会话打开时从文件读,本会话里新选的也加进来 */
128
+ const foreverFile = path.join(ctx.home, "state", "approvals.json");
129
+ const forever: AllowRule[] = (await readForever(foreverFile))[ctx.cwd] ?? [];
130
+ const saved = () => [...forever, ...merged(logged)];
131
+ /** 这一轮里关卡看过、还没有决定的调用 */
132
+ const seen = new Map<string, Asked>();
133
+ /** 已经交给会话的回答:在日志里看到那条 approval 输入时记一条 answered 事件 */
134
+ const answered = new Map<string, { answer: string; by: string }>();
135
+ /** 这一轮里已经在问、或者问过的调用 */
136
+ const handled = new Set<string>();
137
+ /** 这一轮结束(包括被中断)时中止还开着的问题 */
138
+ let turn = new AbortController();
139
+ const canAsk = () => ui?.interactive === true || approvers.size > 0;
140
+ const nobody = (name: string) => `${name} needs the user's approval, but nobody can approve it in this non-interactive run. Do not retry it; tell the user what you wanted to do.`;
141
+
130
142
  const id = ctx.session.id;
131
143
  const check = (call: GatedToolCall) =>
132
- rules.decide(call, { mode: mode === "yolo" ? "yolo" : "readonly", rules: [...logged, ...added] }).decision === "allow";
144
+ rules.decide(call, { mode: mode === "yolo" && call.tool.effect === "read" ? "yolo" : "readonly", rules: [...forever, ...logged, ...added] }).decision === "allow";
133
145
  sessionChecks.set(id, check);
134
146
  await ctx.effect(() => () => {
135
147
  if (sessionChecks.get(id) === check) sessionChecks.delete(id);
@@ -146,12 +158,9 @@ export default definePlugin({
146
158
  ctx.kernel.hook({
147
159
  kind: "gate",
148
160
  point: "tool.gate",
149
- timeoutMs: ASK_TIMEOUT_MS,
161
+ timeoutMs: GATE_TIMEOUT_MS,
150
162
  fn: async (call, hook) => {
151
- const saved = () => {
152
- const logged = (hook.derived[RULES_KEY] as AllowRule[] | undefined) ?? [];
153
- return [...logged, ...added.filter((r) => !logged.some((l) => JSON.stringify(l) === JSON.stringify(r)))];
154
- };
163
+ seen.set(call.toolUseId, { call });
155
164
  const result = rules.decide(call, { mode, rules: saved() });
156
165
  if (result.decision !== "ask") return result;
157
166
  // auto 模式:规则判断不了、本来要问的调用先让模型审一次。审查只能放行或转给用户,不会替用户拒绝
@@ -168,7 +177,7 @@ export default definePlugin({
168
177
  }
169
178
  why = verdict.reason;
170
179
  }
171
- if (!ui?.interactive && approvers.size === 0) {
180
+ if (!canAsk()) {
172
181
  if (!warned) {
173
182
  warned = true;
174
183
  ui?.notify(
@@ -177,42 +186,161 @@ export default definePlugin({
177
186
  "warning",
178
187
  );
179
188
  }
180
- return { decision: "deny", reason: `${call.name} needs the user's approval, but nobody can approve it in this non-interactive run. Do not retry it; tell the user what you wanted to do.` };
189
+ return { decision: "deny", reason: nobody(call.name) };
190
+ }
191
+ seen.set(call.toolUseId, { call, mine: call, ...(why ? { why } : {}) });
192
+ return { decision: "ask" };
193
+ },
194
+ });
195
+
196
+ /** 问用户(或按刚加的规则直接决定),返回交给内核的回答 */
197
+ const decide = async (asked: Asked, signal: AbortSignal): Promise<Verdict> => {
198
+ const { call } = asked;
199
+ if (asked.mine) {
200
+ const again = rules.decide(asked.mine, { mode, rules: saved() });
201
+ if (again.decision === "allow") return { approved: true, answer: "allow", by: "rule" };
202
+ if (again.decision === "deny") return { approved: false, answer: "deny", by: "rule", reason: again.reason };
203
+ }
204
+ if (!canAsk()) return { approved: false, answer: "deny", by: "nobody", reason: nobody(call.name) };
205
+ const rule = rules.ruleFor(call);
206
+ const shown = (await preview(renderers, call)) ?? detail(call);
207
+ const expired = new AbortController();
208
+ const timer = setTimeout(() => expired.abort(), askTimeoutMs);
209
+ let got: { answer: Answer; by: string; said?: string } | undefined;
210
+ try {
211
+ got = await ask(
212
+ ui,
213
+ {
214
+ title: `Allow ${call.name}?`,
215
+ // 审查转给用户的:先说为什么
216
+ detail: asked.why ? `${asked.why}\n\n${shown}` : shown,
217
+ options: [
218
+ { label: "Allow once", value: "once" },
219
+ // 别的插件要问的调用不能"总是允许":这里的规则管不到它的关卡
220
+ ...(asked.mine
221
+ ? [
222
+ { label: `Always allow ${describeRule(rule)} in this session`, value: "always" as const },
223
+ { label: `Always allow ${describeRule(rule)} in this directory, in every session`, value: "forever" as const },
224
+ ]
225
+ : []),
226
+ { label: "Deny", value: "deny" },
227
+ ],
228
+ },
229
+ AbortSignal.any([signal, expired.signal, ctx.signal]),
230
+ );
231
+ } finally {
232
+ clearTimeout(timer);
233
+ }
234
+ if (expired.signal.aborted) {
235
+ return { approved: false, answer: "deny", by: "timeout", reason: `Nobody answered the approval request for ${call.name} in time. Do not retry it; tell the user what you wanted to do.` };
236
+ }
237
+ if (got?.answer === "always" && asked.mine) {
238
+ added.push(rule);
239
+ return { approved: true, answer: "always", by: got.by };
240
+ }
241
+ if (got?.answer === "forever" && asked.mine) {
242
+ forever.push(rule);
243
+ try {
244
+ await addForever(foreverFile, ctx.cwd, rule);
245
+ ui?.notify(`${describeRule(rule)} is now always allowed in ${ctx.cwd}. To ask again, remove it from ${foreverFile}`, "info");
246
+ } catch (e) {
247
+ ui?.notify(`could not save the rule to ${foreverFile} (${e instanceof Error ? e.message : String(e)}); it only applies to this session`, "warning");
248
+ }
249
+ return { approved: true, answer: "forever", by: got.by };
250
+ }
251
+ if (got !== undefined && got.answer !== "deny") return { approved: true, answer: "once", by: got.by };
252
+ if (got?.said) return { approved: false, answer: "deny", by: got.by, reason: `The user denied this tool call and said: ${got.said}` };
253
+ return { approved: false, answer: "deny", by: got?.by ?? "nobody", reason: "The user denied this tool call. Do not retry it unchanged: adjust, or ask what to do instead." };
254
+ };
255
+
256
+ /** 一个要问的调用:得出回答,交给会话。出错也要回答(拒绝),否则这一轮一直等着 */
257
+ const settle = async (asked: Asked, signal: AbortSignal) => {
258
+ const toolUseId = asked.call.toolUseId;
259
+ let verdict: Verdict;
260
+ try {
261
+ verdict = await decide(asked, signal);
262
+ } catch (e) {
263
+ verdict = { approved: false, answer: "deny", by: "error", reason: `Asking for approval failed: ${e instanceof Error ? e.message : String(e)}` };
264
+ }
265
+ // 这一轮已经结束(被中断):回答作废
266
+ if (signal.aborted) return;
267
+ answered.set(toolUseId, { answer: verdict.answer, by: verdict.by });
268
+ // 不等它:它要到内核再次停下才 resolve,后面排着的问题可能就是内核在等的
269
+ void Promise.resolve()
270
+ .then(() => ctx.session.send({ kind: "approval", toolUseId, approved: verdict.approved, ...(verdict.reason ? { reason: verdict.reason } : {}) }))
271
+ .catch(() => void answered.delete(toolUseId));
272
+ };
273
+
274
+ ctx.kernel.hook({
275
+ kind: "observe",
276
+ point: "event",
277
+ fn: async (e, hook) => {
278
+ if (e.type === "tool.decided") {
279
+ const d = e.data as EventDataMap["tool.decided"];
280
+ const asked = seen.get(d.toolUseId);
281
+ seen.delete(d.toolUseId);
282
+ if (d.decision !== "ask" || !asked) return;
283
+ // 不在这里等回答:observe 要马上返回,内核才能停下来等
284
+ handled.add(d.toolUseId);
285
+ const signal = turn.signal;
286
+ asking = asking.then(() => settle(asked, signal));
287
+ } else if (e.type === "input.received") {
288
+ const d = e.data as EventDataMap["input.received"];
289
+ if (d.kind !== "approval") return;
290
+ const a = answered.get(d.toolUseId);
291
+ if (!a) return;
292
+ answered.delete(d.toolUseId);
293
+ // 内核只记同意或拒绝:选了什么、谁回答的(终端、哪个渠道、规则、超时)记在这里
294
+ await hook.emit("answered", { toolUseId: d.toolUseId, ...a });
295
+ if (a.answer === "always") await hook.record(RULES_KEY, merged((hook.derived[RULES_KEY] as AllowRule[] | undefined) ?? []));
296
+ } else if (e.type === "turn.ended") {
297
+ turn.abort(new Error("the turn ended"));
298
+ turn = new AbortController();
299
+ seen.clear();
300
+ answered.clear();
301
+ handled.clear();
181
302
  }
182
- const turn = asking.then(async () => {
183
- const again = rules.decide(call, { mode, rules: saved() });
184
- if (again.decision !== "ask") return again;
185
- const rule = rules.ruleFor(call);
186
- const shown = (await preview(renderers, call)) ?? detail(call);
187
- const answer = await ask(
188
- ui,
189
- {
190
- title: `Allow ${call.name}?`,
191
- // 审查转给用户的:先说为什么
192
- detail: why ? `${why}\n\n${shown}` : shown,
193
- options: [
194
- { label: "Allow once", value: "once" },
195
- { label: `Always allow ${describeRule(rule)} in this session`, value: "always" },
196
- { label: "Deny", value: "deny" },
197
- ],
198
- },
199
- hook.signal,
200
- );
201
- if (answer === "always") {
202
- added.push(rule);
203
- await hook.record(RULES_KEY, saved());
204
- return { decision: "allow" as const };
205
- }
206
- if (answer === "once") return { decision: "allow" as const };
207
- return { decision: "deny" as const, reason: "The user denied this tool call. Do not retry it unchanged: adjust, or ask what to do instead." };
208
- });
209
- asking = turn.catch(() => {});
210
- return turn;
211
303
  },
212
304
  });
305
+
306
+ // 恢复一个上次停在等审批的会话(进程被杀、崩溃):那些调用的关卡是上一个进程跑的,这里没见过。
307
+ // 内核恢复时再发一次 awaiting,据此重新问。只知道调用的名字和参数(工具的声明只有关卡拿得到),
308
+ // 所以当作别的关卡要问的:只有"允许一次"和"拒绝",不重新套规则
309
+ ctx.session.subscribe((n) => {
310
+ if (n.type !== "awaiting") return;
311
+ const waiting = n.toolUseIds.filter((t) => !handled.has(t) && !seen.has(t));
312
+ if (waiting.length === 0) return;
313
+ const batch = ctx.session.state().batch;
314
+ const signal = turn.signal;
315
+ for (const toolUseId of waiting) {
316
+ const c = batch.find((x) => x.toolUseId === toolUseId && x.decision === "ask");
317
+ if (!c) continue;
318
+ handled.add(toolUseId);
319
+ asking = asking.then(() => settle({ call: { toolUseId, name: c.name, input: c.input } }, signal));
320
+ }
321
+ });
213
322
  },
214
323
  });
215
324
 
325
+ /** 一个要问的调用。没有 mine 的是别的插件的关卡要问的,或者恢复会话时还在等的;why:auto 模式的审查转给用户时的理由 */
326
+ interface Asked {
327
+ call: AskedCall;
328
+ /** 这里的规则要问的:关卡看到的完整调用,问之前按它重新判断一次 */
329
+ mine?: GatedToolCall;
330
+ why?: string;
331
+ }
332
+
333
+ /** 要问的调用里给用户看的部分;恢复的会话里只有这些 */
334
+ type AskedCall = Pick<GatedToolCall, "toolUseId" | "name" | "input">;
335
+
336
+ /** 交给内核的回答,和记进 answered 事件的部分(answer、by) */
337
+ interface Verdict {
338
+ approved: boolean;
339
+ answer: "allow" | Answer;
340
+ by: string;
341
+ reason?: string;
342
+ }
343
+
216
344
  /** allowRead、allowWrite:把目录登记进 roots,调用方的作用域关闭时撤销 */
217
345
  function allow(caller: Caller, name: string, roots: string[], dir: string): () => void {
218
346
  if (caller.layer === "project") throw new Error(`approval.${name}: project plugins cannot widen what runs without asking`);
@@ -228,23 +356,33 @@ function allow(caller: Caller, name: string, roots: string[], dir: string): () =
228
356
  }
229
357
 
230
358
  /**
231
- * 把问题同时交给终端(能提问时)和所有审批渠道,返回先到的回答,然后中止其余的。
359
+ * 把问题同时交给终端(能提问时)和所有审批渠道,返回先到的回答和回答的人("terminal" 或渠道的插件 id),然后中止其余的。
232
360
  * 终端里取消(undefined)算拒绝;渠道返回 undefined、不认识的值或出错算它不回答。都不回答时返回 undefined(拒绝)
233
361
  */
234
- async function ask(ui: UI | undefined, request: SelectRequest<Answer>, signal: AbortSignal): Promise<Answer | undefined> {
362
+ async function ask(ui: UI | undefined, request: SelectRequest<Answer>, signal: AbortSignal): Promise<{ answer: Answer; by: string; said?: string } | undefined> {
235
363
  const done = new AbortController();
236
364
  const stop = () => done.abort(signal.reason);
237
365
  signal.addEventListener("abort", stop, { once: true });
238
366
  try {
239
- return await new Promise<Answer | undefined>((resolve, reject) => {
240
- const channels: Promise<Answer | undefined | typeof NONE>[] = [];
241
- if (ui?.interactive) channels.push(ui.select(request, done.signal).then((a) => (a !== undefined && ANSWERS.includes(a) ? a : "deny")));
242
- for (const approver of approvers) {
367
+ return await new Promise<{ answer: Answer; by: string; said?: string } | undefined>((resolve, reject) => {
368
+ const channels: Promise<{ answer: Answer; by: string; said?: string } | typeof NONE>[] = [];
369
+ if (ui?.interactive) {
370
+ // 终端里多一项:拒绝并说明。选了它再问一句话,取消或什么都没写就是普通的拒绝
371
+ const options = [...request.options, { label: "Deny, and tell the agent what to do instead", value: EXPLAIN }];
372
+ channels.push(
373
+ ui.select<string>({ ...request, options }, done.signal).then(async (a) => {
374
+ if (a !== EXPLAIN) return { answer: a !== undefined && ANSWERS.includes(a) ? (a as Answer) : "deny", by: "terminal" };
375
+ const said = (await ui.input({ title: "What should the agent do instead?" }, done.signal))?.trim();
376
+ return { answer: "deny" as const, by: "terminal", ...(said ? { said } : {}) };
377
+ }),
378
+ );
379
+ }
380
+ for (const [approver, by] of approvers) {
243
381
  channels.push(
244
382
  Promise.resolve()
245
383
  .then(() => approver(request, done.signal))
246
384
  .then(
247
- (a) => (typeof a === "string" && ANSWERS.includes(a) ? (a as Answer) : NONE),
385
+ (a) => (typeof a === "string" && ANSWERS.includes(a) ? { answer: a as Answer, by } : NONE),
248
386
  () => NONE,
249
387
  ),
250
388
  );
@@ -265,11 +403,35 @@ async function ask(ui: UI | undefined, request: SelectRequest<Answer>, signal: A
265
403
  }
266
404
  const NONE = Symbol("no answer");
267
405
 
406
+ /** approvals.json:工作目录 → 在这个目录里总是允许的规则。读不了或格式不对时当作没有 */
407
+ async function readForever(file: string): Promise<Record<string, AllowRule[]>> {
408
+ try {
409
+ const data = JSON.parse(await readFile(file, "utf8")) as unknown;
410
+ if (!data || typeof data !== "object" || Array.isArray(data)) return {};
411
+ const out: Record<string, AllowRule[]> = {};
412
+ for (const [dir, rules] of Object.entries(data)) {
413
+ if (Array.isArray(rules)) out[dir] = rules.filter((r): r is AllowRule => !!r && typeof r === "object" && typeof (r as AllowRule).tool === "string");
414
+ }
415
+ return out;
416
+ } catch {
417
+ return {};
418
+ }
419
+ }
420
+
421
+ async function addForever(file: string, cwd: string, rule: AllowRule): Promise<void> {
422
+ const all = await readForever(file);
423
+ const rules = all[cwd] ?? [];
424
+ if (!rules.some((r) => JSON.stringify(r) === JSON.stringify(rule))) rules.push(rule);
425
+ all[cwd] = rules;
426
+ await mkdir(path.dirname(file), { recursive: true });
427
+ await writeFile(file, `${JSON.stringify(all, null, 2)}\n`);
428
+ }
429
+
268
430
  /**
269
431
  * 工具自己登记的审批预览(例如文件修改的 diff)。没有登记、返回的不是文字、或者出错时返回 undefined,
270
432
  * 用下面的 detail:预览是别的插件的代码,它坏了不能让审批卡住或失败
271
433
  */
272
- async function preview(renderers: Renderers | undefined, call: GatedToolCall): Promise<string | undefined> {
434
+ async function preview(renderers: Renderers | undefined, call: AskedCall): Promise<string | undefined> {
273
435
  let timer: ReturnType<typeof setTimeout> | undefined;
274
436
  try {
275
437
  // 预览可能读文件、算 diff;一直不返回时也要能问用户
@@ -286,7 +448,7 @@ async function preview(renderers: Renderers | undefined, call: GatedToolCall): P
286
448
  }
287
449
 
288
450
  /** 给用户看的调用内容:命令、路径和要写的内容,太长的截断 */
289
- function detail(call: GatedToolCall): string {
451
+ function detail(call: AskedCall): string {
290
452
  const input = call.input as Record<string, unknown> | null;
291
453
  let text: string;
292
454
  if (typeof input?.command === "string") text = input.command;
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "id": "jade/approval",
3
- "version": "0.4.0",
3
+ "version": "0.6.0",
4
4
  "api": "^1",
5
5
  "entry": "./index.ts",
6
6
  "provides": ["approval@1"],
@@ -10,6 +10,10 @@
10
10
  "default": "ask",
11
11
  "description": "ask: ask before changes; auto: changes inside the working directory and harmless commands go through; plan: change nothing, present a plan; readonly: change nothing; yolo: never ask"
12
12
  },
13
+ "askTimeoutMinutes": {
14
+ "default": 1440,
15
+ "description": "how long to wait for an answer to an approval question before denying the call (at most 10080, one week)"
16
+ },
13
17
  "review": {
14
18
  "default": true,
15
19
  "description": "in auto mode, let the model review the calls the rules cannot decide (it can only allow or pass them to you); false turns the review off"
@@ -6,13 +6,14 @@
6
6
  import { realpathSync, statSync } from "node:fs";
7
7
  import path from "node:path";
8
8
  import type { GatedToolCall, GateResult } from "uncarved";
9
+ import type { ApprovalMode } from "@uncarved/jade-api/services";
9
10
  import { validate } from "./schema.ts";
10
11
 
11
12
  /**
12
13
  * 权限模式。ask:改东西先问;auto:工作目录里的改动和只建目录、碰文件的命令不问;
13
14
  * plan:不改任何东西,拒绝时告诉模型先给出计划;readonly:不改任何东西(子 Agent 用);yolo:什么都不问
14
15
  */
15
- export const MODES = ["ask", "auto", "plan", "readonly", "yolo"] as const;
16
+ export const MODES = ["ask", "auto", "plan", "readonly", "yolo"] as const satisfies readonly ApprovalMode[];
16
17
  export type Mode = (typeof MODES)[number];
17
18
 
18
19
  /**
@@ -408,14 +409,34 @@ function real(p: string): string {
408
409
  }
409
410
 
410
411
  export function policy(opts: PolicyOptions): Policy {
411
- /** p 在 base 目录里 */
412
- const within = (base: string, p: string) => {
413
- // 按真实路径比较:目录里指向外面的符号链接也算外面
414
- const rel = path.relative(real(base), real(path.resolve(opts.cwd, p)));
412
+ /**
413
+ * 作为范围的目录(工作目录、登记的目录、规则里的目录)的真实路径,本会话内记住:复合命令的每个参数都要和它们比,
414
+ * 每次都 realpathSync 是一串同步 IO。只记已经存在的;要判断的路径本身每次都重新解析,符号链接可能随时被换掉
415
+ */
416
+ const bases = new Map<string, string>();
417
+ const realBase = (dir: string): string => {
418
+ let r = bases.get(dir);
419
+ if (r !== undefined) return r;
420
+ try {
421
+ r = realpathSync(dir);
422
+ } catch {
423
+ return real(dir);
424
+ }
425
+ bases.set(dir, r);
426
+ return r;
427
+ };
428
+ /** 真实路径 target 在真实路径 base 里 */
429
+ const contains = (base: string, target: string) => {
430
+ const rel = path.relative(base, target);
415
431
  // 只有 ".." 这一段才表示上级目录,名为 "..foo" 的目录仍在里面
416
432
  return rel !== ".." && !rel.startsWith(`..${path.sep}`) && !path.isAbsolute(rel);
417
433
  };
418
- const inside = (p: string) => within(opts.cwd, p) || (opts.writeRoots ?? []).some((r) => within(r, p));
434
+ /** p 在 base 目录里。按真实路径比较:目录里指向外面的符号链接也算外面 */
435
+ const within = (base: string, p: string) => contains(realBase(base), real(path.resolve(opts.cwd, p)));
436
+ const inside = (p: string) => {
437
+ const target = real(path.resolve(opts.cwd, p));
438
+ return contains(realBase(opts.cwd), target) || (opts.writeRoots ?? []).some((r) => contains(realBase(r), target));
439
+ };
419
440
  /** glob 的 pattern 是绝对路径或含 ".." 段时,匹配范围会超出 path */
420
441
  const globEscapes = (pattern: string) => path.isAbsolute(pattern) || pattern.split(/[\\/]/).includes("..");
421
442
  /** 以 "." 或 "[" 开头的通配段可能匹配到 ".."(取决于 bash 版本和选项),按越界处理 */
@@ -8,7 +8,7 @@
8
8
  import { readFile } from "node:fs/promises";
9
9
  import path from "node:path";
10
10
  import type { GatedToolCall, GateResult, Message, ModelRequest, Usage } from "uncarved";
11
- import type { Models } from "../models/index.ts";
11
+ import type { Models } from "@uncarved/jade-api/services";
12
12
 
13
13
  /** 审查的结论,加上这次审查用掉的 token(计入会话用量) */
14
14
  export type Review = GateResult & { usage?: Usage };
@@ -5,8 +5,8 @@
5
5
  // 从旧 jade 的 tools/ask.ts 和 main.ts 的 askUser 移植。
6
6
 
7
7
  import type { Tool } from "uncarved";
8
- import { definePlugin, type UI } from "../../src/api.ts";
9
- import type { Renderers, ToolRenderer } from "../renderers/index.ts";
8
+ import { definePlugin, type UI } from "@uncarved/jade-api";
9
+ import type { Renderers, ToolRenderer } from "@uncarved/jade-api/services";
10
10
 
11
11
  export interface Question {
12
12
  question: string;
@@ -2,7 +2,7 @@
2
2
  // 从旧 jade 的 plugins/budget.ts 移植;上限来自配置 maxSteps。
3
3
 
4
4
  import type { State } from "uncarved";
5
- import { definePlugin, type UI } from "../../src/api.ts";
5
+ import { definePlugin, type UI } from "@uncarved/jade-api";
6
6
 
7
7
  const DEFAULT_STEPS = 100;
8
8
 
@@ -18,7 +18,7 @@ import { existsSync, realpathSync } from "node:fs";
18
18
  import { readFile } from "node:fs/promises";
19
19
  import path from "node:path";
20
20
  import type { Block, HookContext, LocalHookSpec, Message } from "uncarved";
21
- import type { RunCommand } from "../shell/shell.ts";
21
+ import type { RunCommand } from "@uncarved/jade-api/services";
22
22
 
23
23
  /** 老版本把整个 ChecksState 记在这一个 key 下、每次检查整份重记;恢复老会话时还要读它 */
24
24
  export const CHECKS_KEY = "jade/checks";
@@ -142,7 +142,8 @@ export interface Problem {
142
142
  * 后面认不出路径的行(多行说明、代码片段)归到它下面;第一个问题之前的行单独算一个没有文件的问题
143
143
  */
144
144
  export function parseProblems(output: string, cwd: string): Problem[] {
145
- const START = /^\s*((?:[A-Za-z]:[\\/])?[^\s:()][^:()]*?)(?:\(\d+,\d+\)|:\d+(?::\d+)?)(?=[:\s]|$)/;
145
+ // 路径里可以有括号(Next.js 的 app/(group)/page.tsx),只是不能以括号开头
146
+ const START = /^\s*((?:[A-Za-z]:[\\/])?[^\s:()][^:]*?)(?:\(\d+,\d+\)|:\d+(?::\d+)?)(?=[:\s]|$)/;
146
147
  const out: Problem[] = [];
147
148
  let cur: Problem | undefined;
148
149
  for (const line of output.split(/\r?\n/)) {
@@ -10,13 +10,10 @@
10
10
 
11
11
  import { createHash } from "node:crypto";
12
12
  import path from "node:path";
13
- import { definePlugin, type SessionContext, type UI } from "../../src/api.ts";
14
- import type { Approval } from "../approval/index.ts";
15
- import type { Commands } from "../commands/index.ts";
16
- import type { EventRenderer, Renderers } from "../renderers/index.ts";
13
+ import { definePlugin, type SessionContext, type UI } from "@uncarved/jade-api";
14
+ import type { Approval, Commands, EventRenderer, Renderers, Shell } from "@uncarved/jade-api/services";
17
15
  import { changedFiles, checks, type Check, type Checks } from "./checks.ts";
18
16
  import { bold, dim, display, realPath, repoRoot, TrustFile, yellow } from "./project.ts";
19
- import type { Shell } from "../shell/service.ts";
20
17
 
21
18
  /** 确认记录:同一个目录里的同一条命令只问一次。和旧 jade 的算法相同 */
22
19
  const checkHash = (c: Check) => createHash("sha256").update(`jade-check\0${c.cwd}\0${c.command}`).digest("hex");