Add opencode-attach.sh for TUI to connect to systemd server

This commit is contained in:
Twentyninehairs_bot 2026-05-04 07:05:59 -07:00
parent 66e5330e96
commit cc5b393631
Signed by: Twentyninehairs_bot
GPG Key ID: CC558AA42F05E387
2 changed files with 62 additions and 8 deletions

View File

@ -21,7 +21,8 @@ This approach:
## Files ## Files
- `omoa` — CLI command to toggle omoa on/off - `omoa` — CLI command to toggle omoa on/off
- `opencode-start.sh` — Wrapper script that starts OpenCode with/without omoa - `opencode-start.sh` — Wrapper script that starts OpenCode with/without omoa (foreground)
- `opencode-attach.sh` — Attach TUI to the systemd server (shared sessions)
- `omoa-post-upgrade.sh` — Removes omoa plugin from `opencode.json` after upstream install - `omoa-post-upgrade.sh` — Removes omoa plugin from `opencode.json` after upstream install
- `omoa.mjs` — Unified OpenCode skill for all omoa operations (toggle, status, post-upgrade) - `omoa.mjs` — Unified OpenCode skill for all omoa operations (toggle, status, post-upgrade)
- `git-ops.mjs` — OpenCode skill for git operations with Hibbhome Gitea server - `git-ops.mjs` — OpenCode skill for git operations with Hibbhome Gitea server
@ -35,12 +36,14 @@ This approach:
```bash ```bash
chmod +x ~/.config/opencode/omoa chmod +x ~/.config/opencode/omoa
chmod +x ~/.config/opencode/opencode-start.sh chmod +x ~/.config/opencode/opencode-start.sh
chmod +x ~/.config/opencode/opencode-attach.sh
chmod +x ~/.config/opencode/omoa-post-upgrade.sh chmod +x ~/.config/opencode/omoa-post-upgrade.sh
``` ```
3. Symlink to PATH: 3. Symlink to PATH:
```bash ```bash
ln -sf ~/.config/opencode/omoa ~/.local/bin/omoa ln -sf ~/.config/opencode/omoa ~/.local/bin/omoa
ln -sf ~/.config/opencode/opencode-start.sh ~/.local/bin/opencode-start ln -sf ~/.config/opencode/opencode-start.sh ~/.local/bin/opencode-start
ln -sf ~/.config/opencode/opencode-attach.sh ~/.local/bin/opencode-attach
ln -sf ~/.config/opencode/omoa-post-upgrade.sh ~/.local/bin/omoa-post-upgrade ln -sf ~/.config/opencode/omoa-post-upgrade.sh ~/.local/bin/omoa-post-upgrade
``` ```
4. Update systemd service to use wrapper: 4. Update systemd service to use wrapper:
@ -70,17 +73,24 @@ omoa off # Disable
omoa status # Check status omoa status # Check status
``` ```
### Shell (start server directly) ### Attach TUI to systemd server (shared sessions)
```bash ```bash
# Start without omoa (vanilla) opencode-attach # Attach to systemd server
opencode-start opencode-attach --omoa # Enable omoa, then attach
```
# Start with omoa enabled ### Start server directly (foreground, separate sessions)
opencode-start --omoa
# After running upstream install script ```bash
omoa-post-upgrade opencode-start # Start without omoa (vanilla)
opencode-start --omoa # Start with omoa enabled
```
### After upstream updates
```bash
omoa-post-upgrade # Clean the plugin entry from opencode.json
``` ```
### Telegram Bot ### Telegram Bot

44
opencode-attach.sh Executable file
View File

@ -0,0 +1,44 @@
#!/bin/bash
# =============================================================================
# opencode-attach.sh — Attach TUI to the systemd OpenCode server
# =============================================================================
#
# PURPOSE:
# Connects the OpenCode TUI to the running systemd server (port 4096).
# This ensures sessions are shared between the TUI and Telegram bot.
#
# USAGE:
# opencode-attach — Attach to systemd server
# opencode-attach --omoa — Start systemd server with omoa, then attach
#
# WHY THIS EXISTS:
# - The systemd server runs on port 4096 (managed by Telegram or systemctl)
# - The TUI can either start its own server (separate sessions) or attach
# - Attaching shares sessions between TUI and Telegram bot
# - omoa is managed via systemd/Telegram, not from the terminal
#
# UPSTREAM REPO:
# https://git.hibbhome.com/Hibbhome/opencode-omoa-toggle
#
# CREATED: 2026-05-03
# =============================================================================
OPENCODE_BIN="$HOME/.opencode/bin/opencode"
SERVER_URL="http://localhost:4096"
# If --omoa flag, ensure systemd server has omoa enabled
if [[ "$*" == *"--omoa"* ]]; then
touch "$HOME/.config/opencode/omoa-enabled"
systemctl --user restart opencode-serve.service
sleep 2
fi
# Check if server is running
if ! curl -s "$SERVER_URL" > /dev/null 2>&1; then
echo "Starting OpenCode server..."
systemctl --user start opencode-serve.service
sleep 2
fi
echo "Attaching to OpenCode server at $SERVER_URL..."
exec "$OPENCODE_BIN" attach "$SERVER_URL"