# Plan 3: Environment-Aware Shell Wrapper for Edge

## Objective
Create a shell wrapper for the `radical-edge-service.py` script that captures the environment (PATH, PYTHONPATH) of the installation. This allows the service to be launched on remote compute nodes (e.g., via PsiJ) without requiring manual environment activation.

## Implementation Steps

### 1. Create Wrapper Template
- **File**: `bin/radical-edge-wrapper.sh.in` (or created dynamically)
- **Content**: A script that exports `PATH`, `PYTHONPATH`, and `LD_LIBRARY_PATH` based on the current `sys.prefix` and then executes `python3 bin/radical-edge-service.py "$@"`.

### 2. Update Installation Process
- **File**: `setup.py`
- **Action**: Add logic to the `install` command (or use `entry_points` logic if possible, but a shell script is more robust for compute nodes).
- **Action**: Generate `bin/radical-edge-wrapper.sh` during installation.
- **Action**: Use `os.path.abspath(sys.prefix)` to hardcode the environment paths into the script.

### 3. Integrate with PsiJ Plugin
- **File**: `examples/edge_explorer.html`
- **Action**: Change the default "Executable" in the PsiJ submission form to `radical-edge-wrapper.sh`.
- **Action**: Ensure the explorer correctly handles the pathing if the wrapper is in the same directory as the service.

## Test Plan
1. **Script Generation**:
    - Run `pip install .` in a virtualenv.
    - Check if `bin/radical-edge-wrapper.sh` exists and contains the correct virtualenv paths.
2. **Compute Node Execution**:
    - Use the `PsiJ` plugin from the explorer to submit a job that runs the wrapper script.
    - The job should start a sub-edge successfully on a compute node where the virtualenv is *not* activated in the shell.
3. **Parameter Passing**:
    - Ensure that flags like `--url` and `--name` passed to the wrapper are correctly forwarded to the underlying python service.
