peer-bridge 0.0.0-stage → 0.7.0

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 (55) hide show
  1. package/LICENSE +21 -0
  2. package/README.ko.md +202 -0
  3. package/README.md +242 -2
  4. package/adapters/antigravity/bin/agy-hook.mjs +24 -0
  5. package/adapters/antigravity/hooks.json +23 -0
  6. package/adapters/antigravity/mcp_config.json +8 -0
  7. package/adapters/antigravity/plugin.json +4 -0
  8. package/adapters/antigravity/rules/AGENTS.md +6 -0
  9. package/adapters/antigravity/skills/peer-bridge/SKILL.md +19 -0
  10. package/adapters/claude/.claude-plugin/plugin.json +5 -0
  11. package/adapters/claude/.mcp.json +8 -0
  12. package/adapters/claude/bin/cc-hook.mjs +20 -0
  13. package/adapters/claude/hooks/hooks.json +46 -0
  14. package/adapters/claude/skills/peer-bridge/SKILL.md +19 -0
  15. package/adapters/codex/bin/codex-hook.mjs +10 -0
  16. package/adapters/codex/config.toml.example +5 -0
  17. package/adapters/codex/hooks.json +44 -0
  18. package/adapters/codex/skills/peer-bridge/SKILL.md +12 -0
  19. package/adapters/gemini/bin/gemini-hook.mjs +10 -0
  20. package/adapters/gemini/settings.json +51 -0
  21. package/adapters/gemini/skills/peer-bridge/SKILL.md +12 -0
  22. package/adapters/paseo/SKILL.md +24 -0
  23. package/bin/pbridge-mcp.mjs +37 -0
  24. package/bin/pbridge-tui.mjs +7 -0
  25. package/bin/pbridge.mjs +5 -0
  26. package/bin/pbridged.mjs +16 -0
  27. package/package.json +57 -4
  28. package/scripts/postinstall.mjs +25 -0
  29. package/scripts/preuninstall.mjs +20 -0
  30. package/skills/peer-bridge/SKILL.md +70 -0
  31. package/src/adapters/antigravity/hooks.mjs +207 -0
  32. package/src/adapters/claude/hooks.mjs +204 -0
  33. package/src/adapters/codex/hooks.mjs +142 -0
  34. package/src/adapters/gemini/hooks.mjs +159 -0
  35. package/src/adapters/installer.mjs +328 -0
  36. package/src/cli/main.mjs +785 -0
  37. package/src/client/rpc.mjs +243 -0
  38. package/src/config.mjs +154 -0
  39. package/src/daemon/broker.mjs +1799 -0
  40. package/src/daemon/resolver.mjs +200 -0
  41. package/src/daemon/server.mjs +221 -0
  42. package/src/index.mjs +60 -0
  43. package/src/mcp/server.mjs +668 -0
  44. package/src/orchestrator/workflows.mjs +496 -0
  45. package/src/project.mjs +81 -0
  46. package/src/protocol.mjs +203 -0
  47. package/src/runtime/conv-api.mjs +101 -0
  48. package/src/runtime/host-discovery.mjs +635 -0
  49. package/src/runtime/native-claude.mjs +88 -0
  50. package/src/runtime/paseo.mjs +289 -0
  51. package/src/runtime/workers.mjs +751 -0
  52. package/src/skills.mjs +115 -0
  53. package/src/storage/db.mjs +704 -0
  54. package/src/tui/render.mjs +472 -0
  55. package/src/tui/viewer.mjs +443 -0
