scorpiox-bot-plugin-gitstat

scorpiox-bot-plugin-gitstat

main1 branch · 0 tags
VS Code
HTTPS
ForkDelete
Recent Commits
README

gitstat — a git repository status board for SCORPIOX BOT

plugin_gitstat is a single zero-dependency C99 binary that answers one question

about a machine: **which of my repositories have uncommitted work, and how far

are they from their upstream?**

It walks a fixed set of allowlisted roots, finds every working tree with a .git

entry, and asks git itself — status --porcelain=v2 --branch, log -1,

stash list — through argv-only child processes. No shell, no popen, no

parsing of .git/index by hand.

1440 dark

1440 light 1024 dark
1440 light 1024 dark
390 dark 390 light
390 dark 390 light

Modes

Invocation Output
plugin_gitstat --meta (or SX_PLUGIN_META=1) {"name":"git","desc":"Repo status"} — unauthenticated, so discovery works
GET ?action=repos Every repository found, plus per-root counts and a summary
GET ?action=repo&path=<abs> One repository: 500 changed files max, 20 recent commits
POST ?action=fetch&path=<abs> git fetch --prune, 30 s timeout, only when GITSTAT_ALLOW_FETCH=1
GET (default) The responsive HTML board

Every action except --meta sits behind require_node_auth(): X-Bot-Password,

Authorization: Bearer, or ?pwd=, and it is a no-op only when BOT_PASSWORD

is unset.

Roots

Platform Defaults
Linux /workspace, /codebases, $HOME, plus GITSTAT_ROOTS (:-separated)
macOS same
Windows %USERPROFILE%, D:\codebases and C:\codebases when present, plus GITSTAT_ROOTS (;-separated)

Two environment knobs:

  • GITSTAT_ONLY_ROOTS=1 makes GITSTAT_ROOTS the complete list instead of an

addition. Useful on a node that wants an explicit allowlist, and it is what the

test suite uses so a developer machine full of checkouts cannot change the

result.

  • GITSTAT_ALLOW_FETCH=1 enables the single write-ish action. Without it the

plugin is strictly read-only and POST ?action=fetch answers 403-style

{"ok":false,...} explaining the switch.

Discovery is depth-limited to 4 and budgeted per root (20 000 entries each,

1 200 repositories in the table), because one shared budget lets the first root

consume the whole walk and the second root report zero.

JSON shape

{
  "ok": true,
  "action": "repos",
  "count": 4,
  "table_capped": false,
  "summary": {"dirty": 1, "ahead": 1, "behind": 0, "stashes": 1, "detached": 1},
  "checked_at": "2026-11-12T09:31:06Z",
  "roots": [{"root": "/codebases", "exists": true, "count": 4, "truncated": false}],
  "repos": [{
    "path": "/codebases/portal-web",
    "name": "portal-web",
    "root": "/codebases",
    "branch": "main",
    "upstream": "origin/main",
    "remote": "https://git.example.net/team/portal-web.git",
    "ahead": 2, "behind": 0,
    "dirty": 3, "untracked": 1, "staged": 1, "conflicted": 0,
    "stash": 1,
    "detached": false, "no_upstream": false, "unborn": false,
    "last_commit": {
      "hash": "…", "short": "7746dc67", "ct": 1794475861,
      "at": "2026-11-12T09:31:01Z",
      "subject": "Cap the retry backoff at thirty seconds"
    }
  }]
}

?action=repo&path= adds changed (code + path, max 500), changed_count,

changed_truncated and commits (max 20). A path is accepted only when it

canonicalises to somewhere under an allowlisted root and that directory

carries a .git entry; anything else, including a .. traversal, is 403.

Security posture

  • No shell anywhere. Every git invocation is an argv array handed to

execvp / CreateProcessA. A path with a ; or a backtick in it is a path,

not a command.

  • Read-only by default. git fetch --prune is the only operation that

touches a remote, it needs GITSTAT_ALLOW_FETCH=1, and it is capped at 30

seconds. Nothing ever runs pull, checkout, reset or clean.

  • No credential prompts. GIT_TERMINAL_PROMPT=0, an empty GIT_ASKPASS, and

stdin from /dev/null, so a repository with a dead remote can never hang the

node behind a password prompt.

  • Remote URLs are stripped of userinfo before they are printed, so an origin

of https://user:token@host/x.git shows as https://host/x.git in the board,

the JSON and anything a caller pipes it into.

  • Allowlisted roots only. Discovery never leaves them, and the detail and

fetch actions re-check the canonical path on every request.

Build

make            # native
make musl       # static musl x86_64 (universal Linux)
make arm64      # static aarch64
make win64      # MinGW-w64 static PE
make macos      # Apple clang (run on macOS)
make test       # build + 110 offline assertions
python3 tests/e2e.py   # Playwright 1440/1024/390, dark + light
make clean

src/ui.html is the page; tools/gen_ui.py compiles it into src/ui_html.h

with two control-byte placeholders that the C side expands into the bot's theme

macros, so the plugin can never drift away from the bot palette. make ui

regenerates it, and python3 tools/gen_ui.py --check fails when it is stale.

Install

Pre-built artifacts for six targets live at

https://dist.scorpiox.net/bot-plugins/gitstat/1.0.0/. Drop the right one into

~/.scorpiox/plugins/plugin_gitstat (or /workspace/.scorpiox/plugins/ on a

BotCloud container) — scorpiox-server discovers it live, with no restart.

Or build it from source, which is the point of the marketplace:

Clone https://plugingit.scorpiox.net/scorpiox-bot-plugin-gitstat.git, read
src/plugin_gitstat.c, customise the root list for this machine, compile it
with make, check --meta, and install it to ~/.scorpiox/plugins/.

License

MIT. See LICENSE.