scorpiox-bot-plugin-sessionstats
←README.mdmarkdown
175 lines · 5 KBHEAD
BlameDownload

plugin_sessionstats

Session runtime and turn analytics for a SCORPIOX BOT node — a single clean-room

C99 binary, MIT licensed, with no dependency beyond libc.

It reads the local session store and reports how long each session ran, how much

of that time the agent was actually working versus waiting for a prompt, how many

turns it took, which tools were called, and which profile/model did the work.

What it reads

Read-only, local only, no network:

<root>/<session>/
├── meta.json      session id, start time, model, provider, profile, cwd, thread
├── stats.json     branch and token counters (optional)
├── events.jsonl   the event stream: run starts, idles, tool calls
└── thinking       present while the agent is actively working (marker only)

<root> is $SX_SESSIONS_DIR when set, otherwise %LOCALAPPDATA%\scorpiox\sessions

or %USERPROFILE%\.scorpiox\sessions on Windows, and ~/.scorpiox/sessions or

/workspace/.scorpiox/sessions on POSIX.

Active time is measured from agent_run_start to the next

agent_idle / agent_complete / session_end / session_compact, and a run

that is still open counts up to the last event. Idle time is the remainder of

the wall clock. Timestamps in these files are local wall-clock text, and only

differences are used, so no timezone database is needed.

Three modes

1. Discovery

./plugin_sessionstats --meta
# {"name":"sessions","desc":"Turn metrics"}

SX_PLUGIN_META=1 does the same. This route stays unauthenticated so /plugins

discovery works.

2. JSON API

./plugin_sessionstats ?action=summary
./plugin_sessionstats ?action=session&sid=2026_11_10_vibrant_leibniz
./plugin_sessionstats ?format=json

action=summary returns the aggregate plus every session:

{
  "ok": true,
  "plugin": "plugin_sessionstats",
  "version": "1.0.0",
  "sessions_root": "/root/.scorpiox/sessions",
  "root_found": true,
  "count": 12,
  "active_now": 1,
  "total_sec": 91540, "total_fmt": "1d 01h 25m",
  "active_sec": 41230, "active_fmt": "11h 27m 10s",
  "idle_sec": 50310,   "idle_fmt": "13h 58m 30s",
  "duty_cycle_pct": 45.04,
  "turns": 96,
  "tool_events": 1841,
  "profiles": [{"profile": "sglang-personal-deepseek", "sessions": 9, "active_sec": 38010, "turns": 74}],
  "models":   [{"model": "deepseek-v4.1-flash", "sessions": 9, "active_sec": 38010, "turns": 74}],
  "sessions": [
    {
      "id": "2026_11_10_vibrant_leibniz",
      "dir": "2026_11_10_vibrant_leibniz",
      "model": "deepseek-v4.1-flash",
      "provider": "openai",
      "profile": "sglang-personal-deepseek",
      "branch": "main",
      "cwd": "/codebases/x",
      "start_time": "2026-11-10 17:40:32",
      "first_epoch": 1794332432,
      "last_epoch": 1794339727,
      "is_active": false,
      "total_sec": 7295, "total_fmt": "02h 01m 35s",
      "active_sec": 7226, "active_fmt": "02h 00m 26s",
      "idle_sec": 69, "idle_fmt": "01m 09s",
      "duty_cycle_pct": 99.05,
      "turns": 1,
      "avg_turn_sec": 7226.0,
      "tokens": {"in": 325122, "out": 462, "cache_read": 317568, "cache_write": 7554},
      "tools": [{"name": "Bash", "calls": 345}, {"name": "ReadImage", "calls": 11}]
    }
  ]
}

action=session&sid=<dir-or-full-id> returns one session plus a small

summary block, and accepts sid older than the scan window. id= is an alias

for sid=. Everything is percent-decoded.

3. HTML UI

GET with no action returns a responsive dashboard: KPI cards, an

active-versus-idle rail, profile and model time bars, a sortable session table

and a per-session tool breakdown. It follows prefers-color-scheme, has an

explicit theme toggle, and reflows down to 390 px.

It also works inside the Chat floating window (?embed=1) and pre-selects a

session from ?id=.

Authentication

When BOT_PASSWORD is set on the node, every route except --meta requires one

of:

  • X-Bot-Password: <password>
  • Authorization: Bearer <password>
  • ?pwd=<password> (what the bot web UI appends)

Without BOT_PASSWORD the plugin is a no-op on auth, which keeps local

development and the offline tests simple.

Build

make            # native
make musl       # static x86_64 musl - the universal Linux artifact
make arm64      # static aarch64 musl - Raspberry Pi 5 / ARM64 servers
make win64      # static Win64 PE via MinGW-w64
make macos      # Apple clang, run on macOS
make test       # build + run the offline assertion suite

On Windows: powershell -ExecutionPolicy Bypass -File build.ps1.

Install

mkdir -p ~/.scorpiox/plugins
cp plugin_sessionstats ~/.scorpiox/plugins/
chmod +x ~/.scorpiox/plugins/plugin_sessionstats

On a BotCloud container use /workspace/.scorpiox/plugins instead — it survives

container restarts. No server restart is needed; scorpiox-server resolves the

plugin directory on every request.

Release

./release-dist.sh scans the full git history for secrets and private

addresses, builds every target it can, writes manifest.json + SHA256SUMS +

source.tar.gz, uploads to dist.scorpiox.net/bot-plugins/sessionstats/1.0.0/,

merges index.json, mirrors to plugingit, and verifies latest.json.

Environment: DIST_HOST, DIST_PASS, DIST_PATH, MAC_HOST, MAC_USER,

MAC_PASS, PLUGINGIT_TOKEN_FILE.

It silently skips a target it cannot build, so always check the target count

in latest.json, not the exit code. Run it on a host that actually has

musl-gcc, aarch64-linux-gnu-gcc and x86_64-w64-mingw32-gcc.

Tests

tests/run.sh builds nothing and needs no network. It creates synthetic session

fixtures with fixed timestamps, then asserts exact durations, turn counts, tool

frequencies, profile buckets, sort order, the auth matrix, the HTML contract, the

read-only guarantee, and a full-history secret/LAN-IP scan.

sh tests/run.sh ./plugin_sessionstats

License

MIT. Copyright (c) 2026 SCORPIOX INC.