shellx-ai 1.0.12 → 1.1.1

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.
Files changed (48) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +666 -0
  3. package/dist/automation/element-finder.d.ts +189 -0
  4. package/dist/automation/element-finder.js +322 -0
  5. package/dist/automation/element-finder.js.map +1 -0
  6. package/dist/automation/ui-action-handler.d.ts +330 -0
  7. package/dist/automation/ui-action-handler.js +873 -0
  8. package/dist/automation/ui-action-handler.js.map +1 -0
  9. package/dist/cbor-compat.d.ts +27 -0
  10. package/dist/cbor-compat.js +111 -0
  11. package/dist/cbor-compat.js.map +1 -0
  12. package/dist/domain-manager.d.ts +80 -0
  13. package/dist/domain-manager.js +161 -0
  14. package/dist/domain-manager.js.map +1 -0
  15. package/dist/error-handler.d.ts +87 -0
  16. package/dist/error-handler.js +151 -0
  17. package/dist/error-handler.js.map +1 -0
  18. package/dist/errors.d.ts +114 -0
  19. package/dist/errors.js +139 -0
  20. package/dist/errors.js.map +1 -0
  21. package/dist/index.d.ts +163 -54
  22. package/dist/index.js +678 -481
  23. package/dist/index.js.map +1 -0
  24. package/dist/logger.d.ts +81 -0
  25. package/dist/logger.js +128 -0
  26. package/dist/logger.js.map +1 -0
  27. package/dist/protocol.d.ts +147 -31
  28. package/dist/protocol.js +2 -2
  29. package/dist/protocol.js.map +1 -0
  30. package/dist/shell/output-buffer.d.ts +152 -0
  31. package/dist/shell/output-buffer.js +176 -0
  32. package/dist/shell/output-buffer.js.map +1 -0
  33. package/dist/shell/shell-command-executor.d.ts +182 -0
  34. package/dist/shell/shell-command-executor.js +404 -0
  35. package/dist/shell/shell-command-executor.js.map +1 -0
  36. package/dist/shellx.d.ts +681 -178
  37. package/dist/shellx.js +762 -1159
  38. package/dist/shellx.js.map +1 -0
  39. package/dist/types.d.ts +132 -57
  40. package/dist/types.js +4 -4
  41. package/dist/types.js.map +1 -0
  42. package/dist/utils/retry-helper.d.ts +73 -0
  43. package/dist/utils/retry-helper.js +95 -0
  44. package/dist/utils/retry-helper.js.map +1 -0
  45. package/dist/utils.d.ts +3 -3
  46. package/dist/utils.js +20 -23
  47. package/dist/utils.js.map +1 -0
  48. package/package.json +95 -62
