shellpuppet 0.0.1 → 0.2.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.
- package/LICENSE +202 -0
- package/NOTICE +31 -0
- package/README.md +499 -8
- package/dist/cli/desktopShortcut.d.ts +22 -0
- package/dist/cli/desktopShortcut.js +157 -0
- package/dist/cli/desktopShortcut.js.map +1 -0
- package/dist/cli/index.d.ts +13 -0
- package/dist/cli/index.js +846 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/client/http.d.ts +143 -0
- package/dist/client/http.js +581 -0
- package/dist/client/http.js.map +1 -0
- package/dist/core/dialogs.d.ts +96 -0
- package/dist/core/dialogs.js +226 -0
- package/dist/core/dialogs.js.map +1 -0
- package/dist/core/echo.d.ts +71 -0
- package/dist/core/echo.js +249 -0
- package/dist/core/echo.js.map +1 -0
- package/dist/core/find.d.ts +34 -0
- package/dist/core/find.js +41 -0
- package/dist/core/find.js.map +1 -0
- package/dist/core/keys.d.ts +22 -0
- package/dist/core/keys.js +80 -0
- package/dist/core/keys.js.map +1 -0
- package/dist/core/manager.d.ts +96 -0
- package/dist/core/manager.js +271 -0
- package/dist/core/manager.js.map +1 -0
- package/dist/core/nativePty.d.ts +73 -0
- package/dist/core/nativePty.js +161 -0
- package/dist/core/nativePty.js.map +1 -0
- package/dist/core/policy.d.ts +61 -0
- package/dist/core/policy.js +143 -0
- package/dist/core/policy.js.map +1 -0
- package/dist/core/promptDetector.d.ts +109 -0
- package/dist/core/promptDetector.js +897 -0
- package/dist/core/promptDetector.js.map +1 -0
- package/dist/core/reasoning.d.ts +265 -0
- package/dist/core/reasoning.js +933 -0
- package/dist/core/reasoning.js.map +1 -0
- package/dist/core/regexBudget.d.ts +64 -0
- package/dist/core/regexBudget.js +103 -0
- package/dist/core/regexBudget.js.map +1 -0
- package/dist/core/renderer.d.ts +127 -0
- package/dist/core/renderer.js +316 -0
- package/dist/core/renderer.js.map +1 -0
- package/dist/core/selection.d.ts +6 -0
- package/dist/core/selection.js +48 -0
- package/dist/core/selection.js.map +1 -0
- package/dist/core/session.d.ts +565 -0
- package/dist/core/session.js +1450 -0
- package/dist/core/session.js.map +1 -0
- package/dist/core/types.d.ts +316 -0
- package/dist/core/types.js +71 -0
- package/dist/core/types.js.map +1 -0
- package/dist/core/waiter.d.ts +94 -0
- package/dist/core/waiter.js +310 -0
- package/dist/core/waiter.js.map +1 -0
- package/dist/core/windowsConsoleHost.d.ts +147 -0
- package/dist/core/windowsConsoleHost.js +588 -0
- package/dist/core/windowsConsoleHost.js.map +1 -0
- package/dist/core/windowsPtyStart.d.ts +161 -0
- package/dist/core/windowsPtyStart.js +236 -0
- package/dist/core/windowsPtyStart.js.map +1 -0
- package/dist/daemon/audit.d.ts +23 -0
- package/dist/daemon/audit.js +51 -0
- package/dist/daemon/audit.js.map +1 -0
- package/dist/daemon/auth.d.ts +197 -0
- package/dist/daemon/auth.js +366 -0
- package/dist/daemon/auth.js.map +1 -0
- package/dist/daemon/config.d.ts +119 -0
- package/dist/daemon/config.js +568 -0
- package/dist/daemon/config.js.map +1 -0
- package/dist/daemon/folderPicker.d.ts +27 -0
- package/dist/daemon/folderPicker.js +115 -0
- package/dist/daemon/folderPicker.js.map +1 -0
- package/dist/daemon/index.d.ts +7 -0
- package/dist/daemon/index.js +88 -0
- package/dist/daemon/index.js.map +1 -0
- package/dist/daemon/launchProfiles.d.ts +155 -0
- package/dist/daemon/launchProfiles.js +554 -0
- package/dist/daemon/launchProfiles.js.map +1 -0
- package/dist/daemon/liveness.d.ts +36 -0
- package/dist/daemon/liveness.js +71 -0
- package/dist/daemon/liveness.js.map +1 -0
- package/dist/daemon/logger.d.ts +7 -0
- package/dist/daemon/logger.js +29 -0
- package/dist/daemon/logger.js.map +1 -0
- package/dist/daemon/meta.d.ts +9 -0
- package/dist/daemon/meta.js +24 -0
- package/dist/daemon/meta.js.map +1 -0
- package/dist/daemon/paths.d.ts +85 -0
- package/dist/daemon/paths.js +154 -0
- package/dist/daemon/paths.js.map +1 -0
- package/dist/daemon/screenshot.d.ts +144 -0
- package/dist/daemon/screenshot.js +402 -0
- package/dist/daemon/screenshot.js.map +1 -0
- package/dist/daemon/server.d.ts +453 -0
- package/dist/daemon/server.js +3954 -0
- package/dist/daemon/server.js.map +1 -0
- package/dist/daemon/sessionFeed.d.ts +48 -0
- package/dist/daemon/sessionFeed.js +101 -0
- package/dist/daemon/sessionFeed.js.map +1 -0
- package/dist/daemon/terminalReports.d.ts +38 -0
- package/dist/daemon/terminalReports.js +84 -0
- package/dist/daemon/terminalReports.js.map +1 -0
- package/dist/daemon/viewerLauncher.d.ts +226 -0
- package/dist/daemon/viewerLauncher.js +562 -0
- package/dist/daemon/viewerLauncher.js.map +1 -0
- package/dist/daemon/viewerSync.d.ts +38 -0
- package/dist/daemon/viewerSync.js +83 -0
- package/dist/daemon/viewerSync.js.map +1 -0
- package/dist/mcp/config.d.ts +50 -0
- package/dist/mcp/config.js +95 -0
- package/dist/mcp/config.js.map +1 -0
- package/dist/mcp/index.d.ts +10 -0
- package/dist/mcp/index.js +78 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/mcp/tools.d.ts +66 -0
- package/dist/mcp/tools.js +638 -0
- package/dist/mcp/tools.js.map +1 -0
- package/dist/viewer/dashboard-folders.js +20 -0
- package/dist/viewer/dashboard-layout.js +52 -0
- package/dist/viewer/dashboard.css +67 -0
- package/dist/viewer/dashboard.html +44 -0
- package/dist/viewer/dashboard.js +1518 -0
- package/dist/viewer/icon-16.png +0 -0
- package/dist/viewer/icon-180.png +0 -0
- package/dist/viewer/icon-32.png +0 -0
- package/dist/viewer/icon-512.png +0 -0
- package/dist/viewer/icon.ico +0 -0
- package/dist/viewer/icon.svg +66 -0
- package/dist/viewer/index.html +61 -0
- package/dist/viewer/pane.js +736 -0
- package/dist/viewer/viewer.css +95 -0
- package/dist/viewer/viewer.js +84 -0
- package/package.json +66 -7
- package/index.js +0 -4
|
@@ -0,0 +1,565 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One PTY session: process + renderer + lifecycle (design §2.4).
|
|
3
|
+
*
|
|
4
|
+
* The session owns the real PTY (ConPTY on Windows), keeps the headless
|
|
5
|
+
* renderer current, serialises that renderer for viewers, tracks readiness
|
|
6
|
+
* and kills the whole process tree on demand (design §3.1), not just the PTY
|
|
7
|
+
* child.
|
|
8
|
+
*
|
|
9
|
+
* Shell wrapping happens HERE, after the caller has already made its policy
|
|
10
|
+
* decision against the pre-wrap command (design §4.3). Callers pass
|
|
11
|
+
* `goose session`; this module turns it into `cmd.exe /c goose session` on
|
|
12
|
+
* Windows because direct ConPTY spawns of single-file binaries hang (§7).
|
|
13
|
+
*
|
|
14
|
+
* No stdout/stderr: logging via the injected Logger only (lint-enforced).
|
|
15
|
+
*/
|
|
16
|
+
import type { IPty } from 'node-pty';
|
|
17
|
+
import type { QueuedConsoleHost, SpawnWindow } from './windowsConsoleHost.js';
|
|
18
|
+
import type { SerializeOptions, StyledLine } from './renderer.js';
|
|
19
|
+
import { detectPrompt } from './promptDetector.js';
|
|
20
|
+
import type { WaiterInternals } from './waiter.js';
|
|
21
|
+
import type { WaitTarget } from './waiter.js';
|
|
22
|
+
import type { Logger, ScreenSnapshot, SessionEnvMode, SessionOptions, SessionSummary, WaitCondition, WaitOptions, WaitResult } from './types.js';
|
|
23
|
+
/**
|
|
24
|
+
* Hard cap on `taskkill`. Without it a wedged kill never calls back, so
|
|
25
|
+
* `kill()` never resolves, `killAll()` never resolves and daemon shutdown
|
|
26
|
+
* never completes. The daemon then becomes an immortal, undiscoverable
|
|
27
|
+
* process the user can only end via Task Manager.
|
|
28
|
+
*
|
|
29
|
+
* **Why 30 s.** On a real Qoder CLI tree (78 descendants, because it spawns
|
|
30
|
+
* an MCP-server fleet) `taskkill /T /F` took **5,433 ms**. A cap tighter than
|
|
31
|
+
* a normal kill cuts the walk short and leaves the tree to the `pty.kill()`
|
|
32
|
+
* fallback below, the path that cannot reach console-detached descendants.
|
|
33
|
+
* The cap exists to bound the wedged case, not to be tighter than the normal
|
|
34
|
+
* case.
|
|
35
|
+
*/
|
|
36
|
+
export declare const TREE_KILL_TIMEOUT_MS = 30000;
|
|
37
|
+
/** Quote one literal argument for the Windows C runtime's argv parser. */
|
|
38
|
+
export declare function windowsArgument(arg: string): string;
|
|
39
|
+
/** What a `taskkill` run reported when it did not simply succeed. */
|
|
40
|
+
export interface TreeKillFailure {
|
|
41
|
+
/** Our timeout fired and `taskkill` was terminated mid-walk. */
|
|
42
|
+
timedOut: boolean;
|
|
43
|
+
exitCode: number | string | null;
|
|
44
|
+
elapsedMs: number;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Tree-kill processes with one `taskkill /T /F` run (Windows). Resolves with
|
|
48
|
+
* null on success and with what went wrong otherwise; never rejects.
|
|
49
|
+
*/
|
|
50
|
+
export type TreeKiller = (pids: readonly number[]) => Promise<TreeKillFailure | null>;
|
|
51
|
+
/**
|
|
52
|
+
* One `taskkill` run for any number of trees. Every run enumerates every
|
|
53
|
+
* process on the machine before it kills anything, and that is most of its
|
|
54
|
+
* cost. Measured on a Windows machine running about 2,700 processes: 9 to
|
|
55
|
+
* 13 s for one lone process; thirty concurrent runs, one per session, each
|
|
56
|
+
* overran the 30 s cap; one run given all thirty pids took 10 s. So daemon
|
|
57
|
+
* shutdown kills every tree in one run (`SessionManager.killAll`).
|
|
58
|
+
*/
|
|
59
|
+
export declare const taskkillTrees: TreeKiller;
|
|
60
|
+
/** Muse needs a short pause after text before its submitting Enter. */
|
|
61
|
+
export declare const MUSE_SUBMIT_DELAY_MS = 400;
|
|
62
|
+
/**
|
|
63
|
+
* Whether the cursor is hidden after this chunk of program output, given
|
|
64
|
+
* whether it was before. The LAST transition in the chunk wins (a TUI
|
|
65
|
+
* re-asserts its modes on every redraw). A reset counts as showing, because
|
|
66
|
+
* both kinds show the cursor (see TERMINAL_RESET).
|
|
67
|
+
*/
|
|
68
|
+
export declare function cursorHiddenAfter(scan: string, current: boolean): boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Whether bracketed paste (DEC 2004) is on after this chunk of program
|
|
71
|
+
* output, given whether it was before. The twin of `cursorHiddenAfter`, and
|
|
72
|
+
* for the same reason: the emulator the daemon mirrors turns the mode OFF on
|
|
73
|
+
* a reset, so this scan does too. In @xterm/headless both RIS (`ESC c`) and
|
|
74
|
+
* DECSTR (`ESC [ ! p`) reach `CoreService.reset()`, which puts the DEC
|
|
75
|
+
* private modes back to their defaults, where bracketed paste is false.
|
|
76
|
+
*
|
|
77
|
+
* After a reset the program does not expect paste markers, and would read
|
|
78
|
+
* `ESC[200~` and `ESC[201~` around a long write as literal input. The last
|
|
79
|
+
* transition in the chunk wins, as above: a TUI re-asserts its modes on
|
|
80
|
+
* every redraw.
|
|
81
|
+
*/
|
|
82
|
+
export declare function bracketedPasteAfter(scan: string, current: boolean): boolean;
|
|
83
|
+
/**
|
|
84
|
+
* A command that cannot be started as given: a bare name not on PATH, a path
|
|
85
|
+
* that is not an executable file, or on Windows a script started without the
|
|
86
|
+
* shell. A caller error, mapped to 400.
|
|
87
|
+
*/
|
|
88
|
+
export declare class CommandNotFoundError extends Error {
|
|
89
|
+
constructor(message: string);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* The Windows build number of an `os.release()` string (`10.0.19045` → 19045),
|
|
93
|
+
* or 0 when the string names none.
|
|
94
|
+
*/
|
|
95
|
+
export declare function windowsBuildNumber(release: string): number;
|
|
96
|
+
/**
|
|
97
|
+
* The first Windows build with ConPTY, as node-pty's own README states:
|
|
98
|
+
* Windows 10 version 1809, build 18309. node-pty 1.2.0 removed its winpty
|
|
99
|
+
* fallback, so a session cannot start on a build below this.
|
|
100
|
+
*/
|
|
101
|
+
export declare const CONPTY_MINIMUM_BUILD = 18309;
|
|
102
|
+
/**
|
|
103
|
+
* A start on a Windows build with no ConPTY, which node-pty 1.2.0 cannot run
|
|
104
|
+
* a terminal on (it removed the winpty fallback). A caller error, mapped to
|
|
105
|
+
* 400: nothing about the daemon is wrong, and the message names the floor.
|
|
106
|
+
*/
|
|
107
|
+
export declare class WindowsWithoutConPTYError extends Error {
|
|
108
|
+
constructor(build: number);
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Input for a session whose input pipe has failed (Windows): refused, because
|
|
112
|
+
* written it would be lost. The daemon answers it with a 409.
|
|
113
|
+
*/
|
|
114
|
+
export declare class SessionInputFailedError extends Error {
|
|
115
|
+
constructor(id: string, cause: Error);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* A resize of a session whose program node-pty has seen end: refused, as there
|
|
119
|
+
* is no terminal left to resize. It can be asked for in the moment between that
|
|
120
|
+
* end and the session's exit, which follows once node-pty has flushed the last
|
|
121
|
+
* output. The daemon answers it with the 409 a session that has exited gets.
|
|
122
|
+
*/
|
|
123
|
+
export declare class SessionProgramEndedError extends Error {
|
|
124
|
+
readonly sessionId: string;
|
|
125
|
+
readonly exitCode: number;
|
|
126
|
+
constructor(sessionId: string, exitCode: number);
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Resolve a command to a concrete executable path before spawning directly
|
|
130
|
+
* (`shell: false`). Necessary on **every** platform, for different reasons:
|
|
131
|
+
*
|
|
132
|
+
* - **Windows:** node-pty does not search PATH at all, and fails with a bare
|
|
133
|
+
* `File not found:` naming nothing.
|
|
134
|
+
* - **POSIX:** this is worse, because `pty.spawn` of a nonexistent command
|
|
135
|
+
* *succeeds*. execvp fails inside the forked child, the parent never learns
|
|
136
|
+
* and the caller gets a healthy-looking session that is silently dead. An
|
|
137
|
+
* agent would then wait out its full timeout for output that can never
|
|
138
|
+
* arrive.
|
|
139
|
+
*
|
|
140
|
+
* Resolving up front turns both into an immediate, actionable error.
|
|
141
|
+
*
|
|
142
|
+
* On Windows the file found must be a program Windows starts as one: an
|
|
143
|
+
* `.exe` or a `.com`. A batch file (`.bat`, `.cmd`) is refused, because
|
|
144
|
+
* Windows would hand it to cmd.exe with the arguments quoted for a program's
|
|
145
|
+
* parser, which cmd reads by different rules. A `.ps1` or an extensionless
|
|
146
|
+
* script is refused too. A path whose file name contains `:` names an
|
|
147
|
+
* alternate data stream and is refused before anything is opened. A command
|
|
148
|
+
* that contains a path separator and is not absolute is resolved from the
|
|
149
|
+
* session's working directory, and that absolute path is what is checked and
|
|
150
|
+
* what is started.
|
|
151
|
+
*/
|
|
152
|
+
/**
|
|
153
|
+
* Whether a Windows path's file name names an alternate data stream.
|
|
154
|
+
* The last path component holds the stream (`run.cmd:payload.exe`). A drive
|
|
155
|
+
* prefix (`C:`) is never in that component, so `C:\dir\app.exe` and the
|
|
156
|
+
* drive-relative `C:app.exe` are false. Strings only: nothing is opened.
|
|
157
|
+
*/
|
|
158
|
+
export declare function windowsCandidateNamesStream(candidate: string): boolean;
|
|
159
|
+
export interface SessionDeps {
|
|
160
|
+
logger?: Logger;
|
|
161
|
+
/** Platform override, for tests only. Defaults to `process.platform`. */
|
|
162
|
+
platform?: NodeJS.Platform;
|
|
163
|
+
/**
|
|
164
|
+
* Windows release override (`os.release()`), for tests only. Defaults to
|
|
165
|
+
* the real one, whose build number decides the ConPTY floor.
|
|
166
|
+
*/
|
|
167
|
+
osRelease?: string;
|
|
168
|
+
/**
|
|
169
|
+
* How long a kill waits for the deferred program's pid, for tests only.
|
|
170
|
+
* Defaults to `PROGRAM_PID_WAIT_MS`.
|
|
171
|
+
*/
|
|
172
|
+
pidWaitMs?: number;
|
|
173
|
+
/** Environment hygiene mode (design §4.6). Defaults to `DEFAULT_SESSION_ENV`. */
|
|
174
|
+
sessionEnv?: SessionEnvMode;
|
|
175
|
+
/** Windows tree killer override, for tests only. Defaults to `taskkillTrees`. */
|
|
176
|
+
treeKiller?: TreeKiller;
|
|
177
|
+
/**
|
|
178
|
+
* Console-host queue, for tests only. Defaults to the real queue.
|
|
179
|
+
* A session calls it only when `platform` is Windows.
|
|
180
|
+
*/
|
|
181
|
+
queueConsoleHostEnd?: (item: QueuedConsoleHost) => void;
|
|
182
|
+
/** Window registration override, for tests only. */
|
|
183
|
+
registerConsoleHostWindow?: (id: string, window: SpawnWindow, platform: NodeJS.Platform) => void;
|
|
184
|
+
/** Internal second attempt: the retry log already names this session. */
|
|
185
|
+
retryAttempt?: boolean;
|
|
186
|
+
/** PTY spawn, for tests only. Defaults to node-pty. No process is started. */
|
|
187
|
+
spawn?: (file: string, args: string[] | string, options: {
|
|
188
|
+
name: string;
|
|
189
|
+
cols: number;
|
|
190
|
+
rows: number;
|
|
191
|
+
cwd: string;
|
|
192
|
+
env: Record<string, string | undefined>;
|
|
193
|
+
}) => IPty;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* A session gets the clean baseline unless the configuration says otherwise
|
|
197
|
+
* (ADR-008): the daemon's environment is whatever the client that auto-started
|
|
198
|
+
* it had, so passing it on would hand that client's secrets to every session.
|
|
199
|
+
*/
|
|
200
|
+
export declare const DEFAULT_SESSION_ENV: SessionEnvMode;
|
|
201
|
+
/**
|
|
202
|
+
* The names (never the values) of variables in `source` whose names look like
|
|
203
|
+
* credentials, sorted: part of what `passthrough` would hand every session.
|
|
204
|
+
*/
|
|
205
|
+
export declare function credentialShapedNames(source?: NodeJS.ProcessEnv): string[];
|
|
206
|
+
/**
|
|
207
|
+
* Build the PTY environment for a session. Variable-name matching is
|
|
208
|
+
* case-insensitive on every platform: Windows environment names are, and a
|
|
209
|
+
* list in the configuration means the same wherever the daemon runs.
|
|
210
|
+
*
|
|
211
|
+
* An explicit allowlist is the CLEAN baseline plus the listed names: a bare
|
|
212
|
+
* list would strip system scaffolding that processes need to start at all
|
|
213
|
+
* (verified: node.exe aborts in CSPRNG initialisation without `SystemRoot` on
|
|
214
|
+
* Windows), and "functional minimum plus exactly what you name" is the intent
|
|
215
|
+
* of the mode: naming secrets in, not naming plumbing.
|
|
216
|
+
*
|
|
217
|
+
* `passed` is the session's own variables from the client that started it
|
|
218
|
+
* (`SessionOptions.env`), set on top of whatever the mode gave. On Windows a
|
|
219
|
+
* passed name replaces the inherited variable of the same name in any case,
|
|
220
|
+
* rather than sitting beside it as a second copy.
|
|
221
|
+
*
|
|
222
|
+
* A name reserved for a connected feature's credential (ADR-007) is never
|
|
223
|
+
* carried, whichever mode is in force: `passthrough` copies the daemon's
|
|
224
|
+
* environment and a list mode can name anything, so the filter has to sit
|
|
225
|
+
* here rather than in one caller. A session's own `passed` value is not the
|
|
226
|
+
* daemon's copy and is left alone.
|
|
227
|
+
*/
|
|
228
|
+
export declare function buildSessionEnv(mode: SessionEnvMode, platform: NodeJS.Platform, source?: NodeJS.ProcessEnv, passed?: Record<string, string>, reserved?: ReadonlySet<string>): Record<string, string>;
|
|
229
|
+
export declare class Session implements WaitTarget {
|
|
230
|
+
readonly id: string;
|
|
231
|
+
readonly label: string;
|
|
232
|
+
/** What this session is for, for the human watching it. */
|
|
233
|
+
readonly purpose: string;
|
|
234
|
+
/** The audit actor that started it: set by the daemon, not by the body. */
|
|
235
|
+
readonly startedBy: string;
|
|
236
|
+
/** The pre-wrap command as given by the caller. */
|
|
237
|
+
readonly command: string;
|
|
238
|
+
readonly args: string[];
|
|
239
|
+
/** The agent it was started as, which chooses how its screen is read. */
|
|
240
|
+
readonly agent: string | undefined;
|
|
241
|
+
readonly createdAt: Date;
|
|
242
|
+
private readonly pty;
|
|
243
|
+
private readonly renderer;
|
|
244
|
+
private readonly logger;
|
|
245
|
+
private readonly platform;
|
|
246
|
+
private readonly endConsoleHost;
|
|
247
|
+
private readonly registerConsoleHost;
|
|
248
|
+
private readonly spawnPty;
|
|
249
|
+
private readonly treeKiller;
|
|
250
|
+
/** How long a kill waits for the deferred program's pid (a test seam). */
|
|
251
|
+
private readonly pidWaitMs;
|
|
252
|
+
/** Set once a wait for the program's pid has run out (`programPid`). */
|
|
253
|
+
private programWaitExpired;
|
|
254
|
+
/** Whether the program has bracketed paste (DEC 2004) enabled. See PASTE_START. */
|
|
255
|
+
private bracketedPaste;
|
|
256
|
+
/**
|
|
257
|
+
* Whether the most recent `write` took the bracketed-paste branch.
|
|
258
|
+
* Diagnostic only. A program that enabled bracketed paste can still report
|
|
259
|
+
* no markers, and from outside the two causes cannot be told apart: we
|
|
260
|
+
* wrapped and the transport stripped the markers off the input (ConPTY
|
|
261
|
+
* can), or the write raced ahead of the flag. This says which.
|
|
262
|
+
*/
|
|
263
|
+
lastWriteWrapped: boolean | null;
|
|
264
|
+
/** Trailing output kept so a mode sequence split across PTY reads is still seen. */
|
|
265
|
+
private modeScanTail;
|
|
266
|
+
private readonly dataListeners;
|
|
267
|
+
private readonly exitListeners;
|
|
268
|
+
private readonly readyListeners;
|
|
269
|
+
/** Whether the program has hidden the cursor (DECTCEM off), carried to viewers. */
|
|
270
|
+
private cursorHidden;
|
|
271
|
+
/** Serialises write() so chunked writes cannot interleave. See write(). */
|
|
272
|
+
private writeChain;
|
|
273
|
+
private museSubmissionsQueued;
|
|
274
|
+
private readonly musePromptSettler;
|
|
275
|
+
/** Why the input pipe failed (Windows), once it has: input is refused from then on. */
|
|
276
|
+
private inputFailure;
|
|
277
|
+
private lastChange;
|
|
278
|
+
/** Sticky: the rendered screen has shown something at least once. */
|
|
279
|
+
private painted;
|
|
280
|
+
/**
|
|
281
|
+
* The last input written, for the waiter's echo guard. Memory only, never
|
|
282
|
+
* logged: §4.5 keeps keystroke content out of the audit trail, and this
|
|
283
|
+
* is one string overwritten by the next write.
|
|
284
|
+
*/
|
|
285
|
+
private lastInputData;
|
|
286
|
+
/** Which prompt the last input answered, and whether it has since gone. */
|
|
287
|
+
private readonly stalePrompts;
|
|
288
|
+
private exitedFlag;
|
|
289
|
+
private exitedAtValue;
|
|
290
|
+
private exitCodeValue;
|
|
291
|
+
private conptyStartError;
|
|
292
|
+
/** The tree kill under way for a program whose session ended with no exit code. */
|
|
293
|
+
private endingProgram;
|
|
294
|
+
private readyFlag;
|
|
295
|
+
private readyReasonValue;
|
|
296
|
+
private geometryHeldFlag;
|
|
297
|
+
private killPromise;
|
|
298
|
+
private consoleHostSettlement;
|
|
299
|
+
/**
|
|
300
|
+
* Times taken immediately before and after the spawn, on Windows. ConPTY
|
|
301
|
+
* creates the console host during that call. Null on any other platform.
|
|
302
|
+
*/
|
|
303
|
+
private consoleHostWindow;
|
|
304
|
+
/** The end has been queued once. A kill and an exit must not queue it twice. */
|
|
305
|
+
private consoleHostQueued;
|
|
306
|
+
constructor(id: string, options: SessionOptions, deps?: SessionDeps);
|
|
307
|
+
/**
|
|
308
|
+
* Windows default: wrap in `cmd.exe` (§7: direct ConPTY spawns of
|
|
309
|
+
* single-file binaries hang). POSIX default: direct spawn; `shell: true`
|
|
310
|
+
* wraps in `/bin/sh -c`.
|
|
311
|
+
*
|
|
312
|
+
* The Windows form is `cmd.exe /d /s /c "<line>"` passed as a VERBATIM
|
|
313
|
+
* string (node-pty applies no quoting to string args). `/s` pins cmd's
|
|
314
|
+
* strip-first-and-last-quote behaviour so the outer quotes vanish cleanly
|
|
315
|
+
* and every quote inside `<line>` survives. Without it, a command path
|
|
316
|
+
* containing spaces (e.g. `C:\Program Files\nodejs\node.exe`) is split at
|
|
317
|
+
* the first space. This is the same invocation libuv uses for shell spawns.
|
|
318
|
+
*/
|
|
319
|
+
private wrapCommand;
|
|
320
|
+
get pid(): number;
|
|
321
|
+
get cols(): number;
|
|
322
|
+
get rows(): number;
|
|
323
|
+
get ready(): boolean;
|
|
324
|
+
/** Why `ready` holds its value. See {@link SessionSummary.readyReason}. */
|
|
325
|
+
get readyReason(): SessionSummary['readyReason'];
|
|
326
|
+
/**
|
|
327
|
+
* True only when the grid is HELD: `hold` at start, or a resize that asked
|
|
328
|
+
* for it. A held grid keeps its size while viewports connect and reshape
|
|
329
|
+
* themselves around it; an unheld grid belongs to the controlling viewport,
|
|
330
|
+
* which fits it to the human's window (design §5).
|
|
331
|
+
*/
|
|
332
|
+
get geometryHeld(): boolean;
|
|
333
|
+
get exited(): boolean;
|
|
334
|
+
/** Epoch ms of process exit: the manager's reap grace counts from here. */
|
|
335
|
+
get exitedAt(): number | null;
|
|
336
|
+
/**
|
|
337
|
+
* The program's exit code once the session has ended. Null while it runs,
|
|
338
|
+
* and for a session that ended with no code because its output failed: the
|
|
339
|
+
* code node-pty records for its program afterwards is not reported
|
|
340
|
+
* (`howSessionEnded`).
|
|
341
|
+
*/
|
|
342
|
+
get exitCode(): number | null;
|
|
343
|
+
/**
|
|
344
|
+
* Whether the session's program is known to have ended: node-pty has
|
|
345
|
+
* recorded its exit code, or its exit came with a code. Until then its
|
|
346
|
+
* tree is walked. The recorded code is enough on its own, before this
|
|
347
|
+
* session's exit event: node-pty closes the process handle first, so the
|
|
348
|
+
* pid is already free. Where node-pty records none (`canReadExitCode`),
|
|
349
|
+
* an exit with no code counts as the end: a pid nothing vouches for is
|
|
350
|
+
* never walked.
|
|
351
|
+
*/
|
|
352
|
+
get programEnded(): boolean;
|
|
353
|
+
/** Whether the input pipe has failed (Windows): input is refused from then on. */
|
|
354
|
+
get inputFailed(): boolean;
|
|
355
|
+
get watchers(): number;
|
|
356
|
+
getScreen(): string;
|
|
357
|
+
lastChangeAt(): number;
|
|
358
|
+
isExited(): boolean;
|
|
359
|
+
hasPainted(): boolean;
|
|
360
|
+
lastInput(): string | null;
|
|
361
|
+
observePrompt(signature: string | null): void;
|
|
362
|
+
isStalePrompt(signature: string): boolean;
|
|
363
|
+
/**
|
|
364
|
+
* Write to the PTY the way the program on the other end asked to be written
|
|
365
|
+
* to: as a bracketed paste when it enabled that mode, otherwise chunked.
|
|
366
|
+
*
|
|
367
|
+
* Anything under WRITE_CHUNK_CHARS goes straight through either way, so keys
|
|
368
|
+
* and human typing are unaffected. Above it the two paths diverge, and the
|
|
369
|
+
* divergence is the point. See PASTE_START for the evidence that chunking a
|
|
370
|
+
* TUI's input is what loses the front of a long prompt.
|
|
371
|
+
*
|
|
372
|
+
* **Writes are serialised.** The chunked path yields between pieces, and this
|
|
373
|
+
* tool's whole premise is that a human and an agent share one session. So
|
|
374
|
+
* without a queue a keystroke (or a multi-character paste, which is what xterm
|
|
375
|
+
* hands us for a clipboard drop) could land *between* an earlier write's
|
|
376
|
+
* chunks and interleave two inputs into gibberish. Making that ordering the
|
|
377
|
+
* caller's problem would be a trap; the queue keeps writes in call order,
|
|
378
|
+
* as a synchronous write would.
|
|
379
|
+
*
|
|
380
|
+
* Resolves with the screen as it was rendered just before this input went
|
|
381
|
+
* in, taken in the queue, so an earlier write still going in cannot be
|
|
382
|
+
* mistaken for this one's effect (`terminal_type`'s verify compares with it).
|
|
383
|
+
*
|
|
384
|
+
* Rejects with `SessionInputFailedError` once the input pipe has failed,
|
|
385
|
+
* including for the rest of a chunked write it fails part-way through.
|
|
386
|
+
*/
|
|
387
|
+
write(data: string): Promise<string>;
|
|
388
|
+
private writeInput;
|
|
389
|
+
private writeData;
|
|
390
|
+
/** Input written after the input pipe has failed would be lost: refuse it. */
|
|
391
|
+
private refuseIfInputFailed;
|
|
392
|
+
private refuseIfEnded;
|
|
393
|
+
/**
|
|
394
|
+
* Resize the PTY.
|
|
395
|
+
*
|
|
396
|
+
* Every caller arrives here, a viewport whose window changed shape and an
|
|
397
|
+
* agent asking for a specific grid alike, because the resize itself is the
|
|
398
|
+
* same act either way. What differs is only whether the caller also means to stop
|
|
399
|
+
* anyone else changing it, and that is said explicitly with `hold` rather
|
|
400
|
+
* than inferred from who is calling. Omitting `hold` leaves the current
|
|
401
|
+
* setting alone, so a viewport following a window cannot quietly release a
|
|
402
|
+
* hold that a scripted run is relying on.
|
|
403
|
+
*
|
|
404
|
+
* Throws `SessionProgramEndedError` once node-pty has seen the program end,
|
|
405
|
+
* where it records that (`recordedExitCode`): there is no terminal left to
|
|
406
|
+
* resize, and node-pty itself throws for that on a Windows terminal that has
|
|
407
|
+
* drawn.
|
|
408
|
+
* On Windows a resize asked for before the terminal's first output is held
|
|
409
|
+
* by node-pty and run later; one that finds the program ended by then is
|
|
410
|
+
* dropped (`windowsPtyStart.ts`).
|
|
411
|
+
*/
|
|
412
|
+
resize(cols: number, rows: number, options?: {
|
|
413
|
+
hold?: boolean;
|
|
414
|
+
}): void | Promise<void>;
|
|
415
|
+
private resizeNow;
|
|
416
|
+
answerablePrompt(screen: string, now?: number): ReturnType<typeof detectPrompt>;
|
|
417
|
+
/** Live raw-stream subscription (viewer mirroring). Returns unsubscribe. */
|
|
418
|
+
onData(listener: (data: string) => void): () => void;
|
|
419
|
+
onExit(listener: (exitCode: number | null) => void): () => void;
|
|
420
|
+
/** Notify the daemon when the readiness condition settles. */
|
|
421
|
+
onReady(listener: () => void): () => void;
|
|
422
|
+
/**
|
|
423
|
+
* The rendered terminal as bytes that rebuild it in a fresh terminal of the
|
|
424
|
+
* same size (design §5): what a viewer receives on connect and after every
|
|
425
|
+
* grid change, in place of any slice of the raw stream. A slice starts
|
|
426
|
+
* mid-frame, and a program that only repaints what changed never puts the
|
|
427
|
+
* rest of its frame back. Every agent CLI repaints that way once its chrome
|
|
428
|
+
* is up, and on Windows every program does as ConPTY relays it. Resolves
|
|
429
|
+
* once every byte received before the call has been parsed, and includes
|
|
430
|
+
* nothing received after it.
|
|
431
|
+
*/
|
|
432
|
+
viewerState(options?: SerializeOptions): Promise<string>;
|
|
433
|
+
/** The filter's styled rows and the viewer replay from one rendered frame. */
|
|
434
|
+
captureViewerScreen(above: number, scrollback: number): Promise<{
|
|
435
|
+
view: {
|
|
436
|
+
lines: StyledLine[];
|
|
437
|
+
firstVisible: number;
|
|
438
|
+
};
|
|
439
|
+
state: string;
|
|
440
|
+
cols: number;
|
|
441
|
+
rows: number;
|
|
442
|
+
}>;
|
|
443
|
+
snapshot(): Promise<ScreenSnapshot>;
|
|
444
|
+
/** Last N lines including scrollback (design §3). */
|
|
445
|
+
lastLines(count: number): Promise<string[]>;
|
|
446
|
+
/** Current viewport lines (for `terminal_find`). */
|
|
447
|
+
viewportLines(): Promise<string[]>;
|
|
448
|
+
/**
|
|
449
|
+
* The viewport with `above` lines of scrollback over it, as drawn
|
|
450
|
+
* (`reasoning.ts`). `firstVisible` is where the viewport begins.
|
|
451
|
+
*/
|
|
452
|
+
styledScreen(above?: number): Promise<{
|
|
453
|
+
lines: StyledLine[];
|
|
454
|
+
firstVisible: number;
|
|
455
|
+
}>;
|
|
456
|
+
/** Current rendered rows for a waiter evaluation, which already reads synchronously. */
|
|
457
|
+
styledScreenNow(above?: number): {
|
|
458
|
+
lines: StyledLine[];
|
|
459
|
+
firstVisible: number;
|
|
460
|
+
};
|
|
461
|
+
/**
|
|
462
|
+
* The last `count` lines, scrollback included, as drawn, with up to
|
|
463
|
+
* `context` more lines over them; `firstVisible` is where the `count` begin.
|
|
464
|
+
*/
|
|
465
|
+
styledTail(count: number, context?: number): Promise<{
|
|
466
|
+
lines: StyledLine[];
|
|
467
|
+
firstVisible: number;
|
|
468
|
+
}>;
|
|
469
|
+
waitFor(condition: WaitCondition, options?: WaitOptions & WaiterInternals): Promise<WaitResult>;
|
|
470
|
+
summary(): SessionSummary;
|
|
471
|
+
/**
|
|
472
|
+
* Kill the whole process tree (design §3.1). Commands are shell-wrapped, so
|
|
473
|
+
* killing only the direct child (`cmd.exe`) strands the real application,
|
|
474
|
+
* and orphaned agent CLIs keep running and keep spending paid API tokens.
|
|
475
|
+
*
|
|
476
|
+
* Windows: `taskkill /T /F` walks and kills the tree, then `pty.kill()` runs.
|
|
477
|
+
* node-pty's kill ends no process of its own
|
|
478
|
+
* (`listNothingToKill` in `windowsPtyStart.ts`), and it closes the
|
|
479
|
+
* pseudoconsole, which sends CTRL_CLOSE_EVENT to the processes on the
|
|
480
|
+
* console, only while node-pty still holds the terminal: while the program
|
|
481
|
+
* runs. After a tree kill that ended the program, its kill closes nothing,
|
|
482
|
+
* so a process on the session's console outside the killed tree gets no
|
|
483
|
+
* close event. The console host is not in that tree. After this returns, a
|
|
484
|
+
* later list ends the one host created during this spawn's window. This does
|
|
485
|
+
* not wait for that list. The daemon's pseudoconsole handle stays open, and
|
|
486
|
+
* the host is given no CTRL_CLOSE_EVENT. (The design's Job
|
|
487
|
+
* Object hardening needs a native module and is
|
|
488
|
+
* deferred. If the daemon itself dies, its pseudoconsole handles close,
|
|
489
|
+
* which gives console-attached descendants a close signal.)
|
|
490
|
+
*
|
|
491
|
+
* POSIX: the PTY child is the session leader of its own process group, so
|
|
492
|
+
* signalling the negated pid takes the group down.
|
|
493
|
+
*
|
|
494
|
+
* The OS tree kill runs only while the root is still alive. A session whose
|
|
495
|
+
* program exited on its own is reaped fifteen minutes later, and by then the
|
|
496
|
+
* process group id may have been recycled, so an unconditional `kill(-pid)`
|
|
497
|
+
* could take down something unrelated; on Windows `taskkill` cannot walk a
|
|
498
|
+
* tree from a dead root either. So a grandchild that outlived its parent is
|
|
499
|
+
* left alone rather than guessed at, a residual risk stated in
|
|
500
|
+
* `docs/reference/security-model.md`. A session whose program has not been
|
|
501
|
+
* seen to end (`programEnded`) is walked, whether or not the session has
|
|
502
|
+
* ended. node-pty holds such a program's handle while it runs and closes it
|
|
503
|
+
* as it sees the program end, a moment before the code is recorded, so a
|
|
504
|
+
* kill in that moment can reach a pid just freed: the same kind of race
|
|
505
|
+
* every kill has while `taskkill` enumerates the processes. Once the code
|
|
506
|
+
* is recorded the pid is not walked.
|
|
507
|
+
*/
|
|
508
|
+
kill(): Promise<void>;
|
|
509
|
+
/** True from the moment a kill begins, including while it waits for a pid. */
|
|
510
|
+
get isKilled(): boolean;
|
|
511
|
+
private killOnce;
|
|
512
|
+
/**
|
|
513
|
+
* Queue an end of this session's console host, once. The list runs later
|
|
514
|
+
* and is not awaited. With no window there is nothing to end. On any
|
|
515
|
+
* platform but Windows the queue does nothing.
|
|
516
|
+
*/
|
|
517
|
+
private queueConsoleHost;
|
|
518
|
+
/** The failed attempt's own console-host result, after it has been queued. */
|
|
519
|
+
whenConsoleHostSettled(): Promise<boolean>;
|
|
520
|
+
/**
|
|
521
|
+
* The program's pid, waiting for node-pty's deferred program creation:
|
|
522
|
+
* on Windows the pid is 0 from the spawn until the output worker has
|
|
523
|
+
* connected and the program exists, and a start whose connection fails
|
|
524
|
+
* reports an exit instead of a pid, which ends the wait. POSIX reports the
|
|
525
|
+
* pid at the spawn, so nothing is waited for there.
|
|
526
|
+
*/
|
|
527
|
+
private programPid;
|
|
528
|
+
/**
|
|
529
|
+
* The program's pid once node-pty has created it, or null when the session
|
|
530
|
+
* ended before any program existed: a start whose ConPTY output worker
|
|
531
|
+
* never connected, or one Windows refused the program of. The start
|
|
532
|
+
* contract waits here: a session is reported as started only once its
|
|
533
|
+
* program exists, as node-pty 1.1.0's synchronous spawn guaranteed.
|
|
534
|
+
*/
|
|
535
|
+
startedProgramPid(): Promise<number | null>;
|
|
536
|
+
/** Only the pinned node-pty timeout, before a program exists, can be retried. */
|
|
537
|
+
get conptyConnectionTimedOut(): boolean;
|
|
538
|
+
/**
|
|
539
|
+
* What went wrong, for a start that ended before any program existed
|
|
540
|
+
* (`startedProgramPid` returned null): node-pty 1.1.0's own words for a
|
|
541
|
+
* program Windows would not create, with Windows' code; for the connection
|
|
542
|
+
* bound, which 1.1.0 did not have, what actually ran out.
|
|
543
|
+
*/
|
|
544
|
+
startFailure(): string;
|
|
545
|
+
/**
|
|
546
|
+
* End the program of a session that ended with no exit code: node-pty
|
|
547
|
+
* closed its terminal when its output failed, and the program would run on
|
|
548
|
+
* where nobody can read or type into it, for an agent CLI still acting and
|
|
549
|
+
* spending. The same tree kill a kill uses. It runs only after the exit, so
|
|
550
|
+
* the pid is never waited for here; a pid of 0 (no program was created) is
|
|
551
|
+
* skipped by the tree kill. Never rejects.
|
|
552
|
+
*/
|
|
553
|
+
private endProgram;
|
|
554
|
+
/**
|
|
555
|
+
* The OS tree kill of `kill()`, for a program that may still be running:
|
|
556
|
+
* `taskkill /T /F` from a live root on Windows, the process group on POSIX.
|
|
557
|
+
* Never rejects.
|
|
558
|
+
*/
|
|
559
|
+
private killTree;
|
|
560
|
+
/**
|
|
561
|
+
* Cheap liveness probe: signal 0 performs the permission and existence
|
|
562
|
+
* checks without delivering a signal, on Windows as well as POSIX.
|
|
563
|
+
*/
|
|
564
|
+
private processAlive;
|
|
565
|
+
}
|