@tmhs/screencast-mcp 0.54.0 → 0.55.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,16 +1,19 @@
1
- import{spawn as S}from"node:child_process";import{existsSync as H,rmSync as P}from"node:fs";var u=class extends Error{hint;constructor(e,n){super(e),this.name="ScreencastError",this.hint=n}};function _(t){return!t||t.device.trim().length===0?[]:["-f","dshow","-i",`audio=${t.device}`]}var j="160k";function C(t=j){return["-c:a","aac",...t?["-b:a",t]:[]]}var tt=168*3600;function I(t,e,n=!0){if(!Number.isSafeInteger(t)||t<=0)throw new u("Invalid window handle.");return["-hide_banner","-nostats","-loglevel","info","-f","lavfi","-i",`gfxcapture=hwnd=${t}:max_framerate=${e}${n?"":":capture_cursor=0"},hwdownload,format=bgra,crop=trunc(iw/2)*2:trunc(ih/2)*2,format=yuv420p`,"-flush_packets","1","-f","rawvideo","-"]}function R(t){let e=t.indexOf("Output #0");if(e<0)return null;let n=/Video: rawvideo[^\n]*?, (\d{2,5})x(\d{2,5})/.exec(t.slice(e));return n?{width:Number(n[1]),height:Number(n[2])}:null}function T(t,e){return t*e*3/2}var g=class{parts=[];length=0;frameBytes=0;push(e){e.length&&(this.parts.push(e),this.length+=e.length)}get buffered(){return this.length}take(){let e=this.frameBytes;if(e<=0||this.length<e)return null;let n=Math.floor(this.length/e),w=this.parts.length===1&&this.parts[0]?this.parts[0]:Buffer.concat(this.parts,this.length),c=n*e,U=w.subarray(c-e,c),E=this.length-c;return this.parts=E?[Buffer.from(w.subarray(c))]:[],this.length=E,U}};function M(t,e,n){return["-hide_banner","-nostats","-loglevel","error","-y","-f","rawvideo","-pix_fmt","yuv420p","-s",`${t}x${e}`,"-framerate",String(n.fps),"-i","pipe:0",...n.audioDevice?[..._({device:n.audioDevice}),"-map","0:v","-map","1:a"]:[],...n.encode,...n.audioDevice?[...C(),"-shortest"]:[],"-movflags","+frag_keyframe+empty_moov+default_base_moof",n.output]}function O(t,e){return Math.floor(t*e/1e3)+1}var k=3;function N(t){return`${t}.stop`}function D(t){return`Input #0, wgc, from 'window':
1
+ import{spawn as $}from"node:child_process";import{existsSync as q,rmSync as z}from"node:fs";var u=class extends Error{hint;constructor(e,r){super(e),this.name="ScreencastError",this.hint=r}};var j="160k";function x(t=j){return["-c:a","aac",...t?["-b:a",t]:[]]}function R(t){return!t||t.device.trim().length===0?[]:["-f","dshow","-i",`audio=${t.device}`]}var st=168*3600;function T(t,e,r=!0){if(!Number.isSafeInteger(t)||t<=0)throw new u("Invalid window handle.");return["-hide_banner","-nostats","-loglevel","info","-f","lavfi","-i",`gfxcapture=hwnd=${t}:max_framerate=${e}${r?"":":capture_cursor=0"},hwdownload,format=bgra,crop=trunc(iw/2)*2:trunc(ih/2)*2,format=yuv420p`,"-flush_packets","1","-f","rawvideo","-"]}function M(t){let e=t.indexOf("Output #0");if(e<0)return null;let r=/Video: rawvideo[^\n]*?, (\d{2,5})x(\d{2,5})/.exec(t.slice(e));return r?{width:Number(r[1]),height:Number(r[2])}:null}function O(t,e){return t*e*3/2}var m=class{parts=[];length=0;frameBytes=0;push(e){e.length&&(this.parts.push(e),this.length+=e.length)}get buffered(){return this.length}take(){let e=this.frameBytes;if(e<=0||this.length<e)return null;let r=Math.floor(this.length/e),g=this.parts.length===1&&this.parts[0]?this.parts[0]:Buffer.concat(this.parts,this.length),c=r*e,_=g.subarray(c-e,c),C=this.length-c;return this.parts=C?[Buffer.from(g.subarray(c))]:[],this.length=C,_}};function N(t,e,r){return["-hide_banner","-nostats","-loglevel","error","-y","-f","rawvideo","-pix_fmt","yuv420p","-s",`${t}x${e}`,"-framerate",String(r.fps),"-i","pipe:0",...r.audioDevice?[...R({device:r.audioDevice}),"-map","0:v","-map","1:a"]:[],...r.encode,...r.audioDevice?[...x(),"-shortest"]:[],"-movflags","+frag_keyframe+empty_moov+default_base_moof",r.output]}function k(t,e){return Math.floor(t*e/1e3)+1}var D=3;function W(t){return`${t}.stop`}function P(t){return`Input #0, wgc, from 'window':
2
2
  Duration: N/A, start: ${(t/1e3).toFixed(6)}, bitrate: N/A
3
- `}function W(t,e,n){return`Add-Type @"
3
+ `}var B="wgc: restored minimized window",H=t=>`if([ScNudge]::IsIconic([IntPtr]${t})){[void][ScNudge]::ShowWindow([IntPtr]${t},4);[void][ScNudge]::SetWindowPos([IntPtr]${t},[IntPtr]1,0,0,0,0,0x13);'restored'};`;function L(t,e,r,g=!1){return`Add-Type @"
4
4
  using System;using System.Runtime.InteropServices;
5
5
  public class ScNudge{
6
6
  [StructLayout(LayoutKind.Sequential)] public struct RECT{public int L,T,R,B;}
7
7
  [DllImport("user32.dll")] public static extern bool RedrawWindow(IntPtr h,ref RECT r,IntPtr g,uint f);
8
8
  [DllImport("user32.dll")] public static extern bool IsWindow(IntPtr h);
9
+ [DllImport("user32.dll")] public static extern bool IsIconic(IntPtr h);
10
+ [DllImport("user32.dll")] public static extern bool ShowWindow(IntPtr h,int c);
11
+ [DllImport("user32.dll")] public static extern bool SetWindowPos(IntPtr h,IntPtr a,int x,int y,int cx,int cy,uint f);
9
12
  }
10
13
  "@
11
14
  $r=New-Object ScNudge+RECT;$r.R=1;$r.B=1
12
- ${n?`$p=Get-Process -Id ${n} -ErrorAction SilentlyContinue
13
- `:""}while([ScNudge]::IsWindow([IntPtr]${t})${n?" -and $p -and !$p.HasExited":""}){[void][ScNudge]::RedrawWindow([IntPtr]${t},[ref]$r,[IntPtr]::Zero,0x0105);Start-Sleep -Milliseconds ${e}}`}var Q=4,r=JSON.parse(process.argv[2]??"{}"),B=r.firstFrameTimeoutMs??1e4,s=t=>process.stderr.write(t.endsWith(`
15
+ ${r?`$p=Get-Process -Id ${r} -ErrorAction SilentlyContinue
16
+ `:""}while([ScNudge]::IsWindow([IntPtr]${t})${r?" -and $p -and !$p.HasExited":""}){${g?H(t):""}[void][ScNudge]::RedrawWindow([IntPtr]${t},[ref]$r,[IntPtr]::Zero,0x0105);Start-Sleep -Milliseconds ${e}}`}var X=4,n=JSON.parse(process.argv[2]??"{}"),F=n.firstFrameTimeoutMs??1e4,s=t=>process.stderr.write(t.endsWith(`
14
17
  `)?t:`${t}
15
- `),d=S(r.ffmpeg,I(r.hwnd,r.fps,r.cursor!==!1),{stdio:["ignore","pipe","pipe"],windowsHide:!0}),F=S("powershell",["-NoProfile","-NonInteractive","-Command",W(r.hwnd,200,process.pid)],{stdio:"ignore",windowsHide:!0}),m="",o=null,y=0,$=new g,h=null,i=null,x=0,b=0,v=null,a=!1,L=!1,A=N(r.output);function l(t){if(t&&t.exitCode===null&&t.signalCode===null)try{t.kill()}catch{}}function f(t){l(F),l(d),l(i),P(A,{force:!0}),process.exit(t)}function z(){if(!o||a)return;let t=$.take();t&&(h=t),h&&!i&&q()}d.stderr.on("data",t=>{o||(m=(m+t.toString()).slice(-8e3),o=R(m),o&&(y=T(o.width,o.height),$.frameBytes=y,z()))});d.stdout.on("data",t=>{$.push(t),z()});function q(){i=S(r.ffmpeg,M(o.width,o.height,r),{stdio:["pipe","ignore","pipe"],windowsHide:!0}),i.stderr?.on("data",e=>s(e.toString())),i.on("exit",e=>f(e===0&&L?k:e??1)),i.stdin?.on("error",()=>{}),x=Date.now(),s(D(x)),s(`wgc: ${o.width}x${o.height} at ${r.fps} fps`);let t=()=>{let e=O(Date.now()-x,r.fps);for(;b<e&&h&&i?.stdin?.writable;){if((i.stdin.writableLength??0)>Q*y){b=e;break}i.stdin.write(h),b++}};t(),v=setInterval(t,Math.max(5,Math.floor(1e3/r.fps/2))),r.maxDurationSec>0&&G(r.maxDurationSec*1e3)}function G(t){let e=Math.min(t,2147483647);setTimeout(()=>t>e?G(t-e):p(),e)}function p(){a||(a=!0,v&&clearInterval(v),l(F),l(d),i||(s("wgc: no frame was captured from the window"),f(1)),i.stdin?.end())}d.on("exit",()=>{a||(i||(s(`wgc: capture failed: ${m.split(`
16
- `).filter(t=>/error|fail|invalid/i.test(t)).slice(-3).join(" ")||"gfxcapture exited"}`),f(1)),s("wgc: the window closed; recording ended"),L=!0,p())});setTimeout(()=>{!i&&!a&&(s(`wgc: the window produced no frame in ${B/1e3}s`),a=!0,f(1))},B);P(A,{force:!0});setInterval(()=>{H(A)&&p()},250).unref();for(let t of["SIGINT","SIGTERM"])process.on(t,()=>f(1));process.stdin.on("data",t=>{t.toString().includes("q")&&p()});process.stdin.on("end",p);
18
+ `),d=$(n.ffmpeg,T(n.hwnd,n.fps,n.cursor!==!1),{stdio:["ignore","pipe","pipe"],windowsHide:!0}),E=$("powershell",["-NoProfile","-NonInteractive","-Command",L(n.hwnd,200,process.pid,!0)],{stdio:["ignore","pipe","ignore"],windowsHide:!0});E.stdout?.on("data",t=>{/restored/.test(t.toString())&&s(B)});var w="",o=null,S=0,I=new m,h=null,i=null,b=0,y=0,v=null,a=!1,G=!1,A=W(n.output);function l(t){if(t&&t.exitCode===null&&t.signalCode===null)try{t.kill()}catch{}}function f(t){l(E),l(d),l(i),z(A,{force:!0}),process.exit(t)}function U(){if(!o||a)return;let t=I.take();t&&(h=t),h&&!i&&J()}d.stderr.on("data",t=>{o||(w=(w+t.toString()).slice(-8e3),o=M(w),o&&(S=O(o.width,o.height),I.frameBytes=S,U()))});d.stdout.on("data",t=>{I.push(t),U()});function J(){i=$(n.ffmpeg,N(o.width,o.height,n),{stdio:["pipe","ignore","pipe"],windowsHide:!0}),i.stderr?.on("data",e=>s(e.toString())),i.on("exit",e=>f(e===0&&G?D:e??1)),i.stdin?.on("error",()=>{}),b=Date.now(),s(P(b)),s(`wgc: ${o.width}x${o.height} at ${n.fps} fps`);let t=()=>{let e=k(Date.now()-b,n.fps);for(;y<e&&h&&i?.stdin?.writable;){if((i.stdin.writableLength??0)>X*S){y=e;break}i.stdin.write(h),y++}};t(),v=setInterval(t,Math.max(5,Math.floor(1e3/n.fps/2))),n.maxDurationSec>0&&Q(n.maxDurationSec*1e3)}function Q(t){let e=Math.min(t,2147483647);setTimeout(()=>t>e?Q(t-e):p(),e)}function p(){a||(a=!0,v&&clearInterval(v),l(E),l(d),i||(s("wgc: no frame was captured from the window"),f(1)),i.stdin?.end())}d.on("exit",()=>{a||(i||(s(`wgc: capture failed: ${w.split(`
19
+ `).filter(t=>/error|fail|invalid/i.test(t)).slice(-3).join(" ")||"gfxcapture exited"}`),f(1)),s("wgc: the window closed; recording ended"),G=!0,p())});setTimeout(()=>{!i&&!a&&(s(`wgc: the window produced no frame in ${F/1e3}s`),a=!0,f(1))},F);z(A,{force:!0});setInterval(()=>{q(A)&&p()},250).unref();for(let t of["SIGINT","SIGTERM"])process.on(t,()=>f(1));process.stdin.on("data",t=>{t.toString().includes("q")&&p()});process.stdin.on("end",p);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tmhs/screencast-mcp",
3
- "version": "0.54.0",
3
+ "version": "0.55.0",
4
4
  "description": "Let AI agents record the Windows screen, watch it as frames, and edit it with ffmpeg",
5
5
  "mcpName": "io.github.TMHSDigital/screencast-mcp",
6
6
  "type": "module",