@@ -0,0 +1,472 @@
1
+ import os from 'node:os';
2
+ import path from 'node:path';
3
+ import { getProjectLabel, isSameProjectScope } from '../project.mjs';
4
+
5
+ const ANSI_RE = /\x1b\[[0-9;?]*[ -/]*[@-~]/g;
6
+ const GRAPHEME_SEG = new Intl.Segmenter(undefined, { granularity: 'grapheme' });
7
+
8
+ export function stripAnsi(str) {
9
+ return String(str ?? '').replace(ANSI_RE, '');
10
+ }
11
+
12
+ function isZeroWidthCodePoint(cp) {
13
+ return (
14
+ cp === 0 ||
15
+ cp < 0x20 ||
16
+ (cp >= 0x7f && cp < 0xa0) ||
17
+ (cp >= 0x0300 && cp <= 0x036f) ||
18
+ (cp >= 0x1ab0 && cp <= 0x1aff) ||
19
+ (cp >= 0x1dc0 && cp <= 0x1dff) ||
20
+ (cp >= 0x200b && cp <= 0x200f) ||
21
+ (cp >= 0x202a && cp <= 0x202e) ||
22
+ (cp >= 0x2060 && cp <= 0x206f) ||
23
+ (cp >= 0xfe00 && cp <= 0xfe0f) ||
24
+ cp === 0xfeff
25
+ );
26
+ }
27
+
28
+ function isWideCodePoint(cp) {
29
+ return (
30
+ (cp >= 0x1100 && cp <= 0x115f) ||
31
+ cp === 0x2329 ||
32
+ cp === 0x232a ||
33
+ (cp >= 0x2e80 && cp <= 0x303e) ||
34
+ (cp >= 0x3041 && cp <= 0x33ff) ||
35
+ (cp >= 0x3400 && cp <= 0x4dbf) ||
36
+ (cp >= 0x4e00 && cp <= 0xa4cf) ||
37
+ (cp >= 0xa960 && cp <= 0xa97c) ||
38
+ (cp >= 0xac00 && cp <= 0xd7a3) ||
39
+ (cp >= 0xf900 && cp <= 0xfaff) ||
40
+ (cp >= 0xfe10 && cp <= 0xfe19) ||
41
+ (cp >= 0xfe30 && cp <= 0xfe6f) ||
42
+ (cp >= 0xff01 && cp <= 0xff60) ||
43
+ (cp >= 0xffe0 && cp <= 0xffe6) ||
44
+ (cp >= 0x1f300 && cp <= 0x1faff) ||
45
+ (cp >= 0x20000 && cp <= 0x3fffd)
46
+ );
47
+ }
48
+
49
+ export function charWidth(grapheme) {
50
+ if (!grapheme) return 0;
51
+ let w = 0;
52
+ for (const ch of grapheme) {
53
+ const cp = ch.codePointAt(0);
54
+ if (cp === undefined || isZeroWidthCodePoint(cp)) continue;
55
+ w = Math.max(w, isWideCodePoint(cp) ? 2 : 1);
56
+ }
57
+ return w;
58
+ }
59
+
60
+ export function visualWidth(str) {
61
+ const plain = stripAnsi(str);
62
+ let total = 0;
63
+ for (const { segment } of GRAPHEME_SEG.segment(plain)) {
64
+ total += charWidth(segment);
65
+ }
66
+ return total;
67
+ }
68
+
69
+ export function truncateVisual(str, maxWidth, ellipsis = '...') {
70
+ const plain = String(str ?? '').replace(/\s+/g, ' ');
71
+ if (maxWidth <= 0) return '';
72
+ if (visualWidth(plain) <= maxWidth) return plain;
73
+
74
+ const ellW = visualWidth(ellipsis);
75
+ if (maxWidth <= ellW) {
76
+ let out = '';
77
+ let w = 0;
78
+ for (const { segment } of GRAPHEME_SEG.segment(plain)) {
79
+ const cw = charWidth(segment);
80
+ if (w + cw > maxWidth) break;
81
+ out += segment;
82
+ w += cw;
83
+ }
84
+ return out;
85
+ }
86
+
87
+ const limit = maxWidth - ellW;
88
+ let out = '';
89
+ let w = 0;
90
+ for (const { segment } of GRAPHEME_SEG.segment(plain)) {
91
+ const cw = charWidth(segment);
92
+ if (w + cw > limit) break;
93
+ out += segment;
94
+ w += cw;
95
+ }
96
+ return `${out.trimEnd()}${ellipsis}`;
97
+ }
98
+
99
+ export function padEndVisual(str, targetWidth) {
100
+ const w = visualWidth(str);
101
+ if (w >= targetWidth) return str;
102
+ return `${str}${' '.repeat(targetWidth - w)}`;
103
+ }
104
+
105
+ export function padStartVisual(str, targetWidth) {
106
+ const w = visualWidth(str);
107
+ if (w >= targetWidth) return str;
108
+ return `${' '.repeat(targetWidth - w)}${str}`;
109
+ }
110
+
111
+ export function formatRelativeAge(updatedMs, nowMs = Date.now()) {
112
+ const diffSec = Math.max(0, Math.floor((nowMs - (Number(updatedMs) || nowMs)) / 1000));
113
+ if (diffSec < 60) return `${diffSec}s`;
114
+ const diffMin = Math.floor(diffSec / 60);
115
+ if (diffMin < 60) return `${diffMin}m`;
116
+ const diffHr = Math.floor(diffMin / 60);
117
+ if (diffHr < 24) return `${diffHr}h`;
118
+ const diffDay = Math.floor(diffHr / 24);
119
+ return `${diffDay}d`;
120
+ }
121
+
122
+ export function shortenHomePath(cwd, homeDir = os.homedir()) {
123
+ if (!cwd) return '~';
124
+ const resolved = path.resolve(cwd);
125
+ const home = path.resolve(homeDir);
126
+ if (resolved === home) return '~';
127
+ if (resolved.startsWith(`${home}${path.sep}`)) {
128
+ return `~${resolved.slice(home.length)}`;
129
+ }
130
+ return resolved;
131
+ }
132
+
133
+ const STATE_RANK = {
134
+ needs_input: 0,
135
+ working: 1,
136
+ error: 2,
137
+ done: 3,
138
+ stopped: 4,
139
+ };
140
+
141
+ export function groupPeersForView(peers = [], { homeDir = os.homedir(), priorityCwd = null } = {}) {
142
+ const byCwd = new Map();
143
+ for (const peer of peers) {
144
+ const label = shortenHomePath(peer.cwd, homeDir);
145
+ let group = byCwd.get(label);
146
+ if (!group) {
147
+ group = {
148
+ label,
149
+ sampleCwd: peer.cwd || null,
150
+ isPriority: Boolean(priorityCwd && peer.cwd && isSameProjectScope(peer.cwd, priorityCwd)),
151
+ peers: [],
152
+ maxUpdated: 0,
153
+ hasActive: false,
154
+ };
155
+ byCwd.set(label, group);
156
+ }
157
+ group.peers.push(peer);
158
+ if (!group.isPriority && priorityCwd && peer.cwd && isSameProjectScope(peer.cwd, priorityCwd)) {
159
+ group.isPriority = true;
160
+ }
161
+ if ((peer.updated_ms || 0) > group.maxUpdated) {
162
+ group.maxUpdated = peer.updated_ms || 0;
163
+ }
164
+ if (peer.display_state !== 'stopped') {
165
+ group.hasActive = true;
166
+ }
167
+ }
168
+
169
+ const groups = [...byCwd.values()].sort((a, b) => {
170
+ if (a.isPriority !== b.isPriority) return a.isPriority ? -1 : 1;
171
+ if (a.hasActive !== b.hasActive) return a.hasActive ? -1 : 1;
172
+ if (b.maxUpdated !== a.maxUpdated) return b.maxUpdated - a.maxUpdated;
173
+ return a.label.localeCompare(b.label);
174
+ });
175
+
176
+ const flatRows = [];
177
+ for (const g of groups) {
178
+ g.peers.sort((a, b) => {
179
+ const ra = STATE_RANK[a.display_state] ?? 9;
180
+ const rb = STATE_RANK[b.display_state] ?? 9;
181
+ if (ra !== rb) return ra - rb;
182
+ if ((b.updated_ms || 0) !== (a.updated_ms || 0)) {
183
+ return (b.updated_ms || 0) - (a.updated_ms || 0);
184
+ }
185
+ return String(a.name || '').localeCompare(String(b.name || ''));
186
+ });
187
+ for (const peer of g.peers) {
188
+ flatRows.push(peer);
189
+ }
190
+ }
191
+
192
+ return { groups, flatRows };
193
+ }
194
+
195
+ function makeStyle(color) {
196
+ const wrap = (code) => (txt) => (color ? `\x1b[${code}m${txt}\x1b[0m` : txt);
197
+ return {
198
+ bold: wrap('1'),
199
+ dim: wrap('2'),
200
+ green: wrap('32'),
201
+ yellow: wrap('33'),
202
+ blue: wrap('34'),
203
+ magenta: wrap('35'),
204
+ cyan: wrap('36'),
205
+ white: wrap('97'),
206
+ gray: wrap('90'),
207
+ red: wrap('31'),
208
+ bgSelected: (txt) => {
209
+ if (!color) return txt;
210
+ // Re-apply selection background after any inner ANSI reset so highlight spans the entire row
211
+ return `\x1b[48;5;238m${String(txt).replace(/\x1b\[0m/g, '\x1b[0m\x1b[48;5;238m')}\x1b[0m`;
212
+ },
213
+ };
214
+ }
215
+
216
+ function formatBadge(peer, S) {
217
+ const raw = peer.origin === 'spawned' ? `[${peer.runtime}+]` : `[${peer.runtime}]`;
218
+ const padded = padEndVisual(raw, 9);
219
+ switch (peer.runtime) {
220
+ case 'cc':
221
+ return S.yellow(padded);
222
+ case 'agy':
223
+ return S.cyan(padded);
224
+ case 'codex':
225
+ return S.green(padded);
226
+ case 'gemini':
227
+ return S.blue(padded);
228
+ case 'paseo':
229
+ return S.magenta(padded);
230
+ default:
231
+ return S.gray(padded);
232
+ }
233
+ }
234
+
235
+ function formatGlyphAndState(peer, S) {
236
+ switch (peer.display_state) {
237
+ case 'working':
238
+ return {
239
+ glyph: S.white('*'),
240
+ label: S.bold(S.white(padEndVisual('Working', 11))),
241
+ };
242
+ case 'needs_input':
243
+ return {
244
+ glyph: S.yellow('*'),
245
+ label: S.bold(S.yellow(padEndVisual('Needs input', 11))),
246
+ };
247
+ case 'error':
248
+ return {
249
+ glyph: S.bold(S.red('!')),
250
+ label: S.bold(S.red(padEndVisual('Error', 11))),
251
+ };
252
+ case 'done':
253
+ return {
254
+ glyph: S.green('•'),
255
+ label: S.green(padEndVisual('Done', 11)),
256
+ };
257
+ default:
258
+ return {
259
+ glyph: S.gray('•'),
260
+ label: S.gray(padEndVisual('Stopped', 11)),
261
+ };
262
+ }
263
+ }
264
+
265
+ export function renderFrame(
266
+ state = {},
267
+ {
268
+ width = 100,
269
+ height = 30,
270
+ color = true,
271
+ compact = false,
272
+ nowMs = Date.now(),
273
+ homeDir = os.homedir(),
274
+ version = '0.7.0',
275
+ } = {},
276
+ ) {
277
+ const cols = Math.max(56, Number(width) || 100);
278
+ const rows = Math.max(10, Number(height) || 30);
279
+ const S = makeStyle(color);
280
+
281
+ const peers = Array.isArray(state.peers) ? state.peers : [];
282
+ const counts = state.counts || {
283
+ needs_input: 0,
284
+ working: 0,
285
+ done: 0,
286
+ error: 0,
287
+ stopped: 0,
288
+ spawned: 0,
289
+ total: peers.length,
290
+ };
291
+ const runtimeFilter = state.runtimeFilter || 'all';
292
+ const hideStopped = Boolean(state.hideStopped);
293
+ const activeWorkflows = Number(state.activeWorkflows || 0);
294
+ const daemonOnline = Boolean(state.daemon);
295
+ const scopeMode = state.scopeMode === 'project' && state.projectCwd ? 'project' : 'all';
296
+ const projectLabel = state.projectCwd ? getProjectLabel(state.projectCwd) : null;
297
+
298
+ // Header lines (3 lines)
299
+ const wfLabel = activeWorkflows === 1 ? '1 workflow' : `${activeWorkflows} workflows`;
300
+ const titleLeft = `${S.bold(S.white(`peer-bridge v${version}`))} ${
301
+ daemonOnline ? S.green('daemon online') : S.gray('host-only mode')
302
+ }${activeWorkflows > 0 ? S.cyan(` · ${wfLabel}`) : ''}`;
303
+ const scopeTag =
304
+ scopeMode === 'project' && projectLabel
305
+ ? `project: ${truncateVisual(projectLabel, cols >= 84 ? 22 : 12)}`
306
+ : cols >= 72
307
+ ? 'all projects'
308
+ : 'all';
309
+ const filterTags = `[${scopeTag} · ${runtimeFilter}${hideStopped ? ' · active' : ''}]`;
310
+ const titleGap = Math.max(1, cols - visualWidth(titleLeft) - visualWidth(filterTags));
311
+ const header1 = `${titleLeft}${' '.repeat(titleGap)}${S.dim(filterTags)}`;
312
+
313
+ const countParts = [
314
+ counts.needs_input > 0
315
+ ? S.yellow(`${counts.needs_input} awaiting input`)
316
+ : S.dim(`${counts.needs_input} awaiting input`),
317
+ counts.working > 0 ? S.white(`${counts.working} working`) : S.dim(`${counts.working} working`),
318
+ S.dim(`${counts.done} completed`),
319
+ ];
320
+ if (counts.error > 0) {
321
+ countParts.push(S.bold(S.red(`${counts.error} error`)));
322
+ }
323
+ countParts.push(S.dim(`${counts.stopped} stopped`));
324
+ if (counts.spawned > 0) {
325
+ countParts.push(S.cyan(`${counts.spawned} spawned`));
326
+ }
327
+ const header2 = countParts.join(S.dim(' · '));
328
+
329
+ const { groups, flatRows } = groupPeersForView(peers, {
330
+ homeDir,
331
+ priorityCwd: scopeMode === 'all' ? state.projectCwd || null : null,
332
+ });
333
+ const selectedIndex =
334
+ flatRows.length === 0
335
+ ? -1
336
+ : Math.max(0, Math.min(Number(state.selectedIndex ?? 0), flatRows.length - 1));
337
+
338
+ // Build display lines (group headers + peer rows)
339
+ const displayItems = [];
340
+ let peerIdx = 0;
341
+ for (let gIdx = 0; gIdx < groups.length; gIdx++) {
342
+ const group = groups[gIdx];
343
+ if (gIdx > 0) {
344
+ displayItems.push({ kind: 'blank', text: '' });
345
+ }
346
+ displayItems.push({
347
+ kind: 'group',
348
+ text: S.dim(truncateVisual(group.label, cols)),
349
+ });
350
+
351
+ const nameColWidth = cols >= 96 ? 18 : 14;
352
+ for (const peer of group.peers) {
353
+ const idx = peerIdx++;
354
+ const isSelected = idx === selectedIndex;
355
+ const cursor = isSelected ? S.bold(S.white('>')) : ' ';
356
+ const { glyph, label: stateLabel } = formatGlyphAndState(peer, S);
357
+ const badge = formatBadge(peer, S);
358
+ const nameStr = padEndVisual(truncateVisual(peer.name || 'peer', nameColWidth), nameColWidth);
359
+ const styledName =
360
+ peer.display_state === 'stopped' ? S.gray(nameStr) : isSelected ? S.bold(S.white(nameStr)) : nameStr;
361
+ const ageStr = padStartVisual(formatRelativeAge(peer.updated_ms, nowMs), 4);
362
+ const styledAge = S.dim(ageStr);
363
+
364
+ // Layout: "<c> <g> <badge(9)> <name(nameColWidth)> <state(11)> · <summary> <age(4)>"
365
+ // Fixed visual width: 1+1+1+1+9+1+nameColWidth+1+11+3 + 1+4 = 34 + nameColWidth
366
+ const prefixPlainWidth = 1 + 1 + 1 + 1 + 9 + 1 + nameColWidth + 1 + 11 + 3;
367
+ const suffixPlainWidth = 1 + 4;
368
+ const availSummary = Math.max(4, cols - prefixPlainWidth - suffixPlainWidth);
369
+ const rawSummary = peer.summary || (peer.display_state === 'stopped' ? 'stopped' : '');
370
+ const sepChar = rawSummary ? S.dim('·') : ' ';
371
+ const summaryClipped = padEndVisual(truncateVisual(rawSummary, availSummary), availSummary);
372
+ const styledSummary =
373
+ peer.display_state === 'error'
374
+ ? S.red(summaryClipped)
375
+ : peer.display_state === 'stopped'
376
+ ? S.gray(summaryClipped)
377
+ : isSelected
378
+ ? S.white(summaryClipped)
379
+ : S.dim(summaryClipped);
380
+
381
+ const rowBody = `${cursor} ${glyph} ${badge} ${styledName} ${stateLabel} ${sepChar} ${styledSummary} ${styledAge}`;
382
+ displayItems.push({
383
+ kind: 'peer',
384
+ peerIndex: idx,
385
+ text: isSelected ? S.bgSelected(rowBody) : rowBody,
386
+ });
387
+ }
388
+ }
389
+
390
+ // Footer takes 2 lines (status/confirm + keybind hints)
391
+ const footerLines = [];
392
+ if (state.confirmClosePeer) {
393
+ const p = state.confirmClosePeer;
394
+ const msg = `Stop spawned peer ${p.handle}? [y/Enter] Confirm [n/Esc] Cancel`;
395
+ footerLines.push(S.bold(S.yellow(truncateVisual(msg, cols))));
396
+ } else if (state.statusMessage?.text) {
397
+ const lvl = state.statusMessage.level || 'info';
398
+ const txt = truncateVisual(state.statusMessage.text, cols);
399
+ footerLines.push(
400
+ lvl === 'warn' ? S.yellow(txt) : lvl === 'error' ? S.red(txt) : S.green(txt),
401
+ );
402
+ } else {
403
+ footerLines.push('');
404
+ }
405
+ const keyHints =
406
+ '[↑/↓,j/k] Navigate [x] Stop spawned [p] Project/All [f] Runtime [a] Active [r] Refresh [q] Quit';
407
+ footerLines.push(S.dim(truncateVisual(keyHints, cols)));
408
+
409
+ // Viewport slicing
410
+ const headerLines = [header1, header2, ''];
411
+ const bodyBudget = Math.max(1, rows - headerLines.length - footerLines.length);
412
+
413
+ const emptyMessage =
414
+ scopeMode === 'project' && projectLabel
415
+ ? ` No peers in project "${projectLabel}". (Press [p] or pass --all to view all projects)`
416
+ : ' No peers to display. (p: project/all · f: runtime · a: toggle stopped)';
417
+
418
+ let bodyLines = [];
419
+ if (displayItems.length === 0) {
420
+ bodyLines = [S.dim(truncateVisual(emptyMessage, cols))];
421
+ } else {
422
+ const selectedLineIdx = displayItems.findIndex(
423
+ (it) => it.kind === 'peer' && it.peerIndex === selectedIndex,
424
+ );
425
+ let scrollOffset = Math.max(0, Number(state.scrollOffset ?? 0));
426
+ if (selectedLineIdx >= 0) {
427
+ // Keep group header visible when first item in group is selected
428
+ const desiredTop =
429
+ selectedLineIdx > 0 && displayItems[selectedLineIdx - 1]?.kind === 'group'
430
+ ? selectedLineIdx - 1
431
+ : selectedLineIdx;
432
+ if (desiredTop < scrollOffset) {
433
+ scrollOffset = desiredTop;
434
+ } else if (selectedLineIdx >= scrollOffset + bodyBudget) {
435
+ scrollOffset = selectedLineIdx - bodyBudget + 1;
436
+ }
437
+ }
438
+ const maxScroll = Math.max(0, displayItems.length - bodyBudget);
439
+ scrollOffset = Math.min(scrollOffset, maxScroll);
440
+
441
+ bodyLines = displayItems.slice(scrollOffset, scrollOffset + bodyBudget).map((it) => it.text);
442
+ const hiddenAbove = scrollOffset;
443
+ const hiddenBelow = Math.max(0, displayItems.length - (scrollOffset + bodyBudget));
444
+ if (hiddenAbove > 0 && bodyLines.length > 0) {
445
+ bodyLines[0] = S.dim(`↑ ${hiddenAbove} more`);
446
+ }
447
+ if (hiddenBelow > 0 && bodyLines.length > 1) {
448
+ bodyLines[bodyLines.length - 1] = S.dim(`↓ ${hiddenBelow} more`);
449
+ }
450
+ }
451
+
452
+ if (compact) {
453
+ const body = displayItems.length
454
+ ? displayItems.map((it) => it.text)
455
+ : [S.dim(truncateVisual(emptyMessage, cols))];
456
+ return {
457
+ lines: [...headerLines, ...body, '', footerLines[footerLines.length - 1]],
458
+ flatRows,
459
+ selectedIndex,
460
+ };
461
+ }
462
+
463
+ while (bodyLines.length < bodyBudget) {
464
+ bodyLines.push('');
465
+ }
466
+
467
+ return {
468
+ lines: [...headerLines, ...bodyLines, ...footerLines],
469
+ flatRows,
470
+ selectedIndex,
471
+ };
472
+ }