aitools
Native Windows CLI tools in C++ designed to be called by LLMs, starting with window-stitch—a screenshot compositor that captures and combines windows side-by-side, overlaid, or as pixel-difference views.
A collection of small, fast native Windows CLI tools built in C++ for direct LLM integration. Each tool is a self-contained .exe that returns structured JSON output, with no runtime overhead or interpreter startup cost. window-stitch kicks off the collection as a screenshot compositor that captures two windows and combines them into a PNG.
- C++17
- Win32 API
- GDI+ (Graphics Device Interface)
- PrintWindow
- BitBlt
- stb_image_write (single-header PNG encoder)
- Windows Unicode (UTF-16/UTF-8)
- MinGW/TDM-GCC
The core premise is simple: LLMs need to call external tools, and those tools should be fast, predictable, and lightweight. Each tool in aitools is a single-shot CLI program (no daemons, no prompts, no stdin blocking) that accepts arguments, does one thing, and returns exactly one line of valid JSON. Built for Windows in C/C++ because near-instant startup and zero-overhead execution matter when an LLM is waiting for the result. The toolset is designed around consistent conventions—one tool per folder under tools/<name>/, each with its own src/, optional vendor/ dependencies, and build.bat. Every tool supports -h/--help and discovery modes.
window-stitch is the flagship tool. It captures two top-level Windows by title (as a case-insensitive substring, or by exact HWND from a --list) and combines them into a single PNG. Three composition modes: side-by-side (canvas width is the sum, height is the taller window), overlay (the right window ghosted on top of the left at controllable opacity), and diff (per-pixel absolute difference, with optional amplification to make subtle changes visible). Optionally zoom out, crop, or reposition overlays using anchors like top-left or center. The tool distinguishes between two capture methods: PrintWindow(PW_RENDERFULLCONTENT), which renders the window's own surface even if it's occluded or backgrounded, and BitBlt from the screen, which sees only what's visually on top but works when PrintWindow fails (e.g. a minimized window). An 'auto' mode tries PrintWindow first, falling back to screen capture if the result is essentially black—useful for Chromium's aggressive occlusion detection.
The output is always one line of JSON on stdout: success includes the output PNG path, dimensions, capture method used for each window, and quantitative stats (nonblack_ratio, diff_mean and diff_fraction for diff mode). Errors are also JSON, tagged with ok:false and a human-readable error message. The tool is per-monitor-DPI aware, creates parent directories automatically, handles Unicode paths via UTF-8, and never changes window focus unless you pass --foreground (which raises each window, lets it repaint, captures, then restores focus—useful for defeating Chromium's content-blank issue). The entire tool is a single ~830-line C++ file with only one external dependency: stb_image_write.h, a single-header PNG encoder.
- PrintWindow vs. screen BitBlt with intelligent fallback (auto mode) — captures work on backgrounded, occluded, and even minimized windows without stealing focus
- Three composition modes: side-by-side, overlay with per-layer opacity/scaling/anchoring, and per-pixel difference view with amplification for detecting subtle changes
- Zoom and crop viewport applied to final image; cropping accepts pixel or percentage coordinates; scaling filter selectable (smooth interpolation or crisp nearest-neighbor for pixel art)
- Structured JSON output with capture metadata (method used, dimensions, window titles, hwnd handles, nonblack_ratio for black-screen detection)
- Designed for LLM integration: single-shot execution, no prompts, UTF-8 Unicode support, fast startup, predictable parsing