scorpiox-bot-plugin-opencode-login
←README.mdmarkdown
139 lines · 6 KBHEAD
BlameDownload

scorpiox-bot-plugin-oss-opencode-login

A clean-room, zero-dependency, cross-platform SCORPIOX BOT node plugin for

OpenCode device-code login and account token management on the node it runs

on. Binary: plugin_opencode_login (Windows: plugin_opencode_login.exe).

Marketplace slug: opencode-login. Category: devtools. License: MIT.

--meta      {"name":"opencode","desc":"OpenCode login"}
?action=    status | start | poll | cancel | refresh
GET         responsive dark/light HTML UI (?embed=1 aware)

Why it drives a CLI instead of speaking TLS

An OAuth device flow is a sequence of HTTPS POSTs. A public clean-room

repository cannot ship a client secret, and vendoring a TLS stack into every

plugin would be a liability on each node. So this plugin opens **no socket of

its own**: it drives the machine-mode login CLI that already ships with

SCORPIOX CODE (SXLOGIN-MACHINE-V1: --status, --start, --poll,

--cancel, one JSON line per call) and reads the credential file that CLI

writes. The repo contains no secret, no internal address and no emoji.

plugin_opencode_login  --popen-->  scorpiox-opencode-login        --status|--start|--poll|--cancel
plugin_opencode_login  --popen-->  scorpiox-opencode-fetchtoken   -local

Files it reads (all on the local node, all overridable):

Path Written by Override
~/.config/opencode/auth.json the login CLI OPENCODE_CREDS_PATH
~/.opencode/token.json (fallback when the primary is absent) hand-written installs —
~/.claude/.login-pending/opencode-default.json the login CLI OPENCODE_PENDING_PATH
~/.claude/scorpiox-env/superopencode.txt the login CLI OPENCODE_ENV_DIR
the login binary SCORPIOX CODE OPENCODE_LOGIN_BIN
the token binary SCORPIOX CODE OPENCODE_TOKEN_BIN

No token is ever printed, logged or returned. status reports

logged_in, has_refresh, expires_at, expires_in_sec, expired;

refresh reports success and the new expiry and discards the payload. The

test suite fails if the mock token appears in any response, and if the words

access_token or refresh_token appear at all.

Actions

Action Behaviour
status (also format=json) credential file + pending marker + CLI JSON merged into one honest picture; pending is owned by the marker file and its TTL, the CLI may only add to it
start returns the CLI's verify_url, user_code, expires_in, interval; already_logged_in when the node already has credentials (force=1 replaces them)
poll one non-blocking round trip: {state:"pending"} while waiting, {state:"done",logged_in:true} on approval, {state:"failed",error:...} on denial or a dead flow
cancel aborts the pending flow and reports the cleared state
refresh re-reads the stored token through the node's token CLI and reports the new expiry with the value discarded
cli_unavailable structured, HTTP 200, when a CLI is missing, so a node without SCORPIOX CODE shows a message, not a broken panel

Auth: X-Bot-Password, Authorization: Bearer or ?pwd=; a no-op when

BOT_PASSWORD is unset; --meta is always unauthenticated.

UI

One page, no framework, no CDN, no <script src=>, no external request. Bot

theme handoff (?theme= then localStorage.bot_theme then

prefers-color-scheme, before first paint, then follows {type:'sx-theme'}),

every colour a token from the vendored src/bot_theme_plugin.h. A status pill

(Connected / Expired / Signing in / Not Connected), a user badge, a

session card, a device-flow card with a large user code and a one-click

Copy Code & Open OpenCode button, a live polling indicator, a cancel

button, and Refresh Token Now. Fluid down to 390 px and the Chat floating

window.

Build

make            # native   -> ./plugin_opencode_login
make musl       # static musl x86_64 (Alpine, Debian, Arch, Omarchy)
make arm64      # static aarch64 (Raspberry Pi 5, ARM servers)
make win64      # MinGW-w64 static PE -> plugin_opencode_login.exe
make macos      # Apple clang, run on a Mac
make ui         # regenerate src/ui_html.h from src/ui.html
make test       # build + run tests/run.sh

On Windows:

powershell -ExecutionPolicy Bypass -File build.ps1

Install

Drop the binary into the node's plugin directory - no restart:

mkdir -p ~/.scorpiox/plugins
cp plugin_opencode_login ~/.scorpiox/plugins/
~/.scorpiox/plugins/plugin_opencode_login --meta

scorpiox-bot-api discovers it on the next GET /plugins and serves it at

/plugin_opencode_login. BotMarket installs the prebuilt artifact for your

platform in one click, or compiles it from the public mirror.

Tests

tests/run.sh is fully offline: both CLIs are replaced by fixtures that emit

the exact production contract shape, and the credential and marker paths point

at throwaway files. It proves the metadata contract, the 401 gate, status

parsing (live, expired, empty, missing, secondary location, pending, stale

marker), the start/poll/cancel/refresh lifecycle, that no token ever surfaces,

that the page has no CDN and no emoji, and that the source history carries no

secret or internal address. Cross-target builds (musl, MinGW PE, aarch64) are

checked when the toolchains are installed.

sh tests/run.sh

Release

release-dist.sh runs the whole publish pipeline: full-history secret scan,

multi-target build, source.tar.gz, manifest.json + SHA256SUMS, upload to

dist.scorpiox.net/bot-plugins/opencode-login/<version>/, latest.json and

the master index.json merge, and the one-way mirror push to

plugingit.scorpiox.net/scorpiox-bot-plugin-opencode-login.git.

The mirror push has three hard requirements, all measured the hard way:

the push URL user must be the literal token

(https://token:<PAT>@plugingit.scorpiox.net/...); a first release needs

POST /api?r=repos&name=<repo> with a request body and the header

Authorization: token <PAT>; and the push must run over HTTP/1.1

(git -c http.version=HTTP/1.1 push).

Never emit Content-Length

The plugin writes Content-Type, Cache-Control and the security headers but

deliberately never a Content-Length. The reverse proxy in front of the bot

gets confused by a length that does not survive the CGI-to-HTTP rewrite and

answers 502.