shellx-ai 1.1.0 → 1.1.2

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 (40) hide show
  1. package/README.md +162 -586
  2. package/dist/automation/element-finder.d.ts +0 -8
  3. package/dist/automation/element-finder.js +0 -7
  4. package/dist/automation/element-finder.js.map +1 -1
  5. package/dist/automation/ui-action-handler.d.ts +1 -1
  6. package/dist/automation/ui-action-handler.js +58 -31
  7. package/dist/automation/ui-action-handler.js.map +1 -1
  8. package/dist/cbor-compat.js +9 -11
  9. package/dist/cbor-compat.js.map +1 -1
  10. package/dist/data/index.d.ts +9 -0
  11. package/dist/data/index.js +11 -0
  12. package/dist/data/index.js.map +1 -0
  13. package/dist/data/types.d.ts +351 -0
  14. package/dist/data/types.js +8 -0
  15. package/dist/data/types.js.map +1 -0
  16. package/dist/domain-manager.js +15 -13
  17. package/dist/domain-manager.js.map +1 -1
  18. package/dist/error-handler.js +5 -2
  19. package/dist/error-handler.js.map +1 -1
  20. package/dist/errors.js +4 -2
  21. package/dist/errors.js.map +1 -1
  22. package/dist/index.d.ts +36 -26
  23. package/dist/index.js +197 -86
  24. package/dist/index.js.map +1 -1
  25. package/dist/protocol.d.ts +27 -5
  26. package/dist/shellx.d.ts +139 -56
  27. package/dist/shellx.js +201 -88
  28. package/dist/shellx.js.map +1 -1
  29. package/dist/types.d.ts +38 -1
  30. package/dist/utils/retry-helper.js +5 -2
  31. package/dist/utils/retry-helper.js.map +1 -1
  32. package/dist/utils.js +6 -3
  33. package/dist/utils.js.map +1 -1
  34. package/package.json +25 -4
  35. package/dist/shell/output-buffer.d.ts +0 -152
  36. package/dist/shell/output-buffer.js +0 -163
  37. package/dist/shell/output-buffer.js.map +0 -1
  38. package/dist/shell/shell-command-executor.d.ts +0 -182
  39. package/dist/shell/shell-command-executor.js +0 -348
  40. package/dist/shell/shell-command-executor.js.map +0 -1
