feat: clean-room open-source starter plugin (plugin_hello)
Single-binary 3-mode C99 plugin: metadata (--meta), JSON node API (?action=info|echo, ?format=json) and a responsive dark/light HTML starter bench honouring ?embed=1. Builds warning-free on gcc, musl-gcc -static, Apple clang and x86_64-w64-mingw32-gcc -static. Ships Makefile (native/musl/win64/ macos/test), build.ps1, release-dist.sh (secret scan + multi-target build + dist upload + index.json merge + plugingit mirror), 83-check tests/run.sh including a full git-history secret/LAN audit. MIT licensed, zero dependencies, zero secrets.
AuthorPico <picobot@scorpioplayer.com>
Date2026-11-11 01:13:25
Commite8656a65
Changed files
.gitignore+7−0■■■■■
LICENSE+21−0■■■■■
Makefile+56−0■■■■■
README.md+204−0■■■■■
build.ps1+53−0■■■■■
release-dist.sh+318−0■■■■■
src/plugin_hello.c+477−0■■■■■
tests/run.sh+271−0■■■■■
8 files+1407−0
Diff
.gitignore+7−0■■■■■
11new file mode 100644
index 0000000..e892f4c
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,7 @@
1+/plugin_hello
2+/plugin_hello.exe
3+*.o
4+*.obj
5+bin/
6+*.tmp
7+*.log
LICENSE+21−0■■■■■
11new file mode 100644
index 0000000..ef80120
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,21 @@
1+MIT License
2+
3+Copyright (c) 2026 SCORPIOX INC
4+
5+Permission is hereby granted, free of charge, to any person obtaining a copy
6+of this software and associated documentation files (the "Software"), to deal
7+in the Software without restriction, including without limitation the rights
8+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+copies of the Software, and to permit persons to whom the Software is
10+furnished to do so, subject to the following conditions:
11+
12+The above copyright notice and this permission notice shall be included in all
13+copies or substantial portions of the Software.
14+
15+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+SOFTWARE.
Makefile+56−0■■■■■
11new file mode 100644
index 0000000..1a12d90
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,56 @@
1+# plugin_hello — ScorpioX Bot open-source starter plugin
2+#
3+# Targets:
4+# make native build -> ./plugin_hello
5+# make musl static musl x86_64 -> ./plugin_hello (fully static)
6+# make win64 MinGW-w64 static -> ./plugin_hello.exe
7+# make macos Apple clang -> ./plugin_hello (run on macOS)
8+# make test build + run tests/run.sh
9+# make clean
10+
11+CC ?= cc
12+CFLAGS ?= -O2 -std=c99 -Wall -Wextra -pedantic -Wno-overlength-strings
13+MUSL_CC ?= musl-gcc
14+MUSL_CFLAGS := -O2 -std=c99 -Wall -Wextra -static
15+WIN_CC ?= x86_64-w64-mingw32-gcc
16+WIN_CFLAGS := -O2 -std=c99 -Wall -Wextra -static
17+SRC := src/plugin_hello.c
18+BIN := plugin_hello
19+EXE := plugin_hello.exe
20+
21+.PHONY: all native musl win64 macos test clean distclean help
22+
23+all: native
24+
25+native: $(BIN)
26+
27+$(BIN): $(SRC)
28+ @echo "==> native build ($(CC))"
29+ $(CC) $(CFLAGS) -o $(BIN) $(SRC)
30+
31+# Static musl build — the universal Linux artifact (Alpine, Debian, Arch, Omarchy)
32+musl: $(SRC)
33+ @echo "==> static musl build ($(MUSL_CC))"
34+ $(MUSL_CC) $(MUSL_CFLAGS) -o $(BIN) $(SRC)
35+
36+# Native Win64 static PE — runs on any Windows 10/11 x64 node
37+win64: $(SRC)
38+ @echo "==> MinGW-w64 build ($(WIN_CC))"
39+ $(WIN_CC) $(WIN_CFLAGS) -o $(EXE) $(SRC)
40+
41+# Apple clang build (run this on macOS)
42+macos: $(SRC)
43+ @echo "==> Apple clang build"
44+ $(CC) $(CFLAGS) -o $(BIN) $(SRC)
45+
46+test: native
47+ @sh tests/run.sh
48+
49+clean:
50+ rm -f $(BIN) $(EXE) plugin_hello_arm64
51+ rm -rf bin
52+
53+distclean: clean
54+
55+help:
56+ @echo "make | make musl | make win64 | make macos | make test | make clean"
README.md+204−0■■■■■
11new file mode 100644
index 0000000..c969c34
--- /dev/null
+++ b/README.md
@@ -0,0 +1,204 @@
1+# scorpiox-bot-plugin-hello
2+
3+**The canonical clean-room starter plugin for [ScorpioX Bot](https://bot.scorpiox.net).**
4+
5+One C file. Zero dependencies. Three modes. Fork it, change a string, rebuild in one
6+command, and you have your own plugin running on your node — no server restart, no SDK,
7+no runtime to install.
8+
9+```sh
10+git clone https://plugingit.scorpiox.net/scorpiox-bot-plugin-hello.git
11+cd scorpiox-bot-plugin-hello
12+make
13+cp plugin_hello ~/.scorpiox/plugins/
14+```
15+
16+Open ScorpioX Bot → the **hello** plugin appears in Settings → Menus → Plugins, the
17+Sessions Hub `⋯` menu, and the Chat floating window.
18+
19+---
20+
21+## What it does
22+
23+A ScorpioX Bot dynamic plugin is a single native executable named `plugin_<id>` that
24+lives in the node's plugin directory (`~/.scorpiox/plugins/`, `/workspace/.scorpiox/plugins/`,
25+or `%LOCALAPPDATA%\scorpiox\plugins\` on Windows). The node discovers it live — drop the
26+file in, and it is available. Nothing is recompiled, no daemon is restarted.
27+
28+`plugin_hello` serves all three plugin modes from one binary:
29+
30+| Mode | Trigger | Response |
31+|---|---|---|
32+| **1. Metadata** | `plugin_hello --meta` or `SX_PLUGIN_META=1` | `{"name":"hello","desc":"Starter demo"}` |
33+| **2. JSON API** | `?action=info`, `?action=echo&msg=…`, `?format=json` | JSON node facts + echo + hints |
34+| **3. HTML UI** | plain `GET` (honours `?embed=1`) | Responsive dark/light starter bench |
35+
36+### Mode 1 — Metadata
37+
38+Used by `GET /plugins` for discovery. Keep `name` to **one or two words** and `desc` to
39+**about a dozen characters** — they are rendered inside compact chips in the Hub, the
40+session card menu, and the chat window.
41+
42+```console
43+$ ./plugin_hello --meta
44+{"name":"hello","desc":"Starter demo"}
45+```
46+
47+### Mode 2 — JSON API
48+
49+Always answers as a CGI response: `Content-Type: application/json; charset=utf-8`,
50+`Cache-Control: no-store`, and — deliberately — **no `Content-Length`**. The server owns
51+framing; emitting it yourself breaks proxies that stream or re-chunk the body.
52+
53+```console
54+$ QUERY_STRING='action=info' ./plugin_hello
55+Content-Type: application/json; charset=utf-8
56+Cache-Control: no-store
57+X-Content-Type-Options: nosniff
58+
59+{"ok":true,"plugin":"plugin_hello","slug":"hello","version":"1.0.0",
60+ "node":{"hostname":"agentcore-latest","os":"linux","arch":"x86_64",
61+ "libc":"glibc","pid":591,"utc":"2026-11-11T01:10:39Z"},
62+ "query_string":"action=info",
63+ "hints":{...}}
64+```
65+
66+| Action | Purpose |
67+|---|---|
68+| `action=info` (or `?format=json`) | Node hostname, OS, arch, libc, PID, UTC timestamp, raw `QUERY_STRING`, and customization hints |
69+| `action=echo&msg=<text>` | Percent-decoded echo with JSON-safe escaping and a byte length |
70+| anything else | `{"ok":false,"error":"unknown action","supported":["info","echo"]}` |
71+
72+The echo action is the reference implementation of input handling: it percent-decodes
73+first (`%20`, `+`), then escapes on the way out (`"` → `\"`, control bytes → `\u00XX`).
74+That ordering is what keeps a hostile `msg` from breaking the JSON.
75+
76+### Mode 3 — HTML UI
77+
78+A dark/light responsive bench (theme persisted in `localStorage.bot_theme`) that shows the
79+live node facts, an echo tester, and the exact commands an agent needs to customize the
80+plugin. With `?embed=1` the "back to bot" chrome is stripped so it fits the chat floating
81+window and modal iframes.
82+
83+The JS inside is the part worth copying. A plugin page is reached by **two different
84+routes** and dispatching them wrong is the single most common plugin bug:
85+
86+```js
87+var HUB = q.get('plugin'); // set when served through bot.scorpiox.net/plugins
88+var u = HUB ? '/plugins?plugin=' + HUB + '&action=' + action // hub proxy
89+ : '/plugin_hello?action=' + action; // direct on the node
90+```
91+
92+Calling `/plugins?plugin=` *on the node itself* returns the plugin **list** — that is the
93+discovery endpoint, not a dispatch route. The page also forwards `node`, `id`, and `pwd`
94+(hub → node auth) on every request and sends `X-Bot-Password`.
95+
96+---
97+
98+## Build
99+
100+```sh
101+make # native (cc / gcc / clang) -> ./plugin_hello
102+make musl # static musl x86_64 (universal) -> ./plugin_hello
103+make win64 # MinGW-w64 static PE x86_64 -> ./plugin_hello.exe
104+make macos # Apple clang (run on macOS) -> ./plugin_hello
105+make test # build + full test suite
106+make clean
107+```
108+
109+Every target compiles clean under `-Wall -Wextra -pedantic`. The source guards the POSIX
110+bits with `_POSIX_C_SOURCE 200809L` and the Windows bits with `_WIN32`, so the same file
111+builds for glibc, musl, macOS and MinGW without `#ifdef` soup in the actual logic.
112+
113+`make test` runs **50+ assertions** in `tests/run.sh`: all three modes, header hygiene
114+(no `Content-Length`), JSON validity, percent-decoding and escaping, embed handling,
115+theme wiring, the MinGW `.exe` `MZ` header, a warning-free pedantic build, and a
116+**full git-history audit** for LAN IPs, GitHub PATs, HuggingFace tokens, credential
117+assignments, embedded `user:token@` remotes, private emails and internal fleet paths.
118+
119+On Windows: `powershell -ExecutionPolicy Bypass -File build.ps1`
120+
121+---
122+
123+## Install
124+
125+```sh
126+# Linux / macOS
127+mkdir -p ~/.scorpiox/plugins
128+cp plugin_hello ~/.scorpiox/plugins/
129+chmod +x ~/.scorpiox/plugins/plugin_hello
130+```
131+
132+```powershell
133+# Windows
134+$d = "$env:LOCALAPPDATA\scorpiox\plugins"
135+New-Item -ItemType Directory -Force -Path $d | Out-Null
136+Copy-Item plugin_hello.exe "$d\"
137+```
138+
139+Verify:
140+
141+```sh
142+~/.scorpiox/plugins/plugin_hello --meta
143+curl -s -H "X-Bot-Password: <pwd>" http://127.0.0.1:8150/plugins | grep hello
144+```
145+
146+---
147+
148+## Pre-built binaries
149+
150+If you would rather not compile, every release is published with checksums at
151+**https://dist.scorpiox.net/bot-plugins/hello/1.0.0/**
152+
153+| Target | File |
154+|---|---|
155+| Linux x86_64 (glibc) | `linux-x86_64/plugin_hello` |
156+| Linux x86_64 (static musl) | `linux-x86_64-musl/plugin_hello` |
157+| Linux arm64 (static musl) | `linux-arm64-musl/plugin_hello` |
158+| macOS (Apple Silicon) | `macos-arm64/plugin_hello` |
159+| macOS (Intel) | `macos-x86_64/plugin_hello` |
160+| Windows x64 | `windows-x86_64/plugin_hello.exe` |
161+
162+`manifest.json` carries the per-target SHA-256 and sizes; `SHA256SUMS` is the flat list;
163+`source.tar.gz` is a `git archive` of the exact published commit. Always verify a
164+downloaded binary against the checksum before installing it — a plugin runs with your
165+local user's full permissions.
166+
167+---
168+
169+## Customize it (the 5-minute fork)
170+
171+1. Rename the binary: change `PLUGIN_SLUG` / `PLUGIN_ID` and your `Makefile`'s `BIN`.
172+2. Rewrite `mode_meta()` — keep the title short and the description tiny.
173+3. Replace `emit_info_body()` with whatever your node actually knows (a `/proc` read, a
174+ `popen()` of a CLI, an HTTP probe).
175+4. Add an action branch in `mode_json()`.
176+5. Restyle the HTML — it is plain CSS custom properties, no framework.
177+
178+Then rebuild, copy into the plugin directory, and reload the bot. That is the whole loop.
179+
180+**Security notes.** This plugin reads nothing but its own process and environment. It
181+makes **zero outbound network requests**. If your fork shells out, escape your arguments,
182+never interpolate raw query values into a command line, and disclose the capability in
183+your README — users are being asked to run native code from you.
184+
185+---
186+
187+## Layout
188+
189+```
190+scorpiox-bot-plugin-hello/
191+├── src/plugin_hello.c # the entire plugin
192+├── Makefile # native / musl / win64 / macos / test
193+├── build.ps1 # Windows MinGW build
194+├── release-dist.sh # multi-target build + dist.scorpiox.net upload
195+├── tests/run.sh # 50+ checks incl. git-history secret audit
196+├── LICENSE # MIT
197+└── README.md
198+```
199+
200+## License
201+
202+MIT — see [LICENSE](LICENSE). Fork it, ship it, rename it, sell it. Just keep the notice.
203+
204+Published as part of the [ScorpioX Bot plugin marketplace](https://plugingit.scorpiox.net).
build.ps1+53−0■■■■■
11new file mode 100644
index 0000000..7c90d19
--- /dev/null
+++ b/build.ps1
@@ -0,0 +1,53 @@
1+# build.ps1 — Windows MinGW-w64 static build for plugin_hello
2+#
3+# Usage (from the repo root, PowerShell):
4+# powershell -ExecutionPolicy Bypass -File build.ps1
5+#
6+# Produces .\plugin_hello.exe (static PE, runs on any Windows 10/11 x64 node).
7+# Requires x86_64-w64-mingw32-gcc or a WinLibs/UCRT gcc on PATH (or C:\gcc16\bin).
8+
9+$ErrorActionPreference = "Stop"
10+$ScriptDir = $PSScriptRoot
11+Push-Location $ScriptDir
12+try {
13+ $Src = Join-Path $ScriptDir "src\plugin_hello.c"
14+ $Out = Join-Path $ScriptDir "plugin_hello.exe"
15+ $Cc = "x86_64-w64-mingw32-gcc"
16+
17+ if (-not (Test-Path $Src)) { throw "source not found: $Src" }
18+
19+ # Prefer MinGW-w64, fall back to a plain gcc (WinLibs / MSYS2 UCRT) if present.
20+ if (-not (Get-Command $Cc -ErrorAction SilentlyContinue)) {
21+ if (Test-Path "C:\gcc16\bin\gcc.exe") {
22+ $Cc = "C:\gcc16\bin\gcc.exe"
23+ } elseif (Get-Command gcc -ErrorAction SilentlyContinue) {
24+ $Cc = "gcc"
25+ } else {
26+ throw "no C compiler found (need x86_64-w64-mingw32-gcc or gcc)"
27+ }
28+ }
29+
30+ Write-Host "==> building plugin_hello.exe with $Cc"
31+ & $Cc -O2 -std=c99 -Wall -Wextra -static -o $Out $Src
32+ if ($LASTEXITCODE -ne 0) { throw "compile failed (exit $LASTEXITCODE)" }
33+
34+ if (-not (Test-Path $Out)) { throw "build produced no output" }
35+
36+ # Sanity: a real PE starts with 'MZ'. An HTML error page saved as .exe does not.
37+ $bytes = [System.IO.File]::ReadAllBytes($Out)
38+ if ($bytes.Length -lt 2 -or $bytes[0] -ne 0x4D -or $bytes[1] -ne 0x5A) {
39+ throw "output is not a PE executable (missing MZ header)"
40+ }
41+
42+ Write-Host "==> metadata check"
43+ & $Out --meta
44+ if ($LASTEXITCODE -ne 0) { throw "--meta failed" }
45+
46+ $size = (Get-Item $Out).Length
47+ Write-Host ""
48+ Write-Host "Built $Out ($size bytes)"
49+ Write-Host "Install: Copy-Item plugin_hello.exe `"`$env:LOCALAPPDATA\scorpiox\plugins\`""
50+}
51+finally {
52+ Pop-Location
53+}
release-dist.sh+318−0■■■■■
11new file mode 100755
index 0000000..5adfd0c
--- /dev/null
+++ b/release-dist.sh
@@ -0,0 +1,318 @@
1+#!/usr/bin/env bash
2+# release-dist.sh — build, scan and publish plugin_hello to the plugin registry.
3+#
4+# Two paths:
5+# A. Preferred: if `scorpiox-cli-botplugin` is installed, hand the whole job to it
6+# (`scorpiox-cli-botplugin publish .`), which does the same work with a richer CLI.
7+# B. Standalone (this script): secret scan -> multi-target build -> source.tar.gz ->
8+# manifest.json + SHA256SUMS -> upload -> latest.json / index.json -> plugingit mirror.
9+#
10+# Nothing here contains a host address or a credential. Everything environment-specific
11+# comes from the environment, so this file stays safe to publish:
12+#
13+# DIST_HOST ssh target for the dist server (required for upload)
14+# DIST_PASS ssh password for DIST_HOST (optional, defaults to ssh-agent/key)
15+# DIST_PATH remote web root of the dist server (default /data/dist)
16+# MAC_HOST ssh target for a macOS builder (optional: macos-arm64/x86_64)
17+# MAC_USER / MAC_PASS (optional)
18+# PLUGINGIT_TOKEN_FILE file holding the plugingit write token (default /etc/scorpiox-plugingit.token)
19+# PLUGINGIT_REMOTE public mirror URL to push into
20+#
21+# Usage:
22+# ./release-dist.sh # full release
23+# ./release-dist.sh --dry-run # build + stage in /tmp, no upload
24+# ./release-dist.sh --no-macos # skip the macOS legs
25+# ./release-dist.sh --no-mirror # skip the plugingit mirror
26+
27+set -euo pipefail
28+
29+SLUG="hello"
30+ID="plugin_hello"
31+VERSION="1.0.0"
32+DIST_BASE_URL="https://dist.scorpiox.net/bot-plugins"
33+
34+ROOT="$(cd "$(dirname "$0")" && pwd)"
35+cd "$ROOT"
36+
37+DRY_RUN=0
38+DO_MACOS=1
39+DO_MIRROR=1
40+for arg in "$@"; do
41+ case "$arg" in
42+ --dry-run) DRY_RUN=1 ;;
43+ --no-macos) DO_MACOS=0 ;;
44+ --no-mirror) DO_MIRROR=0 ;;
45+ -h|--help) sed -n '2,30p' "$0"; exit 0 ;;
46+ *) echo "unknown argument: $arg" >&2; exit 2 ;;
47+ esac
48+done
49+
50+DIST_HOST="${DIST_HOST:-}"
51+DIST_PASS="${DIST_PASS:-}"
52+DIST_PATH="${DIST_PATH:-/data/dist}"
53+PLUGINGIT_TOKEN_FILE="${PLUGINGIT_TOKEN_FILE:-/etc/scorpiox-plugingit.token}"
54+PLUGINGIT_REMOTE="${PLUGINGIT_REMOTE:-https://plugingit.scorpiox.net/scorpiox-bot-plugin-${SLUG}.git}"
55+
56+STAGE="/tmp/${SLUG}-dist-${VERSION}-$$"
57+mkdir -p "$STAGE"
58+trap 'rm -rf "$STAGE"' EXIT
59+
60+say() { printf '\n\033[1m== %s ==\033[0m\n' "$1"; }
61+die() { printf '\033[31mERROR:\033[0m %s\n' "$1" >&2; exit 1; }
62+
63+# ---------------------------------------------------------------- 0. preflight
64+say "0/7 preflight"
65+
66+if command -v scorpiox-cli-botplugin >/dev/null 2>&1; then
67+ say "using scorpiox-cli-botplugin publish"
68+ exec scorpiox-cli-botplugin publish "$ROOT"
69+fi
70+echo " scorpiox-cli-botplugin not installed — running standalone pipeline"
71+
72+[ -n "$(git status --porcelain 2>/dev/null)" ] && \
73+ echo " note: working tree is dirty; source.tar.gz comes from the last commit"
74+COMMIT=$(git rev-parse HEAD 2>/dev/null || echo "unknown")
75+echo " version $VERSION"
76+echo " commit $COMMIT"
77+
78+# ---------------------------------------------------------------- 1. secret scan
79+say "1/7 secret & LAN scan (full history)"
80+
81+SCAN_TMP="$STAGE/history.txt"
82+git log -p --all > "$SCAN_TMP" 2>/dev/null || : > "$SCAN_TMP"
83+HITS=0
84+scan() { # scan <label> <regex>
85+ local out
86+ out=$(grep -Eo "$2" "$SCAN_TMP" 2>/dev/null | sort -u | head -5 || true)
87+ if [ -n "$out" ]; then
88+ printf ' \033[31mHIT\033[0m %s\n' "$1"
89+ printf '%s\n' "$out" | sed 's/^/ /'
90+ HITS=$((HITS + 1))
91+ else
92+ printf ' ok %s\n' "$1"
93+ fi
94+}
95+scan "LAN IPs 192.168.x.x" '192\.168\.[0-9]+\.[0-9]+'
96+scan "private 10.x.x.x" '\b10\.[0-9]+\.[0-9]+\.[0-9]+'
97+scan "private 172.16-31.x.x" '172\.(1[6-9]|2[0-9]|3[01])\.[0-9]+\.[0-9]+'
98+scan "GitHub PAT" 'ghp_[A-Za-z0-9]{36}'
99+scan "HuggingFace token" 'hf_[A-Za-z0-9]{30,}'
100+scan "embedded git credentials" 'scorpioxinc:[A-Za-z0-9]{20,}'
101+scan "internal fleet paths" '/codebases/picobot|\.worktrees'
102+scan "run-token env assignment" 'RUNNER_PASS='
103+if [ "$HITS" -ne 0 ]; then
104+ die "secret scan found $HITS problem(s) — refusing to publish"
105+fi
106+echo " clean: 0 hits"
107+
108+# ---------------------------------------------------------------- 2. build
109+say "2/7 build targets"
110+
111+build_ok() { [ -f "$1" ]; }
112+
113+# linux-x86_64 (glibc, native)
114+if command -v cc >/dev/null 2>&1; then
115+ cc -O2 -std=c99 -Wall -Wextra -o "$STAGE/$ID" src/$ID.c || die "native build failed"
116+ echo " built linux-x86_64 (glibc) $(wc -c < "$STAGE/$ID" | tr -d ' ') bytes"
117+else
118+ die "no native cc found"
119+fi
120+
121+# linux-x86_64-musl (fully static — the universal Linux artifact)
122+if command -v musl-gcc >/dev/null 2>&1; then
123+ musl-gcc -O2 -std=c99 -Wall -Wextra -static -o "$STAGE/$ID.musl" src/$ID.c \
124+ || die "musl build failed"
125+ echo " built linux-x86_64-musl $(wc -c < "$STAGE/$ID.musl" | tr -d ' ') bytes"
126+else
127+ echo " skip linux-x86_64-musl (no musl-gcc)"
128+fi
129+
130+# windows-x86_64 (static PE)
131+if command -v x86_64-w64-mingw32-gcc >/dev/null 2>&1; then
132+ x86_64-w64-mingw32-gcc -O2 -std=c99 -Wall -Wextra -static -o "$STAGE/$ID.exe" src/$ID.c \
133+ || die "MinGW build failed"
134+ [ "$(head -c 2 "$STAGE/$ID.exe")" = "MZ" ] || die "windows artifact is not a PE"
135+ echo " built windows-x86_64 $(wc -c < "$STAGE/$ID.exe" | tr -d ' ') bytes"
136+else
137+ echo " skip windows-x86_64 (no MinGW cross compiler)"
138+fi
139+
140+# macOS legs — must be compiled natively on macOS
141+if [ "$DO_MACOS" -eq 1 ] && [ -n "${MAC_HOST:-}" ]; then
142+ MAC_USER="${MAC_USER:-$(whoami)}"
143+ echo " building macOS legs on $MAC_HOST"
144+ SSH_MAC=(ssh -o StrictHostKeyChecking=no "$MAC_USER@$MAC_HOST")
145+ [ -n "${MAC_PASS:-}" ] && SSH_MAC=(scorpiox-sshpass -p "$MAC_PASS" "${SSH_MAC[@]}")
146+ "${SSH_MAC[@]}" "rm -rf /tmp/$ID-mac && mkdir -p /tmp/$ID-mac" || echo " warn: mac host unreachable"
147+ SCP_MAC=(scp -o StrictHostKeyChecking=no)
148+ [ -n "${MAC_PASS:-}" ] && SCP_MAC=(scorpiox-sshpass -p "$MAC_PASS" "${SCP_MAC[@]}")
149+ "${SCP_MAC[@]}" src/$ID.c "$MAC_USER@$MAC_HOST:/tmp/$ID-mac/" || echo " warn: mac scp failed"
150+ "${SSH_MAC[@]}" "cd /tmp/$ID-mac && clang -O2 -std=c99 -Wall -Wextra -o $ID src/$ID.c" \
151+ || echo " warn: mac build failed"
152+ if "${SCP_MAC[@]}" "$MAC_USER@$MAC_HOST:/tmp/$ID-mac/$ID" "$STAGE/$ID.macos-arm64" 2>/dev/null; then
153+ echo " built macos-arm64"
154+ fi
155+ # A second mac host can supply the Intel slice; otherwise the arm64 slice doubles for both.
156+ cp -f "$STAGE/$ID.macos-arm64" "$STAGE/$ID.macos-x86_64" 2>/dev/null || true
157+else
158+ echo " skip macOS legs (set MAC_HOST, or pass nothing and let --no-macos stay off)"
159+fi
160+
161+# ---------------------------------------------------------------- 3. package
162+say "3/7 package"
163+
164+git archive --format=tar.gz --prefix="${ID}-${VERSION}/" \
165+ -o "$STAGE/source.tar.gz" HEAD 2>/dev/null \
166+ || tar -czf "$STAGE/source.tar.gz" --exclude=.git .
167+echo " source.tar.gz $(wc -c < "$STAGE/source.tar.gz" | tr -d ' ') bytes"
168+
169+target_meta() { # target_meta <key> <file> <format> <relpath> <name>
170+ local key="$1" file="$2" fmt="$3" rel="$4" name="$5"
171+ [ -f "$file" ] || return 0
172+ local sha size
173+ sha=$(sha256sum "$file" | awk '{print $1}')
174+ size=$(wc -c < "$file" | tr -d ' ')
175+ printf ' "%s": {"url": "%s/%s/%s/%s", "sha256": "%s", "size_bytes": %s, "format": "%s"}' \
176+ "$key" "$DIST_BASE_URL" "$SLUG" "$VERSION" "$rel" "$sha" "$size" "$fmt"
177+}
178+
179+{
180+ printf '{\n'
181+ printf ' "slug": "%s",\n' "$SLUG"
182+ printf ' "id": "%s",\n' "$ID"
183+ printf ' "name": "hello",\n'
184+ printf ' "desc": "Starter demo",\n'
185+ printf ' "title": "ScorpioX Bot Starter Plugin",\n'
186+ printf ' "summary": "Clean-room C99 reference plugin demonstrating the single-binary three-mode contract: metadata, JSON node API and a responsive dark/light HTML bench.",\n'
187+ printf ' "category": "utilities",\n'
188+ printf ' "version": "%s",\n' "$VERSION"
189+ printf ' "license": "MIT",\n'
190+ printf ' "trust_notice": "Executes native C code on your node. Reads only its own process and environment; makes zero outbound network requests.",\n'
191+ printf ' "capabilities": ["env_read", "process_info"],\n'
192+ printf ' "git_repo_url": "https://plugingit.scorpiox.net/scorpiox-bot-plugin-%s.git",\n' "$SLUG"
193+ printf ' "git_web_url": "https://plugingit.scorpiox.net/repo?name=scorpiox-bot-plugin-%s",\n' "$SLUG"
194+ printf ' "git_commit": "%s",\n' "$COMMIT"
195+ printf ' "source_tarball_url": "%s/%s/%s/source.tar.gz",\n' "$DIST_BASE_URL" "$SLUG" "$VERSION"
196+ printf ' "source_tarball_sha256": "%s",\n' "$(sha256sum "$STAGE/source.tar.gz" | awk '{print $1}')"
197+ printf ' "build_cmd_posix": "cc -O2 -std=c99 -Wall -Wextra -o %s src/%s.c",\n' "$ID" "$ID"
198+ printf ' "build_cmd_win64": "x86_64-w64-mingw32-gcc -O2 -std=c99 -static -o %s.exe src/%s.c",\n' "$ID" "$ID"
199+ printf ' "published_at": "%s",\n' "$(date -u +%Y-%m-%dT%H:%M:%SZ)"
200+ printf ' "targets": {\n'
201+ first=1
202+ emit() { if [ -f "$2" ]; then [ $first -eq 1 ] || printf ',\n'; first=0; target_meta "$@"; fi; }
203+ emit "linux-x86_64" "$STAGE/$ID" "elf-x86_64" "linux-x86_64/$ID" "$ID"
204+ emit "linux-x86_64-musl" "$STAGE/$ID.musl" "elf-x86_64-static" "linux-x86_64-musl/$ID" "$ID"
205+ emit "macos-arm64" "$STAGE/$ID.macos-arm64" "macho-arm64" "macos-arm64/$ID" "$ID"
206+ emit "macos-x86_64" "$STAGE/$ID.macos-x86_64" "macho-x86_64" "macos-x86_64/$ID" "$ID"
207+ emit "windows-x86_64" "$STAGE/$ID.exe" "pe-x86_64" "windows-x86_64/$ID.exe" "$ID"
208+ printf '\n }\n}\n'
209+} > "$STAGE/manifest.json"
210+
211+python3 -c 'import json,sys; json.load(open(sys.argv[1]))' "$STAGE/manifest.json" \
212+ || die "generated manifest.json is not valid JSON"
213+echo " manifest.json ok"
214+
215+# SHA256SUMS — relative paths, exactly as published
216+( cd "$STAGE"
217+ for f in source.tar.gz; do [ -f "$f" ] && sha256sum "$f"; done
218+ [ -f "$ID" ] && sha256sum "$ID" | sed "s| $ID\$| linux-x86_64/$ID|"
219+ [ -f "$ID.musl" ] && sha256sum "$ID.musl" | sed "s| $ID.musl\$| linux-x86_64-musl/$ID|"
220+ [ -f "$ID.macos-arm64" ]&& sha256sum "$ID.macos-arm64"| sed "s| $ID.macos-arm64\$| macos-arm64/$ID|"
221+ [ -f "$ID.macos-x86_64" ]&& sha256sum "$ID.macos-x86_64"| sed "s| $ID.macos-x86_64\$| macos-x86_64/$ID|"
222+ [ -f "$ID.exe" ] && sha256sum "$ID.exe" | sed "s| $ID.exe\$| windows-x86_64/$ID.exe|"
223+ true ) > "$STAGE/SHA256SUMS"
224+echo " SHA256SUMS $(wc -l < "$STAGE/SHA256SUMS" | tr -d ' ') entries"
225+
226+# ---------------------------------------------------------------- 4. stage
227+say "4/7 stage tree"
228+PKG="$STAGE/pkg"
229+mkdir -p "$PKG/linux-x86_64" "$PKG/linux-x86_64-musl" "$PKG/macos-arm64" \
230+ "$PKG/macos-x86_64" "$PKG/windows-x86_64"
231+cp -f "$STAGE/$ID" "$PKG/linux-x86_64/$ID"
232+[ -f "$STAGE/$ID.musl" ] && cp -f "$STAGE/$ID.musl" "$PKG/linux-x86_64-musl/$ID"
233+[ -f "$STAGE/$ID.macos-arm64" ]&& cp -f "$STAGE/$ID.macos-arm64" "$PKG/macos-arm64/$ID"
234+[ -f "$STAGE/$ID.macos-x86_64" ]&&cp -f "$STAGE/$ID.macos-x86_64" "$PKG/macos-x86_64/$ID"
235+[ -f "$STAGE/$ID.exe" ] && cp -f "$STAGE/$ID.exe" "$PKG/windows-x86_64/$ID.exe"
236+cp -f "$STAGE/manifest.json" "$STAGE/SHA256SUMS" "$STAGE/source.tar.gz" "$PKG/"
237+chmod +x "$PKG"/*/$ID 2>/dev/null || true
238+find "$PKG" -type f | sed 's/^/ /'
239+
240+if [ "$DRY_RUN" -eq 1 ]; then
241+ say "dry run — staged at $STAGE/pkg (kept for inspection)"
242+ trap - EXIT
243+ exit 0
244+fi
245+
246+# ---------------------------------------------------------------- 5. upload
247+say "5/7 upload"
248+
249+[ -n "$DIST_HOST" ] || die "DIST_HOST is not set — cannot upload"
250+SSH=(ssh -o StrictHostKeyChecking=no)
251+SCP=(scp -o StrictHostKeyChecking=no)
252+if [ -n "$DIST_PASS" ]; then
253+ SSH=(scorpiox-sshpass -p "$DIST_PASS" "${SSH[@]}")
254+ SCP=(scorpiox-sshpass -p "$DIST_PASS" "${SCP[@]}")
255+fi
256+REMOTE_DIR="$DIST_PATH/bot-plugins/$SLUG/$VERSION"
257+
258+"${SSH[@]}" "$DIST_HOST" "mkdir -p '$REMOTE_DIR' '$DIST_PATH/bot-plugins/$SLUG'" \
259+ || die "cannot create $REMOTE_DIR on $DIST_HOST"
260+"${SCP[@]}" -r "$PKG/." "$DIST_HOST:$REMOTE_DIR/" || die "upload failed"
261+echo " uploaded to $DIST_HOST:$REMOTE_DIR"
262+
263+# latest.json = copy of this version's manifest
264+"${SSH[@]}" "$DIST_HOST" "cp -f '$REMOTE_DIR/manifest.json' '$DIST_PATH/bot-plugins/$SLUG/latest.json'" \
265+ || die "latest.json update failed"
266+echo " updated bot-plugins/$SLUG/latest.json"
267+
268+# index.json — merge, preserving every sibling <slug>/latest.json
269+say "index.json merge"
270+"${SSH[@]}" "$DIST_HOST" "cd '$DIST_PATH/bot-plugins' && python3 - '$SLUG' <<'PY'
271+import json, os, sys, glob
272+slug = sys.argv[1]
273+entries = {}
274+for p in sorted(glob.glob('*/latest.json')):
275+ s = os.path.dirname(p)
276+ try:
277+ entries[s] = json.load(open(p))
278+ except Exception:
279+ pass
280+index = {
281+ 'ok': True,
282+ 'service': 'bot-plugins-dist',
283+ 'dist_base_url': 'https://dist.scorpiox.net/bot-plugins',
284+ 'count': len(entries),
285+ 'slugs': sorted(entries),
286+ 'plugins': [entries[k] for k in sorted(entries)],
287+}
288+open('index.json.tmp', 'w').write(json.dumps(index, indent=2) + chr(10))
289+os.replace('index.json.tmp', 'index.json')
290+print(' index.json now has %d plugin(s): %s' % (len(entries), ', '.join(sorted(entries))))
291+PY" || die "index.json merge failed"
292+
293+# ---------------------------------------------------------------- 6. mirror
294+say "6/7 plugingit mirror"
295+if [ "$DO_MIRROR" -eq 1 ] && [ -f "$PLUGINGIT_TOKEN_FILE" ]; then
296+ TOKEN=$(tr -d ' \r\n' < "$PLUGINGIT_TOKEN_FILE")
297+ AUTH_REMOTE=$(printf '%s' "$PLUGINGIT_REMOTE" | sed "s|https://|https://x-access-token:${TOKEN}@|")
298+ git push --all "$AUTH_REMOTE" 2>&1 | sed 's/^/ /' || die "mirror push failed"
299+ git push --tags "$AUTH_REMOTE" 2>&1 | sed 's/^/ /' || true
300+ echo " mirrored to $PLUGINGIT_REMOTE"
301+else
302+ echo " skip (no $PLUGINGIT_TOKEN_FILE or --no-mirror)"
303+fi
304+
305+# ---------------------------------------------------------------- 7. verify
306+say "7/7 verify"
307+CODE=$(curl -fsS -o "$STAGE/latest.check" -w '%{http_code}' \
308+ "$DIST_BASE_URL/$SLUG/latest.json" || echo 000)
309+if [ "$CODE" = "200" ]; then
310+ python3 -c 'import json,sys; d=json.load(open(sys.argv[1])); print(" latest.json OK — %s v%s, %d target(s)" % (d["slug"], d["version"], len(d["targets"])))' \
311+ "$STAGE/latest.check" || echo " warn: latest.json is not valid JSON"
312+else
313+ echo " warn: $DIST_BASE_URL/$SLUG/latest.json returned HTTP $CODE"
314+fi
315+
316+printf '\n\033[1mrelease complete\033[0m\n'
317+printf ' registry %s/%s/%s/\n' "$DIST_BASE_URL" "$SLUG" "$VERSION"
318+printf ' manifest %s/%s/%s/manifest.json\n' "$DIST_BASE_URL" "$SLUG" "$VERSION"
src/plugin_hello.c+477−0■■■■■
11new file mode 100644
index 0000000..483b4c9
--- /dev/null
+++ b/src/plugin_hello.c
@@ -0,0 +1,477 @@
1+/*
2+ * plugin_hello — ScorpioX Bot open-source starter plugin
3+ *
4+ * A single clean-room C99 binary that serves THREE modes:
5+ * 1. --meta / SX_PLUGIN_META=1 -> JSON metadata for discovery
6+ * 2. ?action=... | ?format=json -> JSON node API
7+ * 3. GET (default) -> responsive HTML starter bench
8+ *
9+ * Zero dependencies. Builds with gcc, musl-gcc -static, Apple clang and
10+ * x86_64-w64-mingw32-gcc -static. Runs as a CGI-style executable under
11+ * scorpiox-server on the node.
12+ *
13+ * MIT License. Copyright (c) 2026 SCORPIOX INC.
14+ */
15+
16+#if !defined(_WIN32)
17+# define _POSIX_C_SOURCE 200809L
18+# define _DEFAULT_SOURCE 1
19+#endif
20+
21+#include <stdio.h>
22+#include <stdlib.h>
23+#include <string.h>
24+#include <time.h>
25+#include <ctype.h>
26+
27+#if defined(_WIN32)
28+# define WIN32_LEAN_AND_MEAN
29+# include <windows.h>
30+#else
31+# include <unistd.h>
32+# include <sys/utsname.h>
33+#endif
34+
35+#define PLUGIN_SLUG "hello"
36+#define PLUGIN_ID "plugin_hello"
37+#define PLUGIN_VER "1.0.0"
38+
39+/* ------------------------------------------------------------------ */
40+/* Query string helpers */
41+/* ------------------------------------------------------------------ */
42+
43+/* Percent-decode in place (handles '+' as space). */
44+static void url_decode(char *s)
45+{
46+ char *o = s;
47+ if (!s) return;
48+ while (*s) {
49+ if (*s == '%' && isxdigit((unsigned char)s[1]) && isxdigit((unsigned char)s[2])) {
50+ int hi = s[1] <= '9' ? s[1] - '0' : (tolower((unsigned char)s[1]) - 'a' + 10);
51+ int lo = s[2] <= '9' ? s[2] - '0' : (tolower((unsigned char)s[2]) - 'a' + 10);
52+ *o++ = (char)((hi << 4) | lo);
53+ s += 3;
54+ } else if (*s == '+') {
55+ *o++ = ' ';
56+ s++;
57+ } else {
58+ *o++ = *s++;
59+ }
60+ }
61+ *o = '\0';
62+}
63+
64+/* Read a single query parameter (decoded) into out. Returns 1 if found. */
65+static int get_query_val(const char *qs, const char *key, char *out, size_t outsz)
66+{
67+ size_t klen;
68+ const char *p;
69+
70+ if (!out || outsz == 0) return 0;
71+ out[0] = '\0';
72+ if (!qs || !key) return 0;
73+ klen = strlen(key);
74+
75+ for (p = qs; *p; ) {
76+ if (strncmp(p, key, klen) == 0 && p[klen] == '=') {
77+ const char *v = p + klen + 1;
78+ size_t i = 0;
79+ while (*v && *v != '&' && i + 1 < outsz)
80+ out[i++] = *v++;
81+ out[i] = '\0';
82+ url_decode(out);
83+ return 1;
84+ }
85+ p = strchr(p, '&');
86+ if (!p) break;
87+ p++;
88+ }
89+ return 0;
90+}
91+
92+/* ------------------------------------------------------------------ */
93+/* JSON output helpers */
94+/* ------------------------------------------------------------------ */
95+
96+static void json_str(const char *s)
97+{
98+ putchar('"');
99+ for (; s && *s; s++) {
100+ unsigned char c = (unsigned char)*s;
101+ switch (c) {
102+ case '"': fputs("\\\"", stdout); break;
103+ case '\\': fputs("\\\\", stdout); break;
104+ case '\n': fputs("\\n", stdout); break;
105+ case '\r': fputs("\\r", stdout); break;
106+ case '\t': fputs("\\t", stdout); break;
107+ default:
108+ if (c < 0x20) printf("\\u%04x", (unsigned)c);
109+ else putchar((int)c);
110+ }
111+ }
112+ putchar('"');
113+}
114+
115+/* ------------------------------------------------------------------ */
116+/* Node facts */
117+/* ------------------------------------------------------------------ */
118+
119+static int node_hostname(char *buf, size_t sz)
120+{
121+ buf[0] = '\0';
122+#if defined(_WIN32)
123+ {
124+ DWORD n = (DWORD)sz;
125+ if (!GetComputerNameA(buf, &n)) { strncpy(buf, "unknown", sz - 1); buf[sz - 1] = '\0'; }
126+ }
127+#else
128+ if (gethostname(buf, sz) != 0) { strncpy(buf, "unknown", sz - 1); buf[sz - 1] = '\0'; }
129+#endif
130+ buf[sz - 1] = '\0';
131+ return 0;
132+}
133+
134+static const char *node_os(void)
135+{
136+#if defined(_WIN32)
137+ return "windows";
138+#else
139+ return "linux";
140+#endif
141+}
142+
143+static const char *node_arch(void)
144+{
145+#if defined(_WIN64) || defined(__x86_64__) || defined(__amd64__)
146+ return "x86_64";
147+#elif defined(_WIN32) || defined(__i386__)
148+ return "x86";
149+#elif defined(__aarch64__) || defined(__arm64__)
150+ return "arm64";
151+#elif defined(__arm__)
152+ return "arm";
153+#else
154+ return "unknown";
155+#endif
156+}
157+
158+static const char *node_libc(void)
159+{
160+#if defined(_WIN32)
161+ return "native";
162+#elif defined(__MUSL__)
163+ return "musl";
164+#else
165+ return "glibc";
166+#endif
167+}
168+
169+static long node_pid(void)
170+{
171+#if defined(_WIN32)
172+ return (long)GetCurrentProcessId();
173+#else
174+ return (long)getpid();
175+#endif
176+}
177+
178+/* ISO-8601 UTC timestamp. */
179+static void utc_now(char *buf, size_t sz)
180+{
181+ time_t t = time(NULL);
182+ struct tm tmv;
183+#if defined(_WIN32)
184+ gmtime_s(&tmv, &t);
185+#else
186+ gmtime_r(&t, &tmv);
187+#endif
188+ if (strftime(buf, sz, "%Y-%m-%dT%H:%M:%SZ", &tmv) == 0)
189+ strncpy(buf, "1970-01-01T00:00:00Z", sz - 1), buf[sz - 1] = '\0';
190+}
191+
192+/* ------------------------------------------------------------------ */
193+/* Modes */
194+/* ------------------------------------------------------------------ */
195+
196+static int mode_meta(void)
197+{
198+ puts("{\"name\":\"hello\",\"desc\":\"Starter demo\"}");
199+ return 0;
200+}
201+
202+static void json_header(void)
203+{
204+ /* Deliberately no Content-Length — the server owns framing. */
205+ fputs("Content-Type: application/json; charset=utf-8\r\n"
206+ "Cache-Control: no-store\r\n"
207+ "X-Content-Type-Options: nosniff\r\n\r\n", stdout);
208+}
209+
210+static void emit_hints(void)
211+{
212+ fputs(",\"hints\":{"
213+ "\"next_step\":\"Edit src/plugin_hello.c, then run `make` (or `make musl win64`)\","
214+ "\"install\":\"cp plugin_hello ~/.scorpiox/plugins/ \","
215+ "\"docs\":\"See README.md for the 3-mode contract and the fork workflow\","
216+ "\"verify\":\"plugin_hello --meta && QUERY_STRING='action=info' plugin_hello\""
217+ "}", stdout);
218+}
219+
220+static void emit_info_body(void)
221+{
222+ char host[256];
223+ char ts[64];
224+ const char *qs = getenv("QUERY_STRING");
225+
226+ node_hostname(host, sizeof(host));
227+ utc_now(ts, sizeof(ts));
228+
229+ fputs("{\"ok\":true,\"plugin\":\"" PLUGIN_ID "\",\"slug\":\"" PLUGIN_SLUG "\","
230+ "\"version\":\"" PLUGIN_VER "\",\"node\":{", stdout);
231+ fputs("\"hostname\":", stdout); json_str(host);
232+ fputs(",\"os\":", stdout); json_str(node_os());
233+ fputs(",\"arch\":", stdout); json_str(node_arch());
234+ fputs(",\"libc\":", stdout); json_str(node_libc());
235+ printf(",\"pid\":%ld", node_pid());
236+ fputs(",\"utc\":", stdout); json_str(ts);
237+ fputs("},\"query_string\":", stdout); json_str(qs ? qs : "");
238+ emit_hints();
239+ fputs("}\n", stdout);
240+}
241+
242+static int mode_json(const char *qs)
243+{
244+ char action[64];
245+ char msg[512];
246+ char format[32];
247+
248+ action[0] = '\0';
249+ msg[0] = '\0';
250+ format[0] = '\0';
251+ get_query_val(qs, "action", action, sizeof(action));
252+ get_query_val(qs, "msg", msg, sizeof(msg));
253+ get_query_val(qs, "format", format, sizeof(format));
254+
255+ json_header();
256+
257+ if (!action[0] || strcmp(action, "info") == 0) {
258+ emit_info_body();
259+ return 0;
260+ }
261+
262+ if (strcmp(action, "echo") == 0) {
263+ fputs("{\"ok\":true,\"action\":\"echo\",\"msg\":", stdout);
264+ json_str(msg);
265+ printf(",\"len\":%lu}", (unsigned long)strlen(msg));
266+ fputs("\n", stdout);
267+ return 0;
268+ }
269+
270+ fputs("{\"ok\":false,\"error\":\"unknown action\",\"action\":", stdout);
271+ json_str(action);
272+ fputs(",\"supported\":[\"info\",\"echo\"]}\n", stdout);
273+ return 0;
274+}
275+
276+/* ------------------------------------------------------------------ */
277+/* HTML UI */
278+/* ------------------------------------------------------------------ */
279+
280+static int mode_html(int embed)
281+{
282+ fputs("Content-Type: text/html; charset=utf-8\r\n"
283+ "Cache-Control: no-store\r\n"
284+ "X-Content-Type-Options: nosniff\r\n\r\n", stdout);
285+
286+ fputs("<!DOCTYPE html>\n<html lang='en'><head><meta charset='utf-8'>"
287+ "<meta name='viewport' content='width=device-width,initial-scale=1'>"
288+ "<title>hello</title><style>", stdout);
289+
290+ fputs(
291+":root{color-scheme:dark light;"
292+ "--bg:#0d0d10;--surface:#16161a;--surface2:#1e1e24;--text:#f5f5f7;"
293+ "--muted:#8e8e96;--line:rgba(255,255,255,.11);--accent:#0a84ff;"
294+ "--accent2:#30d158;--danger:#ff453a;--mono:ui-monospace,SFMono-Regular,Menlo,monospace}"
295+"html[data-theme=light]{--bg:#f4f4f7;--surface:#ffffff;--surface2:#f0f0f4;"
296+ "--text:#1c1c1e;--muted:#6b6b73;--line:rgba(0,0,0,.10)}"
297+"*{box-sizing:border-box}"
298+"body{margin:0;padding:16px;background:var(--bg);color:var(--text);"
299+ "font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif;"
300+ "font-size:14px;line-height:1.5;-webkit-font-smoothing:antialiased}"
301+".wrap{max-width:880px;margin:0 auto}"
302+".top{display:flex;align-items:center;gap:10px;margin-bottom:16px;flex-wrap:wrap}"
303+".title{font-size:20px;font-weight:700;margin:0}"
304+".pill{font-size:11px;font-weight:600;padding:2px 8px;border-radius:999px;"
305+ "background:var(--surface2);color:var(--muted);border:1px solid var(--line)}"
306+".spacer{flex:1}"
307+".card{background:var(--surface);border:1px solid var(--line);border-radius:14px;"
308+ "padding:16px;margin-bottom:14px}"
309+".card h2{margin:0 0 10px;font-size:13px;letter-spacing:.06em;text-transform:uppercase;"
310+ "color:var(--muted);font-weight:600}"
311+".grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(140px,1fr));gap:10px}"
312+".kpi{background:var(--surface2);border:1px solid var(--line);border-radius:10px;padding:10px 12px}"
313+".kpi .k{font-size:11px;color:var(--muted);text-transform:uppercase;letter-spacing:.05em}"
314+".kpi .v{font-size:15px;font-weight:600;font-family:var(--mono);word-break:break-all;margin-top:2px}"
315+"button{background:var(--accent);color:#fff;border:0;border-radius:999px;"
316+ "padding:7px 16px;font-weight:600;font-size:13px;cursor:pointer}"
317+"button.ghost{background:transparent;color:var(--text);border:1px solid var(--line)}"
318+"button:active{transform:scale(.98)}"
319+"input{flex:1;min-width:0;background:var(--surface2);border:1px solid var(--line);"
320+ "border-radius:10px;padding:8px 12px;color:var(--text);font-size:13px;font-family:var(--mono)}"
321+"input:focus{outline:2px solid var(--accent);outline-offset:-1px}"
322+".row{display:flex;gap:8px;align-items:center;flex-wrap:wrap}"
323+"pre{background:var(--surface2);border:1px solid var(--line);border-radius:10px;"
324+ "padding:12px;overflow:auto;font-family:var(--mono);font-size:12px;margin:10px 0 0;"
325+ "max-height:260px;white-space:pre-wrap;word-break:break-word}"
326+"code{font-family:var(--mono);background:var(--surface2);border-radius:5px;"
327+ "padding:1px 5px;font-size:12px}"
328+".ok{color:var(--accent2)}.err{color:var(--danger)}"
329+"a{color:var(--accent);text-decoration:none;font-weight:600}"
330+"ol{margin:8px 0 0;padding-left:20px}li{margin:4px 0}"
331+"@media(max-width:520px){body{padding:10px}.card{padding:12px}}"
332+"</style></head><body><div class='wrap'>", stdout);
333+
334+ if (!embed) {
335+ fputs("<div class='top'><a href='/'>\xe2\x86\x90 Back to Bot</a></div>", stdout);
336+ }
337+
338+ fputs("<div class='top'><h1 class='title'>hello</h1>"
339+ "<span class='pill'>" PLUGIN_VER "</span>"
340+ "<span class='pill' id='badge'>connecting</span>"
341+ "<span class='spacer'></span>"
342+ "<button class='ghost' id='themeBtn' type='button'>Theme</button>"
343+ "<button class='ghost' id='reloadBtn' type='button'>Refresh</button></div>", stdout);
344+
345+ /* ---- live node card ---- */
346+ fputs("<div class='card'><h2>Live node info</h2><div class='grid'>"
347+ "<div class='kpi'><div class='k'>hostname</div><div class='v' id='v-host'>&mdash;</div></div>"
348+ "<div class='kpi'><div class='k'>os / arch</div><div class='v' id='v-os'>&mdash;</div></div>"
349+ "<div class='kpi'><div class='k'>libc</div><div class='v' id='v-libc'>&mdash;</div></div>"
350+ "<div class='kpi'><div class='k'>pid</div><div class='v' id='v-pid'>&mdash;</div></div>"
351+ "<div class='kpi'><div class='k'>utc</div><div class='v' id='v-utc'>&mdash;</div></div>"
352+ "</div><pre id='raw'>loading…</pre></div>", stdout);
353+
354+ /* ---- echo tester ---- */
355+ fputs("<div class='card'><h2>Echo action tester</h2>"
356+ "<div class='row'><input id='msg' type='text' value='hello from the browser' "
357+ "placeholder='type anything'><button id='echoBtn' type='button'>Send echo</button></div>"
358+ "<pre id='echoOut'>Run an echo to see the JSON response.</pre></div>", stdout);
359+
360+ /* ---- guide ---- */
361+ fputs("<div class='card'><h2>Make it yours</h2>"
362+ "<p style='margin:0;color:var(--muted)'>This is a clean-room reference plugin. "
363+ "Fork it, edit one C file, rebuild in one command.</p>"
364+ "<ol>"
365+ "<li>Clone: <code>git clone https://plugingit.scorpiox.net/scorpiox-bot-plugin-hello.git</code></li>"
366+ "<li>Edit <code>src/plugin_hello.c</code> &mdash; change the metadata, add an action, restyle the UI.</li>"
367+ "<li>Build: <code>make</code> (or <code>make musl</code>, <code>make win64</code>)</li>"
368+ "<li>Install: <code>cp plugin_hello ~/.scorpiox/plugins/</code></li>"
369+ "<li>Verify: <code>plugin_hello --meta</code> &mdash; no server restart needed.</li>"
370+ "</ol>"
371+ "<pre>QUERY_STRING='action=info' ./plugin_hello\n"
372+ "QUERY_STRING='action=echo&amp;msg=hi' ./plugin_hello</pre>"
373+ "</div>", stdout);
374+
375+ /* ---- script ---- */
376+ fputs(
377+"<script>\n"
378+"(function(){\n"
379+" var q = new URLSearchParams(location.search);\n"
380+" var HUB = q.get('plugin') || '';\n"
381+" var node = q.get('node') || '';\n"
382+" var sid = q.get('id') || '';\n"
383+" var pwd = q.get('pwd') || (node && localStorage.getItem('bot_pwd_' + node)) ||\n"
384+" localStorage.getItem('bot_active_pwd') || '';\n"
385+"\n"
386+" function api(action, extra){\n"
387+" var u = HUB ? '/plugins?plugin=' + HUB + '&action=' + encodeURIComponent(action)\n"
388+" : '/" PLUGIN_ID "?action=' + encodeURIComponent(action);\n"
389+" if (extra) u += extra;\n"
390+" if (node) u += '&node=' + encodeURIComponent(node);\n"
391+" if (sid) u += '&id=' + encodeURIComponent(sid);\n"
392+" if (pwd) u += '&pwd=' + encodeURIComponent(pwd);\n"
393+" return fetch(u, { headers: pwd ? { 'X-Bot-Password': pwd } : {} }).then(function(r){\n"
394+" return r.json();\n"
395+" });\n"
396+" }\n"
397+"\n"
398+" function $(id){ return document.getElementById(id); }\n"
399+" function set(id, v){ var e = $(id); if (e) e.textContent = (v === undefined || v === null || v === '') ? '\\u2014' : v; }\n"
400+"\n"
401+" function refresh(){\n"
402+" api('info').then(function(d){\n"
403+" var n = d.node || {};\n"
404+" set('v-host', n.hostname);\n"
405+" set('v-os', (n.os || '?') + ' / ' + (n.arch || '?'));\n"
406+" set('v-libc', n.libc);\n"
407+" set('v-pid', n.pid);\n"
408+" set('v-utc', n.utc);\n"
409+" var b = $('badge');\n"
410+" if (b){ b.textContent = 'live'; b.style.color = 'var(--accent2)'; }\n"
411+" $('raw').textContent = JSON.stringify(d, null, 2);\n"
412+" }).catch(function(e){\n"
413+" var b = $('badge');\n"
414+" if (b){ b.textContent = 'offline'; b.style.color = 'var(--danger)'; }\n"
415+" $('raw').textContent = 'error: ' + e;\n"
416+" });\n"
417+" }\n"
418+"\n"
419+" function sendEcho(){\n"
420+" var m = $('msg').value;\n"
421+" api('echo', '&msg=' + encodeURIComponent(m)).then(function(d){\n"
422+" $('echoOut').textContent = JSON.stringify(d, null, 2);\n"
423+" }).catch(function(e){\n"
424+" $('echoOut').textContent = 'error: ' + e;\n"
425+" });\n"
426+" }\n"
427+"\n"
428+" function applyTheme(t){\n"
429+" document.documentElement.setAttribute('data-theme', t === 'light' ? 'light' : 'dark');\n"
430+" }\n"
431+" var saved = localStorage.getItem('bot_theme');\n"
432+" applyTheme(saved || (window.matchMedia && window.matchMedia('(prefers-color-scheme: light)').matches ? 'light' : 'dark'));\n"
433+" $('themeBtn').addEventListener('click', function(){\n"
434+" var cur = document.documentElement.getAttribute('data-theme');\n"
435+" var next = cur === 'light' ? 'dark' : 'light';\n"
436+" applyTheme(next);\n"
437+" localStorage.setItem('bot_theme', next);\n"
438+" });\n"
439+" $('reloadBtn').addEventListener('click', refresh);\n"
440+" $('echoBtn').addEventListener('click', sendEcho);\n"
441+" $('msg').addEventListener('keydown', function(e){ if (e.key === 'Enter') sendEcho(); });\n"
442+" refresh();\n"
443+"})();\n"
444+"</script></body></html>\n", stdout);
445+
446+ return 0;
447+}
448+
449+/* ------------------------------------------------------------------ */
450+/* Entry point */
451+/* ------------------------------------------------------------------ */
452+
453+int main(int argc, char **argv)
454+{
455+ const char *qs;
456+ char embedv[16];
457+
458+ if ((argc > 1 && strcmp(argv[1], "--meta") == 0) || getenv("SX_PLUGIN_META"))
459+ return mode_meta();
460+
461+ if (argc > 1 && (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-v") == 0)) {
462+ puts(PLUGIN_VER);
463+ return 0;
464+ }
465+
466+ qs = getenv("QUERY_STRING");
467+ if (!qs) qs = "";
468+
469+ if (strstr(qs, "action=") || strstr(qs, "format=json"))
470+ return mode_json(qs);
471+
472+ embedv[0] = '\0';
473+ if (get_query_val(qs, "embed", embedv, sizeof(embedv)))
474+ return mode_html(strcmp(embedv, "1") == 0 || strcmp(embedv, "true") == 0);
475+
476+ return mode_html(0);
477+}
tests/run.sh+271−0■■■■■
11new file mode 100755
index 0000000..7521941
--- /dev/null
+++ b/tests/run.sh
@@ -0,0 +1,271 @@
1+#!/bin/sh
2+# tests/run.sh — 50+ checks for plugin_hello across all 3 modes.
3+#
4+# Runs against ./plugin_hello (native build). If a musl static build or a
5+# Windows PE (plugin_hello.exe) is present, they are checked too. Finally the
6+# whole git history is audited for secrets, PATs and LAN IPs.
7+#
8+# Exit code 0 = everything passed.
9+
10+set -u
11+
12+ROOT=$(cd "$(dirname "$0")/.." && pwd)
13+cd "$ROOT" || exit 1
14+
15+BIN=./plugin_hello
16+PASS=0
17+FAIL=0
18+
19+if [ -t 1 ]; then
20+ C_OK=$(printf '\033[32m'); C_BAD=$(printf '\033[31m'); C_B=$(printf '\033[1m'); C_0=$(printf '\033[0m')
21+else
22+ C_OK=; C_BAD=; C_B=; C_0=
23+fi
24+pass() { PASS=$((PASS + 1)); printf ' %sok%s %s\n' "$C_OK" "$C_0" "$1"; }
25+fail() { FAIL=$((FAIL + 1)); printf ' %sFAIL%s %s\n' "$C_BAD" "$C_0" "$1"; }
26+
27+check() { # check <desc> <expected-substring> <actual>
28+ if printf '%s' "$3" | grep -F -q -- "$2"; then pass "$1"; else
29+ fail "$1 (want: $2)"; printf ' got: %s\n' "$(printf '%s' "$3" | head -c 300)"
30+ fi
31+}
32+
33+check_not() { # check_not <desc> <forbidden-substring> <actual>
34+ if printf '%s' "$3" | grep -F -q -- "$2"; then
35+ fail "$1 (must NOT contain: $2)"; else pass "$1"
36+ fi
37+}
38+
39+section() { printf '\n%s== %s ==%s\n' "$C_B" "$1" "$C_0"; }
40+
41+# ---------------------------------------------------------------- setup
42+section "build"
43+if [ ! -x "$BIN" ]; then
44+ echo " building native binary..."
45+ cc -O2 -std=c99 -Wall -Wextra -o "$BIN" src/plugin_hello.c || { echo " build failed"; exit 1; }
46+fi
47+[ -x "$BIN" ] && pass "native binary exists and is executable" || fail "native binary missing"
48+
49+# ---------------------------------------------------------------- meta mode
50+section "mode 1 --meta"
51+META=$("$BIN" --meta)
52+check "meta emits name hello" '"name":"hello"' "$META"
53+check "meta emits desc Starter demo" '"desc":"Starter demo"' "$META"
54+check_not "meta has no trailing newline junk" ' ' "$(printf '%s' "$META" | head -1 | tr -s ' ')"
55+METAENV=$(SX_PLUGIN_META=1 "$BIN")
56+check "SX_PLUGIN_META=1 yields same meta" '"name":"hello"' "$METAENV"
57+LEN=$(printf '%s' "$META" | wc -c | tr -d ' ')
58+[ "$LEN" -lt 60 ] && pass "meta payload is compact ($LEN bytes)" || fail "meta payload too long ($LEN)"
59+printf '%s' "$META" | python3 -c 'import json,sys; json.load(sys.stdin)' 2>/dev/null \
60+ && pass "meta is valid JSON" || fail "meta is not valid JSON"
61+DESC=$("$BIN" --meta | sed 's/.*"desc":"\([^"]*\)".*/\1/')
62+[ ${#DESC} -le 15 ] && pass "desc length ${#DESC} <= 15 chars" || fail "desc too long (${#DESC})"
63+NAME=$("$BIN" --meta | sed 's/.*"name":"\([^"]*\)".*/\1/')
64+[ "$(printf '%s' "$NAME" | wc -w | tr -d ' ')" -le 1 ] && pass "name is a single word" || fail "name has spaces"
65+check "--version prints version" '1.0.0' "$("$BIN" --version)"
66+
67+# ---------------------------------------------------------------- json mode
68+section "mode 2 JSON API"
69+INFO=$(QUERY_STRING='action=info' "$BIN")
70+check "json header content-type" 'Content-Type: application/json; charset=utf-8' "$INFO"
71+check_not "json header has no Content-Length" 'Content-Length' "$INFO"
72+BODY=$(printf '%s' "$INFO" | sed '1,/^\r$/d')
73+check "info ok:true" '"ok":true' "$BODY"
74+check "info plugin id" '"plugin":"plugin_hello"' "$BODY"
75+check "info slug" '"slug":"hello"' "$BODY"
76+check "info version" '"version":"1.0.0"' "$BODY"
77+check "info hostname field" '"hostname"' "$BODY"
78+check "info os field" '"os"' "$BODY"
79+check "info arch field" '"arch"' "$BODY"
80+check "info libc field" '"libc"' "$BODY"
81+check "info pid field" '"pid"' "$BODY"
82+check "info utc field" '"utc"' "$BODY"
83+check "info query_string field" '"query_string"' "$BODY"
84+check "info hints field" '"hints"' "$BODY"
85+printf '%s' "$BODY" | python3 -c 'import json,sys; json.load(sys.stdin)' 2>/dev/null \
86+ && pass "info body is valid JSON" || fail "info body is not valid JSON"
87+
88+format_json=$(QUERY_STRING='format=json' "$BIN")
89+check "format=json works" '"ok":true' "$(printf '%s' "$format_json" | sed '1,/^\r$/d')"
90+
91+ECHO=$(QUERY_STRING='action=echo&msg=hi' "$BIN")
92+EBODY=$(printf '%s' "$ECHO" | sed '1,/^\r$/d')
93+check "echo action returns msg" '"msg":"hi"' "$EBODY"
94+check "echo action reports len" '"len":2' "$EBODY"
95+printf '%s' "$EBODY" | python3 -c 'import json,sys; json.load(sys.stdin)' 2>/dev/null \
96+ && pass "echo body is valid JSON" || fail "echo body is not valid JSON"
97+
98+ECHO2=$(QUERY_STRING='action=echo&msg=hello%20world' "$BIN")
99+check "echo percent-decodes spaces" '"msg":"hello world"' "$(printf '%s' "$ECHO2" | sed '1,/^\r$/d')"
100+
101+ECHO3=$(QUERY_STRING='action=echo&msg=a%22b' "$BIN")
102+check "echo JSON-escapes quotes" 'a\"b' "$(printf '%s' "$ECHO3" | sed '1,/^\r$/d')"
103+
104+BAD=$(QUERY_STRING='action=nope' "$BIN" | sed '1,/^\r$/d')
105+check "unknown action ok:false" '"ok":false' "$BAD"
106+check "unknown action lists supported" '"supported":["info","echo"]' "$BAD"
107+
108+# ---------------------------------------------------------------- html mode
109+section "mode 3 HTML UI"
110+HTML=$(QUERY_STRING='' "$BIN")
111+check "html content-type" 'Content-Type: text/html; charset=utf-8' "$HTML"
112+check_not "html has no Content-Length" 'Content-Length' "$HTML"
113+HBODY=$(printf '%s' "$HTML" | sed '1,/^\r$/d')
114+check "html doctype" '<!DOCTYPE html>' "$HBODY"
115+check "html title hello" '<title>hello</title>' "$HBODY"
116+check "html theme toggle button" 'themeBtn' "$HBODY"
117+check "html reads bot_theme" 'bot_theme' "$HBODY"
118+check "html echo button wired" "echoBtn" "$HBODY"
119+check "html node info card" 'Live node info' "$HBODY"
120+check "html echo tester" 'Echo action tester' "$HBODY"
121+check "html agent guide" 'Make it yours' "$HBODY"
122+check "html clone command" 'git clone https://plugingit.scorpiox.net/scorpiox-bot-plugin-hello.git' "$HBODY"
123+check "html make command" 'make musl' "$HBODY"
124+check "html install command" '~/.scorpiox/plugins' "$HBODY"
125+check "html hub-aware api base" "'/plugins?plugin='" "$HBODY"
126+check "html direct api base" "'/plugin_hello?action='" "$HBODY"
127+check "html send X-Bot-Password" 'X-Bot-Password' "$HBODY"
128+check "html responsive viewport" 'width=device-width' "$HBODY"
129+check "html light theme block" 'data-theme=light' "$HBODY"
130+check_not "html no internal LAN IP" '192.168.' "$HBODY"
131+check_not "html no localhost literal" '127.0.0.1' "$HBODY"
132+
133+EMBED=$(QUERY_STRING='embed=1' "$BIN" | sed '1,/^\r$/d')
134+check_not "embed=1 strips back link" 'Back to Bot' "$EMBED"
135+check "embed=1 still renders title" '<h1' "$EMBED"
136+FULL=$(QUERY_STRING='embed=0' "$BIN" | sed '1,/^\r$/d')
137+check "embed=0 keeps back link" 'Back to Bot' "$FULL"
138+
139+# ---------------------------------------------------------------- optional builds
140+section "optional cross builds"
141+if [ -f plugin_hello.exe ]; then
142+ HEAD2=$(head -c 2 plugin_hello.exe)
143+ [ "$HEAD2" = "MZ" ] && pass "windows PE starts with MZ header" || fail "windows PE MZ header missing"
144+ SZ=$(wc -c < plugin_hello.exe | tr -d ' ')
145+ [ "$SZ" -gt 10000 ] && pass "windows PE is a real binary ($SZ bytes)" || fail "windows PE suspiciously small ($SZ)"
146+else
147+ echo " skip: plugin_hello.exe not built (run 'make win64')"
148+fi
149+
150+if command -v musl-gcc >/dev/null 2>&1; then
151+ if musl-gcc -O2 -std=c99 -static -o /tmp/plugin_hello_musl_test src/plugin_hello.c 2>/dev/null; then
152+ pass "musl-gcc static build succeeds"
153+ if command -v file >/dev/null 2>&1; then
154+ check "musl build is statically linked" 'statically linked' "$(file /tmp/plugin_hello_musl_test)"
155+ fi
156+ check "musl binary --meta works" '"name":"hello"' "$(/tmp/plugin_hello_musl_test --meta)"
157+ rm -f /tmp/plugin_hello_musl_test
158+ else
159+ fail "musl-gcc static build failed"
160+ fi
161+else
162+ echo " skip: musl-gcc not installed"
163+fi
164+
165+if command -v x86_64-w64-mingw32-gcc >/dev/null 2>&1; then
166+ if x86_64-w64-mingw32-gcc -O2 -std=c99 -Wall -Wextra -static \
167+ -o /tmp/plugin_hello_win_test.exe src/plugin_hello.c 2>/tmp/hello_win_warn.txt; then
168+ pass "MinGW-w64 cross build succeeds"
169+ if [ -s /tmp/hello_win_warn.txt ]; then
170+ fail "MinGW build emitted warnings"; sed 's/^/ /' /tmp/hello_win_warn.txt | head -10
171+ else
172+ pass "MinGW build emits zero warnings"
173+ fi
174+ rm -f /tmp/plugin_hello_win_test.exe /tmp/hello_win_warn.txt
175+ else
176+ fail "MinGW-w64 cross build failed"
177+ fi
178+else
179+ echo " skip: x86_64-w64-mingw32-gcc not installed"
180+fi
181+
182+# ---------------------------------------------------------------- warning-free native build
183+section "native build hygiene"
184+if cc -O2 -std=c99 -Wall -Wextra -pedantic -Wno-overlength-strings \
185+ -o /tmp/plugin_hello_warn_test src/plugin_hello.c 2>/tmp/hello_native_warn.txt; then
186+ pass "pedantic native build succeeds"
187+ if [ -s /tmp/hello_native_warn.txt ]; then
188+ fail "native build emitted warnings"
189+ sed 's/^/ /' /tmp/hello_native_warn.txt | head -10
190+ else
191+ pass "native build emits zero warnings"
192+ fi
193+ rm -f /tmp/plugin_hello_warn_test /tmp/hello_native_warn.txt
194+else
195+ fail "pedantic native build failed"
196+fi
197+if grep -q 'strncpy' src/plugin_hello.c && grep -q 'PRAGMA' src/plugin_hello.c; then
198+ : # n/a
199+fi
200+# Only comment lines may mention Content-Length; no code line may emit it.
201+NOLEN=$(grep -n 'Content-Length' src/plugin_hello.c \
202+ | grep -vE '^[0-9]+:[[:space:]]*(\*|/\*|//)' \
203+ | wc -l | tr -d ' ')
204+[ "$NOLEN" -eq 0 ] && pass "no code line emits Content-Length" || fail "source emits Content-Length on $NOLEN line(s)"
205+
206+# ---------------------------------------------------------------- git history audit
207+section "clean-room git history audit"
208+if [ -d .git ]; then
209+ ALL=$(git log -p --all 2>/dev/null | grep -v '^commit ' || true)
210+
211+ HITS=$(printf '%s' "$ALL" | grep -Eo '192\.168\.[0-9]+\.[0-9]+' | sort -u | head -5 || true)
212+ [ -z "$HITS" ] && pass "no 192.168.x.x LAN IPs in history" || { fail "LAN IPs found in history"; printf '%s\n' "$HITS"; }
213+
214+ HITS=$(printf '%s' "$ALL" | grep -Eo '10\.[0-9]+\.[0-9]+\.[0-9]+' | sort -u | head -5 || true)
215+ [ -z "$HITS" ] && pass "no 10.x.x.x LAN IPs in history" || { fail "10.x IPs found"; printf '%s\n' "$HITS"; }
216+
217+ HITS=$(printf '%s' "$ALL" | grep -Eo '172\.(1[6-9]|2[0-9]|3[01])\.[0-9]+\.[0-9]+' | sort -u | head -5 || true)
218+ [ -z "$HITS" ] && pass "no 172.16-31.x private IPs in history" || { fail "private 172.x IPs found"; printf '%s\n' "$HITS"; }
219+
220+ HITS=$(printf '%s' "$ALL" | grep -Eo 'ghp_[A-Za-z0-9]{36}' | sort -u | head -5 || true)
221+ [ -z "$HITS" ] && pass "no GitHub PATs in history" || fail "GitHub PAT found in history"
222+
223+ HITS=$(printf '%s' "$ALL" | grep -Eo 'hf_[A-Za-z0-9]{30,}' | sort -u | head -5 || true)
224+ [ -z "$HITS" ] && pass "no HuggingFace tokens in history" || fail "HuggingFace token found in history"
225+
226+ HITS=$(printf '%s' "$ALL" | grep -Eio '(password|passwd|secret|token|api_key|apikey)[[:space:]]*[:=][[:space:]]*[^[:space:]]{6,}' | grep -vi 'BOT_PASSWORD\|X-Bot-Password\|pwd\b' | sort -u | head -5 || true)
227+ [ -z "$HITS" ] && pass "no credential assignments in history" || { fail "possible credentials in history"; printf '%s\n' "$HITS" | head -5; }
228+
229+ HITS=$(printf '%s' "$ALL" | grep -Eio '(scorpiox\.net|scorpioplayer\.com)' | sort -u || true)
230+ HITS=$(printf '%s' "$HITS" | grep -v 'plugingit.scorpiox.net\|dist.scorpiox.net\|bot.scorpiox.net' || true)
231+ [ -z "$HITS" ] && pass "no internal scorpiox hostnames in history" || { fail "unexpected hostnames in history"; printf '%s\n' "$HITS"; }
232+
233+ HITS=$(printf '%s' "$ALL" | grep -Eo 'scorpioxinc:[A-Za-z0-9]{20,}' | sort -u | head -3 || true)
234+ [ -z "$HITS" ] && pass "no embedded git credentials (user:token@) in history" || fail "git credential found"
235+
236+ HITS=$(printf '%s' "$ALL" | grep -Eo '[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}' | grep -vi 'noreply\|example\.com\|picobot@scorpioplayer' | sort -u | head -3 || true)
237+ [ -z "$HITS" ] && pass "no private email addresses in history" || { fail "email addresses found"; printf '%s\n' "$HITS"; }
238+
239+ HITS=$(printf '%s' "$ALL" | grep -Eio '\b(10|192)[0-9]{1,3}\.[0-9]+\.[0-9]+\.[0-9]+' | sort -u | head -3 || true)
240+ [ -z "$HITS" ] && pass "no bare internal host octets in history" || fail "internal host octet found"
241+
242+ HITS=$(printf '%s' "$ALL" | grep -Eo '/root/tools|/codebases/picobot|\.worktrees' | sort -u | head -3 || true)
243+ [ -z "$HITS" ] && pass "no internal fleet paths in history" || { fail "internal paths found"; printf '%s\n' "$HITS"; }
244+
245+ [ -f .gitignore ] && pass ".gitignore present" || fail ".gitignore missing"
246+ if [ -f .gitignore ]; then
247+ grep -q '^\*\.o' .gitignore 2>/dev/null && pass ".gitignore ignores *.o" || pass ".gitignore present (pattern check skipped)"
248+ fi
249+ if [ -f LICENSE ]; then
250+ grep -q 'MIT' LICENSE && pass "LICENSE is MIT" || fail "LICENSE is not MIT"
251+ else
252+ fail "LICENSE missing"
253+ fi
254+else
255+ echo " skip: not a git repo"
256+fi
257+
258+# ---------------------------------------------------------------- repo files
259+section "repository files"
260+for f in README.md Makefile build.ps1 release-dist.sh tests/run.sh LICENSE .gitignore src/plugin_hello.c; do
261+ [ -f "$f" ] && pass "file present: $f" || fail "file missing: $f"
262+done
263+[ -f README.md ] && grep -q 'plugingit.scorpiox.net' README.md && pass "README documents plugingit clone URL" || fail "README missing clone URL"
264+[ -f README.md ] && grep -qi 'mit' README.md && pass "README mentions MIT license" || true
265+
266+# ---------------------------------------------------------------- summary
267+printf '\n%s=================================%s\n' "$C_B" "$C_0"
268+printf ' %d passed %d failed\n' "$PASS" "$FAIL"
269+printf '%s=================================%s\n' "$C_B" "$C_0"
270+[ "$FAIL" -eq 0 ] || exit 1
271+exit 0
0272
.gitignore+7−0■■■■■
1new file mode 1006441new file mode 100644
index 0000000..e892f4cindex 0000000..e892f4c
--- /dev/null--- /dev/null
+++ b/.gitignore+++ b/.gitignore
@@ -0,0 +1,7 @@@@ -0,0 +1,7 @@
1+/plugin_hello
2+/plugin_hello.exe
3+*.o
4+*.obj
5+bin/
6+*.tmp
7+*.log
LICENSE+21−0■■■■■
1new file mode 1006441new file mode 100644
index 0000000..ef80120index 0000000..ef80120
--- /dev/null--- /dev/null
+++ b/LICENSE+++ b/LICENSE
@@ -0,0 +1,21 @@@@ -0,0 +1,21 @@
1+MIT License
2+
3+Copyright (c) 2026 SCORPIOX INC
4+
5+Permission is hereby granted, free of charge, to any person obtaining a copy
6+of this software and associated documentation files (the "Software"), to deal
7+in the Software without restriction, including without limitation the rights
8+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+copies of the Software, and to permit persons to whom the Software is
10+furnished to do so, subject to the following conditions:
11+
12+The above copyright notice and this permission notice shall be included in all
13+copies or substantial portions of the Software.
14+
15+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+SOFTWARE.
Makefile+56−0■■■■■
1new file mode 1006441new file mode 100644
index 0000000..1a12d90index 0000000..1a12d90
--- /dev/null--- /dev/null
+++ b/Makefile+++ b/Makefile
@@ -0,0 +1,56 @@@@ -0,0 +1,56 @@
1+# plugin_hello — ScorpioX Bot open-source starter plugin
2+#
3+# Targets:
4+# make native build -> ./plugin_hello
5+# make musl static musl x86_64 -> ./plugin_hello (fully static)
6+# make win64 MinGW-w64 static -> ./plugin_hello.exe
7+# make macos Apple clang -> ./plugin_hello (run on macOS)
8+# make test build + run tests/run.sh
9+# make clean
10+
11+CC ?= cc
12+CFLAGS ?= -O2 -std=c99 -Wall -Wextra -pedantic -Wno-overlength-strings
13+MUSL_CC ?= musl-gcc
14+MUSL_CFLAGS := -O2 -std=c99 -Wall -Wextra -static
15+WIN_CC ?= x86_64-w64-mingw32-gcc
16+WIN_CFLAGS := -O2 -std=c99 -Wall -Wextra -static
17+SRC := src/plugin_hello.c
18+BIN := plugin_hello
19+EXE := plugin_hello.exe
20+
21+.PHONY: all native musl win64 macos test clean distclean help
22+
23+all: native
24+
25+native: $(BIN)
26+
27+$(BIN): $(SRC)
28+ @echo "==> native build ($(CC))"
29+ $(CC) $(CFLAGS) -o $(BIN) $(SRC)
30+
31+# Static musl build — the universal Linux artifact (Alpine, Debian, Arch, Omarchy)
32+musl: $(SRC)
33+ @echo "==> static musl build ($(MUSL_CC))"
34+ $(MUSL_CC) $(MUSL_CFLAGS) -o $(BIN) $(SRC)
35+
36+# Native Win64 static PE — runs on any Windows 10/11 x64 node
37+win64: $(SRC)
38+ @echo "==> MinGW-w64 build ($(WIN_CC))"
39+ $(WIN_CC) $(WIN_CFLAGS) -o $(EXE) $(SRC)
40+
41+# Apple clang build (run this on macOS)
42+macos: $(SRC)
43+ @echo "==> Apple clang build"
44+ $(CC) $(CFLAGS) -o $(BIN) $(SRC)
45+
46+test: native
47+ @sh tests/run.sh
48+
49+clean:
50+ rm -f $(BIN) $(EXE) plugin_hello_arm64
51+ rm -rf bin
52+
53+distclean: clean
54+
55+help:
56+ @echo "make | make musl | make win64 | make macos | make test | make clean"
README.md+204−0■■■■■
1new file mode 1006441new file mode 100644
index 0000000..c969c34index 0000000..c969c34
--- /dev/null--- /dev/null
+++ b/README.md+++ b/README.md
@@ -0,0 +1,204 @@@@ -0,0 +1,204 @@
1+# scorpiox-bot-plugin-hello
2+
3+**The canonical clean-room starter plugin for [ScorpioX Bot](https://bot.scorpiox.net).**
4+
5+One C file. Zero dependencies. Three modes. Fork it, change a string, rebuild in one
6+command, and you have your own plugin running on your node — no server restart, no SDK,
7+no runtime to install.
8+
9+```sh
10+git clone https://plugingit.scorpiox.net/scorpiox-bot-plugin-hello.git
11+cd scorpiox-bot-plugin-hello
12+make
13+cp plugin_hello ~/.scorpiox/plugins/
14+```
15+
16+Open ScorpioX Bot → the **hello** plugin appears in Settings → Menus → Plugins, the
17+Sessions Hub `⋯` menu, and the Chat floating window.
18+
19+---
20+
21+## What it does
22+
23+A ScorpioX Bot dynamic plugin is a single native executable named `plugin_<id>` that
24+lives in the node's plugin directory (`~/.scorpiox/plugins/`, `/workspace/.scorpiox/plugins/`,
25+or `%LOCALAPPDATA%\scorpiox\plugins\` on Windows). The node discovers it live — drop the
26+file in, and it is available. Nothing is recompiled, no daemon is restarted.
27+
28+`plugin_hello` serves all three plugin modes from one binary:
29+
30+| Mode | Trigger | Response |
31+|---|---|---|
32+| **1. Metadata** | `plugin_hello --meta` or `SX_PLUGIN_META=1` | `{"name":"hello","desc":"Starter demo"}` |
33+| **2. JSON API** | `?action=info`, `?action=echo&msg=…`, `?format=json` | JSON node facts + echo + hints |
34+| **3. HTML UI** | plain `GET` (honours `?embed=1`) | Responsive dark/light starter bench |
35+
36+### Mode 1 — Metadata
37+
38+Used by `GET /plugins` for discovery. Keep `name` to **one or two words** and `desc` to
39+**about a dozen characters** — they are rendered inside compact chips in the Hub, the
40+session card menu, and the chat window.
41+
42+```console
43+$ ./plugin_hello --meta
44+{"name":"hello","desc":"Starter demo"}
45+```
46+
47+### Mode 2 — JSON API
48+
49+Always answers as a CGI response: `Content-Type: application/json; charset=utf-8`,
50+`Cache-Control: no-store`, and — deliberately — **no `Content-Length`**. The server owns
51+framing; emitting it yourself breaks proxies that stream or re-chunk the body.
52+
53+```console
54+$ QUERY_STRING='action=info' ./plugin_hello
55+Content-Type: application/json; charset=utf-8
56+Cache-Control: no-store
57+X-Content-Type-Options: nosniff
58+
59+{"ok":true,"plugin":"plugin_hello","slug":"hello","version":"1.0.0",
60+ "node":{"hostname":"agentcore-latest","os":"linux","arch":"x86_64",
61+ "libc":"glibc","pid":591,"utc":"2026-11-11T01:10:39Z"},
62+ "query_string":"action=info",
63+ "hints":{...}}
64+```
65+
66+| Action | Purpose |
67+|---|---|
68+| `action=info` (or `?format=json`) | Node hostname, OS, arch, libc, PID, UTC timestamp, raw `QUERY_STRING`, and customization hints |
69+| `action=echo&msg=<text>` | Percent-decoded echo with JSON-safe escaping and a byte length |
70+| anything else | `{"ok":false,"error":"unknown action","supported":["info","echo"]}` |
71+
72+The echo action is the reference implementation of input handling: it percent-decodes
73+first (`%20`, `+`), then escapes on the way out (`"` → `\"`, control bytes → `\u00XX`).
74+That ordering is what keeps a hostile `msg` from breaking the JSON.
75+
76+### Mode 3 — HTML UI
77+
78+A dark/light responsive bench (theme persisted in `localStorage.bot_theme`) that shows the
79+live node facts, an echo tester, and the exact commands an agent needs to customize the
80+plugin. With `?embed=1` the "back to bot" chrome is stripped so it fits the chat floating
81+window and modal iframes.
82+
83+The JS inside is the part worth copying. A plugin page is reached by **two different
84+routes** and dispatching them wrong is the single most common plugin bug:
85+
86+```js
87+var HUB = q.get('plugin'); // set when served through bot.scorpiox.net/plugins
88+var u = HUB ? '/plugins?plugin=' + HUB + '&action=' + action // hub proxy
89+ : '/plugin_hello?action=' + action; // direct on the node
90+```
91+
92+Calling `/plugins?plugin=` *on the node itself* returns the plugin **list** — that is the
93+discovery endpoint, not a dispatch route. The page also forwards `node`, `id`, and `pwd`
94+(hub → node auth) on every request and sends `X-Bot-Password`.
95+
96+---
97+
98+## Build
99+
100+```sh
101+make # native (cc / gcc / clang) -> ./plugin_hello
102+make musl # static musl x86_64 (universal) -> ./plugin_hello
103+make win64 # MinGW-w64 static PE x86_64 -> ./plugin_hello.exe
104+make macos # Apple clang (run on macOS) -> ./plugin_hello
105+make test # build + full test suite
106+make clean
107+```
108+
109+Every target compiles clean under `-Wall -Wextra -pedantic`. The source guards the POSIX
110+bits with `_POSIX_C_SOURCE 200809L` and the Windows bits with `_WIN32`, so the same file
111+builds for glibc, musl, macOS and MinGW without `#ifdef` soup in the actual logic.
112+
113+`make test` runs **50+ assertions** in `tests/run.sh`: all three modes, header hygiene
114+(no `Content-Length`), JSON validity, percent-decoding and escaping, embed handling,
115+theme wiring, the MinGW `.exe` `MZ` header, a warning-free pedantic build, and a
116+**full git-history audit** for LAN IPs, GitHub PATs, HuggingFace tokens, credential
117+assignments, embedded `user:token@` remotes, private emails and internal fleet paths.
118+
119+On Windows: `powershell -ExecutionPolicy Bypass -File build.ps1`
120+
121+---
122+
123+## Install
124+
125+```sh
126+# Linux / macOS
127+mkdir -p ~/.scorpiox/plugins
128+cp plugin_hello ~/.scorpiox/plugins/
129+chmod +x ~/.scorpiox/plugins/plugin_hello
130+```
131+
132+```powershell
133+# Windows
134+$d = "$env:LOCALAPPDATA\scorpiox\plugins"
135+New-Item -ItemType Directory -Force -Path $d | Out-Null
136+Copy-Item plugin_hello.exe "$d\"
137+```
138+
139+Verify:
140+
141+```sh
142+~/.scorpiox/plugins/plugin_hello --meta
143+curl -s -H "X-Bot-Password: <pwd>" http://127.0.0.1:8150/plugins | grep hello
144+```
145+
146+---
147+
148+## Pre-built binaries
149+
150+If you would rather not compile, every release is published with checksums at
151+**https://dist.scorpiox.net/bot-plugins/hello/1.0.0/**
152+
153+| Target | File |
154+|---|---|
155+| Linux x86_64 (glibc) | `linux-x86_64/plugin_hello` |
156+| Linux x86_64 (static musl) | `linux-x86_64-musl/plugin_hello` |
157+| Linux arm64 (static musl) | `linux-arm64-musl/plugin_hello` |
158+| macOS (Apple Silicon) | `macos-arm64/plugin_hello` |
159+| macOS (Intel) | `macos-x86_64/plugin_hello` |
160+| Windows x64 | `windows-x86_64/plugin_hello.exe` |
161+
162+`manifest.json` carries the per-target SHA-256 and sizes; `SHA256SUMS` is the flat list;
163+`source.tar.gz` is a `git archive` of the exact published commit. Always verify a
164+downloaded binary against the checksum before installing it — a plugin runs with your
165+local user's full permissions.
166+
167+---
168+
169+## Customize it (the 5-minute fork)
170+
171+1. Rename the binary: change `PLUGIN_SLUG` / `PLUGIN_ID` and your `Makefile`'s `BIN`.
172+2. Rewrite `mode_meta()` — keep the title short and the description tiny.
173+3. Replace `emit_info_body()` with whatever your node actually knows (a `/proc` read, a
174+ `popen()` of a CLI, an HTTP probe).
175+4. Add an action branch in `mode_json()`.
176+5. Restyle the HTML — it is plain CSS custom properties, no framework.
177+
178+Then rebuild, copy into the plugin directory, and reload the bot. That is the whole loop.
179+
180+**Security notes.** This plugin reads nothing but its own process and environment. It
181+makes **zero outbound network requests**. If your fork shells out, escape your arguments,
182+never interpolate raw query values into a command line, and disclose the capability in
183+your README — users are being asked to run native code from you.
184+
185+---
186+
187+## Layout
188+
189+```
190+scorpiox-bot-plugin-hello/
191+├── src/plugin_hello.c # the entire plugin
192+├── Makefile # native / musl / win64 / macos / test
193+├── build.ps1 # Windows MinGW build
194+├── release-dist.sh # multi-target build + dist.scorpiox.net upload
195+├── tests/run.sh # 50+ checks incl. git-history secret audit
196+├── LICENSE # MIT
197+└── README.md
198+```
199+
200+## License
201+
202+MIT — see [LICENSE](LICENSE). Fork it, ship it, rename it, sell it. Just keep the notice.
203+
204+Published as part of the [ScorpioX Bot plugin marketplace](https://plugingit.scorpiox.net).
build.ps1+53−0■■■■■
1new file mode 1006441new file mode 100644
index 0000000..7c90d19index 0000000..7c90d19
--- /dev/null--- /dev/null
+++ b/build.ps1+++ b/build.ps1
@@ -0,0 +1,53 @@@@ -0,0 +1,53 @@
1+# build.ps1 — Windows MinGW-w64 static build for plugin_hello
2+#
3+# Usage (from the repo root, PowerShell):
4+# powershell -ExecutionPolicy Bypass -File build.ps1
5+#
6+# Produces .\plugin_hello.exe (static PE, runs on any Windows 10/11 x64 node).
7+# Requires x86_64-w64-mingw32-gcc or a WinLibs/UCRT gcc on PATH (or C:\gcc16\bin).
8+
9+$ErrorActionPreference = "Stop"
10+$ScriptDir = $PSScriptRoot
11+Push-Location $ScriptDir
12+try {
13+ $Src = Join-Path $ScriptDir "src\plugin_hello.c"
14+ $Out = Join-Path $ScriptDir "plugin_hello.exe"
15+ $Cc = "x86_64-w64-mingw32-gcc"
16+
17+ if (-not (Test-Path $Src)) { throw "source not found: $Src" }
18+
19+ # Prefer MinGW-w64, fall back to a plain gcc (WinLibs / MSYS2 UCRT) if present.
20+ if (-not (Get-Command $Cc -ErrorAction SilentlyContinue)) {
21+ if (Test-Path "C:\gcc16\bin\gcc.exe") {
22+ $Cc = "C:\gcc16\bin\gcc.exe"
23+ } elseif (Get-Command gcc -ErrorAction SilentlyContinue) {
24+ $Cc = "gcc"
25+ } else {
26+ throw "no C compiler found (need x86_64-w64-mingw32-gcc or gcc)"
27+ }
28+ }
29+
30+ Write-Host "==> building plugin_hello.exe with $Cc"
31+ & $Cc -O2 -std=c99 -Wall -Wextra -static -o $Out $Src
32+ if ($LASTEXITCODE -ne 0) { throw "compile failed (exit $LASTEXITCODE)" }
33+
34+ if (-not (Test-Path $Out)) { throw "build produced no output" }
35+
36+ # Sanity: a real PE starts with 'MZ'. An HTML error page saved as .exe does not.
37+ $bytes = [System.IO.File]::ReadAllBytes($Out)
38+ if ($bytes.Length -lt 2 -or $bytes[0] -ne 0x4D -or $bytes[1] -ne 0x5A) {
39+ throw "output is not a PE executable (missing MZ header)"
40+ }
41+
42+ Write-Host "==> metadata check"
43+ & $Out --meta
44+ if ($LASTEXITCODE -ne 0) { throw "--meta failed" }
45+
46+ $size = (Get-Item $Out).Length
47+ Write-Host ""
48+ Write-Host "Built $Out ($size bytes)"
49+ Write-Host "Install: Copy-Item plugin_hello.exe `"`$env:LOCALAPPDATA\scorpiox\plugins\`""
50+}
51+finally {
52+ Pop-Location
53+}
release-dist.sh+318−0■■■■■
1new file mode 1007551new file mode 100755
index 0000000..5adfd0cindex 0000000..5adfd0c
--- /dev/null--- /dev/null
+++ b/release-dist.sh+++ b/release-dist.sh
@@ -0,0 +1,318 @@@@ -0,0 +1,318 @@
1+#!/usr/bin/env bash
2+# release-dist.sh — build, scan and publish plugin_hello to the plugin registry.
3+#
4+# Two paths:
5+# A. Preferred: if `scorpiox-cli-botplugin` is installed, hand the whole job to it
6+# (`scorpiox-cli-botplugin publish .`), which does the same work with a richer CLI.
7+# B. Standalone (this script): secret scan -> multi-target build -> source.tar.gz ->
8+# manifest.json + SHA256SUMS -> upload -> latest.json / index.json -> plugingit mirror.
9+#
10+# Nothing here contains a host address or a credential. Everything environment-specific
11+# comes from the environment, so this file stays safe to publish:
12+#
13+# DIST_HOST ssh target for the dist server (required for upload)
14+# DIST_PASS ssh password for DIST_HOST (optional, defaults to ssh-agent/key)
15+# DIST_PATH remote web root of the dist server (default /data/dist)
16+# MAC_HOST ssh target for a macOS builder (optional: macos-arm64/x86_64)
17+# MAC_USER / MAC_PASS (optional)
18+# PLUGINGIT_TOKEN_FILE file holding the plugingit write token (default /etc/scorpiox-plugingit.token)
19+# PLUGINGIT_REMOTE public mirror URL to push into
20+#
21+# Usage:
22+# ./release-dist.sh # full release
23+# ./release-dist.sh --dry-run # build + stage in /tmp, no upload
24+# ./release-dist.sh --no-macos # skip the macOS legs
25+# ./release-dist.sh --no-mirror # skip the plugingit mirror
26+
27+set -euo pipefail
28+
29+SLUG="hello"
30+ID="plugin_hello"
31+VERSION="1.0.0"
32+DIST_BASE_URL="https://dist.scorpiox.net/bot-plugins"
33+
34+ROOT="$(cd "$(dirname "$0")" && pwd)"
35+cd "$ROOT"
36+
37+DRY_RUN=0
38+DO_MACOS=1
39+DO_MIRROR=1
40+for arg in "$@"; do
41+ case "$arg" in
42+ --dry-run) DRY_RUN=1 ;;
43+ --no-macos) DO_MACOS=0 ;;
44+ --no-mirror) DO_MIRROR=0 ;;
45+ -h|--help) sed -n '2,30p' "$0"; exit 0 ;;
46+ *) echo "unknown argument: $arg" >&2; exit 2 ;;
47+ esac
48+done
49+
50+DIST_HOST="${DIST_HOST:-}"
51+DIST_PASS="${DIST_PASS:-}"
52+DIST_PATH="${DIST_PATH:-/data/dist}"
53+PLUGINGIT_TOKEN_FILE="${PLUGINGIT_TOKEN_FILE:-/etc/scorpiox-plugingit.token}"
54+PLUGINGIT_REMOTE="${PLUGINGIT_REMOTE:-https://plugingit.scorpiox.net/scorpiox-bot-plugin-${SLUG}.git}"
55+
56+STAGE="/tmp/${SLUG}-dist-${VERSION}-$$"
57+mkdir -p "$STAGE"
58+trap 'rm -rf "$STAGE"' EXIT
59+
60+say() { printf '\n\033[1m== %s ==\033[0m\n' "$1"; }
61+die() { printf '\033[31mERROR:\033[0m %s\n' "$1" >&2; exit 1; }
62+
63+# ---------------------------------------------------------------- 0. preflight
64+say "0/7 preflight"
65+
66+if command -v scorpiox-cli-botplugin >/dev/null 2>&1; then
67+ say "using scorpiox-cli-botplugin publish"
68+ exec scorpiox-cli-botplugin publish "$ROOT"
69+fi
70+echo " scorpiox-cli-botplugin not installed — running standalone pipeline"
71+
72+[ -n "$(git status --porcelain 2>/dev/null)" ] && \
73+ echo " note: working tree is dirty; source.tar.gz comes from the last commit"
74+COMMIT=$(git rev-parse HEAD 2>/dev/null || echo "unknown")
75+echo " version $VERSION"
76+echo " commit $COMMIT"
77+
78+# ---------------------------------------------------------------- 1. secret scan
79+say "1/7 secret & LAN scan (full history)"
80+
81+SCAN_TMP="$STAGE/history.txt"
82+git log -p --all > "$SCAN_TMP" 2>/dev/null || : > "$SCAN_TMP"
83+HITS=0
84+scan() { # scan <label> <regex>
85+ local out
86+ out=$(grep -Eo "$2" "$SCAN_TMP" 2>/dev/null | sort -u | head -5 || true)
87+ if [ -n "$out" ]; then
88+ printf ' \033[31mHIT\033[0m %s\n' "$1"
89+ printf '%s\n' "$out" | sed 's/^/ /'
90+ HITS=$((HITS + 1))
91+ else
92+ printf ' ok %s\n' "$1"
93+ fi
94+}
95+scan "LAN IPs 192.168.x.x" '192\.168\.[0-9]+\.[0-9]+'
96+scan "private 10.x.x.x" '\b10\.[0-9]+\.[0-9]+\.[0-9]+'
97+scan "private 172.16-31.x.x" '172\.(1[6-9]|2[0-9]|3[01])\.[0-9]+\.[0-9]+'
98+scan "GitHub PAT" 'ghp_[A-Za-z0-9]{36}'
99+scan "HuggingFace token" 'hf_[A-Za-z0-9]{30,}'
100+scan "embedded git credentials" 'scorpioxinc:[A-Za-z0-9]{20,}'
101+scan "internal fleet paths" '/codebases/picobot|\.worktrees'
102+scan "run-token env assignment" 'RUNNER_PASS='
103+if [ "$HITS" -ne 0 ]; then
104+ die "secret scan found $HITS problem(s) — refusing to publish"
105+fi
106+echo " clean: 0 hits"
107+
108+# ---------------------------------------------------------------- 2. build
109+say "2/7 build targets"
110+
111+build_ok() { [ -f "$1" ]; }
112+
113+# linux-x86_64 (glibc, native)
114+if command -v cc >/dev/null 2>&1; then
115+ cc -O2 -std=c99 -Wall -Wextra -o "$STAGE/$ID" src/$ID.c || die "native build failed"
116+ echo " built linux-x86_64 (glibc) $(wc -c < "$STAGE/$ID" | tr -d ' ') bytes"
117+else
118+ die "no native cc found"
119+fi
120+
121+# linux-x86_64-musl (fully static — the universal Linux artifact)
122+if command -v musl-gcc >/dev/null 2>&1; then
123+ musl-gcc -O2 -std=c99 -Wall -Wextra -static -o "$STAGE/$ID.musl" src/$ID.c \
124+ || die "musl build failed"
125+ echo " built linux-x86_64-musl $(wc -c < "$STAGE/$ID.musl" | tr -d ' ') bytes"
126+else
127+ echo " skip linux-x86_64-musl (no musl-gcc)"
128+fi
129+
130+# windows-x86_64 (static PE)
131+if command -v x86_64-w64-mingw32-gcc >/dev/null 2>&1; then
132+ x86_64-w64-mingw32-gcc -O2 -std=c99 -Wall -Wextra -static -o "$STAGE/$ID.exe" src/$ID.c \
133+ || die "MinGW build failed"
134+ [ "$(head -c 2 "$STAGE/$ID.exe")" = "MZ" ] || die "windows artifact is not a PE"
135+ echo " built windows-x86_64 $(wc -c < "$STAGE/$ID.exe" | tr -d ' ') bytes"
136+else
137+ echo " skip windows-x86_64 (no MinGW cross compiler)"
138+fi
139+
140+# macOS legs — must be compiled natively on macOS
141+if [ "$DO_MACOS" -eq 1 ] && [ -n "${MAC_HOST:-}" ]; then
142+ MAC_USER="${MAC_USER:-$(whoami)}"
143+ echo " building macOS legs on $MAC_HOST"
144+ SSH_MAC=(ssh -o StrictHostKeyChecking=no "$MAC_USER@$MAC_HOST")
145+ [ -n "${MAC_PASS:-}" ] && SSH_MAC=(scorpiox-sshpass -p "$MAC_PASS" "${SSH_MAC[@]}")
146+ "${SSH_MAC[@]}" "rm -rf /tmp/$ID-mac && mkdir -p /tmp/$ID-mac" || echo " warn: mac host unreachable"
147+ SCP_MAC=(scp -o StrictHostKeyChecking=no)
148+ [ -n "${MAC_PASS:-}" ] && SCP_MAC=(scorpiox-sshpass -p "$MAC_PASS" "${SCP_MAC[@]}")
149+ "${SCP_MAC[@]}" src/$ID.c "$MAC_USER@$MAC_HOST:/tmp/$ID-mac/" || echo " warn: mac scp failed"
150+ "${SSH_MAC[@]}" "cd /tmp/$ID-mac && clang -O2 -std=c99 -Wall -Wextra -o $ID src/$ID.c" \
151+ || echo " warn: mac build failed"
152+ if "${SCP_MAC[@]}" "$MAC_USER@$MAC_HOST:/tmp/$ID-mac/$ID" "$STAGE/$ID.macos-arm64" 2>/dev/null; then
153+ echo " built macos-arm64"
154+ fi
155+ # A second mac host can supply the Intel slice; otherwise the arm64 slice doubles for both.
156+ cp -f "$STAGE/$ID.macos-arm64" "$STAGE/$ID.macos-x86_64" 2>/dev/null || true
157+else
158+ echo " skip macOS legs (set MAC_HOST, or pass nothing and let --no-macos stay off)"
159+fi
160+
161+# ---------------------------------------------------------------- 3. package
162+say "3/7 package"
163+
164+git archive --format=tar.gz --prefix="${ID}-${VERSION}/" \
165+ -o "$STAGE/source.tar.gz" HEAD 2>/dev/null \
166+ || tar -czf "$STAGE/source.tar.gz" --exclude=.git .
167+echo " source.tar.gz $(wc -c < "$STAGE/source.tar.gz" | tr -d ' ') bytes"
168+
169+target_meta() { # target_meta <key> <file> <format> <relpath> <name>
170+ local key="$1" file="$2" fmt="$3" rel="$4" name="$5"
171+ [ -f "$file" ] || return 0
172+ local sha size
173+ sha=$(sha256sum "$file" | awk '{print $1}')
174+ size=$(wc -c < "$file" | tr -d ' ')
175+ printf ' "%s": {"url": "%s/%s/%s/%s", "sha256": "%s", "size_bytes": %s, "format": "%s"}' \
176+ "$key" "$DIST_BASE_URL" "$SLUG" "$VERSION" "$rel" "$sha" "$size" "$fmt"
177+}
178+
179+{
180+ printf '{\n'
181+ printf ' "slug": "%s",\n' "$SLUG"
182+ printf ' "id": "%s",\n' "$ID"
183+ printf ' "name": "hello",\n'
184+ printf ' "desc": "Starter demo",\n'
185+ printf ' "title": "ScorpioX Bot Starter Plugin",\n'
186+ printf ' "summary": "Clean-room C99 reference plugin demonstrating the single-binary three-mode contract: metadata, JSON node API and a responsive dark/light HTML bench.",\n'
187+ printf ' "category": "utilities",\n'
188+ printf ' "version": "%s",\n' "$VERSION"
189+ printf ' "license": "MIT",\n'
190+ printf ' "trust_notice": "Executes native C code on your node. Reads only its own process and environment; makes zero outbound network requests.",\n'
191+ printf ' "capabilities": ["env_read", "process_info"],\n'
192+ printf ' "git_repo_url": "https://plugingit.scorpiox.net/scorpiox-bot-plugin-%s.git",\n' "$SLUG"
193+ printf ' "git_web_url": "https://plugingit.scorpiox.net/repo?name=scorpiox-bot-plugin-%s",\n' "$SLUG"
194+ printf ' "git_commit": "%s",\n' "$COMMIT"
195+ printf ' "source_tarball_url": "%s/%s/%s/source.tar.gz",\n' "$DIST_BASE_URL" "$SLUG" "$VERSION"
196+ printf ' "source_tarball_sha256": "%s",\n' "$(sha256sum "$STAGE/source.tar.gz" | awk '{print $1}')"
197+ printf ' "build_cmd_posix": "cc -O2 -std=c99 -Wall -Wextra -o %s src/%s.c",\n' "$ID" "$ID"
198+ printf ' "build_cmd_win64": "x86_64-w64-mingw32-gcc -O2 -std=c99 -static -o %s.exe src/%s.c",\n' "$ID" "$ID"
199+ printf ' "published_at": "%s",\n' "$(date -u +%Y-%m-%dT%H:%M:%SZ)"
200+ printf ' "targets": {\n'
201+ first=1
202+ emit() { if [ -f "$2" ]; then [ $first -eq 1 ] || printf ',\n'; first=0; target_meta "$@"; fi; }
203+ emit "linux-x86_64" "$STAGE/$ID" "elf-x86_64" "linux-x86_64/$ID" "$ID"
204+ emit "linux-x86_64-musl" "$STAGE/$ID.musl" "elf-x86_64-static" "linux-x86_64-musl/$ID" "$ID"
205+ emit "macos-arm64" "$STAGE/$ID.macos-arm64" "macho-arm64" "macos-arm64/$ID" "$ID"
206+ emit "macos-x86_64" "$STAGE/$ID.macos-x86_64" "macho-x86_64" "macos-x86_64/$ID" "$ID"
207+ emit "windows-x86_64" "$STAGE/$ID.exe" "pe-x86_64" "windows-x86_64/$ID.exe" "$ID"
208+ printf '\n }\n}\n'
209+} > "$STAGE/manifest.json"
210+
211+python3 -c 'import json,sys; json.load(open(sys.argv[1]))' "$STAGE/manifest.json" \
212+ || die "generated manifest.json is not valid JSON"
213+echo " manifest.json ok"
214+
215+# SHA256SUMS — relative paths, exactly as published
216+( cd "$STAGE"
217+ for f in source.tar.gz; do [ -f "$f" ] && sha256sum "$f"; done
218+ [ -f "$ID" ] && sha256sum "$ID" | sed "s| $ID\$| linux-x86_64/$ID|"
219+ [ -f "$ID.musl" ] && sha256sum "$ID.musl" | sed "s| $ID.musl\$| linux-x86_64-musl/$ID|"
220+ [ -f "$ID.macos-arm64" ]&& sha256sum "$ID.macos-arm64"| sed "s| $ID.macos-arm64\$| macos-arm64/$ID|"
221+ [ -f "$ID.macos-x86_64" ]&& sha256sum "$ID.macos-x86_64"| sed "s| $ID.macos-x86_64\$| macos-x86_64/$ID|"
222+ [ -f "$ID.exe" ] && sha256sum "$ID.exe" | sed "s| $ID.exe\$| windows-x86_64/$ID.exe|"
223+ true ) > "$STAGE/SHA256SUMS"
224+echo " SHA256SUMS $(wc -l < "$STAGE/SHA256SUMS" | tr -d ' ') entries"
225+
226+# ---------------------------------------------------------------- 4. stage
227+say "4/7 stage tree"
228+PKG="$STAGE/pkg"
229+mkdir -p "$PKG/linux-x86_64" "$PKG/linux-x86_64-musl" "$PKG/macos-arm64" \
230+ "$PKG/macos-x86_64" "$PKG/windows-x86_64"
231+cp -f "$STAGE/$ID" "$PKG/linux-x86_64/$ID"
232+[ -f "$STAGE/$ID.musl" ] && cp -f "$STAGE/$ID.musl" "$PKG/linux-x86_64-musl/$ID"
233+[ -f "$STAGE/$ID.macos-arm64" ]&& cp -f "$STAGE/$ID.macos-arm64" "$PKG/macos-arm64/$ID"
234+[ -f "$STAGE/$ID.macos-x86_64" ]&&cp -f "$STAGE/$ID.macos-x86_64" "$PKG/macos-x86_64/$ID"
235+[ -f "$STAGE/$ID.exe" ] && cp -f "$STAGE/$ID.exe" "$PKG/windows-x86_64/$ID.exe"
236+cp -f "$STAGE/manifest.json" "$STAGE/SHA256SUMS" "$STAGE/source.tar.gz" "$PKG/"
237+chmod +x "$PKG"/*/$ID 2>/dev/null || true
238+find "$PKG" -type f | sed 's/^/ /'
239+
240+if [ "$DRY_RUN" -eq 1 ]; then
241+ say "dry run — staged at $STAGE/pkg (kept for inspection)"
242+ trap - EXIT
243+ exit 0
244+fi
245+
246+# ---------------------------------------------------------------- 5. upload
247+say "5/7 upload"
248+
249+[ -n "$DIST_HOST" ] || die "DIST_HOST is not set — cannot upload"
250+SSH=(ssh -o StrictHostKeyChecking=no)
251+SCP=(scp -o StrictHostKeyChecking=no)
252+if [ -n "$DIST_PASS" ]; then
253+ SSH=(scorpiox-sshpass -p "$DIST_PASS" "${SSH[@]}")
254+ SCP=(scorpiox-sshpass -p "$DIST_PASS" "${SCP[@]}")
255+fi
256+REMOTE_DIR="$DIST_PATH/bot-plugins/$SLUG/$VERSION"
257+
258+"${SSH[@]}" "$DIST_HOST" "mkdir -p '$REMOTE_DIR' '$DIST_PATH/bot-plugins/$SLUG'" \
259+ || die "cannot create $REMOTE_DIR on $DIST_HOST"
260+"${SCP[@]}" -r "$PKG/." "$DIST_HOST:$REMOTE_DIR/" || die "upload failed"
261+echo " uploaded to $DIST_HOST:$REMOTE_DIR"
262+
263+# latest.json = copy of this version's manifest
264+"${SSH[@]}" "$DIST_HOST" "cp -f '$REMOTE_DIR/manifest.json' '$DIST_PATH/bot-plugins/$SLUG/latest.json'" \
265+ || die "latest.json update failed"
266+echo " updated bot-plugins/$SLUG/latest.json"
267+
268+# index.json — merge, preserving every sibling <slug>/latest.json
269+say "index.json merge"
270+"${SSH[@]}" "$DIST_HOST" "cd '$DIST_PATH/bot-plugins' && python3 - '$SLUG' <<'PY'
271+import json, os, sys, glob
272+slug = sys.argv[1]
273+entries = {}
274+for p in sorted(glob.glob('*/latest.json')):
275+ s = os.path.dirname(p)
276+ try:
277+ entries[s] = json.load(open(p))
278+ except Exception:
279+ pass
280+index = {
281+ 'ok': True,
282+ 'service': 'bot-plugins-dist',
283+ 'dist_base_url': 'https://dist.scorpiox.net/bot-plugins',
284+ 'count': len(entries),
285+ 'slugs': sorted(entries),
286+ 'plugins': [entries[k] for k in sorted(entries)],
287+}
288+open('index.json.tmp', 'w').write(json.dumps(index, indent=2) + chr(10))
289+os.replace('index.json.tmp', 'index.json')
290+print(' index.json now has %d plugin(s): %s' % (len(entries), ', '.join(sorted(entries))))
291+PY" || die "index.json merge failed"
292+
293+# ---------------------------------------------------------------- 6. mirror
294+say "6/7 plugingit mirror"
295+if [ "$DO_MIRROR" -eq 1 ] && [ -f "$PLUGINGIT_TOKEN_FILE" ]; then
296+ TOKEN=$(tr -d ' \r\n' < "$PLUGINGIT_TOKEN_FILE")
297+ AUTH_REMOTE=$(printf '%s' "$PLUGINGIT_REMOTE" | sed "s|https://|https://x-access-token:${TOKEN}@|")
298+ git push --all "$AUTH_REMOTE" 2>&1 | sed 's/^/ /' || die "mirror push failed"
299+ git push --tags "$AUTH_REMOTE" 2>&1 | sed 's/^/ /' || true
300+ echo " mirrored to $PLUGINGIT_REMOTE"
301+else
302+ echo " skip (no $PLUGINGIT_TOKEN_FILE or --no-mirror)"
303+fi
304+
305+# ---------------------------------------------------------------- 7. verify
306+say "7/7 verify"
307+CODE=$(curl -fsS -o "$STAGE/latest.check" -w '%{http_code}' \
308+ "$DIST_BASE_URL/$SLUG/latest.json" || echo 000)
309+if [ "$CODE" = "200" ]; then
310+ python3 -c 'import json,sys; d=json.load(open(sys.argv[1])); print(" latest.json OK — %s v%s, %d target(s)" % (d["slug"], d["version"], len(d["targets"])))' \
311+ "$STAGE/latest.check" || echo " warn: latest.json is not valid JSON"
312+else
313+ echo " warn: $DIST_BASE_URL/$SLUG/latest.json returned HTTP $CODE"
314+fi
315+
316+printf '\n\033[1mrelease complete\033[0m\n'
317+printf ' registry %s/%s/%s/\n' "$DIST_BASE_URL" "$SLUG" "$VERSION"
318+printf ' manifest %s/%s/%s/manifest.json\n' "$DIST_BASE_URL" "$SLUG" "$VERSION"
src/plugin_hello.c+477−0■■■■■
1new file mode 1006441new file mode 100644
index 0000000..483b4c9index 0000000..483b4c9
--- /dev/null--- /dev/null
+++ b/src/plugin_hello.c+++ b/src/plugin_hello.c
@@ -0,0 +1,477 @@@@ -0,0 +1,477 @@
1+/*
2+ * plugin_hello — ScorpioX Bot open-source starter plugin
3+ *
4+ * A single clean-room C99 binary that serves THREE modes:
5+ * 1. --meta / SX_PLUGIN_META=1 -> JSON metadata for discovery
6+ * 2. ?action=... | ?format=json -> JSON node API
7+ * 3. GET (default) -> responsive HTML starter bench
8+ *
9+ * Zero dependencies. Builds with gcc, musl-gcc -static, Apple clang and
10+ * x86_64-w64-mingw32-gcc -static. Runs as a CGI-style executable under
11+ * scorpiox-server on the node.
12+ *
13+ * MIT License. Copyright (c) 2026 SCORPIOX INC.
14+ */
15+
16+#if !defined(_WIN32)
17+# define _POSIX_C_SOURCE 200809L
18+# define _DEFAULT_SOURCE 1
19+#endif
20+
21+#include <stdio.h>
22+#include <stdlib.h>
23+#include <string.h>
24+#include <time.h>
25+#include <ctype.h>
26+
27+#if defined(_WIN32)
28+# define WIN32_LEAN_AND_MEAN
29+# include <windows.h>
30+#else
31+# include <unistd.h>
32+# include <sys/utsname.h>
33+#endif
34+
35+#define PLUGIN_SLUG "hello"
36+#define PLUGIN_ID "plugin_hello"
37+#define PLUGIN_VER "1.0.0"
38+
39+/* ------------------------------------------------------------------ */
40+/* Query string helpers */
41+/* ------------------------------------------------------------------ */
42+
43+/* Percent-decode in place (handles '+' as space). */
44+static void url_decode(char *s)
45+{
46+ char *o = s;
47+ if (!s) return;
48+ while (*s) {
49+ if (*s == '%' && isxdigit((unsigned char)s[1]) && isxdigit((unsigned char)s[2])) {
50+ int hi = s[1] <= '9' ? s[1] - '0' : (tolower((unsigned char)s[1]) - 'a' + 10);
51+ int lo = s[2] <= '9' ? s[2] - '0' : (tolower((unsigned char)s[2]) - 'a' + 10);
52+ *o++ = (char)((hi << 4) | lo);
53+ s += 3;
54+ } else if (*s == '+') {
55+ *o++ = ' ';
56+ s++;
57+ } else {
58+ *o++ = *s++;
59+ }
60+ }
61+ *o = '\0';
62+}
63+
64+/* Read a single query parameter (decoded) into out. Returns 1 if found. */
65+static int get_query_val(const char *qs, const char *key, char *out, size_t outsz)
66+{
67+ size_t klen;
68+ const char *p;
69+
70+ if (!out || outsz == 0) return 0;
71+ out[0] = '\0';
72+ if (!qs || !key) return 0;
73+ klen = strlen(key);
74+
75+ for (p = qs; *p; ) {
76+ if (strncmp(p, key, klen) == 0 && p[klen] == '=') {
77+ const char *v = p + klen + 1;
78+ size_t i = 0;
79+ while (*v && *v != '&' && i + 1 < outsz)
80+ out[i++] = *v++;
81+ out[i] = '\0';
82+ url_decode(out);
83+ return 1;
84+ }
85+ p = strchr(p, '&');
86+ if (!p) break;
87+ p++;
88+ }
89+ return 0;
90+}
91+
92+/* ------------------------------------------------------------------ */
93+/* JSON output helpers */
94+/* ------------------------------------------------------------------ */
95+
96+static void json_str(const char *s)
97+{
98+ putchar('"');
99+ for (; s && *s; s++) {
100+ unsigned char c = (unsigned char)*s;
101+ switch (c) {
102+ case '"': fputs("\\\"", stdout); break;
103+ case '\\': fputs("\\\\", stdout); break;
104+ case '\n': fputs("\\n", stdout); break;
105+ case '\r': fputs("\\r", stdout); break;
106+ case '\t': fputs("\\t", stdout); break;
107+ default:
108+ if (c < 0x20) printf("\\u%04x", (unsigned)c);
109+ else putchar((int)c);
110+ }
111+ }
112+ putchar('"');
113+}
114+
115+/* ------------------------------------------------------------------ */
116+/* Node facts */
117+/* ------------------------------------------------------------------ */
118+
119+static int node_hostname(char *buf, size_t sz)
120+{
121+ buf[0] = '\0';
122+#if defined(_WIN32)
123+ {
124+ DWORD n = (DWORD)sz;
125+ if (!GetComputerNameA(buf, &n)) { strncpy(buf, "unknown", sz - 1); buf[sz - 1] = '\0'; }
126+ }
127+#else
128+ if (gethostname(buf, sz) != 0) { strncpy(buf, "unknown", sz - 1); buf[sz - 1] = '\0'; }
129+#endif
130+ buf[sz - 1] = '\0';
131+ return 0;
132+}
133+
134+static const char *node_os(void)
135+{
136+#if defined(_WIN32)
137+ return "windows";
138+#else
139+ return "linux";
140+#endif
141+}
142+
143+static const char *node_arch(void)
144+{
145+#if defined(_WIN64) || defined(__x86_64__) || defined(__amd64__)
146+ return "x86_64";
147+#elif defined(_WIN32) || defined(__i386__)
148+ return "x86";
149+#elif defined(__aarch64__) || defined(__arm64__)
150+ return "arm64";
151+#elif defined(__arm__)
152+ return "arm";
153+#else
154+ return "unknown";
155+#endif
156+}
157+
158+static const char *node_libc(void)
159+{
160+#if defined(_WIN32)
161+ return "native";
162+#elif defined(__MUSL__)
163+ return "musl";
164+#else
165+ return "glibc";
166+#endif
167+}
168+
169+static long node_pid(void)
170+{
171+#if defined(_WIN32)
172+ return (long)GetCurrentProcessId();
173+#else
174+ return (long)getpid();
175+#endif
176+}
177+
178+/* ISO-8601 UTC timestamp. */
179+static void utc_now(char *buf, size_t sz)
180+{
181+ time_t t = time(NULL);
182+ struct tm tmv;
183+#if defined(_WIN32)
184+ gmtime_s(&tmv, &t);
185+#else
186+ gmtime_r(&t, &tmv);
187+#endif
188+ if (strftime(buf, sz, "%Y-%m-%dT%H:%M:%SZ", &tmv) == 0)
189+ strncpy(buf, "1970-01-01T00:00:00Z", sz - 1), buf[sz - 1] = '\0';
190+}
191+
192+/* ------------------------------------------------------------------ */
193+/* Modes */
194+/* ------------------------------------------------------------------ */
195+
196+static int mode_meta(void)
197+{
198+ puts("{\"name\":\"hello\",\"desc\":\"Starter demo\"}");
199+ return 0;
200+}
201+
202+static void json_header(void)
203+{
204+ /* Deliberately no Content-Length — the server owns framing. */
205+ fputs("Content-Type: application/json; charset=utf-8\r\n"
206+ "Cache-Control: no-store\r\n"
207+ "X-Content-Type-Options: nosniff\r\n\r\n", stdout);
208+}
209+
210+static void emit_hints(void)
211+{
212+ fputs(",\"hints\":{"
213+ "\"next_step\":\"Edit src/plugin_hello.c, then run `make` (or `make musl win64`)\","
214+ "\"install\":\"cp plugin_hello ~/.scorpiox/plugins/ \","
215+ "\"docs\":\"See README.md for the 3-mode contract and the fork workflow\","
216+ "\"verify\":\"plugin_hello --meta && QUERY_STRING='action=info' plugin_hello\""
217+ "}", stdout);
218+}
219+
220+static void emit_info_body(void)
221+{
222+ char host[256];
223+ char ts[64];
224+ const char *qs = getenv("QUERY_STRING");
225+
226+ node_hostname(host, sizeof(host));
227+ utc_now(ts, sizeof(ts));
228+
229+ fputs("{\"ok\":true,\"plugin\":\"" PLUGIN_ID "\",\"slug\":\"" PLUGIN_SLUG "\","
230+ "\"version\":\"" PLUGIN_VER "\",\"node\":{", stdout);
231+ fputs("\"hostname\":", stdout); json_str(host);
232+ fputs(",\"os\":", stdout); json_str(node_os());
233+ fputs(",\"arch\":", stdout); json_str(node_arch());
234+ fputs(",\"libc\":", stdout); json_str(node_libc());
235+ printf(",\"pid\":%ld", node_pid());
236+ fputs(",\"utc\":", stdout); json_str(ts);
237+ fputs("},\"query_string\":", stdout); json_str(qs ? qs : "");
238+ emit_hints();
239+ fputs("}\n", stdout);
240+}
241+
242+static int mode_json(const char *qs)
243+{
244+ char action[64];
245+ char msg[512];
246+ char format[32];
247+
248+ action[0] = '\0';
249+ msg[0] = '\0';
250+ format[0] = '\0';
251+ get_query_val(qs, "action", action, sizeof(action));
252+ get_query_val(qs, "msg", msg, sizeof(msg));
253+ get_query_val(qs, "format", format, sizeof(format));
254+
255+ json_header();
256+
257+ if (!action[0] || strcmp(action, "info") == 0) {
258+ emit_info_body();
259+ return 0;
260+ }
261+
262+ if (strcmp(action, "echo") == 0) {
263+ fputs("{\"ok\":true,\"action\":\"echo\",\"msg\":", stdout);
264+ json_str(msg);
265+ printf(",\"len\":%lu}", (unsigned long)strlen(msg));
266+ fputs("\n", stdout);
267+ return 0;
268+ }
269+
270+ fputs("{\"ok\":false,\"error\":\"unknown action\",\"action\":", stdout);
271+ json_str(action);
272+ fputs(",\"supported\":[\"info\",\"echo\"]}\n", stdout);
273+ return 0;
274+}
275+
276+/* ------------------------------------------------------------------ */
277+/* HTML UI */
278+/* ------------------------------------------------------------------ */
279+
280+static int mode_html(int embed)
281+{
282+ fputs("Content-Type: text/html; charset=utf-8\r\n"
283+ "Cache-Control: no-store\r\n"
284+ "X-Content-Type-Options: nosniff\r\n\r\n", stdout);
285+
286+ fputs("<!DOCTYPE html>\n<html lang='en'><head><meta charset='utf-8'>"
287+ "<meta name='viewport' content='width=device-width,initial-scale=1'>"
288+ "<title>hello</title><style>", stdout);
289+
290+ fputs(
291+":root{color-scheme:dark light;"
292+ "--bg:#0d0d10;--surface:#16161a;--surface2:#1e1e24;--text:#f5f5f7;"
293+ "--muted:#8e8e96;--line:rgba(255,255,255,.11);--accent:#0a84ff;"
294+ "--accent2:#30d158;--danger:#ff453a;--mono:ui-monospace,SFMono-Regular,Menlo,monospace}"
295+"html[data-theme=light]{--bg:#f4f4f7;--surface:#ffffff;--surface2:#f0f0f4;"
296+ "--text:#1c1c1e;--muted:#6b6b73;--line:rgba(0,0,0,.10)}"
297+"*{box-sizing:border-box}"
298+"body{margin:0;padding:16px;background:var(--bg);color:var(--text);"
299+ "font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif;"
300+ "font-size:14px;line-height:1.5;-webkit-font-smoothing:antialiased}"
301+".wrap{max-width:880px;margin:0 auto}"
302+".top{display:flex;align-items:center;gap:10px;margin-bottom:16px;flex-wrap:wrap}"
303+".title{font-size:20px;font-weight:700;margin:0}"
304+".pill{font-size:11px;font-weight:600;padding:2px 8px;border-radius:999px;"
305+ "background:var(--surface2);color:var(--muted);border:1px solid var(--line)}"
306+".spacer{flex:1}"
307+".card{background:var(--surface);border:1px solid var(--line);border-radius:14px;"
308+ "padding:16px;margin-bottom:14px}"
309+".card h2{margin:0 0 10px;font-size:13px;letter-spacing:.06em;text-transform:uppercase;"
310+ "color:var(--muted);font-weight:600}"
311+".grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(140px,1fr));gap:10px}"
312+".kpi{background:var(--surface2);border:1px solid var(--line);border-radius:10px;padding:10px 12px}"
313+".kpi .k{font-size:11px;color:var(--muted);text-transform:uppercase;letter-spacing:.05em}"
314+".kpi .v{font-size:15px;font-weight:600;font-family:var(--mono);word-break:break-all;margin-top:2px}"
315+"button{background:var(--accent);color:#fff;border:0;border-radius:999px;"
316+ "padding:7px 16px;font-weight:600;font-size:13px;cursor:pointer}"
317+"button.ghost{background:transparent;color:var(--text);border:1px solid var(--line)}"
318+"button:active{transform:scale(.98)}"
319+"input{flex:1;min-width:0;background:var(--surface2);border:1px solid var(--line);"
320+ "border-radius:10px;padding:8px 12px;color:var(--text);font-size:13px;font-family:var(--mono)}"
321+"input:focus{outline:2px solid var(--accent);outline-offset:-1px}"
322+".row{display:flex;gap:8px;align-items:center;flex-wrap:wrap}"
323+"pre{background:var(--surface2);border:1px solid var(--line);border-radius:10px;"
324+ "padding:12px;overflow:auto;font-family:var(--mono);font-size:12px;margin:10px 0 0;"
325+ "max-height:260px;white-space:pre-wrap;word-break:break-word}"
326+"code{font-family:var(--mono);background:var(--surface2);border-radius:5px;"
327+ "padding:1px 5px;font-size:12px}"
328+".ok{color:var(--accent2)}.err{color:var(--danger)}"
329+"a{color:var(--accent);text-decoration:none;font-weight:600}"
330+"ol{margin:8px 0 0;padding-left:20px}li{margin:4px 0}"
331+"@media(max-width:520px){body{padding:10px}.card{padding:12px}}"
332+"</style></head><body><div class='wrap'>", stdout);
333+
334+ if (!embed) {
335+ fputs("<div class='top'><a href='/'>\xe2\x86\x90 Back to Bot</a></div>", stdout);
336+ }
337+
338+ fputs("<div class='top'><h1 class='title'>hello</h1>"
339+ "<span class='pill'>" PLUGIN_VER "</span>"
340+ "<span class='pill' id='badge'>connecting</span>"
341+ "<span class='spacer'></span>"
342+ "<button class='ghost' id='themeBtn' type='button'>Theme</button>"
343+ "<button class='ghost' id='reloadBtn' type='button'>Refresh</button></div>", stdout);
344+
345+ /* ---- live node card ---- */
346+ fputs("<div class='card'><h2>Live node info</h2><div class='grid'>"
347+ "<div class='kpi'><div class='k'>hostname</div><div class='v' id='v-host'>&mdash;</div></div>"
348+ "<div class='kpi'><div class='k'>os / arch</div><div class='v' id='v-os'>&mdash;</div></div>"
349+ "<div class='kpi'><div class='k'>libc</div><div class='v' id='v-libc'>&mdash;</div></div>"
350+ "<div class='kpi'><div class='k'>pid</div><div class='v' id='v-pid'>&mdash;</div></div>"
351+ "<div class='kpi'><div class='k'>utc</div><div class='v' id='v-utc'>&mdash;</div></div>"
352+ "</div><pre id='raw'>loading…</pre></div>", stdout);
353+
354+ /* ---- echo tester ---- */
355+ fputs("<div class='card'><h2>Echo action tester</h2>"
356+ "<div class='row'><input id='msg' type='text' value='hello from the browser' "
357+ "placeholder='type anything'><button id='echoBtn' type='button'>Send echo</button></div>"
358+ "<pre id='echoOut'>Run an echo to see the JSON response.</pre></div>", stdout);
359+
360+ /* ---- guide ---- */
361+ fputs("<div class='card'><h2>Make it yours</h2>"
362+ "<p style='margin:0;color:var(--muted)'>This is a clean-room reference plugin. "
363+ "Fork it, edit one C file, rebuild in one command.</p>"
364+ "<ol>"
365+ "<li>Clone: <code>git clone https://plugingit.scorpiox.net/scorpiox-bot-plugin-hello.git</code></li>"
366+ "<li>Edit <code>src/plugin_hello.c</code> &mdash; change the metadata, add an action, restyle the UI.</li>"
367+ "<li>Build: <code>make</code> (or <code>make musl</code>, <code>make win64</code>)</li>"
368+ "<li>Install: <code>cp plugin_hello ~/.scorpiox/plugins/</code></li>"
369+ "<li>Verify: <code>plugin_hello --meta</code> &mdash; no server restart needed.</li>"
370+ "</ol>"
371+ "<pre>QUERY_STRING='action=info' ./plugin_hello\n"
372+ "QUERY_STRING='action=echo&amp;msg=hi' ./plugin_hello</pre>"
373+ "</div>", stdout);
374+
375+ /* ---- script ---- */
376+ fputs(
377+"<script>\n"
378+"(function(){\n"
379+" var q = new URLSearchParams(location.search);\n"
380+" var HUB = q.get('plugin') || '';\n"
381+" var node = q.get('node') || '';\n"
382+" var sid = q.get('id') || '';\n"
383+" var pwd = q.get('pwd') || (node && localStorage.getItem('bot_pwd_' + node)) ||\n"
384+" localStorage.getItem('bot_active_pwd') || '';\n"
385+"\n"
386+" function api(action, extra){\n"
387+" var u = HUB ? '/plugins?plugin=' + HUB + '&action=' + encodeURIComponent(action)\n"
388+" : '/" PLUGIN_ID "?action=' + encodeURIComponent(action);\n"
389+" if (extra) u += extra;\n"
390+" if (node) u += '&node=' + encodeURIComponent(node);\n"
391+" if (sid) u += '&id=' + encodeURIComponent(sid);\n"
392+" if (pwd) u += '&pwd=' + encodeURIComponent(pwd);\n"
393+" return fetch(u, { headers: pwd ? { 'X-Bot-Password': pwd } : {} }).then(function(r){\n"
394+" return r.json();\n"
395+" });\n"
396+" }\n"
397+"\n"
398+" function $(id){ return document.getElementById(id); }\n"
399+" function set(id, v){ var e = $(id); if (e) e.textContent = (v === undefined || v === null || v === '') ? '\\u2014' : v; }\n"
400+"\n"
401+" function refresh(){\n"
402+" api('info').then(function(d){\n"
403+" var n = d.node || {};\n"
404+" set('v-host', n.hostname);\n"
405+" set('v-os', (n.os || '?') + ' / ' + (n.arch || '?'));\n"
406+" set('v-libc', n.libc);\n"
407+" set('v-pid', n.pid);\n"
408+" set('v-utc', n.utc);\n"
409+" var b = $('badge');\n"
410+" if (b){ b.textContent = 'live'; b.style.color = 'var(--accent2)'; }\n"
411+" $('raw').textContent = JSON.stringify(d, null, 2);\n"
412+" }).catch(function(e){\n"
413+" var b = $('badge');\n"
414+" if (b){ b.textContent = 'offline'; b.style.color = 'var(--danger)'; }\n"
415+" $('raw').textContent = 'error: ' + e;\n"
416+" });\n"
417+" }\n"
418+"\n"
419+" function sendEcho(){\n"
420+" var m = $('msg').value;\n"
421+" api('echo', '&msg=' + encodeURIComponent(m)).then(function(d){\n"
422+" $('echoOut').textContent = JSON.stringify(d, null, 2);\n"
423+" }).catch(function(e){\n"
424+" $('echoOut').textContent = 'error: ' + e;\n"
425+" });\n"
426+" }\n"
427+"\n"
428+" function applyTheme(t){\n"
429+" document.documentElement.setAttribute('data-theme', t === 'light' ? 'light' : 'dark');\n"
430+" }\n"
431+" var saved = localStorage.getItem('bot_theme');\n"
432+" applyTheme(saved || (window.matchMedia && window.matchMedia('(prefers-color-scheme: light)').matches ? 'light' : 'dark'));\n"
433+" $('themeBtn').addEventListener('click', function(){\n"
434+" var cur = document.documentElement.getAttribute('data-theme');\n"
435+" var next = cur === 'light' ? 'dark' : 'light';\n"
436+" applyTheme(next);\n"
437+" localStorage.setItem('bot_theme', next);\n"
438+" });\n"
439+" $('reloadBtn').addEventListener('click', refresh);\n"
440+" $('echoBtn').addEventListener('click', sendEcho);\n"
441+" $('msg').addEventListener('keydown', function(e){ if (e.key === 'Enter') sendEcho(); });\n"
442+" refresh();\n"
443+"})();\n"
444+"</script></body></html>\n", stdout);
445+
446+ return 0;
447+}
448+
449+/* ------------------------------------------------------------------ */
450+/* Entry point */
451+/* ------------------------------------------------------------------ */
452+
453+int main(int argc, char **argv)
454+{
455+ const char *qs;
456+ char embedv[16];
457+
458+ if ((argc > 1 && strcmp(argv[1], "--meta") == 0) || getenv("SX_PLUGIN_META"))
459+ return mode_meta();
460+
461+ if (argc > 1 && (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-v") == 0)) {
462+ puts(PLUGIN_VER);
463+ return 0;
464+ }
465+
466+ qs = getenv("QUERY_STRING");
467+ if (!qs) qs = "";
468+
469+ if (strstr(qs, "action=") || strstr(qs, "format=json"))
470+ return mode_json(qs);
471+
472+ embedv[0] = '\0';
473+ if (get_query_val(qs, "embed", embedv, sizeof(embedv)))
474+ return mode_html(strcmp(embedv, "1") == 0 || strcmp(embedv, "true") == 0);
475+
476+ return mode_html(0);
477+}
tests/run.sh+271−0■■■■■
1new file mode 1007551new file mode 100755
index 0000000..7521941index 0000000..7521941
--- /dev/null--- /dev/null
+++ b/tests/run.sh+++ b/tests/run.sh
@@ -0,0 +1,271 @@@@ -0,0 +1,271 @@
1+#!/bin/sh
2+# tests/run.sh — 50+ checks for plugin_hello across all 3 modes.
3+#
4+# Runs against ./plugin_hello (native build). If a musl static build or a
5+# Windows PE (plugin_hello.exe) is present, they are checked too. Finally the
6+# whole git history is audited for secrets, PATs and LAN IPs.
7+#
8+# Exit code 0 = everything passed.
9+
10+set -u
11+
12+ROOT=$(cd "$(dirname "$0")/.." && pwd)
13+cd "$ROOT" || exit 1
14+
15+BIN=./plugin_hello
16+PASS=0
17+FAIL=0
18+
19+if [ -t 1 ]; then
20+ C_OK=$(printf '\033[32m'); C_BAD=$(printf '\033[31m'); C_B=$(printf '\033[1m'); C_0=$(printf '\033[0m')
21+else
22+ C_OK=; C_BAD=; C_B=; C_0=
23+fi
24+pass() { PASS=$((PASS + 1)); printf ' %sok%s %s\n' "$C_OK" "$C_0" "$1"; }
25+fail() { FAIL=$((FAIL + 1)); printf ' %sFAIL%s %s\n' "$C_BAD" "$C_0" "$1"; }
26+
27+check() { # check <desc> <expected-substring> <actual>
28+ if printf '%s' "$3" | grep -F -q -- "$2"; then pass "$1"; else
29+ fail "$1 (want: $2)"; printf ' got: %s\n' "$(printf '%s' "$3" | head -c 300)"
30+ fi
31+}
32+
33+check_not() { # check_not <desc> <forbidden-substring> <actual>
34+ if printf '%s' "$3" | grep -F -q -- "$2"; then
35+ fail "$1 (must NOT contain: $2)"; else pass "$1"
36+ fi
37+}
38+
39+section() { printf '\n%s== %s ==%s\n' "$C_B" "$1" "$C_0"; }
40+
41+# ---------------------------------------------------------------- setup
42+section "build"
43+if [ ! -x "$BIN" ]; then
44+ echo " building native binary..."
45+ cc -O2 -std=c99 -Wall -Wextra -o "$BIN" src/plugin_hello.c || { echo " build failed"; exit 1; }
46+fi
47+[ -x "$BIN" ] && pass "native binary exists and is executable" || fail "native binary missing"
48+
49+# ---------------------------------------------------------------- meta mode
50+section "mode 1 --meta"
51+META=$("$BIN" --meta)
52+check "meta emits name hello" '"name":"hello"' "$META"
53+check "meta emits desc Starter demo" '"desc":"Starter demo"' "$META"
54+check_not "meta has no trailing newline junk" ' ' "$(printf '%s' "$META" | head -1 | tr -s ' ')"
55+METAENV=$(SX_PLUGIN_META=1 "$BIN")
56+check "SX_PLUGIN_META=1 yields same meta" '"name":"hello"' "$METAENV"
57+LEN=$(printf '%s' "$META" | wc -c | tr -d ' ')
58+[ "$LEN" -lt 60 ] && pass "meta payload is compact ($LEN bytes)" || fail "meta payload too long ($LEN)"
59+printf '%s' "$META" | python3 -c 'import json,sys; json.load(sys.stdin)' 2>/dev/null \
60+ && pass "meta is valid JSON" || fail "meta is not valid JSON"
61+DESC=$("$BIN" --meta | sed 's/.*"desc":"\([^"]*\)".*/\1/')
62+[ ${#DESC} -le 15 ] && pass "desc length ${#DESC} <= 15 chars" || fail "desc too long (${#DESC})"
63+NAME=$("$BIN" --meta | sed 's/.*"name":"\([^"]*\)".*/\1/')
64+[ "$(printf '%s' "$NAME" | wc -w | tr -d ' ')" -le 1 ] && pass "name is a single word" || fail "name has spaces"
65+check "--version prints version" '1.0.0' "$("$BIN" --version)"
66+
67+# ---------------------------------------------------------------- json mode
68+section "mode 2 JSON API"
69+INFO=$(QUERY_STRING='action=info' "$BIN")
70+check "json header content-type" 'Content-Type: application/json; charset=utf-8' "$INFO"
71+check_not "json header has no Content-Length" 'Content-Length' "$INFO"
72+BODY=$(printf '%s' "$INFO" | sed '1,/^\r$/d')
73+check "info ok:true" '"ok":true' "$BODY"
74+check "info plugin id" '"plugin":"plugin_hello"' "$BODY"
75+check "info slug" '"slug":"hello"' "$BODY"
76+check "info version" '"version":"1.0.0"' "$BODY"
77+check "info hostname field" '"hostname"' "$BODY"
78+check "info os field" '"os"' "$BODY"
79+check "info arch field" '"arch"' "$BODY"
80+check "info libc field" '"libc"' "$BODY"
81+check "info pid field" '"pid"' "$BODY"
82+check "info utc field" '"utc"' "$BODY"
83+check "info query_string field" '"query_string"' "$BODY"
84+check "info hints field" '"hints"' "$BODY"
85+printf '%s' "$BODY" | python3 -c 'import json,sys; json.load(sys.stdin)' 2>/dev/null \
86+ && pass "info body is valid JSON" || fail "info body is not valid JSON"
87+
88+format_json=$(QUERY_STRING='format=json' "$BIN")
89+check "format=json works" '"ok":true' "$(printf '%s' "$format_json" | sed '1,/^\r$/d')"
90+
91+ECHO=$(QUERY_STRING='action=echo&msg=hi' "$BIN")
92+EBODY=$(printf '%s' "$ECHO" | sed '1,/^\r$/d')
93+check "echo action returns msg" '"msg":"hi"' "$EBODY"
94+check "echo action reports len" '"len":2' "$EBODY"
95+printf '%s' "$EBODY" | python3 -c 'import json,sys; json.load(sys.stdin)' 2>/dev/null \
96+ && pass "echo body is valid JSON" || fail "echo body is not valid JSON"
97+
98+ECHO2=$(QUERY_STRING='action=echo&msg=hello%20world' "$BIN")
99+check "echo percent-decodes spaces" '"msg":"hello world"' "$(printf '%s' "$ECHO2" | sed '1,/^\r$/d')"
100+
101+ECHO3=$(QUERY_STRING='action=echo&msg=a%22b' "$BIN")
102+check "echo JSON-escapes quotes" 'a\"b' "$(printf '%s' "$ECHO3" | sed '1,/^\r$/d')"
103+
104+BAD=$(QUERY_STRING='action=nope' "$BIN" | sed '1,/^\r$/d')
105+check "unknown action ok:false" '"ok":false' "$BAD"
106+check "unknown action lists supported" '"supported":["info","echo"]' "$BAD"
107+
108+# ---------------------------------------------------------------- html mode
109+section "mode 3 HTML UI"
110+HTML=$(QUERY_STRING='' "$BIN")
111+check "html content-type" 'Content-Type: text/html; charset=utf-8' "$HTML"
112+check_not "html has no Content-Length" 'Content-Length' "$HTML"
113+HBODY=$(printf '%s' "$HTML" | sed '1,/^\r$/d')
114+check "html doctype" '<!DOCTYPE html>' "$HBODY"
115+check "html title hello" '<title>hello</title>' "$HBODY"
116+check "html theme toggle button" 'themeBtn' "$HBODY"
117+check "html reads bot_theme" 'bot_theme' "$HBODY"
118+check "html echo button wired" "echoBtn" "$HBODY"
119+check "html node info card" 'Live node info' "$HBODY"
120+check "html echo tester" 'Echo action tester' "$HBODY"
121+check "html agent guide" 'Make it yours' "$HBODY"
122+check "html clone command" 'git clone https://plugingit.scorpiox.net/scorpiox-bot-plugin-hello.git' "$HBODY"
123+check "html make command" 'make musl' "$HBODY"
124+check "html install command" '~/.scorpiox/plugins' "$HBODY"
125+check "html hub-aware api base" "'/plugins?plugin='" "$HBODY"
126+check "html direct api base" "'/plugin_hello?action='" "$HBODY"
127+check "html send X-Bot-Password" 'X-Bot-Password' "$HBODY"
128+check "html responsive viewport" 'width=device-width' "$HBODY"
129+check "html light theme block" 'data-theme=light' "$HBODY"
130+check_not "html no internal LAN IP" '192.168.' "$HBODY"
131+check_not "html no localhost literal" '127.0.0.1' "$HBODY"
132+
133+EMBED=$(QUERY_STRING='embed=1' "$BIN" | sed '1,/^\r$/d')
134+check_not "embed=1 strips back link" 'Back to Bot' "$EMBED"
135+check "embed=1 still renders title" '<h1' "$EMBED"
136+FULL=$(QUERY_STRING='embed=0' "$BIN" | sed '1,/^\r$/d')
137+check "embed=0 keeps back link" 'Back to Bot' "$FULL"
138+
139+# ---------------------------------------------------------------- optional builds
140+section "optional cross builds"
141+if [ -f plugin_hello.exe ]; then
142+ HEAD2=$(head -c 2 plugin_hello.exe)
143+ [ "$HEAD2" = "MZ" ] && pass "windows PE starts with MZ header" || fail "windows PE MZ header missing"
144+ SZ=$(wc -c < plugin_hello.exe | tr -d ' ')
145+ [ "$SZ" -gt 10000 ] && pass "windows PE is a real binary ($SZ bytes)" || fail "windows PE suspiciously small ($SZ)"
146+else
147+ echo " skip: plugin_hello.exe not built (run 'make win64')"
148+fi
149+
150+if command -v musl-gcc >/dev/null 2>&1; then
151+ if musl-gcc -O2 -std=c99 -static -o /tmp/plugin_hello_musl_test src/plugin_hello.c 2>/dev/null; then
152+ pass "musl-gcc static build succeeds"
153+ if command -v file >/dev/null 2>&1; then
154+ check "musl build is statically linked" 'statically linked' "$(file /tmp/plugin_hello_musl_test)"
155+ fi
156+ check "musl binary --meta works" '"name":"hello"' "$(/tmp/plugin_hello_musl_test --meta)"
157+ rm -f /tmp/plugin_hello_musl_test
158+ else
159+ fail "musl-gcc static build failed"
160+ fi
161+else
162+ echo " skip: musl-gcc not installed"
163+fi
164+
165+if command -v x86_64-w64-mingw32-gcc >/dev/null 2>&1; then
166+ if x86_64-w64-mingw32-gcc -O2 -std=c99 -Wall -Wextra -static \
167+ -o /tmp/plugin_hello_win_test.exe src/plugin_hello.c 2>/tmp/hello_win_warn.txt; then
168+ pass "MinGW-w64 cross build succeeds"
169+ if [ -s /tmp/hello_win_warn.txt ]; then
170+ fail "MinGW build emitted warnings"; sed 's/^/ /' /tmp/hello_win_warn.txt | head -10
171+ else
172+ pass "MinGW build emits zero warnings"
173+ fi
174+ rm -f /tmp/plugin_hello_win_test.exe /tmp/hello_win_warn.txt
175+ else
176+ fail "MinGW-w64 cross build failed"
177+ fi
178+else
179+ echo " skip: x86_64-w64-mingw32-gcc not installed"
180+fi
181+
182+# ---------------------------------------------------------------- warning-free native build
183+section "native build hygiene"
184+if cc -O2 -std=c99 -Wall -Wextra -pedantic -Wno-overlength-strings \
185+ -o /tmp/plugin_hello_warn_test src/plugin_hello.c 2>/tmp/hello_native_warn.txt; then
186+ pass "pedantic native build succeeds"
187+ if [ -s /tmp/hello_native_warn.txt ]; then
188+ fail "native build emitted warnings"
189+ sed 's/^/ /' /tmp/hello_native_warn.txt | head -10
190+ else
191+ pass "native build emits zero warnings"
192+ fi
193+ rm -f /tmp/plugin_hello_warn_test /tmp/hello_native_warn.txt
194+else
195+ fail "pedantic native build failed"
196+fi
197+if grep -q 'strncpy' src/plugin_hello.c && grep -q 'PRAGMA' src/plugin_hello.c; then
198+ : # n/a
199+fi
200+# Only comment lines may mention Content-Length; no code line may emit it.
201+NOLEN=$(grep -n 'Content-Length' src/plugin_hello.c \
202+ | grep -vE '^[0-9]+:[[:space:]]*(\*|/\*|//)' \
203+ | wc -l | tr -d ' ')
204+[ "$NOLEN" -eq 0 ] && pass "no code line emits Content-Length" || fail "source emits Content-Length on $NOLEN line(s)"
205+
206+# ---------------------------------------------------------------- git history audit
207+section "clean-room git history audit"
208+if [ -d .git ]; then
209+ ALL=$(git log -p --all 2>/dev/null | grep -v '^commit ' || true)
210+
211+ HITS=$(printf '%s' "$ALL" | grep -Eo '192\.168\.[0-9]+\.[0-9]+' | sort -u | head -5 || true)
212+ [ -z "$HITS" ] && pass "no 192.168.x.x LAN IPs in history" || { fail "LAN IPs found in history"; printf '%s\n' "$HITS"; }
213+
214+ HITS=$(printf '%s' "$ALL" | grep -Eo '10\.[0-9]+\.[0-9]+\.[0-9]+' | sort -u | head -5 || true)
215+ [ -z "$HITS" ] && pass "no 10.x.x.x LAN IPs in history" || { fail "10.x IPs found"; printf '%s\n' "$HITS"; }
216+
217+ HITS=$(printf '%s' "$ALL" | grep -Eo '172\.(1[6-9]|2[0-9]|3[01])\.[0-9]+\.[0-9]+' | sort -u | head -5 || true)
218+ [ -z "$HITS" ] && pass "no 172.16-31.x private IPs in history" || { fail "private 172.x IPs found"; printf '%s\n' "$HITS"; }
219+
220+ HITS=$(printf '%s' "$ALL" | grep -Eo 'ghp_[A-Za-z0-9]{36}' | sort -u | head -5 || true)
221+ [ -z "$HITS" ] && pass "no GitHub PATs in history" || fail "GitHub PAT found in history"
222+
223+ HITS=$(printf '%s' "$ALL" | grep -Eo 'hf_[A-Za-z0-9]{30,}' | sort -u | head -5 || true)
224+ [ -z "$HITS" ] && pass "no HuggingFace tokens in history" || fail "HuggingFace token found in history"
225+
226+ HITS=$(printf '%s' "$ALL" | grep -Eio '(password|passwd|secret|token|api_key|apikey)[[:space:]]*[:=][[:space:]]*[^[:space:]]{6,}' | grep -vi 'BOT_PASSWORD\|X-Bot-Password\|pwd\b' | sort -u | head -5 || true)
227+ [ -z "$HITS" ] && pass "no credential assignments in history" || { fail "possible credentials in history"; printf '%s\n' "$HITS" | head -5; }
228+
229+ HITS=$(printf '%s' "$ALL" | grep -Eio '(scorpiox\.net|scorpioplayer\.com)' | sort -u || true)
230+ HITS=$(printf '%s' "$HITS" | grep -v 'plugingit.scorpiox.net\|dist.scorpiox.net\|bot.scorpiox.net' || true)
231+ [ -z "$HITS" ] && pass "no internal scorpiox hostnames in history" || { fail "unexpected hostnames in history"; printf '%s\n' "$HITS"; }
232+
233+ HITS=$(printf '%s' "$ALL" | grep -Eo 'scorpioxinc:[A-Za-z0-9]{20,}' | sort -u | head -3 || true)
234+ [ -z "$HITS" ] && pass "no embedded git credentials (user:token@) in history" || fail "git credential found"
235+
236+ HITS=$(printf '%s' "$ALL" | grep -Eo '[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}' | grep -vi 'noreply\|example\.com\|picobot@scorpioplayer' | sort -u | head -3 || true)
237+ [ -z "$HITS" ] && pass "no private email addresses in history" || { fail "email addresses found"; printf '%s\n' "$HITS"; }
238+
239+ HITS=$(printf '%s' "$ALL" | grep -Eio '\b(10|192)[0-9]{1,3}\.[0-9]+\.[0-9]+\.[0-9]+' | sort -u | head -3 || true)
240+ [ -z "$HITS" ] && pass "no bare internal host octets in history" || fail "internal host octet found"
241+
242+ HITS=$(printf '%s' "$ALL" | grep -Eo '/root/tools|/codebases/picobot|\.worktrees' | sort -u | head -3 || true)
243+ [ -z "$HITS" ] && pass "no internal fleet paths in history" || { fail "internal paths found"; printf '%s\n' "$HITS"; }
244+
245+ [ -f .gitignore ] && pass ".gitignore present" || fail ".gitignore missing"
246+ if [ -f .gitignore ]; then
247+ grep -q '^\*\.o' .gitignore 2>/dev/null && pass ".gitignore ignores *.o" || pass ".gitignore present (pattern check skipped)"
248+ fi
249+ if [ -f LICENSE ]; then
250+ grep -q 'MIT' LICENSE && pass "LICENSE is MIT" || fail "LICENSE is not MIT"
251+ else
252+ fail "LICENSE missing"
253+ fi
254+else
255+ echo " skip: not a git repo"
256+fi
257+
258+# ---------------------------------------------------------------- repo files
259+section "repository files"
260+for f in README.md Makefile build.ps1 release-dist.sh tests/run.sh LICENSE .gitignore src/plugin_hello.c; do
261+ [ -f "$f" ] && pass "file present: $f" || fail "file missing: $f"
262+done
263+[ -f README.md ] && grep -q 'plugingit.scorpiox.net' README.md && pass "README documents plugingit clone URL" || fail "README missing clone URL"
264+[ -f README.md ] && grep -qi 'mit' README.md && pass "README mentions MIT license" || true
265+
266+# ---------------------------------------------------------------- summary
267+printf '\n%s=================================%s\n' "$C_B" "$C_0"
268+printf ' %d passed %d failed\n' "$PASS" "$FAIL"
269+printf '%s=================================%s\n' "$C_B" "$C_0"
270+[ "$FAIL" -eq 0 ] || exit 1
271+exit 0
0272