How pig-dot-dev/pig-python works
Main Components
• SDK Client Library (located under src/pig): This encapsulates the core functionality including API client classes, CLI interface, and various modules (e.g., connection_session, connections, machines, sync_wrapper). These components handle the connection logic and the orchestration of commands.
• Command Line Interface (CLI): Found in src/pig/cli.py, this component exposes command line tools (e.g., pig ls) that allow users to interact with the system.
• Connection & Workflow Manager: The connection_session, connections, and sync_wrapper modules work together to abstract the process of establishing connections and sending workflows (keyboard, mouse, and screen actions) either locally or remotely.
• Examples: The examples directory (particularly examples/chat) shows how the SDK is integrated within an AI agent context. It demonstrates a practical use-case of the SDK by launching a “chat agent” that might interface with the automation API.
• Testing Suite: The tests directory contains unit, end-to-end, load, and local tests verifying the functionality. Although not part of the runtime architecture, it reinforces the design by verifying the connections and session handling.
• External Component – Piglet: While not part of the repository itself, the README makes it clear that a separate process called “Piglet” is a key part of the system. This process runs on Windows and listens on a port (default localhost:3000) for automation requests. It’s the component that executes the actual actions (keystrokes, mouse events, etc.).
Relationships and Interactions
• Connection Lifecycle: Illustrate how a machine (local or remote) is selected and how a connection is established, used (by sending commands as a workflow), and then closed – highlighting usage of the context manager pattern.
Architectural Patterns
• Modular Design: The project is organized into clearly separated modules for API communication, session management, and CLI handling.
• Abstraction via API Clients: The use of client classes abstracts the details of the underlying network or inter-process communication (with Piglet) from the user.
• Context Manager Pattern: Emphasize that all connection operations use Python’s with-statement for safe and predictable connection management.
• Test Driven Validation: The tests directory suggests a design that supports continuous integration and extensive automated testing.