playwright-repl 0.3.0 → 0.7.10

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,13 @@
1
+ /**
2
+ * playwright-repl — public API
3
+ *
4
+ * Usage as CLI:
5
+ * npx playwright-repl [options]
6
+ *
7
+ * Usage as library:
8
+ * import { Engine, parseInput, SessionRecorder } from 'playwright-repl';
9
+ */
10
+ export { parseInput, ALIASES, ALL_COMMANDS, buildCompletionItems, Engine } from '@playwright-repl/core';
11
+ export { SessionRecorder, SessionPlayer } from './recorder.js';
12
+ export { startRepl } from './repl.js';
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAGxG,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,15 @@
1
+ /**
2
+ * playwright-repl — public API
3
+ *
4
+ * Usage as CLI:
5
+ * npx playwright-repl [options]
6
+ *
7
+ * Usage as library:
8
+ * import { Engine, parseInput, SessionRecorder } from 'playwright-repl';
9
+ */
10
+ // Re-export core
11
+ export { parseInput, ALIASES, ALL_COMMANDS, buildCompletionItems, Engine } from '@playwright-repl/core';
12
+ // CLI-specific
13
+ export { SessionRecorder, SessionPlayer } from './recorder.js';
14
+ export { startRepl } from './repl.js';
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,iBAAiB;AACjB,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAExG,eAAe;AACf,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC"}
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * playwright-repl CLI entry point.
4
+ *
5
+ * Usage:
6
+ * playwright-repl [options]
7
+ * playwright-repl --replay session.pw
8
+ * playwright-repl --replay session.pw --step
9
+ * playwright-repl --replay file1.pw file2.pw
10
+ * playwright-repl --replay examples/
11
+ * playwright-repl --record my-test.pw
12
+ */
13
+ export {};
14
+ //# sourceMappingURL=playwright-repl.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"playwright-repl.d.ts","sourceRoot":"","sources":["../src/playwright-repl.ts"],"names":[],"mappings":";AAEA;;;;;;;;;;GAUG"}
@@ -0,0 +1,107 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * playwright-repl CLI entry point.
4
+ *
5
+ * Usage:
6
+ * playwright-repl [options]
7
+ * playwright-repl --replay session.pw
8
+ * playwright-repl --replay session.pw --step
9
+ * playwright-repl --replay file1.pw file2.pw
10
+ * playwright-repl --replay examples/
11
+ * playwright-repl --record my-test.pw
12
+ */
13
+ import { minimist } from '@playwright-repl/core';
14
+ import { startRepl } from './repl.js';
15
+ const args = minimist(process.argv.slice(2), {
16
+ boolean: ['headed', 'persistent', 'extension', 'help', 'step', 'silent', 'spawn'],
17
+ string: ['session', 'browser', 'profile', 'config', 'replay', 'record', 'connect', 'port', 'cdp-port'],
18
+ alias: { s: 'session', h: 'help', b: 'browser', q: 'silent' },
19
+ default: { session: 'default' },
20
+ });
21
+ // --connect without a value → default port 9222
22
+ if (args.connect === '')
23
+ args.connect = 9222;
24
+ else if (args.connect)
25
+ args.connect = parseInt(args.connect, 10) || 9222;
26
+ if (args.help) {
27
+ console.log(`
28
+ playwright-repl - Interactive REPL for Playwright browser automation
29
+
30
+ Usage:
31
+ playwright-repl [options]
32
+
33
+ Options:
34
+ -s, --session <name> Session name (default: "default")
35
+ -b, --browser <type> Browser: chrome, firefox, webkit, msedge
36
+ --headed Run browser in headed mode
37
+ --persistent Use persistent browser profile
38
+ --profile <dir> Persistent profile directory
39
+ --connect [port] Connect to existing Chrome via CDP (default: 9222)
40
+ --extension Connect to Chrome with side panel extension
41
+ --spawn Spawn Chrome automatically (default: connect to existing)
42
+ --port <number> Extension server port (default: 6781)
43
+ --cdp-port <number> Chrome CDP port (default: 9222)
44
+ --config <file> Path to config file
45
+ --replay <files...> Replay .pw file(s) or folder(s)
46
+ --record <file> Start REPL with recording to file
47
+ --step Pause between commands during replay
48
+ -q, --silent Suppress banner and status messages
49
+ -h, --help Show this help
50
+
51
+ REPL Meta-Commands:
52
+ .help Show available commands
53
+ .aliases Show command aliases
54
+ .status Show connection status
55
+ .reconnect Restart browser
56
+ .record [filename] Start recording commands
57
+ .save Stop recording and save to file
58
+ .pause Pause/resume recording
59
+ .discard Discard current recording
60
+ .replay <filename> Replay a recorded session
61
+ .exit / Ctrl+D Exit REPL
62
+
63
+ Examples:
64
+ playwright-repl # start REPL
65
+ playwright-repl --headed # start with visible browser
66
+ playwright-repl --connect # connect to Chrome on port 9222
67
+ playwright-repl --connect 9333 # connect to Chrome on custom port
68
+ playwright-repl --extension # connect to existing Chrome + side panel
69
+ playwright-repl --extension --spawn # spawn Chrome automatically
70
+ playwright-repl --extension --port 7000 # custom server port
71
+ playwright-repl --extension --cdp-port 9333 # custom CDP port
72
+ playwright-repl --replay login.pw # replay a session
73
+ playwright-repl --replay login.pw --step # step through replay
74
+ playwright-repl --replay tests/ # replay all .pw files in folder
75
+ playwright-repl --replay a.pw b.pw # replay multiple files
76
+ echo "open https://example.com" | playwright-repl # pipe commands
77
+ `);
78
+ process.exit(0);
79
+ }
80
+ // Collect replay targets: --replay value + any remaining positional args
81
+ const replayFiles = [];
82
+ if (args.replay) {
83
+ replayFiles.push(args.replay);
84
+ for (const a of args._)
85
+ replayFiles.push(String(a));
86
+ }
87
+ startRepl({
88
+ session: args.session,
89
+ headed: args.headed,
90
+ browser: args.browser,
91
+ persistent: args.persistent,
92
+ profile: args.profile,
93
+ connect: args.connect,
94
+ extension: args.extension,
95
+ spawn: args.spawn === true,
96
+ port: args.port ? parseInt(args.port, 10) : undefined,
97
+ cdpPort: args['cdp-port'] ? parseInt(args['cdp-port'], 10) : undefined,
98
+ config: args.config,
99
+ replay: replayFiles.length > 0 ? replayFiles : undefined,
100
+ record: args.record,
101
+ step: args.step,
102
+ silent: args.silent,
103
+ }).catch((err) => {
104
+ console.error(`Fatal: ${err.message}`);
105
+ process.exit(1);
106
+ });
107
+ //# sourceMappingURL=playwright-repl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"playwright-repl.js","sourceRoot":"","sources":["../src/playwright-repl.ts"],"names":[],"mappings":";AAEA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,MAAM,IAAI,GAAG,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE;IAC3C,OAAO,EAAE,CAAC,QAAQ,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,CAAC;IACjF,MAAM,EAAE,CAAC,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,CAAC;IACtG,KAAK,EAAE,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,QAAQ,EAAE;IAC7D,OAAO,EAAE,EAAE,OAAO,EAAE,SAAS,EAAE;CAChC,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AAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,UAAU,CAAW,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS;IAChF,MAAM,EAAE,IAAI,CAAC,MAAgB;IAC7B,MAAM,EAAE,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS;IACxD,MAAM,EAAE,IAAI,CAAC,MAAgB;IAC7B,IAAI,EAAE,IAAI,CAAC,IAAe;IAC1B,MAAM,EAAE,IAAI,CAAC,MAAiB;CAC/B,CAAC,CAAC,KAAK,CAAC,CAAC,GAAU,EAAE,EAAE;IACtB,OAAO,CAAC,KAAK,CAAC,UAAU,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC;IACvC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
@@ -0,0 +1,95 @@
1
+ /**
2
+ * Session recorder and player.
3
+ *
4
+ * Records REPL commands to .pw files and replays them.
5
+ *
6
+ * File format (.pw):
7
+ * - One command per line (exactly as typed in REPL)
8
+ * - Comments start with #
9
+ * - Blank lines are ignored
10
+ * - First line is a metadata comment with timestamp
11
+ *
12
+ * Example:
13
+ * # Login test
14
+ * # recorded 2026-02-09T19:30:00Z
15
+ *
16
+ * open https://myapp.com
17
+ * snapshot
18
+ * click e5
19
+ * fill e7 admin@test.com
20
+ * fill e9 password123
21
+ * click e12
22
+ * verify-text Welcome back
23
+ */
24
+ export declare class SessionRecorder {
25
+ commands: string[];
26
+ recording: boolean;
27
+ filename: string | null;
28
+ paused: boolean;
29
+ /**
30
+ * Start recording commands.
31
+ */
32
+ start(filename?: string): string;
33
+ /**
34
+ * Record a command (called after each successful REPL command).
35
+ * Skips meta-commands (lines starting with .).
36
+ */
37
+ record(line: string): void;
38
+ /**
39
+ * Pause recording (toggle).
40
+ */
41
+ pause(): boolean;
42
+ /**
43
+ * Stop recording and save to file.
44
+ */
45
+ save(): {
46
+ filename: string;
47
+ count: number;
48
+ };
49
+ /**
50
+ * Discard recording without saving.
51
+ */
52
+ discard(): void;
53
+ get status(): string;
54
+ get commandCount(): number;
55
+ }
56
+ export declare class SessionPlayer {
57
+ filename: string;
58
+ commands: string[];
59
+ index: number;
60
+ /**
61
+ * Load commands from a .pw file.
62
+ */
63
+ static load(filename: string): string[];
64
+ /**
65
+ * Create a player that yields commands one at a time.
66
+ * Supports step-through mode where it pauses between commands.
67
+ */
68
+ constructor(filename: string);
69
+ get done(): boolean;
70
+ get current(): string | null;
71
+ get progress(): string;
72
+ next(): string | null;
73
+ reset(): void;
74
+ }
75
+ export declare class SessionManager {
76
+ #private;
77
+ /** Current mode: 'idle' | 'recording' | 'paused' | 'replaying' */
78
+ get mode(): string;
79
+ startRecording(filename?: string): string;
80
+ save(): {
81
+ filename: string;
82
+ count: number;
83
+ };
84
+ togglePause(): boolean;
85
+ discard(): void;
86
+ /** Called after each successful command — records if active. */
87
+ record(line: string): void;
88
+ get recordingFilename(): string | null;
89
+ get recordedCount(): number;
90
+ startReplay(filename: string, step?: boolean): SessionPlayer;
91
+ endReplay(): void;
92
+ get player(): SessionPlayer | null;
93
+ get step(): boolean;
94
+ }
95
+ //# sourceMappingURL=recorder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recorder.d.ts","sourceRoot":"","sources":["../src/recorder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAOH,qBAAa,eAAe;IAC1B,QAAQ,EAAE,MAAM,EAAE,CAAM;IACxB,SAAS,UAAS;IAClB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAQ;IAC/B,MAAM,UAAS;IAEf;;OAEG;IACH,KAAK,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM;IAQhC;;;OAGG;IACH,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAO1B;;OAEG;IACH,KAAK,IAAI,OAAO;IAKhB;;OAEG;IACH,IAAI,IAAI;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**
2
+ * Session recorder and player.
3
+ *
4
+ * Records REPL commands to .pw files and replays them.
5
+ *
6
+ * File format (.pw):
7
+ * - One command per line (exactly as typed in REPL)
8
+ * - Comments start with #
9
+ * - Blank lines are ignored
10
+ * - First line is a metadata comment with timestamp
11
+ *
12
+ * Example:
13
+ * # Login test
14
+ * # recorded 2026-02-09T19:30:00Z
15
+ *
16
+ * open https://myapp.com
17
+ * snapshot
18
+ * click e5
19
+ * fill e7 admin@test.com
20
+ * fill e9 password123
21
+ * click e12
22
+ * verify-text Welcome back
23
+ */
24
+ import fs from 'node:fs';
25
+ import path from 'node:path';
26
+ // ─── Session Recorder ────────────────────────────────────────────────────────
27
+ export class SessionRecorder {
28
+ commands = [];
29
+ recording = false;
30
+ filename = null;
31
+ paused = false;
32
+ /**
33
+ * Start recording commands.
34
+ */
35
+ start(filename) {
36
+ this.filename = filename || `session-${new Date().toISOString().replace(/[:.]/g, '-')}.pw`;
37
+ this.commands = [];
38
+ this.recording = true;
39
+ this.paused = false;
40
+ return this.filename;
41
+ }
42
+ /**
43
+ * Record a command (called after each successful REPL command).
44
+ * Skips meta-commands (lines starting with .).
45
+ */
46
+ record(line) {
47
+ if (!this.recording || this.paused)
48
+ return;
49
+ const trimmed = line.trim();
50
+ if (!trimmed || trimmed.startsWith('.'))
51
+ return;
52
+ this.commands.push(trimmed);
53
+ }
54
+ /**
55
+ * Pause recording (toggle).
56
+ */
57
+ pause() {
58
+ this.paused = !this.paused;
59
+ return this.paused;
60
+ }
61
+ /**
62
+ * Stop recording and save to file.
63
+ */
64
+ save() {
65
+ if (!this.recording)
66
+ throw new Error('Not recording');
67
+ const header = [
68
+ `# Playwright REPL session`,
69
+ `# recorded ${new Date().toISOString()}`,
70
+ ``,
71
+ ];
72
+ const content = [...header, ...this.commands, ''].join('\n');
73
+ // Ensure directory exists
74
+ const dir = path.dirname(this.filename);
75
+ if (dir && dir !== '.') {
76
+ fs.mkdirSync(dir, { recursive: true });
77
+ }
78
+ fs.writeFileSync(this.filename, content, 'utf-8');
79
+ const result = { filename: this.filename, count: this.commands.length };
80
+ this.recording = false;
81
+ this.commands = [];
82
+ this.filename = null;
83
+ this.paused = false;
84
+ return result;
85
+ }
86
+ /**
87
+ * Discard recording without saving.
88
+ */
89
+ discard() {
90
+ this.recording = false;
91
+ this.commands = [];
92
+ this.filename = null;
93
+ this.paused = false;
94
+ }
95
+ get status() {
96
+ if (!this.recording)
97
+ return 'idle';
98
+ if (this.paused)
99
+ return 'paused';
100
+ return 'recording';
101
+ }
102
+ get commandCount() {
103
+ return this.commands.length;
104
+ }
105
+ }
106
+ // ─── Session Player ──────────────────────────────────────────────────────────
107
+ export class SessionPlayer {
108
+ filename;
109
+ commands;
110
+ index = 0;
111
+ /**
112
+ * Load commands from a .pw file.
113
+ */
114
+ static load(filename) {
115
+ if (!fs.existsSync(filename)) {
116
+ throw new Error(`File not found: ${filename}`);
117
+ }
118
+ const content = fs.readFileSync(filename, 'utf-8');
119
+ return content
120
+ .split('\n')
121
+ .map(line => line.trim())
122
+ .filter(line => line && !line.startsWith('#'));
123
+ }
124
+ /**
125
+ * Create a player that yields commands one at a time.
126
+ * Supports step-through mode where it pauses between commands.
127
+ */
128
+ constructor(filename) {
129
+ this.filename = filename;
130
+ this.commands = SessionPlayer.load(filename);
131
+ }
132
+ get done() {
133
+ return this.index >= this.commands.length;
134
+ }
135
+ get current() {
136
+ return this.commands[this.index] || null;
137
+ }
138
+ get progress() {
139
+ return `[${this.index}/${this.commands.length}]`;
140
+ }
141
+ next() {
142
+ if (this.done)
143
+ return null;
144
+ return this.commands[this.index++];
145
+ }
146
+ reset() {
147
+ this.index = 0;
148
+ }
149
+ }
150
+ // ─── Session Manager (state machine) ────────────────────────────────────────
151
+ //
152
+ // States: idle → recording ⇄ paused → idle
153
+ // idle → replaying → idle
154
+ //
155
+ export class SessionManager {
156
+ #recorder = new SessionRecorder();
157
+ #player = null;
158
+ #step = false;
159
+ /** Current mode: 'idle' | 'recording' | 'paused' | 'replaying' */
160
+ get mode() {
161
+ if (this.#player && !this.#player.done)
162
+ return 'replaying';
163
+ return this.#recorder.status;
164
+ }
165
+ // ── Recording ──────────────────────────────────────────────────
166
+ startRecording(filename) {
167
+ if (this.mode !== 'idle')
168
+ throw new Error(`Cannot record while ${this.mode}`);
169
+ return this.#recorder.start(filename);
170
+ }
171
+ save() {
172
+ if (this.mode !== 'recording' && this.mode !== 'paused')
173
+ throw new Error('Not recording');
174
+ return this.#recorder.save();
175
+ }
176
+ togglePause() {
177
+ if (this.mode !== 'recording' && this.mode !== 'paused')
178
+ throw new Error('Not recording');
179
+ return this.#recorder.pause();
180
+ }
181
+ discard() {
182
+ if (this.mode !== 'recording' && this.mode !== 'paused')
183
+ throw new Error('Not recording');
184
+ this.#recorder.discard();
185
+ }
186
+ /** Called after each successful command — records if active. */
187
+ record(line) {
188
+ this.#recorder.record(line);
189
+ }
190
+ get recordingFilename() { return this.#recorder.filename; }
191
+ get recordedCount() { return this.#recorder.commandCount; }
192
+ // ── Playback ───────────────────────────────────────────────────
193
+ startReplay(filename, step = false) {
194
+ if (this.mode !== 'idle')
195
+ throw new Error(`Cannot replay while ${this.mode}`);
196
+ this.#player = new SessionPlayer(filename);
197
+ this.#step = step;
198
+ return this.#player;
199
+ }
200
+ endReplay() {
201
+ this.#player = null;
202
+ this.#step = false;
203
+ }
204
+ get player() { return this.#player; }
205
+ get step() { return this.#step; }
206
+ }
207
+ //# sourceMappingURL=recorder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recorder.js","sourceRoot":"","sources":["../src/recorder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,gFAAgF;AAEhF,MAAM,OAAO,eAAe;IAC1B,QAAQ,GAAa,EAAE,CAAC;IACxB,SAAS,GAAG,KAAK,CAAC;IAClB,QAAQ,GAAkB,IAAI,CAAC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AAM,CAAC,IAAI,CAAC,CAAC;IAC9B,CAAC;IAED,IAAI,iBAAiB,KAAoB,OAAO,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC1E,IAAI,aAAa,KAAa,OAAO,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC,CAAC;IAEnE,kEAAkE;IAElE,WAAW,CAAC,QAAgB,EAAE,IAAI,GAAG,KAAK;QACxC,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM;YAAE,MAAM,IAAI,KAAK,CAAC,uBAAuB,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;QAC9E,IAAI,CAAC,OAAO,GAAG,IAAI,aAAa,CAAC,QAAQ,CAAC,CAAC;QAC3C,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED,SAAS;QACP,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;QACpB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;IAED,IAAI,MAAM,KAA2B,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IAC3D,IAAI,IAAI,KAAc,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;CAC3C"}
package/dist/repl.d.ts ADDED
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Main REPL loop.
3
+ *
4
+ * Handles readline, command queue, meta-commands, and session management.
5
+ */
6
+ import readline from 'node:readline';
7
+ import { Engine } from '@playwright-repl/core';
8
+ import type { EngineOpts } from '@playwright-repl/core';
9
+ import { SessionManager } from './recorder.js';
10
+ export interface ReplOpts extends EngineOpts {
11
+ session?: string;
12
+ replay?: string[];
13
+ record?: string;
14
+ step?: boolean;
15
+ silent?: boolean;
16
+ }
17
+ export interface ReplContext {
18
+ conn: Engine;
19
+ session: SessionManager;
20
+ rl: readline.Interface | null;
21
+ opts: ReplOpts;
22
+ log: (...args: unknown[]) => void;
23
+ historyFile: string;
24
+ sessionHistory: string[];
25
+ commandCount: number;
26
+ errors: number;
27
+ }
28
+ export declare function filterResponse(text: string, cmdName?: string): string | null;
29
+ export declare function showHelp(): void;
30
+ export declare function showAliases(): void;
31
+ export declare function showStatus(ctx: ReplContext): void;
32
+ export declare function handleKillAll(ctx: ReplContext): Promise<void>;
33
+ export declare function handleClose(ctx: ReplContext): Promise<void>;
34
+ export declare function handleSessionCommand(ctx: ReplContext, line: string): boolean;
35
+ export declare function processLine(ctx: ReplContext, line: string): Promise<void>;
36
+ export declare function resolveReplayFiles(targets: string[]): string[];
37
+ export declare function runReplayMode(ctx: ReplContext, replayFile: string, step: boolean): Promise<void>;
38
+ export declare function runMultiReplayMode(ctx: ReplContext, targets: string[], step: boolean): Promise<void>;
39
+ export declare function startCommandLoop(ctx: ReplContext): void;
40
+ export declare function promptStr(ctx: ReplContext): string;
41
+ /**
42
+ * Returns matching commands for ghost completion.
43
+ * When the input exactly matches a command AND there are longer matches,
44
+ * the exact match is included so the user can cycle through all options.
45
+ */
46
+ export declare function getGhostMatches(cmds: string[], input: string): string[];
47
+ export declare function startRepl(opts?: ReplOpts): Promise<void>;
48
+ //# sourceMappingURL=repl.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"repl.d.ts","sourceRoot":"","sources":["../src/repl.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,QAAQ,MAAM,eAAe,CAAC;AAIrC,OAAO,EAKL,MAAM,EACP,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,UAAU,EAAc,MAAM,uBAAuB,CAAC;AACpE,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAK/C,MAAM,WAAW,QAAS,SAAQ,UAAU;IAC1C,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf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