@uncarved/jade 0.4.1 → 0.4.2
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.
- package/README.md +279 -279
- package/dist/api.d.ts +1 -1
- package/dist/api.js +1 -1
- package/dist/session.js +7 -0
- package/dist/session.js.map +1 -1
- package/package.json +3 -3
- package/plugins/mentions/candidates.ts +14 -0
- package/plugins/mentions/index.ts +2 -2
- package/plugins/models/configure.ts +25 -1
- package/plugins/models/index.ts +62 -5
- package/plugins/models/plugin.json +1 -1
- package/plugins/models/provider.ts +31 -9
- package/plugins/models/saved.ts +1 -1
- package/plugins/screenshot/browser.ts +1 -1
- package/plugins/shell/shell.ts +33 -7
- package/plugins/steer/index.ts +1 -1
- package/plugins/todo/index.ts +6 -10
- package/plugins/tui/frontend.ts +6 -2
- package/plugins/tui/markdown.ts +10 -8
- package/plugins/tui/mentions.ts +10 -0
- package/plugins/tui/transcript.ts +14 -17
- package/plugins/tui/tui.ts +13 -12
- package/plugins/tui/width.ts +240 -0
- package/plugins-dist/mentions/candidates.js +6 -0
- package/plugins-dist/mentions/index.js +2 -2
- package/plugins-dist/models/configure.js +22 -1
- package/plugins-dist/models/index.js +58 -4
- package/plugins-dist/models/plugin.json +2 -1
- package/plugins-dist/models/provider.js +23 -8
- package/plugins-dist/models/saved.js +1 -1
- package/plugins-dist/screenshot/browser.js +1 -1
- package/plugins-dist/shell/shell.js +21 -7
- package/plugins-dist/steer/index.js +1 -1
- package/plugins-dist/todo/index.js +3 -8
- package/plugins-dist/tui/frontend.js +5 -2
- package/plugins-dist/tui/markdown.js +11 -9
- package/plugins-dist/tui/mentions.js +6 -0
- package/plugins-dist/tui/transcript.js +9 -12
- package/plugins-dist/tui/tui.js +10 -9
- package/plugins-dist/tui/vendor.js +1388 -1088
- package/plugins-dist/tui/width.js +219 -0
- package/sdk/python/__pycache__/jade_plugin.cpython-312.pyc +0 -0
- package/src/api.ts +1 -1
- package/src/session.ts +5 -0
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import stringWidth from "string-width";
|
|
2
|
+
import wrapAnsi from "wrap-ansi";
|
|
3
|
+
export function standalone(c) {
|
|
4
|
+
if (c < 127)
|
|
5
|
+
return c >= 32;
|
|
6
|
+
if (c < 8208)
|
|
7
|
+
return c >= 160 && c <= 255 && c !== 173;
|
|
8
|
+
if (c <= 8231)
|
|
9
|
+
return true;
|
|
10
|
+
if (c >= 8240 && c <= 8286)
|
|
11
|
+
return true;
|
|
12
|
+
if (c >= 8592 && c <= 10175)
|
|
13
|
+
return c !== 9001 && c !== 9002;
|
|
14
|
+
if (c >= 11904 && c <= 12255)
|
|
15
|
+
return true;
|
|
16
|
+
if (c >= 12288 && c <= 12543)
|
|
17
|
+
return !(c >= 12330 && c <= 12335) && c !== 12441 && c !== 12442;
|
|
18
|
+
if (c >= 12544 && c <= 40959)
|
|
19
|
+
return true;
|
|
20
|
+
if (c >= 44032 && c <= 55203)
|
|
21
|
+
return true;
|
|
22
|
+
return c >= 65281 && c <= 65376 || c >= 65504 && c <= 65510;
|
|
23
|
+
}
|
|
24
|
+
const widths = new Uint8Array(65536);
|
|
25
|
+
function charWidth(c) {
|
|
26
|
+
let w = widths[c];
|
|
27
|
+
if (w === 0)
|
|
28
|
+
widths[c] = w = stringWidth(String.fromCharCode(c)) + 1;
|
|
29
|
+
return w - 1;
|
|
30
|
+
}
|
|
31
|
+
const SGR = /\x1b\[(\d{1,2})m/y;
|
|
32
|
+
function sgrAt(s, i) {
|
|
33
|
+
SGR.lastIndex = i;
|
|
34
|
+
const m = SGR.exec(s);
|
|
35
|
+
if (!m)
|
|
36
|
+
return;
|
|
37
|
+
const code = Number(m[1]);
|
|
38
|
+
return CLOSE_OF.has(code) || RESETS.has(code) ? { code, length: m[0].length } : undefined;
|
|
39
|
+
}
|
|
40
|
+
const CLOSE_OF = new Map([
|
|
41
|
+
[1, 22],
|
|
42
|
+
[2, 22],
|
|
43
|
+
[3, 23],
|
|
44
|
+
[4, 24],
|
|
45
|
+
[9, 29],
|
|
46
|
+
...[30, 31, 32, 33, 34, 35, 36, 37, 90, 91, 92, 93, 94, 95, 96, 97].map((c) => [c, 39])
|
|
47
|
+
]);
|
|
48
|
+
const RESETS = new Set([22, 23, 24, 29, 39]);
|
|
49
|
+
function fastWidth(s) {
|
|
50
|
+
let w = 0;
|
|
51
|
+
for (let i = 0;i < s.length; i++) {
|
|
52
|
+
const c = s.charCodeAt(i);
|
|
53
|
+
if (c === 27) {
|
|
54
|
+
const m = sgrAt(s, i);
|
|
55
|
+
if (!m)
|
|
56
|
+
return;
|
|
57
|
+
i += m.length - 1;
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
if (!standalone(c))
|
|
61
|
+
return;
|
|
62
|
+
w += c < 127 ? 1 : charWidth(c);
|
|
63
|
+
}
|
|
64
|
+
return w;
|
|
65
|
+
}
|
|
66
|
+
export function visibleWidth(s) {
|
|
67
|
+
return fastWidth(s) ?? stringWidth(s);
|
|
68
|
+
}
|
|
69
|
+
function words(line) {
|
|
70
|
+
let word = { tokens: [], value: "", width: 0 };
|
|
71
|
+
const out = [word];
|
|
72
|
+
for (let i = 0;i < line.length; i++) {
|
|
73
|
+
const c = line.charCodeAt(i);
|
|
74
|
+
if (c === 32) {
|
|
75
|
+
word = { tokens: [], value: "", width: 0 };
|
|
76
|
+
out.push(word);
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
let token;
|
|
80
|
+
if (c === 27) {
|
|
81
|
+
const m = sgrAt(line, i);
|
|
82
|
+
if (!m)
|
|
83
|
+
return;
|
|
84
|
+
token = { value: line.slice(i, i + m.length), width: 0 };
|
|
85
|
+
i += m.length - 1;
|
|
86
|
+
} else {
|
|
87
|
+
if (!standalone(c))
|
|
88
|
+
return;
|
|
89
|
+
token = { value: line[i], width: c < 127 ? 1 : charWidth(c) };
|
|
90
|
+
}
|
|
91
|
+
word.tokens.push(token);
|
|
92
|
+
word.value += token.value;
|
|
93
|
+
word.width += token.width;
|
|
94
|
+
}
|
|
95
|
+
return out;
|
|
96
|
+
}
|
|
97
|
+
function wrapWord(rows, tokens, columns, rowWidth) {
|
|
98
|
+
let visible = rowWidth;
|
|
99
|
+
tokens.forEach((t, i) => {
|
|
100
|
+
if (t.width > 0 && visible > 0 && visible + t.width > columns) {
|
|
101
|
+
rows.push("");
|
|
102
|
+
visible = 0;
|
|
103
|
+
}
|
|
104
|
+
rows[rows.length - 1] += t.value;
|
|
105
|
+
visible += t.width;
|
|
106
|
+
if (visible === columns && i < tokens.length - 1) {
|
|
107
|
+
rows.push("");
|
|
108
|
+
visible = 0;
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
if (!visible && rows.at(-1).length > 0 && rows.length > 1)
|
|
112
|
+
rows[rows.length - 2] += rows.pop();
|
|
113
|
+
return fastWidth(rows.at(-1));
|
|
114
|
+
}
|
|
115
|
+
function applySgr(code, active, resetsOnly = false) {
|
|
116
|
+
if (code === 39) {
|
|
117
|
+
const i = active.findIndex((s) => s.family === "foreground");
|
|
118
|
+
if (i !== -1)
|
|
119
|
+
active.splice(i, 1);
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
if (RESETS.has(code)) {
|
|
123
|
+
for (let i = active.length - 1;i >= 0; i--)
|
|
124
|
+
if (active[i].family.startsWith("modifier-") && active[i].close === code)
|
|
125
|
+
active.splice(i, 1);
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
if (resetsOnly)
|
|
129
|
+
return;
|
|
130
|
+
const close = CLOSE_OF.get(code);
|
|
131
|
+
const family = close === 39 ? "foreground" : `modifier-${code}`;
|
|
132
|
+
const i = active.findIndex((s) => s.family === family);
|
|
133
|
+
if (i !== -1)
|
|
134
|
+
active.splice(i, 1);
|
|
135
|
+
active.push({ family, open: code, close });
|
|
136
|
+
}
|
|
137
|
+
function restoreStyles(s) {
|
|
138
|
+
let out = "";
|
|
139
|
+
const active = [];
|
|
140
|
+
let copied = 0;
|
|
141
|
+
let i = 0;
|
|
142
|
+
while (i < s.length) {
|
|
143
|
+
const c = s.charCodeAt(i);
|
|
144
|
+
if (c === 27) {
|
|
145
|
+
const m = sgrAt(s, i);
|
|
146
|
+
applySgr(m.code, active);
|
|
147
|
+
i += m.length;
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
if (c !== 10) {
|
|
151
|
+
i++;
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
out += s.slice(copied, i);
|
|
155
|
+
if (i > copied)
|
|
156
|
+
out += [...active].reverse().map((st) => `\x1B[${st.close}m`).join("");
|
|
157
|
+
out += `
|
|
158
|
+
`;
|
|
159
|
+
copied = ++i;
|
|
160
|
+
if (i < s.length && s[i] !== `
|
|
161
|
+
`) {
|
|
162
|
+
const opening = [...active];
|
|
163
|
+
for (let j = i, m = sgrAt(s, j);m; j += m.length, m = sgrAt(s, j))
|
|
164
|
+
applySgr(m.code, opening, true);
|
|
165
|
+
out += opening.map((st) => `\x1B[${st.open}m`).join("");
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return out + s.slice(copied);
|
|
169
|
+
}
|
|
170
|
+
function fastWrap(line, columns) {
|
|
171
|
+
const width = fastWidth(line);
|
|
172
|
+
if (width === undefined)
|
|
173
|
+
return;
|
|
174
|
+
if (width <= columns)
|
|
175
|
+
return [line];
|
|
176
|
+
const list = words(line);
|
|
177
|
+
const rows = [""];
|
|
178
|
+
let rowLength = 0;
|
|
179
|
+
list.forEach((word, k) => {
|
|
180
|
+
if (k > 0) {
|
|
181
|
+
if (rowLength >= columns) {
|
|
182
|
+
rows.push("");
|
|
183
|
+
rowLength = 0;
|
|
184
|
+
}
|
|
185
|
+
rows[rows.length - 1] += " ";
|
|
186
|
+
rowLength++;
|
|
187
|
+
}
|
|
188
|
+
if (word.width > columns) {
|
|
189
|
+
const remaining = columns - rowLength;
|
|
190
|
+
const thisLine = 1 + Math.floor((word.width - remaining - 1) / columns);
|
|
191
|
+
const nextLine = Math.floor((word.width - 1) / columns);
|
|
192
|
+
if (nextLine < thisLine) {
|
|
193
|
+
rows.push("");
|
|
194
|
+
rowLength = 0;
|
|
195
|
+
}
|
|
196
|
+
rowLength = wrapWord(rows, word.tokens, columns, rowLength);
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
if (rowLength + word.width > columns && rowLength > 0 && word.width > 0) {
|
|
200
|
+
rows.push("");
|
|
201
|
+
rowLength = 0;
|
|
202
|
+
}
|
|
203
|
+
rows[rows.length - 1] += word.value;
|
|
204
|
+
rowLength += word.width;
|
|
205
|
+
});
|
|
206
|
+
return line.includes("\x1B") ? restoreStyles(rows.join(`
|
|
207
|
+
`)).split(`
|
|
208
|
+
`) : rows;
|
|
209
|
+
}
|
|
210
|
+
const WRAP = { hard: true, trim: false };
|
|
211
|
+
export function wrapLines(text, width) {
|
|
212
|
+
if (text.includes("\r"))
|
|
213
|
+
return;
|
|
214
|
+
return text.split(`
|
|
215
|
+
`).map((line) => fastWrap(line, width) ?? wrapAnsi(line, width, WRAP).split(`
|
|
216
|
+
`));
|
|
217
|
+
}
|
|
218
|
+
export const wrapText = (text, width) => wrapLines(text, width)?.flat() ?? wrapAnsi(text, width, WRAP).split(`
|
|
219
|
+
`);
|
|
Binary file
|
package/src/api.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type { PluginLayer } from "@uncarved/jade-api";
|
|
|
5
5
|
export * from "@uncarved/jade-api";
|
|
6
6
|
|
|
7
7
|
/** 插件 API 的版本,插件在 plugin.json 的 api 字段里用 ^ 范围声明。和 @uncarved/jade-api 的版本一致 */
|
|
8
|
-
export const API_VERSION = "1.
|
|
8
|
+
export const API_VERSION = "1.5.0";
|
|
9
9
|
|
|
10
10
|
/** 来源层级,后面的层级更高(3.3) */
|
|
11
11
|
export const LAYERS: readonly PluginLayer[] = ["bundled", "user", "project"];
|
package/src/session.ts
CHANGED
|
@@ -766,6 +766,11 @@ export class Sessions implements SessionManager {
|
|
|
766
766
|
if (!s.rt) throw new Error(`plugin ${id}: the session's state is not available while session() runs`);
|
|
767
767
|
return s.rt.state;
|
|
768
768
|
},
|
|
769
|
+
phase: () => {
|
|
770
|
+
if (scope.closed) throw new StaleContext(id);
|
|
771
|
+
if (!s.rt) throw new Error(`plugin ${id}: the session's phase is not available while session() runs`);
|
|
772
|
+
return s.rt.phase;
|
|
773
|
+
},
|
|
769
774
|
subscribe: (fn) => {
|
|
770
775
|
if (scope.closed) throw new StaleContext(id);
|
|
771
776
|
const off = s.watch(fn, owner);
|