@uncarved/jade 0.3.1 → 0.4.1

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 (206) 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 +490 -29
  11. package/dist/session.js.map +1 -1
  12. package/package.json +4 -4
  13. package/plugins/approval/index.ts +36 -14
  14. package/plugins/approval/policy.ts +15 -10
  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 +42 -9
  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 +47 -12
  50. package/plugins/models/index.ts +27 -1
  51. package/plugins/models/provider.ts +24 -0
  52. package/plugins/models/saved.ts +1 -1
  53. package/plugins/modes/index.ts +13 -2
  54. package/plugins/print/index.ts +7 -4
  55. package/plugins/prompts/index.ts +0 -0
  56. package/plugins/renderers/index.ts +10 -5
  57. package/plugins/repeats/index.ts +8 -8
  58. package/plugins/schedule/index.ts +5 -1
  59. package/plugins/screenshot/browser.ts +10 -0
  60. package/plugins/sessions/index.ts +48 -2
  61. package/plugins/shell/index.ts +27 -28
  62. package/plugins/shell/plugin.json +1 -1
  63. package/plugins/shell/renderers.ts +9 -7
  64. package/plugins/shell/shell.ts +3 -1
  65. package/plugins/skills/index.ts +28 -19
  66. package/plugins/skills/project.ts +12 -7
  67. package/plugins/steer/index.ts +5 -4
  68. package/plugins/task/index.ts +80 -50
  69. package/plugins/task/plugin.json +6 -2
  70. package/plugins/task/style.ts +13 -14
  71. package/plugins/task/subagent.ts +67 -184
  72. package/plugins/todo/index.ts +39 -9
  73. package/plugins/tools/index.ts +9 -2
  74. package/plugins/tui/frontend.ts +139 -89
  75. package/plugins/tui/index.ts +2 -3
  76. package/plugins/tui/mentions.ts +11 -80
  77. package/plugins/tui/plugin.json +1 -1
  78. package/plugins/tui/screen.ts +55 -5
  79. package/plugins/tui/transcript.ts +17 -7
  80. package/plugins/tui/tui.ts +337 -101
  81. package/plugins/tui/vendor.ts +1 -1
  82. package/plugins/undo/checkpoint.ts +8 -4
  83. package/plugins/undo/index.ts +170 -31
  84. package/plugins/undo/plugin.json +1 -0
  85. package/plugins/undo/snapshot.ts +87 -14
  86. package/plugins/undo/style.ts +13 -14
  87. package/plugins/web/index.ts +7 -18
  88. package/plugins/web/plugin.json +1 -1
  89. package/plugins-dist/approval/index.js +363 -418
  90. package/plugins-dist/approval/policy.js +391 -508
  91. package/plugins-dist/approval/review.js +132 -158
  92. package/plugins-dist/approval/schema.js +50 -55
  93. package/plugins-dist/ask/index.js +115 -129
  94. package/plugins-dist/budget/index.js +27 -31
  95. package/plugins-dist/checks/checks.js +293 -329
  96. package/plugins-dist/checks/index.js +119 -139
  97. package/plugins-dist/checks/plugin.json +2 -1
  98. package/plugins-dist/checks/project.js +57 -65
  99. package/plugins-dist/commands/index.js +47 -29
  100. package/plugins-dist/compact/compact.js +233 -249
  101. package/plugins-dist/compact/index.js +98 -95
  102. package/plugins-dist/compact/style.js +9 -14
  103. package/plugins-dist/completions/index.js +30 -0
  104. package/plugins-dist/completions/plugin.json +9 -0
  105. package/plugins-dist/continue/index.js +40 -52
  106. package/plugins-dist/copy/index.js +40 -0
  107. package/plugins-dist/copy/plugin.json +9 -0
  108. package/plugins-dist/cost/index.js +98 -115
  109. package/plugins-dist/custom-commands/index.js +55 -72
  110. package/plugins-dist/editor/index.js +64 -72
  111. package/plugins-dist/fs/diff.js +111 -124
  112. package/plugins-dist/fs/fs.js +426 -469
  113. package/plugins-dist/fs/grep.js +262 -253
  114. package/plugins-dist/fs/index.js +20 -34
  115. package/plugins-dist/fs/plugin.json +1 -2
  116. package/plugins-dist/fs/renderers.js +100 -112
  117. package/plugins-dist/fs/style.js +11 -15
  118. package/plugins-dist/fs/sys.js +31 -43
  119. package/plugins-dist/hooks/index.js +107 -127
  120. package/plugins-dist/keys/index.js +27 -31
  121. package/plugins-dist/mcp/index.js +271 -199
  122. package/plugins-dist/mcp/install.js +123 -137
  123. package/plugins-dist/mcp/mcp.js +638 -577
  124. package/plugins-dist/mcp/plugin.json +3 -1
  125. package/plugins-dist/mcp/project.js +98 -115
  126. package/plugins-dist/memory/index.js +83 -88
  127. package/plugins-dist/memory/memory.js +111 -128
  128. package/plugins-dist/memory/style.js +9 -14
  129. package/plugins-dist/mentions/attach.js +91 -99
  130. package/plugins-dist/mentions/candidates.js +49 -0
  131. package/plugins-dist/mentions/index.js +71 -81
  132. package/plugins-dist/mentions/plugin.json +2 -1
  133. package/plugins-dist/mentions/style.js +9 -14
  134. package/plugins-dist/models/config.js +29 -43
  135. package/plugins-dist/models/configure.js +421 -474
  136. package/plugins-dist/models/context.js +14 -22
  137. package/plugins-dist/models/index.js +182 -189
  138. package/plugins-dist/models/provider.js +263 -307
  139. package/plugins-dist/models/saved.js +60 -72
  140. package/plugins-dist/modes/index.js +138 -165
  141. package/plugins-dist/plugins/index.js +34 -34
  142. package/plugins-dist/print/index.js +192 -175
  143. package/plugins-dist/prompts/index.js +86 -89
  144. package/plugins-dist/prompts/notes.js +31 -37
  145. package/plugins-dist/prompts/prompts.js +155 -193
  146. package/plugins-dist/prompts/results.js +40 -53
  147. package/plugins-dist/prompts/sys.js +39 -50
  148. package/plugins-dist/renderers/index.js +32 -32
  149. package/plugins-dist/repeats/index.js +131 -174
  150. package/plugins-dist/schedule/cron.js +49 -56
  151. package/plugins-dist/schedule/index.js +230 -247
  152. package/plugins-dist/schedule/store.js +93 -109
  153. package/plugins-dist/scratch/index.js +12 -18
  154. package/plugins-dist/screenshot/browser.js +136 -154
  155. package/plugins-dist/screenshot/index.js +37 -46
  156. package/plugins-dist/screenshot/sys.js +53 -65
  157. package/plugins-dist/screenshot/tool.js +98 -126
  158. package/plugins-dist/sessions/index.js +149 -117
  159. package/plugins-dist/shell/index.js +117 -135
  160. package/plugins-dist/shell/plugin.json +1 -1
  161. package/plugins-dist/shell/renderers.js +28 -33
  162. package/plugins-dist/shell/service.js +17 -23
  163. package/plugins-dist/shell/shell.js +307 -362
  164. package/plugins-dist/shell/sys.js +64 -79
  165. package/plugins-dist/skills/index.js +193 -211
  166. package/plugins-dist/skills/install.js +122 -149
  167. package/plugins-dist/skills/project.js +65 -73
  168. package/plugins-dist/skills/skills.js +135 -171
  169. package/plugins-dist/steer/index.js +108 -125
  170. package/plugins-dist/suggest/index.js +235 -259
  171. package/plugins-dist/task/index.js +130 -117
  172. package/plugins-dist/task/plugin.json +5 -2
  173. package/plugins-dist/task/style.js +9 -14
  174. package/plugins-dist/task/subagent.js +156 -279
  175. package/plugins-dist/todo/index.js +79 -63
  176. package/plugins-dist/tools/index.js +36 -42
  177. package/plugins-dist/tui/editor.js +145 -160
  178. package/plugins-dist/tui/frontend.js +639 -678
  179. package/plugins-dist/tui/history.js +34 -37
  180. package/plugins-dist/tui/index.js +16 -18
  181. package/plugins-dist/tui/markdown.js +203 -247
  182. package/plugins-dist/tui/mascot.js +266 -355
  183. package/plugins-dist/tui/mentions.js +67 -144
  184. package/plugins-dist/tui/plugin.json +1 -2
  185. package/plugins-dist/tui/render.js +35 -45
  186. package/plugins-dist/tui/screen.js +197 -180
  187. package/plugins-dist/tui/transcript.js +436 -468
  188. package/plugins-dist/tui/tui.js +1554 -1656
  189. package/plugins-dist/tui/vendor.js +1088 -1388
  190. package/plugins-dist/undo/checkpoint.js +97 -118
  191. package/plugins-dist/undo/index.js +281 -192
  192. package/plugins-dist/undo/plugin.json +3 -0
  193. package/plugins-dist/undo/snapshot.js +134 -99
  194. package/plugins-dist/undo/style.js +9 -14
  195. package/plugins-dist/update/index.js +26 -28
  196. package/plugins-dist/web/env.js +55 -68
  197. package/plugins-dist/web/index.js +80 -110
  198. package/plugins-dist/web/plugin.json +1 -2
  199. package/plugins-dist/web/renderers.js +4 -5
  200. package/plugins-dist/web/web.js +514 -593
  201. package/sdk/python/__pycache__/jade_plugin.cpython-312.pyc +0 -0
  202. package/sdk/python/jade_plugin.py +9 -2
  203. package/src/api.ts +1 -1
  204. package/src/host.ts +39 -4
  205. package/src/remote.ts +6 -1
  206. package/src/session.ts +496 -36
