feat(opencode): add serve and attach recipes

This commit is contained in:
Guillaume ARM 2026-06-09 06:08:29 +02:00
parent 5b46662f2a
commit 54ffe82786
2 changed files with 38 additions and 3 deletions

View File

@ -6,4 +6,4 @@ TRAP_CCLIBS_TEST_TIMEOUT_WATCHDOG_SECONDS=1
# Test placeholder. The real value is generated in `.env` on first `just install`, # Test placeholder. The real value is generated in `.env` on first `just install`,
# or after `just clean` / `just reinstall`. # or after `just clean` / `just reinstall`.
TRAP_CCLIBS_OPENCODE_PASSWORD=redacted OPENCODE_SERVER_PASSWORD=redacted

View File

@ -102,8 +102,8 @@ generate-env:
password="$(openssl rand -hex 32)" password="$(openssl rand -hex 32)"
while IFS= read -r line || [ -n "$line" ]; do while IFS= read -r line || [ -n "$line" ]; do
case "$line" in case "$line" in
TRAP_CCLIBS_OPENCODE_PASSWORD=*) OPENCODE_SERVER_PASSWORD=*)
printf '%s\n' "TRAP_CCLIBS_OPENCODE_PASSWORD=$password" printf '%s\n' "OPENCODE_SERVER_PASSWORD=$password"
;; ;;
*) *)
printf '%s\n' "$line" printf '%s\n' "$line"
@ -214,6 +214,41 @@ trapos-install: check-install
repl: repl:
@just trapos --cli @just trapos --cli
# Serve opencode for remote/browser attachment using repo-local .env secrets.
[positional-arguments]
opencode-serve *args:
#!/usr/bin/env bash
set -euo pipefail
repo='{{justfile_directory()}}'
if [ -f "$repo/.env" ]; then set -a; . "$repo/.env"; set +a; fi
if [ -z "${OPENCODE_SERVER_PASSWORD:-}" ]; then
printf '%s\n' 'Missing OPENCODE_SERVER_PASSWORD in .env' >&2
exit 1
fi
export OPENCODE_SERVER_PASSWORD
hostname="${TRAP_CCLIBS_OPENCODE_HOSTNAME:-0.0.0.0}"
port="${TRAP_CCLIBS_OPENCODE_PORT:-4242}"
exec opencode serve --hostname "$hostname" --port "$port" "$@"
# Attach to the local opencode server. Pass a URL first to override the default.
[positional-arguments]
opencode-attach *args:
#!/usr/bin/env bash
set -euo pipefail
repo='{{justfile_directory()}}'
if [ -f "$repo/.env" ]; then set -a; . "$repo/.env"; set +a; fi
if [ -z "${OPENCODE_SERVER_PASSWORD:-}" ]; then
printf '%s\n' 'Missing OPENCODE_SERVER_PASSWORD in .env' >&2
exit 1
fi
export OPENCODE_SERVER_PASSWORD
port="${TRAP_CCLIBS_OPENCODE_PORT:-4242}"
target="http://127.0.0.1:$port"
if [ "${1:-}" != "" ]; then
case "$1" in http://*|https://*) target="$1"; shift ;; esac
fi
exec opencode attach "$target" "$@"
# Local CI entry point used by Git hooks. Pass args through to `test`. # Local CI entry point used by Git hooks. Pass args through to `test`.
ci *args: check-craftos check check-packages ci *args: check-craftos check check-packages
@just test {{args}} @just test {{args}}