@evandu/super-pi 0.1.246 → 0.1.248

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.
@@ -1,4 +1,182 @@
1
1
  export const BACKGROUND_LOG_LIMIT = 128_000;
2
+ /** Render a PTY byte stream as readable text for logs and chat. This is deliberately a text view, not a
3
+ * terminal UI: cursor movement edits the buffered lines, while colour, title and mode controls vanish. */
4
+ export function sanitizeBackgroundOutput(value) {
5
+ const lines = [[]];
6
+ let row = 0;
7
+ let column = 0;
8
+ let savedCursor = [0, 0];
9
+ const ensureRow = (index) => {
10
+ while (lines.length <= index)
11
+ lines.push([]);
12
+ };
13
+ const write = (text) => {
14
+ const cells = lines[row];
15
+ while (cells.length < column)
16
+ cells.push(" ");
17
+ for (const char of text) {
18
+ cells[column] = char;
19
+ column += 1;
20
+ }
21
+ };
22
+ const paramsOf = (raw) => raw.replace(/^[?>!]/u, "").split(";").map(item => Number.parseInt(item, 10) || 0);
23
+ const consumeCsi = (raw, final) => {
24
+ const params = paramsOf(raw);
25
+ const amount = Math.max(1, params[0] || 1);
26
+ switch (final) {
27
+ case "A":
28
+ row = Math.max(0, row - amount);
29
+ break;
30
+ case "B":
31
+ case "e":
32
+ row += amount;
33
+ ensureRow(row);
34
+ break;
35
+ case "C":
36
+ case "a":
37
+ column += amount;
38
+ break;
39
+ case "D":
40
+ column = Math.max(0, column - amount);
41
+ break;
42
+ case "E":
43
+ row += amount;
44
+ ensureRow(row);
45
+ column = 0;
46
+ break;
47
+ case "F":
48
+ row = Math.max(0, row - amount);
49
+ column = 0;
50
+ break;
51
+ case "G":
52
+ case "`":
53
+ column = Math.max(0, amount - 1);
54
+ break;
55
+ case "d":
56
+ row = Math.max(0, amount - 1);
57
+ ensureRow(row);
58
+ break;
59
+ case "H":
60
+ case "f":
61
+ row = Math.max(0, amount - 1);
62
+ ensureRow(row);
63
+ column = Math.max(0, (params[1] || 1) - 1);
64
+ break;
65
+ case "K": {
66
+ const cells = lines[row];
67
+ if ((params[0] ?? 0) === 2)
68
+ lines[row] = [];
69
+ else if ((params[0] ?? 0) === 1)
70
+ lines[row] = [...Array.from({ length: Math.min(column + 1, cells.length) }, () => " "), ...cells.slice(column + 1)];
71
+ else
72
+ cells.splice(column);
73
+ break;
74
+ }
75
+ case "J":
76
+ if ((params[0] ?? 0) === 2 || (params[0] ?? 0) === 3) {
77
+ lines.splice(0, lines.length, []);
78
+ row = 0;
79
+ column = 0;
80
+ }
81
+ else if ((params[0] ?? 0) === 0)
82
+ lines.splice(row + 1);
83
+ else if ((params[0] ?? 0) === 1) {
84
+ lines.splice(0, row);
85
+ row = 0;
86
+ lines[0] = [];
87
+ }
88
+ break;
89
+ case "s":
90
+ savedCursor = [row, column];
91
+ break;
92
+ case "u":
93
+ [row, column] = savedCursor;
94
+ ensureRow(row);
95
+ break;
96
+ case "P":
97
+ lines[row].splice(column, amount);
98
+ break;
99
+ case "X": {
100
+ const cells = lines[row];
101
+ for (let index = column; index < Math.min(cells.length, column + amount); index += 1)
102
+ cells[index] = " ";
103
+ break;
104
+ }
105
+ case "@": {
106
+ const cells = lines[row];
107
+ cells.splice(column, 0, ...Array.from({ length: amount }, () => " "));
108
+ break;
109
+ }
110
+ default: break;
111
+ }
112
+ };
113
+ const skipStringControl = (start) => {
114
+ for (let index = start; index < value.length; index += 1) {
115
+ if (value[index] === "\u0007")
116
+ return index + 1;
117
+ if (value[index] === "\u001b" && value[index + 1] === "\\")
118
+ return index + 2;
119
+ }
120
+ return value.length;
121
+ };
122
+ for (let index = 0; index < value.length;) {
123
+ const char = value[index];
124
+ if (char === "\u0090" || char === "\u009d" || char === "\u009e" || char === "\u009f") {
125
+ index = skipStringControl(index + 1);
126
+ continue;
127
+ }
128
+ if (char === "\u001b" || char === "\u009b") {
129
+ const next = value[index + 1];
130
+ if (char === "\u001b" && (next === "]" || next === "P" || next === "^" || next === "_")) {
131
+ index = skipStringControl(index + 2);
132
+ continue;
133
+ }
134
+ if ((char === "\u001b" && next === "[") || char === "\u009b") {
135
+ const parameterStart = index + (char === "\u009b" ? 1 : 2);
136
+ let end = parameterStart;
137
+ while (end < value.length && !(value.charCodeAt(end) >= 0x40 && value.charCodeAt(end) <= 0x7e))
138
+ end += 1;
139
+ if (end < value.length)
140
+ consumeCsi(value.slice(parameterStart, end), value[end]);
141
+ index = Math.min(value.length, end + 1);
142
+ continue;
143
+ }
144
+ index += next === undefined ? 1 : 2;
145
+ continue;
146
+ }
147
+ if (char === "\r") {
148
+ index += 1;
149
+ column = 0;
150
+ continue;
151
+ }
152
+ if (char === "\n") {
153
+ index += 1;
154
+ row += 1;
155
+ ensureRow(row);
156
+ column = 0;
157
+ continue;
158
+ }
159
+ if (char === "\b") {
160
+ index += 1;
161
+ column = Math.max(0, column - 1);
162
+ continue;
163
+ }
164
+ if (char === "\t") {
165
+ index += 1;
166
+ write(" ".repeat(8 - (column % 8)));
167
+ continue;
168
+ }
169
+ const code = value.codePointAt(index) ?? 0;
170
+ if (code < 0x20 || code === 0x7f || (code >= 0x80 && code <= 0x9f)) {
171
+ index += code > 0xffff ? 2 : 1;
172
+ continue;
173
+ }
174
+ const printable = String.fromCodePoint(code);
175
+ write(printable);
176
+ index += printable.length;
177
+ }
178
+ return lines.map(cells => cells.join("")).join("\n").replace(/\n+$/u, "");
179
+ }
2
180
  export function subagentProgress(run) {
3
181
  return [run.partialOutput ?? run.output, ...(run.toolCalls ?? []).map(call => call.output)]
4
182
  .filter(Boolean).join("\n\n");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@evandu/super-pi",
3
- "version": "0.1.246",
3
+ "version": "0.1.248",
4
4
  "description": "Web control plane and companion for Pi",
5
5
  "license": "MIT",
6
6
  "type": "module",