package/package.json CHANGED
@@ -1,10 +1,13 @@
1
1
  {
2
2
  "name": "shellx-ai",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "type": "module",
5
5
  "description": "A powerful TypeScript library for Android device automation and UI control via WebSocket",
6
6
  "workspaces": [
7
- "example"
7
+ "example",
8
+ "phone-agent",
9
+ "shellx-cli",
10
+ "gui-agent"
8
11
  ],
9
12
  "keywords": [
10
13
  "android",
@@ -44,8 +47,11 @@
44
47
  ],
45
48
  "scripts": {
46
49
  "build": "tsc",
50
+ "build:gui-agent": "cd gui-agent && npm run build:all",
47
51
  "build:phone-agent": "cd phone-agent && npm run build:all",
48
- "build:all": "npm run build && npm run build:phone-agent",
52
+ "build:shellx-cli": "cd shellx-cli && npm run build",
53
+ "build:example": "cd example && npm run build",
54
+ "build:all": "npm run build && npm run build:gui-agent && npm run build:phone-agent && npm run build:shellx-cli && npm run build:example",
49
55
  "build:watch": "tsc --watch",
50
56
  "type-check": "tsc --noEmit",
51
57
  "lint": "eslint src --ext .ts",
@@ -55,11 +61,13 @@
55
61
  "test": "jest",
56
62
  "test:coverage": "jest --coverage",
57
63
  "test:watch": "jest --watch",
58
- "clean": "rimraf dist && cd phone-agent && rimraf dist",
64
+ "clean": "rimraf dist && cd gui-agent && rimraf dist && cd ../phone-agent && rimraf dist && cd ../shellx-cli && rimraf dist && cd ../example && rimraf dist",
59
65
  "prepublishOnly": "npm run clean && npm run build && npm run type-check",
60
66
  "prepare": "husky install || echo 'Husky not available'"
61
67
  },
62
68
  "dependencies": {
69
+ "@mariozechner/pi-agent-core": "^0.65.2",
70
+ "@mariozechner/pi-ai": "^0.65.2",
63
71
  "cbor": "^9.0.0",
64
72
  "dotenv": "^16.4.5",
65
73
  "ofetch": "^1.4.1",
@@ -72,18 +80,31 @@
72
80
  "ws": "^8.14.2"
73
81
  },
74
82
  "devDependencies": {
83
+ "@eslint/plugin-kit": "^0.4.1",
75
84
  "@types/jest": "^30.0.0",
76
85
  "@types/node": "^24.0.13",
86
+ "@types/react": "^19.2.11",
87
+ "@types/uuid": "^9.0.7",
77
88
  "@types/ws": "^8.18.1",
78
89
  "@typescript-eslint/eslint-plugin": "^8.0.0",
79
90
  "@typescript-eslint/parser": "^8.0.0",
91
+ "autocomplete-cli": "^0.0.2",
92
+ "chalk": "^5.6.2",
93
+ "esbuild": "^0.27.4",
94
+ "esbuild-node-externals": "^1.20.1",
80
95
  "eslint": "^9.0.0",
81
96
  "eslint-config-prettier": "^9.1.0",
82
97
  "eslint-plugin-prettier": "^5.2.0",
98
+ "ink": "^6.6.0",
99
+ "ink-spinner": "^5.0.0",
100
+ "ink-text-input": "^6.0.0",
83
101
  "jest": "^30.0.4",
84
102
  "prettier": "^3.3.0",
103
+ "prettier-linter-helpers": "^1.0.1",
104
+ "react": "^19.2.4",
85
105
  "rimraf": "^6.0.0",
86
106
  "ts-jest": "^29.4.0",
107
+ "tsx": "^4.19.2",
87
108
  "typescript": "^5.8.3"
88
109
  },
89
110
  "engines": {
@@ -1,152 +0,0 @@
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 {};
@@ -1,163 +0,0 @@
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
- * OutputBuffer class manages shell command output buffering and processing
9
- *
10
- * This class handles:
11
- * - Buffering output from multiple shell command sessions
12
- * - Managing pending command promises
13
- * - Cleaning and combining output from different sessions
14
- * - Providing access to accumulated command results
15
- */
16
- export class OutputBuffer {
17
- /** Map of pending command promises keyed by command ID */
18
- commandPromises = new Map();
19
- /**
20
- * Register a new command promise for tracking
21
- *
22
- * @param commandId - Unique identifier for the command
23
- * @param resolve - Promise resolve function
24
- * @param reject - Promise reject function
25
- * @param startTime - Command start timestamp
26
- * @param options - Command execution options
27
- * @param command - Original command string
28
- */
29
- registerCommand(commandId, resolve, reject, startTime, options, command) {
30
- this.commandPromises.set(commandId, {
31
- resolve,
32
- reject,
33
- startTime,
34
- options,
35
- output: "",
36
- sessionOutputs: new Map(),
37
- command,
38
- });
39
- console.log(`📋 [OutputBuffer] Registered command: ${commandId}`);
40
- console.log(`📊 [OutputBuffer] Pending commands: ${this.commandPromises.size}`);
41
- }
42
- /**
43
- * Unregister and resolve a command promise
44
- *
45
- * @param commandId - Unique identifier for the command
46
- * @returns The command promise data if found, undefined otherwise
47
- */
48
- unregisterCommand(commandId) {
49
- const commandPromise = this.commandPromises.get(commandId);
50
- if (commandPromise) {
51
- this.commandPromises.delete(commandId);
52
- console.log(`✅ [OutputBuffer] Unregistered command: ${commandId}`);
53
- }
54
- return commandPromise;
55
- }
56
- /**
57
- * Get a registered command promise
58
- *
59
- * @param commandId - Unique identifier for the command
60
- * @returns The command promise data if found, undefined otherwise
61
- */
62
- getCommand(commandId) {
63
- return this.commandPromises.get(commandId);
64
- }
65
- /**
66
- * Check if a command is registered
67
- *
68
- * @param commandId - Unique identifier for the command
69
- * @returns True if the command is registered, false otherwise
70
- */
71
- hasCommand(commandId) {
72
- return this.commandPromises.has(commandId);
73
- }
74
- /**
75
- * Get the number of pending commands
76
- *
77
- * @returns The number of currently registered commands
78
- */
79
- getPendingCount() {
80
- return this.commandPromises.size;
81
- }
82
- /**
83
- * Handle incoming shell output chunks
84
- *
85
- * This method processes output from shell sessions and distributes it
86
- * to all waiting commands.
87
- *
88
- * @param sessionId - The session ID for the output
89
- * @param chunks - Array of Uint8Array data chunks
90
- */
91
- handleShellOutput(sessionId, chunks) {
92
- try {
93
- // Decode chunks to string
94
- let output = "";
95
- for (const data of chunks) {
96
- output += new TextDecoder().decode(data);
97
- }
98
- // Distribute output to all waiting commands
99
- for (const [_commandId, commandPromise] of this.commandPromises.entries()) {
100
- // Initialize session output if not exists
101
- if (!commandPromise.sessionOutputs.has(sessionId)) {
102
- commandPromise.sessionOutputs.set(sessionId, "");
103
- }
104
- // Accumulate session output
105
- const currentSessionOutput = commandPromise.sessionOutputs.get(sessionId) || "";
106
- commandPromise.sessionOutputs.set(sessionId, currentSessionOutput + output);
107
- // Update combined output
108
- commandPromise.output = this.combineSessionOutputs(commandPromise.sessionOutputs);
109
- // Call output callback if provided
110
- if (commandPromise.options.onOutput) {
111
- const cleanOutput = this.cleanCommandOutput(output, commandPromise.command);
112
- commandPromise.options.onOutput(cleanOutput);
113
- }
114
- }
115
- }
116
- catch (error) {
117
- console.error(`❌ [OutputBuffer] Failed to handle shell output:`, error);
118
- }
119
- }
120
- /**
121
- * Clean command output by removing the command itself
122
- *
123
- * @param output - The raw output string
124
- * @param command - The command string to remove
125
- * @returns Cleaned output string
126
- */
127
- cleanCommandOutput(output, command) {
128
- return output.replace(command, "");
129
- }
130
- /**
131
- * Combine outputs from multiple sessions into a single string
132
- *
133
- * @param sessionOutputs - Map of session IDs to their outputs
134
- * @returns Combined output string
135
- */
136
- combineSessionOutputs(sessionOutputs) {
137
- const sessions = Array.from(sessionOutputs.keys()).sort();
138
- let combined = "";
139
- for (const sessionId of sessions) {
140
- const sessionOutput = sessionOutputs.get(sessionId) || "";
141
- combined += sessionOutput;
142
- }
143
- return combined;
144
- }
145
- /**
146
- * Clear all registered commands
147
- *
148
- * This method is useful for cleanup or reset scenarios
149
- */
150
- clear() {
151
- this.commandPromises.clear();
152
- console.log("🧹 [OutputBuffer] Cleared all command promises");
153
- }
154
- /**
155
- * Get all registered command IDs
156
- *
157
- * @returns Array of command IDs
158
- */
159
- getCommandIds() {
160
- return Array.from(this.commandPromises.keys());
161
- }
162
- }
163
- //# sourceMappingURL=output-buffer.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"output-buffer.js","sourceRoot":"","sources":["../../src/shell/output-buffer.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AA8DH;;;;;;;;GAQG;AACH,MAAM,OAAO,YAAY;IACvB,0DAA0D;IAClD,eAAe,GAAgC,IAAI,GAAG,EAAE,CAAC;IAEjE;;;;;;;;;OASG;IACH,eAAe,CACb,SAAiB,EACjB,OAA6C,EAC7C,MAA8B,EAC9B,SAAiB,EACjB,OAA4B,E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,IAAI,CAAC,cAAc,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;QAC1D,IAAI,QAAQ,GAAG,EAAE,CAAC;QAElB,KAAK,MAAM,SAAS,IAAI,QAAQ,EAAE,CAAC;YACjC,MAAM,aAAa,GAAG,cAAc,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC;YAC1D,QAAQ,IAAI,aAAa,CAAC;QAC5B,CAAC;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED;;;;OAIG;IACH,KAAK;QACH,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE,CAAC;QAC7B,OAAO,CAAC,GAAG,CAAC,gDAAgD,CAAC,CAAC;IAChE,CAAC;IAED;;;;OAIG;IACH,aAAa;QACX,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,IAAI,EAAE,CAAC,CAAC;IACjD,CAAC;CACF"}
@@ -1,182 +0,0 @@
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
- }