@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,140 +1,127 @@
1
- // 按行比较两段文本,生成带行号和上下文的 unified diff:审批修改时的预览、对话里修改结果的展开内容。从旧 jade 的 ui/diff.ts 移植。
2
- //
3
- // 先去掉相同的开头和结尾,只对中间部分求最长公共子序列;中间部分太大时(整个文件重写)
4
- // 不再逐行比较,整段显示为删除加新增,避免占用大量内存和时间。
5
- import { dim, green, red } from "./style.js";
6
- /** LCS 表的上限:中间部分的行数乘积超过它就整段替换 */
7
- const MAX_CELLS = 4_000_000;
1
+ import { added as plus, dim, lines as joinLines, removed as minus } from "./style.js";
2
+ const MAX_CELLS = 4000000;
8
3
  const splitLines = (s) => {
9
- if (s === "")
10
- return [];
11
- const lines = s.split(/\r?\n/);
12
- if (lines.at(-1) === "")
13
- lines.pop();
14
- return lines;
4
+ if (s === "")
5
+ return [];
6
+ const lines = s.split(/\r?\n/);
7
+ if (lines.at(-1) === "")
8
+ lines.pop();
9
+ return lines;
15
10
  };
16
- /** 两段文本的逐行差异,包括相同的行 */
17
11
  export function diffLines(before, after) {
18
- const a = splitLines(before);
19
- const b = splitLines(after);
20
- let start = 0;
21
- while (start < a.length && start < b.length && a[start] === b[start])
22
- start++;
23
- let endA = a.length;
24
- let endB = b.length;
25
- while (endA > start && endB > start && a[endA - 1] === b[endB - 1]) {
26
- endA--;
27
- endB--;
28
- }
29
- const out = [];
30
- for (let i = 0; i < start; i++)
31
- out.push({ kind: " ", text: a[i], old: i + 1, new: i + 1 });
32
- const midA = a.slice(start, endA);
33
- const midB = b.slice(start, endB);
34
- for (const op of middle(midA, midB)) {
35
- if (op.kind === " ")
36
- out.push({ kind: " ", text: midA[op.i], old: start + op.i + 1, new: start + op.j + 1 });
37
- else if (op.kind === "-")
38
- out.push({ kind: "-", text: midA[op.i], old: start + op.i + 1 });
39
- else
40
- out.push({ kind: "+", text: midB[op.j], new: start + op.j + 1 });
41
- }
42
- for (let k = 0; endA + k < a.length; k++)
43
- out.push({ kind: " ", text: a[endA + k], old: endA + k + 1, new: endB + k + 1 });
44
- return out;
12
+ const a = splitLines(before);
13
+ const b = splitLines(after);
14
+ let start = 0;
15
+ while (start < a.length && start < b.length && a[start] === b[start])
16
+ start++;
17
+ let endA = a.length;
18
+ let endB = b.length;
19
+ while (endA > start && endB > start && a[endA - 1] === b[endB - 1]) {
20
+ endA--;
21
+ endB--;
22
+ }
23
+ const out = [];
24
+ for (let i = 0;i < start; i++)
25
+ out.push({ kind: " ", text: a[i], old: i + 1, new: i + 1 });
26
+ const midA = a.slice(start, endA);
27
+ const midB = b.slice(start, endB);
28
+ for (const op of middle(midA, midB)) {
29
+ if (op.kind === " ")
30
+ out.push({ kind: " ", text: midA[op.i], old: start + op.i + 1, new: start + op.j + 1 });
31
+ else if (op.kind === "-")
32
+ out.push({ kind: "-", text: midA[op.i], old: start + op.i + 1 });
33
+ else
34
+ out.push({ kind: "+", text: midB[op.j], new: start + op.j + 1 });
35
+ }
36
+ for (let k = 0;endA + k < a.length; k++)
37
+ out.push({ kind: " ", text: a[endA + k], old: endA + k + 1, new: endB + k + 1 });
38
+ return out;
45
39
  }
