Skip to content

Commit eb3c49e

Browse files
committed
Added multi-workspace support, image support and other improvements
1 parent c4bfbfe commit eb3c49e

File tree

5 files changed

+1211
-397
lines changed

5 files changed

+1211
-397
lines changed

.env.example

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,31 @@
66

77
# --- Telegram (REQUIRED) ---
88
# Get from @BotFather on Telegram (/newbot)
9-
TELEGRAM_BOT_TOKEN=your_bot_token_here
9+
TELEGRAM_BOT_TOKEN=000000000:AAAAAAAAAA # Replace with actual
1010

1111
# Get from @userinfobot on Telegram
12-
ALLOWED_CHAT_ID=your_chat_id_here
12+
ALLOWED_CHAT_ID=123456 #,0002,0003 so on
1313

1414
# --- Connection Mode ---
1515
# How the bot connects to the environment where the AI agent runs.
1616
# Options:
1717
# ssh (in WSL or macOS connecting to HPC using SSH)
1818
# wsl (I am in WSL and connect to WSL)
1919
# local (in local connect to local, e.g., macOS/Linux)
20-
# CONNECTION_MODE=ssh
20+
CONNECTION_MODE=wsl
2121

2222
# --- SSH ---
2323
# Must match a Host entry in your ~/.ssh/config if CONNECTION_MODE=ssh
24-
SSH_HOST=hpc
24+
SSH_HOST=
2525

2626
# --- Agent Paths ---
27-
# Full path to the AI agent binary on the target machine
28-
OPENCODE_PATH=/path/to/opencode
27+
# Full path to the AI agent binary on the HPC
28+
OPENCODE_PATH=~/.opencode/bin/opencode
2929

30-
# Default working directory on the target machine
31-
WORKDIR=/path/to/your/project
30+
# Default working directory on the HPC
31+
HPC_WORKDIR=~/
3232

33-
# Default AI model (see README for alias list)
33+
# Default AI model (Select depending on your subscription)
3434
DEFAULT_MODEL=opencode/minimax-m2.5-free
3535

3636
# --- Environment Setup (REQUIRED if your target uses environment modules) ---
@@ -55,10 +55,10 @@ DEFAULT_MODEL=opencode/minimax-m2.5-free
5555
# Node installed globally, no setup needed:
5656
# SETUP_CMD=
5757
#
58-
SETUP_CMD=module purge && module load tools/dev && module load nodejs/20.13.1-GCCcore-13.3.0
58+
SETUP_CMD=
5959

6060
# --- rclone Integration (optional) ---
61-
# Destination for the @@upload:@@ rclone transfer directive.
61+
# Destination for /upload rclone transfer.
6262
# Format: remote_name:path (as configured in `rclone config` on target)
6363
#
6464
# Examples:
@@ -67,7 +67,7 @@ SETUP_CMD=module purge && module load tools/dev && module load nodejs/20.13.1-GC
6767
# s3:mybucket/results (S3-compatible)
6868
# sharepoint:Documents/HPC (SharePoint)
6969
#
70-
RCLONE_DEST=gdrive:HPC-Results
70+
RCLONE_DEST=
7171

7272
# --- OpenCode Session Database (optional) ---
7373
# Path to OpenCode's SQLite database ON THE TARGET (used by the chat viewer tool).
@@ -78,3 +78,18 @@ RCLONE_DEST=gdrive:HPC-Results
7878
# --- Session Persistence (optional) ---
7979
# File on the RELAY MACHINE where active session IDs are stored between messages.
8080
# SESSIONS_FILE=~/.hpc_relay_sessions.json
81+
82+
83+
# --- Workspace Separation (optional but recommended) ---
84+
# Explicit mapping per Telegram chat_id -> isolated workspace/session/task files.
85+
# JSON format example:
86+
# CHANNEL_WORKSPACES={"123456":{"name":"AA","workdir":"~/workspace_AA","allowed_users":[123456]},"-000000":{"name":"group_shared","workdir":"~/workspace_shared"}}
87+
# If name is set, session/task files become:
88+
# hpc_relay_sessions_<name>.json
89+
# hpc_relay_tasks_<name>.json
90+
CHANNEL_WORKSPACES=
91+
# Auto-create isolated workspace namespace by chat_id when no explicit mapping exists.
92+
# 0 = disabled (default), 1 = enabled
93+
AUTO_WORKSPACE_PER_CHAT=0
94+
# Prefix for auto workspace names: <prefix>_<chat_id>
95+
AUTO_WORKSPACE_PREFIX=chat

