agent-sh 0.6.0 → 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.
@@ -0,0 +1,198 @@
1
+ import { TerminalBuffer } from "./terminal-buffer.js";
2
+ import { HandlerRegistry } from "./handler-registry.js";
3
+ import type { EventBus } from "../event-bus.js";
4
+ import type { BorderStyle } from "./box-frame.js";
5
+ export interface FloatingPanelConfig {
6
+ /** Key sequence that toggles the panel (e.g. "\x1c" for Ctrl+\). */
7
+ trigger: string;
8
+ /** Panel width. Number = columns, string with % = percentage. Default: "80%". */
9
+ width?: number | string;
10
+ /** Max width in columns. Default: 100. */
11
+ maxWidth?: number;
12
+ /** Panel height. Number = rows, string with % = percentage. Default: "60%". */
13
+ height?: number | string;
14
+ /** Min content rows inside the panel. Default: 6. */
15
+ minHeight?: number;
16
+ /** Border style. Default: "rounded". */
17
+ borderStyle?: BorderStyle;
18
+ /**
19
+ * Show dimmed terminal content behind the panel. Default: true.
20
+ * Requires @xterm/headless — falls back to blank background if unavailable.
21
+ */
22
+ dimBackground?: boolean;
23
+ /** Auto-dismiss delay in ms when done (0 = disabled). Default: 0. */
24
+ autoDismissMs?: number;
25
+ /** Icon shown before the input cursor. Default: "\u276f". */
26
+ promptIcon?: string;
27
+ /**
28
+ * Pre-existing TerminalBuffer to reuse. If provided, the panel will
29
+ * not create its own headless terminal. Useful when sharing a buffer
30
+ * with other features (e.g. context injection, terminal_read tool).
31
+ */
32
+ terminalBuffer?: TerminalBuffer;
33
+ /**
34
+ * Handler namespace prefix. Default: "panel".
35
+ * All handlers are registered as `{prefix}:render-content`,
36
+ * `{prefix}:submit`, etc. Use different prefixes for multiple panels.
37
+ */
38
+ handlerPrefix?: string;
39
+ }
40
+ /**
41
+ * Context passed to the render-content handler.
42
+ */
43
+ export interface RenderContext {
44
+ /** Available width for content (inside box, excluding borders and padding). */
45
+ width: number;
46
+ /** Available height for content (rows inside box). */
47
+ height: number;
48
+ /** Current panel phase. */
49
+ phase: Phase;
50
+ /** Current input buffer text (during input phase). */
51
+ inputBuffer: string;
52
+ /** Current input cursor position (during input phase). */
53
+ inputCursor: number;
54
+ /** Current scroll offset. */
55
+ scrollOffset: number;
56
+ /** Built-in content lines (from appendText/appendLine). */
57
+ contentLines: readonly string[];
58
+ /** Current partial line being streamed. */
59
+ partialLine: string;
60
+ }
61
+ /**
62
+ * Result from render-content handler.
63
+ */
64
+ export interface RenderResult {
65
+ lines: string[];
66
+ /** Optional cursor position within the content area. */
67
+ cursor?: {
68
+ row: number;
69
+ col: number;
70
+ };
71
+ }
72
+ /**
73
+ * Box geometry computed from config + terminal size.
74
+ */
75
+ export interface BoxGeometry {
76
+ /** Terminal columns. */
77
+ cols: number;
78
+ /** Terminal rows. */
79
+ rows: number;
80
+ /** Box width in columns (including borders). */
81
+ boxW: number;
82
+ /** Box height in rows (including borders). */
83
+ boxH: number;
84
+ /** Box top offset (0-indexed row). */
85
+ boxTop: number;
86
+ /** Box left offset (0-indexed column). */
87
+ boxLeft: number;
88
+ /** Usable content width inside box. */
89
+ contentW: number;
90
+ /** Usable content height inside box. */
91
+ contentH: number;
92
+ }
93
+ /**
94
+ * Context passed to the render-frame handler.
95
+ */
96
+ export interface FrameContext {
97
+ /** Box geometry. */
98
+ geo: BoxGeometry;
99
+ /** Content render result (from render-content handler). */
100
+ content: RenderResult;
101
+ /** Background lines from the terminal buffer (null if no dimming). */
102
+ bgLines: string[] | null;
103
+ /** Current panel phase. */
104
+ phase: Phase;
105
+ /** Current title text. */
106
+ title: string;
107
+ /** Current footer text. */
108
+ footer: string;
109
+ /** Border characters for the configured border style. */
110
+ border: {
111
+ tl: string;
112
+ tr: string;
113
+ bl: string;
114
+ br: string;
115
+ h: string;
116
+ v: string;
117
+ };
118
+ }
119
+ /**
120
+ * Result from render-frame handler.
121
+ */
122
+ export interface FrameResult {
123
+ /** One string per terminal row. */
124
+ rows: string[];
125
+ /** ANSI sequence to position the cursor (empty string if no cursor). */
126
+ cursorSeq: string;
127
+ }
128
+ export type Phase = "idle" | "input" | "active" | "done";
129
+ export declare class FloatingPanel {
130
+ private readonly config;
131
+ private readonly bus;
132
+ private readonly border;
133
+ private readonly externalBuffer;
134
+ private readonly prefix;
135
+ /**
136
+ * Handler registry for this panel. Extensions use `handlers.advise()`
137
+ * to customize rendering and behavior.
138
+ *
139
+ * Registered handlers:
140
+ * - `{prefix}:render-content(ctx: RenderContext) -> RenderResult`
141
+ * - `{prefix}:render-frame(ctx: FrameContext) -> FrameResult`
142
+ * - `{prefix}:render-border-top(ctx: FrameContext) -> string`
143
+ * - `{prefix}:render-border-bottom(ctx: FrameContext) -> string`
144
+ * - `{prefix}:composite-row(content: string, bgLine: string|null, boxLeft: number, boxW: number, cols: number) -> string`
145
+ * - `{prefix}:submit(query: string) -> void`
146
+ * - `{prefix}:dismiss() -> void`
147
+ * - `{prefix}:input(data: string) -> boolean`
148
+ * - `{prefix}:build-row(content: string, width: number) -> string`
149
+ */
150
+ readonly handlers: HandlerRegistry;
151
+ private buffer;
152
+ private bufferInitialized;
153
+ /** All byte sequences that should be recognized as the trigger key. */
154
+ private readonly triggerSeqs;
155
+ private phase;
156
+ private editor;
157
+ private contentLines;
158
+ private currentPartialLine;
159
+ private scrollOffset;
160
+ private title;
161
+ private footer;
162
+ private renderTimer;
163
+ private autoDismissTimer;
164
+ private resizeHandler;
165
+ private prevFrame;
166
+ private suppressNextRedraw;
167
+ private ptyBuffer;
168
+ private usedAltScreen;
169
+ constructor(bus: EventBus, config: FloatingPanelConfig, handlers?: HandlerRegistry);
170
+ private registerDefaultHandlers;
171
+ private wireEvents;
172
+ /** Check whether data matches any encoding of the trigger key. */
173
+ private isTrigger;
174
+ private ensureBuffer;
175
+ get active(): boolean;
176
+ get terminalBuffer(): TerminalBuffer | null;
177
+ open(): void;
178
+ dismiss(): void;
179
+ appendText(text: string): void;
180
+ appendLine(line: string): void;
181
+ updateLastLine(fn: (line: string) => string): void;
182
+ clearContent(): void;
183
+ setTitle(title: string): void;
184
+ setFooter(footer: string): void;
185
+ setActive(): void;
186
+ setDone(): void;
187
+ getInput(): string;
188
+ requestRender(): void;
189
+ private handleIntercept;
190
+ private handleInputKey;
191
+ /** Compute box geometry from config + current terminal size. */
192
+ computeGeometry(): BoxGeometry;
193
+ private buildFrame;
194
+ private scheduleRender;
195
+ private render;
196
+ private restoreScreen;
197
+ private resolveSize;
198
+ }