46
40
  function middle(a, b) {
47
- const n = a.length;
48
- const m = b.length;
49
- if (n === 0 || m === 0 || n * m > MAX_CELLS) {
50
- return [...a.map((_, i) => ({ kind: "-", i, j: 0 })), ...b.map((_, j) => ({ kind: "+", i: 0, j }))];
51
- }
52
- // lcs[i][j]:a[i..] 和 b[j..] 的最长公共子序列长度,按行存成一维
53
- const w = m + 1;
54
- const lcs = new Uint32Array((n + 1) * w);
55
- for (let i = n - 1; i >= 0; i--) {
56
- for (let j = m - 1; j >= 0; j--) {
57
- lcs[i * w + j] = a[i] === b[j] ? lcs[(i + 1) * w + j + 1] + 1 : Math.max(lcs[(i + 1) * w + j], lcs[i * w + j + 1]);
58
- }
41
+ const n = a.length;
42
+ const m = b.length;
43
+ if (n === 0 || m === 0 || n * m > MAX_CELLS) {
44
+ return [...a.map((_, i) => ({ kind: "-", i, j: 0 })), ...b.map((_, j) => ({ kind: "+", i: 0, j }))];
45
+ }
46
+ const w = m + 1;
47
+ const lcs = new Uint32Array((n + 1) * w);
48
+ for (let i = n - 1;i >= 0; i--) {
49
+ for (let j = m - 1;j >= 0; j--) {
50
+ lcs[i * w + j] = a[i] === b[j] ? lcs[(i + 1) * w + j + 1] + 1 : Math.max(lcs[(i + 1) * w + j], lcs[i * w + j + 1]);
59
51
  }
60
- const ops = [];
61
- let i = 0;
62
- let j = 0;
63
- while (i < n && j < m) {
64
- if (a[i] === b[j])
65
- ops.push({ kind: " ", i: i++, j: j++ });
66
- // 先删后加:同一处的修改显示成一组 - 再一组 +
67
- else if (lcs[(i + 1) * w + j] >= lcs[i * w + j + 1])
68
- ops.push({ kind: "-", i: i++, j });
69
- else
70
- ops.push({ kind: "+", i, j: j++ });
71
- }
72
- while (i < n)
73
- ops.push({ kind: "-", i: i++, j });
74
- while (j < m)
75
- ops.push({ kind: "+", i, j: j++ });
76
- return ops;
52
+ }
53
+ const ops = [];
54
+ let i = 0;
55
+ let j = 0;
56
+ while (i < n && j < m) {
57
+ if (a[i] === b[j])
58
+ ops.push({ kind: " ", i: i++, j: j++ });
59
+ else if (lcs[(i + 1) * w + j] >= lcs[i * w + j + 1])
60
+ ops.push({ kind: "-", i: i++, j });
61
+ else
62
+ ops.push({ kind: "+", i, j: j++ });
63
+ }
64
+ while (i < n)
65
+ ops.push({ kind: "-", i: i++, j });
66
+ while (j < m)
67
+ ops.push({ kind: "+", i, j: j++ });
68
+ return ops;
77
69
  }
78
- /** 有改动的行加上前后 context 行;相隔不远的改动合成一段 */
79
70
  export function hunks(lines, context = 3) {
80
- const changed = lines.flatMap((l, i) => (l.kind === " " ? [] : [i]));
81
- const out = [];
82
- let from = -1;
83
- let to = -1;
84
- for (const i of changed) {
85
- if (from >= 0 && i - context <= to + 1) {
86
- to = Math.min(lines.length - 1, i + context);
87
- continue;
88
- }
89
- if (from >= 0)
90
- out.push(lines.slice(from, to + 1));
91
- from = Math.max(0, i - context);
92
- to = Math.min(lines.length - 1, i + context);
71
+ const changed = lines.flatMap((l, i) => l.kind === " " ? [] : [i]);
72
+ const out = [];
73
+ let from = -1;
74
+ let to = -1;
75
+ for (const i of changed) {
76
+ if (from >= 0 && i - context <= to + 1) {
77
+ to = Math.min(lines.length - 1, i + context);
78
+ continue;
93
79
  }
94
80
  if (from >= 0)
95
- out.push(lines.slice(from, to + 1));
96
- return out;
81
+ out.push(lines.slice(from, to + 1));
82
+ from = Math.max(0, i - context);
83
+ to = Math.min(lines.length - 1, i + context);
84
+ }
85
+ if (from >= 0)
86
+ out.push(lines.slice(from, to + 1));
87
+ return out;
97
88
  }
98
89
  export function diffStats(lines) {
99
- let added = 0;
100
- let removed = 0;
101
- for (const l of lines) {
102
- if (l.kind === "+")
103
- added++;
104
- else if (l.kind === "-")
105
- removed++;
106
- }
107
- return { added, removed };
90
+ let added = 0;
91
+ let removed = 0;
92
+ for (const l of lines) {
93
+ if (l.kind === "+")
94
+ added++;
95
+ else if (l.kind === "-")
96
+ removed++;
97
+ }
98
+ return { added, removed };
108
99
  }
109
- /**
110
- * 显示用:每行前面是行号(新增行用新文件的行号,其余用旧文件的),段与段之间用 ⋯ 分开。
111
- * 超过 maxLines 行时截断
112
- */
113
100
  export function renderDiff(before, after, maxLines = 60, lines = diffLines(before, after)) {
114
- const parts = hunks(lines);
115
- if (parts.length === 0)
116
- return dim(" (no changes)");
117
- const width = String(lines.reduce((w, l) => Math.max(w, l.old ?? 0, l.new ?? 0), 0)).length;
118
- const out = [];
119
- let shown = 0;
120
- let total = 0;
121
- for (const h of parts)
122
- total += h.length;
123
- for (const [k, h] of parts.entries()) {
124
- if (k > 0)
125
- out.push(dim(`${" ".repeat(width)} ⋯`));
126
- for (const l of h) {
127
- if (shown >= maxLines)
128
- break;
129
- const no = String((l.kind === "+" ? l.new : l.old) ?? "").padStart(width);
130
- const text = `${no} ${l.kind} ${l.text}`;
131
- out.push(l.kind === "+" ? green(text) : l.kind === "-" ? red(text) : dim(text));
132
- shown++;
133
- }
101
+ const parts = hunks(lines);
102
+ if (parts.length === 0)
103
+ return dim(" (no changes)");
104
+ const width = String(lines.reduce((w, l) => Math.max(w, l.old ?? 0, l.new ?? 0), 0)).length;
105
+ const out = [];
106
+ let shown = 0;
107
+ let total = 0;
108
+ for (const h of parts)
109
+ total += h.length;
110
+ for (const [k, h] of parts.entries()) {
111
+ if (k > 0)
112
+ out.push(dim(`${" ".repeat(width)} ⋯`));
113
+ for (const l of h) {
114
+ if (shown >= maxLines)
115
+ break;
116
+ const no = String((l.kind === "+" ? l.new : l.old) ?? "").padStart(width);
117
+ const text = `${no} ${l.kind} ${l.text}`;
118
+ out.push(l.kind === "+" ? plus(text) : l.kind === "-" ? minus(text) : dim(text));
119
+ shown++;
134
120
  }
135
- if (total > shown)
136
- out.push(dim(` … ${total - shown} more lines`));
137
- const { added, removed } = diffStats(lines);
138
- out.push(dim(` ${green(`+${added}`)} ${red(`-${removed}`)}`));
139
- return out.join("\n");
121
+ }
122
+ if (total > shown)
123
+ out.push(dim(` … ${total - shown} more lines`));
124
+ const { added, removed } = diffStats(lines);
125
+ out.push([" ", plus(`+${added}`), " ", minus(`-${removed}`)]);
126
+ return joinLines(out);
140
127
  }