feat(m0): check a virtual monitor for the bot browser window
The user wants the bot window on no real screen at all. Add a vdisplay stage that drives the Parsec Virtual Display Adapter already on the PC (no install, the display dies with the script), moves the clock window onto it as a normal and as a tool window, and asks about real monitors, Alt+Tab, Discord's Screens tab and whether the cursor can wander there. Record the M0 defaults the user confirmed in docs/v2. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -14,13 +14,24 @@
|
||||
| 동시 대화 응답 정책 기본값 | 처음 대화만 |
|
||||
| "제일 중요한 대화" 판단 기준 | 사람별 우선순위 → 호출어로 직접 불렀는지 → LLM이 판단한 중요도 |
|
||||
| 대화 기억 범위 기본값 | 본인 기록 + 등록한 채팅 채널 + 같은 음성 채널에 함께 있던 다른 사람 말. 채팅 채널과 다른 사람 말은 각각 켜기/끄기, 기본은 둘 다 켜짐 ([memory.md](memory.md)) |
|
||||
| 가상 디스플레이 드라이버 | 필요해지면 설치. 설치 때 관리자 권한 1회 |
|
||||
| 가상 디스플레이 드라이버 | 필요해지면 설치. 설치 때 관리자 권한 1회. 게임PC에는 Parsec 가상 디스플레이 드라이버가 이미 있어 먼저 그것으로 확인 |
|
||||
| 게임 모드 | 테두리 없는 창 게임도 감지. (a) RAM 위주로 / (b) 빠름 모델로 / (c) 일시정지 각각 켜기/끄기, 기본은 (a)만 ([pc-features.md](pc-features.md#게임-모드)) |
|
||||
| 안티치트 | 안티치트 게임 실행 중에는 키보드·마우스 제어를 막고 안티치트 이름으로 안내 |
|
||||
| 다른 사람 화면공유 보기 | 자비스가 말로 창 분리(팝아웃)를 요청하고 분리된 창만 캡처. 디스코드 앱을 직접 조작하지 않음 ([pc-features.md](pc-features.md#다른-사람의-디스코드-화면공유-보기-창-분리-방식)) |
|
||||
| AI 채팅 채널 | GUI에서 채널 ID·이름·설명 편집, AI가 읽기·보내기·수정 등 수행 ([conversation.md](conversation.md#ai-채팅-채널)) |
|
||||
| 채팅 채널 이름·설명 반영 | 실제 디스코드 채널 이름·주제까지 바꿈. "디스코드에도 반영" 켜기/끄기, 기본 켜짐 |
|
||||
|
||||
## M0 결과로 정한 기본값 (2026-11-10)
|
||||
|
||||
| 항목 | 결정 |
|
||||
|---|---|
|
||||
| TTS | MeloTTS만 기본 제공. CosyVoice2/3는 첫 소리까지 중앙값 3.4~3.6초라 뺌. 앱 시작 때 한 번 미리 합성(첫 합성 30초) |
|
||||
| STT | large-v3-turbo, `int8_float16`(1.3GB). `float16`과 정확도가 같았음 |
|
||||
| LLM | 빠름 모델(Qwen3.6-35B-A3B) 기본, 동시 요청 2개, 이미지는 GPU 처리, 화질 1280x720, 음성 답변은 생각 모드 끔. 권장 모델은 재측정 뒤 다시 판단 |
|
||||
| 지난 대화 맥락 | 약 8천 토큰에서 시작(텍스트 첫 문장 1.8초). 상한은 M4에서 왕복 지연을 실측해 정함 |
|
||||
| 게임 모드 VRAM 비우기 | Strata 0.1.59가 지원하지 않아 당분간 LLM을 껐다 켜는 방식(약 52초). 엔진이 지원하면 다시 측정 |
|
||||
| 봇용 크롬창 | 실제 모니터 어디에도 보이지 않게 가상 모니터에 둠(사용자 선택). 가능 여부는 M0 `vdisplay` 단계로 확인 중 ([pc-features.md](pc-features.md#봇용-크롬창과-디스코드-화면공유)) |
|
||||
|
||||
## 확인이 필요한 질문
|
||||
|
||||
지금은 없습니다.
|
||||
|
||||
@@ -102,16 +102,20 @@
|
||||
셀프봇 Go Live 송출은 v2에서 뺍니다. 대신 봇이 쓰는 크롬창을 사용자가 디스코드 앱에서 직접 화면공유할 수 있게 합니다.
|
||||
|
||||
- **GUI 설정 "봇용 크롬창 화면공유 선택 표시"**:
|
||||
- 켜짐: 봇용 크롬창이 디스코드 "화면 공유 → 창" 목록에 "Jarvis 브라우저"로 나타납니다.
|
||||
- 켜짐: 봇용 크롬창이 있는 가상 모니터가 디스코드 "화면 공유 → 화면" 탭에 나타납니다(아래 가상 모니터 방식).
|
||||
- 꺼짐(기본): 봇용 크롬창은 화면 없이(백그라운드) 돌고, 디스코드 목록에도 나오지 않습니다.
|
||||
- **Alt+Tab, Win+Tab, 작업 표시줄에는 항상 안 보입니다.** 켜짐 상태에서도 창을 "도구 창" 속성으로 바꿔 창 전환 목록에서 빼고, 다른 창들 뒤(맨 아래)에 둡니다.
|
||||
- 크롬은 가려진 창의 그리기를 멈추는 기능이 있습니다. 봇용 크롬은 이 기능을 끄고 실행해서, 다른 창 뒤에 있어도 화면공유 영상이 멈추지 않게 합니다.
|
||||
|
||||
**먼저 확인할 점**: 디스코드가 화면공유 목록을 Alt+Tab과 같은 기준으로 거르면, 도구 창 속성 때문에 목록에서도 빠질 수 있습니다. M0 확인 스크립트에서 가장 먼저 봅니다.
|
||||
|
||||
**안 될 때 예비안**: 가상 모니터를 하나 만들고 봇용 크롬을 그 모니터에 둡니다.
|
||||
**M0 결과**: 도구 창으로 바꾸면 디스코드 "창" 목록에서도 빠졌습니다. 그래서 아래 가상 모니터 방식으로 갑니다(사용자 선택: 두 번째 모니터에도 보이지 않게).
|
||||
|
||||
- 가상 디스플레이 드라이버를 씁니다. 설치 때 관리자 권한을 한 번 묻습니다(설치 승인받음).
|
||||
**가상 모니터 방식**: 가상 모니터를 하나 만들고 봇용 크롬을 그 모니터에 둡니다.
|
||||
|
||||
- 가상 디스플레이 드라이버를 씁니다. 설치 때 관리자 권한을 한 번 묻습니다(설치 승인받음). 게임PC에 이미 있는 Parsec 가상 디스플레이로 먼저 확인합니다(M0 `vdisplay` 단계).
|
||||
- Parsec 드라이버의 가상 모니터는 앱이 0.1초 안쪽 간격으로 신호를 보내는 동안만 살아 있습니다. 앱이 꺼지면 모니터도 사라지고, 그 위의 창은 실제 모니터로 옮겨집니다. 그래서 앱은 꺼질 때 봇용 크롬을 먼저 닫아야 합니다.
|
||||
- 마우스가 가상 모니터로 넘어가지 않도록, 실제 모니터와 구석 한 점만 닿게 배치합니다.
|
||||
- 디스코드에서는 "화면" 탭에서 그 가상 모니터를 고릅니다.
|
||||
- Alt+Tab에서는 그대로 빠지고, 실제 모니터에도 보이지 않습니다.
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ M0~M4는 "더 빠르고 똑똑한 음성 대화"의 핵심이고, M5~M8은 "설
|
||||
| 서명 안 된 exe라 SmartScreen 경고 | 처음에는 "추가 정보 → 실행"으로 안내. 필요하면 코드 서명 인증서 구매 검토(유료) |
|
||||
| 디스코드 음성 암호화(DAVE) 변경 | v1에서 쓰는 `@snazzah/davey` 기반 유지, 라이브러리 업데이트 추적 |
|
||||
| 모델 다운로드가 수십 GB | 이어받기, 해시 검증, 진행률 표시. 빠름 모델 먼저 받고 권장 모델은 나중에 받기 가능 |
|
||||
| CosyVoice2 한국어 품질·속도 미검증 | M0에서 측정. 기준 미달이면 MeloTTS만 기본 제공 |
|
||||
| CosyVoice2 한국어 품질·속도 미검증 | M0에서 측정 결과 기준 미달. MeloTTS만 기본 제공 |
|
||||
| 디스코드 화면공유 목록이 Alt+Tab에서 숨긴 창도 빼 버림 | M0에서 확인. 안 되면 가상 모니터 예비안(드라이버 설치 승인받음) |
|
||||
| 지난 대화를 많이 넣을수록 첫 소리가 늦어짐 | 관련 부분만 검색해 넣고 분량 상한을 둠. GUI에 예상 지연 표시 |
|
||||
| 일부 화면이 검게 캡처됨 (보호 영상, 독점 전체화면 게임) | 테두리 없는 창 모드 안내. 캡처 실패 시 자비스가 "그 화면은 볼 수 없다"고 그대로 말함 |
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
## TTS
|
||||
|
||||
- Piper는 공식 한국어 음성이 없습니다(비공식 KSS 모델만 있음). 그래서 기본값은 v1에서 쓰고 있고 한국어가 검증된 **MeloTTS**입니다.
|
||||
- 고품질 옵션으로 CosyVoice2(한국어 지원, 목소리 복제 가능)를 넣고, M0에서 속도와 품질을 비교해 기본값을 정합니다.
|
||||
- CosyVoice2/3도 M0에서 쟀지만 스트리밍으로도 첫 소리까지 중앙값 3.4~3.6초가 걸려 넣지 않습니다. MeloTTS는 92자 문장을 0.5초에 만듭니다([decisions.md](decisions.md#m0-결과로-정한-기본값-2026-11-10)).
|
||||
- LLM 답변을 문장 단위로 끊어 첫 문장부터 바로 읽습니다.
|
||||
|
||||
## 목표 지연 시간 (말이 끝난 뒤 첫 소리까지)
|
||||
|
||||
@@ -21,6 +21,7 @@ LLM 단계는 8080 포트를 씁니다. 다른 프로그램이 이 포트를 쓰
|
||||
| 확인 | 하실 일 |
|
||||
|---|---|
|
||||
| 봇용 창 숨김 | 시계가 움직이는 테스트 창이 뜹니다. Alt+Tab, 작업 표시줄, 디스코드 "화면 공유 → 창" 목록에 보이는지 답합니다. |
|
||||
| 가상 모니터 | 이미 설치된 Parsec 가상 디스플레이로 모니터를 잠시 하나 만들고 시계 창을 그리로 옮깁니다. 실제 모니터와 Alt+Tab에 보이는지, 디스코드 "화면 공유 → 화면" 탭에 그 모니터가 나오는지, 마우스가 그쪽으로 넘어가는지 답합니다. 끝나면 가상 모니터는 사라지고 아무것도 설치하지 않습니다. |
|
||||
| 디스코드 창 분리 | 친구(또는 다른 기기의 내 계정)의 화면공유를 시청하고 "창 분리(팝아웃)"를 누릅니다. 지금 할 수 없으면 `s`로 건너뜁니다. |
|
||||
| 게임 감지 | 게임을 하나 켜고(테두리 없는 창 모드면 가장 좋음), 안티치트 게임이 있으면 그것도 켭니다. 마지막으로 브라우저 영상을 전체화면으로 틉니다. 각각 Enter 후 15초 안에 그 화면으로 바꾸면 됩니다. |
|
||||
|
||||
@@ -50,6 +51,6 @@ LLM 단계는 8080 포트를 씁니다. 다른 프로그램이 이 포트를 쓰
|
||||
.\run_m0.ps1 -Only stt,tts_melo -Redo # 특정 단계만 다시
|
||||
```
|
||||
|
||||
단계 이름: `sysinfo`, `winchecks`, `tts_melo`, `tts_cosy2`, `tts_cosy3`, `stt`, `llm_fast`, `llm_recommended`
|
||||
단계 이름: `sysinfo`, `winchecks`, `vdisplay`, `tts_melo`, `tts_cosy2`, `tts_cosy3`, `stt`, `llm_fast`, `llm_recommended`
|
||||
|
||||
다 끝나고 필요 없으면 작업 폴더(`\JarvisM0`)를 통째로 지우면 됩니다. Python, 모델, Strata(엔진과 설정 포함)는 모두 그 안에 설치하도록 지정해 두었습니다.
|
||||
|
||||
@@ -28,6 +28,7 @@ from m0lib.common import read_json, say, step, write_json # noqa: E402
|
||||
STAGES = [
|
||||
("sysinfo", "PC 정보", "", "sysinfo.py", [], 0),
|
||||
("winchecks", "창·디스코드·게임 확인 (직접 답해 주셔야 합니다)", "", "winchecks.py", [], 0),
|
||||
("vdisplay", "가상 모니터에 봇용 창 두기 (직접 답해 주셔야 합니다)", "", "vdisplay.py", [], 0),
|
||||
("tts_melo", "MeloTTS 속도", "melo", "tts_melo.py", [], 10),
|
||||
("tts_cosy2", "CosyVoice2 속도", "cosy", "tts_cosy.py", ["models=cosyvoice2"], 15),
|
||||
("tts_cosy3", "Fun-CosyVoice3 속도", "cosy", "tts_cosy.py", ["models=cosyvoice3"], 8),
|
||||
@@ -114,7 +115,7 @@ def main() -> int:
|
||||
say("Jarvis v2 M0 측정을 시작합니다.")
|
||||
say(f"작업 폴더: {work} (남은 공간 {free_gb(work):.0f} GB)")
|
||||
say("모든 파일은 이 작업 폴더 안에만 받습니다. 끝나면 결과 zip 파일 위치를 알려 드립니다.")
|
||||
say("처음 두 단계는 직접 답해 주셔야 하고, 그 뒤는 자리를 비우셔도 됩니다.")
|
||||
say("앞쪽의 '직접 답해 주셔야 합니다' 단계가 끝나면 자리를 비우셔도 됩니다.")
|
||||
say("측정이 정확하도록 그동안 게임이나 무거운 프로그램은 꺼 두세요.\n")
|
||||
|
||||
t0 = time.time()
|
||||
@@ -141,7 +142,7 @@ def main() -> int:
|
||||
except Exception as e:
|
||||
say(f" [오류] {title}: {e}")
|
||||
write_json(out, {"stage": key, "status": "failed", "errors": [{"where": "setup", "error": str(e)}]})
|
||||
if key == "winchecks":
|
||||
if key == "vdisplay":
|
||||
say("\n직접 확인하는 단계는 끝났습니다. 이제 자리를 비우셔도 됩니다.")
|
||||
|
||||
target = pack(work)
|
||||
|
||||
206
scripts/m0/m0lib/vdisplay.py
Normal file
206
scripts/m0/m0lib/vdisplay.py
Normal file
@@ -0,0 +1,206 @@
|
||||
"""Stage: a virtual monitor for the bot browser window (needs the user at the PC).
|
||||
|
||||
The plan's fallback (docs/v2/pc-features.md, "봇용 크롬창과 디스코드 화면공유"):
|
||||
the bot window lives on a virtual monitor as a tool window, so it is on no
|
||||
real screen and not in Alt+Tab, and Discord shares it through the "Screens"
|
||||
tab. This stage checks each part on the PC with the Parsec Virtual Display
|
||||
Adapter that is already installed there:
|
||||
|
||||
driver can the kit open the driver and add a display without admin rights
|
||||
window the bot window moved onto that display, normal and as a tool window
|
||||
discord the display in Discord's "Screens" tab, and the shared preview moving
|
||||
mouse whether the cursor can wander onto the display
|
||||
cleanup the display goes away again, and where the window ends up
|
||||
|
||||
The display only lives while this script pings the driver, so it disappears by
|
||||
itself if the script stops. Nothing is installed and nothing is kept.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
||||
from m0lib.common import IS_WINDOWS, StageResult, ask, say, stage_args, step, wait_enter # noqa: E402
|
||||
from m0lib.winchecks import TEST_TITLE, find_browser, frames, html_page # noqa: E402
|
||||
|
||||
|
||||
SWP_NOZORDER = 0x0004
|
||||
|
||||
|
||||
def _inside(pt: tuple[int, int], rect: list[int]) -> bool:
|
||||
return rect[0] <= pt[0] < rect[2] and rect[1] <= pt[1] < rect[3]
|
||||
|
||||
|
||||
def watch_cursor(w, rect: list[int], seconds: float) -> dict:
|
||||
import ctypes
|
||||
from ctypes import wintypes
|
||||
p = wintypes.POINT()
|
||||
hits, samples = 0, 0
|
||||
end = time.time() + seconds
|
||||
while time.time() < end:
|
||||
w.user32.GetCursorPos(ctypes.byref(p))
|
||||
samples += 1
|
||||
hits += int(_inside((p.x, p.y), rect))
|
||||
time.sleep(0.02)
|
||||
return {"samples": samples, "inside_virtual": hits}
|
||||
|
||||
|
||||
def open_bot_window(work: Path):
|
||||
from m0lib import winwin as w
|
||||
browser = find_browser()
|
||||
if not browser:
|
||||
return None, None, None
|
||||
page = html_page(work / "m0_clock.html")
|
||||
profile = work / "browser_vdisplay_profile"
|
||||
proc = subprocess.Popen([browser, f"--user-data-dir={profile}", "--no-first-run", "--no-default-browser-check",
|
||||
"--disable-backgrounding-occluded-windows", "--disable-renderer-backgrounding",
|
||||
"--disable-background-timer-throttling", "--window-size=900,600",
|
||||
"--window-position=200,200", f"--app={page.as_uri()}"])
|
||||
for _ in range(60):
|
||||
time.sleep(0.5)
|
||||
for win in w.top_windows():
|
||||
if TEST_TITLE in win["title"] and win["class"].startswith("Chrome_WidgetWin"):
|
||||
return proc, profile, win["hwnd"]
|
||||
return proc, profile, None
|
||||
|
||||
|
||||
def run(r: StageResult, work: Path) -> None:
|
||||
from m0lib import winvdd as v
|
||||
from m0lib import winwin as w
|
||||
res: dict = {}
|
||||
r["vdisplay"] = res
|
||||
before = v.displays()
|
||||
res["displays_before"] = [{k: d[k] for k in ("adapter", "rect", "primary", "virtual")} for d in before]
|
||||
res["parsec_app_running"] = "parsecd.exe" in set(w.processes().values())
|
||||
|
||||
step("1/5 가상 모니터 드라이버 열기")
|
||||
try:
|
||||
vdd = v.Vdd()
|
||||
except OSError as e:
|
||||
r.error("driver_open", e)
|
||||
res["driver_open"] = False
|
||||
say(f" 드라이버를 열지 못했습니다: {e}")
|
||||
return
|
||||
res["driver_open"] = True
|
||||
proc = profile = None
|
||||
try:
|
||||
res["driver_minor_version"] = vdd.version()
|
||||
step("2/5 가상 모니터 추가")
|
||||
say(" 잠시 뒤 가상 모니터가 하나 생깁니다. 실제 모니터가 잠깐 깜빡일 수 있습니다.")
|
||||
t0 = time.perf_counter()
|
||||
idx = vdd.add()
|
||||
res["add_index"] = idx
|
||||
after = v.wait_for_displays(lambda cur: sum(d["virtual"] for d in cur) > sum(d["virtual"] for d in before))
|
||||
res["add_seconds"] = round(time.perf_counter() - t0, 2)
|
||||
new = [d for d in after if d["virtual"] and d["device"] not in {b["device"] for b in before}]
|
||||
if idx < 0 or not new:
|
||||
r.error("add", f"가상 모니터가 생기지 않았습니다 (index {idx})")
|
||||
return
|
||||
virt = new[0]
|
||||
res["virtual_default"] = {"rect": virt["rect"], "hz": virt["hz"]}
|
||||
say(f" 생겼습니다: {virt['rect'][2] - virt['rect'][0]}x{virt['rect'][3] - virt['rect'][1]}, "
|
||||
f"{res['add_seconds']}초 걸림")
|
||||
res["flicker_on_add"] = ask(" 가상 모니터가 생길 때 실제 모니터가 깜빡이거나 열린 창 위치가 바뀌었나요?", "yn")
|
||||
|
||||
physical = [d for d in after if not d["virtual"]]
|
||||
x, y = v.corner_position(physical)
|
||||
res["move_target"] = [x, y]
|
||||
res["move_result"] = v.move_display(virt["device"], x, y)
|
||||
time.sleep(1.5)
|
||||
virt = next((d for d in v.displays() if d["device"] == virt["device"]), virt)
|
||||
res["virtual_rect"] = virt["rect"]
|
||||
res["corner_only"] = virt["rect"][0] == x and virt["rect"][1] == y
|
||||
res["physical_rects"] = [d["rect"] for d in physical]
|
||||
|
||||
step("3/5 봇용 창을 가상 모니터로 옮기기")
|
||||
proc, profile, hwnd = open_bot_window(work)
|
||||
if not hwnd:
|
||||
r.error("window", "테스트 창을 찾지 못했습니다")
|
||||
return
|
||||
vx, vy = virt["rect"][0], virt["rect"][1]
|
||||
w.user32.SetWindowPos(hwnd, None, vx + 50, vy + 50, 900, 600, w.SWP_NOACTIVATE | SWP_NOZORDER)
|
||||
time.sleep(1)
|
||||
res["window_on_virtual"] = w.monitor_rect(hwnd) == virt["rect"]
|
||||
res["drawing_normal"] = frames(hwnd, 3)
|
||||
say(f" 옮김: {'예' if res['window_on_virtual'] else '아니요'}, "
|
||||
f"그리기 계속: {'예' if res['drawing_normal']['drawing'] else '아니요'}")
|
||||
res["seen_on_real_monitors"] = ask(f" 실제 모니터 어디에든 '{TEST_TITLE}'(시계 창)가 보이나요?", "yn", "n")
|
||||
res["alt_tab_listed_normal"] = ask(" Alt+Tab을 눌러 보세요. 목록에 이 창이 있나요?", "yn")
|
||||
|
||||
w.set_tool_window(hwnd)
|
||||
w.user32.SetWindowPos(hwnd, None, vx + 50, vy + 50, 900, 600, w.SWP_NOACTIVATE | SWP_NOZORDER)
|
||||
time.sleep(1.5)
|
||||
res["tool_window_on_virtual"] = w.monitor_rect(hwnd) == virt["rect"]
|
||||
res["drawing_tool"] = frames(hwnd, 3)
|
||||
say("\n 같은 창을 '도구 창' 속성으로 바꿨습니다 (계획에 적은 실제 사용 형태입니다).")
|
||||
res["alt_tab_hidden_tool"] = ask(" Alt+Tab을 다시 눌러 보세요. 이번에는 목록에서 빠졌나요?", "yn")
|
||||
res["taskbar_hidden_tool"] = ask(" 작업 표시줄에서도 이 창 아이콘이 없나요?", "yn")
|
||||
|
||||
step("4/5 디스코드 '화면' 탭에서 가상 모니터 공유")
|
||||
say(" 디스코드에서 '화면 공유'를 누르고 '화면'(모니터) 탭을 열어 보세요.")
|
||||
res["discord_screens_listed"] = ask(" 모니터가 하나 더(가상 모니터) 보이나요? 미리보기에 시계 창이 보이면 그것입니다. (s=디스코드 없음)",
|
||||
"yns", "s")
|
||||
if res["discord_screens_listed"] == "y":
|
||||
say(" 그 화면을 실제로 공유해 보세요 (나만 있는 채널도 괜찮습니다).")
|
||||
if wait_enter(" 공유를 시작했으면 Enter (건너뛰려면 s 입력 후 Enter):") != "s":
|
||||
res["drawing_while_shared"] = frames(hwnd, 5)
|
||||
res["discord_preview_moving"] = ask(" 디스코드 공유 미리보기에서 시계가 계속 움직이나요?", "yn")
|
||||
say(" 공유를 끝내 주세요.")
|
||||
wait_enter(" 끝냈으면 Enter:")
|
||||
|
||||
step("5/5 마우스가 가상 모니터로 넘어가는지")
|
||||
say(" 10초 동안 마우스를 모든 모니터의 가장자리와 구석, 특히 오른쪽 아래 구석으로 여러 번 밀어 보세요.")
|
||||
if wait_enter(" 준비되면 Enter (건너뛰려면 s 입력 후 Enter):") != "s":
|
||||
res["cursor"] = watch_cursor(w, virt["rect"], 10)
|
||||
say(f" 커서가 가상 모니터로 넘어간 횟수(측정 표본): {res['cursor']['inside_virtual']}")
|
||||
res["cursor_lost_user"] = ask(" 그동안 커서가 화면 밖으로 사라진 적이 있나요?", "yn")
|
||||
finally:
|
||||
def new_virtual(cur: list[dict]) -> list[dict]:
|
||||
return [d for d in cur if d["virtual"] and d["device"] not in {b["device"] for b in before}]
|
||||
|
||||
try:
|
||||
t0 = time.perf_counter()
|
||||
vdd.close()
|
||||
res["removed"] = not new_virtual(v.wait_for_displays(lambda cur: not new_virtual(cur)))
|
||||
res["remove_seconds"] = round(time.perf_counter() - t0, 2)
|
||||
except Exception as e:
|
||||
r.error("remove", e)
|
||||
if proc is not None:
|
||||
# Where Windows puts the window once its display is gone: if the app ever stops
|
||||
# without closing its browser, this is where the bot window would show up.
|
||||
time.sleep(1)
|
||||
for win in w.top_windows():
|
||||
if TEST_TITLE in win["title"]:
|
||||
corner = (win["rect"][0] + 10, win["rect"][1] + 10)
|
||||
res["window_after_remove"] = {"on_real_monitor": any(_inside(corner, d["rect"]) for d in before)}
|
||||
break
|
||||
w.kill_tree(proc.pid)
|
||||
w.kill_by_cmdline(profile.name)
|
||||
say(f" 가상 모니터를 없앴습니다: {'예' if res.get('removed') else '아니요'}")
|
||||
|
||||
|
||||
def main() -> int:
|
||||
out, work, _opts = stage_args()
|
||||
r = StageResult("vdisplay", out)
|
||||
if not IS_WINDOWS:
|
||||
r.error("vdisplay", "Windows가 아니라서 건너뜁니다")
|
||||
r.save("skipped")
|
||||
return 0
|
||||
from m0lib import winwin as w
|
||||
w.dpi_aware()
|
||||
try:
|
||||
run(r, work)
|
||||
except Exception as e:
|
||||
r.error("vdisplay", e)
|
||||
# "failed" so the next run asks again: this stage exists to answer one question.
|
||||
r.save("ok" if not r["errors"] else "failed")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
269
scripts/m0/m0lib/winvdd.py
Normal file
269
scripts/m0/m0lib/winvdd.py
Normal file
@@ -0,0 +1,269 @@
|
||||
"""Parsec Virtual Display Adapter control and display enumeration over ctypes. Windows only at run time.
|
||||
|
||||
The driver interface follows nomi-san/parsec-vdd (core/parsec-vdd.h): open the
|
||||
device interface, then DeviceIoControl with a 32-byte input buffer and a DWORD
|
||||
output. An added display stays only while UPDATE is sent at least every 100 ms,
|
||||
so a display dies with the process that keeps it (no display is left behind
|
||||
if the kit crashes).
|
||||
|
||||
The structures are defined at import time so their sizes can be checked on any
|
||||
OS; the DLLs are loaded only when a function is called.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import ctypes
|
||||
import threading
|
||||
import time
|
||||
from ctypes import wintypes
|
||||
|
||||
GUID_VDD_ADAPTER = (0x00B41627, 0x04C4, 0x429E, (0xA2, 0x6E, 0x02, 0x65, 0xCF, 0x50, 0xC8, 0xFA))
|
||||
IOCTL_ADD, IOCTL_REMOVE, IOCTL_UPDATE, IOCTL_VERSION = 0x0022E004, 0x0022A008, 0x0022A00C, 0x0022E010
|
||||
DIGCF_PRESENT, DIGCF_DEVICEINTERFACE = 0x2, 0x10
|
||||
DISPLAY_DEVICE_ATTACHED_TO_DESKTOP, DISPLAY_DEVICE_PRIMARY_DEVICE = 0x1, 0x4
|
||||
ENUM_CURRENT_SETTINGS = -1
|
||||
DM_POSITION = 0x20
|
||||
CDS_UPDATEREGISTRY, CDS_NORESET = 0x1, 0x10000000
|
||||
|
||||
|
||||
# UTF-16 code units, so the layout is the Windows one on every OS (c_wchar is 4 bytes on Linux).
|
||||
# DWORD/LONG are fixed 32-bit for the same reason (wintypes.DWORD is 8 bytes on 64-bit Linux).
|
||||
WCHAR, WORD, DWORD, LONG = ctypes.c_uint16, ctypes.c_uint16, ctypes.c_uint32, ctypes.c_int32
|
||||
|
||||
|
||||
def wstr(units) -> str:
|
||||
raw = bytes(memoryview(units).cast("B"))
|
||||
return raw.decode("utf-16-le", errors="replace").split("\x00", 1)[0]
|
||||
|
||||
|
||||
class GUID(ctypes.Structure):
|
||||
_fields_ = [("Data1", DWORD), ("Data2", WORD), ("Data3", WORD),
|
||||
("Data4", ctypes.c_ubyte * 8)]
|
||||
|
||||
|
||||
class SP_DEVICE_INTERFACE_DATA(ctypes.Structure):
|
||||
_fields_ = [("cbSize", DWORD), ("InterfaceClassGuid", GUID), ("Flags", DWORD),
|
||||
("Reserved", ctypes.c_size_t)]
|
||||
|
||||
|
||||
class OVERLAPPED(ctypes.Structure):
|
||||
_fields_ = [("Internal", ctypes.c_size_t), ("InternalHigh", ctypes.c_size_t), ("Offset", DWORD),
|
||||
("OffsetHigh", DWORD), ("hEvent", ctypes.c_void_p)]
|
||||
|
||||
|
||||
class DISPLAY_DEVICEW(ctypes.Structure):
|
||||
_fields_ = [("cb", DWORD), ("DeviceName", WCHAR * 32), ("DeviceString", WCHAR * 128),
|
||||
("StateFlags", DWORD), ("DeviceID", WCHAR * 128), ("DeviceKey", WCHAR * 128)]
|
||||
|
||||
|
||||
class POINTL(ctypes.Structure):
|
||||
_fields_ = [("x", LONG), ("y", LONG)]
|
||||
|
||||
|
||||
class DEVMODEW(ctypes.Structure):
|
||||
"""The display variant of DEVMODEW (220 bytes)."""
|
||||
_fields_ = [("dmDeviceName", WCHAR * 32), ("dmSpecVersion", WORD),
|
||||
("dmDriverVersion", WORD), ("dmSize", WORD), ("dmDriverExtra", WORD),
|
||||
("dmFields", DWORD), ("dmPosition", POINTL), ("dmDisplayOrientation", DWORD),
|
||||
("dmDisplayFixedOutput", DWORD), ("dmColor", ctypes.c_short), ("dmDuplex", ctypes.c_short),
|
||||
("dmYResolution", ctypes.c_short), ("dmTTOption", ctypes.c_short), ("dmCollate", ctypes.c_short),
|
||||
("dmFormName", WCHAR * 32), ("dmLogPixels", WORD), ("dmBitsPerPel", DWORD),
|
||||
("dmPelsWidth", DWORD), ("dmPelsHeight", DWORD), ("dmDisplayFlags", DWORD),
|
||||
("dmDisplayFrequency", DWORD), ("dmICMMethod", DWORD),
|
||||
("dmICMIntent", DWORD), ("dmMediaType", DWORD), ("dmDitherType", DWORD),
|
||||
("dmReserved1", DWORD), ("dmReserved2", DWORD),
|
||||
("dmPanningWidth", DWORD), ("dmPanningHeight", DWORD)]
|
||||
|
||||
|
||||
def _guid(parts) -> GUID:
|
||||
return GUID(parts[0], parts[1], parts[2], (ctypes.c_ubyte * 8)(*parts[3]))
|
||||
|
||||
|
||||
def _dlls():
|
||||
setupapi = ctypes.WinDLL("setupapi", use_last_error=True)
|
||||
kernel32 = ctypes.WinDLL("kernel32", use_last_error=True)
|
||||
user32 = ctypes.WinDLL("user32", use_last_error=True)
|
||||
vp, H, D, B = ctypes.c_void_p, wintypes.HANDLE, wintypes.DWORD, wintypes.BOOL
|
||||
for fn, args, res in (
|
||||
(setupapi.SetupDiGetClassDevsW, [ctypes.POINTER(GUID), wintypes.LPCWSTR, wintypes.HWND, D], vp),
|
||||
(setupapi.SetupDiEnumDeviceInterfaces, [vp, vp, ctypes.POINTER(GUID), D,
|
||||
ctypes.POINTER(SP_DEVICE_INTERFACE_DATA)], B),
|
||||
(setupapi.SetupDiGetDeviceInterfaceDetailW, [vp, ctypes.POINTER(SP_DEVICE_INTERFACE_DATA), vp, D,
|
||||
ctypes.POINTER(D), vp], B),
|
||||
(setupapi.SetupDiDestroyDeviceInfoList, [vp], B),
|
||||
(kernel32.CreateFileW, [wintypes.LPCWSTR, D, D, vp, D, D, H], H),
|
||||
(kernel32.CreateEventW, [vp, B, B, wintypes.LPCWSTR], H),
|
||||
(kernel32.DeviceIoControl, [H, D, vp, D, vp, D, ctypes.POINTER(D), ctypes.POINTER(OVERLAPPED)], B),
|
||||
(kernel32.GetOverlappedResultEx, [H, ctypes.POINTER(OVERLAPPED), ctypes.POINTER(D), D, B], B),
|
||||
(kernel32.CancelIoEx, [H, ctypes.POINTER(OVERLAPPED)], B),
|
||||
(kernel32.GetOverlappedResult, [H, ctypes.POINTER(OVERLAPPED), ctypes.POINTER(D), B], B),
|
||||
(kernel32.CloseHandle, [H], B),
|
||||
(user32.EnumDisplayDevicesW, [wintypes.LPCWSTR, D, ctypes.POINTER(DISPLAY_DEVICEW), D], B),
|
||||
(user32.EnumDisplaySettingsW, [wintypes.LPCWSTR, D, ctypes.POINTER(DEVMODEW)], B),
|
||||
(user32.ChangeDisplaySettingsExW, [wintypes.LPCWSTR, ctypes.POINTER(DEVMODEW), wintypes.HWND, D, vp],
|
||||
ctypes.c_long),
|
||||
):
|
||||
fn.argtypes, fn.restype = args, res
|
||||
return setupapi, kernel32, user32
|
||||
|
||||
|
||||
INVALID = ctypes.c_void_p(-1).value
|
||||
|
||||
|
||||
class Vdd:
|
||||
"""One open handle to the driver, with the keep-alive thread."""
|
||||
|
||||
def __init__(self):
|
||||
self.setupapi, self.kernel32, self.user32 = _dlls()
|
||||
self.handle = self._open()
|
||||
self.lock = threading.Lock()
|
||||
self._stop = threading.Event()
|
||||
self._pinger: threading.Thread | None = None
|
||||
self.added: list[int] = []
|
||||
|
||||
def _open(self):
|
||||
guid = _guid(GUID_VDD_ADAPTER)
|
||||
info = self.setupapi.SetupDiGetClassDevsW(ctypes.byref(guid), None, None,
|
||||
DIGCF_PRESENT | DIGCF_DEVICEINTERFACE)
|
||||
if not info or info == INVALID:
|
||||
raise OSError(ctypes.get_last_error(), "Parsec 가상 디스플레이 장치를 찾지 못했습니다")
|
||||
try:
|
||||
i = 0
|
||||
data = SP_DEVICE_INTERFACE_DATA()
|
||||
data.cbSize = ctypes.sizeof(SP_DEVICE_INTERFACE_DATA)
|
||||
last_err = 0
|
||||
while self.setupapi.SetupDiEnumDeviceInterfaces(info, None, ctypes.byref(guid), i, ctypes.byref(data)):
|
||||
i += 1
|
||||
size = wintypes.DWORD(0)
|
||||
self.setupapi.SetupDiGetDeviceInterfaceDetailW(info, ctypes.byref(data), None, 0, ctypes.byref(size),
|
||||
None)
|
||||
buf = ctypes.create_string_buffer(max(size.value, 16))
|
||||
# cbSize is the fixed part of SP_DEVICE_INTERFACE_DETAIL_DATA_W: 8 on 64-bit, 6 on 32-bit.
|
||||
ctypes.cast(buf, ctypes.POINTER(wintypes.DWORD))[0] = 8 if ctypes.sizeof(ctypes.c_void_p) == 8 else 6
|
||||
if not self.setupapi.SetupDiGetDeviceInterfaceDetailW(info, ctypes.byref(data), buf, size,
|
||||
ctypes.byref(size), None):
|
||||
last_err = ctypes.get_last_error()
|
||||
continue
|
||||
path = ctypes.wstring_at(ctypes.addressof(buf) + 4)
|
||||
h = self.kernel32.CreateFileW(path, 0xC0000000, 0x3, None, 3,
|
||||
0x80 | 0x20000000 | 0x40000000 | 0x80000000, None)
|
||||
if h and h != INVALID:
|
||||
return h
|
||||
last_err = ctypes.get_last_error()
|
||||
raise OSError(last_err or ctypes.get_last_error(), f"장치를 열지 못했습니다 (인터페이스 {i}개)")
|
||||
finally:
|
||||
self.setupapi.SetupDiDestroyDeviceInfoList(info)
|
||||
|
||||
def ioctl(self, code: int, data: bytes = b"") -> int:
|
||||
inbuf = ctypes.create_string_buffer(data[:32], 32)
|
||||
out = wintypes.DWORD(0)
|
||||
ov = OVERLAPPED()
|
||||
ov.hEvent = self.kernel32.CreateEventW(None, True, False, None)
|
||||
n = wintypes.DWORD(0)
|
||||
try:
|
||||
with self.lock:
|
||||
self.kernel32.DeviceIoControl(self.handle, code, inbuf, 32, ctypes.byref(out), 4, None,
|
||||
ctypes.byref(ov))
|
||||
if not self.kernel32.GetOverlappedResultEx(self.handle, ctypes.byref(ov), ctypes.byref(n), 5000,
|
||||
False):
|
||||
# The request may still be pending: cancel it and wait, or the driver
|
||||
# could later write into these buffers after they are freed.
|
||||
self.kernel32.CancelIoEx(self.handle, ctypes.byref(ov))
|
||||
self.kernel32.GetOverlappedResult(self.handle, ctypes.byref(ov), ctypes.byref(n), True)
|
||||
return -1
|
||||
return out.value
|
||||
finally:
|
||||
if ov.hEvent:
|
||||
self.kernel32.CloseHandle(ov.hEvent)
|
||||
|
||||
def version(self) -> int:
|
||||
return self.ioctl(IOCTL_VERSION)
|
||||
|
||||
def _ping(self) -> None:
|
||||
while not self._stop.wait(0.05):
|
||||
self.ioctl(IOCTL_UPDATE)
|
||||
|
||||
def add(self) -> int:
|
||||
if self._pinger is None:
|
||||
self._pinger = threading.Thread(target=self._ping, daemon=True)
|
||||
self._pinger.start()
|
||||
idx = self.ioctl(IOCTL_ADD)
|
||||
self.ioctl(IOCTL_UPDATE)
|
||||
if idx >= 0:
|
||||
self.added.append(idx)
|
||||
return idx
|
||||
|
||||
def remove(self, idx: int) -> None:
|
||||
# The driver reads the index as a big-endian UINT16.
|
||||
self.ioctl(IOCTL_REMOVE, (idx & 0xFFFF).to_bytes(2, "big"))
|
||||
self.ioctl(IOCTL_UPDATE)
|
||||
if idx in self.added:
|
||||
self.added.remove(idx)
|
||||
|
||||
def close(self) -> None:
|
||||
for idx in list(self.added):
|
||||
self.remove(idx)
|
||||
self._stop.set()
|
||||
if self._pinger:
|
||||
self._pinger.join(timeout=2)
|
||||
self.kernel32.CloseHandle(self.handle)
|
||||
|
||||
|
||||
def displays() -> list[dict]:
|
||||
"""Displays attached to the desktop: device name, adapter, rect in desktop pixels, primary flag."""
|
||||
_, _, user32 = _dlls()
|
||||
out = []
|
||||
i = 0
|
||||
while True:
|
||||
dd = DISPLAY_DEVICEW()
|
||||
dd.cb = ctypes.sizeof(DISPLAY_DEVICEW)
|
||||
if not user32.EnumDisplayDevicesW(None, i, ctypes.byref(dd), 0):
|
||||
break
|
||||
i += 1
|
||||
if not dd.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP:
|
||||
continue
|
||||
dm = DEVMODEW()
|
||||
dm.dmSize = ctypes.sizeof(DEVMODEW)
|
||||
name, adapter = wstr(dd.DeviceName), wstr(dd.DeviceString)
|
||||
if not user32.EnumDisplaySettingsW(name, ENUM_CURRENT_SETTINGS, ctypes.byref(dm)):
|
||||
continue
|
||||
x, y = dm.dmPosition.x, dm.dmPosition.y
|
||||
out.append({"device": name, "adapter": adapter,
|
||||
"rect": [x, y, x + dm.dmPelsWidth, y + dm.dmPelsHeight], "hz": dm.dmDisplayFrequency,
|
||||
"primary": bool(dd.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE),
|
||||
"virtual": "parsec" in adapter.lower()})
|
||||
return out
|
||||
|
||||
|
||||
def wait_for_displays(pred, timeout: float = 10.0) -> list[dict]:
|
||||
end = time.time() + timeout
|
||||
cur = displays()
|
||||
while not pred(cur) and time.time() < end:
|
||||
time.sleep(0.25)
|
||||
cur = displays()
|
||||
return cur
|
||||
|
||||
|
||||
def corner_position(physical: list[dict]) -> tuple[int, int]:
|
||||
"""Where a display only touches the others at the bottom-right corner of the desktop.
|
||||
|
||||
The cursor crosses from one display to another only along a shared edge, so a display that meets the
|
||||
rest at a single point is the hardest one for the mouse to wander onto.
|
||||
"""
|
||||
right = max(d["rect"][2] for d in physical)
|
||||
bottom = max(d["rect"][3] for d in physical if d["rect"][2] == right)
|
||||
return right, bottom
|
||||
|
||||
|
||||
def move_display(device: str, x: int, y: int) -> list[int]:
|
||||
"""Move a display; returns the two ChangeDisplaySettingsEx results (0 = DISP_CHANGE_SUCCESSFUL)."""
|
||||
_, _, user32 = _dlls()
|
||||
dm = DEVMODEW()
|
||||
dm.dmSize = ctypes.sizeof(DEVMODEW)
|
||||
if not user32.EnumDisplaySettingsW(device, ENUM_CURRENT_SETTINGS, ctypes.byref(dm)):
|
||||
return [-99]
|
||||
dm.dmFields = DM_POSITION
|
||||
dm.dmPosition.x, dm.dmPosition.y = x, y
|
||||
a = user32.ChangeDisplaySettingsExW(device, ctypes.byref(dm), None, CDS_UPDATEREGISTRY | CDS_NORESET, None)
|
||||
b = user32.ChangeDisplaySettingsExW(None, None, None, 0, None)
|
||||
return [a, b]
|
||||
@@ -178,3 +178,69 @@ def test_failed_strata_launch_keeps_the_engine_log_for_the_zip(tmp_path, monkeyp
|
||||
text = kept[0].read_text(encoding="utf-8")
|
||||
assert "out of memory" in text
|
||||
assert home not in text
|
||||
|
||||
|
||||
def test_recommended_launch_does_not_ask_for_the_dflash2_drafter(tmp_path, monkeypatch):
|
||||
# Strata 0.1.59 picks DFlash2 alone (--draft-fallback none) for Q2_0, but the
|
||||
# canonical Q2_0 pack is not a native pack, so the engine stops at start
|
||||
# ("DFlash2 is off here: it needs a native pack ... the start ends here").
|
||||
ran = []
|
||||
monkeypatch.setattr(llm, "run_logged", lambda cmd, *a, **k: ran.append(cmd) or 1)
|
||||
s = llm.Strata(tmp_path, tmp_path / "strata.log")
|
||||
monkeypatch.setattr(s, "supported_flags", lambda: {"--family", "--model", "--drafting", "--parallel"})
|
||||
for parallel in (1, 2):
|
||||
s.launch(llm.PRESETS["recommended"], 32768, parallel=parallel)
|
||||
for cmd in ran:
|
||||
assert "--drafting" in cmd
|
||||
assert cmd[cmd.index("--drafting") + 1] not in ("auto", "dflash2")
|
||||
|
||||
|
||||
def test_virtual_display_structures_match_the_win32_layout():
|
||||
# A wrong layout makes every display call fail on the PC, where we cannot debug it.
|
||||
import ctypes
|
||||
|
||||
from m0lib import winvdd
|
||||
assert ctypes.sizeof(winvdd.DEVMODEW) == 220
|
||||
assert ctypes.sizeof(winvdd.DISPLAY_DEVICEW) == 840
|
||||
if ctypes.sizeof(ctypes.c_void_p) == 8:
|
||||
assert ctypes.sizeof(winvdd.SP_DEVICE_INTERFACE_DATA) == 32
|
||||
assert ctypes.sizeof(winvdd.OVERLAPPED) == 32
|
||||
|
||||
|
||||
def test_virtual_display_goes_where_it_only_touches_a_corner():
|
||||
from m0lib import winvdd
|
||||
# Two side-by-side 1440p monitors, the second one lower than the first.
|
||||
physical = [{"rect": [0, 0, 2560, 1440]}, {"rect": [2560, 200, 5120, 1640]}]
|
||||
x, y = winvdd.corner_position(physical)
|
||||
assert (x, y) == (5120, 1640)
|
||||
for d in physical:
|
||||
left, top, right, bottom = d["rect"]
|
||||
# Only a point is shared: no edge of length > 0 with any real monitor.
|
||||
assert not (left <= x < right and top <= y < bottom)
|
||||
|
||||
|
||||
def test_virtual_display_remove_sends_the_index_the_driver_expects():
|
||||
from m0lib import winvdd
|
||||
sent = []
|
||||
vdd = object.__new__(winvdd.Vdd)
|
||||
vdd.added = [1]
|
||||
vdd.ioctl = lambda code, data=b"": sent.append((code, data)) or 0
|
||||
vdd.remove(1)
|
||||
assert sent[0] == (winvdd.IOCTL_REMOVE, b"\x00\x01")
|
||||
assert vdd.added == []
|
||||
|
||||
|
||||
def test_kit_runs_the_virtual_display_check_before_the_unattended_stages():
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "scripts" / "m0"))
|
||||
import m0
|
||||
keys = [s[0] for s in m0.STAGES]
|
||||
assert keys.index("vdisplay") < keys.index("tts_melo")
|
||||
assert (Path(m0.KIT) / "m0lib" / m0.STAGES[keys.index("vdisplay")][3]).exists()
|
||||
|
||||
|
||||
def test_virtual_display_names_are_read_from_utf16_buffers():
|
||||
from m0lib import winvdd
|
||||
dd = winvdd.DISPLAY_DEVICEW()
|
||||
text = "Parsec Virtual Display Adapter".encode("utf-16-le")
|
||||
winvdd.ctypes.memmove(winvdd.ctypes.addressof(dd) + winvdd.DISPLAY_DEVICEW.DeviceString.offset, text, len(text))
|
||||
assert winvdd.wstr(dd.DeviceString) == "Parsec Virtual Display Adapter"
|
||||
|
||||
Reference in New Issue
Block a user