@@ -0,0 +1,152 @@
1
+ /**
2
+ * OutputBuffer - A module for managing shell command output buffering
3
+ *
4
+ * This module handles buffering, processing, and managing output from shell commands
5
+ * across multiple sessions, with support for output cleaning and combination.
6
+ */
7
+ /**
8
+ * Options for shell command execution
9
+ */
10
+ export interface ShellCommandOptions {
11
+ /** Title for the command (used for logging) */
12
+ title?: string;
13
+ /** Timeout in milliseconds */
14
+ timeout?: number;
15
+ /** Wait time after command execution in milliseconds */
16
+ waitAfterMs?: number;
17
+ /** Callback for handling output chunks as they arrive */
18
+ onOutput?: (output: string) => void;
19
+ /** Callback for handling error messages */
20
+ onError?: (error: string) => void;
21
+ /** Expected output pattern (string or RegExp) */
22
+ expectedOutput?: string | RegExp;
23
+ /** Success pattern to match in output (string or RegExp) */
24
+ successPattern?: string | RegExp;
25
+ /** Whether to allow returning partial results on timeout */
26
+ allowPartialResult?: boolean;
27
+ /** Whether to automatically set Android PATH (default: true) */
28
+ setAndroidPath?: boolean;
29
+ }
30
+ /**
31
+ * Result of a shell command execution
32
+ */
33
+ export interface ShellCommandResult {
34
+ /** Whether the command executed successfully */
35
+ success: boolean;
36
+ /** The command output */
37
+ output: string;
38
+ /** Error message if command failed */
39
+ error?: string;
40
+ /** Exit code of the command */
41
+ exitCode?: number;
42
+ /** Duration of command execution in milliseconds */
43
+ duration: number;
44
+ }
45
+ /**
46
+ * Internal promise representation for a pending shell command
47
+ */
48
+ interface CommandPromise {
49
+ /** Resolve function for the promise */
50
+ resolve: (result: ShellCommandResult) => void;
51
+ /** Reject function for the promise */
52
+ reject: (error: Error) => void;
53
+ /** Start time of the command */
54
+ startTime: number;
55
+ /** Execution options */
56
+ options: ShellCommandOptions;
57
+ /** Accumulated output */
58
+ output: string;
59
+ /** Session-specific outputs */
60
+ sessionOutputs: Map<number, string>;
61
+ /** Original command string */
62
+ command: string;
63
+ }
64
+ /**
65
+ * OutputBuffer class manages shell command output buffering and processing
66
+ *
67
+ * This class handles:
68
+ * - Buffering output from multiple shell command sessions
69
+ * - Managing pending command promises
70
+ * - Cleaning and combining output from different sessions
71
+ * - Providing access to accumulated command results
72
+ */
73
+ export declare class OutputBuffer {
74
+ /** Map of pending command promises keyed by command ID */
75
+ private commandPromises;
76
+ /**
77
+ * Register a new command promise for tracking
78
+ *
79
+ * @param commandId - Unique identifier for the command
80
+ * @param resolve - Promise resolve function
81
+ * @param reject - Promise reject function
82
+ * @param startTime - Command start timestamp
83
+ * @param options - Command execution options
84
+ * @param command - Original command string
85
+ */
86
+ registerCommand(commandId: string, resolve: (result: ShellCommandResult) => void, reject: (error: Error) => void, startTime: number, options: ShellCommandOptions, command: string): void;
87
+ /**
88
+ * Unregister and resolve a command promise
89
+ *
90
+ * @param commandId - Unique identifier for the command
91
+ * @returns The command promise data if found, undefined otherwise
92
+ */
93
+ unregisterCommand(commandId: string): CommandPromise | undefined;
94
+ /**
95
+ * Get a registered command promise
96
+ *
97
+ * @param commandId - Unique identifier for the command
98
+ * @returns The command promise data if found, undefined otherwise
99
+ */
100
+ getCommand(commandId: string): CommandPromise | undefined;
101
+ /**
102
+ * Check if a command is registered
103
+ *
104
+ * @param commandId - Unique identifier for the command
105
+ * @returns True if the command is registered, false otherwise
106
+ */
107
+ hasCommand(commandId: string): boolean;
108
+ /**
109
+ * Get the number of pending commands
110
+ *
111
+ * @returns The number of currently registered commands
112
+ */
113
+ getPendingCount(): number;
114
+ /**
115
+ * Handle incoming shell output chunks
116
+ *
117
+ * This method processes output from shell sessions and distributes it
118
+ * to all waiting commands.
119
+ *
120
+ * @param sessionId - The session ID for the output
121
+ * @param chunks - Array of Uint8Array data chunks
122
+ */
123
+ handleShellOutput(sessionId: number, chunks: Uint8Array[]): void;
124
+ /**
125
+ * Clean command output by removing the command itself
126
+ *
127
+ * @param output - The raw output string
128
+ * @param command - The command string to remove
129
+ * @returns Cleaned output string
130
+ */
131
+ cleanCommandOutput(output: string, command: string): string;
132
+ /**
133
+ * Combine outputs from multiple sessions into a single string
134
+ *
135
+ * @param sessionOutputs - Map of session IDs to their outputs
136
+ * @returns Combined output string
137
+ */
138
+ private combineSessionOutputs;
139
+ /**
140
+ * Clear all registered commands
141
+ *
142
+ * This method is useful for cleanup or reset scenarios
143
+ */
144
+ clear(): void;
145
+ /**
146
+ * Get all registered command IDs
147
+ *
148
+ * @returns Array of command IDs
149
+ */
150
+ getCommandIds(): string[];
151
+ }
152
+ export {};
@@ -0,0 +1,176 @@
1
+ /**
2
+ * OutputBuffer - A module for managing shell command output buffering
3
+ *
4
+ * This module handles buffering, processing, and managing output from shell commands
5
+ * across multiple sessions, with support for output cleaning and combination.
6
+ */
7
+ import { createLogger } from "../logger.js";
8
+ // Create logger for OutputBuffer
9
+ const logger = createLogger("OutputBuffer");
10
+ /**
11
+ * OutputBuffer class manages shell command output buffering and processing
12
+ *
13
+ * This class handles:
14
+ * - Buffering output from multiple shell command sessions
15
+ * - Managing pending command promises
16
+ * - Cleaning and combining output from different sessions
17
+ * - Providing access to accumulated command results
18
+ */
19
+ export class OutputBuffer {
20
+ /** Map of pending command promises keyed by command ID */
21
+ commandPromises = new Map();
22
+ /**
23
+ * Register a new command promise for tracking
24
+ *
25
+ * @param commandId - Unique identifier for the command
26
+ * @param resolve - Promise resolve function
27
+ * @param reject - Promise reject function
28
+ * @param startTime - Command start timestamp
29
+ * @param options - Command execution options
30
+ * @param command - Original command string
31
+ */
32
+ registerCommand(commandId, resolve, reject, startTime, options, command) {
33
+ this.commandPromises.set(commandId, {
34
+ resolve,
35
+ reject,
36
+ startTime,
37
+ options,
38
+ output: "",
39
+ sessionOutputs: new Map(),
40
+ command,
41
+ });
42
+ logger.info(`📋 Registered command: ${commandId}`);
43
+ logger.debug(`📊 Pending commands: ${this.commandPromises.size}`);
44
+ }
45
+ /**
46
+ * Unregister and resolve a command promise
47
+ *
48
+ * @param commandId - Unique identifier for the command
49
+ * @returns The command promise data if found, undefined otherwise
50
+ */
51
+ unregisterCommand(commandId) {
52
+ const commandPromise = this.commandPromises.get(commandId);
53
+ if (commandPromise) {
54
+ this.commandPromises.delete(commandId);
55
+ logger.info(`✅ Unregistered command: ${commandId}`);
56
+ }
57
+ return commandPromise;
58
+ }
59
+ /**
60
+ * Get a registered command promise
61
+ *
62
+ * @param commandId - Unique identifier for the command
63
+ * @returns The command promise data if found, undefined otherwise
64
+ */
65
+ getCommand(commandId) {
66
+ return this.commandPromises.get(commandId);
67
+ }
68
+ /**
69
+ * Check if a command is registered
70
+ *
71
+ * @param commandId - Unique identifier for the command
72
+ * @returns True if the command is registered, false otherwise
73
+ */
74
+ hasCommand(commandId) {
75
+ return this.commandPromises.has(commandId);
76
+ }
77
+ /**
78
+ * Get the number of pending commands
79
+ *
80
+ * @returns The number of currently registered commands
81
+ */
82
+ getPendingCount() {
83
+ return this.commandPromises.size;
84
+ }
85
+ /**
86
+ * Handle incoming shell output chunks
87
+ *
88
+ * This method processes output from shell sessions and distributes it
89
+ * to all waiting commands.
90
+ *
91
+ * @param sessionId - The session ID for the output
92
+ * @param chunks - Array of Uint8Array data chunks
93
+ */
94
+ handleShellOutput(sessionId, chunks) {
95
+ try {
96
+ // Decode chunks to string
97
+ let output = "";
98
+ for (const data of chunks) {
99
+ // Validate data is a valid Uint8Array
100
+ if (!data || !(data instanceof Uint8Array) || data.length === 0) {
101
+ logger.warn(`⚠️ Skipping invalid chunk:`, {
102
+ type: typeof data,
103
+ isUint8Array: data instanceof Uint8Array,
104
+ length: data?.length,
105
+ data: data,
106
+ });
107
+ continue;
108
+ }
109
+ output += new TextDecoder().decode(data);
110
+ }
111
+ // Distribute output to all waiting commands
112
+ for (const [_commandId, commandPromise] of this.commandPromises.entries()) {
113
+ // Initialize session output if not exists
114
+ if (!commandPromise.sessionOutputs.has(sessionId)) {
115
+ commandPromise.sessionOutputs.set(sessionId, "");
116
+ }
117
+ // Accumulate session output
118
+ const currentSessionOutput = commandPromise.sessionOutputs.get(sessionId) || "";
119
+ commandPromise.sessionOutputs.set(sessionId, currentSessionOutput + output);
120
+ // Update combined output
121
+ commandPromise.output = this.combineSessionOutputs(commandPromise.sessionOutputs);
122
+ // Call output callback if provided
123
+ if (commandPromise.options.onOutput) {
124
+ const cleanOutput = this.cleanCommandOutput(output, commandPromise.command);
125
+ commandPromise.options.onOutput(cleanOutput);
126
+ }
127
+ }
128
+ }
129
+ catch (error) {
130
+ logger.error(`❌ Failed to handle shell output:`, error);
131
+ }
132
+ }
133
+ /**
134
+ * Clean command output by removing the command itself
135
+ *
136
+ * @param output - The raw output string
137
+ * @param command - The command string to remove
138
+ * @returns Cleaned output string
139
+ */
140
+ cleanCommandOutput(output, command) {
141
+ return output.replace(command, "");
142
+ }
143
+ /**
144
+ * Combine outputs from multiple sessions into a single string
145
+ *
146
+ * @param sessionOutputs - Map of session IDs to their outputs
147
+ * @returns Combined output string
148
+ */
149
+ combineSessionOutputs(sessionOutputs) {
150
+ const sessions = Array.from(sessionOutputs.keys()).sort();
151
+ let combined = "";
152
+ for (const sessionId of sessions) {
153
+ const sessionOutput = sessionOutputs.get(sessionId) || "";
154
+ combined += sessionOutput;
155
+ }
156
+ return combined;
157
+ }
158
+ /**
159
+ * Clear all registered commands
160
+ *
161
+ * This method is useful for cleanup or reset scenarios
162
+ */
163
+ clear() {
164
+ this.commandPromises.clear();
165
+ logger.debug("🧹 Cleared all command promises");
166
+ }
167
+ /**
168
+ * Get all registered command IDs
169
+ *
170
+ * @returns Array of command IDs
171
+ */
172
+ getCommandIds() {
173
+ return Array.from(this.commandPromises.keys());
174
+ }
175
+ }
176
+ //# sourceMappingURL=output-buffer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"output-buffer.js","sourceRoot":"","sources":["../../src/shell/output-buffer.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAA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}
@@ -0,0 +1,182 @@
1
+ /**
2
+ * ShellCommandExecutor - A module for executing shell commands
3
+ *
4
+ * This module provides functionality for executing shell commands with
5
+ * output monitoring, timeout handling, and result management.
6
+ */
7
+ import type { ActionSequence as LegacyActionSequence } from "../protocol.js";
8
+ import type { ShellCommandResult, ShellCommandOptions } from "./output-buffer.js";
9
+ import { OutputBuffer } from "./output-buffer.js";
10
+ export type { ShellCommandResult, ShellCommandOptions };
11
+ /**
12
+ * Interface for ConnectionClient methods used by ShellCommandExecutor
13
+ */
14
+ interface IConnectionClient {
15
+ sendMessageWithTaskId(message: unknown, type: string, definedTaskId?: string, timeout?: number): Promise<{
16
+ promise: Promise<unknown>;
17
+ }>;
18
+ executeAction(action: LegacyActionSequence): Promise<void>;
19
+ appendExecutionLog: (log: string) => void;
20
+ }
21
+ /**
22
+ * ShellCommandExecutor class handles shell command execution
23
+ *
24
+ * This class provides methods to:
25
+ * - Execute single or multiple shell commands
26
+ * - Monitor command output in real-time
27
+ * - Handle command timeouts
28
+ * - Manage command execution state
29
+ */
30
+ export declare class ShellCommandExecutor {
31
+ private client;
32
+ private outputBuffer;
33
+ /**
34
+ * Creates a ShellCommandExecutor instance
35
+ *
36
+ * @param client - The ConnectionClient instance for command execution
37
+ */
38
+ constructor(client: IConnectionClient);
39
+ /**
40
+ * Handle shell output data from WebSocket messages
41
+ *
42
+ * This method should be called when receiving shell output chunks
43
+ * from the WebSocket connection.
44
+ *
45
+ * @param chunks - Array of [sessionId, length, dataArray] tuples
46
+ *
47
+ * @example
48
+ * ```typescript
49
+ * // In WebSocket message handler
50
+ * if (message.chunks) {
51
+ * executor.handleShellOutput(message.chunks);
52
+ * }
53
+ * ```
54
+ */
55
+ handleShellOutput(chunks: [number, number, Uint8Array[]]): void;
56
+ /**
57
+ * Execute a shell command with output monitoring
58
+ *
59
+ * @param command - The shell command to execute
60
+ * @param options - Command execution options
61
+ * @returns Promise resolving to ShellCommandResult
62
+ *
63
+ * @example
64
+ * ```typescript
65
+ * const result = await executor.executeShellCommand('ls -la', {
66
+ * title: 'List files',
67
+ * timeout: 5000,
68
+ * onOutput: (output) => console.log(output)
69
+ * });
70
+ * ```
71
+ */
72
+ executeShellCommand(command: string, options?: ShellCommandOptions): Promise<ShellCommandResult>;
73
+ /**
74
+ * Execute shell command with simple output (for backward compatibility)
75
+ *
76
+ * @param command - The shell command to execute
77
+ * @param options - Command execution options
78
+ * @returns Promise resolving to ShellCommandResult
79
+ *
80
+ * @example
81
+ * ```typescript
82
+ * const result = await executor.executeSimpleShellCommand('pm list packages', {
83
+ * title: 'List packages',
84
+ * timeout: 10000,
85
+ * waitAfterMs: 1000
86
+ * });
87
+ * ```
88
+ */
89
+ executeSimpleShellCommand(command: string, options?: {
90
+ title?: string;
91
+ timeout?: number;
92
+ waitAfterMs?: number;
93
+ }): Promise<ShellCommandResult>;
94
+ /**
95
+ * Execute multiple shell commands in sequence
96
+ *
97
+ * @param commands - Array of command configurations
98
+ * @param options - Execution options
99
+ * @returns Promise resolving to array of ShellCommandResult
100
+ *
101
+ * @example
102
+ * ```typescript
103
+ * const results = await executor.executeShellCommands(
104
+ * [
105
+ * { command: 'pm list packages', title: 'List packages' },
106
+ * { command: 'dumpsys battery', title: 'Get battery info' }
107
+ * ],
108
+ * {
109
+ * continueOnError: true,
110
+ * timeout: 5000
111
+ * }
112
+ * );
113
+ * ```
114
+ */
115
+ executeShellCommands(commands: Array<{
116
+ command: string;
117
+ title?: string;
118
+ waitAfterMs?: number;
119
+ }>, options?: {
120
+ continueOnError?: boolean;
121
+ timeout?: number;
122
+ }): Promise<ShellCommandResult[]>;
123
+ /**
124
+ * Execute an ADB command
125
+ *
126
+ * @param command - The ADB command to execute (without 'adb' prefix)
127
+ * @param options - Command execution options
128
+ * @returns Promise resolving to ShellCommandResult
129
+ *
130
+ * @example
131
+ * ```typescript
132
+ * const result = await executor.adbCommand('shell pm list packages', {
133
+ * title: 'List packages via ADB',
134
+ * timeout: 10000
135
+ * });
136
+ * ```
137
+ */
138
+ adbCommand(command: string, options?: ShellCommandOptions): Promise<ShellCommandResult>;
139
+ /**
140
+ * Execute a key action (press a hardware key)
141
+ *
142
+ * @param keyCode - The key code to press (e.g., 'KEYCODE_HOME', 'KEYCODE_BACK')
143
+ * @param options - Execution options
144
+ * @returns Promise resolving to boolean indicating success
145
+ *
146
+ * @example
147
+ * ```typescript
148
+ * const success = await executor.executeKeyAction('KEYCODE_HOME', {
149
+ * longPress: false,
150
+ * waitAfterMs: 500
151
+ * });
152
+ * ```
153
+ */
154
+ executeKeyAction(keyCode: string, options?: {
155
+ longPress?: boolean;
156
+ waitAfterMs?: number;
157
+ }): Promise<boolean>;
158
+ /**
159
+ * Get the underlying client instance
160
+ *
161
+ * @returns The ConnectionClient instance
162
+ */
163
+ private getClient;
164
+ /**
165
+ * Get the output buffer instance
166
+ *
167
+ * @returns The OutputBuffer instance
168
+ */
169
+ getOutputBuffer(): OutputBuffer;
170
+ /**
171
+ * Clear all pending command promises
172
+ *
173
+ * This method is useful for cleanup scenarios
174
+ */
175
+ clearPendingCommands(): void;
176
+ /**
177
+ * Get the number of pending commands
178
+ *
179
+ * @returns The number of currently pending commands
180
+ */
181
+ getPendingCommandCount(): number;
182
+ }