@aragon-agent/cli 0.6.31 → 0.6.33
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 +119 -0
- package/README.md +2970 -2826
- package/dist/agent/controller.d.ts +46 -0
- package/dist/agent/controller.js +175 -7
- package/dist/agent/job-notices.d.ts +143 -0
- package/dist/agent/job-notices.js +182 -0
- package/dist/agent/reducer.d.ts +21 -1
- package/dist/agent/reducer.js +7 -0
- package/dist/agent/system-prompt.d.ts +12 -0
- package/dist/agent/system-prompt.js +2 -0
- package/dist/cli.js +236 -8
- package/dist/commands/builtins.js +23 -8
- package/dist/commands/perf.d.ts +77 -1
- package/dist/commands/perf.js +37 -5
- package/dist/config/cli-commands.d.ts +27 -0
- package/dist/config/cli-commands.js +54 -1
- package/dist/config/env.js +38 -0
- package/dist/config/load.js +50 -1
- package/dist/config/schema.d.ts +73 -0
- package/dist/config/schema.js +34 -0
- package/dist/config/store.js +14 -1
- package/dist/exec/events.d.ts +29 -3
- package/dist/exec/events.js +3 -12
- package/dist/exec/runner.d.ts +24 -0
- package/dist/exec/runner.js +79 -0
- package/dist/input/cursor-report.d.ts +61 -0
- package/dist/input/cursor-report.js +97 -0
- package/dist/input/stdin-filter.d.ts +22 -0
- package/dist/input/stdin-filter.js +48 -3
- package/dist/proc/limits.d.ts +76 -2
- package/dist/proc/limits.js +83 -2
- package/dist/proc/log-mirror.d.ts +59 -0
- package/dist/proc/log-mirror.js +203 -0
- package/dist/proc/log-ring.d.ts +22 -0
- package/dist/proc/log-ring.js +20 -1
- package/dist/proc/notices.d.ts +57 -0
- package/dist/proc/notices.js +101 -0
- package/dist/proc/progress.d.ts +40 -0
- package/dist/proc/progress.js +135 -0
- package/dist/proc/prompt.d.ts +24 -2
- package/dist/proc/prompt.js +51 -2
- package/dist/proc/supervisor.d.ts +35 -2
- package/dist/proc/supervisor.js +142 -43
- package/dist/proc/types.d.ts +89 -1
- package/dist/proc/wait.d.ts +57 -0
- package/dist/proc/wait.js +133 -0
- package/dist/session/persist.js +3 -1
- package/dist/session/validate-session.js +17 -0
- package/dist/tools/bash-tool.d.ts +12 -1
- package/dist/tools/bash-tool.js +100 -13
- package/dist/tools/index.d.ts +26 -2
- package/dist/tools/index.js +43 -2
- package/dist/tools/job-tools.d.ts +54 -0
- package/dist/tools/job-tools.js +329 -0
- package/dist/tools/proc-tools.d.ts +1 -1
- package/dist/tools/proc-tools.js +49 -17
- package/dist/ui/ActivityLine.js +7 -0
- package/dist/ui/App.js +98 -12
- package/dist/ui/ScrollbackShell.d.ts +62 -11
- package/dist/ui/ScrollbackShell.js +11 -3
- package/dist/ui/StatusBar.d.ts +5 -0
- package/dist/ui/StatusBar.js +1 -0
- package/dist/ui/Transcript.d.ts +14 -0
- package/dist/ui/Transcript.js +14 -2
- package/dist/ui/entries/ServiceCard.d.ts +17 -1
- package/dist/ui/entries/ServiceCard.js +39 -4
- package/dist/ui/layout/status-layout.d.ts +13 -1
- package/dist/ui/layout/status-layout.js +10 -0
- package/dist/ui/layout/virtual-window.js +14 -1
- package/dist/ui/run-status-row.d.ts +12 -0
- package/dist/ui/screen.d.ts +17 -4
- package/dist/ui/screen.js +14 -6
- package/dist/ui/scrollback/LiveTail.d.ts +79 -0
- package/dist/ui/scrollback/LiveTail.js +32 -0
- package/dist/ui/scrollback/band.d.ts +114 -0
- package/dist/ui/scrollback/band.js +130 -0
- package/dist/ui/scrollback/budget.d.ts +51 -10
- package/dist/ui/scrollback/budget.js +69 -20
- package/dist/ui/scrollback/canvas.d.ts +99 -0
- package/dist/ui/scrollback/canvas.js +113 -0
- package/dist/ui/scrollback/cursor-probe.d.ts +71 -0
- package/dist/ui/scrollback/cursor-probe.js +133 -0
- package/dist/ui/scrollback/limits.d.ts +61 -4
- package/dist/ui/scrollback/limits.js +61 -4
- package/dist/ui/scrollback/live-preview.d.ts +18 -10
- package/dist/ui/scrollback/live-preview.js +14 -11
- package/dist/ui/scrollback/scrollback-writer.d.ts +104 -16
- package/dist/ui/scrollback/scrollback-writer.js +368 -82
- package/dist/ui/scrollback/tail-window.d.ts +60 -0
- package/dist/ui/scrollback/tail-window.js +73 -0
- package/dist/ui/scrollback/use-scrollback-view.d.ts +34 -15
- package/dist/ui/scrollback/use-scrollback-view.js +110 -59
- package/dist/ui/scrollback/writer-shapes.d.ts +68 -2
- package/dist/ui/scrollback/writer-shapes.js +53 -8
- package/package.json +3 -3
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canvas arithmetic for native-scroll mode (tui-canvas-bottom-anchor §5.3).
|
|
3
|
+
*
|
|
4
|
+
* The defect this exists for: the bottom anchor of
|
|
5
|
+
* `tui-bottom-anchored-live-region` pinned the live region to the last two rows by
|
|
6
|
+
* prepending `pad` blank rows to the region's own block, so the blank space of a
|
|
7
|
+
* conversation that does not fill the screen sat BETWEEN the newest printed row and
|
|
8
|
+
* the composer. The user sees a reply that is not attached to the input box.
|
|
9
|
+
*
|
|
10
|
+
* The fix is a position change, not a value change: every row above the parked row
|
|
11
|
+
* becomes a CANVAS the writer owns, laid out top-down as `[gap][content][region]`.
|
|
12
|
+
* The blank space therefore lives ABOVE every visible content row, and the newest
|
|
13
|
+
* content row always touches the top row of the live region. The steady state is
|
|
14
|
+
* unchanged: `gap` equals the old `pad` row for row (the screen holds the same
|
|
15
|
+
* number of content rows either way).
|
|
16
|
+
*
|
|
17
|
+
* EVERYTHING HERE IS PURE: no I/O, no terminal, no clock, no `node:*` import. The
|
|
18
|
+
* writer's state machine decides which measurement is authoritative; this module
|
|
19
|
+
* only does the arithmetic, so the arithmetic can be property-tested over every
|
|
20
|
+
* combination instead of being sampled through a screen.
|
|
21
|
+
*/
|
|
22
|
+
/**
|
|
23
|
+
* How far the canvas may reach and how tall it may be, as far as anything measured.
|
|
24
|
+
*
|
|
25
|
+
* `pinned` carries BOTH numbers because they are not independent: the writer parks
|
|
26
|
+
* the cursor on the last row, so `top + capacity === rows - 1` at all times
|
|
27
|
+
* (invariant LB-3). Storing one and deriving the other is what makes an off-by-one
|
|
28
|
+
* invisible until a blank row lands in the scrollback.
|
|
29
|
+
*/
|
|
30
|
+
export type CanvasAnchor = {
|
|
31
|
+
kind: 'unknown';
|
|
32
|
+
} | {
|
|
33
|
+
kind: 'pinned';
|
|
34
|
+
top: number;
|
|
35
|
+
capacity: number;
|
|
36
|
+
};
|
|
37
|
+
/** Nothing measured yet: the pre-canvas append path, byte for byte (I-A3 / I-A8). */
|
|
38
|
+
export declare const UNKNOWN_CANVAS: CanvasAnchor;
|
|
39
|
+
/** Where a `pinned` anchor came from; `/perf` reports it so a fallback is visible. */
|
|
40
|
+
export type AnchorSource = 'probe' | 'fill' | 'none';
|
|
41
|
+
export interface CanvasLayoutInput {
|
|
42
|
+
/** Rows the canvas may occupy, as measured (`rows - top`). */
|
|
43
|
+
capacity: number;
|
|
44
|
+
/** Canvas top row (0-based). */
|
|
45
|
+
top: number;
|
|
46
|
+
/** Content rows already on screen. */
|
|
47
|
+
heldRows: number;
|
|
48
|
+
/** Content rows arriving in this batch. */
|
|
49
|
+
statRows: number;
|
|
50
|
+
/** Height of the live region in this batch. */
|
|
51
|
+
frameRows: number;
|
|
52
|
+
/** 1 when the batch is a re-seed and starts with its own CRLF, else 0. */
|
|
53
|
+
lead: number;
|
|
54
|
+
}
|
|
55
|
+
/** The whole geometry of one batch, as pure numbers (never strings). */
|
|
56
|
+
export interface CanvasLayout {
|
|
57
|
+
/** Content rows the canvas holds after this batch, i.e. after the trim. */
|
|
58
|
+
heldRows: number;
|
|
59
|
+
/** Blank rows above the content. Skipped with CUD, never written (I-B3). */
|
|
60
|
+
gap: number;
|
|
61
|
+
/** Rows this batch writes past the screen bottom; the terminal scrolls them away. */
|
|
62
|
+
scroll: number;
|
|
63
|
+
/** Content rows dropped from the head because they left the screen for good. */
|
|
64
|
+
dropped: number;
|
|
65
|
+
/** The canvas top after this batch. */
|
|
66
|
+
top: number;
|
|
67
|
+
/** The canvas height after this batch, which is the next erase distance. */
|
|
68
|
+
canvasRows: number;
|
|
69
|
+
}
|
|
70
|
+
/** The capacity above the parked row: `rows - 1`. Degrades to 0, never negative. */
|
|
71
|
+
export declare function screenCapacity(rows: number | undefined): number;
|
|
72
|
+
/**
|
|
73
|
+
* Clamp a measured "rows below the cursor" figure into `[0, rows - 1]`.
|
|
74
|
+
*
|
|
75
|
+
* `rows` unknown is treated as `0`: the caller is then exactly at the bottom, which
|
|
76
|
+
* is the conservative branch (no canvas to open up).
|
|
77
|
+
*/
|
|
78
|
+
export declare function clampSpaceBelow(spaceBelow: number, rows: number | undefined): number;
|
|
79
|
+
/**
|
|
80
|
+
* A terminal that grew adds rows BELOW the cursor, so the capacity grows by the
|
|
81
|
+
* exact difference (D6). Shrinking is NOT handled here: it re-measures instead of
|
|
82
|
+
* guessing (D5), so a smaller value would only hide a lost measurement.
|
|
83
|
+
*/
|
|
84
|
+
export declare function applyResizeGrowth(capacity: number, rowsPrev: number, rowsNow: number): number;
|
|
85
|
+
/**
|
|
86
|
+
* The layout of one batch.
|
|
87
|
+
*
|
|
88
|
+
* `heldRows` / `statRows` / `frameRows` are COUNTS, never strings, so this function
|
|
89
|
+
* can be property-tested over every combination without building a screen.
|
|
90
|
+
*
|
|
91
|
+
* TWO BRANCHES, and the difference is physical rather than cosmetic:
|
|
92
|
+
* - FIT: the content plus the region fits the capacity, so the leftover becomes the
|
|
93
|
+
* `gap` at the TOP of the canvas and nothing scrolls.
|
|
94
|
+
* - SCROLL: the canvas cannot hold everything. The batch writes every content row
|
|
95
|
+
* (the caller passes them untrimmed for exactly this reason), the terminal scrolls
|
|
96
|
+
* `scroll` rows away, and the rows that leave are the oldest content rows plus the
|
|
97
|
+
* host output above the canvas. `dropped` is how many content rows left.
|
|
98
|
+
*/
|
|
99
|
+
export declare function resolveCanvasLayout(input: CanvasLayoutInput): CanvasLayout;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canvas arithmetic for native-scroll mode (tui-canvas-bottom-anchor §5.3).
|
|
3
|
+
*
|
|
4
|
+
* The defect this exists for: the bottom anchor of
|
|
5
|
+
* `tui-bottom-anchored-live-region` pinned the live region to the last two rows by
|
|
6
|
+
* prepending `pad` blank rows to the region's own block, so the blank space of a
|
|
7
|
+
* conversation that does not fill the screen sat BETWEEN the newest printed row and
|
|
8
|
+
* the composer. The user sees a reply that is not attached to the input box.
|
|
9
|
+
*
|
|
10
|
+
* The fix is a position change, not a value change: every row above the parked row
|
|
11
|
+
* becomes a CANVAS the writer owns, laid out top-down as `[gap][content][region]`.
|
|
12
|
+
* The blank space therefore lives ABOVE every visible content row, and the newest
|
|
13
|
+
* content row always touches the top row of the live region. The steady state is
|
|
14
|
+
* unchanged: `gap` equals the old `pad` row for row (the screen holds the same
|
|
15
|
+
* number of content rows either way).
|
|
16
|
+
*
|
|
17
|
+
* EVERYTHING HERE IS PURE: no I/O, no terminal, no clock, no `node:*` import. The
|
|
18
|
+
* writer's state machine decides which measurement is authoritative; this module
|
|
19
|
+
* only does the arithmetic, so the arithmetic can be property-tested over every
|
|
20
|
+
* combination instead of being sampled through a screen.
|
|
21
|
+
*/
|
|
22
|
+
/** Nothing measured yet: the pre-canvas append path, byte for byte (I-A3 / I-A8). */
|
|
23
|
+
export const UNKNOWN_CANVAS = { kind: 'unknown' };
|
|
24
|
+
/**
|
|
25
|
+
* `Math.floor` with the two answers a measurement must never produce collapsed onto
|
|
26
|
+
* `fallback`: `NaN` and `Infinity`. A `NaN` row count would make `Array(n)` throw and
|
|
27
|
+
* would turn `rows - 1 - n` into a lie, so a broken number degrades to "nothing".
|
|
28
|
+
*/
|
|
29
|
+
function whole(value, fallback) {
|
|
30
|
+
return Number.isFinite(value) ? Math.floor(value) : fallback;
|
|
31
|
+
}
|
|
32
|
+
/** The capacity above the parked row: `rows - 1`. Degrades to 0, never negative. */
|
|
33
|
+
export function screenCapacity(rows) {
|
|
34
|
+
if (rows === undefined || !Number.isFinite(rows))
|
|
35
|
+
return 0;
|
|
36
|
+
return Math.max(0, Math.floor(rows) - 1);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Clamp a measured "rows below the cursor" figure into `[0, rows - 1]`.
|
|
40
|
+
*
|
|
41
|
+
* `rows` unknown is treated as `0`: the caller is then exactly at the bottom, which
|
|
42
|
+
* is the conservative branch (no canvas to open up).
|
|
43
|
+
*/
|
|
44
|
+
export function clampSpaceBelow(spaceBelow, rows) {
|
|
45
|
+
const upper = screenCapacity(rows);
|
|
46
|
+
const value = Number.isFinite(spaceBelow) ? Math.floor(spaceBelow) : 0;
|
|
47
|
+
return Math.min(upper, Math.max(0, value));
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* A terminal that grew adds rows BELOW the cursor, so the capacity grows by the
|
|
51
|
+
* exact difference (D6). Shrinking is NOT handled here: it re-measures instead of
|
|
52
|
+
* guessing (D5), so a smaller value would only hide a lost measurement.
|
|
53
|
+
*/
|
|
54
|
+
export function applyResizeGrowth(capacity, rowsPrev, rowsNow) {
|
|
55
|
+
// No capacity to grow: a broken number must not become a canvas by arithmetic.
|
|
56
|
+
if (!Number.isFinite(capacity))
|
|
57
|
+
return 0;
|
|
58
|
+
const base = Math.max(0, Math.floor(capacity));
|
|
59
|
+
const delta = Number.isFinite(rowsNow) && Number.isFinite(rowsPrev) ? rowsNow - rowsPrev : 0;
|
|
60
|
+
return base + Math.max(0, Math.floor(delta));
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* The layout of one batch.
|
|
64
|
+
*
|
|
65
|
+
* `heldRows` / `statRows` / `frameRows` are COUNTS, never strings, so this function
|
|
66
|
+
* can be property-tested over every combination without building a screen.
|
|
67
|
+
*
|
|
68
|
+
* TWO BRANCHES, and the difference is physical rather than cosmetic:
|
|
69
|
+
* - FIT: the content plus the region fits the capacity, so the leftover becomes the
|
|
70
|
+
* `gap` at the TOP of the canvas and nothing scrolls.
|
|
71
|
+
* - SCROLL: the canvas cannot hold everything. The batch writes every content row
|
|
72
|
+
* (the caller passes them untrimmed for exactly this reason), the terminal scrolls
|
|
73
|
+
* `scroll` rows away, and the rows that leave are the oldest content rows plus the
|
|
74
|
+
* host output above the canvas. `dropped` is how many content rows left.
|
|
75
|
+
*/
|
|
76
|
+
export function resolveCanvasLayout(input) {
|
|
77
|
+
// A re-seed writes its own leading CRLF, which eats one row of the space below the
|
|
78
|
+
// cursor and starts the canvas one row lower (P1-1 in the canvas model).
|
|
79
|
+
const lead = Math.max(0, whole(input.lead, 0));
|
|
80
|
+
const capacity = Math.max(0, whole(input.capacity, 0) - lead);
|
|
81
|
+
const held = Math.max(0, whole(input.heldRows, 0));
|
|
82
|
+
const stat = Math.max(0, whole(input.statRows, 0));
|
|
83
|
+
const frame = Math.max(0, whole(input.frameRows, 0));
|
|
84
|
+
const top = Math.max(0, whole(input.top, 0)) + lead;
|
|
85
|
+
const content = held + stat;
|
|
86
|
+
const need = content + frame;
|
|
87
|
+
if (need <= capacity) {
|
|
88
|
+
return {
|
|
89
|
+
heldRows: content,
|
|
90
|
+
gap: capacity - need,
|
|
91
|
+
scroll: 0,
|
|
92
|
+
dropped: 0,
|
|
93
|
+
top,
|
|
94
|
+
canvasRows: capacity,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
const scroll = need - capacity;
|
|
98
|
+
// Rows above the canvas are the host's old output: they leave the screen first.
|
|
99
|
+
const hostUsed = Math.min(scroll, top);
|
|
100
|
+
const grown = capacity + hostUsed;
|
|
101
|
+
const dropped = Math.min(scroll - hostUsed, content);
|
|
102
|
+
const keptContent = content - dropped;
|
|
103
|
+
return {
|
|
104
|
+
heldRows: keptContent,
|
|
105
|
+
// Zero whenever anything scrolled, and that is what keeps blank rows out of the
|
|
106
|
+
// scrollback: a skipped gap is un-written cells, a scrolled one is a written row.
|
|
107
|
+
gap: Math.max(0, grown - keptContent - frame),
|
|
108
|
+
scroll,
|
|
109
|
+
dropped,
|
|
110
|
+
top: top - hostUsed,
|
|
111
|
+
canvasRows: grown,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cursor-position probe — the one measurement the bottom anchor cannot do without
|
|
3
|
+
* (tui-bottom-anchored-live-region §4.4 / §6.3).
|
|
4
|
+
*
|
|
5
|
+
* WHY IT EXISTS. "How many rows are left below the cursor" cannot be derived from
|
|
6
|
+
* anything the process already knows: `CUD` clamps silently at the last row and
|
|
7
|
+
* reports nothing, and the only other way to reach the bottom is to print `rows - 1`
|
|
8
|
+
* newlines, which scrolls the user's screen. `ESC[6n` asks instead of guessing, and
|
|
9
|
+
* every target terminal answers it — Windows Terminal, conhost through ConPTY, tmux,
|
|
10
|
+
* screen, xterm/vte/alacritty/kitty/wezterm/foot/ghostty, the VS Code terminal and an
|
|
11
|
+
* SSH session's far end.
|
|
12
|
+
*
|
|
13
|
+
* WHAT IT DOES NOT DO:
|
|
14
|
+
* - It does not touch raw mode. Raising raw is the HOST's job and must happen BEFORE
|
|
15
|
+
* the query (P0-1 / I-A10): in canonical mode the reply is line-buffered until a
|
|
16
|
+
* newline and the terminal ECHOES it as `^[[12;1R` onto the screen, so the probe
|
|
17
|
+
* would time out forever on Linux/macOS while printing garbage.
|
|
18
|
+
* - It does not consume input. The filter ahead of Ink owns every byte; this module
|
|
19
|
+
* is a second `'data'` listener that never `pause()`s, `read()`s or `unshift()`s
|
|
20
|
+
* (D5 / R2).
|
|
21
|
+
* - It does not retry. One query, one bounded wait, then the caller degrades.
|
|
22
|
+
*
|
|
23
|
+
* FAILURE IS NORMAL, NOT AN ERROR: a terminal that never answers is a terminal that
|
|
24
|
+
* gets the one-off screen fill instead (rung 2 of the ladder). Nothing here throws,
|
|
25
|
+
* and nothing here can keep the process alive: the timer is `unref()`ed and the
|
|
26
|
+
* listener is always removed.
|
|
27
|
+
*/
|
|
28
|
+
export interface CursorProbeOptions {
|
|
29
|
+
/** The REAL stdin — not the filter's PassThrough, and not Ink's stream. */
|
|
30
|
+
stdin: NodeJS.ReadStream;
|
|
31
|
+
stdout: NodeJS.WriteStream;
|
|
32
|
+
/** Terminal height, read at answer time so a mid-wait resize is not fatal. */
|
|
33
|
+
rows: () => number | undefined;
|
|
34
|
+
/** Overrides `SCROLLBACK_LIMITS.anchorProbeTimeoutMs` (tests). */
|
|
35
|
+
timeoutMs?: number;
|
|
36
|
+
/**
|
|
37
|
+
* Keep the event loop alive while waiting for the answer.
|
|
38
|
+
*
|
|
39
|
+
* THE STARTUP PROBE MUST SET THIS, and the reason is measured rather than
|
|
40
|
+
* theoretical: an `unref()`ed timer is invisible to the event loop, so on a session
|
|
41
|
+
* where nothing is referenced yet — stdin already at EOF, a piped stdin, a console
|
|
42
|
+
* whose reader is paused — the process can exit BEFORE the first frame is ever
|
|
43
|
+
* drawn. `screen.test.ts`'s subprocess probe caught exactly that: exit code 0,
|
|
44
|
+
* `ESC[6n` on screen and no application at all.
|
|
45
|
+
*
|
|
46
|
+
* Background re-probes keep the default (`false`): a teardown must never be
|
|
47
|
+
* delayed, and by then the UI itself is holding the loop.
|
|
48
|
+
*/
|
|
49
|
+
holdProcess?: boolean;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Arm or disarm the switch. `true` is permanent for the process: there is no
|
|
53
|
+
* legitimate reason to probe after the screen has been handed back.
|
|
54
|
+
*/
|
|
55
|
+
export declare function setAnchorProbeDisabled(value: boolean): void;
|
|
56
|
+
/** Test hook — the switch is process-wide by design, so tests must reset it. */
|
|
57
|
+
export declare function resetAnchorProbeForTests(): void;
|
|
58
|
+
/**
|
|
59
|
+
* Ask the terminal where the cursor is and return the rows left below it
|
|
60
|
+
* (`0` = already on the last row). Returns `null` for every failure mode:
|
|
61
|
+
*
|
|
62
|
+
* | Situation | Result |
|
|
63
|
+
* |----------------------------------|---------------------------------|
|
|
64
|
+
* | switches off / not a TTY / rows unknown | `null`, synchronously, zero bytes |
|
|
65
|
+
* | terminal answers | `rows - 1 - (row - 1)` |
|
|
66
|
+
* | timeout (`anchorProbeTimeoutMs`) | `null`, timer and listener removed |
|
|
67
|
+
* | concurrent call | the same promise; one query only |
|
|
68
|
+
* | `stdout.write` throws | `null` |
|
|
69
|
+
* | a late reply after the timeout | ignored here; the filter strips it |
|
|
70
|
+
*/
|
|
71
|
+
export declare function probeAnchorSpaceBelow(o: CursorProbeOptions): Promise<number | null>;
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cursor-position probe — the one measurement the bottom anchor cannot do without
|
|
3
|
+
* (tui-bottom-anchored-live-region §4.4 / §6.3).
|
|
4
|
+
*
|
|
5
|
+
* WHY IT EXISTS. "How many rows are left below the cursor" cannot be derived from
|
|
6
|
+
* anything the process already knows: `CUD` clamps silently at the last row and
|
|
7
|
+
* reports nothing, and the only other way to reach the bottom is to print `rows - 1`
|
|
8
|
+
* newlines, which scrolls the user's screen. `ESC[6n` asks instead of guessing, and
|
|
9
|
+
* every target terminal answers it — Windows Terminal, conhost through ConPTY, tmux,
|
|
10
|
+
* screen, xterm/vte/alacritty/kitty/wezterm/foot/ghostty, the VS Code terminal and an
|
|
11
|
+
* SSH session's far end.
|
|
12
|
+
*
|
|
13
|
+
* WHAT IT DOES NOT DO:
|
|
14
|
+
* - It does not touch raw mode. Raising raw is the HOST's job and must happen BEFORE
|
|
15
|
+
* the query (P0-1 / I-A10): in canonical mode the reply is line-buffered until a
|
|
16
|
+
* newline and the terminal ECHOES it as `^[[12;1R` onto the screen, so the probe
|
|
17
|
+
* would time out forever on Linux/macOS while printing garbage.
|
|
18
|
+
* - It does not consume input. The filter ahead of Ink owns every byte; this module
|
|
19
|
+
* is a second `'data'` listener that never `pause()`s, `read()`s or `unshift()`s
|
|
20
|
+
* (D5 / R2).
|
|
21
|
+
* - It does not retry. One query, one bounded wait, then the caller degrades.
|
|
22
|
+
*
|
|
23
|
+
* FAILURE IS NORMAL, NOT AN ERROR: a terminal that never answers is a terminal that
|
|
24
|
+
* gets the one-off screen fill instead (rung 2 of the ladder). Nothing here throws,
|
|
25
|
+
* and nothing here can keep the process alive: the timer is `unref()`ed and the
|
|
26
|
+
* listener is always removed.
|
|
27
|
+
*/
|
|
28
|
+
import { SCROLLBACK_LIMITS } from './limits.js';
|
|
29
|
+
import { formatCursorReportQuery, spaceBelowFromReport, splitCursorReports, } from '../../input/cursor-report.js';
|
|
30
|
+
/** Longest acceptable report prefix we buffer before giving up on the chunk. */
|
|
31
|
+
const MAX_BUFFER_CHARS = 64;
|
|
32
|
+
/**
|
|
33
|
+
* THE DEATH SWITCH (I-A9 / P1-6).
|
|
34
|
+
*
|
|
35
|
+
* Once the session is over — `finalizeNativeScreen()`, `disposeFrameWriter()`, a
|
|
36
|
+
* disposed filter, the process `exit` hook — a query must never reach the terminal
|
|
37
|
+
* again. It would be written at a terminal already handed back to the shell, where
|
|
38
|
+
* nothing strips the reply, and the user's prompt would gain a literal `^[[12;1R`.
|
|
39
|
+
* The flag lives at module level because `cli.tsx`'s four exit paths converge on one
|
|
40
|
+
* call and must not each own a copy of the state.
|
|
41
|
+
*/
|
|
42
|
+
let disabled = false;
|
|
43
|
+
/** Single-flight: a drag can ask twice inside one settle window. */
|
|
44
|
+
let inFlight = null;
|
|
45
|
+
/**
|
|
46
|
+
* Arm or disarm the switch. `true` is permanent for the process: there is no
|
|
47
|
+
* legitimate reason to probe after the screen has been handed back.
|
|
48
|
+
*/
|
|
49
|
+
export function setAnchorProbeDisabled(value) {
|
|
50
|
+
disabled = value;
|
|
51
|
+
if (value)
|
|
52
|
+
inFlight = null;
|
|
53
|
+
}
|
|
54
|
+
/** Test hook — the switch is process-wide by design, so tests must reset it. */
|
|
55
|
+
export function resetAnchorProbeForTests() {
|
|
56
|
+
disabled = false;
|
|
57
|
+
inFlight = null;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Ask the terminal where the cursor is and return the rows left below it
|
|
61
|
+
* (`0` = already on the last row). Returns `null` for every failure mode:
|
|
62
|
+
*
|
|
63
|
+
* | Situation | Result |
|
|
64
|
+
* |----------------------------------|---------------------------------|
|
|
65
|
+
* | switches off / not a TTY / rows unknown | `null`, synchronously, zero bytes |
|
|
66
|
+
* | terminal answers | `rows - 1 - (row - 1)` |
|
|
67
|
+
* | timeout (`anchorProbeTimeoutMs`) | `null`, timer and listener removed |
|
|
68
|
+
* | concurrent call | the same promise; one query only |
|
|
69
|
+
* | `stdout.write` throws | `null` |
|
|
70
|
+
* | a late reply after the timeout | ignored here; the filter strips it |
|
|
71
|
+
*/
|
|
72
|
+
export function probeAnchorSpaceBelow(o) {
|
|
73
|
+
if (disabled)
|
|
74
|
+
return Promise.resolve(null);
|
|
75
|
+
if (!o.stdin.isTTY || !o.stdout.isTTY)
|
|
76
|
+
return Promise.resolve(null);
|
|
77
|
+
if (inFlight)
|
|
78
|
+
return inFlight;
|
|
79
|
+
const rowsNow = o.rows();
|
|
80
|
+
if (rowsNow === undefined || !Number.isFinite(rowsNow) || rowsNow < 1) {
|
|
81
|
+
return Promise.resolve(null);
|
|
82
|
+
}
|
|
83
|
+
const promise = new Promise((resolve) => {
|
|
84
|
+
const timeoutMs = o.timeoutMs ?? SCROLLBACK_LIMITS.anchorProbeTimeoutMs;
|
|
85
|
+
let buffer = '';
|
|
86
|
+
let settled = false;
|
|
87
|
+
let timer = null;
|
|
88
|
+
const finish = (value) => {
|
|
89
|
+
if (settled)
|
|
90
|
+
return;
|
|
91
|
+
settled = true;
|
|
92
|
+
if (timer) {
|
|
93
|
+
clearTimeout(timer);
|
|
94
|
+
timer = null;
|
|
95
|
+
}
|
|
96
|
+
o.stdin.removeListener('data', onData);
|
|
97
|
+
resolve(value);
|
|
98
|
+
};
|
|
99
|
+
function onData(chunk) {
|
|
100
|
+
if (settled)
|
|
101
|
+
return;
|
|
102
|
+
buffer += typeof chunk === 'string' ? chunk : chunk.toString('utf8');
|
|
103
|
+
if (buffer.length > MAX_BUFFER_CHARS)
|
|
104
|
+
buffer = buffer.slice(-MAX_BUFFER_CHARS);
|
|
105
|
+
const split = splitCursorReports(buffer);
|
|
106
|
+
const report = split.reports[0];
|
|
107
|
+
if (!report)
|
|
108
|
+
return;
|
|
109
|
+
finish(spaceBelowFromReport(report, o.rows() ?? undefined));
|
|
110
|
+
}
|
|
111
|
+
try {
|
|
112
|
+
o.stdout.write(formatCursorReportQuery());
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
// A closed or broken stdout is an ordinary failure, not a crash on startup.
|
|
116
|
+
finish(null);
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
o.stdin.on('data', onData);
|
|
120
|
+
timer = setTimeout(() => finish(null), Math.max(1, Math.floor(timeoutMs)));
|
|
121
|
+
// `unref()` by default (see `holdProcess`), so a stray re-probe can never keep a
|
|
122
|
+
// teardown alive. The startup probe opts back in: there it is the ONLY thing
|
|
123
|
+
// holding the loop, and losing the session to save 150 ms is not a trade.
|
|
124
|
+
if (!o.holdProcess)
|
|
125
|
+
timer.unref?.();
|
|
126
|
+
});
|
|
127
|
+
inFlight = promise;
|
|
128
|
+
void promise.then(() => {
|
|
129
|
+
if (inFlight === promise)
|
|
130
|
+
inFlight = null;
|
|
131
|
+
});
|
|
132
|
+
return promise;
|
|
133
|
+
}
|
|
@@ -18,8 +18,65 @@ export declare const SCROLLBACK_LIMITS: {
|
|
|
18
18
|
readonly guardTripCount: 3;
|
|
19
19
|
/** Session summary rows printed on exit. */
|
|
20
20
|
readonly exitSummaryMaxRows: 4;
|
|
21
|
-
/**
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Entries the region may hold on screen at once
|
|
23
|
+
* (tui-full-height-live-region D6; the WINDOW is defined by I-F8 and computed in
|
|
24
|
+
* `tail-window.ts`).
|
|
25
|
+
*
|
|
26
|
+
* 10 is DERIVED, not a preference. The band's left column is the whole pool
|
|
27
|
+
* (`pool = rows - 1 - header - composer - status`, i.e. 24 rows on a 30-row
|
|
28
|
+
* terminal) and one entry occupies about 2.4 rows, so a window of 4 would leave
|
|
29
|
+
* the column half empty - the blank band this feature removes. It stays in the
|
|
30
|
+
* per-frame COST class the old value of 4 was measured in: `EntryView` is
|
|
31
|
+
* memoised and only the streaming entry re-renders, so this bounds component
|
|
32
|
+
* instances, not per-frame work.
|
|
33
|
+
*
|
|
34
|
+
* There is deliberately NO companion row cap any more (retired: the old
|
|
35
|
+
* `maxLiveTailRows` / `liveTailRowShare` pair). The rows a tail may take are
|
|
36
|
+
* `band.previewRows` - the whole left column - and "the region can never be
|
|
37
|
+
* taller than the screen" is `liveRows === rows - 1`'s job (I-F5), not a second
|
|
38
|
+
* number's. Those two caps disagreed with the pool, and that disagreement WAS the
|
|
39
|
+
* blank band between the result and the running card.
|
|
40
|
+
*/
|
|
41
|
+
readonly liveTailMaxEntries: 10;
|
|
42
|
+
/**
|
|
43
|
+
* Rows the rail needs before the band will show it: `TODO_LIMITS.panelMinRows + 1`.
|
|
44
|
+
*
|
|
45
|
+
* The `+ 1` is not decoration - the rail takes its rows from the same pool as one
|
|
46
|
+
* preview row, and a band that seats the rail but no preview loses the streaming
|
|
47
|
+
* answer entirely (band.ts step 3 / AC-12).
|
|
48
|
+
*/
|
|
49
|
+
readonly railBandMinRows: 4;
|
|
50
|
+
/**
|
|
51
|
+
* How long the cursor-position probe waits for `ESC[<row>;<col>R`.
|
|
52
|
+
*
|
|
53
|
+
* A STRUCTURAL CAP, not a preference (tui-bottom-anchored-live-region §4.4): it
|
|
54
|
+
* bounds "how much startup latency a terminal that does not answer may cost". The
|
|
55
|
+
* round trip is under 5 ms locally and under 60 ms over SSH, so 150 ms is
|
|
56
|
+
* generous, and the probe runs once per session — never per frame, never per
|
|
57
|
+
* keystroke. Anything longer and a terminal without CPR support would pay it on
|
|
58
|
+
* every launch.
|
|
59
|
+
*/
|
|
60
|
+
readonly anchorProbeTimeoutMs: 150;
|
|
61
|
+
/**
|
|
62
|
+
* Settle window before re-measuring the cursor after a resize.
|
|
63
|
+
*
|
|
64
|
+
* A STRUCTURAL CAP for the same reason: a drag fires dozens of resize events, and
|
|
65
|
+
* one CPR per event would both flood the input channel and make the region jitter.
|
|
66
|
+
* 200 ms is below the point a user perceives as "the input box is stuck".
|
|
67
|
+
*/
|
|
68
|
+
readonly anchorReprobeDelayMs: 200;
|
|
69
|
+
/**
|
|
70
|
+
* Structural ceiling on the height of a STARTING canvas.
|
|
71
|
+
*
|
|
72
|
+
* It bounds the bytes a batch may write and the rows the content cache may hold on
|
|
73
|
+
* an extreme terminal (`rows` 3000). Two limits on how it may be applied, both
|
|
74
|
+
* arithmetic rather than taste:
|
|
75
|
+
* - the rows a canvas leaves unused do not disappear, they stay above it as the
|
|
76
|
+
* permanent region, so a smaller starting canvas never loses content;
|
|
77
|
+
* - it must NEVER clip a live canvas. A canvas that has overflowed and scrolled
|
|
78
|
+
* grows to `rows - 1`, and shrinking one back would make the next erase reach
|
|
79
|
+
* above its own top: host output erased, every visible row printed twice.
|
|
80
|
+
*/
|
|
81
|
+
readonly maxCanvasRows: 200;
|
|
25
82
|
};
|
|
@@ -18,8 +18,65 @@ export const SCROLLBACK_LIMITS = {
|
|
|
18
18
|
guardTripCount: 3,
|
|
19
19
|
/** Session summary rows printed on exit. */
|
|
20
20
|
exitSummaryMaxRows: 4,
|
|
21
|
-
/**
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Entries the region may hold on screen at once
|
|
23
|
+
* (tui-full-height-live-region D6; the WINDOW is defined by I-F8 and computed in
|
|
24
|
+
* `tail-window.ts`).
|
|
25
|
+
*
|
|
26
|
+
* 10 is DERIVED, not a preference. The band's left column is the whole pool
|
|
27
|
+
* (`pool = rows - 1 - header - composer - status`, i.e. 24 rows on a 30-row
|
|
28
|
+
* terminal) and one entry occupies about 2.4 rows, so a window of 4 would leave
|
|
29
|
+
* the column half empty - the blank band this feature removes. It stays in the
|
|
30
|
+
* per-frame COST class the old value of 4 was measured in: `EntryView` is
|
|
31
|
+
* memoised and only the streaming entry re-renders, so this bounds component
|
|
32
|
+
* instances, not per-frame work.
|
|
33
|
+
*
|
|
34
|
+
* There is deliberately NO companion row cap any more (retired: the old
|
|
35
|
+
* `maxLiveTailRows` / `liveTailRowShare` pair). The rows a tail may take are
|
|
36
|
+
* `band.previewRows` - the whole left column - and "the region can never be
|
|
37
|
+
* taller than the screen" is `liveRows === rows - 1`'s job (I-F5), not a second
|
|
38
|
+
* number's. Those two caps disagreed with the pool, and that disagreement WAS the
|
|
39
|
+
* blank band between the result and the running card.
|
|
40
|
+
*/
|
|
41
|
+
liveTailMaxEntries: 10,
|
|
42
|
+
/**
|
|
43
|
+
* Rows the rail needs before the band will show it: `TODO_LIMITS.panelMinRows + 1`.
|
|
44
|
+
*
|
|
45
|
+
* The `+ 1` is not decoration - the rail takes its rows from the same pool as one
|
|
46
|
+
* preview row, and a band that seats the rail but no preview loses the streaming
|
|
47
|
+
* answer entirely (band.ts step 3 / AC-12).
|
|
48
|
+
*/
|
|
49
|
+
railBandMinRows: 4,
|
|
50
|
+
/**
|
|
51
|
+
* How long the cursor-position probe waits for `ESC[<row>;<col>R`.
|
|
52
|
+
*
|
|
53
|
+
* A STRUCTURAL CAP, not a preference (tui-bottom-anchored-live-region §4.4): it
|
|
54
|
+
* bounds "how much startup latency a terminal that does not answer may cost". The
|
|
55
|
+
* round trip is under 5 ms locally and under 60 ms over SSH, so 150 ms is
|
|
56
|
+
* generous, and the probe runs once per session — never per frame, never per
|
|
57
|
+
* keystroke. Anything longer and a terminal without CPR support would pay it on
|
|
58
|
+
* every launch.
|
|
59
|
+
*/
|
|
60
|
+
anchorProbeTimeoutMs: 150,
|
|
61
|
+
/**
|
|
62
|
+
* Settle window before re-measuring the cursor after a resize.
|
|
63
|
+
*
|
|
64
|
+
* A STRUCTURAL CAP for the same reason: a drag fires dozens of resize events, and
|
|
65
|
+
* one CPR per event would both flood the input channel and make the region jitter.
|
|
66
|
+
* 200 ms is below the point a user perceives as "the input box is stuck".
|
|
67
|
+
*/
|
|
68
|
+
anchorReprobeDelayMs: 200,
|
|
69
|
+
/**
|
|
70
|
+
* Structural ceiling on the height of a STARTING canvas.
|
|
71
|
+
*
|
|
72
|
+
* It bounds the bytes a batch may write and the rows the content cache may hold on
|
|
73
|
+
* an extreme terminal (`rows` 3000). Two limits on how it may be applied, both
|
|
74
|
+
* arithmetic rather than taste:
|
|
75
|
+
* - the rows a canvas leaves unused do not disappear, they stay above it as the
|
|
76
|
+
* permanent region, so a smaller starting canvas never loses content;
|
|
77
|
+
* - it must NEVER clip a live canvas. A canvas that has overflowed and scrolled
|
|
78
|
+
* grows to `rows - 1`, and shrinking one back would make the next erase reach
|
|
79
|
+
* above its own top: host output erased, every visible row printed twice.
|
|
80
|
+
*/
|
|
81
|
+
maxCanvasRows: 200,
|
|
25
82
|
};
|
|
@@ -1,18 +1,28 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* (tui-native-terminal-scroll §4.6).
|
|
2
|
+
* Plain-text fallback rows for the native-scroll live region
|
|
3
|
+
* (tui-native-terminal-scroll §4.6, tui-full-height-live-region RV-P2-7).
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
5
|
+
* THE REAL TAIL IS `LiveTail`, NOT THIS. Native mode draws the region's tail with the
|
|
6
|
+
* actual entry components, so these rows are only the fallback for a frame that mounts
|
|
7
|
+
* no component there (and the floor of the measurement path). They are kept rather than
|
|
8
|
+
* deleted because the render tests use them to assert exactly that frame, and because
|
|
9
|
+
* `<= 24 wrapToRows` calls per frame is far below the cost of the components it stands
|
|
10
|
+
* in for.
|
|
11
|
+
*
|
|
12
|
+
* The input is the TAIL WINDOW (`selectTailWindow`), settled entries included: at
|
|
13
|
+
* `H = rows - 1` the region shows the last K entries of the conversation, so a
|
|
14
|
+
* projection built only from the unfinished ones would disagree with the screen.
|
|
15
|
+
* The field keeps its historical name `unsettled` because it is still "the entries the
|
|
16
|
+
* region is showing", and renaming it would touch the preview tests for no behaviour.
|
|
10
17
|
*
|
|
11
18
|
* PURE: no Ink, no theme, no I/O. Every returned row fits `cols` display columns.
|
|
12
19
|
*/
|
|
13
20
|
import type { Entry } from '../../agent/reducer.js';
|
|
14
21
|
export interface LivePreviewInput {
|
|
15
|
-
/**
|
|
22
|
+
/**
|
|
23
|
+
* The entries to project, oldest first - the tail window in native mode. May include
|
|
24
|
+
* excluded entries; they are skipped.
|
|
25
|
+
*/
|
|
16
26
|
unsettled: readonly Entry[];
|
|
17
27
|
/** Content width (`cols - 1`). */
|
|
18
28
|
cols: number;
|
|
@@ -22,5 +32,3 @@ export interface LivePreviewInput {
|
|
|
22
32
|
}
|
|
23
33
|
/** The last `rows` preview rows, oldest first. `[]` when `rows <= 0`. */
|
|
24
34
|
export declare function buildLivePreview(input: LivePreviewInput): string[];
|
|
25
|
-
/** How many preview rows the unsettled entries would like, before budget clamping. */
|
|
26
|
-
export declare function wantedPreviewRows(input: Omit<LivePreviewInput, 'rows'>, cap: number): number;
|
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* (tui-native-terminal-scroll §4.6).
|
|
2
|
+
* Plain-text fallback rows for the native-scroll live region
|
|
3
|
+
* (tui-native-terminal-scroll §4.6, tui-full-height-live-region RV-P2-7).
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
5
|
+
* THE REAL TAIL IS `LiveTail`, NOT THIS. Native mode draws the region's tail with the
|
|
6
|
+
* actual entry components, so these rows are only the fallback for a frame that mounts
|
|
7
|
+
* no component there (and the floor of the measurement path). They are kept rather than
|
|
8
|
+
* deleted because the render tests use them to assert exactly that frame, and because
|
|
9
|
+
* `<= 24 wrapToRows` calls per frame is far below the cost of the components it stands
|
|
10
|
+
* in for.
|
|
11
|
+
*
|
|
12
|
+
* The input is the TAIL WINDOW (`selectTailWindow`), settled entries included: at
|
|
13
|
+
* `H = rows - 1` the region shows the last K entries of the conversation, so a
|
|
14
|
+
* projection built only from the unfinished ones would disagree with the screen.
|
|
15
|
+
* The field keeps its historical name `unsettled` because it is still "the entries the
|
|
16
|
+
* region is showing", and renaming it would touch the preview tests for no behaviour.
|
|
10
17
|
*
|
|
11
18
|
* PURE: no Ink, no theme, no I/O. Every returned row fits `cols` display columns.
|
|
12
19
|
*/
|
|
@@ -100,7 +107,3 @@ export function buildLivePreview(input) {
|
|
|
100
107
|
}
|
|
101
108
|
return all.slice(-rows);
|
|
102
109
|
}
|
|
103
|
-
/** How many preview rows the unsettled entries would like, before budget clamping. */
|
|
104
|
-
export function wantedPreviewRows(input, cap) {
|
|
105
|
-
return buildLivePreview({ ...input, rows: cap }).length;
|
|
106
|
-
}
|