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,226 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Opening the viewer in its own browser window.
|
|
3
|
+
*
|
|
4
|
+
* Two problems with handing the URL to the default browser
|
|
5
|
+
* (`launchMode: "default-browser"`), which opens it in the user's normal
|
|
6
|
+
* profile:
|
|
7
|
+
*
|
|
8
|
+
* 1. The viewer then shares a browsing context with every other page that
|
|
9
|
+
* profile has open: cookie jar, storage and history. Loopback is not a boundary
|
|
10
|
+
* against the browser itself. The daemon's Host/Origin checks and bearer
|
|
11
|
+
* auth (§4.2) are what holds this; a separate profile removes the exposure
|
|
12
|
+
* rather than defending it.
|
|
13
|
+
* 2. The viewer grant is in the URL, so it lands in that profile's history.
|
|
14
|
+
*
|
|
15
|
+
* **Why no bundled browser.** The viewer IS a web page: a browser is already a
|
|
16
|
+
* hard prerequisite for ShellPuppet to be usable at all. Bundling one
|
|
17
|
+
* (Playwright's ~130 MB download, or Electron) adds a very large dependency to
|
|
18
|
+
* solve a problem every user already has a browser for. Playwright is the
|
|
19
|
+
* wrong shape besides, being built to DRIVE a page while here a human does.
|
|
20
|
+
* So: detect an installed Chromium-family browser, and degrade gracefully when
|
|
21
|
+
* there is none. `chrome-launcher` (Apache-2.0, ~140 KB) does the fiddly
|
|
22
|
+
* cross-platform detection, which is exactly the part that would otherwise
|
|
23
|
+
* be machine-specific guesswork: the install folders on Windows,
|
|
24
|
+
* LaunchServices on macOS, `.desktop` files and PATH on Linux. On macOS and
|
|
25
|
+
* Linux the part of that search which shells out runs in a child process,
|
|
26
|
+
* never in the daemon (`detectBrowser`); on Windows the paths checked by
|
|
27
|
+
* file access are the whole search, so the child is not run. A lookup that
|
|
28
|
+
* times out, crashes or returns something other than a JSON list is logged
|
|
29
|
+
* once. We spawn the browser ourselves, because the detachment discipline
|
|
30
|
+
* below is not negotiable.
|
|
31
|
+
*
|
|
32
|
+
* Nothing here may ever fail a session start. A browser that will not launch is
|
|
33
|
+
* an inconvenience: the launcher reports that nothing opened, the daemon hands
|
|
34
|
+
* the caller the URL instead, and the human can open it themselves. That report
|
|
35
|
+
* has to be truthful, because the caller is told the human needs no link when a
|
|
36
|
+
* window opened: a spawn settles on the child's `spawn` or `error` event, and
|
|
37
|
+
* the system's opener (`start`, `open`, `xdg-open`) on its exit code.
|
|
38
|
+
*/
|
|
39
|
+
import { type Logger } from '../core/types.js';
|
|
40
|
+
export type ViewerLaunchMode = 'dashboard' | 'isolated-app' | 'default-browser' | 'no-window';
|
|
41
|
+
export interface ViewerLaunchConfig {
|
|
42
|
+
launchMode?: ViewerLaunchMode;
|
|
43
|
+
/** Explicit browser binary, overriding detection entirely. */
|
|
44
|
+
browserPath?: string;
|
|
45
|
+
/** Where the isolated profile lives. Defaults to <home>/viewer-profile. */
|
|
46
|
+
profileDir?: string;
|
|
47
|
+
}
|
|
48
|
+
export interface ViewerLaunchResult {
|
|
49
|
+
launched: boolean;
|
|
50
|
+
mode: ViewerLaunchMode;
|
|
51
|
+
/** The browser used, when one was detected. */
|
|
52
|
+
browser?: string;
|
|
53
|
+
/**
|
|
54
|
+
* Why nothing opened, when nothing did; or, beside `launched: true`, why the
|
|
55
|
+
* default browser was used instead of the isolated window.
|
|
56
|
+
*/
|
|
57
|
+
reason?: string;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Chromium-family browsers that `chrome-launcher` does NOT look for, checked
|
|
61
|
+
* after it. Edge earns its place: it ships with Windows, so including it means
|
|
62
|
+
* a Windows machine effectively always has a usable browser even with no
|
|
63
|
+
* Chrome installed. Paths only, never a bare name, because a bare name would
|
|
64
|
+
* resolve against PATH and PATH is attacker-influenced on a shared machine.
|
|
65
|
+
*/
|
|
66
|
+
export declare function extraBrowserCandidates(): string[];
|
|
67
|
+
/**
|
|
68
|
+
* The Chrome installations `chrome-launcher` checks by file access alone,
|
|
69
|
+
* before any lookup that shells out, in the order it ranks them: the
|
|
70
|
+
* `CHROME_PATH` and `LIGHTHOUSE_CHROMIUM_PATH` overrides first everywhere; on
|
|
71
|
+
* Windows its whole search, which is these paths and nothing else; on macOS
|
|
72
|
+
* the two `/Applications` bundles its own `getFirstInstallation()` checks
|
|
73
|
+
* before its LaunchServices query, which rank above anything that query
|
|
74
|
+
* finds. Linux has only the overrides here: its lookup reads `.desktop` files
|
|
75
|
+
* and PATH, which a fixed list cannot match.
|
|
76
|
+
*/
|
|
77
|
+
export declare function wellKnownChromePaths(platform?: NodeJS.Platform, env?: NodeJS.ProcessEnv): string[];
|
|
78
|
+
/** Where browser detection looks, in the order it looks. */
|
|
79
|
+
export interface BrowserDetection {
|
|
80
|
+
/** Checked first, by file access alone. */
|
|
81
|
+
wellKnown: string[];
|
|
82
|
+
/**
|
|
83
|
+
* A module exporting chrome-launcher's `Launcher`, as a file URL. A child
|
|
84
|
+
* process imports it and runs `Launcher.getInstallations()`. Empty skips
|
|
85
|
+
* the lookup.
|
|
86
|
+
*/
|
|
87
|
+
lookupModule: string;
|
|
88
|
+
/** How long the child process may take before it is ended and counts as finding nothing. */
|
|
89
|
+
lookupTimeoutMs: number;
|
|
90
|
+
/** Checked last, by file access alone. */
|
|
91
|
+
extra: string[];
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* How long chrome-launcher's full lookup may take. Its macOS query took 5.7 s
|
|
95
|
+
* and 9.7 s on macOS CI runners, so this leaves room for a slower machine.
|
|
96
|
+
*/
|
|
97
|
+
export declare const BROWSER_LOOKUP_TIMEOUT_MS = 30000;
|
|
98
|
+
/** The detection the daemon runs: chrome-launcher's, then the supplementary list. */
|
|
99
|
+
export declare function defaultBrowserDetection(): BrowserDetection;
|
|
100
|
+
/**
|
|
101
|
+
* Find a Chromium-family browser, or null. Detection can never stop the
|
|
102
|
+
* daemon from serving: nothing here throws, and no part of it holds the
|
|
103
|
+
* daemon's event loop (see `detectBrowser`).
|
|
104
|
+
*/
|
|
105
|
+
export declare function findBrowser(explicitPath?: string, logger?: Logger): Promise<string | null>;
|
|
106
|
+
/** Test hook: forget the memoised browser so detection runs again. */
|
|
107
|
+
export declare function resetBrowserCache(): void;
|
|
108
|
+
/**
|
|
109
|
+
* Detect a browser without holding the daemon's event loop. chrome-launcher's
|
|
110
|
+
* lookup is synchronous and shells out on macOS (`lsregister -dump`, seconds)
|
|
111
|
+
* and Linux (`grep` over `.desktop` files, `which`). Run in the daemon, it
|
|
112
|
+
* would stop `/health` and every other request being answered while it ran,
|
|
113
|
+
* on macOS for long enough that a client gives up on a daemon it has just
|
|
114
|
+
* started. So the paths chrome-launcher itself checks first are tried with
|
|
115
|
+
* asynchronous file checks; only when none exists does its full lookup run,
|
|
116
|
+
* in a child process; and the supplementary list is checked last. On Windows
|
|
117
|
+
* the default detection leaves that lookup empty, because the well-known
|
|
118
|
+
* paths are the whole search. The answer is the one chrome-launcher's own
|
|
119
|
+
* ranking gives, then the first supplementary browser present. A lookup that
|
|
120
|
+
* times out, crashes or prints something other than a JSON list is logged
|
|
121
|
+
* once, through `logger`.
|
|
122
|
+
*/
|
|
123
|
+
export declare function detectBrowser(detection?: BrowserDetection, logger?: Logger): Promise<string | null>;
|
|
124
|
+
/**
|
|
125
|
+
* Open `url` in a chromeless window backed by its own browser profile.
|
|
126
|
+
*
|
|
127
|
+
* `--app=` removes the address bar, tabs and navigation. A terminal viewer has
|
|
128
|
+
* no use for them, and the address bar is where the viewer grant would
|
|
129
|
+
* otherwise be on display. `--user-data-dir` is the isolation: its own cookie
|
|
130
|
+
* jar, storage and history, invisible to the user's normal browsing and vice
|
|
131
|
+
* versa.
|
|
132
|
+
*
|
|
133
|
+
* The profile directory is per-daemon rather than per-session, so window
|
|
134
|
+
* position and the text-size preference persist across sessions. A per-session
|
|
135
|
+
* profile would isolate marginally harder at the cost of a cold browser start
|
|
136
|
+
* every time, which is the wrong trade for a window a human is meant to keep
|
|
137
|
+
* open and glance at.
|
|
138
|
+
*/
|
|
139
|
+
export declare function isolatedWindowArgs(url: string, profileDir: string): string[];
|
|
140
|
+
/**
|
|
141
|
+
* Switches that ask a Chromium-family browser ShellPuppet starts, the viewer
|
|
142
|
+
* window and the screenshot browser alike, to make no network requests of its
|
|
143
|
+
* own: updates, reports and the services a browser contacts in the
|
|
144
|
+
* background. Nothing leaves the machine unless a human sends it or switches
|
|
145
|
+
* it on, and nobody asked these browsers to call anywhere. Each switch is
|
|
146
|
+
* documented in Chromium's source, named beside it; none changes what a page
|
|
147
|
+
* can do, so the viewer and its WebSocket to the daemon work as they would
|
|
148
|
+
* without them.
|
|
149
|
+
*
|
|
150
|
+
* They ask, and they do not reach everything. A NetLog of a fresh Chrome
|
|
151
|
+
* started with them, over its first minute, still showed its component
|
|
152
|
+
* updater, a Safe Browsing key fetch, an account check and a search endpoint
|
|
153
|
+
* contacted, none of which these switches turn off; a vendor's own services,
|
|
154
|
+
* such as Edge's, may be beyond Chromium's switches too.
|
|
155
|
+
*/
|
|
156
|
+
export declare const QUIET_BROWSER_SWITCHES: readonly string[];
|
|
157
|
+
/**
|
|
158
|
+
* What a test may inject in place of the platform's opener command, so the
|
|
159
|
+
* default-browser path can be exercised without opening a browser.
|
|
160
|
+
*/
|
|
161
|
+
export interface LaunchDependencies {
|
|
162
|
+
opener?: (url: string) => DefaultBrowserCommand;
|
|
163
|
+
/** How long to wait for the opener's exit code; `OPENER_SETTLE_MS` by default. */
|
|
164
|
+
openerSettleMs?: number;
|
|
165
|
+
/** Checked after detection and immediately before an isolated browser spawn. */
|
|
166
|
+
shouldLaunch?: () => boolean;
|
|
167
|
+
/** Test seams for the two sides of the shutdown race. */
|
|
168
|
+
findBrowser?: typeof findBrowser;
|
|
169
|
+
spawnIsolated?: (command: string, args: string[]) => Promise<SpawnOutcome>;
|
|
170
|
+
}
|
|
171
|
+
export declare function launchViewer(url: string, home: string, config: ViewerLaunchConfig, logger: Logger, deps?: LaunchDependencies): Promise<ViewerLaunchResult>;
|
|
172
|
+
/**
|
|
173
|
+
* Open the dashboard in ShellPuppet's isolated browser profile, and never in
|
|
174
|
+
* the person's default browser.
|
|
175
|
+
*
|
|
176
|
+
* The dashboard URL carries the one-use grant, so the profile it lands in has
|
|
177
|
+
* to be the one ShellPuppet owns. `viewer.launchMode` is deliberately not
|
|
178
|
+
* consulted: `shellpuppet dashboard` exists to open a window, and a mode meant
|
|
179
|
+
* for automatic viewer windows must not turn that into a default-browser
|
|
180
|
+
* hand-off. `viewer.browserPath` and `viewer.profileDir` still apply.
|
|
181
|
+
*
|
|
182
|
+
* `deps` is accepted so a test can inject a recording opener and prove that a
|
|
183
|
+
* failure never reaches it.
|
|
184
|
+
*/
|
|
185
|
+
export declare function launchDashboard(url: string, home: string, config: ViewerLaunchConfig, logger: Logger, deps?: LaunchDependencies): Promise<ViewerLaunchResult>;
|
|
186
|
+
/** How to hand a URL to the platform's default browser. */
|
|
187
|
+
export interface DefaultBrowserCommand {
|
|
188
|
+
command: string;
|
|
189
|
+
args: string[];
|
|
190
|
+
/** Windows only: pass `args` to the command line exactly as written. */
|
|
191
|
+
windowsVerbatimArguments: boolean;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* The command that opens `url` in the default browser.
|
|
195
|
+
*
|
|
196
|
+
* On Windows that is cmd's `start` builtin, so the URL passes through cmd's
|
|
197
|
+
* command-line parser, where an unquoted `&` ends a command. The viewer URL
|
|
198
|
+
* holds one (`?s=<id>&vt=<grant>`), and Node quotes an argument only when it
|
|
199
|
+
* holds a space, so the URL goes over verbatim inside double quotes. Within
|
|
200
|
+
* quotes cmd still expands `%NAME%`, and `!NAME!` where delayed expansion is
|
|
201
|
+
* switched on in the registry; a `"` ends the quoting and a line break ends
|
|
202
|
+
* the command. A URL holding any of those is refused rather than handed over.
|
|
203
|
+
* The empty `""` is `start`'s window title, without which it would take the
|
|
204
|
+
* quoted URL as the title. `/d` skips cmd's AutoRun commands.
|
|
205
|
+
*/
|
|
206
|
+
export declare function defaultBrowserCommand(url: string, platform?: NodeJS.Platform, comspec?: string | undefined): DefaultBrowserCommand;
|
|
207
|
+
/**
|
|
208
|
+
* How long to wait for the system's opener to say whether it managed. `start`,
|
|
209
|
+
* `open` and `xdg-open` return within a fraction of a second, with a non-zero
|
|
210
|
+
* code when they could hand the URL to nothing (no display, no registered
|
|
211
|
+
* browser). An opener still running after this is taken to have become the
|
|
212
|
+
* browser itself, which `xdg-open` does on some desktops.
|
|
213
|
+
*/
|
|
214
|
+
export declare const OPENER_SETTLE_MS = 1500;
|
|
215
|
+
/** What became of a detached spawn. */
|
|
216
|
+
export interface SpawnOutcome {
|
|
217
|
+
/** The process started. False when it could not be executed at all. */
|
|
218
|
+
spawned: boolean;
|
|
219
|
+
/** Why it could not start. */
|
|
220
|
+
error?: string;
|
|
221
|
+
/**
|
|
222
|
+
* Its exit code, when `settleMs` was given and it ended within that time;
|
|
223
|
+
* `null` means a signal ended it.
|
|
224
|
+
*/
|
|
225
|
+
exitCode?: number | null;
|
|
226
|
+
}
|