Skip to main content
S

dsh-streamvision

shet114513/dsh-streamvision

Samples the screen, converts frames to SVG and writes readable change events, plus a band-split OCR text stream.

Install

dsh plugin --profile web add github:shet114513/dsh-streamvision

README

dsh-streamvision

Continuous screen vision for an agent that otherwise only sees single screenshots.

The main path never puts pixels into the conversation:

sample → SVG conversion → event writing → injected information

Every sample writes two timestamped files at once — the raw frame (data/samples/s_<ts>.png) and its vector conversion (data/vectors/s_<ts>.svg + .json) — then differences it against the previous frame on a coarse block grid and turns the change into events an agent can read: how strong, where, what the screen looks like now, whether it looks crowded, and what the previous event was. Text has its own parallel channel (band-split OCR, no subtitle-band selection).

Small and dependency-light: Win32 GDI through koffi, a hand-written PNG encoder, and the OCR engine shipped with Windows. No Python, no model weights, no network.

What's new in 0.2.9

  • sv_frame was silently shooting at 1/4 size (blocking, #3) — capture() only honoured maxHeight when it was smaller than the frame; otherwise it fell into a w / 4 fallback, so maxHeight: 1440 on a 2560×1440 screen returned 640×360 (and a 1554×1205 window returned 389×302). Sizing now is: outW → outH/maxHeight → native, always clamped to the source, never upscaled. Small regions are no longer downscaled to a quarter either. sv_frame returns the real size, and it now matches sv_watch for the same screen.
  • sv_text never admitted a line on a live screen (blocking, #3) — stability used to be judged on the whole band concatenation: one changed character anywhere (blinking caret, clock, one scrolling log line, a streaming reply) replaced the pending entry and reset the 1.2 s timer, so written stayed at 0 forever. Admission is now per line: each line is matched against the previous scan independently, so one moving line no longer blocks the rest of its band. Lines that disappear are kept for a short TTL (so a missed OCR beat doesn't restart the clock), the same line recognised in two overlapping bands is written once, and duplicates only bump lastSeen/hits as before.
  • sv_text({action:'scan', force:true}) — skip the stability gate and flush every recognised line immediately: one-shot snapshots and "is the text path alive at all" debugging. scan now also reports size, per-band lines, scannedChars/scannedLines and forced, so a zero result is distinguishable from a zero scan.
  • Fresh install could not write at all — scanText/scanFull wrote their temp PNG before the data directory was ever created, so a fresh install (no data/) failed with ENOENT on the very first scan. The directory is now created before any write.
  • SV_DATA_DIR — all data (samples/, vectors/, text.jsonl, events.jsonl, ocr.json, frames/) can live outside the package, e.g. in a host state directory, so upgrades and reinstalls don't wipe it. Default unchanged (<package>/data).

What's new in 0.2.8

  • Non-ASCII install paths fixed (blocking) — lib/pipeline.js computed ROOT from new URL(import.meta.url).pathname, which keeps percent-encoding: with a Chinese (or any non-ASCII) Windows user name, data/samples could not be created and sv_arm reported armed: true while events.jsonl never appeared. It now uses fileURLToPath, like the other three modules.
  • Failures are no longer silent — sampling and event-append exceptions are recorded in ARMED.lastError and exposed by sv_info / sv_arm({action:'status'}); 10 consecutive failures stop the watcher with stopReason: "error". sv_events now tells the three empty cases apart: not armed / armed but nothing changed / last arm failed.
  • Local-change detector — besides the whole-frame HSV score (diluted on chat/document screens) and the busiest 8×6 block, an area criterion counts the share of pixels that changed noticeably. Default areaCut: 0.004 (0.4%): a one-line document edit is ~0.4%–1%, a static screen is <0.1%, a full-screen animation is tens of percent. Events now carry local and area.

What's new in 0.2.7

  • Event stream — each event now carries edgeDensity (share of blocks with a strong neighbour contrast: <10 empty, 10–25 normal, >25 busy) next to strength, where, scene and sample. 32×18 grid, svg capped at 2400 chars with the sample path kept for the full text.
  • Reading is lossless — sv_events returns the oldest unread events, reports pending/truncated and the next id; a high-water mark in data/events.seq survives daemon restarts, so a stale sinceId is clamped and flagged (staleSince) instead of silently skipping events.
  • Text stream — three overlapping bands (0–38% / 32–72% / 66–100%), 2× / 2× / 3×, three parallel OCR passes (1.2 s for a full pass). A line only enters the stream after being recognised twice ≥1.2 s apart with bigram similarity ≥0.85; the earlier version is kept. Unstable text never pollutes the stream.
  • Pluggable OCR — lib/ocr.js resolves an engine in this order: data/ocr.json ({cmd,args,timeoutMs}, placeholders {file}/{scale}/{top}/{bottom}) → SV_OCR_CMD env → registerOcrHook() → Windows OCR fallback. Anything that prints {"text": ...} or plain text works.
  • Bounded disk — the sample pool keeps the last 3 minutes by age (SV_KEEP_MS, default 180000, hard cap 3000), pruning the png/svg/json of a timestamp as one unit.

What it does

  • Continuous capture — BitBlt + nearest-neighbour downscale, ~45–65 ms per 720p frame.
  • Block differencing — 32×18 blocks, mean absolute difference; reports which blocks moved and how much.
  • Gated events — a still screen produces no events at all.
  • Scene segmentation / peaks — activity runs split into scenes; peaks keeps the N most-changed moments.
  • Working memory — three capacity-limited layers (sink / ring / text).

Motion events land in data/events.jsonl, recognised text in data/text.jsonl; the two loops are independent, so captioning never blocks the motion channel.

Tools

toolpurpose
sv_watchsample for N seconds, return a change timeline (optionally dump frames)
sv_frameexport a raw frame (the SVG conversion loses detail)
sv_scenessample for N seconds, cut activity into scenes or peaks, update working memory
sv_memoryread / append / clear the working-memory layers
sv_eventsread the motion event queue; wait long-polls and returns the moment a new event lands
sv_texttext stream: scan runs one band-split OCR pass (force:true skips the 2-scan gate); a line enters only after being seen twice; read long-polls
sv_armarm an in-process watcher that appends events to data/events.jsonl
sv_blocksread the newest SVG conversion (or sample one more with mode:"live")
sv_infoscreen size, armed state, frame-file accounting

Watching without being woken up

sv_arm does not push messages into the conversation. It samples at fps and appends one compact event per meaningful change; you read the stream with a long-poll:

sv_arm({ action: 'on', window: 'Game', fps: 2, cutAbs: 12, cooldownMs: 3000, idleExit: 900 })
sv_events({ wait: 60, sinceId: lastId })   // returns as soon as something lands
// → handle it, then loop again; sv_arm({ action: 'off' }) when done

Long-poll instead of injecting a message per event: an injected message starts a new turn, and a new turn means re-reading the context — slower and far more expensive than staying in the same turn.

Detector sensitivity

Three criteria are OR-ed; an event fires if any of them passes:

parameterdefaultcatches
cutAbs12whole-frame change — scene cuts, scrolling, video motion
localCut12one 8×6 block changing a lot (a small dialog, a HUD element)
areaCut0.004share of pixels changed noticeably — a one-line edit in a document or chat

Tuning: static screens that never fire → lower areaCut to 0.002. Too many events on a busy screen → raise areaCut toward 0.02. Noisy video that fires constantly → areaCut: 0.03, cutAbs: 20, and a longer cooldownMs. If you want the old block-mean behaviour instead, pass score: 'blocks', threshold: 4. Events echo all three numbers (score, local, area in percent), so you can tune from the stream itself instead of guessing.

Daemon

sv_daemon.mjs runs the same pipeline outside the agent loop:

node sv_daemon.mjs --window "<window title>" --seconds 60 --fps 8 --captions --captionMs 1500

Install

# inside your DSH profile directory
npm install link:/path/to/dsh-streamvision

Add dsh-streamvision to your profile's dsh.profile.bundles, then restart DSH (plugins are not hot-reloaded).

Notes

  • Windows only (Win32 GDI + Windows.Media.Ocr).
  • Text stream accuracy: the bundled Windows OCR is stable but not accurate for Chinese — a line is only admitted after being seen twice, so a consistently misread line still enters the stream ("安装" → "女装", "目录" → "d i rectO"). Treat sv_text as a hint, not as the source of truth, and prefer picture reads (sv_frame / sv_blocks) when the exact wording matters. For better Chinese, plug a real engine through SV_OCR_CMD / data/ocr.json (PaddleOCR, RapidOCR, PP-OCR).
  • The process must be DPI-aware; the plugin calls SetProcessDpiAwarenessContext(PER_MONITOR_AWARE_V2) on load.
  • Capture reads screen pixels: a window that is not in front gets whatever covers it.
  • Sampling only. Input and window control deliberately live elsewhere.

License

MIT

Related plugins