.gitignore

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*.env
44
.env.*
55
!.env.example
6+
hpcrelay/
67

78
# Python
89
__pycache__/
@@ -39,5 +40,8 @@ Thumbs.db
3940
opencode_chat_viewer/
4041

4142
# Session data
42-
oc_sessions.json
43-
hpc_relay_sessions_ssh.json
43+
*session*.json
44+
*task*.json
45+
46+
# Workspace data
47+
workspace*/

README.md

Lines changed: 52 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# HPC-Relay
44

5-
### Control AI Coding Agents on Your HPC Cluster, WSL, or macOS -- From Your Phone
5+
### Opencode AI agent on your phone - Access anywhere!
66

77
[![Python 3.9+](https://img.shields.io/badge/Python-3.9+-blue?style=flat-square&logo=python)](https://python.org)
88
[![Telegram Bot API](https://img.shields.io/badge/Telegram-Bot%20API-26A5E4?style=flat-square&logo=telegram)](https://core.telegram.org/bots/api)
@@ -70,9 +70,9 @@ You authenticate **once**. Everything else is automatic.
7070
|---|---|
7171
| **No VPN on phone** | Relay sits inside the authenticated network |
7272
| **AI session memory** | Parses & re-injects `sessionID` -- full context from cold start |
73-
| **File transfer** | Download files from the target machine to Telegram (`@@send:path@@`) |
74-
| **File upload** | Upload files from target to cloud (`@@upload:file@@`) |
75-
| **Wildcard fetch** | Send multiple files with glob patterns (e.g. `@@send:Auto*.png@@`) |
73+
| **File transfer** | Download files from the target machine to Telegram (`/send <path>`) |
74+
| **File upload** | Upload files from target to cloud (`/upload <path>`) |
75+
| **Wildcard fetch** | Send multiple files with glob patterns (e.g. `/send Auto*.png`) |
7676
| **Chat history viewer** | Generate interactive HTML viewer of all AI conversations |
7777
| **Agent-agnostic** | Works with OpenCode, Claude Code, Aider, or any headless CLI agent |
7878

@@ -82,22 +82,28 @@ You authenticate **once**. Everything else is automatic.
8282

8383
### Talking to the AI Agent
8484

85+
> Use slash commands only.
86+
87+
8588
Simply type a message. It gets forwarded to the AI agent on your target machine, for example:
8689

8790
```
8891
Generate an expression heatmap with random synthetic data.
8992
```
9093

91-
### Inline Directives
94+
### Slash Commands
9295

9396
| Syntax | Action | Example |
9497
|---|---|---|
95-
| `@@model: <alias>@@` | Change the AI model for this message | `@@model: opus46@@ refactor my script` |
96-
| `@@session: <id>@@` | Switch to a specific AI session | `@@session: ses_abc123@@` / `@@session: new@@` |
97-
| `@@kill@@` or `!kill` | Kill the currently running AI process | `@@kill@@` |
98-
| `@@send: <path>@@` | Download a file from target machine to Telegram | `@@send: ~/results/plot.png@@` |
99-
| `@@send: Auto*.png@@` | Download matching files (wildcard) | `@@send: /project/Auto*.png@@` |
100-
| `@@upload: file@@` | Upload a file from target machine to cloud | `@@upload: ~/data/input.csv@@` |
98+
| `/model` | Open interactive provider -> model picker | `/model` |
99+
| `/new` | Start a fresh AI session | `/new` |
100+
| `/id <session_id>` | Switch to a specific session ID | `/id ses_abc123...` |
101+
| `/id` | Show recent sessions and pick one interactively | `/id` |
102+
| `/kill` or `/q` | Kill the currently running AI process | `/kill` |
103+
| `/send <path>` | Download a file from target machine to Telegram | `/send ~/results/plot.png` |
104+
| `/send Auto*.png` | Download matching files (wildcard) | `/send /project/Auto*.png` |
105+
| `/upload <path>` | Upload a file from target machine to cloud | `/upload ~/data/input.csv` |
106+
| `/scheduled` | Open scheduled tasks manager (edit/delete interactively) | `/scheduled` |
101107

102108
### Shell Commands
103109

@@ -114,13 +120,14 @@ Prefix with `!` to run raw shell commands directly on the target machine (bypass
114120
Change models persistently (applies to all subsequent messages):
115121

116122
```
117-
@@model: opus46@@
123+
/model
118124
```
119125

120126
Or change just for one message:
121127

122128
```
123-
@@model: g5@@ explain this error in my GWAS script
129+
(after selecting model via /model)
130+
explain this error in my GWAS script
124131
```
125132

126133
**Available model aliases (For Github Copilot Pro):**
@@ -140,8 +147,9 @@ Or change just for one message:
140147
Sessions provide conversation memory. The bot auto-tracks sessions, but you can:
141148

142149
```
143-
@@session: ses_abc123@@ # Switch to a specific session
144-
@@session: new@@ # Start a fresh session (clear context)
150+
/id ses_abc123 # Switch to a specific session
151+
/new # Start a fresh session (clear context)
152+
/id # Show recent sessions to pick
145153
```
146154

147155
The AI retains full context within a session -- ask follow-ups without re-explaining.
@@ -155,16 +163,16 @@ The AI retains full context within a session -- ask follow-ups without re-explai
155163
The AI automatically sends files it creates. You can also request files manually:
156164

157165
```
158-
@@send: ~/results/summary.pdf@@
159-
@@send: /project/output/Auto*.png@@ # wildcard: sends all matching files
166+
/send ~/results/summary.pdf
167+
/send /project/output/Auto*.png # wildcard: sends all matching files
160168
```
161169

162170
### Upload to cloud
163171

164172
Upload any file to your pre-configured cloud storage:
165173

166174
```
167-
@@upload :~/data/input.csv@@
175+
/upload ~/data/input.csv
168176
```
169177

170178
The file will be transferred to your preferred cloud storage such as google drive or onedrive.
@@ -280,7 +288,7 @@ python3 tools/chat_viewer.py
280288

281289
```bash
282290
!python3 /path/to/tools/chat_viewer.py
283-
@@send:~/opencode_chat_viewer/index.html@@
291+
/send ~/opencode_chat_viewer/index.html
284292
# Can be downloaded and viewed on Telegram
285293
```
286294

@@ -311,7 +319,7 @@ Many HPC clusters **prohibit heavy computation on login nodes**. HPC-Relay is de
311319
1. **Use the AI agent to generate job scripts** -- not to run heavy computation directly
312320
2. **Submit jobs** via `sbatch`, `qsub`, etc. directly from the HPC (or using `!` shell commands if supported by your workflow).
313321
3. **Monitor jobs** through your HPC's scheduling commands (e.g. `squeue`, `qstat`).
314-
4. **Retrieve results** with `@@send:path@@` or rclone
322+
4. **Retrieve results** with `/send <path>` or rclone
315323

316324
### Example
317325

@@ -413,3 +421,27 @@ BSD-3 -- free for academic and personal use. See [LICENSE](LICENSE).
413421
If this helped your workflow, please star the repo -- it helps others find it.
414422

415423
</div>
424+
425+
426+
### Schedule Management
427+
428+
Use `/scheduled` to open an interactive task list. Tap a task to:
429+
- Delete it
430+
- Edit schedule presets (hourly/daily/once-after)
431+
432+
Use `/scheduled` for all scheduled task management.
433+
434+
435+
### Workspace Separation (multi-chat isolation)
436+
437+
HPC-Relay can isolate sessions/tasks/workdir per chat. Configure with env:
438+
439+
```bash
440+
CHANNEL_WORKSPACES={"8670800334":{"name":"mg","workdir":"~/workspace_mg","allowed_users":[8670800334]}}
441+
AUTO_WORKSPACE_PER_CHAT=1
442+
AUTO_WORKSPACE_PREFIX=chat
443+
```
444+
445+
- Explicit mapping (`CHANNEL_WORKSPACES`) has highest priority.
446+
- If unmapped and `AUTO_WORKSPACE_PER_CHAT=1`, bot uses namespace `<prefix>_<chat_id>`.
447+
- Session/task stores become `hpc_relay_sessions_<name>.json` and `hpc_relay_tasks_<name>.json`.

index.html

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,8 +1084,8 @@ <h3>Stateful AI Sessions</h3>
10841084
<div class="feature-icon" style="background:rgba(16,185,129,0.1)">&#x1F4E6;</div>
10851085
<h3>File Transfers</h3>
10861086
<p>Download files from the target machine to Telegram with <code
1087-
style="font-family:monospace;font-size:12px;color:var(--accent3)">@@send:path@@</code>. Upload from phone
1088-
with <code style="font-family:monospace;font-size:12px;color:var(--accent3)">@@upload:file@@</code>.
1087+
style="font-family:monospace;font-size:12px;color:var(--accent3)">/send <path></code>. Upload from phone
1088+
with <code style="font-family:monospace;font-size:12px;color:var(--accent3)">/upload <path></code>.
10891089
Supports wildcards for batch transfer.</p>
10901090
<span class="tag green">Send + Upload + Wildcards</span>
10911091
</div>
@@ -1116,7 +1116,7 @@ <h3>Chat History Viewer</h3>
11161116
<div class="container">
11171117
<div class="section-label reveal">Control</div>
11181118
<h2 class="section-title reveal">Commands Reference</h2>
1119-
<p class="section-sub reveal">Everything you can do from Telegram.</p>
1119+
<p class="section-sub reveal">Everything you can do from Telegram. Supports per-chat workspace/session isolation via env config.</p>
11201120
<div class="cmd-grid">
11211121

11221122
<div class="cmd-card reveal">
@@ -1133,41 +1133,47 @@ <h2 class="section-title reveal">Commands Reference</h2>
11331133

11341134
<div class="cmd-card reveal">
11351135
<div class="cmd-label">Switch Model</div>
1136-
<div class="cmd-syntax">@@model: opus46@@</div>
1137-
<div class="cmd-desc">Change AI model. Use alone (persistent) or inline with a prompt.</div>
1136+
<div class="cmd-syntax">/model</div>
1137+
<div class="cmd-desc">Open interactive model picker (provider -> model) and switch persistently.</div>
11381138
</div>
11391139

11401140
<div class="cmd-card reveal">
11411141
<div class="cmd-label">Switch Session</div>
1142-
<div class="cmd-syntax">@@session: ses_abc123@@</div>
1143-
<div class="cmd-desc">Jump to a specific session for conversation context.</div>
1142+
<div class="cmd-syntax">/id ses_abc123</div>
1143+
<div class="cmd-desc">Switch sessions by ID (or run /id to pick from recent sessions).</div>
11441144
</div>
11451145

11461146
<div class="cmd-card reveal">
11471147
<div class="cmd-label">Kill Process</div>
1148-
<div class="cmd-syntax">@@kill@@ or !kill</div>
1149-
<div class="cmd-desc">Terminate the currently running AI process immediately.</div>
1148+
<div class="cmd-syntax">/kill or /q</div>
1149+
<div class="cmd-desc">Terminate the currently running AI process immediately (/kill or /q).</div>
11501150
</div>
11511151

11521152
<div class="cmd-card reveal">
11531153
<div class="cmd-label">Download File</div>
1154-
<div class="cmd-syntax">@@send:~/results/plot.png@@</div>
1154+
<div class="cmd-syntax">/send ~/results/plot.png</div>
11551155
<div class="cmd-desc">Fetch a file from HPC and receive it in Telegram.</div>
11561156
</div>
11571157

11581158
<div class="cmd-card reveal">
11591159
<div class="cmd-label">Wildcard Fetch</div>
1160-
<div class="cmd-syntax">@@send:Auto*.png@@</div>
1160+
<div class="cmd-syntax">/send Auto*.png</div>
11611161
<div class="cmd-desc">Download all matching files. Supports glob patterns.</div>
11621162
</div>
11631163

11641164
<div class="cmd-card reveal">
11651165
<div class="cmd-label">Upload File</div>
1166-
<div class="cmd-syntax">@@upload:~/data/input.csv@@</div>
1166+
<div class="cmd-syntax">/upload ~/data/input.csv</div>
11671167
<div class="cmd-desc">Send a file from your phone to a path on HPC. Use as caption when sending a document.
11681168
</div>
11691169
</div>
11701170

1171+
<div class="cmd-card reveal">
1172+
<div class="cmd-label">Scheduled Tasks</div>
1173+
<div class="cmd-syntax">/scheduled</div>
1174+
<div class="cmd-desc">Open interactive scheduled task manager (view/edit/delete).</div>
1175+
</div>
1176+
11711177
</div>
11721178
</div>
11731179
</section>
@@ -1328,7 +1334,7 @@ <h4>Example Workflow</h4>
13281334
<li>You: <code style="font-family:monospace;font-size:12px;color:var(--accent3)">!squeue -u $USER</code>
13291335
</li>
13301336
<li>You: <code
1331-
style="font-family:monospace;font-size:12px;color:var(--accent3)">@@send:~/results/output.pdf@@</code>
1337+
style="font-family:monospace;font-size:12px;color:var(--accent3)">/send ~/results/output.pdf</code>
13321338
</li>
13331339
</ul>
13341340
</div>

0 commit comments

Comments
 (0)