@@ -1,153 +1,76 @@
1
- // @ 引用文件的补全:输入框里打 @ 时找出光标处正在输入的路径、给候选路径排序。
2
- // 候选从工作目录来(git 仓库里只看版本控制的,和 glob 一样),发送时附上文件内容由 jade/mentions 负责。
3
- import { execFile } from "node:child_process";
4
- import { readdir } from "node:fs/promises";
5
- import path from "node:path";
6
- /** 候选(文件加目录)最多这么多,再多也只是拖慢补全 */
7
- const MAX_CANDIDATES = 20_000;
8
- /** 光标正在输入的 @ 引用:@ 的下标和已经输入的部分;不在引用里时返回 undefined */
9
- export function mentionAt(value, cursor) {
10
- const m = /(?:^|\s)@("?[^\s"]*)$/.exec(value.slice(0, cursor));
11
- if (!m)
12
- return undefined;
13
- return { start: cursor - m[1].length - 1, query: m[1].replace(/^"/, "") };
1
+ export function mentionAt(value, cursor, triggers) {
2
+ if (triggers.length === 0)
3
+ return;
4
+ const chars = triggers.map((t) => t.replace(/[\\^\]\-]/g, "\\$&")).join("");
5
+ const m = new RegExp(`(?:^|\\s)([${chars}])("?[^\\s"]*)$`, "u").exec(value.slice(0, cursor));
6
+ if (!m)
7
+ return;
8
+ return { trigger: m[1], start: cursor - m[2].length - m[1].length, query: m[2].replace(/^"/, "") };
14
9
  }
15
- /** 补全后的文本:@ 引用加一个空格,含空白的路径加引号 */
16
- export const mentionText = (p) => (/\s/.test(p) ? `@"${p}"` : `@${p}`);
17
- const prepared = new WeakMap();
10
+ export const mentionText = (trigger, p) => /\s/.test(p) ? `${trigger}"${p}"` : `${trigger}${p}`;
11
+ const prepared = new WeakMap;
18
12
  function prepare(paths) {
19
- let out = prepared.get(paths);
20
- if (!out) {
21
- out = paths.map((p) => {
22
- const lower = p.toLowerCase();
23
- const trimmed = lower.endsWith("/") ? lower.slice(0, -1) : lower;
24
- return { lower, base: trimmed.slice(trimmed.lastIndexOf("/") + 1) };
25
- });
26
- prepared.set(paths, out);
27
- }
28
- return out;
13
+ let out = prepared.get(paths);
14
+ if (!out) {
15
+ out = paths.map((p) => {
16
+ const lower = p.toLowerCase();
17
+ const trimmed = lower.endsWith("/") ? lower.slice(0, -1) : lower;
18
+ return { lower, base: trimmed.slice(trimmed.lastIndexOf("/") + 1) };
19
+ });
20
+ prepared.set(paths, out);
21
+ }
22
+ return out;
29
23
  }
30
- /**
31
- * 上一次排序时命中的全部候选(下标)。query 只是在后面追加了字符时,新的命中一定在这些里面
32
- * (包含 q 加字符的也包含 q,按顺序出现的同理),只筛它们,不用再扫一遍全部路径
33
- */
34
24
  let last;
35
- /**
36
- * 按 query 给候选路径排序:文件名以 query 开头的最前,其次文件名包含、路径包含,
37
- * 最后是按顺序出现 query 每个字符的模糊匹配;同一档里短的在前
38
- */
39
25
  export function rankPaths(paths, query, limit) {
40
- const q = query.toLowerCase().replaceAll("\\", "/");
41
- if (!q)
42
- return paths.filter((p) => !p.slice(0, -1).includes("/")).slice(0, limit);
43
- const info = prepare(paths);
44
- const from = last && last.paths === paths && q.startsWith(last.q) ? last.hits : undefined;
45
- const scored = [];
46
- const check = (i) => {
47
- const { lower, base } = info[i];
48
- let score;
49
- if (lower.startsWith(q))
50
- score = 0;
51
- else if (base.startsWith(q))
52
- score = 1;
53
- else if (base.includes(q))
54
- score = 2;
55
- else if (lower.includes(q))
56
- score = 3;
57
- else if (subsequence(lower, q))
58
- score = 4;
59
- else
60
- return;
61
- scored.push({ i, score });
62
- };
63
- if (from)
64
- for (const i of from)
65
- check(i);
26
+ const q = query.toLowerCase().replaceAll("\\", "/");
27
+ if (!q)
28
+ return paths.filter((p) => !p.slice(0, -1).includes("/")).slice(0, limit);
29
+ const info = prepare(paths);
30
+ const from = last && last.paths === paths && q.startsWith(last.q) ? last.hits : undefined;
31
+ const scored = [];
32
+ const check = (i) => {
33
+ const { lower, base } = info[i];
34
+ let score;
35
+ if (lower.startsWith(q))
36
+ score = 0;
37
+ else if (base.startsWith(q))
38
+ score = 1;
39
+ else if (base.includes(q))
40
+ score = 2;
41
+ else if (lower.includes(q))
42
+ score = 3;
43
+ else if (subsequence(lower, q))
44
+ score = 4;
66
45
  else
67
- for (let i = 0; i < paths.length; i++)
68
- check(i);
69
- last = { paths, q, hits: scored.map((s) => s.i) };
70
- const cmp = (a, b) => a.score - b.score || paths[a.i].length - paths[b.i].length || paths[a.i].localeCompare(paths[b.i]);
71
- // 只要前 limit 条:命中常有上万条,全部排序(localeCompare 很慢)每按一个键要十几毫秒
72
- const top = [];
73
- for (const s of scored) {
74
- if (top.length === limit && cmp(s, top[limit - 1]) >= 0)
75
- continue;
76
- let at = top.length;
77
- while (at > 0 && cmp(s, top[at - 1]) < 0)
78
- at--;
79
- top.splice(at, 0, s);
80
- if (top.length > limit)
81
- top.pop();
82
- }
83
- return top.map((s) => paths[s.i]);
46
+ return;
47
+ scored.push({ i, score });
48
+ };
49
+ if (from)
50
+ for (const i of from)
51
+ check(i);
52
+ else
53
+ for (let i = 0;i < paths.length; i++)
54
+ check(i);
55
+ last = { paths, q, hits: scored.map((s) => s.i) };
56
+ const cmp = (a, b) => a.score - b.score || paths[a.i].length - paths[b.i].length || paths[a.i].localeCompare(paths[b.i]);
57
+ const top = [];
58
+ for (const s of scored) {
59
+ if (top.length === limit && cmp(s, top[limit - 1]) >= 0)
60
+ continue;
61
+ let at = top.length;
62
+ while (at > 0 && cmp(s, top[at - 1]) < 0)
63
+ at--;
64
+ top.splice(at, 0, s);
65
+ if (top.length > limit)
66
+ top.pop();
67
+ }
68
+ return top.map((s) => paths[s.i]);
84
69
  }
85
70
  function subsequence(text, q) {
86
- let i = 0;
87
- for (const ch of text)
88
- if (ch === q[i] && ++i === q.length)
89
- return true;
90
- return false;
91
- }
92
- /**
93
- * @ 补全的候选:工作目录里的文件(git 仓库里只看版本控制的)和它们所在的目录,目录以 / 结尾。
94
- * 5 秒还没列完就先给已经找到的(大仓库第一次列得慢,不该让输入框卡住)
95
- */
96
- export async function mentionCandidates(cwd, signal = AbortSignal.timeout(5000)) {
97
- const files = [];
98
- const dirs = new Set();
99
- try {
100
- for await (const full of await listFiles(cwd, signal)) {
101
- const rel = display(cwd, full);
102
- files.push(rel);
103
- for (let i = rel.lastIndexOf("/"); i > 0; i = rel.lastIndexOf("/", i - 1)) {
104
- const dir = rel.slice(0, i + 1);
105
- if (dirs.has(dir))
106
- break;
107
- dirs.add(dir);
108
- }
109
- if (files.length + dirs.size >= MAX_CANDIDATES)
110
- break;
111
- }
112
- }
113
- catch {
114
- // 列到一半被中止(超时):用已经找到的
115
- }
116
- return [...dirs, ...files];
117
- }
118
- // 以下和 jade/fs 的 listFiles、display 相同:插件之间不共享代码(只能共享类型),所以这里留一份
119
- const SKIP_DIRS = new Set([".git", "node_modules"]);
120
- /** 显示用:工作目录内的路径用相对形式,统一为正斜杠 */
121
- function display(cwd, full) {
122
- const rel = path.relative(cwd, full);
123
- const shown = rel && rel !== ".." && !rel.startsWith(`..${path.sep}`) && !path.isAbsolute(rel) ? rel : full;
124
- return shown.split(path.sep).join("/");
125
- }
126
- /** git 仓库里的文件(版本控制的和没忽略的新文件);不是仓库、没有 git 时 undefined */
127
- function gitFiles(root) {
128
- return new Promise((resolve) => {
129
- execFile("git", ["ls-files", "-z", "--cached", "--others", "--exclude-standard"], { cwd: root, maxBuffer: 256 * 1024 * 1024, windowsHide: true }, (err, out) =>
130
- // 合并冲突中的文件会出现多次
131
- resolve(err ? undefined : [...new Set(out.split("\0").filter(Boolean))]));
132
- });
133
- }
134
- async function listFiles(root, signal) {
135
- const tracked = await gitFiles(root);
136
- if (!tracked)
137
- return walk(root, signal);
138
- return tracked.filter((rel) => !rel.split("/").some((seg) => SKIP_DIRS.has(seg))).map((rel) => path.join(root, rel));
139
- }
140
- async function* walk(dir, signal) {
141
- signal.throwIfAborted();
142
- const entries = (await readdir(dir, { withFileTypes: true })).sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
143
- for (const e of entries) {
144
- const full = path.join(dir, e.name);
145
- if (e.isDirectory()) {
146
- if (!SKIP_DIRS.has(e.name))
147
- yield* walk(full, signal);
148
- }
149
- else if (e.isFile()) {
150
- yield full;
151
- }
152
- }
71
+ let i = 0;
72
+ for (const ch of text)
73
+ if (ch === q[i] && ++i === q.length)
74
+ return true;
75
+ return false;
153
76
  }
@@ -13,9 +13,8 @@
13
13
  "renderers@1"
14
14
  ],
15
15
  "optional": [
16
- "modes@1",
17
16
  "models@1",
18
- "compact@1",
17
+ "completions@1",
19
18
  "sessions@1",
20
19
  "steer@1"
21
20
  ],
@@ -1,61 +1,51 @@
1
- // 宿主显示用的纯函数:工具调用的默认摘要和预览、折叠的工具结果。不依赖运行时和界面状态。
2
- // 各个工具自己的显示由插件经 renderers@1 登记。
3
1
  import os from "node:os";
4
2
  import path from "node:path";
5
3
  import { dim } from "./screen.js";
6
- /** 显示用的路径:工作目录里的用相对路径,其余用绝对路径;都用正斜杠。和 jade/fs 的 display 相同,插件之间不 import 值,所以这里留一份 */
7
4
  function display(cwd, full) {
8
- const rel = path.relative(cwd, full);
9
- const shown = rel && rel !== ".." && !rel.startsWith(`..${path.sep}`) && !path.isAbsolute(rel) ? rel : full;
10
- return shown.split(path.sep).join("/");
5
+ const rel = path.relative(cwd, full);
6
+ const shown = rel && rel !== ".." && !rel.startsWith(`..${path.sep}`) && !path.isAbsolute(rel) ? rel : full;
7
+ return shown.split(path.sep).join("/");
11
8
  }
12
- export const clip = (s, n) => (s.length > n ? s.slice(0, n) + "…" : s);
13
- /**
14
- * 带颜色(SGR 序列)的文字截到 n 个可见字符:序列不算长度、不会被切开;截断时在最后复位颜色,
15
- * 不让没关上的颜色渗到后面的行
16
- */
9
+ export const clip = (s, n) => s.length > n ? s.slice(0, n) + "…" : s;
17
10
  export function clipStyled(s, n) {
18
- const sgr = /\x1b\[[0-9;:]*m/y;
19
- let out = "";
20
- let visible = 0;
21
- let styled = false;
22
- for (let i = 0; i < s.length;) {
23
- sgr.lastIndex = i;
24
- const m = sgr.exec(s);
25
- if (m) {
26
- out += m[0];
27
- styled = true;
28
- i += m[0].length;
29
- continue;
30
- }
31
- if (visible === n)
32
- return out + "…" + (styled ? "\x1b[0m" : "");
33
- out += s[i];
34
- visible++;
35
- i++;
11
+ const sgr = /\x1b\[[0-9;:]*m/y;
12
+ let out = "";
13
+ let visible = 0;
14
+ let styled = false;
15
+ for (let i = 0;i < s.length; ) {
16
+ sgr.lastIndex = i;
17
+ const m = sgr.exec(s);
18
+ if (m) {
19
+ out += m[0];
20
+ styled = true;
21
+ i += m[0].length;
22
+ continue;
36
23
  }
37
- return out;
24
+ if (visible === n)
25
+ return out + "…" + (styled ? "\x1B[0m" : "");
26
+ out += s[i];
27
+ visible++;
28
+ i++;
29
+ }
30
+ return out;
38
31
  }
39
- /** 家目录下的路径显示成 ~/… */
40
32
  export function shortPath(p) {
41
- const rel = path.relative(os.homedir(), p);
42
- const shown = rel && !rel.startsWith("..") && !path.isAbsolute(rel) ? `~/${rel}` : rel === "" ? "~" : p;
43
- return shown.split(path.sep).join("/");
33
+ const rel = path.relative(os.homedir(), p);
34
+ const shown = rel && !rel.startsWith("..") && !path.isAbsolute(rel) ? `~/${rel}` : rel === "" ? "~" : p;
35
+ return shown.split(path.sep).join("/");
44
36
  }
45
- /** 工具调用默认的一行摘要,显示在工具名后面的括号里:path 参数,没有时是参数的 JSON */
46
37
  export function summarize(cwd, input) {
47
- const i = (input ?? {});
48
- const where = typeof i.path === "string" ? display(cwd, i.path) : "";
49
- return where || clip(JSON.stringify(input), 120);
38
+ const i = input ?? {};
39
+ const where = typeof i.path === "string" ? display(cwd, i.path) : "";
40
+ return where || clip(JSON.stringify(input), 120);
50
41
  }
51
- /** 审批时默认的预览:参数的 JSON */
52
42
  export function preview(input) {
53
- return dim(clip(JSON.stringify(input, null, 2), 2000));
43
+ return dim(clip(JSON.stringify(input, null, 2), 2000));
54
44
  }
55
- /** 工具结果展开后的内容:缩进的全部行,超过 max 行时截断 */
56
45
  export function detailsOf(lines, color, max) {
57
- const body = lines.slice(0, max).map((l) => color(` ${l}`));
58
- if (lines.length > max)
59
- body.push(dim(` … ${lines.length - max} more lines`));
60
- return body.join("\n");
46
+ const body = lines.slice(0, max).map((l) => color(` ${l}`));
47
+ if (lines.length > max)
48
+ body.push(dim(` … ${lines.length - max} more lines`));
49
+ return body.join(`
50
+ `);
61
51
  }