@xingular/harness 1.3.1-unstable.2 → 1.3.1-unstable.4
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/CHANGELOG.md +82 -0
- package/README.md +1 -1
- package/dist/cli.js +3680 -1947
- package/dist/sdk/cli.js +2 -0
- package/dist/sdk/commands/registry.d.ts +15 -0
- package/dist/sdk/commands/registry.js +2 -0
- package/dist/sdk/computer/screenshot.d.ts +32 -0
- package/dist/sdk/computer/screenshot.js +35 -0
- package/dist/sdk/context/attribution.d.ts +18 -0
- package/dist/sdk/context/attribution.js +295 -0
- package/dist/sdk/context/types.d.ts +94 -0
- package/dist/sdk/context/types.js +10 -0
- package/dist/sdk/index.d.ts +2 -1
- package/dist/sdk/index.js +2 -1
- package/dist/sdk/plugins/builtin.js +1 -0
- package/dist/sdk/prompt/compile.d.ts +42 -2
- package/dist/sdk/prompt/compile.js +87 -15
- package/dist/sdk/remote/addresses.d.ts +19 -0
- package/dist/sdk/remote/addresses.js +52 -0
- package/dist/sdk/remote/pairing.d.ts +59 -0
- package/dist/sdk/remote/pairing.js +160 -0
- package/dist/sdk/remote/seal.d.ts +28 -0
- package/dist/sdk/remote/seal.js +84 -0
- package/dist/sdk/remote/server.d.ts +28 -0
- package/dist/sdk/remote/server.js +158 -0
- package/dist/sdk/remote/service.d.ts +125 -0
- package/dist/sdk/remote/service.js +330 -0
- package/dist/sdk/remote/webClient.d.ts +4 -0
- package/dist/sdk/remote/webClient.js +444 -0
- package/dist/sdk/server/methods.js +3 -0
- package/dist/sdk/sessions/contracts.d.ts +4 -0
- package/dist/sdk/sessions/contracts.js +2 -0
- package/dist/sdk/sessions/planMode.d.ts +26 -1
- package/dist/sdk/sessions/planMode.js +48 -1
- package/dist/sdk/sessions/runner.d.ts +12 -0
- package/dist/sdk/sessions/runner.js +34 -2
- package/dist/sdk/sessions/sessions.js +1 -0
- package/dist/sdk/sessions/subagentService.d.ts +11 -1
- package/dist/sdk/sessions/subagentService.js +120 -38
- package/dist/sdk/sessions/subagents.d.ts +31 -0
- package/dist/sdk/sessions/subagents.js +45 -0
- package/dist/sdk/sessions/workSlice.d.ts +5 -9
- package/dist/sdk/sessions/workSlice.js +8 -149
- package/dist/sdk/terminal/client.d.ts +3 -1
- package/dist/sdk/terminal/client.js +15 -6
- package/dist/sdk/terminal/control.d.ts +1 -1
- package/dist/sdk/terminal/control.js +2 -2
- package/dist/sdk/terminal/controller.d.ts +22 -0
- package/dist/sdk/terminal/controller.js +104 -13
- package/dist/sdk/terminal/piExtension.js +106 -4
- package/dist/sdk/terminal/stallWatch.d.ts +13 -0
- package/dist/sdk/terminal/stallWatch.js +16 -0
- package/dist/sdk/terminal/standalone.d.ts +2 -0
- package/dist/sdk/terminal/standalone.js +9 -2
- package/dist/sdk/terminal/terminals.d.ts +14 -0
- package/dist/sdk/terminal/terminals.js +98 -2
- package/dist/sdk/terminal/tui/commandPages.d.ts +4 -1
- package/dist/sdk/terminal/tui/commandPages.js +12 -0
- package/dist/sdk/terminal/tui/commands.d.ts +3 -2
- package/dist/sdk/terminal/tui/commands.js +19 -5
- package/dist/sdk/terminal/tui/dialogs.d.ts +3 -2
- package/dist/sdk/terminal/tui/dialogs.js +4 -3
- package/dist/sdk/terminal/tui/keybindings.d.ts +1 -1
- package/dist/sdk/terminal/tui/keybindings.js +1 -1
- package/dist/sdk/terminal/tui/markdown.d.ts +16 -0
- package/dist/sdk/terminal/tui/markdown.js +55 -0
- package/dist/sdk/terminal/tui/modeChoices.d.ts +3 -2
- package/dist/sdk/terminal/tui/modeChoices.js +4 -4
- package/dist/sdk/terminal/tui/mouseReport.d.ts +30 -0
- package/dist/sdk/terminal/tui/mouseReport.js +80 -0
- package/dist/sdk/terminal/tui/pages/annotatePage.js +3 -2
- package/dist/sdk/terminal/tui/pages/browserPage.d.ts +1 -1
- package/dist/sdk/terminal/tui/pages/contextPage.d.ts +62 -0
- package/dist/sdk/terminal/tui/pages/contextPage.js +484 -0
- package/dist/sdk/terminal/tui/pages/remoteControlPage.d.ts +32 -0
- package/dist/sdk/terminal/tui/pages/remoteControlPage.js +170 -0
- package/dist/sdk/terminal/tui/pages/trajectoryPage.js +5 -4
- package/dist/sdk/terminal/tui/qr.d.ts +4 -0
- package/dist/sdk/terminal/tui/qr.js +35 -0
- package/dist/sdk/terminal/tui/runtime.js +8 -2
- package/dist/sdk/terminal/tui/search.js +3 -2
- package/dist/sdk/terminal/tui/sideQuestion.d.ts +1 -0
- package/dist/sdk/terminal/tui/sideQuestion.js +8 -3
- package/dist/sdk/terminal/tui/skillInvocation.d.ts +21 -2
- package/dist/sdk/terminal/tui/skillInvocation.js +31 -11
- package/dist/sdk/terminal/tui/status.d.ts +6 -0
- package/dist/sdk/terminal/tui/status.js +15 -1
- package/dist/sdk/terminal/tui/theme.d.ts +9 -0
- package/dist/sdk/terminal/tui/theme.js +9 -0
- package/dist/sdk/tools/defaultSkills.d.ts +19 -0
- package/dist/sdk/tools/defaultSkills.js +27 -1
- package/dist/sdk/tools/dispatch.js +8 -9
- package/dist/sdk/tools/spawnSubagent.d.ts +1 -1
- package/dist/sdk/tools/spawnSubagent.js +4 -2
- package/dist/terminal-opentui.js +1607 -492
- package/dist/terminal-pi.js +256 -144
- package/docs/README.md +1 -0
- package/docs/architecture/02-sessions-and-runs.md +55 -22
- package/docs/architecture/04-prompt.md +23 -4
- package/docs/architecture/07-tools-and-gate.md +4 -2
- package/docs/architecture/10-server-protocol.md +24 -0
- package/docs/architecture/11-terminal.md +52 -10
- package/docs/architecture/12-storage.md +5 -2
- package/docs/architecture/13-world-tools.md +17 -3
- package/docs/architecture/14-surfaces-and-parity.md +7 -3
- package/docs/architecture/15-remote-control.md +118 -0
- package/docs/architecture/README.md +3 -0
- package/docs/architecture/proposals/PROP-0049-context-attribution.md +409 -0
- package/docs/architecture/proposals/README.md +2 -1
- package/docs/decisions/ADR-0039-progress-aware-stall-guards.md +4 -0
- package/docs/decisions/ADR-0048-required-skills-from-a-message.md +42 -0
- package/docs/decisions/ADR-0050-approved-window-screenshots.md +19 -0
- package/docs/decisions/ADR-0051-terminal-decision-wait.md +10 -0
- package/docs/decisions/ADR-0052-per-profile-subagent-budgets.md +25 -0
- package/docs/decisions/ADR-0053-no-repeated-work-guard.md +45 -0
- package/docs/decisions/ADR-0054-terminal-reply-heartbeat-and-stall.md +52 -0
- package/docs/decisions/ADR-0055-plan-output-repair.md +51 -0
- package/docs/decisions/ADR-0056-remote-control.md +53 -0
- package/docs/decisions/ADR-0057-structured-plan-outcomes.md +39 -0
- package/docs/decisions/ADR-0058-ask-user-only-plan-clarification.md +36 -0
- package/docs/parity.md +14 -10
- package/docs/releases/1.3.1-unstable.3.md +54 -0
- package/docs/releases/1.3.1-unstable.4.md +56 -0
- package/docs/terminal-tui.md +43 -18
- package/package.json +3 -1
|
@@ -0,0 +1,484 @@
|
|
|
1
|
+
import { matchesKey, parseColor, truncateToWidth, visibleWidth, wrapTextWithAnsi } from '@earendil-works/pi-tui';
|
|
2
|
+
import { CHROME_PAD, padded, selectedRow } from "../chrome.js";
|
|
3
|
+
import { SERIES_COLORS } from "../theme.js";
|
|
4
|
+
const BARS = '▁▂▃▄▅▆▇█';
|
|
5
|
+
/** Characters per token, for the budget column: the same ratio the attribution estimates with. */
|
|
6
|
+
const CHARS = 4;
|
|
7
|
+
const OWNER_TITLES = {
|
|
8
|
+
foundation: 'Foundation · harness',
|
|
9
|
+
variant: 'Variant',
|
|
10
|
+
application: 'Your application',
|
|
11
|
+
conversation: 'Conversation',
|
|
12
|
+
reserved: 'Reserved and free'
|
|
13
|
+
};
|
|
14
|
+
const OWNER_ORDER = ['foundation', 'variant', 'application', 'conversation', 'reserved'];
|
|
15
|
+
const KIND_ORDER = ['System prompt', 'Tools', 'Memory', 'Skills', 'Messages', 'Reserved'];
|
|
16
|
+
function kindOf(row) {
|
|
17
|
+
if (row.group === 'reserved')
|
|
18
|
+
return 'Reserved';
|
|
19
|
+
if (row.id === 'messages' || row.id === 'context-update' || row.id === 'references' || row.id === 'required-skills' || row.id === 'wiki' || row.id === 'session-state')
|
|
20
|
+
return 'Messages';
|
|
21
|
+
if (row.id === 'memory')
|
|
22
|
+
return 'Memory';
|
|
23
|
+
if (row.id === 'skills')
|
|
24
|
+
return 'Skills';
|
|
25
|
+
if (row.id === 'tools' || row.id === 'tools-harness' || row.id === 'tools-application' || row.id === 'tool-guidance')
|
|
26
|
+
return 'Tools';
|
|
27
|
+
return 'System prompt';
|
|
28
|
+
}
|
|
29
|
+
function count(value) {
|
|
30
|
+
if (!Number.isFinite(value) || value <= 0)
|
|
31
|
+
return '0';
|
|
32
|
+
if (value >= 1_000_000)
|
|
33
|
+
return `${(value / 1_000_000).toFixed(value % 1_000_000 === 0 ? 0 : 1)}M`;
|
|
34
|
+
if (value >= 1_000)
|
|
35
|
+
return `${(value / 1_000).toFixed(1)}K`;
|
|
36
|
+
return String(Math.round(value));
|
|
37
|
+
}
|
|
38
|
+
function percent(value) {
|
|
39
|
+
return value === null ? '?' : `${value.toFixed(1)}%`;
|
|
40
|
+
}
|
|
41
|
+
/** One rule for capacity, shared with the App's `Meter`: amber at 80, red at 95. */
|
|
42
|
+
function tone(share) {
|
|
43
|
+
if (share === null)
|
|
44
|
+
return 'dim';
|
|
45
|
+
if (share >= 95)
|
|
46
|
+
return 'error';
|
|
47
|
+
if (share >= 80)
|
|
48
|
+
return 'warning';
|
|
49
|
+
return 'success';
|
|
50
|
+
}
|
|
51
|
+
/** What a bar's run is called, short enough to sit in a legend. */
|
|
52
|
+
const SERIES_LABELS = {
|
|
53
|
+
foundation: 'foundation',
|
|
54
|
+
variant: 'variant',
|
|
55
|
+
application: 'your app',
|
|
56
|
+
conversation: 'conversation',
|
|
57
|
+
reserved: 'reserved'
|
|
58
|
+
};
|
|
59
|
+
/** The categorical colour of an owner group: the App's `--data-1..4`, in the same order. */
|
|
60
|
+
function seriesColor(theme, index) {
|
|
61
|
+
const palette = theme.appearance === 'light' ? SERIES_COLORS.light : SERIES_COLORS.dark;
|
|
62
|
+
return palette[index] ?? palette[palette.length - 1];
|
|
63
|
+
}
|
|
64
|
+
/** Cells for each value out of `total`, by largest remainder, so the runs always add up. */
|
|
65
|
+
export function allocateCells(values, total) {
|
|
66
|
+
const cells = Math.max(0, Math.floor(total));
|
|
67
|
+
const sum = values.reduce((acc, value) => acc + Math.max(0, value), 0);
|
|
68
|
+
if (sum <= 0 || cells <= 0)
|
|
69
|
+
return values.map(() => 0);
|
|
70
|
+
const present = values.map((value, index) => ({ value: Math.max(0, value), index })).filter((entry) => entry.value > 0);
|
|
71
|
+
if (cells < present.length) {
|
|
72
|
+
const out = values.map(() => 0);
|
|
73
|
+
for (const entry of [...present].sort((left, right) => right.value - left.value).slice(0, cells))
|
|
74
|
+
out[entry.index] = 1;
|
|
75
|
+
return out;
|
|
76
|
+
}
|
|
77
|
+
const exact = values.map((value) => (Math.max(0, value) / sum) * cells);
|
|
78
|
+
const out = exact.map((value) => Math.floor(value));
|
|
79
|
+
let left = cells - out.reduce((acc, value) => acc + value, 0);
|
|
80
|
+
for (const entry of exact.map((value, index) => ({ rest: value - Math.floor(value), index })).sort((left_, right) => right.rest - left_.rest)) {
|
|
81
|
+
if (left <= 0)
|
|
82
|
+
break;
|
|
83
|
+
out[entry.index] = (out[entry.index] ?? 0) + 1;
|
|
84
|
+
left -= 1;
|
|
85
|
+
}
|
|
86
|
+
// A kind with tokens gets one cell while there is room to spare, so it never vanishes silently.
|
|
87
|
+
for (const entry of present) {
|
|
88
|
+
if ((out[entry.index] ?? 0) > 0)
|
|
89
|
+
continue;
|
|
90
|
+
const donor = out.map((value, index) => ({ value, index })).filter((candidate) => candidate.index !== entry.index && candidate.value > 1).sort((a, b) => b.value - a.value)[0];
|
|
91
|
+
if (!donor)
|
|
92
|
+
break;
|
|
93
|
+
out[donor.index] = (out[donor.index] ?? 0) - 1;
|
|
94
|
+
out[entry.index] = 1;
|
|
95
|
+
}
|
|
96
|
+
return out;
|
|
97
|
+
}
|
|
98
|
+
/** The bar and its legend: one colour per kind of context, the track for free space, a marker at the reserve. */
|
|
99
|
+
export function contextBar(data, width, theme) {
|
|
100
|
+
const room = Math.max(1, width - 2);
|
|
101
|
+
const parts = OWNER_ORDER.slice(0, 4)
|
|
102
|
+
.map((group, index) => ({ group, tokens: data.totals[group], color: seriesColor(theme, index) }))
|
|
103
|
+
.filter((part) => part.tokens > 0);
|
|
104
|
+
const window = data.window;
|
|
105
|
+
const share = window === null || window <= 0 ? 100 : Math.min(100, (data.used / window) * 100);
|
|
106
|
+
const filled = Math.max(0, Math.min(room, Math.round((share / 100) * room)));
|
|
107
|
+
const cells = allocateCells(parts.map((part) => part.tokens), filled);
|
|
108
|
+
const runs = parts.flatMap((part, index) => (cells[index] ?? 0) > 0 ? [{ text: '█'.repeat(cells[index]), color: part.color }] : []);
|
|
109
|
+
const trackCells = Math.max(0, room - filled);
|
|
110
|
+
const reserve = data.compaction?.reserveTokens ?? null;
|
|
111
|
+
const markerAt = reserve !== null && window !== null && window > 0 ? Math.round(((data.used + reserve) / window) * room) : null;
|
|
112
|
+
const inTrack = markerAt !== null && markerAt >= filled && markerAt < room ? markerAt - filled : null;
|
|
113
|
+
const bar = '[' + runs.map((run) => theme.style(run.text, { fg: parseColor(run.color) })).join('')
|
|
114
|
+
+ (trackCells > 0
|
|
115
|
+
? theme.fg('dim', '░'.repeat(inTrack ?? trackCells))
|
|
116
|
+
+ (inTrack === null ? '' : theme.fg('warning', '│') + theme.fg('dim', '░'.repeat(Math.max(0, trackCells - inTrack - 1))))
|
|
117
|
+
: (inTrack === null ? '' : theme.fg('warning', '│')))
|
|
118
|
+
+ ']';
|
|
119
|
+
const entries = parts.map((part) => ({ text: `▌${SERIES_LABELS[part.group]} ${count(part.tokens)}`, color: part.color }));
|
|
120
|
+
entries.push({ text: `free ${data.free === null ? '?' : count(data.free)}`, color: null });
|
|
121
|
+
if (reserve !== null)
|
|
122
|
+
entries.push({ text: `│ compaction at ${count(Math.min(window ?? data.used + reserve, data.used + reserve))}`, color: null });
|
|
123
|
+
const legend = [];
|
|
124
|
+
let line = '';
|
|
125
|
+
for (const entry of entries) {
|
|
126
|
+
const piece = entry.color ? theme.style(entry.text, { fg: parseColor(entry.color) }) : theme.fg('dim', entry.text);
|
|
127
|
+
const candidate = line ? `${line} ${piece}` : piece;
|
|
128
|
+
if (line && visibleWidth(candidate) > width) {
|
|
129
|
+
legend.push(line);
|
|
130
|
+
line = piece;
|
|
131
|
+
}
|
|
132
|
+
else
|
|
133
|
+
line = candidate;
|
|
134
|
+
}
|
|
135
|
+
if (line)
|
|
136
|
+
legend.push(line);
|
|
137
|
+
return { bar, legend };
|
|
138
|
+
}
|
|
139
|
+
/** A label on the left and a quiet value at the right edge of the same row. */
|
|
140
|
+
function spread(left, right, width) {
|
|
141
|
+
if (!right)
|
|
142
|
+
return truncateToWidth(left, width, '');
|
|
143
|
+
const room = Math.max(0, width - visibleWidth(left) - 2);
|
|
144
|
+
const value = truncateToWidth(right, room, '');
|
|
145
|
+
return left + ' '.repeat(Math.max(1, width - visibleWidth(left) - visibleWidth(value))) + value;
|
|
146
|
+
}
|
|
147
|
+
export class ContextPage {
|
|
148
|
+
options;
|
|
149
|
+
presentation = 'fullscreen';
|
|
150
|
+
focused = false;
|
|
151
|
+
tab;
|
|
152
|
+
grouping = 'owner';
|
|
153
|
+
data = null;
|
|
154
|
+
detail = null;
|
|
155
|
+
selectedId = null;
|
|
156
|
+
folded = new Set();
|
|
157
|
+
offset = 0;
|
|
158
|
+
detailOffset = 0;
|
|
159
|
+
maxOffset = 0;
|
|
160
|
+
scrollRows = 1;
|
|
161
|
+
busy = false;
|
|
162
|
+
reloadPending = false;
|
|
163
|
+
error = null;
|
|
164
|
+
disposed = false;
|
|
165
|
+
constructor(options) {
|
|
166
|
+
this.options = options;
|
|
167
|
+
this.tab = options.initialTab ?? 'request';
|
|
168
|
+
}
|
|
169
|
+
tabs() {
|
|
170
|
+
return [{ id: 'request', title: 'Request' }, { id: 'growth', title: 'Growth' }];
|
|
171
|
+
}
|
|
172
|
+
activeTab() {
|
|
173
|
+
return this.tab;
|
|
174
|
+
}
|
|
175
|
+
selectTab(id) {
|
|
176
|
+
if (id !== 'request' && id !== 'growth')
|
|
177
|
+
return;
|
|
178
|
+
if (id === this.tab)
|
|
179
|
+
return;
|
|
180
|
+
this.tab = id;
|
|
181
|
+
this.offset = 0;
|
|
182
|
+
this.detail = null;
|
|
183
|
+
this.options.changed();
|
|
184
|
+
if (!this.data)
|
|
185
|
+
void this.load();
|
|
186
|
+
}
|
|
187
|
+
hint() {
|
|
188
|
+
if (this.detail)
|
|
189
|
+
return '↑/↓ scroll · esc close · q close page';
|
|
190
|
+
return this.tab === 'request'
|
|
191
|
+
? '↑/↓ move · space fold · enter text · g group · c compact · v variant · r refresh · q close'
|
|
192
|
+
: '↑/↓ scroll · r refresh · q close';
|
|
193
|
+
}
|
|
194
|
+
activate() {
|
|
195
|
+
if (!this.data)
|
|
196
|
+
void this.load();
|
|
197
|
+
}
|
|
198
|
+
dispose() {
|
|
199
|
+
this.disposed = true;
|
|
200
|
+
}
|
|
201
|
+
async load(section) {
|
|
202
|
+
if (this.disposed)
|
|
203
|
+
return;
|
|
204
|
+
if (this.busy) {
|
|
205
|
+
this.reloadPending = true;
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
this.busy = true;
|
|
209
|
+
this.error = null;
|
|
210
|
+
this.options.changed();
|
|
211
|
+
try {
|
|
212
|
+
const answer = await this.options.call('terminal.context', section ? { section } : {});
|
|
213
|
+
if (this.disposed)
|
|
214
|
+
return;
|
|
215
|
+
this.data = answer.attribution ?? null;
|
|
216
|
+
// Start on the first row so space and enter act on something the person can see.
|
|
217
|
+
if (!this.entries().some((entry) => entry.row.id === this.selectedId))
|
|
218
|
+
this.selectedId = this.entries()[0]?.row.id ?? null;
|
|
219
|
+
if (section) {
|
|
220
|
+
if (answer.text)
|
|
221
|
+
this.detail = answer.text;
|
|
222
|
+
else
|
|
223
|
+
this.error = 'That row carries no text: it is measured, not written.';
|
|
224
|
+
this.detailOffset = 0;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
catch (cause) {
|
|
228
|
+
this.error = cause instanceof Error ? cause.message : 'The context could not be read.';
|
|
229
|
+
}
|
|
230
|
+
finally {
|
|
231
|
+
this.busy = false;
|
|
232
|
+
this.options.changed();
|
|
233
|
+
if (this.reloadPending) {
|
|
234
|
+
this.reloadPending = false;
|
|
235
|
+
void this.load();
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
handleInput(data) {
|
|
240
|
+
if (this.detail) {
|
|
241
|
+
const page = Math.max(1, this.scrollRows - 2);
|
|
242
|
+
if (matchesKey(data, 'up'))
|
|
243
|
+
this.detailOffset = Math.max(0, this.detailOffset - 1);
|
|
244
|
+
else if (matchesKey(data, 'down'))
|
|
245
|
+
this.detailOffset += 1;
|
|
246
|
+
else if (matchesKey(data, 'pageUp'))
|
|
247
|
+
this.detailOffset = Math.max(0, this.detailOffset - page);
|
|
248
|
+
else if (matchesKey(data, 'pageDown'))
|
|
249
|
+
this.detailOffset += page;
|
|
250
|
+
else if (matchesKey(data, 'escape') || data === 'q') {
|
|
251
|
+
this.detail = null;
|
|
252
|
+
this.options.changed();
|
|
253
|
+
}
|
|
254
|
+
else
|
|
255
|
+
return false;
|
|
256
|
+
this.options.changed();
|
|
257
|
+
return true;
|
|
258
|
+
}
|
|
259
|
+
if (matchesKey(data, 'tab') || matchesKey(data, 'shift+tab')) {
|
|
260
|
+
const tabs = ['request', 'growth'];
|
|
261
|
+
const direction = matchesKey(data, 'shift+tab') ? -1 : 1;
|
|
262
|
+
this.selectTab(tabs[(tabs.indexOf(this.tab) + direction + tabs.length) % tabs.length]);
|
|
263
|
+
return true;
|
|
264
|
+
}
|
|
265
|
+
const entries = this.entries();
|
|
266
|
+
const found = entries.findIndex((entry) => entry.row.id === this.selectedId);
|
|
267
|
+
const current = found >= 0 ? found : 0;
|
|
268
|
+
if (!entries.length)
|
|
269
|
+
return false;
|
|
270
|
+
if (matchesKey(data, 'up'))
|
|
271
|
+
this.move(entries, current - 1);
|
|
272
|
+
else if (matchesKey(data, 'down'))
|
|
273
|
+
this.move(entries, current + 1);
|
|
274
|
+
else if (matchesKey(data, 'home'))
|
|
275
|
+
this.offset = 0;
|
|
276
|
+
else if (matchesKey(data, 'end'))
|
|
277
|
+
this.offset = this.maxOffset;
|
|
278
|
+
else if (data === ' ' && entries[current]) {
|
|
279
|
+
const row = entries[current].row;
|
|
280
|
+
if (this.folded.has(row.group))
|
|
281
|
+
this.folded.delete(row.group);
|
|
282
|
+
else
|
|
283
|
+
this.folded.add(row.group);
|
|
284
|
+
}
|
|
285
|
+
else if (matchesKey(data, 'enter') && entries[current]) {
|
|
286
|
+
void this.load(entries[current].row.id);
|
|
287
|
+
return true;
|
|
288
|
+
}
|
|
289
|
+
else if (data === 'g') {
|
|
290
|
+
this.grouping = this.grouping === 'owner' ? 'kind' : 'owner';
|
|
291
|
+
this.folded.clear();
|
|
292
|
+
this.offset = 0;
|
|
293
|
+
}
|
|
294
|
+
else if (data === 'r') {
|
|
295
|
+
void this.load();
|
|
296
|
+
return true;
|
|
297
|
+
}
|
|
298
|
+
else if (data === 'c') {
|
|
299
|
+
void this.compact();
|
|
300
|
+
return true;
|
|
301
|
+
}
|
|
302
|
+
else if (data === 'v') {
|
|
303
|
+
this.options.openVariant?.();
|
|
304
|
+
return true;
|
|
305
|
+
}
|
|
306
|
+
else
|
|
307
|
+
return false;
|
|
308
|
+
this.options.changed();
|
|
309
|
+
return true;
|
|
310
|
+
}
|
|
311
|
+
move(entries, index) {
|
|
312
|
+
if (!entries.length)
|
|
313
|
+
return;
|
|
314
|
+
const next = entries[Math.max(0, Math.min(entries.length - 1, index))];
|
|
315
|
+
if (next)
|
|
316
|
+
this.selectedId = next.row.id;
|
|
317
|
+
}
|
|
318
|
+
async compact() {
|
|
319
|
+
if (!this.options.compact)
|
|
320
|
+
return;
|
|
321
|
+
const free = this.data?.free === null || this.data?.free === undefined ? null : this.data.free;
|
|
322
|
+
const question = free === null
|
|
323
|
+
? 'Pi will summarize this conversation and start the next request from the summary.'
|
|
324
|
+
: `Pi will summarize this conversation. About ${count(free)} tokens are free before it does.`;
|
|
325
|
+
if (this.options.confirm && !(await this.options.confirm('Compact the conversation now?', question)))
|
|
326
|
+
return;
|
|
327
|
+
try {
|
|
328
|
+
await this.options.compact();
|
|
329
|
+
await this.load();
|
|
330
|
+
}
|
|
331
|
+
catch (cause) {
|
|
332
|
+
this.error = cause instanceof Error ? cause.message : 'Compaction failed.';
|
|
333
|
+
this.options.changed();
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
/** The rows in the order the page draws them, with the heading each one introduces. */
|
|
337
|
+
entries() {
|
|
338
|
+
const rows = this.data?.rows ?? [];
|
|
339
|
+
if (this.grouping === 'owner') {
|
|
340
|
+
const ordered = [...rows].sort((left, right) => OWNER_ORDER.indexOf(left.group) - OWNER_ORDER.indexOf(right.group));
|
|
341
|
+
const out = [];
|
|
342
|
+
for (const row of ordered) {
|
|
343
|
+
const previous = out.at(-1)?.row.group;
|
|
344
|
+
out.push({ row, heading: previous === row.group ? null : (OWNER_TITLES[row.group] ?? row.group), folded: this.folded.has(row.group) });
|
|
345
|
+
}
|
|
346
|
+
return out;
|
|
347
|
+
}
|
|
348
|
+
const ordered = [...rows].sort((left, right) => KIND_ORDER.indexOf(kindOf(left)) - KIND_ORDER.indexOf(kindOf(right)));
|
|
349
|
+
const out = [];
|
|
350
|
+
let last = null;
|
|
351
|
+
for (const row of ordered) {
|
|
352
|
+
const kind = kindOf(row);
|
|
353
|
+
const folded = this.folded.has(kind);
|
|
354
|
+
out.push({ row, heading: last === kind ? null : kind, folded });
|
|
355
|
+
last = kind;
|
|
356
|
+
}
|
|
357
|
+
return out;
|
|
358
|
+
}
|
|
359
|
+
render(width, rows) {
|
|
360
|
+
if (width < 1 || rows < 1)
|
|
361
|
+
return [];
|
|
362
|
+
const theme = this.options.theme();
|
|
363
|
+
// The overlay owns the tab strip, both rules and the hint; the body starts at the reading.
|
|
364
|
+
const body = this.detail ? this.detailBody(width, theme) : this.tab === 'growth' ? this.growthBody(width, theme) : this.requestBody(width, theme);
|
|
365
|
+
const room = Math.max(1, rows);
|
|
366
|
+
this.scrollRows = room;
|
|
367
|
+
this.maxOffset = Math.max(0, body.length - room);
|
|
368
|
+
const wanted = this.detail ? this.detailOffset : this.offset;
|
|
369
|
+
const offset = Math.max(0, Math.min(wanted, this.maxOffset));
|
|
370
|
+
if (this.detail)
|
|
371
|
+
this.detailOffset = offset;
|
|
372
|
+
else
|
|
373
|
+
this.offset = offset;
|
|
374
|
+
return body.slice(offset, offset + room).map((line) => truncateToWidth(line, width, ''));
|
|
375
|
+
}
|
|
376
|
+
requestBody(width, theme) {
|
|
377
|
+
const data = this.data;
|
|
378
|
+
if (!data) {
|
|
379
|
+
return [padded(theme.fg(this.error ? 'error' : 'dim', this.error ?? (this.busy ? 'Reading the recorded context…' : 'No reply yet: the next request records what it is made of.')), width)];
|
|
380
|
+
}
|
|
381
|
+
const inner = Math.max(8, width - CHROME_PAD * 2);
|
|
382
|
+
const body = [];
|
|
383
|
+
body.push(padded(spread(theme.fg('text', `${count(data.used)} of ${data.window === null ? 'an unknown window' : count(data.window)}`), theme.fg(tone(data.share), `${percent(data.share)} used · ${data.source}`), inner), width));
|
|
384
|
+
const chart = contextBar(data, inner, theme);
|
|
385
|
+
body.push(padded(chart.bar, width));
|
|
386
|
+
for (const line of chart.legend)
|
|
387
|
+
body.push(padded(line, width));
|
|
388
|
+
body.push('');
|
|
389
|
+
for (const entry of this.entries()) {
|
|
390
|
+
if (entry.heading) {
|
|
391
|
+
const total = data.rows.filter((row) => (this.grouping === 'owner' ? OWNER_TITLES[row.group] === entry.heading : kindOf(row) === entry.heading)).reduce((sum, row) => sum + row.tokens, 0);
|
|
392
|
+
// The heading carries its group's colour, so the list and the bar read as one picture.
|
|
393
|
+
const owner = this.grouping === 'owner' ? OWNER_ORDER.find((group) => OWNER_TITLES[group] === entry.heading) : undefined;
|
|
394
|
+
const swatch = owner ? theme.style('█ ', { fg: parseColor(seriesColor(theme, OWNER_ORDER.indexOf(owner))) }) : '';
|
|
395
|
+
body.push(padded(swatch + theme.bold(theme.fg('accent', entry.heading)) + theme.fg('dim', ` ${count(total)}`), width));
|
|
396
|
+
}
|
|
397
|
+
if (entry.folded)
|
|
398
|
+
continue;
|
|
399
|
+
body.push(this.rowLine(entry.row, inner, width, theme));
|
|
400
|
+
}
|
|
401
|
+
if (data.onDemand.length) {
|
|
402
|
+
body.push('');
|
|
403
|
+
body.push(padded(theme.fg('accent', 'On demand') + theme.fg('dim', ' not in this request'), width));
|
|
404
|
+
for (const item of data.onDemand) {
|
|
405
|
+
const cost = item.tokensEach === null ? (item.note ?? '') : `about ${count(item.tokensEach)} each · ${item.note ?? ''}`;
|
|
406
|
+
body.push(padded(` ${theme.fg('text', item.title)} ${theme.fg('dim', `${item.items} available · ${cost}`)}`, width));
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
if (data.note) {
|
|
410
|
+
body.push('');
|
|
411
|
+
body.push(...wrapTextWithAnsi(theme.fg('dim', data.note), inner).map((line) => padded(line, width)));
|
|
412
|
+
}
|
|
413
|
+
if (this.error)
|
|
414
|
+
body.push(padded(theme.fg('error', this.error), width));
|
|
415
|
+
return body;
|
|
416
|
+
}
|
|
417
|
+
rowLine(row, inner, width, theme) {
|
|
418
|
+
const selected = row.id === this.selectedId;
|
|
419
|
+
const marker = selected ? '❯ ' : row.always ? ' ' : '· ';
|
|
420
|
+
const tail = `${count(row.tokens).padStart(7)}${percent(row.share).padStart(7)}`;
|
|
421
|
+
// The note says why a figure is not exact, so it outranks the budget and the tool breakdown.
|
|
422
|
+
const extras = [
|
|
423
|
+
row.note ? row.note : '',
|
|
424
|
+
row.budget ? `${count(row.chars ?? row.tokens * CHARS)} of ${count(row.budget)} chars` : '',
|
|
425
|
+
row.tools?.length ? row.tools.map((tool) => `${tool.group} ${tool.count}`).join(' · ') : ''
|
|
426
|
+
].filter(Boolean);
|
|
427
|
+
const room = () => Math.max(12, inner - visibleWidth(tail) - 1 - (extras.length ? visibleWidth(extras.join(' ')) + 2 : 0));
|
|
428
|
+
let left = truncateToWidth(`${marker}${row.title}`, room(), '…');
|
|
429
|
+
while (extras.length && visibleWidth(left) + visibleWidth(tail) + 2 + visibleWidth(extras.join(' ')) > inner)
|
|
430
|
+
extras.pop();
|
|
431
|
+
const rest = extras.join(' ');
|
|
432
|
+
const gap = Math.max(1, inner - visibleWidth(left) - visibleWidth(tail) - (rest ? visibleWidth(rest) + 2 : 0));
|
|
433
|
+
const line = `${left}${' '.repeat(gap)}${rest ? theme.fg('dim', rest) + ' ' : ''}${tail}`;
|
|
434
|
+
if (selected)
|
|
435
|
+
return selectedRow(padded(line, width), width, theme);
|
|
436
|
+
return padded(line, width);
|
|
437
|
+
}
|
|
438
|
+
growthBody(width, theme) {
|
|
439
|
+
const data = this.data;
|
|
440
|
+
if (!data)
|
|
441
|
+
return [padded(theme.fg('dim', this.busy ? 'Reading the recorded context…' : 'No reply yet.'), width)];
|
|
442
|
+
const inner = Math.max(8, width - CHROME_PAD * 2);
|
|
443
|
+
const body = [];
|
|
444
|
+
const history = data.history.slice(-24);
|
|
445
|
+
if (history.length) {
|
|
446
|
+
const peak = Math.max(...history.map((point) => point.used), 1);
|
|
447
|
+
const spark = history.map((point) => BARS[Math.min(BARS.length - 1, Math.round((point.used / peak) * (BARS.length - 1)))]).join('');
|
|
448
|
+
body.push(padded(theme.fg('accent', spark), width));
|
|
449
|
+
body.push(padded(theme.fg('dim', `${history.length} requests · peak ${count(peak)}${data.compactions.length ? ` · ${data.compactions.length} compaction${data.compactions.length === 1 ? '' : 's'}` : ''}`), width));
|
|
450
|
+
}
|
|
451
|
+
else {
|
|
452
|
+
body.push(padded(theme.fg('dim', 'No measured request yet.'), width));
|
|
453
|
+
}
|
|
454
|
+
body.push('');
|
|
455
|
+
body.push(padded(spread(theme.fg('dim', 'REQUEST'), theme.fg('dim', 'USED SHARE'), inner), width));
|
|
456
|
+
for (const point of history.slice().reverse().slice(0, 12)) {
|
|
457
|
+
body.push(padded(spread(` ${point.request}`, `${count(point.used).padStart(8)}${percent(point.share).padStart(8)}`, inner), width));
|
|
458
|
+
}
|
|
459
|
+
for (const compaction of data.compactions.slice(-3)) {
|
|
460
|
+
const before = compaction.before === null ? '?' : count(compaction.before);
|
|
461
|
+
const after = compaction.after === null ? '?' : count(compaction.after);
|
|
462
|
+
body.push(padded(theme.fg('warning', ` compacted ${before} → ${after}`), width));
|
|
463
|
+
}
|
|
464
|
+
body.push('');
|
|
465
|
+
body.push(...wrapTextWithAnsi(theme.fg('dim', data.note ?? ''), inner).filter(Boolean).map((line) => padded(line, width)));
|
|
466
|
+
return body;
|
|
467
|
+
}
|
|
468
|
+
detailBody(width, theme) {
|
|
469
|
+
const detail = this.detail;
|
|
470
|
+
const inner = Math.max(8, width - CHROME_PAD * 2);
|
|
471
|
+
const body = [];
|
|
472
|
+
body.push(padded(theme.bold(theme.fg('accent', detail.title)), width));
|
|
473
|
+
body.push('');
|
|
474
|
+
for (const line of detail.text.split('\n')) {
|
|
475
|
+
if (!line.trim()) {
|
|
476
|
+
body.push('');
|
|
477
|
+
continue;
|
|
478
|
+
}
|
|
479
|
+
for (const wrapped of wrapTextWithAnsi(theme.fg('text', line), inner))
|
|
480
|
+
body.push(padded(wrapped, width));
|
|
481
|
+
}
|
|
482
|
+
return body;
|
|
483
|
+
}
|
|
484
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Theme } from '@earendil-works/pi-coding-agent';
|
|
2
|
+
import type { TerminalPage } from "../page.js";
|
|
3
|
+
export interface RemoteControlPageOptions {
|
|
4
|
+
theme(): Theme;
|
|
5
|
+
call<T = unknown>(method: string, params?: Record<string, unknown>): Promise<T>;
|
|
6
|
+
changed(): void;
|
|
7
|
+
copy(text: string): Promise<void>;
|
|
8
|
+
notify(message: string, type?: 'info' | 'warning' | 'error'): void;
|
|
9
|
+
}
|
|
10
|
+
export declare class RemoteControlPage implements TerminalPage {
|
|
11
|
+
private readonly options;
|
|
12
|
+
presentation: "fullscreen";
|
|
13
|
+
private status;
|
|
14
|
+
private error;
|
|
15
|
+
private showQr;
|
|
16
|
+
private busy;
|
|
17
|
+
private disposed;
|
|
18
|
+
private watching;
|
|
19
|
+
constructor(options: RemoteControlPageOptions);
|
|
20
|
+
tabs(): {
|
|
21
|
+
id: string;
|
|
22
|
+
title: string;
|
|
23
|
+
}[];
|
|
24
|
+
activeTab(): string;
|
|
25
|
+
hint(): string;
|
|
26
|
+
activate(): void;
|
|
27
|
+
dispose(): void;
|
|
28
|
+
private watch;
|
|
29
|
+
private act;
|
|
30
|
+
handleInput(data: string): boolean;
|
|
31
|
+
render(width: number, rows: number): string[];
|
|
32
|
+
}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { truncateToWidth, visibleWidth, wrapTextWithAnsi } from '@earendil-works/pi-tui';
|
|
2
|
+
import { safeText } from "../chrome.js";
|
|
3
|
+
import { qrLines } from "../qr.js";
|
|
4
|
+
const KIND_LABEL = { tailscale: 'Tailscale', lan: 'Wi-Fi' };
|
|
5
|
+
export class RemoteControlPage {
|
|
6
|
+
options;
|
|
7
|
+
presentation = 'fullscreen';
|
|
8
|
+
status = null;
|
|
9
|
+
error = null;
|
|
10
|
+
showQr = true;
|
|
11
|
+
busy = false;
|
|
12
|
+
disposed = false;
|
|
13
|
+
watching = null;
|
|
14
|
+
constructor(options) {
|
|
15
|
+
this.options = options;
|
|
16
|
+
}
|
|
17
|
+
tabs() {
|
|
18
|
+
return [{ id: 'remote', title: 'Remote Control' }];
|
|
19
|
+
}
|
|
20
|
+
activeTab() {
|
|
21
|
+
return 'remote';
|
|
22
|
+
}
|
|
23
|
+
hint() {
|
|
24
|
+
const status = this.status;
|
|
25
|
+
if (status?.request)
|
|
26
|
+
return 'a allow · d deny';
|
|
27
|
+
if (!status?.running)
|
|
28
|
+
return 's start';
|
|
29
|
+
const parts = ['space QR', 'c copy link', 'n new link'];
|
|
30
|
+
if (status.kinds.length > 1)
|
|
31
|
+
parts.push(`t use ${status.kind === 'tailscale' ? 'Wi-Fi' : 'Tailscale'}`);
|
|
32
|
+
parts.push('x stop');
|
|
33
|
+
return parts.join(' · ');
|
|
34
|
+
}
|
|
35
|
+
activate() {
|
|
36
|
+
void this.watch();
|
|
37
|
+
}
|
|
38
|
+
dispose() {
|
|
39
|
+
this.disposed = true;
|
|
40
|
+
this.watching?.abort();
|
|
41
|
+
}
|
|
42
|
+
async watch() {
|
|
43
|
+
const watching = new AbortController();
|
|
44
|
+
this.watching = watching;
|
|
45
|
+
let revision;
|
|
46
|
+
while (!this.disposed && !watching.signal.aborted) {
|
|
47
|
+
try {
|
|
48
|
+
const status = await this.options.call(revision === undefined ? 'terminal.remoteControl.status' : 'terminal.remoteControl.status.wait', { revision });
|
|
49
|
+
if (this.disposed)
|
|
50
|
+
return;
|
|
51
|
+
this.status = status;
|
|
52
|
+
this.error = null;
|
|
53
|
+
revision = status.revision;
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
if (this.disposed)
|
|
57
|
+
return;
|
|
58
|
+
this.error = error instanceof Error ? error.message : String(error);
|
|
59
|
+
revision = undefined;
|
|
60
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
61
|
+
}
|
|
62
|
+
this.options.changed();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
async act(method, params = {}, done) {
|
|
66
|
+
if (this.busy)
|
|
67
|
+
return;
|
|
68
|
+
this.busy = true;
|
|
69
|
+
this.options.changed();
|
|
70
|
+
try {
|
|
71
|
+
this.status = await this.options.call(method, params);
|
|
72
|
+
this.error = null;
|
|
73
|
+
if (done)
|
|
74
|
+
this.options.notify(done);
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
this.error = error instanceof Error ? error.message : String(error);
|
|
78
|
+
}
|
|
79
|
+
finally {
|
|
80
|
+
this.busy = false;
|
|
81
|
+
this.options.changed();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
handleInput(data) {
|
|
85
|
+
const status = this.status;
|
|
86
|
+
if (status?.request) {
|
|
87
|
+
if (data === 'a' || data === 'y')
|
|
88
|
+
void this.act('terminal.remoteControl.confirm', { requestId: status.request.id, allow: true }, `${status.request.label} can now control this session.`);
|
|
89
|
+
else if (data === 'd' || data === 'n')
|
|
90
|
+
void this.act('terminal.remoteControl.confirm', { requestId: status.request.id, allow: false });
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
if (!status?.running) {
|
|
94
|
+
if (data === 's')
|
|
95
|
+
void this.act('terminal.remoteControl.start');
|
|
96
|
+
return data === 's';
|
|
97
|
+
}
|
|
98
|
+
if (data === ' ')
|
|
99
|
+
this.showQr = !this.showQr;
|
|
100
|
+
else if (data === 'c' && status.url)
|
|
101
|
+
void this.options.copy(status.url).then(() => this.options.notify('Remote-control link copied'), (error) => this.options.notify(error instanceof Error ? error.message : String(error), 'error'));
|
|
102
|
+
else if (data === 'n')
|
|
103
|
+
void this.act('terminal.remoteControl.rotate', {}, 'New link. Paired devices were disconnected.');
|
|
104
|
+
else if (data === 't' && status.kinds.length > 1)
|
|
105
|
+
void this.act('terminal.remoteControl.start', { interface: status.kind === 'tailscale' ? 'lan' : 'tailscale' });
|
|
106
|
+
else if (data === 'x')
|
|
107
|
+
void this.act('terminal.remoteControl.stop', {}, 'Remote control stopped.');
|
|
108
|
+
else
|
|
109
|
+
return false;
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
render(width, rows) {
|
|
113
|
+
const theme = this.options.theme();
|
|
114
|
+
const status = this.status;
|
|
115
|
+
const lines = [];
|
|
116
|
+
const wrap = (text, color = 'text') => {
|
|
117
|
+
for (const line of wrapTextWithAnsi(text, Math.max(1, width)))
|
|
118
|
+
lines.push(theme.fg(color, line));
|
|
119
|
+
};
|
|
120
|
+
if (this.error) {
|
|
121
|
+
wrap(this.error, 'error');
|
|
122
|
+
lines.push('');
|
|
123
|
+
}
|
|
124
|
+
if (!status) {
|
|
125
|
+
wrap('Starting remote control…', 'dim');
|
|
126
|
+
return lines.slice(0, rows);
|
|
127
|
+
}
|
|
128
|
+
if (status.request) {
|
|
129
|
+
wrap(`${safeText(status.request.label)} wants to control this session.`, 'warning');
|
|
130
|
+
wrap('It will be able to send messages, stop replies, and answer approvals and questions. Press a to allow or d to deny.', 'text');
|
|
131
|
+
lines.push('');
|
|
132
|
+
}
|
|
133
|
+
if (!status.running) {
|
|
134
|
+
wrap('Remote control is off.', 'dim');
|
|
135
|
+
wrap('Press s to start it, then scan the QR code with your phone or iPad.', 'dim');
|
|
136
|
+
return lines.slice(0, rows);
|
|
137
|
+
}
|
|
138
|
+
const kind = status.kind ? KIND_LABEL[status.kind] : '';
|
|
139
|
+
lines.push(theme.fg('success', '● ') + theme.bold(`Remote control is on${kind ? ` · ${kind}` : ''}`));
|
|
140
|
+
wrap(status.kind === 'tailscale'
|
|
141
|
+
? 'Scan with a phone or iPad signed in to the same Tailscale network, or open this link on it:'
|
|
142
|
+
: 'Scan with a phone or iPad on the same Wi-Fi, or open this link on it:', 'dim');
|
|
143
|
+
if (status.url)
|
|
144
|
+
wrap(status.url, 'accent');
|
|
145
|
+
if (status.warning)
|
|
146
|
+
wrap(safeText(status.warning), 'warning');
|
|
147
|
+
if (status.kind === 'lan')
|
|
148
|
+
wrap('On a network you do not trust, use Tailscale instead: anyone there can see that this computer is listening.', 'dim');
|
|
149
|
+
const devices = status.devices.length
|
|
150
|
+
? status.devices.map((device) => `${device.connected ? theme.fg('success', '●') : theme.fg('dim', '○')} ${safeText(device.label)}${device.connected ? '' : theme.fg('dim', ' (paired, not connected)')}`)
|
|
151
|
+
: [theme.fg('dim', 'No device paired yet.')];
|
|
152
|
+
const footer = ['', ...devices];
|
|
153
|
+
if (this.showQr && status.url) {
|
|
154
|
+
const qr = qrLines(status.url);
|
|
155
|
+
const room = rows - lines.length - footer.length - 1;
|
|
156
|
+
const qrWidth = visibleWidth(qr[0] ?? '');
|
|
157
|
+
if (qr.length <= room && qrWidth <= width) {
|
|
158
|
+
lines.push('');
|
|
159
|
+
const pad = ' '.repeat(Math.max(0, Math.floor((width - qrWidth) / 2)));
|
|
160
|
+
for (const line of qr)
|
|
161
|
+
lines.push(pad + line);
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
lines.push('', theme.fg('dim', 'Make the terminal larger to show the QR code, or press c to copy the link.'));
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
lines.push(...footer);
|
|
168
|
+
return lines.slice(0, rows).map((line) => truncateToWidth(line, width, ''));
|
|
169
|
+
}
|
|
170
|
+
}
|