diff --git a/README.md b/README.md index 738437d..93330e5 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,8 @@ This approach: ## Files - `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.mjs` — Unified OpenCode skill for all omoa operations (toggle, status, post-upgrade) - `git-ops.mjs` — OpenCode skill for git operations with Hibbhome Gitea server @@ -35,12 +36,14 @@ This approach: ```bash chmod +x ~/.config/opencode/omoa chmod +x ~/.config/opencode/opencode-start.sh + chmod +x ~/.config/opencode/opencode-attach.sh chmod +x ~/.config/opencode/omoa-post-upgrade.sh ``` 3. Symlink to PATH: ```bash ln -sf ~/.config/opencode/omoa ~/.local/bin/omoa 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 ``` 4. Update systemd service to use wrapper: @@ -70,17 +73,24 @@ omoa off # Disable omoa status # Check status ``` -### Shell (start server directly) +### Attach TUI to systemd server (shared sessions) ```bash -# Start without omoa (vanilla) -opencode-start +opencode-attach # Attach to systemd server +opencode-attach --omoa # Enable omoa, then attach +``` -# Start with omoa enabled -opencode-start --omoa +### Start server directly (foreground, separate sessions) -# After running upstream install script -omoa-post-upgrade +```bash +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 diff --git a/opencode-attach.sh b/opencode-attach.sh new file mode 100755 index 0000000..a0227e2 --- /dev/null +++ b/opencode-attach.sh @@ -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"