claude-code-best 2.5.0 → 2.6.5
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.
- package/dist/chunks/AddWorkspaceDirectory-BYyM_V0q.js +1 -0
- package/dist/chunks/App-BboadKdn.js +1 -0
- package/dist/chunks/ApproveApiKey-BLp4742y.js +1 -0
- package/dist/chunks/ApproveApiKey-DiEe4eui.js +1 -0
- package/dist/chunks/AssistantSessionChooser-B88DM0Oq.js +1 -0
- package/dist/chunks/BackgroundTasksDialog-ByraVuXh.js +2 -0
- package/dist/chunks/BypassPermissionsModeDialog-BDvmz12S.js +1 -0
- package/dist/chunks/ClaudeInChromeOnboarding-B6XNhFqq.js +1 -0
- package/dist/chunks/ClaudeMdExternalIncludesDialog-B4ocUjev.js +1 -0
- package/dist/chunks/ClaudeMdExternalIncludesDialog-BNhlq7_K.js +1 -0
- package/dist/chunks/ConsoleOAuthFlow-BvaB9b0y.js +1 -0
- package/dist/chunks/DesktopHandoff-S-w4bs5T.js +1 -0
- package/dist/chunks/DevChannelsDialog-BljR0X9X.js +1 -0
- package/dist/chunks/Dialog-DYFGqyDs.js +1 -0
- package/dist/chunks/DiffDialog-BhQ2QaLW.js +3 -0
- package/dist/chunks/Doctor-BXb0qv6n.js +3 -0
- package/dist/chunks/Doctor-C5DYPEGl.js +1 -0
- package/dist/chunks/ExitFlow-CSBDxw9H.js +2 -0
- package/dist/chunks/Feedback-DwHzc4UT.js +2 -0
- package/dist/chunks/Grove-DSXRnXKv.js +11 -0
- package/dist/chunks/Grove-DnTo982-.js +1 -0
- package/dist/chunks/HybridTransport-CuT3KI5e.js +4 -0
- package/dist/chunks/ITermBackend-mokGZVH_.js +1 -0
- package/dist/chunks/InProcessTransport-DB52dh4f.js +1 -0
- package/dist/chunks/InvalidConfigDialog-Bi4RKYlk.js +1 -0
- package/dist/chunks/InvalidSettingsDialog-0zKo4-so.js +1 -0
- package/dist/chunks/ListItem-OFARanN7.js +1 -0
- package/dist/chunks/MCPConnectionManager-DYGoS1Ht.js +1 -0
- package/dist/chunks/McpParsingWarnings-EzgsOoHw.js +1 -0
- package/dist/chunks/MessageSelector-DTmUuEKJ.js +3 -0
- package/dist/chunks/Messages-DWiKTx5o.js +11 -0
- package/dist/chunks/Onboarding-odmthwzz.js +1 -0
- package/dist/chunks/OverageCreditUpsell-Cpk_5Lv0.js +1 -0
- package/dist/chunks/PermissionDialog-5MlJf7ew.js +1 -0
- package/dist/chunks/PluginSettings-eYcWehI8.js +17 -0
- package/dist/chunks/PressEnterToContinue-BdA9zDGs.js +1 -0
- package/dist/chunks/PromptInputFooterSuggestions-DrrkNOuS.js +1 -0
- package/dist/chunks/PromptInputHelpMenu-DMsF4D6d.js +1 -0
- package/dist/chunks/QueryEngine-C_KZts4y.js +1 -0
- package/dist/chunks/REPL-C6YR0VKU.js +1 -0
- package/dist/chunks/REPL-DzHz-LOY.js +97 -0
- package/dist/chunks/RemoteCallout-CnpCWRPk.js +1 -0
- package/dist/chunks/RemoteSessionManager-OWg_Yccq.js +2 -0
- package/dist/chunks/ResumeConversation-BktSnsCm.js +1 -0
- package/dist/chunks/SSETransport-BpnapvlK.js +4 -0
- package/dist/chunks/SearchBox-DfOmUoaI.js +1 -0
- package/dist/chunks/SearchExtraToolsTool-CqFD8vVS.js +1 -0
- package/dist/chunks/SentryErrorBoundary-BUirJRWU.js +1 -0
- package/dist/chunks/SentryErrorBoundary-C-NlfQZw.js +2 -0
- package/dist/chunks/Settings-vfFvcweR.js +2 -0
- package/dist/chunks/TeleportProgress-CYXay2ZL.js +1 -0
- package/dist/chunks/TeleportRepoMismatchDialog-_zbZTvcJ.js +1 -0
- package/dist/chunks/TeleportResumeWrapper-DiHQeZIM.js +1 -0
- package/dist/chunks/ThemePicker-BRh027fA.js +1 -0
- package/dist/chunks/TmuxBackend-BaX2U7iZ.js +9 -0
- package/dist/chunks/TrustDialog-CVbzrv6g.js +1 -0
- package/dist/chunks/TungstenTool-C5IqKVr0.js +1 -0
- package/dist/chunks/TungstenTool-V-Bwqlx3.js +1 -0
- package/dist/chunks/ValidationErrorsList-CdCUgfIl.js +2 -0
- package/dist/chunks/WelcomeV2-DCXcYd2x.js +1 -0
- package/dist/chunks/WindowsTerminalBackend-BE9NX5IH.js +2 -0
- package/dist/chunks/add-dir-ldGd3Ppz.js +1 -0
- package/dist/chunks/agentDisplay-CVnAeURF.js +1 -0
- package/dist/chunks/agents-C08NzRZx.js +2 -0
- package/dist/chunks/agents-DH5fmbVw.js +103 -0
- package/dist/chunks/ajv-B_OpU_Uh.js +8 -0
- package/dist/chunks/analytics-DqMQntaB.js +1 -0
- package/dist/chunks/ant-DJren1Aa.js +1 -0
- package/dist/chunks/api-6tcwJlf_.js +1 -0
- package/dist/chunks/api-CGOR_Xfl.js +1 -0
- package/dist/chunks/asciicast-aoKFhc7C.js +1 -0
- package/dist/chunks/asciicast-o5Zg4dJt.js +4 -0
- package/dist/chunks/assistant-BlzrMSkM.js +1 -0
- package/dist/chunks/assistant-CwbhlCM-.js +1 -0
- package/dist/chunks/assistant-aWkDcurV.js +1 -0
- package/dist/chunks/attributionHooks-PygdohOh.js +1 -0
- package/dist/chunks/attributionTrailer-BpvhXgRP.js +1 -0
- package/dist/chunks/auth-CSB2RDKF.js +1 -0
- package/dist/chunks/auth-GxZhOvQ1.js +1 -0
- package/dist/chunks/autoMode-CWvZs1jO.js +45 -0
- package/dist/chunks/autoModeDenials-Cp6VFdsm.js +1 -0
- package/dist/chunks/autonomy-BkVcSMCZ.js +19 -0
- package/dist/chunks/autonomy-DK42aJYt.js +1 -0
- package/dist/chunks/autonomyPanel-Cn4IhXgE.js +1 -0
- package/dist/chunks/axios-DLnc2dVy.js +1 -0
- package/dist/chunks/axios-DhfaybwJ.js +12 -0
- package/dist/chunks/backgroundHousekeeping-BIZTAYho.js +17 -0
- package/dist/chunks/backgroundHousekeeping-Csh58CxV.js +1 -0
- package/dist/chunks/banner-CVXH2xts.js +2 -0
- package/dist/chunks/base64-js-DIVSFswY.js +1 -0
- package/dist/chunks/bedrockClient-qi1-JCOK.js +15 -0
- package/dist/chunks/bg-DK0E4ZtW.js +9 -0
- package/dist/chunks/bg-Dbh5z3Y8.js +1 -0
- package/dist/chunks/branch-juox_fko.js +3 -0
- package/dist/chunks/break-cache-ByJ7U2Ts.js +8 -0
- package/dist/chunks/bridge-DudsCZkh.js +2 -0
- package/dist/chunks/bridgeConfig-D4tpc568.js +1 -0
- package/dist/chunks/bridgeConfig-lRZfQqmA.js +1 -0
- package/dist/chunks/bridgeEnabled-B8_c_Ppq.js +1 -0
- package/dist/chunks/bridgeEnabled-D2IykaHE.js +1 -0
- package/dist/chunks/bridgeMain-C5RDihlX.js +68 -0
- package/dist/chunks/bridgeMain-D7_lg2iJ.js +1 -0
- package/dist/chunks/bridgeMessaging-CqNURC4-.js +1 -0
- package/dist/chunks/bridgePointer-FvAMj3re.js +1 -0
- package/dist/chunks/browser-fLRXxIsQ.js +1 -0
- package/dist/chunks/btw-DKlE3Dea.js +1 -0
- package/dist/chunks/buddy-DQYgHR63.js +3 -0
- package/dist/chunks/bundledMode-kSQejuY4.js +1 -0
- package/dist/chunks/bypassPermissionsKillswitch-Bof-UtM-.js +1 -0
- package/dist/chunks/caches-B5QZDncQ.js +3 -0
- package/dist/chunks/caches-dGk7xsDu.js +1 -0
- package/dist/chunks/capacityWake-BXlUpptF.js +1 -0
- package/dist/chunks/ccrClient-BaWg4E9-.js +1 -0
- package/dist/chunks/ccshareResume-DWLjTF22.js +1 -0
- package/dist/chunks/changeDetector-DoLfg8a6.js +1 -0
- package/dist/chunks/channelNotification-B7A-9DIl.js +1 -0
- package/dist/chunks/channelNotification-DDErroWn.js +1 -0
- package/dist/chunks/chokidar-BcI3rIKm.js +1 -0
- package/dist/chunks/chokidar-SzksMqYp.js +1 -0
- package/dist/chunks/chrome-jMAks7-w.js +1 -0
- package/dist/chunks/chromeNativeHost-4U39yLtd.js +1 -0
- package/dist/chunks/chunk-DR8-3Aex.js +1 -0
- package/dist/chunks/classPrivateFieldSet2-EAQNhHs8.js +1 -0
- package/dist/chunks/claudeDesktop-D0S1eq1F.js +1 -0
- package/dist/chunks/cleanup-Bg_gFgcj.js +1 -0
- package/dist/chunks/clear-OudnCGa7.js +1 -0
- package/dist/chunks/cliLaunch-BQa48gsr.js +1 -0
- package/dist/chunks/client-CPn1wQyc.js +7 -0
- package/dist/chunks/client-DxDmXXTh.js +1 -0
- package/dist/chunks/client-_sjL0I7A.js +35 -0
- package/dist/chunks/color-DG_R5-hl.js +1 -0
- package/dist/chunks/color-convert-ULbeSgNC.js +1 -0
- package/dist/chunks/commands-BWIOEBPs.js +1 -0
- package/dist/chunks/commitAttribution-BA4fcbHf.js +1 -0
- package/dist/chunks/commitAttribution-C22a3OCi.js +2 -0
- package/dist/chunks/common-B379wT22.js +1 -0
- package/dist/chunks/common-B_BC3eMY.js +1 -0
- package/dist/chunks/common-CMCv4N_v.js +1 -0
- package/dist/chunks/compact-BWvnb4or.js +3 -0
- package/dist/chunks/companion-Bkn2lSLj.js +1 -0
- package/dist/chunks/completionCache-DHfUBBMH.js +1 -0
- package/dist/chunks/completionCache-DORrtxkS.js +4 -0
- package/dist/chunks/computerUseLock-BjoDJH2h.js +1 -0
- package/dist/chunks/config-BvpTbJ5p.js +1 -0
- package/dist/chunks/config-D-dzD6n-.js +1 -0
- package/dist/chunks/connectHeadless-CwsFt-Mh.js +1 -0
- package/dist/chunks/constants-41VpZw2G.js +1 -0
- package/dist/chunks/context-DzNahdyP.js +1 -0
- package/dist/chunks/context-noninteractive-CM1-lUSe.js +1 -0
- package/dist/chunks/context-noninteractive-yiyJriiw.js +54 -0
- package/dist/chunks/controlMessageCompat-BJhFiS7u.js +1 -0
- package/dist/chunks/conversation-DKlz47xf.js +1 -0
- package/dist/chunks/conversation-cUxdb8MN.js +1 -0
- package/dist/chunks/copy-9k9JPRqW.js +7 -0
- package/dist/chunks/createSSHSession-BZf-Loo5.js +6 -0
- package/dist/chunks/createSession-BuJcoBAj.js +1 -0
- package/dist/chunks/createSession-kiTHYXSL.js +1 -0
- package/dist/chunks/cron-DiW7eIPP.js +1 -0
- package/dist/chunks/cronJitterConfig-CYP7yrQu.js +6 -0
- package/dist/chunks/crossProjectResume-BJisir9Z.js +40 -0
- package/dist/chunks/cwd--iizewsn.js +1 -0
- package/dist/chunks/cwd-BgpSJxd7.js +1 -0
- package/dist/chunks/daemon-VYRit6Aq.js +2 -0
- package/dist/chunks/dangerousBackend-BU_PHGR2.js +1 -0
- package/dist/chunks/datadog-Bg-zL-i7.js +1 -0
- package/dist/chunks/datadog-CVeFkaQu.js +1 -0
- package/dist/chunks/debug-DM5ezCBS.js +1 -0
- package/dist/chunks/debug-UI3T040K.js +5 -0
- package/dist/chunks/debugUtils-BBMFODKH.js +1 -0
- package/dist/chunks/defineProperty-80gRi2ZW.js +1 -0
- package/dist/chunks/desktop-DpaStjc-.js +1 -0
- package/dist/chunks/detached-D300jlhj.js +5 -0
- package/dist/chunks/detect-libc-DNuQfUvI.js +1 -0
- package/dist/chunks/detectRepository-CBk3S2zv.js +1 -0
- package/dist/chunks/detectRepository-DCTvg4p0.js +1 -0
- package/dist/chunks/detection-CQsNad64.js +1 -0
- package/dist/chunks/detection-DJ-vTbBf.js +1 -0
- package/dist/chunks/diff-N_VSBo3Z.js +1 -0
- package/dist/chunks/directoryCompletion-DP_4B1GL.js +1 -0
- package/dist/chunks/dist-CanSxOZ1.js +5 -0
- package/dist/chunks/dist-Cg1a1Exw.js +29 -0
- package/dist/chunks/dist-Q7YNoZ0H.js +20 -0
- package/dist/chunks/dist-es-4z5T3Jzm.js +1 -0
- package/dist/chunks/dist-es-B2jg52tM2.js +1 -0
- package/dist/chunks/dist-es-B6OXHQ1S.js +1 -0
- package/dist/chunks/dist-es-B8NEy5hc.js +1 -0
- package/dist/chunks/dist-es-BVGppqE4.js +1 -0
- package/dist/chunks/dist-es-Bcw5GZko.js +1 -0
- package/dist/chunks/dist-es-BoIJpncb.js +9 -0
- package/dist/chunks/dist-es-Bu_Fshi1.js +1 -0
- package/dist/chunks/dist-es-C-1vn4OP2.js +1 -0
- package/dist/chunks/dist-es-C41b_0B5.js +1 -0
- package/dist/chunks/dist-es-CCZYybbG2.js +1 -0
- package/dist/chunks/dist-es-CLK1mey-.js +1 -0
- package/dist/chunks/dist-es-CQz2aNf72.js +1 -0
- package/dist/chunks/dist-es-CSfI8B8l.js +1 -0
- package/dist/chunks/dist-es-CUZBYppo.js +1 -0
- package/dist/chunks/dist-es-CZkzHpjF.js +1 -0
- package/dist/chunks/dist-es-Cbf0_D8d.js +5 -0
- package/dist/chunks/dist-es-ChHe-SVL.js +1 -0
- package/dist/chunks/dist-es-ClYOf0My.js +1 -0
- package/dist/chunks/dist-es-D-kJbj4A2.js +1 -0
- package/dist/chunks/dist-es-D1LN6CJd.js +1 -0
- package/dist/chunks/dist-es-DC1sC3ph.js +1 -0
- package/dist/chunks/dist-es-DGn8uOwQ2.js +1 -0
- package/dist/chunks/dist-es-DK5fTeKM2.js +1 -0
- package/dist/chunks/dist-es-DN7otr6F.js +1 -0
- package/dist/chunks/dist-es-DPM0mPK5.js +1 -0
- package/dist/chunks/dist-es-DqZAh3nG.js +1 -0
- package/dist/chunks/dist-es-DuAZyxJ02.js +5 -0
- package/dist/chunks/dist-es-HVQrM0oE.js +1 -0
- package/dist/chunks/dist-es-OVleIB54.js +1 -0
- package/dist/chunks/dist-es-UAs0rdXg.js +1 -0
- package/dist/chunks/dist-es-WvMMuHmx2.js +1 -0
- package/dist/chunks/dist-es-fjXft-jH.js +1 -0
- package/dist/chunks/dist-es-hdN_ShpZ.js +3 -0
- package/dist/chunks/dist-es-neiUvMJb.js +1 -0
- package/dist/chunks/dist-es-yMYpDtui2.js +1 -0
- package/dist/chunks/dist-es-zjcbuB72.js +1 -0
- package/dist/chunks/distRoot-CcxmnzqQ.js +1 -0
- package/dist/chunks/doctor-CUWjbh1X.js +1 -0
- package/dist/chunks/earlyInput-JGJo1zcC.js +1 -0
- package/dist/chunks/earlyInput-tRkbxFv2.js +2 -0
- package/dist/chunks/effort-loH1TUvE.js +9 -0
- package/dist/chunks/entry-D58E-E6Y.js +14 -0
- package/dist/chunks/env-chR0gV31.js +1 -0
- package/dist/chunks/envLessBridgeConfig-CT8sdmFu.js +1 -0
- package/dist/chunks/envLessBridgeConfig-SPEr9oqO.js +1 -0
- package/dist/chunks/envUtils-BWeoiL4Y.js +1 -0
- package/dist/chunks/escHotkey-Cyz0yyh1.js +259 -0
- package/dist/chunks/esm--xjzB1hI.js +1 -0
- package/dist/chunks/esm-B2HIF0XY.js +1 -0
- package/dist/chunks/esm-BGQPWnJy.js +1 -0
- package/dist/chunks/esm-C-1qL9Mn.js +1 -0
- package/dist/chunks/esm-C3jcs1DH.js +1 -0
- package/dist/chunks/esm-C97WL9nC.js +1 -0
- package/dist/chunks/esm-CIL-SKM8.js +1 -0
- package/dist/chunks/esm-CJlBxjtx.js +1 -0
- package/dist/chunks/esm-CsGLyWmS.js +56 -0
- package/dist/chunks/esm-DQHmDm-H.js +1 -0
- package/dist/chunks/esm-DcdOXSzi.js +1 -0
- package/dist/chunks/esm-DhNYgGTV.js +1 -0
- package/dist/chunks/esm-DxPW7qPs.js +1 -0
- package/dist/chunks/esm-FBUWr3vI.js +1 -0
- package/dist/chunks/esm-QgL6y---.js +10 -0
- package/dist/chunks/esm-v0kPjgVS.js +1 -0
- package/dist/chunks/esm-vIn-YV_h.js +1 -0
- package/dist/chunks/event-streams-BV7ngMXu.js +1 -0
- package/dist/chunks/eventLoopStallDetector-Dnh1fc31.js +1 -0
- package/dist/chunks/execAsync-BkA6ogic.js +1 -0
- package/dist/chunks/execFileNoThrow-CuQN1sz8.js +1 -0
- package/dist/chunks/execSyncWrapper-C2XQnFVo.js +1 -0
- package/dist/chunks/execa-CGue6Z3n.js +34 -0
- package/dist/chunks/executor-4EeD8GNm.js +1561 -0
- package/dist/chunks/executor-BHEuNh5F.js +1 -0
- package/dist/chunks/exit-D-tuPpbx.js +1 -0
- package/dist/chunks/exit-_obETqBv.js +2 -0
- package/dist/chunks/export-BIZ_SPXJ.js +2 -0
- package/dist/chunks/exportRenderer-CWPSMaqM.js +1 -0
- package/dist/chunks/extra-usage-CCMwIa85.js +1 -0
- package/dist/chunks/extra-usage-core-BNW4VT7o.js +1 -0
- package/dist/chunks/extra-usage-noninteractive-B_WjXO1E.js +1 -0
- package/dist/chunks/extra-usage-rdJ7ecEb.js +1 -0
- package/dist/chunks/extraUsage-CNMMTNJi.js +1 -0
- package/dist/chunks/extractMemories-BrvZVsmM.js +1 -0
- package/dist/chunks/fast-CG1v3fRr.js +1 -0
- package/dist/chunks/fast-CLKKsx2H.js +1 -0
- package/dist/chunks/featureCheck-Cm0YNDXO.js +1 -0
- package/dist/chunks/featureCheck-p7OeCYzj.js +1 -0
- package/dist/chunks/feedback-CG4mS_-B.js +1 -0
- package/dist/chunks/figures-gfT9mM8P.js +1 -0
- package/dist/chunks/fileStateCache-C7-TxF8G.js +1 -0
- package/dist/chunks/files-DYvAZGxp.js +2 -0
- package/dist/chunks/firstPartyEventLogger-Y_jAnHoR.js +1 -0
- package/dist/chunks/flushGate-COPcye5f.js +1 -0
- package/dist/chunks/foundry-sdk-BFN5VDFQ.js +1 -0
- package/dist/chunks/fpsMetrics-DeezdcwV.js +1 -0
- package/dist/chunks/fuse-Ch_OAlm3.js +1 -0
- package/dist/chunks/gates-CSHuXnUx.js +1 -0
- package/dist/chunks/gates-CSKxLmMJ.js +1 -0
- package/dist/chunks/gemini-B3uSLiNp.js +1 -0
- package/dist/chunks/generateRecap-D7rG3jIm.js +1 -0
- package/dist/chunks/generateSessionName-zbqanivg.js +1 -0
- package/dist/chunks/genericProcessUtils-BGvcwuPt.js +23 -0
- package/dist/chunks/getMachineId-bsd-BMtYGBUL.js +1 -0
- package/dist/chunks/getMachineId-darwin-CiLdFH7z.js +2 -0
- package/dist/chunks/getMachineId-linux-Cr27rIeY.js +1 -0
- package/dist/chunks/getMachineId-unsupported-ceiBLwAN.js +1 -0
- package/dist/chunks/getMachineId-win-DFTmsQHq.js +1 -0
- package/dist/chunks/git-CN3qtTb_.js +6 -0
- package/dist/chunks/git-D23Mzu_K.js +1 -0
- package/dist/chunks/githubRepoPathMapping-B04nEUDG.js +1 -0
- package/dist/chunks/graceful-fs-Cgc0rjGF.js +2 -0
- package/dist/chunks/grok-CDOpos8E.js +1 -0
- package/dist/chunks/growthbook-C_EY78Sn.js +1 -0
- package/dist/chunks/hash-BRmOQc3c.js +1 -0
- package/dist/chunks/heapdump-CpmhJ55b.js +5 -0
- package/dist/chunks/help-EHn2neTv.js +1 -0
- package/dist/chunks/hooks-BFdX17Za.js +1 -0
- package/dist/chunks/hooks-BV6HqbU4.js +79 -0
- package/dist/chunks/hostAdapter-_SmFAVNf.js +1 -0
- package/dist/chunks/hostGuard-zim_4F9V.js +1 -0
- package/dist/chunks/httpAuthSchemes-Wq4XWeLL.js +13 -0
- package/dist/chunks/ide-DkN0KdTR.js +2 -0
- package/dist/chunks/inboundAttachments-BVUunfAX.js +1 -0
- package/dist/chunks/inboundAttachments-DnGQw7Pf.js +1 -0
- package/dist/chunks/index.min-BJnb9GQI.js +1 -0
- package/dist/chunks/initReplBridge-tPRGPBq7.js +1 -0
- package/dist/chunks/insights-Bs9kJDG6.js +822 -0
- package/dist/chunks/install-CFX_ph9z.js +1 -0
- package/dist/chunks/install-github-app-CvRjY1Wi.js +147 -0
- package/dist/chunks/install-slack-app-DjhnVSe0.js +1 -0
- package/dist/chunks/instinctParser-DHMa8xa0.js +1 -0
- package/dist/chunks/instrumentation-c5zlOWom.js +12 -0
- package/dist/chunks/intl-Pse97ORk.js +1 -0
- package/dist/chunks/isObject-DaxDnPKm.js +1 -0
- package/dist/chunks/isSymbol-Dp3irZaY.js +1 -0
- package/dist/chunks/job-3QwLq609.js +2 -0
- package/dist/chunks/json-bigint-OxRwRvup.js +8 -0
- package/dist/chunks/jsx-runtime-D-D469L8.js +1 -0
- package/dist/chunks/jws-2vqRyZtR.js +3 -0
- package/dist/chunks/jwtUtils-CpXwh_du.js +1 -0
- package/dist/chunks/keybindings-7mDm3UKD.js +2 -0
- package/dist/chunks/lang-DyyjY20G.js +1 -0
- package/dist/chunks/language-CPRGmY8Q.js +1 -0
- package/dist/chunks/language-Cf6bMI4N.js +1 -0
- package/dist/chunks/launchAgentsPlatform-CpsMsTqQ.js +1 -0
- package/dist/chunks/launchAutofixPr-D9h6YAZY.js +2 -0
- package/dist/chunks/launchCommand-Du91jxMC.js +1 -0
- package/dist/chunks/launchLocalMemory-DlYQcEQJ.js +3 -0
- package/dist/chunks/launchLocalVault-CP0AyPjj.js +3 -0
- package/dist/chunks/launchMemoryStores-BHoDFkJ5.js +1 -0
- package/dist/chunks/launchOnboarding-CFTNXcnc.js +8 -0
- package/dist/chunks/launchSchedule-5KQr6x_A.js +1 -0
- package/dist/chunks/launchSkillStore-D0yGuE68.js +1 -0
- package/dist/chunks/launchTeleport-DRKnXOwY.js +3 -0
- package/dist/chunks/launchVault-XA-zAswX.js +1 -0
- package/dist/chunks/lazySchema-2sOku3cX.js +1 -0
- package/dist/chunks/lib-B4Q0Nrpb.js +14 -0
- package/dist/chunks/lib-Ca3QWJjN.js +2 -0
- package/dist/chunks/lib-inCisXen.js +8 -0
- package/dist/chunks/loadAgentsDir-DCyiY0MN.js +1 -0
- package/dist/chunks/loadAgentsDir-DI1a76pd.js +4601 -0
- package/dist/chunks/loadPluginHooks-C0Ei-0E2.js +1 -0
- package/dist/chunks/loadSso-sDs471GC.js +1 -0
- package/dist/chunks/localSearch-CDOJNc_E.js +1 -0
- package/dist/chunks/localSearch-MBx7KzC2.js +1 -0
- package/dist/chunks/lockfile-DBwdlC3K.js +1 -0
- package/dist/chunks/log-CzsijfHZ.js +1 -0
- package/dist/chunks/login-D8UKKaud.js +1 -0
- package/dist/chunks/login-nwTOoyxv.js +1 -0
- package/dist/chunks/logoV2Utils-DDUoPClc.js +1 -0
- package/dist/chunks/logout-B0BjqlGi.js +1 -0
- package/dist/chunks/magicDocs-CmUlOWjI.js +57 -0
- package/dist/chunks/main-C6be1KFk.js +31 -0
- package/dist/chunks/main-CeG_nUsC.js +1108 -0
- package/dist/chunks/mappers-CJ8IO1o1.js +1 -0
- package/dist/chunks/mcp-CanCqnch.js +2 -0
- package/dist/chunks/mcp-Dq0kxZFx.js +6 -0
- package/dist/chunks/mcp-zbxZM9BP.js +1 -0
- package/dist/chunks/mcpServer-DPHQVYdC.js +1 -0
- package/dist/chunks/mcpServer-lIneUZ5p.js +1 -0
- package/dist/chunks/memoize-DNnuA2aU.js +1 -0
- package/dist/chunks/memoize-DxwLawI2.js +1 -0
- package/dist/chunks/memory-BcWBkKV8.js +1 -0
- package/dist/chunks/mobile-umu5P0cM.js +2 -0
- package/dist/chunks/modalContext-CmSKRyea.js +1 -0
- package/dist/chunks/model-DJLzVvcF.js +1 -0
- package/dist/chunks/model-H3rtl6eR.js +1 -0
- package/dist/chunks/normalization-Cox8C0dP.js +1 -0
- package/dist/chunks/oauth-CdZEzMww.js +1 -0
- package/dist/chunks/oauth-CmensepG.js +1 -0
- package/dist/chunks/observationStore-tvkldXUo.js +4 -0
- package/dist/chunks/onChangeAppState-Dxbl8fvk.js +1 -0
- package/dist/chunks/open-CDditBQ-.js +1 -0
- package/dist/chunks/openai-DkYK4THc.js +10 -0
- package/dist/chunks/openaiShared-D5lOejS1.js +16 -0
- package/dist/chunks/output-style-XDb9-2Kk.js +1 -0
- package/dist/chunks/overageCreditGrant-DLKadMYU.js +1 -0
- package/dist/chunks/p-map-9Ud1LOrJ.js +1 -0
- package/dist/chunks/p-map-D7WEmnBE.js +1 -0
- package/dist/chunks/package-BhL7chzt.js +1 -0
- package/dist/chunks/panel-ByW1omJn.js +1 -0
- package/dist/chunks/panel-Bz_8td5D.js +1 -0
- package/dist/chunks/parseConnectUrl-BS6i9JPo.js +1 -0
- package/dist/chunks/parser-CmngCwjB.js +1 -0
- package/dist/chunks/parser-SWIZo39J.js +1 -0
- package/dist/chunks/passes-BIfuerjL.js +1 -0
- package/dist/chunks/path-C4kbwvSH.js +1 -0
- package/dist/chunks/paths-BBvuDQl9.js +39 -0
- package/dist/chunks/permissions-DXLfdE7b.js +1 -0
- package/dist/chunks/permissions-Ps_D01ZB.js +1 -0
- package/dist/chunks/permissions-S2EvIRKj.js +3 -0
- package/dist/chunks/pipeTransport-DVoIA1uN.js +1 -0
- package/dist/chunks/plan--lnWxB3Q.js +1 -0
- package/dist/chunks/platform-CuyedWpe.js +2 -0
- package/dist/chunks/plist-BO4ZqMZc.js +6 -0
- package/dist/chunks/plugin-DWLyrLw4.js +1 -0
- package/dist/chunks/pluginAutoupdate-CGXIWBrb.js +1 -0
- package/dist/chunks/pluginBlocklist-DJrMdzT0.js +1 -0
- package/dist/chunks/pluginCliCommands-C08q9dHk.js +1 -0
- package/dist/chunks/pluginFlagging-Dggxke70.js +1 -0
- package/dist/chunks/pluginOperations-CNCImIe8.js +2 -0
- package/dist/chunks/pluginStartupCheck-BW2fjg2P.js +1 -0
- package/dist/chunks/pluginStartupCheck-DpxQPXJE.js +1 -0
- package/dist/chunks/plugins-DQ3CRWWO.js +4 -0
- package/dist/chunks/policyLimits-BotYrS-v.js +1 -0
- package/dist/chunks/pollConfig-DAQ-ives.js +1 -0
- package/dist/chunks/poller-Ds0Y6Cir.js +1 -0
- package/dist/chunks/poor-DqfrQT61.js +1 -0
- package/dist/chunks/poorMode-DEAe3hiK.js +1 -0
- package/dist/chunks/poorMode-DzYT47KW.js +1 -0
- package/dist/chunks/postCommitAttribution-Ehmwzzuq.js +1 -0
- package/dist/chunks/print-GGVp62vj.js +39 -0
- package/dist/chunks/privacy-settings-agwqjYJo.js +1 -0
- package/dist/chunks/process-CWupreF6.js +1 -0
- package/dist/chunks/process-DMKLUQIO.js +1 -0
- package/dist/chunks/processBashCommand-DHHN8Ca4.js +1 -0
- package/dist/chunks/processSlashCommand-COtIO6Jy.js +6 -0
- package/dist/chunks/projectContext-0fpRKUeH.js +1 -0
- package/dist/chunks/projectContext-eXMSfgdZ.js +1 -0
- package/dist/chunks/prompt-4tea6NJQ.js +54 -0
- package/dist/chunks/prompt-CO160cIr.js +1 -0
- package/dist/chunks/prompt-CjFAtm3w.js +222 -0
- package/dist/chunks/prompt-GY9hlRvI.js +1 -0
- package/dist/chunks/promptEditor-EgosPsy-.js +4 -0
- package/dist/chunks/protocolHandler-mtPUT9U0.js +13 -0
- package/dist/chunks/protocols-CAyQOlkr.js +7 -0
- package/dist/chunks/proxy-CfZp-wce.js +99 -0
- package/dist/chunks/rate-limit-options-C6SFOHue.js +1 -0
- package/dist/chunks/rcDebugLog-CPKZCtR8.js +11 -0
- package/dist/chunks/referral-DeDr9zAE.js +1 -0
- package/dist/chunks/refresh-D7pdoY_X.js +1 -0
- package/dist/chunks/registerProtocol-BZBH8Zgl.js +36 -0
- package/dist/chunks/registry-Dz6AbiYP.js +1 -0
- package/dist/chunks/release-notes-DiUNOrg9.js +4 -0
- package/dist/chunks/releaseNotes-CnhQit0y.js +2 -0
- package/dist/chunks/reload-plugins-Dx52GcaG.js +1 -0
- package/dist/chunks/remote-env-B67Oo3sI.js +1 -0
- package/dist/chunks/remoteBridgeCore-BzSUgPbt.js +1 -0
- package/dist/chunks/remoteControlServer-L8smP7Zu.js +3 -0
- package/dist/chunks/rename-C4PauyTZ.js +1 -0
- package/dist/chunks/renderOptions-BiyC2rj1.js +1 -0
- package/dist/chunks/resume-CrSn26xq.js +2 -0
- package/dist/chunks/rewind-CXplHgh_.js +1 -0
- package/dist/chunks/rollback-DbSpxmJE.js +11 -0
- package/dist/chunks/runtimeObserver-YNy3mIb7.js +1 -0
- package/dist/chunks/runtimeObserver-nAhH4Wca.js +10 -0
- package/dist/chunks/sandbox-adapter-CzwHes1i.js +1 -0
- package/dist/chunks/sandbox-toggle-BYqbcI5d.js +1 -0
- package/dist/chunks/sanitization-CYp-9DbE.js +1 -0
- package/dist/chunks/satisfies-BaHgd_ie.js +1 -0
- package/dist/chunks/schemas-BGAvj1T4.js +40 -0
- package/dist/chunks/sdk-DEtgRZvI.js +1 -0
- package/dist/chunks/sdkHeapDumpMonitor--fevrC5z.js +1 -0
- package/dist/chunks/searchExtraTools-CcpdCO6l.js +1 -0
- package/dist/chunks/semver-Cq33BYay.js +1 -0
- package/dist/chunks/semver-Tw0AFar5.js +1 -0
- package/dist/chunks/sentry-BNVxoVLS.js +13 -0
- package/dist/chunks/server-C5XZSlto.js +1 -0
- package/dist/chunks/server-DzOdtq8A.js +1 -0
- package/dist/chunks/serverBanner-WlSYP-f8.js +1 -0
- package/dist/chunks/serverLog-DtsUvDiY.js +1 -0
- package/dist/chunks/session-BuEmHrqM.js +2 -0
- package/dist/chunks/sessionDataUploader-Ctjo1bgR.js +1 -0
- package/dist/chunks/sessionDiscovery-Mcsfa0g-.js +1 -0
- package/dist/chunks/sessionFileAccessHooks-qnNiGMnE.js +1 -0
- package/dist/chunks/sessionManager-Dw72ZUTg.js +1 -0
- package/dist/chunks/sessionMemory-CMahwDdW.js +1 -0
- package/dist/chunks/sessionMemory-pFSn4HSN.js +1 -0
- package/dist/chunks/sessionMemoryUtils-Du5jUl7M.js +1 -0
- package/dist/chunks/sessionObserver-DG2zQgfi.js +20 -0
- package/dist/chunks/sessionObserver-Je868MC9.js +1 -0
- package/dist/chunks/sessionStorage-D3FhAADV.js +1 -0
- package/dist/chunks/sessionStoragePortable-BI9q2WcJ.js +3 -0
- package/dist/chunks/sessionTitle-zUVSAHO7.js +14 -0
- package/dist/chunks/sessionTracing-DoRJ4nSa.js +11 -0
- package/dist/chunks/settingsSync-B9bz77E1.js +1 -0
- package/dist/chunks/setup-B1JbPepL.js +9 -0
- package/dist/chunks/setup-CCOLlRtP.js +1 -0
- package/dist/chunks/setup-DWkSjA49.js +2 -0
- package/dist/chunks/shadowedRuleDetection-BBR3uEgx.js +1 -0
- package/dist/chunks/shellQuote-DgjT8KBA.js +1 -0
- package/dist/chunks/sideQuestion-DHW5rgKz.js +20 -0
- package/dist/chunks/signin-QEeYpJZw.js +1 -0
- package/dist/chunks/sink-DxDOsLa2.js +1 -0
- package/dist/chunks/sink-cQOgsnw3.js +1 -0
- package/dist/chunks/sinks-BrrTUxkC.js +2 -0
- package/dist/chunks/sinks-Djiz_5-Z.js +1 -0
- package/dist/chunks/skill-learning-C0nOKZfg.js +5 -0
- package/dist/chunks/skillChangeDetector-D8C-uQSQ.js +1 -0
- package/dist/chunks/skillGapStore-Czi5jKjJ.js +1 -0
- package/dist/chunks/skillGapStore-_YuJP5KI.js +5 -0
- package/dist/chunks/skillGenerator-kbaRbpqJ.js +8 -0
- package/dist/chunks/skillLearning-3KWrBczS.js +1 -0
- package/dist/chunks/skillLearning-DBbdGbk-.js +1 -0
- package/dist/chunks/skillPanel-BxDvlPzd.js +28 -0
- package/dist/chunks/skillSearchPanel-D-MX6Qgt.js +21 -0
- package/dist/chunks/skills-NpEgFkFZ.js +1 -0
- package/dist/chunks/slashCommandParsing-Cari0pNg.js +1 -0
- package/dist/chunks/sleep-8Eb9j_Ly.js +1 -0
- package/dist/chunks/sprites-DD4eIkN7.js +1 -0
- package/dist/chunks/src-BIPP3_mo.js +26 -0
- package/dist/chunks/src-BJz1KAd_.js +6 -0
- package/dist/chunks/src-BRAdBA8A.js +1 -0
- package/dist/chunks/src-BRC_BuUP.js +1 -0
- package/dist/chunks/src-BaB-bpCj.js +5 -0
- package/dist/chunks/src-BlLavFUS.js +7 -0
- package/dist/chunks/src-C5yhFG0C.js +19 -0
- package/dist/chunks/src-CI_jaaBj.js +2 -0
- package/dist/chunks/src-CRsA-Z4y.js +1 -0
- package/dist/chunks/src-CYLfL70h.js +1 -0
- package/dist/chunks/src-DJXCzwyJ.js +1 -0
- package/dist/chunks/src-DJXKJavk.js +1 -0
- package/dist/chunks/src-Di342QoJ.js +53 -0
- package/dist/chunks/src-DsMd9Q9e.js +2 -0
- package/dist/chunks/src-DzH9IdOo.js +1 -0
- package/dist/chunks/src-hdbPEvzO.js +9 -0
- package/dist/chunks/src-poaoYkuc.js +1 -0
- package/dist/chunks/src-x7u_sB6m.js +1 -0
- package/dist/chunks/sso-oidc-BX1MlBX0.js +1 -0
- package/dist/chunks/startupProfiler-DnXZaX4A.js +3 -0
- package/dist/chunks/startupProfiler-SOE--nM9.js +1 -0
- package/dist/chunks/state-B2GIOsTB.js +1 -0
- package/dist/chunks/state-Ce1HlR-H.js +1 -0
- package/dist/chunks/state-sIHsFpDu.js +1 -0
- package/dist/chunks/staticRender-Br64h1E1.js +1 -0
- package/dist/chunks/stats-xL3NHwhp.js +1 -0
- package/dist/chunks/status-B5E70xRv.js +1 -0
- package/dist/chunks/statusNoticeHelpers-DcssRhLw.js +1 -0
- package/dist/chunks/stdio-BEEzuxaZ.js +1 -0
- package/dist/chunks/stdio-D4cT86R0.js +3 -0
- package/dist/chunks/stickers-2K05wjSp.js +1 -0
- package/dist/chunks/store-DhI7Lcan.js +1 -0
- package/dist/chunks/sts-BDFJ-6QE.js +1 -0
- package/dist/chunks/subprocessEnv-CggQWZCx.js +1 -0
- package/dist/chunks/subprocessEnv-DV6q6o6w.js +1 -0
- package/dist/chunks/supports-color-lkzOMQ6u.js +1 -0
- package/dist/chunks/systemPromptSections-BcN_XBTx.js +1 -0
- package/dist/chunks/systemPromptSections-DB93ZNWP.js +1 -0
- package/dist/chunks/systemTheme-dDbitcxB.js +1 -0
- package/dist/chunks/tag-BELr-qIa.js +11 -0
- package/dist/chunks/tasks-CrdWcSt-.js +1 -0
- package/dist/chunks/teamHelpers--3ZyNDlv.js +1 -0
- package/dist/chunks/teamHelpers-CUAiXng3.js +1 -0
- package/dist/chunks/teammate-DMYOtLTK.js +1 -0
- package/dist/chunks/teammateModeSnapshot-C6EWhR0X.js +1 -0
- package/dist/chunks/teammateModeSnapshot-DOQMTKbQ.js +1 -0
- package/dist/chunks/teleport-LXFOan9C.js +1 -0
- package/dist/chunks/templateJobs-8IY2Cgig.js +12 -0
- package/dist/chunks/terminalSetup-C4psrmpb.js +1 -0
- package/dist/chunks/terminalSetup-Lyg4NbGA.js +33 -0
- package/dist/chunks/theme-B8GNnJ_q.js +1 -0
- package/dist/chunks/thinkback-DPXwEK3B.js +1 -0
- package/dist/chunks/thinkback-DZW3Mcx_.js +1 -0
- package/dist/chunks/thinkback-play-BMOE-ceh.js +1 -0
- package/dist/chunks/tmux-CvbhsfwG.js +1 -0
- package/dist/chunks/toolEventObserver-D0TSHm01.js +1 -0
- package/dist/chunks/toolEventObserver-DzLd0MSn.js +1 -0
- package/dist/chunks/toolPool-DVOfpjDz.js +1 -0
- package/dist/chunks/toolPool-Dq-Vtvrj.js +1 -0
- package/dist/chunks/trustedDevice-1iTu4LEm.js +1 -0
- package/dist/chunks/trustedDevice-BvYYXfd8.js +1 -0
- package/dist/chunks/tui-BVc2q4Xv.js +6 -0
- package/dist/chunks/turndown.es-Bv06VjMb.js +69 -0
- package/dist/chunks/types-CQ1wrnQ0.js +1 -0
- package/dist/chunks/types-Csi32ZXh.js +17 -0
- package/dist/chunks/types-RJTEOuIt.js +3 -0
- package/dist/chunks/udsClient-BvG_Jip0.js +1 -0
- package/dist/chunks/ultrareviewCommand-BTXAN2wP.js +3 -0
- package/dist/chunks/undercover-C_44e3oN.js +1 -0
- package/dist/chunks/undercover-DvvnEmsX.js +31 -0
- package/dist/chunks/up-D-U4wUCe.js +12 -0
- package/dist/chunks/updateCCB-C-qfLi0j.js +11 -0
- package/dist/chunks/upgrade-CGXa5Dwy.js +1 -0
- package/dist/chunks/upgrade-DTBZSxwv.js +1 -0
- package/dist/chunks/upload-BF8tf_Eo.js +1 -0
- package/dist/chunks/upstreamproxy-DcLeL2XX.js +11 -0
- package/dist/chunks/usage-BRYRRgNt.js +1 -0
- package/dist/chunks/usage-DvSTXEYY.js +1 -0
- package/dist/chunks/useKeybinding-FsOnjW6T.js +1 -0
- package/dist/chunks/useMainLoopModel-CwvuTRXn.js +1 -0
- package/dist/chunks/useManagePlugins-GmnI9K53.js +1 -0
- package/dist/chunks/useMergedTools-Dah5KDMi.js +1 -0
- package/dist/chunks/useSearchInput-BV_azHiA.js +1 -0
- package/dist/chunks/useSettingsErrors-C-j_Zt7g.js +1 -0
- package/dist/chunks/useVoice-DR69NLxp.js +1 -0
- package/dist/chunks/util-BpyJ4Bom.js +1 -0
- package/dist/chunks/utils-CrZcpypC.js +1 -0
- package/dist/chunks/v4-f1i_CNUT.js +1 -0
- package/dist/chunks/validatePlugin-vptAYuYu.js +1 -0
- package/dist/chunks/vertex-sdk-CSGw3fvU.js +9 -0
- package/dist/chunks/vim-DvOw8dfR.js +1 -0
- package/dist/chunks/voice-B3BZs53f.js +2 -0
- package/dist/chunks/voice-DXiiy8HX.js +8 -0
- package/dist/chunks/voiceModeEnabled-DA76xN1Q.js +1 -0
- package/dist/chunks/voiceModeEnabled-DIveLYGb.js +1 -0
- package/dist/chunks/voiceStreamSTT-_w1VjIOs.js +1 -0
- package/dist/chunks/voiceStreamSTT-hpzWd_zl.js +1 -0
- package/dist/chunks/which-DqSAIvp2.js +1 -0
- package/dist/chunks/windowsPaths-C9CigqoF.js +1 -0
- package/dist/chunks/windowsPaths-swxCp7bX.js +2 -0
- package/dist/chunks/workSecret-mS2OrpxF.js +1 -0
- package/dist/chunks/workerRegistry-2_MZVih1.js +1 -0
- package/dist/chunks/worktree-CCuDwRmS.js +1 -0
- package/dist/chunks/worktreeModeEnabled-Db6b_Iy_.js +1 -0
- package/dist/chunks/worktreeModeEnabled-THQb19xR.js +1 -0
- package/dist/chunks/wrapper-BSK0MCQH.js +1 -0
- package/dist/chunks/wrapper-D5qL1aQL.js +6 -0
- package/dist/chunks/xdg-CBxMmQux.js +1 -0
- package/dist/chunks/xml-Dx--sNE1.js +1 -0
- package/dist/chunks/zod-DT6hytkp.js +1 -0
- package/dist/cli.js +1 -10978
- package/package.json +1 -1
|
@@ -0,0 +1,1561 @@
|
|
|
1
|
+
import{a as e,n as t,r as n}from"./chunk-DR8-3Aex.js";import{L as r,V as i,d as a,s as o}from"./debug-UI3T040K.js";import{r as s,t as c}from"./execFileNoThrow-CuQN1sz8.js";import{n as l,t as u}from"./sleep-8Eb9j_Ly.js";import{a as ee,n as te,o as ne,t as re}from"./common-B379wT22.js";import{a as ie,o as ae,t as oe}from"./src-BlLavFUS.js";import{a as d,c as f,d as se,l as ce,n as le,o as ue,s as de,t as fe,u as pe}from"./escHotkey-Cyz0yyh1.js";import*as me from"path";import{extname as he}from"path";import*as p from"fs";import{promisify as ge}from"util";import{execFile as _e,execFileSync as ve}from"child_process";var ye=n({getFrontmostAppInfo:()=>Me,key:()=>Ee,keys:()=>De,mouseButton:()=>ke,mouseLocation:()=>Oe,mouseScroll:()=>Ae,moveMouse:()=>Te,typeText:()=>je});async function be(e){let{stdout:t}=await Se(`osascript`,[`-e`,e],{encoding:`utf-8`});return t.trim()}async function m(e){let{stdout:t}=await Se(`osascript`,[`-l`,`JavaScript`,`-e`,e],{encoding:`utf-8`});return t.trim()}function xe(e,t,n,r,i){let a=`ObjC.import("CoreGraphics"); var p = $.CGPointMake(${t},${n}); var e = $.CGEventCreateMouseEvent(null, $.${e}, p, ${r});`;return i!==void 0&&(a+=` $.CGEventSetIntegerValueField(e, $.kCGMouseEventClickState, ${i});`),a+=` $.CGEventPost($.kCGHIDEventTap, e);`,a}var Se,Ce,we,Te,Ee,De,Oe,ke,Ae,je,Me,Ne=t((()=>{Se=ge(_e),Ce={return:36,enter:36,tab:48,space:49,delete:51,backspace:51,escape:53,esc:53,left:123,right:124,down:125,up:126,f1:122,f2:120,f3:99,f4:118,f5:96,f6:97,f7:98,f8:100,f9:101,f10:109,f11:103,f12:111,home:115,end:119,pageup:116,pagedown:121},we={command:`command down`,cmd:`command down`,meta:`command down`,super:`command down`,shift:`shift down`,option:`option down`,alt:`option down`,control:`control down`,ctrl:`control down`},Te=async(e,t,n)=>{await m(xe(`kCGEventMouseMoved`,e,t,0))},Ee=async(e,t)=>{if(t===`release`)return;let n=e.toLowerCase(),r=Ce[n];r===void 0?await be(`tell application "System Events" to keystroke "${e.length===1?e:n}"`):await be(`tell application "System Events" to key code ${r}`)},De=async e=>{let t=[],n=null;for(let r of e){let e=we[r.toLowerCase()];e?t.push(e):n=r}if(!n)return;let r=n.toLowerCase(),i=Ce[r],a=t.length>0?` using {${t.join(`, `)}}`:``;i===void 0?await be(`tell application "System Events" to keystroke "${n.length===1?n:r}"${a}`):await be(`tell application "System Events" to key code ${i}${a}`)},Oe=async()=>{let[e,t]=(await m(`ObjC.import("CoreGraphics"); var e = $.CGEventCreate(null); var p = $.CGEventGetLocation(e); p.x + "," + p.y`)).split(`,`);return{x:Math.round(Number(e)),y:Math.round(Number(t))}},ke=async(e,t,n)=>{let r=await Oe(),i=e===`left`?0:e===`right`?1:2,a=i===0?`kCGEventLeftMouseDown`:i===1?`kCGEventRightMouseDown`:`kCGEventOtherMouseDown`,o=i===0?`kCGEventLeftMouseUp`:i===1?`kCGEventRightMouseUp`:`kCGEventOtherMouseUp`;if(t===`click`)for(let e=0;e<(n??1);e++)await m(xe(a,r.x,r.y,i,e+1)),await m(xe(o,r.x,r.y,i,e+1));else t===`press`?await m(xe(a,r.x,r.y,i)):await m(xe(o,r.x,r.y,i))},Ae=async(e,t)=>{await m(t===`vertical`?`ObjC.import("CoreGraphics"); var e = $.CGEventCreateScrollWheelEvent(null, 0, 1, ${e}); $.CGEventPost($.kCGHIDEventTap, e);`:`ObjC.import("CoreGraphics"); var e = $.CGEventCreateScrollWheelEvent(null, 0, 2, 0, ${e}); $.CGEventPost($.kCGHIDEventTap, e);`)},je=async e=>{await be(`tell application "System Events" to keystroke "${e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`)}"`)},Me=()=>{try{let e=ve(`osascript`,[`-e`,`
|
|
2
|
+
tell application "System Events"
|
|
3
|
+
set frontApp to first application process whose frontmost is true
|
|
4
|
+
set appName to name of frontApp
|
|
5
|
+
set bundleId to bundle identifier of frontApp
|
|
6
|
+
return bundleId & "|" & appName
|
|
7
|
+
end tell
|
|
8
|
+
`],{encoding:`utf-8`,stdio:[`pipe`,`pipe`,`ignore`]}).trim();if(!e||!e.includes(`|`))return null;let[t,n]=e.split(`|`,2);return{bundleId:t,appName:n}}catch{return null}}})),Pe=n({getFrontmostAppInfo:()=>We,key:()=>Ve,keys:()=>He,mouseButton:()=>ze,mouseLocation:()=>Re,mouseScroll:()=>Be,moveMouse:()=>Le,typeText:()=>Ue});function h(e){let t=Bun.spawnSync({cmd:[`powershell`,`-NoProfile`,`-NonInteractive`,`-Command`,e],stdout:`pipe`,stderr:`pipe`});return new TextDecoder().decode(t.stdout).trim()}var g,Fe,Ie,Le,Re,ze,Be,Ve,He,Ue,We,Ge=t((()=>{g=`
|
|
9
|
+
Add-Type -Language CSharp @'
|
|
10
|
+
using System;
|
|
11
|
+
using System.Runtime.InteropServices;
|
|
12
|
+
using System.Text;
|
|
13
|
+
using System.Diagnostics;
|
|
14
|
+
|
|
15
|
+
public class CuWin32 {
|
|
16
|
+
// --- Cursor ---
|
|
17
|
+
[DllImport("user32.dll")] public static extern bool SetCursorPos(int X, int Y);
|
|
18
|
+
[DllImport("user32.dll")] public static extern bool GetCursorPos(out POINT p);
|
|
19
|
+
[StructLayout(LayoutKind.Sequential)] public struct POINT { public int X; public int Y; }
|
|
20
|
+
|
|
21
|
+
// --- SendInput ---
|
|
22
|
+
[StructLayout(LayoutKind.Sequential)] public struct MOUSEINPUT {
|
|
23
|
+
public int dx; public int dy; public int mouseData; public uint dwFlags; public uint time; public IntPtr dwExtraInfo;
|
|
24
|
+
}
|
|
25
|
+
[StructLayout(LayoutKind.Explicit)] public struct INPUT {
|
|
26
|
+
[FieldOffset(0)] public uint type;
|
|
27
|
+
[FieldOffset(4)] public MOUSEINPUT mi;
|
|
28
|
+
}
|
|
29
|
+
[StructLayout(LayoutKind.Sequential)] public struct KEYBDINPUT {
|
|
30
|
+
public ushort wVk; public ushort wScan; public uint dwFlags; public uint time; public IntPtr dwExtraInfo;
|
|
31
|
+
}
|
|
32
|
+
[StructLayout(LayoutKind.Explicit)] public struct KINPUT {
|
|
33
|
+
[FieldOffset(0)] public uint type;
|
|
34
|
+
[FieldOffset(4)] public KEYBDINPUT ki;
|
|
35
|
+
}
|
|
36
|
+
[DllImport("user32.dll", SetLastError=true)] public static extern uint SendInput(uint n, INPUT[] i, int cb);
|
|
37
|
+
[DllImport("user32.dll", SetLastError=true)] public static extern uint SendInput(uint n, KINPUT[] i, int cb);
|
|
38
|
+
|
|
39
|
+
// --- Keyboard ---
|
|
40
|
+
[DllImport("user32.dll")] public static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, UIntPtr dwExtraInfo);
|
|
41
|
+
[DllImport("user32.dll")] public static extern short VkKeyScan(char ch);
|
|
42
|
+
|
|
43
|
+
// --- Window ---
|
|
44
|
+
[DllImport("user32.dll")] public static extern IntPtr GetForegroundWindow();
|
|
45
|
+
[DllImport("user32.dll")] public static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint pid);
|
|
46
|
+
[DllImport("user32.dll", CharSet=CharSet.Unicode)] public static extern int GetWindowText(IntPtr hWnd, StringBuilder sb, int max);
|
|
47
|
+
|
|
48
|
+
// Constants
|
|
49
|
+
public const uint INPUT_MOUSE = 0, INPUT_KEYBOARD = 1;
|
|
50
|
+
public const uint MOUSEEVENTF_LEFTDOWN = 0x0002, MOUSEEVENTF_LEFTUP = 0x0004;
|
|
51
|
+
public const uint MOUSEEVENTF_RIGHTDOWN = 0x0008, MOUSEEVENTF_RIGHTUP = 0x0010;
|
|
52
|
+
public const uint MOUSEEVENTF_MIDDLEDOWN = 0x0020, MOUSEEVENTF_MIDDLEUP = 0x0040;
|
|
53
|
+
public const uint MOUSEEVENTF_WHEEL = 0x0800, MOUSEEVENTF_HWHEEL = 0x1000;
|
|
54
|
+
public const uint KEYEVENTF_KEYUP = 0x0002;
|
|
55
|
+
}
|
|
56
|
+
'@
|
|
57
|
+
`,Fe={return:13,enter:13,tab:9,space:32,backspace:8,delete:46,escape:27,esc:27,left:37,up:38,right:39,down:40,home:36,end:35,pageup:33,pagedown:34,f1:112,f2:113,f3:114,f4:115,f5:116,f6:117,f7:118,f8:119,f9:120,f10:121,f11:122,f12:123,shift:160,lshift:160,rshift:161,control:162,ctrl:162,lcontrol:162,rcontrol:163,alt:164,option:164,lalt:164,ralt:165,win:91,meta:91,command:91,cmd:91,super:91,insert:45,printscreen:44,pause:19,numlock:144,capslock:20,scrolllock:145},Ie=new Set([`shift`,`lshift`,`rshift`,`control`,`ctrl`,`lcontrol`,`rcontrol`,`alt`,`option`,`lalt`,`ralt`,`win`,`meta`,`command`,`cmd`,`super`]),Le=async(e,t,n)=>{h(`${g}; [CuWin32]::SetCursorPos(${Math.round(e)}, ${Math.round(t)}) | Out-Null`)},Re=async()=>{let[e,t]=h(`${g}; $p = New-Object CuWin32+POINT; [CuWin32]::GetCursorPos([ref]$p) | Out-Null; "$($p.X),$($p.Y)"`).split(`,`);return{x:Number(e),y:Number(t)}},ze=async(e,t,n)=>{let r=e===`left`?`MOUSEEVENTF_LEFTDOWN`:e===`right`?`MOUSEEVENTF_RIGHTDOWN`:`MOUSEEVENTF_MIDDLEDOWN`,i=e===`left`?`MOUSEEVENTF_LEFTUP`:e===`right`?`MOUSEEVENTF_RIGHTUP`:`MOUSEEVENTF_MIDDLEUP`;if(t===`click`){let e=n??1,t=``;for(let n=0;n<e;n++)t+=`$i.mi.dwFlags=[CuWin32]::${r}; [CuWin32]::SendInput(1, @($i), [Runtime.InteropServices.Marshal]::SizeOf($i)) | Out-Null; $i.mi.dwFlags=[CuWin32]::${i}; [CuWin32]::SendInput(1, @($i), [Runtime.InteropServices.Marshal]::SizeOf($i)) | Out-Null; `;h(`${g}; $i = New-Object CuWin32+INPUT; $i.type=[CuWin32]::INPUT_MOUSE; ${t}`)}else h(t===`press`?`${g}; $i = New-Object CuWin32+INPUT; $i.type=[CuWin32]::INPUT_MOUSE; $i.mi.dwFlags=[CuWin32]::${r}; [CuWin32]::SendInput(1, @($i), [Runtime.InteropServices.Marshal]::SizeOf($i)) | Out-Null`:`${g}; $i = New-Object CuWin32+INPUT; $i.type=[CuWin32]::INPUT_MOUSE; $i.mi.dwFlags=[CuWin32]::${i}; [CuWin32]::SendInput(1, @($i), [Runtime.InteropServices.Marshal]::SizeOf($i)) | Out-Null`)},Be=async(e,t)=>{h(`${g}; $i = New-Object CuWin32+INPUT; $i.type=[CuWin32]::INPUT_MOUSE; $i.mi.dwFlags=[CuWin32]::${t===`vertical`?`MOUSEEVENTF_WHEEL`:`MOUSEEVENTF_HWHEEL`}; $i.mi.mouseData=${e*120}; [CuWin32]::SendInput(1, @($i), [Runtime.InteropServices.Marshal]::SizeOf($i)) | Out-Null`)},Ve=async(e,t)=>{let n=Fe[e.toLowerCase()],r=t===`release`?`2`:`0`;n===void 0?e.length===1&&h(`${g}; $vk = [CuWin32]::VkKeyScan([char]${e.charCodeAt(0)}) -band 0xFF; [CuWin32]::keybd_event([byte]$vk, 0, ${r}, [UIntPtr]::Zero)`):h(`${g}; [CuWin32]::keybd_event(${n}, 0, ${r}, [UIntPtr]::Zero)`)},He=async e=>{let t=[],n=null;for(let r of e){let e=r.toLowerCase();if(Ie.has(e)){let n=Fe[e];n!==void 0&&t.push(n)}else n=r}if(!n)return;let r=g+`; `;for(let e of t)r+=`[CuWin32]::keybd_event(${e}, 0, 0, [UIntPtr]::Zero); `;let i=Fe[n.toLowerCase()];if(i!==void 0)r+=`[CuWin32]::keybd_event(${i}, 0, 0, [UIntPtr]::Zero); [CuWin32]::keybd_event(${i}, 0, 2, [UIntPtr]::Zero); `;else if(n.length===1){let e=n.charCodeAt(0);r+=`$vk = [CuWin32]::VkKeyScan([char]${e}) -band 0xFF; [CuWin32]::keybd_event([byte]$vk, 0, 0, [UIntPtr]::Zero); [CuWin32]::keybd_event([byte]$vk, 0, 2, [UIntPtr]::Zero); `}for(let e of t.reverse())r+=`[CuWin32]::keybd_event(${e}, 0, 2, [UIntPtr]::Zero); `;h(r)},Ue=async e=>{h(`Add-Type -AssemblyName System.Windows.Forms; [System.Windows.Forms.SendKeys]::SendWait('${e.replace(/'/g,`''`)}')`)},We=()=>{try{let e=h(`${g}
|
|
58
|
+
$hwnd = [CuWin32]::GetForegroundWindow()
|
|
59
|
+
$procId = [uint32]0
|
|
60
|
+
[CuWin32]::GetWindowThreadProcessId($hwnd, [ref]$procId) | Out-Null
|
|
61
|
+
$proc = Get-Process -Id $procId -ErrorAction SilentlyContinue
|
|
62
|
+
"$($proc.MainModule.FileName)|$($proc.ProcessName)"`);if(!e||!e.includes(`|`))return null;let[t,n]=e.split(`|`,2);return{bundleId:t,appName:n}}catch{return null}}})),Ke=n({getFrontmostAppInfo:()=>it,key:()=>tt,keys:()=>nt,mouseButton:()=>$e,mouseLocation:()=>Qe,mouseScroll:()=>et,moveMouse:()=>Ze,typeText:()=>rt});function _(e){let t=Bun.spawnSync({cmd:e,stdout:`pipe`,stderr:`pipe`});return new TextDecoder().decode(t.stdout).trim()}function qe(e){return Ye[e.toLowerCase()]??e}function Je(e){return e===`left`?`1`:e===`right`?`3`:`2`}var Ye,Xe,Ze,Qe,$e,et,tt,nt,rt,it,at=t((()=>{Ye={return:`Return`,enter:`Return`,tab:`Tab`,space:`space`,backspace:`BackSpace`,delete:`Delete`,escape:`Escape`,esc:`Escape`,left:`Left`,up:`Up`,right:`Right`,down:`Down`,home:`Home`,end:`End`,pageup:`Prior`,pagedown:`Next`,f1:`F1`,f2:`F2`,f3:`F3`,f4:`F4`,f5:`F5`,f6:`F6`,f7:`F7`,f8:`F8`,f9:`F9`,f10:`F10`,f11:`F11`,f12:`F12`,shift:`shift`,lshift:`shift`,rshift:`shift`,control:`ctrl`,ctrl:`ctrl`,lcontrol:`ctrl`,rcontrol:`ctrl`,alt:`alt`,option:`alt`,lalt:`alt`,ralt:`alt`,win:`super`,meta:`super`,command:`super`,cmd:`super`,super:`super`,insert:`Insert`,printscreen:`Print`,pause:`Pause`,numlock:`Num_Lock`,capslock:`Caps_Lock`,scrolllock:`Scroll_Lock`},Xe=new Set([`shift`,`lshift`,`rshift`,`control`,`ctrl`,`lcontrol`,`rcontrol`,`alt`,`option`,`lalt`,`ralt`,`win`,`meta`,`command`,`cmd`,`super`]),Ze=async(e,t,n)=>{_([`xdotool`,`mousemove`,`--sync`,String(Math.round(e)),String(Math.round(t))])},Qe=async()=>{let e=_([`xdotool`,`getmouselocation`]),t=e.match(/x:(\d+)/),n=e.match(/y:(\d+)/);return{x:t?Number(t[1]):0,y:n?Number(n[1]):0}},$e=async(e,t,n)=>{let r=Je(e);_(t===`click`?[`xdotool`,`click`,`--repeat`,String(n??1),r]:t===`press`?[`xdotool`,`mousedown`,r]:[`xdotool`,`mouseup`,r])},et=async(e,t)=>{if(t===`vertical`){let t=e>=0?`5`:`4`,n=Math.abs(Math.round(e));n>0&&_([`xdotool`,`click`,`--repeat`,String(n),t])}else{let t=e>=0?`7`:`6`,n=Math.abs(Math.round(e));n>0&&_([`xdotool`,`click`,`--repeat`,String(n),t])}},tt=async(e,t)=>{let n=qe(e);_(t===`press`?[`xdotool`,`keydown`,n]:[`xdotool`,`keyup`,n])},nt=async e=>{let t=[],n=null;for(let r of e)Xe.has(r.toLowerCase())?t.push(qe(r)):n=r;n&&_([`xdotool`,`key`,[...t,qe(n)].join(`+`)])},rt=async e=>{_([`xdotool`,`type`,`--delay`,`12`,e])},it=()=>{try{let e=_([`xdotool`,`getactivewindow`]);if(!e)return null;let t=_([`xdotool`,`getwindowpid`,e]);if(!t)return null;let n=t.trim(),r=``;try{r=_([`readlink`,`-f`,`/proc/${n}/exe`])}catch{}let i=``;try{i=_([`cat`,`/proc/${n}/comm`])}catch{}return!r&&!i?null:{bundleId:r||`/proc/${n}/exe`,appName:i||`unknown`}}catch{return null}}})),ot=n({ComputerUseInputAPI:()=>_t,getFrontmostAppInfo:()=>gt,isSupported:()=>ct,key:()=>ut,keys:()=>dt,mouseButton:()=>pt,mouseLocation:()=>ft,mouseScroll:()=>mt,moveMouse:()=>lt,typeText:()=>ht});function st(){try{if(process.platform===`darwin`)return Ne(),e(ye);if(process.platform===`win32`)return Ge(),e(Pe);if(process.platform===`linux`)return at(),e(Ke)}catch{return null}return null}var v,ct,lt,ut,dt,ft,pt,mt,ht,gt,_t,vt=t((()=>{v=st(),ct=v!==null,lt=v?.moveMouse,ut=v?.key,dt=v?.keys,ft=v?.mouseLocation,pt=v?.mouseButton,mt=v?.mouseScroll,ht=v?.typeText,gt=v?.getFrontmostAppInfo??(()=>null),_t=class{}}));function y(){if(yt)return yt;let t=(vt(),e(ot));if(!t.isSupported)throw Error(`@ant/computer-use-input is not supported on this platform`);return yt=t}var yt,bt=t((()=>{})),xt=n({MODIFIER_KEYS:()=>Tt,VK_MAP:()=>wt,getTmpDir:()=>Ct,ps:()=>x,psAsync:()=>St,runPs:()=>S,validateHwnd:()=>b});function b(e){if(!/^\d+$/.test(e))throw Error(`Invalid HWND: "${e}" — must be numeric`);return e}function x(e){let t=Bun.spawnSync({cmd:[`powershell`,`-NoProfile`,`-NonInteractive`,`-Command`,e],stdout:`pipe`,stderr:`pipe`});return new TextDecoder().decode(t.stdout).trim()}function S(e){try{let t=Bun.spawnSync({cmd:[`powershell`,`-NoProfile`,`-NonInteractive`,`-Command`,e],stdout:`pipe`,stderr:`pipe`});return t.exitCode===0?new TextDecoder().decode(t.stdout).trim():null}catch{return null}}async function St(e){let t=Bun.spawn([`powershell`,`-NoProfile`,`-NonInteractive`,`-Command`,e],{stdout:`pipe`,stderr:`pipe`}),n=await new Response(t.stdout).text();return await t.exited,n.trim()}function Ct(){return process.env.TEMP||process.env.TMP||`/tmp`}var wt,Tt,C=t((()=>{wt={backspace:8,tab:9,enter:13,return:13,shift:16,lshift:160,rshift:161,ctrl:17,control:17,lcontrol:162,rcontrol:163,alt:18,option:18,menu:18,lalt:164,ralt:165,pause:19,capslock:20,escape:27,esc:27,space:32,pageup:33,pagedown:34,end:35,home:36,left:37,up:38,right:39,down:40,insert:45,delete:46,win:91,meta:91,command:91,cmd:91,super:91,numlock:144,scrolllock:145,printscreen:44,f1:112,f2:113,f3:114,f4:115,f5:116,f6:117,f7:118,f8:119,f9:120,f10:121,f11:122,f12:123},Tt=new Set([`shift`,`lshift`,`rshift`,`control`,`ctrl`,`lcontrol`,`rcontrol`,`alt`,`option`,`lalt`,`ralt`,`win`,`meta`,`command`,`cmd`,`super`])})),Et=n({platform:()=>jt}),Dt,Ot,kt,At,jt,Mt=t((()=>{bt(),de(),Dt={async moveMouse(e,t){await y().moveMouse(e,t,!1)},async click(e,t,n){let r=y();await r.moveMouse(e,t,!1),await r.mouseButton(n,`click`,1)},async typeText(e){await y().typeText(e)},async key(e,t){await y().key(e,t)},async keys(e){await y().keys(e)},async scroll(e,t){await y().mouseScroll(e,t)},async mouseLocation(){return y().mouseLocation()}},Ot={async captureScreen(e){return f().screenshot.captureExcluding([],void 0,void 0,void 0,e)},async captureRegion(e,t,n,r){return f().screenshot.captureRegion([],e,t,n,r)}},kt={listAll(){return f().display.listAll()},getSize(e){return f().display.getSize(e)}},At={listRunning(){return f().apps.listRunning().map(e=>({id:e.bundleId??``,pid:0,title:e.displayName??``}))},async listInstalled(){return(await f().apps.listInstalled()).map(e=>({id:e.bundleId??``,displayName:e.displayName??``,path:e.path??``}))},async open(e){await f().apps.open(e)},getFrontmostApp(){let e=y().getFrontmostAppInfo();return e?{id:e.bundleId,appName:e.appName}:null},findWindowByTitle(e){return this.listRunning().find(t=>t.title.includes(e))??null}},jt={input:Dt,screenshot:Ot,display:kt,apps:At}})),Nt=n({closeExcel:()=>Ut,createExcel:()=>Ht,openExcel:()=>Ft,readCell:()=>It,readRange:()=>Lt,saveExcel:()=>Vt,setFormula:()=>Bt,writeCell:()=>Rt,writeRange:()=>zt});function w(e){let t=Bun.spawnSync({cmd:[`powershell`,`-NoProfile`,`-NonInteractive`,`-Command`,e],stdout:`pipe`,stderr:`pipe`}),n=new TextDecoder().decode(t.stderr).trim();if(t.exitCode!==0&&n)throw Error(`PowerShell error: ${n}`);return new TextDecoder().decode(t.stdout).trim()}function T(e){return e.replace(/'/g,`''`)}function Pt(e,t){return typeof t==`number`?`$${e} = $wb.Sheets.Item(${t})`:`$${e} = $wb.Sheets.Item('${t.replace(/'/g,`''`)}')`}function E(e=!0){let t=[];return e&&t.push(`if ($wb) { $wb.Close($false) }`),t.push(`$excel.Quit()`),t.push(`[System.Runtime.InteropServices.Marshal]::ReleaseComObject($excel) | Out-Null`),t.join(`
|
|
63
|
+
`)}function Ft(e){let t=w(`
|
|
64
|
+
${D}
|
|
65
|
+
try {
|
|
66
|
+
$wb = $excel.Workbooks.Open('${T(e)}')
|
|
67
|
+
$result = @{ sheets = @(); sheetNames = @() }
|
|
68
|
+
foreach ($sheet in $wb.Sheets) {
|
|
69
|
+
$result.sheetNames += $sheet.Name
|
|
70
|
+
$ur = $sheet.UsedRange
|
|
71
|
+
$rows = $ur.Rows.Count
|
|
72
|
+
$cols = $ur.Columns.Count
|
|
73
|
+
$cells = @()
|
|
74
|
+
$count = 0
|
|
75
|
+
for ($r = 1; $r -le $rows -and $count -lt 1000; $r++) {
|
|
76
|
+
for ($c = 1; $c -le $cols -and $count -lt 1000; $c++) {
|
|
77
|
+
$cell = $sheet.Cells.Item($r, $c)
|
|
78
|
+
$val = $cell.Value2
|
|
79
|
+
if ($null -ne $val) {
|
|
80
|
+
$f = $null
|
|
81
|
+
if ($cell.HasFormula) { $f = $cell.Formula }
|
|
82
|
+
$entry = @{ row = $r; col = $c; value = $val }
|
|
83
|
+
if ($f) { $entry.formula = $f }
|
|
84
|
+
$cells += $entry
|
|
85
|
+
$count++
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
$result.sheets += @{
|
|
90
|
+
name = $sheet.Name
|
|
91
|
+
usedRange = @{ rows = $rows; cols = $cols }
|
|
92
|
+
cells = $cells
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
$result | ConvertTo-Json -Depth 5 -Compress
|
|
96
|
+
} finally {
|
|
97
|
+
${E()}
|
|
98
|
+
}
|
|
99
|
+
`);if(!t)throw Error(`No output from openExcel`);let n=JSON.parse(t),r=Array.isArray(n.sheets)?n.sheets:[n.sheets],i=Array.isArray(n.sheetNames)?n.sheetNames:[n.sheetNames];return{sheets:r.map(e=>({name:e.name,usedRange:e.usedRange,cells:Array.isArray(e.cells)?e.cells:e.cells?[e.cells]:[]})),sheetNames:i}}function It(e,t,n,r){let i=w(`
|
|
100
|
+
${D}
|
|
101
|
+
try {
|
|
102
|
+
$wb = $excel.Workbooks.Open('${T(e)}')
|
|
103
|
+
${Pt(`sheet`,t)}
|
|
104
|
+
$val = $sheet.Cells.Item(${n}, ${r}).Value2
|
|
105
|
+
if ($null -eq $val) { Write-Output 'null' } else { Write-Output ($val | ConvertTo-Json -Compress) }
|
|
106
|
+
} finally {
|
|
107
|
+
${E()}
|
|
108
|
+
}
|
|
109
|
+
`);return i===`null`||i===``?null:JSON.parse(i)}function Lt(e,t,n,r,i,a){let o=w(`
|
|
110
|
+
${D}
|
|
111
|
+
try {
|
|
112
|
+
$wb = $excel.Workbooks.Open('${T(e)}')
|
|
113
|
+
${Pt(`sheet`,t)}
|
|
114
|
+
$rows = @()
|
|
115
|
+
for ($r = ${n}; $r -le ${i}; $r++) {
|
|
116
|
+
$row = @()
|
|
117
|
+
for ($c = ${r}; $c -le ${a}; $c++) {
|
|
118
|
+
$val = $sheet.Cells.Item($r, $c).Value2
|
|
119
|
+
$row += if ($null -eq $val) { '__NULL__' } else { $val }
|
|
120
|
+
}
|
|
121
|
+
$rows += ,@($row)
|
|
122
|
+
}
|
|
123
|
+
$rows | ConvertTo-Json -Depth 3 -Compress
|
|
124
|
+
} finally {
|
|
125
|
+
${E()}
|
|
126
|
+
}
|
|
127
|
+
`);if(!o)return[];let s=JSON.parse(o);return(Array.isArray(s[0])?s:[s]).map(e=>e.map(e=>e===`__NULL__`?null:e))}function Rt(e,t,n,r,i){let a=JSON.stringify(i);return w(`
|
|
128
|
+
${D}
|
|
129
|
+
try {
|
|
130
|
+
$wb = $excel.Workbooks.Open('${T(e)}')
|
|
131
|
+
${Pt(`sheet`,t)}
|
|
132
|
+
$sheet.Cells.Item(${n}, ${r}).Value2 = (ConvertFrom-Json '${a.replace(/'/g,`''`)}')
|
|
133
|
+
$wb.Save()
|
|
134
|
+
Write-Output 'true'
|
|
135
|
+
} finally {
|
|
136
|
+
${E()}
|
|
137
|
+
}
|
|
138
|
+
`)===`true`}function zt(e,t,n,r,i){let a=JSON.stringify(i).replace(/'/g,`''`);return w(`
|
|
139
|
+
${D}
|
|
140
|
+
try {
|
|
141
|
+
$wb = $excel.Workbooks.Open('${T(e)}')
|
|
142
|
+
${Pt(`sheet`,t)}
|
|
143
|
+
$data = ConvertFrom-Json '${a}'
|
|
144
|
+
for ($r = 0; $r -lt $data.Count; $r++) {
|
|
145
|
+
$row = $data[$r]
|
|
146
|
+
for ($c = 0; $c -lt $row.Count; $c++) {
|
|
147
|
+
$val = $row[$c]
|
|
148
|
+
if ($null -ne $val) {
|
|
149
|
+
if ($val -is [int] -or $val -is [long] -or $val -is [double] -or $val -is [decimal]) {
|
|
150
|
+
$sheet.Cells.Item(${n} + $r, ${r} + $c).Value2 = [double]$val
|
|
151
|
+
} else {
|
|
152
|
+
$sheet.Cells.Item(${n} + $r, ${r} + $c).Value2 = [string]$val
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
$wb.Save()
|
|
158
|
+
Write-Output 'true'
|
|
159
|
+
} finally {
|
|
160
|
+
${E()}
|
|
161
|
+
}
|
|
162
|
+
`)===`true`}function Bt(e,t,n,r,i){return w(`
|
|
163
|
+
${D}
|
|
164
|
+
try {
|
|
165
|
+
$wb = $excel.Workbooks.Open('${T(e)}')
|
|
166
|
+
${Pt(`sheet`,t)}
|
|
167
|
+
$sheet.Cells.Item(${n}, ${r}).Formula = '${i.replace(/'/g,`''`)}'
|
|
168
|
+
$wb.Save()
|
|
169
|
+
Write-Output 'true'
|
|
170
|
+
} finally {
|
|
171
|
+
${E()}
|
|
172
|
+
}
|
|
173
|
+
`)===`true`}function Vt(e,t){let n=t?`$wb.SaveAs('${T(t)}')`:`$wb.Save()`;return w(`
|
|
174
|
+
${D}
|
|
175
|
+
try {
|
|
176
|
+
$wb = $excel.Workbooks.Open('${T(e)}')
|
|
177
|
+
${n}
|
|
178
|
+
Write-Output 'true'
|
|
179
|
+
} finally {
|
|
180
|
+
${E()}
|
|
181
|
+
}
|
|
182
|
+
`)===`true`}function Ht(e){return w(`
|
|
183
|
+
${D}
|
|
184
|
+
try {
|
|
185
|
+
$wb = $excel.Workbooks.Add()
|
|
186
|
+
$wb.SaveAs('${T(e)}')
|
|
187
|
+
Write-Output 'true'
|
|
188
|
+
} finally {
|
|
189
|
+
${E()}
|
|
190
|
+
}
|
|
191
|
+
`)===`true`}function Ut(e){}var D,Wt=t((()=>{D=`$excel = New-Object -ComObject Excel.Application
|
|
192
|
+
$excel.Visible = $false
|
|
193
|
+
$excel.DisplayAlerts = $false`})),Gt=n({appendText:()=>Xt,closeWord:()=>rn,createWord:()=>nn,findReplace:()=>Qt,insertTable:()=>$t,insertText:()=>Zt,openWord:()=>Jt,readText:()=>Yt,saveAsPdf:()=>tn,saveWord:()=>en});function O(e){let t=Bun.spawnSync({cmd:[`powershell`,`-NoProfile`,`-NonInteractive`,`-Command`,e],stdout:`pipe`,stderr:`pipe`});return new TextDecoder().decode(t.stdout).trim()}function k(e,t){if(!e)return t;try{return JSON.parse(e)}catch{return t}}function A(e){return e.replace(/'/g,`''`)}function Kt(e,t){return`
|
|
194
|
+
$word = New-Object -ComObject Word.Application
|
|
195
|
+
$word.Visible = $false
|
|
196
|
+
$word.DisplayAlerts = 0
|
|
197
|
+
try {
|
|
198
|
+
${t?`$doc = $word.Documents.Open('${A(t)}')`:`$doc = $word.Documents.Add()`}
|
|
199
|
+
${e}
|
|
200
|
+
} finally {
|
|
201
|
+
if ($doc -ne $null) { $doc.Close($false); }
|
|
202
|
+
if ($word -ne $null) { $word.Quit(); }
|
|
203
|
+
if ($word -ne $null) { [System.Runtime.InteropServices.Marshal]::ReleaseComObject($word) | Out-Null }
|
|
204
|
+
}
|
|
205
|
+
`}function qt(e,t){return`
|
|
206
|
+
$word = New-Object -ComObject Word.Application
|
|
207
|
+
$word.Visible = $false
|
|
208
|
+
$word.DisplayAlerts = 0
|
|
209
|
+
try {
|
|
210
|
+
$doc = $word.Documents.Open('${A(t)}')
|
|
211
|
+
${e}
|
|
212
|
+
$doc.Save()
|
|
213
|
+
Write-Output '{"ok":true}'
|
|
214
|
+
} catch {
|
|
215
|
+
Write-Output ('{"ok":false,"error":"' + ($_.Exception.Message -replace '"','\\"') + '"}')
|
|
216
|
+
} finally {
|
|
217
|
+
if ($doc -ne $null) { $doc.Close($false); }
|
|
218
|
+
if ($word -ne $null) { $word.Quit(); }
|
|
219
|
+
if ($word -ne $null) { [System.Runtime.InteropServices.Marshal]::ReleaseComObject($word) | Out-Null }
|
|
220
|
+
}
|
|
221
|
+
`}async function Jt(e){return k(O(Kt(`
|
|
222
|
+
# Paragraphs (limit 500)
|
|
223
|
+
$paras = @()
|
|
224
|
+
$paraCount = $doc.Paragraphs.Count
|
|
225
|
+
$limit = [Math]::Min($paraCount, 500)
|
|
226
|
+
for ($i = 1; $i -le $limit; $i++) {
|
|
227
|
+
$p = $doc.Paragraphs.Item($i)
|
|
228
|
+
$r = $p.Range
|
|
229
|
+
$paras += @{
|
|
230
|
+
text = $r.Text -replace '\\r$',''
|
|
231
|
+
bold = [bool]($r.Font.Bold -eq -1)
|
|
232
|
+
italic = [bool]($r.Font.Italic -eq -1)
|
|
233
|
+
fontSize = $r.Font.Size
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
# Tables
|
|
238
|
+
$tables = @()
|
|
239
|
+
foreach ($table in $doc.Tables) {
|
|
240
|
+
$rows = $table.Rows.Count
|
|
241
|
+
$cols = $table.Columns.Count
|
|
242
|
+
$data = @()
|
|
243
|
+
for ($r = 1; $r -le $rows; $r++) {
|
|
244
|
+
$row = @()
|
|
245
|
+
for ($c = 1; $c -le $cols; $c++) {
|
|
246
|
+
try {
|
|
247
|
+
$cellText = $table.Cell($r, $c).Range.Text
|
|
248
|
+
# Trim trailing \\r\\a that Word adds to cell text
|
|
249
|
+
$cellText = $cellText -replace '[\\r\\n\\a]+$',''
|
|
250
|
+
$row += $cellText
|
|
251
|
+
} catch {
|
|
252
|
+
$row += ''
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
$data += ,@($row)
|
|
256
|
+
}
|
|
257
|
+
$tables += @{ rows = $rows; cols = $cols; data = $data }
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
# Counts: wdStatisticWords=0, wdStatisticPages=2
|
|
261
|
+
$wordCount = $doc.ComputeStatistics(0)
|
|
262
|
+
$pageCount = $doc.ComputeStatistics(2)
|
|
263
|
+
|
|
264
|
+
$result = @{
|
|
265
|
+
text = $doc.Content.Text
|
|
266
|
+
paragraphs = $paras
|
|
267
|
+
tables = $tables
|
|
268
|
+
wordCount = $wordCount
|
|
269
|
+
pageCount = $pageCount
|
|
270
|
+
}
|
|
271
|
+
Write-Output (ConvertTo-Json $result -Depth 5 -Compress)
|
|
272
|
+
`,e)),{text:``,paragraphs:[],tables:[],wordCount:0,pageCount:0})}async function Yt(e){return O(Kt(`Write-Output $doc.Content.Text`,e))}async function Xt(e,t,n){return k(O(qt(`
|
|
273
|
+
$sel = $word.Selection
|
|
274
|
+
$sel.EndKey(6) | Out-Null
|
|
275
|
+
${n?[n.bold===void 0?``:`$sel.Font.Bold = ${n.bold?`-1`:`0`}`,n.italic===void 0?``:`$sel.Font.Italic = ${n.italic?`-1`:`0`}`,n.fontSize===void 0?``:`$sel.Font.Size = ${n.fontSize}`,n.fontName?`$sel.Font.Name = '${A(n.fontName)}'`:``].filter(Boolean).join(`
|
|
276
|
+
`):``}
|
|
277
|
+
$sel.TypeText('${A(t)}')
|
|
278
|
+
`,e)),{ok:!1}).ok}async function Zt(e,t,n){return k(O(qt(`
|
|
279
|
+
$doc.Paragraphs.Item(${t}).Range.InsertBefore('${A(n)}')
|
|
280
|
+
`,e)),{ok:!1}).ok}async function Qt(e,t,n,r){let i=r===!1?1:2,a=`
|
|
281
|
+
$content = $doc.Content
|
|
282
|
+
$findObj = $content.Find
|
|
283
|
+
$findObj.ClearFormatting()
|
|
284
|
+
$findObj.Replacement.ClearFormatting()
|
|
285
|
+
|
|
286
|
+
# Count replacements by iterating
|
|
287
|
+
$count = 0
|
|
288
|
+
$findObj.Text = '${A(t)}'
|
|
289
|
+
$findObj.Replacement.Text = '${A(n)}'
|
|
290
|
+
$findObj.Forward = $true
|
|
291
|
+
$findObj.Wrap = 0
|
|
292
|
+
$findObj.Format = $false
|
|
293
|
+
$findObj.MatchCase = $false
|
|
294
|
+
$findObj.MatchWholeWord = $false
|
|
295
|
+
$findObj.MatchWildcards = $false
|
|
296
|
+
|
|
297
|
+
if (${i} -eq 2) {
|
|
298
|
+
# Count occurrences first using a clone of content
|
|
299
|
+
$range2 = $doc.Content.Duplicate
|
|
300
|
+
while ($range2.Find.Execute('${A(t)}')) { $count++ }
|
|
301
|
+
# Now do the actual replace
|
|
302
|
+
$findObj.Execute('${A(t)}', $false, $false, $false, $false, $false, $true, 0, $false, '${A(n)}', 2)
|
|
303
|
+
} else {
|
|
304
|
+
$found = $findObj.Execute('${A(t)}', $false, $false, $false, $false, $false, $true, 0, $false, '${A(n)}', 1)
|
|
305
|
+
if ($found) { $count = 1 }
|
|
306
|
+
}
|
|
307
|
+
`;return k(O(`
|
|
308
|
+
$word = New-Object -ComObject Word.Application
|
|
309
|
+
$word.Visible = $false
|
|
310
|
+
$word.DisplayAlerts = 0
|
|
311
|
+
try {
|
|
312
|
+
$doc = $word.Documents.Open('${A(e)}')
|
|
313
|
+
${a}
|
|
314
|
+
$doc.Save()
|
|
315
|
+
Write-Output ('{"count":' + $count + '}')
|
|
316
|
+
} catch {
|
|
317
|
+
Write-Output '{"count":0}'
|
|
318
|
+
} finally {
|
|
319
|
+
if ($doc -ne $null) { $doc.Close($false); }
|
|
320
|
+
if ($word -ne $null) { $word.Quit(); }
|
|
321
|
+
if ($word -ne $null) { [System.Runtime.InteropServices.Marshal]::ReleaseComObject($word) | Out-Null }
|
|
322
|
+
}
|
|
323
|
+
`),{count:0}).count}async function $t(e,t,n,r){return k(O(qt(`
|
|
324
|
+
$sel = $word.Selection
|
|
325
|
+
$sel.EndKey(6) | Out-Null
|
|
326
|
+
$table = $doc.Tables.Add($sel.Range, ${t}, ${n})
|
|
327
|
+
$data = @(${r.map(e=>`,@(`+e.map(e=>`'${A(e)}'`).join(`,`)+`)`).join(`
|
|
328
|
+
`)})
|
|
329
|
+
for ($r = 0; $r -lt $data.Count; $r++) {
|
|
330
|
+
for ($c = 0; $c -lt $data[$r].Count; $c++) {
|
|
331
|
+
$table.Cell($r + 1, $c + 1).Range.Text = $data[$r][$c]
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
`,e)),{ok:!1}).ok}async function en(e,t){if(!t||t===e)return k(O(qt(``,e)),{ok:!1}).ok;let n=`$doc.SaveAs('${A(t)}')`;return k(O(`
|
|
335
|
+
$word = New-Object -ComObject Word.Application
|
|
336
|
+
$word.Visible = $false
|
|
337
|
+
$word.DisplayAlerts = 0
|
|
338
|
+
try {
|
|
339
|
+
$doc = $word.Documents.Open('${A(e)}')
|
|
340
|
+
${n}
|
|
341
|
+
Write-Output '{"ok":true}'
|
|
342
|
+
} catch {
|
|
343
|
+
Write-Output ('{"ok":false,"error":"' + ($_.Exception.Message -replace '"','\\"') + '"}')
|
|
344
|
+
} finally {
|
|
345
|
+
if ($doc -ne $null) { $doc.Close($false); }
|
|
346
|
+
if ($word -ne $null) { $word.Quit(); }
|
|
347
|
+
if ($word -ne $null) { [System.Runtime.InteropServices.Marshal]::ReleaseComObject($word) | Out-Null }
|
|
348
|
+
}
|
|
349
|
+
`),{ok:!1}).ok}async function tn(e,t){let n=`$doc.SaveAs2('${A(t)}', 17)`;return k(O(`
|
|
350
|
+
$word = New-Object -ComObject Word.Application
|
|
351
|
+
$word.Visible = $false
|
|
352
|
+
$word.DisplayAlerts = 0
|
|
353
|
+
try {
|
|
354
|
+
$doc = $word.Documents.Open('${A(e)}')
|
|
355
|
+
${n}
|
|
356
|
+
Write-Output '{"ok":true}'
|
|
357
|
+
} catch {
|
|
358
|
+
Write-Output ('{"ok":false,"error":"' + ($_.Exception.Message -replace '"','\\"') + '"}')
|
|
359
|
+
} finally {
|
|
360
|
+
if ($doc -ne $null) { $doc.Close($false); }
|
|
361
|
+
if ($word -ne $null) { $word.Quit(); }
|
|
362
|
+
if ($word -ne $null) { [System.Runtime.InteropServices.Marshal]::ReleaseComObject($word) | Out-Null }
|
|
363
|
+
}
|
|
364
|
+
`),{ok:!1}).ok}async function nn(e){return k(O(`
|
|
365
|
+
$word = New-Object -ComObject Word.Application
|
|
366
|
+
$word.Visible = $false
|
|
367
|
+
$word.DisplayAlerts = 0
|
|
368
|
+
try {
|
|
369
|
+
$doc = $word.Documents.Add()
|
|
370
|
+
$doc.SaveAs('${A(e)}')
|
|
371
|
+
Write-Output '{"ok":true}'
|
|
372
|
+
} catch {
|
|
373
|
+
Write-Output ('{"ok":false,"error":"' + ($_.Exception.Message -replace '"','\\"') + '"}')
|
|
374
|
+
} finally {
|
|
375
|
+
if ($doc -ne $null) { $doc.Close($false); }
|
|
376
|
+
if ($word -ne $null) { $word.Quit(); }
|
|
377
|
+
if ($word -ne $null) { [System.Runtime.InteropServices.Marshal]::ReleaseComObject($word) | Out-Null }
|
|
378
|
+
}
|
|
379
|
+
`),{ok:!1}).ok}function rn(e){}var an=t((()=>{}));function on(e){let t=e.toLowerCase(),n=he(t);if(n){if(cn.has(n))return`excel`;if(ln.has(n))return`word`;if(un.has(n))return`text`}let r=t.replace(/\.exe$/,``).split(/[/\\]/).pop()??``;return r===`excel`||r.includes(`excel`)?`excel`:r===`winword`||r===`word`||r.includes(`word`)?`word`:r===`notepad`||r===`notepad++`||r===`code`?`text`:dn.has(r)?`browser`:`generic`}async function sn(t){let n=on(t);switch(n){case`excel`:{let{createExcel:n,openExcel:r}=(Wt(),e(Nt));if(t.match(/\.(xlsx|xls|csv|xlsm|xlsb)$/i))try{return r(t),{type:`excel`,filePath:t}}catch{return{type:`excel`,filePath:t}}let i=`${process.env.TEMP||`/tmp`}\\cu_new_${Date.now()}.xlsx`;return n(i),{type:`excel`,filePath:i}}case`word`:{let{createWord:n,openWord:r}=(an(),e(Gt));if(t.match(/\.(docx|doc|rtf)$/i))try{return r(t),{type:`word`,filePath:t}}catch{return{type:`word`,filePath:t}}let i=`${process.env.TEMP||`/tmp`}\\cu_new_${Date.now()}.docx`;return n(i),{type:`word`,filePath:i}}default:return{type:n}}}var cn,ln,un,dn,fn=t((()=>{cn=new Set([`.xlsx`,`.xls`,`.csv`,`.xlsm`,`.xlsb`]),ln=new Set([`.docx`,`.doc`,`.rtf`]),un=new Set([`.txt`,`.log`,`.md`,`.json`,`.xml`,`.yaml`,`.yml`,`.ini`,`.cfg`,`.conf`]),dn=new Set([`chrome`,`msedge`,`firefox`,`brave`,`opera`])}));function pn(e){return e=b(e),x(`Add-Type @'
|
|
380
|
+
using System;
|
|
381
|
+
using System.Runtime.InteropServices;
|
|
382
|
+
public class CuDwm {
|
|
383
|
+
[DllImport("dwmapi.dll")]
|
|
384
|
+
public static extern int DwmSetWindowAttribute(IntPtr hwnd, int attr, ref uint val, int size);
|
|
385
|
+
}
|
|
386
|
+
'@
|
|
387
|
+
$color = [uint32]0x0000C800
|
|
388
|
+
[CuDwm]::DwmSetWindowAttribute([IntPtr]::new([long]${e}), 34, [ref]$color, 4)`)===`0`}function mn(e){return e=b(e),x(`Add-Type @'
|
|
389
|
+
using System;
|
|
390
|
+
using System.Runtime.InteropServices;
|
|
391
|
+
public class CuDwm {
|
|
392
|
+
[DllImport("dwmapi.dll")]
|
|
393
|
+
public static extern int DwmSetWindowAttribute(IntPtr hwnd, int attr, ref uint val, int size);
|
|
394
|
+
}
|
|
395
|
+
'@
|
|
396
|
+
$color = [uint32]0xFFFFFFFF
|
|
397
|
+
[CuDwm]::DwmSetWindowAttribute([IntPtr]::new([long]${e}), 34, [ref]$color, 4)`)===`0`}var hn=t((()=>{C()})),gn=n({hideVirtualCursor:()=>bn,isVirtualCursorActive:()=>xn,moveVirtualCursor:()=>yn,showVirtualCursor:()=>vn});function _n(e,t){return`
|
|
398
|
+
Add-Type -AssemblyName System.Windows.Forms
|
|
399
|
+
Add-Type -AssemblyName System.Drawing
|
|
400
|
+
Add-Type @'
|
|
401
|
+
using System;
|
|
402
|
+
using System.Runtime.InteropServices;
|
|
403
|
+
using System.Drawing;
|
|
404
|
+
using System.Drawing.Drawing2D;
|
|
405
|
+
|
|
406
|
+
public class VCursor {
|
|
407
|
+
[DllImport("user32.dll")]
|
|
408
|
+
public static extern bool IsWindow(IntPtr hWnd);
|
|
409
|
+
|
|
410
|
+
[DllImport("user32.dll", SetLastError = true)]
|
|
411
|
+
public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
|
|
412
|
+
|
|
413
|
+
[DllImport("user32.dll", SetLastError = true)]
|
|
414
|
+
public static extern int GetWindowLong(IntPtr hWnd, int nIndex);
|
|
415
|
+
|
|
416
|
+
[DllImport("user32.dll")]
|
|
417
|
+
public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hAfter, int X, int Y, int cx, int cy, uint f);
|
|
418
|
+
|
|
419
|
+
[DllImport("user32.dll")]
|
|
420
|
+
public static extern bool GetWindowRect(IntPtr h, out RECT r);
|
|
421
|
+
|
|
422
|
+
[StructLayout(LayoutKind.Sequential)]
|
|
423
|
+
public struct RECT { public int L, T, R, B; }
|
|
424
|
+
|
|
425
|
+
public const int GWL_EXSTYLE = -20;
|
|
426
|
+
public const int WS_EX_LAYERED = 0x80000;
|
|
427
|
+
public const int WS_EX_TRANSPARENT = 0x20;
|
|
428
|
+
public const int WS_EX_TOOLWINDOW = 0x80;
|
|
429
|
+
public const int WS_EX_NOACTIVATE = 0x08000000;
|
|
430
|
+
public static readonly IntPtr HWND_TOPMOST = new IntPtr(-1);
|
|
431
|
+
public const uint SWP_NOACTIVATE = 0x0010;
|
|
432
|
+
public const uint SWP_SHOWWINDOW = 0x0040;
|
|
433
|
+
public const uint SWP_NOSIZE = 0x0001;
|
|
434
|
+
|
|
435
|
+
public static void MakeOverlay(IntPtr h) {
|
|
436
|
+
int ex = GetWindowLong(h, GWL_EXSTYLE);
|
|
437
|
+
ex |= WS_EX_LAYERED | WS_EX_TRANSPARENT | WS_EX_TOOLWINDOW | WS_EX_NOACTIVATE;
|
|
438
|
+
SetWindowLong(h, GWL_EXSTYLE, ex);
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
'@
|
|
442
|
+
|
|
443
|
+
$targetHwnd = [IntPtr]::new([long]${e})
|
|
444
|
+
$stopFile = '${t.replace(/\\/g,`\\\\`)}'
|
|
445
|
+
$cursorSize = ${Sn}
|
|
446
|
+
|
|
447
|
+
# Create cursor form with arrow shape
|
|
448
|
+
$cursor = New-Object System.Windows.Forms.Form
|
|
449
|
+
$cursor.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::None
|
|
450
|
+
$cursor.ShowInTaskbar = $false
|
|
451
|
+
$cursor.TopMost = $true
|
|
452
|
+
$cursor.StartPosition = [System.Windows.Forms.FormStartPosition]::Manual
|
|
453
|
+
$cursor.Size = New-Object System.Drawing.Size($cursorSize, $cursorSize)
|
|
454
|
+
$cursor.Location = New-Object System.Drawing.Point(-32000, -32000)
|
|
455
|
+
$cursor.Opacity = ${En}
|
|
456
|
+
$cursor.BackColor = [System.Drawing.Color]::Magenta
|
|
457
|
+
$cursor.TransparencyKey = [System.Drawing.Color]::Magenta
|
|
458
|
+
|
|
459
|
+
# Draw arrow cursor shape
|
|
460
|
+
$bmp = New-Object System.Drawing.Bitmap($cursorSize, $cursorSize)
|
|
461
|
+
$g = [System.Drawing.Graphics]::FromImage($bmp)
|
|
462
|
+
$g.SmoothingMode = [System.Drawing.Drawing2D.SmoothingMode]::AntiAlias
|
|
463
|
+
# Arrow polygon (pointing top-left)
|
|
464
|
+
$points = @(
|
|
465
|
+
(New-Object System.Drawing.Point(1, 1)),
|
|
466
|
+
(New-Object System.Drawing.Point(1, 16)),
|
|
467
|
+
(New-Object System.Drawing.Point(5, 12)),
|
|
468
|
+
(New-Object System.Drawing.Point(9, 18)),
|
|
469
|
+
(New-Object System.Drawing.Point(12, 16)),
|
|
470
|
+
(New-Object System.Drawing.Point(8, 10)),
|
|
471
|
+
(New-Object System.Drawing.Point(13, 10)),
|
|
472
|
+
(New-Object System.Drawing.Point(1, 1))
|
|
473
|
+
)
|
|
474
|
+
$brush = New-Object System.Drawing.SolidBrush([System.Drawing.Color]::FromArgb(${Cn}, ${wn}, ${Tn}))
|
|
475
|
+
$g.FillPolygon($brush, $points)
|
|
476
|
+
$pen = New-Object System.Drawing.Pen([System.Drawing.Color]::White, 1)
|
|
477
|
+
$g.DrawPolygon($pen, $points)
|
|
478
|
+
$g.Dispose()
|
|
479
|
+
$cursor.BackgroundImage = $bmp
|
|
480
|
+
|
|
481
|
+
$cursor.Show()
|
|
482
|
+
[VCursor]::MakeOverlay($cursor.Handle)
|
|
483
|
+
|
|
484
|
+
# Position file: the TS side writes "x,y" or "x,y,click" to this file
|
|
485
|
+
$posFile = $stopFile + '.pos'
|
|
486
|
+
|
|
487
|
+
$script:lastCX = -32000
|
|
488
|
+
$script:lastCY = -32000
|
|
489
|
+
$script:clickFlash = 0
|
|
490
|
+
|
|
491
|
+
$timer = New-Object System.Windows.Forms.Timer
|
|
492
|
+
$timer.Interval = 16 # ~60fps
|
|
493
|
+
|
|
494
|
+
$timer.Add_Tick({
|
|
495
|
+
if (-not [VCursor]::IsWindow($targetHwnd)) {
|
|
496
|
+
$timer.Stop(); $cursor.Close()
|
|
497
|
+
[System.Windows.Forms.Application]::ExitThread()
|
|
498
|
+
return
|
|
499
|
+
}
|
|
500
|
+
# Check stop
|
|
501
|
+
if (Test-Path $stopFile) {
|
|
502
|
+
$timer.Stop(); $cursor.Close()
|
|
503
|
+
try { Remove-Item $stopFile -ErrorAction SilentlyContinue } catch {}
|
|
504
|
+
try { Remove-Item $posFile -ErrorAction SilentlyContinue } catch {}
|
|
505
|
+
[System.Windows.Forms.Application]::ExitThread()
|
|
506
|
+
return
|
|
507
|
+
}
|
|
508
|
+
# Read position updates
|
|
509
|
+
if (Test-Path $posFile) {
|
|
510
|
+
try {
|
|
511
|
+
$data = Get-Content $posFile -Raw -ErrorAction SilentlyContinue
|
|
512
|
+
if ($data) {
|
|
513
|
+
$parts = $data.Trim().Split(',')
|
|
514
|
+
if ($parts.Length -ge 2) {
|
|
515
|
+
$script:lastCX = [int]$parts[0]
|
|
516
|
+
$script:lastCY = [int]$parts[1]
|
|
517
|
+
if ($parts.Length -ge 3 -and $parts[2] -eq 'click') {
|
|
518
|
+
$script:clickFlash = 6 # flash for 6 frames (~100ms)
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
Remove-Item $posFile -ErrorAction SilentlyContinue
|
|
522
|
+
}
|
|
523
|
+
} catch {}
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
# Get window position to convert client coords to screen coords
|
|
527
|
+
$wr = New-Object VCursor+RECT
|
|
528
|
+
[VCursor]::GetWindowRect($targetHwnd, [ref]$wr) | Out-Null
|
|
529
|
+
$screenX = $wr.L + $script:lastCX
|
|
530
|
+
$screenY = $wr.T + $script:lastCY
|
|
531
|
+
|
|
532
|
+
# Click flash: briefly change color
|
|
533
|
+
if ($script:clickFlash -gt 0) {
|
|
534
|
+
$cursor.Opacity = 1.0
|
|
535
|
+
$script:clickFlash--
|
|
536
|
+
if ($script:clickFlash -eq 0) {
|
|
537
|
+
$cursor.Opacity = ${En}
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
[VCursor]::SetWindowPos($cursor.Handle, [VCursor]::HWND_TOPMOST,
|
|
542
|
+
$screenX, $screenY, 0, 0,
|
|
543
|
+
[VCursor]::SWP_NOSIZE -bor [VCursor]::SWP_NOACTIVATE -bor [VCursor]::SWP_SHOWWINDOW) | Out-Null
|
|
544
|
+
$cursor.Visible = $true
|
|
545
|
+
})
|
|
546
|
+
|
|
547
|
+
$timer.Start()
|
|
548
|
+
[System.Windows.Forms.Application]::Run()
|
|
549
|
+
`}function vn(e){e=b(e),bn();try{let t=Ct(),n=Date.now(),r=me.join(t,`cu_vcursor_stop_${n}`),i=me.join(t,`cu_vcursor_${n}.ps1`),a=_n(e,r);return p.writeFileSync(i,a,`utf-8`),Dn=Bun.spawn([`powershell`,`-NoProfile`,`-ExecutionPolicy`,`Bypass`,`-File`,i],{stdout:`ignore`,stderr:`ignore`}),j=r,On=i,!0}catch{return!1}}function yn(e,t,n=!1){if(!j)return;let r=j+`.pos`;try{let i=n?`${Math.round(e)},${Math.round(t)},click`:`${Math.round(e)},${Math.round(t)}`;p.writeFileSync(r,i,`utf-8`)}catch{}}function bn(){if(j){try{p.writeFileSync(j,`STOP`,`utf-8`)}catch{}setTimeout(()=>{try{Dn?.kill()}catch{}try{On&&p.unlinkSync(On)}catch{}try{j&&p.unlinkSync(j)}catch{}},2e3)}Dn=null,j=null,On=null}function xn(){return Dn!==null}var Sn,Cn,wn,Tn,En,Dn,j,On,kn=t((()=>{C(),Sn=20,Cn=255,wn=50,Tn=50,En=.9,Dn=null,j=null,On=null})),An=n({hideIndicator:()=>Pn,indicateClick:()=>Ln,indicateDone:()=>zn,indicateKey:()=>In,indicateScroll:()=>Rn,indicateTyping:()=>Fn,showIndicator:()=>Mn,updateIndicator:()=>Nn});function jn(e,t){return`
|
|
550
|
+
Add-Type -AssemblyName System.Windows.Forms
|
|
551
|
+
Add-Type -AssemblyName System.Drawing
|
|
552
|
+
Add-Type @'
|
|
553
|
+
using System;
|
|
554
|
+
using System.Runtime.InteropServices;
|
|
555
|
+
public class Indicator {
|
|
556
|
+
[DllImport("user32.dll")] public static extern bool IsWindow(IntPtr h);
|
|
557
|
+
[DllImport("user32.dll",SetLastError=true)] public static extern int SetWindowLong(IntPtr h, int i, int v);
|
|
558
|
+
[DllImport("user32.dll",SetLastError=true)] public static extern int GetWindowLong(IntPtr h, int i);
|
|
559
|
+
[DllImport("user32.dll")] public static extern bool SetWindowPos(IntPtr h, IntPtr a, int x, int y, int w, int h2, uint f);
|
|
560
|
+
[DllImport("user32.dll")] public static extern bool GetWindowRect(IntPtr h, out RECT r);
|
|
561
|
+
[StructLayout(LayoutKind.Sequential)] public struct RECT { public int L,T,R,B; }
|
|
562
|
+
public const int GWL_EXSTYLE = -20;
|
|
563
|
+
public const int WS_EX_LAYERED = 0x80000;
|
|
564
|
+
public const int WS_EX_TRANSPARENT = 0x20;
|
|
565
|
+
public const int WS_EX_TOOLWINDOW = 0x80;
|
|
566
|
+
public const int WS_EX_NOACTIVATE = 0x08000000;
|
|
567
|
+
public static readonly IntPtr HWND_TOPMOST = new IntPtr(-1);
|
|
568
|
+
public const uint SWP_NOACTIVATE = 0x0010;
|
|
569
|
+
public const uint SWP_SHOWWINDOW = 0x0040;
|
|
570
|
+
public static void MakeOverlay(IntPtr h) {
|
|
571
|
+
int ex = GetWindowLong(h, GWL_EXSTYLE);
|
|
572
|
+
ex |= WS_EX_LAYERED | WS_EX_TRANSPARENT | WS_EX_TOOLWINDOW | WS_EX_NOACTIVATE;
|
|
573
|
+
SetWindowLong(h, GWL_EXSTYLE, ex);
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
'@
|
|
577
|
+
|
|
578
|
+
$targetHwnd = [IntPtr]::new([long]${e})
|
|
579
|
+
$stopFile = '${t.replace(/\\/g,`\\\\`)}'
|
|
580
|
+
$msgFile = $stopFile + '.msg'
|
|
581
|
+
|
|
582
|
+
$form = New-Object System.Windows.Forms.Form
|
|
583
|
+
$form.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::None
|
|
584
|
+
$form.ShowInTaskbar = $false
|
|
585
|
+
$form.TopMost = $true
|
|
586
|
+
$form.StartPosition = [System.Windows.Forms.FormStartPosition]::Manual
|
|
587
|
+
$form.Size = New-Object System.Drawing.Size(${Bn}, ${Vn})
|
|
588
|
+
$form.Location = New-Object System.Drawing.Point(-32000, -32000)
|
|
589
|
+
$form.BackColor = [System.Drawing.Color]::FromArgb(240, ${Hn})
|
|
590
|
+
$form.Opacity = 0.92
|
|
591
|
+
|
|
592
|
+
$label = New-Object System.Windows.Forms.Label
|
|
593
|
+
$label.Dock = [System.Windows.Forms.DockStyle]::Fill
|
|
594
|
+
$label.ForeColor = [System.Drawing.Color]::FromArgb(${Un})
|
|
595
|
+
$label.Font = New-Object System.Drawing.Font("Segoe UI", 10, [System.Drawing.FontStyle]::Regular)
|
|
596
|
+
$label.TextAlign = [System.Drawing.ContentAlignment]::MiddleLeft
|
|
597
|
+
$label.Padding = New-Object System.Windows.Forms.Padding(8, 0, 8, 0)
|
|
598
|
+
$label.Text = ""
|
|
599
|
+
$form.Controls.Add($label)
|
|
600
|
+
|
|
601
|
+
$form.Show()
|
|
602
|
+
[Indicator]::MakeOverlay($form.Handle)
|
|
603
|
+
|
|
604
|
+
$script:lastMsg = ""
|
|
605
|
+
$script:lastMsgTime = [DateTime]::MinValue
|
|
606
|
+
$script:visible = $false
|
|
607
|
+
|
|
608
|
+
$timer = New-Object System.Windows.Forms.Timer
|
|
609
|
+
$timer.Interval = 50 # 20fps
|
|
610
|
+
|
|
611
|
+
$timer.Add_Tick({
|
|
612
|
+
if (-not [Indicator]::IsWindow($targetHwnd)) {
|
|
613
|
+
$timer.Stop(); $form.Close()
|
|
614
|
+
[System.Windows.Forms.Application]::ExitThread()
|
|
615
|
+
return
|
|
616
|
+
}
|
|
617
|
+
if (Test-Path $stopFile) {
|
|
618
|
+
$timer.Stop(); $form.Close()
|
|
619
|
+
try { Remove-Item $stopFile -ErrorAction SilentlyContinue } catch {}
|
|
620
|
+
try { Remove-Item $msgFile -ErrorAction SilentlyContinue } catch {}
|
|
621
|
+
[System.Windows.Forms.Application]::ExitThread()
|
|
622
|
+
return
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
# Read new message
|
|
626
|
+
if (Test-Path $msgFile) {
|
|
627
|
+
try {
|
|
628
|
+
$msg = Get-Content $msgFile -Raw -Encoding UTF8 -ErrorAction SilentlyContinue
|
|
629
|
+
if ($msg) {
|
|
630
|
+
$script:lastMsg = $msg.Trim()
|
|
631
|
+
$script:lastMsgTime = [DateTime]::Now
|
|
632
|
+
Remove-Item $msgFile -ErrorAction SilentlyContinue
|
|
633
|
+
}
|
|
634
|
+
} catch {}
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
# Fade logic: hide after ${M}ms of no updates
|
|
638
|
+
$elapsed = ([DateTime]::Now - $script:lastMsgTime).TotalMilliseconds
|
|
639
|
+
if ($elapsed -gt ${M} -and $script:visible) {
|
|
640
|
+
$form.Visible = $false
|
|
641
|
+
$script:visible = $false
|
|
642
|
+
return
|
|
643
|
+
}
|
|
644
|
+
if ($elapsed -le ${M} -and $script:lastMsg -ne "") {
|
|
645
|
+
# Position at bottom-center of the bound window
|
|
646
|
+
$wr = New-Object Indicator+RECT
|
|
647
|
+
[Indicator]::GetWindowRect($targetHwnd, [ref]$wr) | Out-Null
|
|
648
|
+
$ww = $wr.R - $wr.L
|
|
649
|
+
$fx = $wr.L + [int](($ww - ${Bn}) / 2)
|
|
650
|
+
$fy = $wr.B - ${Vn} - 8
|
|
651
|
+
$label.Text = $script:lastMsg
|
|
652
|
+
[Indicator]::SetWindowPos($form.Handle, [Indicator]::HWND_TOPMOST,
|
|
653
|
+
$fx, $fy, 0, 0,
|
|
654
|
+
0x0001 -bor [Indicator]::SWP_NOACTIVATE -bor [Indicator]::SWP_SHOWWINDOW) | Out-Null
|
|
655
|
+
$form.Visible = $true
|
|
656
|
+
$script:visible = $true
|
|
657
|
+
# Fade opacity near end
|
|
658
|
+
if ($elapsed -gt ${M*.7}) {
|
|
659
|
+
$form.Opacity = [Math]::Max(0.3, 0.92 * (1.0 - ($elapsed - ${M*.7}) / ${M*.3}))
|
|
660
|
+
} else {
|
|
661
|
+
$form.Opacity = 0.92
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
})
|
|
665
|
+
|
|
666
|
+
$timer.Start()
|
|
667
|
+
[System.Windows.Forms.Application]::Run()
|
|
668
|
+
`}function Mn(e){e=b(e),Pn();try{let t=Ct(),n=Date.now();return N=me.join(t,`cu_indicator_stop_${n}`),P=me.join(t,`cu_indicator_${n}.ps1`),F=N+`.msg`,p.writeFileSync(P,jn(e,N),`utf-8`),Wn=Bun.spawn([`powershell`,`-NoProfile`,`-ExecutionPolicy`,`Bypass`,`-File`,P],{stdout:`ignore`,stderr:`ignore`}),!0}catch{return!1}}function Nn(e){if(F)try{p.writeFileSync(F,e,`utf-8`)}catch{}}function Pn(){if(N){try{p.writeFileSync(N,`STOP`,`utf-8`)}catch{}setTimeout(()=>{try{Wn?.kill()}catch{}try{P&&p.unlinkSync(P)}catch{}try{N&&p.unlinkSync(N)}catch{}try{F&&p.unlinkSync(F)}catch{}},2e3)}Wn=null,N=null,P=null,F=null}function Fn(e){Nn(`\u2328 Typing "${e.length>30?e.slice(0,30)+`...`:e}"`)}function In(e){Nn(`\u2328 ${e}`)}function Ln(e,t,n=`left`){Nn(`\uD83D\uDDB1 ${n===`right`?`Right-click`:`Click`} (${e}, ${t})`)}function Rn(e,t){Nn(`\uD83D\uDCDC Scroll ${e===`up`?`↑`:e===`down`?`↓`:e===`left`?`←`:`→`} ${t}`)}function zn(){Nn(`✅ Done`)}var Bn,Vn,M,Hn,Un,Wn,N,P,F,Gn=t((()=>{C(),Bn=350,Vn=28,M=2e3,Hn=`30, 30, 30`,Un=`220, 220, 220`,Wn=null,N=null,P=null,F=null})),Kn=n({call:()=>Jn,callSync:()=>Yn,ensureBridge:()=>qn,stopBridge:()=>Xn});function qn(){if(I)return!0;try{let e=me.join(__dirname,`bridge.py`);I=Bun.spawn([`python`,`-u`,e],{stdin:`pipe`,stdout:`pipe`,stderr:`ignore`,env:{...process.env,PYTHONIOENCODING:`utf-8`,PYTHONUNBUFFERED:`1`}});let t=I.stdout.getReader();return(async()=>{try{for(;;){let{done:e,value:n}=await t.read();if(e)break;Qn+=new TextDecoder().decode(n);let r;for(;(r=Qn.indexOf(`
|
|
669
|
+
`))!==-1;){let e=Qn.slice(0,r).trim();if(Qn=Qn.slice(r+1),e)try{let t=JSON.parse(e),n=L.get(t.id);n&&(L.delete(t.id),t.error?n.reject(Error(t.error)):n.resolve(t.result))}catch{}}}}catch{}})(),!0}catch{return I=null,!1}}async function Jn(e,t={},n=1e4){if(!qn())throw Error(`Python bridge not available`);let r=++Zn,i={id:r,method:e,params:t};return new Promise((t,a)=>{L.set(r,{resolve:t,reject:a});let o=setTimeout(()=>{L.delete(r),a(Error(`Bridge call ${e} timed out after ${n}ms`))},n),s=t,c=a;L.set(r,{resolve:e=>{clearTimeout(o),s(e)},reject:e=>{clearTimeout(o),c(e)}});try{let e=I.stdin;if(e){let t=e;t.write(JSON.stringify(i)+`
|
|
670
|
+
`),typeof t.flush==`function`&&t.flush()}}catch(e){clearTimeout(o),L.delete(r),a(Error(`Bridge write failed: ${e}`))}})}function Yn(e,t={},n=1e4){try{let r=me.join(__dirname,`bridge.py`),i=JSON.stringify({id:1,method:e,params:t}),a=Bun.spawnSync({cmd:[`python`,`-u`,r],stdin:Buffer.from(i+`
|
|
671
|
+
`),stdout:`pipe`,stderr:`pipe`,env:{...process.env,PYTHONIOENCODING:`utf-8`},timeout:n}),o=new TextDecoder().decode(a.stdout).trim();if(!o)return null;let s=JSON.parse(o);if(s.error)throw Error(s.error);return s.result}catch{return null}}function Xn(){if(I){try{let e=I.stdin;if(e){let t=e;typeof t.end==`function`&&t.end()}I.kill()}catch{}I=null}L.clear(),Qn=``}var I,Zn,L,Qn,$n=t((()=>{I=null,Zn=0,L=new Map,Qn=``})),R=n({clearEditChildCache:()=>er,consoleKey:()=>sr,consoleText:()=>cr,findEditChild:()=>tr,resolveInputHwnd:()=>z,sendChar:()=>nr,sendClick:()=>lr,sendKey:()=>ar,sendKeys:()=>or,sendMouseDown:()=>ur,sendMouseMove:()=>fr,sendMouseUp:()=>dr,sendMouseWheel:()=>pr,sendText:()=>ir});function er(e){e?B.delete(e):B.clear()}function z(e){return e=b(e),tr(e)??e}function tr(e){if(e=b(e),B.has(e))return B.get(e);let t=S(`${V}
|
|
672
|
+
[WinMsg]::FindChildren([IntPtr]::new([long]${e}))
|
|
673
|
+
[WinMsg]::childResults | ForEach-Object { $_ }
|
|
674
|
+
`);if(t){let n=t.split(`
|
|
675
|
+
`).filter(Boolean).map(e=>{let t=e.trim(),n=t.indexOf(`|`);return n===-1?null:{hwnd:t.slice(0,n),className:t.slice(n+1)}}).filter(e=>e!==null);for(let t of mr){let r=n.find(e=>e.className===t);if(r)return B.set(e,r.hwnd),r.hwnd}}let n=S(`
|
|
676
|
+
Add-Type -AssemblyName UIAutomationClient
|
|
677
|
+
Add-Type -AssemblyName UIAutomationTypes
|
|
678
|
+
Add-Type @'
|
|
679
|
+
using System;
|
|
680
|
+
using System.Runtime.InteropServices;
|
|
681
|
+
public class UiaHelper {
|
|
682
|
+
[DllImport("user32.dll")]
|
|
683
|
+
public static extern bool IsWindow(IntPtr hWnd);
|
|
684
|
+
}
|
|
685
|
+
'@
|
|
686
|
+
try {
|
|
687
|
+
$el = [System.Windows.Automation.AutomationElement]::FromHandle([IntPtr]::new([long]${e}))
|
|
688
|
+
if ($el -eq $null) { Write-Output 'NONE'; exit }
|
|
689
|
+
|
|
690
|
+
# Search for Edit or Document control types (covers text editors)
|
|
691
|
+
$editCond = [System.Windows.Automation.PropertyCondition]::new(
|
|
692
|
+
[System.Windows.Automation.AutomationElement]::ControlTypeProperty,
|
|
693
|
+
[System.Windows.Automation.ControlType]::Edit)
|
|
694
|
+
$docCond = [System.Windows.Automation.PropertyCondition]::new(
|
|
695
|
+
[System.Windows.Automation.AutomationElement]::ControlTypeProperty,
|
|
696
|
+
[System.Windows.Automation.ControlType]::Document)
|
|
697
|
+
$orCond = [System.Windows.Automation.OrCondition]::new($editCond, $docCond)
|
|
698
|
+
|
|
699
|
+
$found = $el.FindFirst([System.Windows.Automation.TreeScope]::Descendants, $orCond)
|
|
700
|
+
if ($found -eq $null) { Write-Output 'NONE'; exit }
|
|
701
|
+
|
|
702
|
+
$nativeHwnd = $found.Current.NativeWindowHandle
|
|
703
|
+
if ($nativeHwnd -ne 0) {
|
|
704
|
+
Write-Output $nativeHwnd
|
|
705
|
+
} else {
|
|
706
|
+
Write-Output 'NONE'
|
|
707
|
+
}
|
|
708
|
+
} catch {
|
|
709
|
+
Write-Output 'NONE'
|
|
710
|
+
}
|
|
711
|
+
`);if(n&&n!==`NONE`){let t=n.trim();if(t&&t!==`0`)return B.set(e,t),t}return B.set(e,null),null}function nr(e,t){e=b(e);let n=t.codePointAt(0);if(n===void 0)return!1;let r=`[IntPtr]::new([long]${e})`;return n<=65535?S(`${V}
|
|
712
|
+
[WinMsg]::SendMessage(${r}, [WinMsg]::WM_CHAR, [IntPtr]${n}, [IntPtr]0)
|
|
713
|
+
`)!==null:S(`${V}
|
|
714
|
+
[WinMsg]::SendMessage(${r}, [WinMsg]::WM_CHAR, [IntPtr]${Math.floor((n-65536)/1024)+55296}, [IntPtr]0)
|
|
715
|
+
[WinMsg]::SendMessage(${r}, [WinMsg]::WM_CHAR, [IntPtr]${(n-65536)%1024+56320}, [IntPtr]0)
|
|
716
|
+
`)!==null}function rr(e,t){let n=`[IntPtr]::new([long]${e})`,r=[];for(let e of t){let t=e.codePointAt(0);if(t<=65535)r.push(`[WinMsg]::SendMessage(${n}, [WinMsg]::WM_CHAR, [IntPtr]${t}, [IntPtr]0)`);else{let e=Math.floor((t-65536)/1024)+55296,i=(t-65536)%1024+56320;r.push(`[WinMsg]::SendMessage(${n}, [WinMsg]::WM_CHAR, [IntPtr]${e}, [IntPtr]0)`),r.push(`[WinMsg]::SendMessage(${n}, [WinMsg]::WM_CHAR, [IntPtr]${i}, [IntPtr]0)`)}}return r}function ir(e,t){return S(`${V}
|
|
717
|
+
${rr(z(e),t).join(`
|
|
718
|
+
`)}
|
|
719
|
+
`)!==null}function ar(e,t,n){return e=b(e),S(`${V}
|
|
720
|
+
[WinMsg]::PostMessage([IntPtr]::new([long]${e}), ${n===`down`?`0x0100`:`0x0101`}, [IntPtr]${t}, [WinMsg]::${n===`down`?`KeyDownLParam`:`KeyUpLParam`}(${t}))
|
|
721
|
+
`)!==null}function or(e,t){if(e=z(e),t.length===0)return!1;let n=[],r;for(let e of t){let t=e.toLowerCase(),i=wt[t];if(i!==void 0)Tt.has(t)?n.push(i):r=i;else if(t.length===1)r=t.toUpperCase().charCodeAt(0);else return!1}if(r===void 0)return!1;let i=`[IntPtr]::new([long]${e})`,a=[];for(let e of n)a.push(`[WinMsg]::PostMessage(${i}, [WinMsg]::WM_KEYDOWN, [IntPtr]${e}, [WinMsg]::KeyDownLParam(${e}))`);a.push(`[WinMsg]::PostMessage(${i}, [WinMsg]::WM_KEYDOWN, [IntPtr]${r}, [WinMsg]::KeyDownLParam(${r}))`),a.push(`[WinMsg]::PostMessage(${i}, [WinMsg]::WM_KEYUP, [IntPtr]${r}, [WinMsg]::KeyUpLParam(${r}))`);for(let e of[...n].reverse())a.push(`[WinMsg]::PostMessage(${i}, [WinMsg]::WM_KEYUP, [IntPtr]${e}, [WinMsg]::KeyUpLParam(${e}))`);return S(`${V}
|
|
722
|
+
${a.join(`
|
|
723
|
+
`)}
|
|
724
|
+
`)!==null}function sr(e,t,n=`\0`){e=b(e);let r=n.charCodeAt(0);return S(`${hr}
|
|
725
|
+
[ConsoleInput]::SendKeyToConsole([IntPtr]::new([long]${e}), ${t}, [char]${r})
|
|
726
|
+
`)!==null}function cr(e,t){e=b(e);let n=t.replace(/'/g,`''`);return S(`${hr}
|
|
727
|
+
[ConsoleInput]::SendTextToConsole([IntPtr]::new([long]${e}), '${n}')
|
|
728
|
+
`)!==null}function lr(e,t,n,r){e=z(e);let i=r===`left`?`0x0201`:`0x0204`,a=r===`left`?`0x0202`:`0x0205`,o=`[IntPtr]::new([long]${e})`;return S(`${V}
|
|
729
|
+
$lp = [WinMsg]::MakeLParam(${t}, ${n})
|
|
730
|
+
[WinMsg]::SendMessage(${o}, ${i}, [IntPtr]0, $lp)
|
|
731
|
+
[WinMsg]::SendMessage(${o}, ${a}, [IntPtr]0, $lp)
|
|
732
|
+
`)!==null}function ur(e,t,n){return e=z(e),S(`${V}
|
|
733
|
+
$lp = [WinMsg]::MakeLParam(${t}, ${n})
|
|
734
|
+
[WinMsg]::SendMessage([IntPtr]::new([long]${e}), [WinMsg]::WM_LBUTTONDOWN, [IntPtr]1, $lp)
|
|
735
|
+
`)!==null}function dr(e,t,n){return e=z(e),S(`${V}
|
|
736
|
+
$lp = [WinMsg]::MakeLParam(${t}, ${n})
|
|
737
|
+
[WinMsg]::SendMessage([IntPtr]::new([long]${e}), [WinMsg]::WM_LBUTTONUP, [IntPtr]0, $lp)
|
|
738
|
+
`)!==null}function fr(e,t,n){return e=z(e),S(`${V}
|
|
739
|
+
$lp = [WinMsg]::MakeLParam(${t}, ${n})
|
|
740
|
+
[WinMsg]::SendMessage([IntPtr]::new([long]${e}), 0x0200, [IntPtr]1, $lp)
|
|
741
|
+
`)!==null}function pr(e,t,n,r,i=!1){e=z(e);let a=i?`0x020E`:`0x020A`,o=Math.round(r)*120;return S(`${V}
|
|
742
|
+
# WM_MOUSEWHEEL/WM_MOUSEHWHEEL require screen coords in lParam
|
|
743
|
+
# and wheel delta in high word of wParam
|
|
744
|
+
Add-Type @'
|
|
745
|
+
using System;
|
|
746
|
+
using System.Runtime.InteropServices;
|
|
747
|
+
public class WheelHelper {
|
|
748
|
+
[DllImport("user32.dll")] public static extern bool ClientToScreen(IntPtr hWnd, ref POINT p);
|
|
749
|
+
[StructLayout(LayoutKind.Sequential)] public struct POINT { public int X, Y; }
|
|
750
|
+
|
|
751
|
+
[DllImport("user32.dll", CharSet=CharSet.Unicode, EntryPoint="SendMessageW")]
|
|
752
|
+
public static extern IntPtr SendMsg(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam);
|
|
753
|
+
|
|
754
|
+
public static void Scroll(IntPtr hWnd, int clientX, int clientY, int delta, uint msg) {
|
|
755
|
+
POINT pt; pt.X = clientX; pt.Y = clientY;
|
|
756
|
+
ClientToScreen(hWnd, ref pt);
|
|
757
|
+
IntPtr wParam = (IntPtr)(delta << 16);
|
|
758
|
+
IntPtr lParam = (IntPtr)((pt.Y << 16) | (pt.X & 0xFFFF));
|
|
759
|
+
SendMsg(hWnd, msg, wParam, lParam);
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
'@
|
|
763
|
+
[WheelHelper]::Scroll([IntPtr]::new([long]${e}), ${t}, ${n}, ${o}, ${a})
|
|
764
|
+
`)!==null}var B,V,mr,hr,H=t((()=>{C(),B=new Map,V=`
|
|
765
|
+
Add-Type @'
|
|
766
|
+
using System;
|
|
767
|
+
using System.Collections.Generic;
|
|
768
|
+
using System.Runtime.InteropServices;
|
|
769
|
+
using System.Text;
|
|
770
|
+
|
|
771
|
+
public class WinMsg {
|
|
772
|
+
public delegate bool EnumChildProc(IntPtr hWnd, IntPtr lParam);
|
|
773
|
+
|
|
774
|
+
[DllImport("user32.dll")]
|
|
775
|
+
public static extern bool EnumChildWindows(IntPtr parent, EnumChildProc proc, IntPtr lParam);
|
|
776
|
+
|
|
777
|
+
[DllImport("user32.dll", CharSet=CharSet.Unicode)]
|
|
778
|
+
public static extern int GetClassName(IntPtr h, StringBuilder sb, int max);
|
|
779
|
+
|
|
780
|
+
// CRITICAL: CharSet.Unicode → resolves to SendMessageW
|
|
781
|
+
// SendMessageW sends Unicode WM_CHAR (full UTF-16 codepoints including CJK)
|
|
782
|
+
[DllImport("user32.dll", CharSet=CharSet.Unicode, EntryPoint="SendMessageW")]
|
|
783
|
+
public static extern IntPtr SendMessage(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam);
|
|
784
|
+
|
|
785
|
+
[DllImport("user32.dll", CharSet=CharSet.Unicode, EntryPoint="PostMessageW")]
|
|
786
|
+
public static extern bool PostMessage(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam);
|
|
787
|
+
|
|
788
|
+
[DllImport("user32.dll")]
|
|
789
|
+
public static extern uint MapVirtualKeyW(uint uCode, uint uMapType);
|
|
790
|
+
|
|
791
|
+
public static IntPtr MakeLParam(int lo, int hi) {
|
|
792
|
+
return (IntPtr)((hi << 16) | (lo & 0xFFFF));
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
// Build lParam for WM_KEYDOWN / WM_KEYUP with correct scan code
|
|
796
|
+
// lParam bits: 0-15 repeat count, 16-23 scan code, 24 extended, 30 prev state, 31 transition
|
|
797
|
+
public static IntPtr KeyDownLParam(uint vk) {
|
|
798
|
+
uint scanCode = MapVirtualKeyW(vk, 0); // MAPVK_VK_TO_VSC = 0
|
|
799
|
+
return (IntPtr)(1 | (scanCode << 16)); // repeat=1, scanCode in bits 16-23
|
|
800
|
+
}
|
|
801
|
+
public static IntPtr KeyUpLParam(uint vk) {
|
|
802
|
+
uint scanCode = MapVirtualKeyW(vk, 0);
|
|
803
|
+
return (IntPtr)(1 | (scanCode << 16) | (1 << 30) | (1u << 31)); // prev=1, transition=1
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
public const uint WM_CHAR = 0x0102;
|
|
807
|
+
public const uint WM_KEYDOWN = 0x0100;
|
|
808
|
+
public const uint WM_KEYUP = 0x0101;
|
|
809
|
+
public const uint WM_LBUTTONDOWN = 0x0201;
|
|
810
|
+
public const uint WM_LBUTTONUP = 0x0202;
|
|
811
|
+
public const uint WM_RBUTTONDOWN = 0x0204;
|
|
812
|
+
public const uint WM_RBUTTONUP = 0x0205;
|
|
813
|
+
|
|
814
|
+
public static List<string> childResults = new List<string>();
|
|
815
|
+
|
|
816
|
+
public static void FindChildren(IntPtr parent) {
|
|
817
|
+
childResults.Clear();
|
|
818
|
+
EnumChildWindows(parent, delegate(IntPtr hWnd, IntPtr lParam) {
|
|
819
|
+
StringBuilder sb = new StringBuilder(256);
|
|
820
|
+
GetClassName(hWnd, sb, sb.Capacity);
|
|
821
|
+
childResults.Add(hWnd.ToInt64() + "|" + sb.ToString());
|
|
822
|
+
return true;
|
|
823
|
+
}, IntPtr.Zero);
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
'@
|
|
827
|
+
`,mr=[`Windows.UI.Input.InputSite.WindowClass`,`RichEditD2DPT`,`RichEdit20W`,`Edit`,`Scintilla`,`Chrome_RenderWidgetHostHWND`,`TextBox`,`RichTextBox`,`Windows.UI.Core.CoreWindow`],hr=`
|
|
828
|
+
Add-Type @'
|
|
829
|
+
using System;
|
|
830
|
+
using System.Runtime.InteropServices;
|
|
831
|
+
|
|
832
|
+
public class ConsoleInput {
|
|
833
|
+
[DllImport("kernel32.dll", SetLastError=true)]
|
|
834
|
+
public static extern bool AttachConsole(uint dwProcessId);
|
|
835
|
+
|
|
836
|
+
[DllImport("kernel32.dll", SetLastError=true)]
|
|
837
|
+
public static extern bool FreeConsole();
|
|
838
|
+
|
|
839
|
+
[DllImport("kernel32.dll", SetLastError=true)]
|
|
840
|
+
public static extern IntPtr GetStdHandle(int nStdHandle);
|
|
841
|
+
|
|
842
|
+
[DllImport("kernel32.dll", CharSet=CharSet.Unicode, SetLastError=true)]
|
|
843
|
+
public static extern bool WriteConsoleInput(
|
|
844
|
+
IntPtr hConsoleInput,
|
|
845
|
+
INPUT_RECORD[] lpBuffer,
|
|
846
|
+
uint nLength,
|
|
847
|
+
out uint lpNumberOfEventsWritten);
|
|
848
|
+
|
|
849
|
+
[DllImport("kernel32.dll")]
|
|
850
|
+
public static extern uint MapVirtualKeyW(uint uCode, uint uMapType);
|
|
851
|
+
|
|
852
|
+
[DllImport("user32.dll")]
|
|
853
|
+
public static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId);
|
|
854
|
+
|
|
855
|
+
public const int STD_INPUT_HANDLE = -10;
|
|
856
|
+
|
|
857
|
+
[StructLayout(LayoutKind.Explicit)]
|
|
858
|
+
public struct INPUT_RECORD {
|
|
859
|
+
[FieldOffset(0)] public ushort EventType;
|
|
860
|
+
[FieldOffset(4)] public KEY_EVENT_RECORD KeyEvent;
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
[StructLayout(LayoutKind.Explicit, CharSet=CharSet.Unicode)]
|
|
864
|
+
public struct KEY_EVENT_RECORD {
|
|
865
|
+
[FieldOffset(0)] public bool bKeyDown;
|
|
866
|
+
[FieldOffset(4)] public ushort wRepeatCount;
|
|
867
|
+
[FieldOffset(6)] public ushort wVirtualKeyCode;
|
|
868
|
+
[FieldOffset(8)] public ushort wVirtualScanCode;
|
|
869
|
+
[FieldOffset(10)] public char UnicodeChar;
|
|
870
|
+
[FieldOffset(12)] public uint dwControlKeyState;
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
public static bool SendKeyToConsole(IntPtr hwnd, ushort vk, char ch) {
|
|
874
|
+
uint pid;
|
|
875
|
+
GetWindowThreadProcessId(hwnd, out pid);
|
|
876
|
+
if (pid == 0) return false;
|
|
877
|
+
|
|
878
|
+
FreeConsole();
|
|
879
|
+
if (!AttachConsole(pid)) return false;
|
|
880
|
+
|
|
881
|
+
try {
|
|
882
|
+
IntPtr hInput = GetStdHandle(STD_INPUT_HANDLE);
|
|
883
|
+
if (hInput == IntPtr.Zero || hInput == (IntPtr)(-1)) return false;
|
|
884
|
+
|
|
885
|
+
ushort scanCode = (ushort)MapVirtualKeyW(vk, 0);
|
|
886
|
+
INPUT_RECORD[] records = new INPUT_RECORD[2];
|
|
887
|
+
|
|
888
|
+
// Key down
|
|
889
|
+
records[0].EventType = 1; // KEY_EVENT
|
|
890
|
+
records[0].KeyEvent.bKeyDown = true;
|
|
891
|
+
records[0].KeyEvent.wRepeatCount = 1;
|
|
892
|
+
records[0].KeyEvent.wVirtualKeyCode = vk;
|
|
893
|
+
records[0].KeyEvent.wVirtualScanCode = scanCode;
|
|
894
|
+
records[0].KeyEvent.UnicodeChar = ch;
|
|
895
|
+
records[0].KeyEvent.dwControlKeyState = 0;
|
|
896
|
+
|
|
897
|
+
// Key up
|
|
898
|
+
records[1].EventType = 1;
|
|
899
|
+
records[1].KeyEvent.bKeyDown = false;
|
|
900
|
+
records[1].KeyEvent.wRepeatCount = 1;
|
|
901
|
+
records[1].KeyEvent.wVirtualKeyCode = vk;
|
|
902
|
+
records[1].KeyEvent.wVirtualScanCode = scanCode;
|
|
903
|
+
records[1].KeyEvent.UnicodeChar = ch;
|
|
904
|
+
records[1].KeyEvent.dwControlKeyState = 0;
|
|
905
|
+
|
|
906
|
+
uint written;
|
|
907
|
+
return WriteConsoleInput(hInput, records, 2, out written);
|
|
908
|
+
} finally {
|
|
909
|
+
FreeConsole();
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
public static bool SendTextToConsole(IntPtr hwnd, string text) {
|
|
914
|
+
uint pid;
|
|
915
|
+
GetWindowThreadProcessId(hwnd, out pid);
|
|
916
|
+
if (pid == 0) return false;
|
|
917
|
+
|
|
918
|
+
FreeConsole();
|
|
919
|
+
if (!AttachConsole(pid)) return false;
|
|
920
|
+
|
|
921
|
+
try {
|
|
922
|
+
IntPtr hInput = GetStdHandle(STD_INPUT_HANDLE);
|
|
923
|
+
if (hInput == IntPtr.Zero || hInput == (IntPtr)(-1)) return false;
|
|
924
|
+
|
|
925
|
+
INPUT_RECORD[] records = new INPUT_RECORD[text.Length * 2];
|
|
926
|
+
for (int i = 0; i < text.Length; i++) {
|
|
927
|
+
char c = text[i];
|
|
928
|
+
ushort vk = 0;
|
|
929
|
+
ushort sc = 0;
|
|
930
|
+
|
|
931
|
+
// Key down
|
|
932
|
+
records[i * 2].EventType = 1;
|
|
933
|
+
records[i * 2].KeyEvent.bKeyDown = true;
|
|
934
|
+
records[i * 2].KeyEvent.wRepeatCount = 1;
|
|
935
|
+
records[i * 2].KeyEvent.wVirtualKeyCode = vk;
|
|
936
|
+
records[i * 2].KeyEvent.wVirtualScanCode = sc;
|
|
937
|
+
records[i * 2].KeyEvent.UnicodeChar = c;
|
|
938
|
+
records[i * 2].KeyEvent.dwControlKeyState = 0;
|
|
939
|
+
|
|
940
|
+
// Key up
|
|
941
|
+
records[i * 2 + 1].EventType = 1;
|
|
942
|
+
records[i * 2 + 1].KeyEvent.bKeyDown = false;
|
|
943
|
+
records[i * 2 + 1].KeyEvent.wRepeatCount = 1;
|
|
944
|
+
records[i * 2 + 1].KeyEvent.wVirtualKeyCode = vk;
|
|
945
|
+
records[i * 2 + 1].KeyEvent.wVirtualScanCode = sc;
|
|
946
|
+
records[i * 2 + 1].KeyEvent.UnicodeChar = c;
|
|
947
|
+
records[i * 2 + 1].KeyEvent.dwControlKeyState = 0;
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
uint written;
|
|
951
|
+
return WriteConsoleInput(hInput, records, (uint)records.Length, out written);
|
|
952
|
+
} finally {
|
|
953
|
+
FreeConsole();
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
'@
|
|
958
|
+
`})),U=n({bindFile:()=>xr,bindWindow:()=>br,getBoundAppType:()=>yr,getBoundHwnd:()=>vr,platform:()=>Pr,unbindWindow:()=>Sr});function gr(){if(!Tr)try{Tr=($n(),e(Kn))}catch{}return Tr}function _r(e,t={}){try{let n=gr();return n?n.callSync(e,t):null}catch{return null}}function vr(){return K}function yr(){return Er}function br(e,t){e=b(e),K&&(mn(K),bn(),Pn()),K=e,Er=`generic`,Dr=null,x(`
|
|
959
|
+
Add-Type @'
|
|
960
|
+
using System;
|
|
961
|
+
using System.Runtime.InteropServices;
|
|
962
|
+
public class CuActivate {
|
|
963
|
+
[DllImport("user32.dll")] public static extern IntPtr GetForegroundWindow();
|
|
964
|
+
[DllImport("user32.dll")] public static extern bool SetForegroundWindow(IntPtr h);
|
|
965
|
+
[DllImport("user32.dll")] public static extern bool IsIconic(IntPtr h);
|
|
966
|
+
[DllImport("user32.dll")] public static extern bool ShowWindow(IntPtr h, int cmd);
|
|
967
|
+
}
|
|
968
|
+
'@
|
|
969
|
+
$prev = [CuActivate]::GetForegroundWindow()
|
|
970
|
+
$target = [IntPtr]::new([long]${e})
|
|
971
|
+
if ([CuActivate]::IsIconic($target)) { [CuActivate]::ShowWindow($target, 9) | Out-Null }
|
|
972
|
+
[CuActivate]::SetForegroundWindow($target) | Out-Null
|
|
973
|
+
Start-Sleep -Milliseconds 100
|
|
974
|
+
if ($prev -ne [IntPtr]::Zero -and $prev -ne $target) {
|
|
975
|
+
[CuActivate]::SetForegroundWindow($prev) | Out-Null
|
|
976
|
+
}
|
|
977
|
+
`),pn(e),vn(e),Mn(e)}function xr(e,t){K=null,Er=t,Dr=e}function Sr(){K&&mn(K),bn(),Pn(),W().clearEditChildCache(),K=null,Er=null,Dr=null}function W(){return Or??(Or=(H(),e(R)))}function Cr(e){let t=pe(),n=e.toLowerCase();for(let e of t)if((e.title??``).toLowerCase().includes(n))return{hwnd:e.hwnd,pid:e.pid};return null}function wr(){bn(),Pn();try{gr()?.stopBridge()}catch{}}var Tr,G,K,Er,Dr,Or,kr,Ar,jr,Mr,q,Nr,Pr,J=t((()=>{ce(),fn(),hn(),kn(),Gn(),C(),G=`
|
|
978
|
+
Add-Type -Language CSharp @'
|
|
979
|
+
using System;
|
|
980
|
+
using System.Runtime.InteropServices;
|
|
981
|
+
using System.Text;
|
|
982
|
+
using System.Diagnostics;
|
|
983
|
+
|
|
984
|
+
public class CuWin32 {
|
|
985
|
+
// --- Cursor ---
|
|
986
|
+
[DllImport("user32.dll")] public static extern bool SetCursorPos(int X, int Y);
|
|
987
|
+
[DllImport("user32.dll")] public static extern bool GetCursorPos(out POINT p);
|
|
988
|
+
[StructLayout(LayoutKind.Sequential)] public struct POINT { public int X; public int Y; }
|
|
989
|
+
|
|
990
|
+
// --- SendInput ---
|
|
991
|
+
[StructLayout(LayoutKind.Sequential)] public struct MOUSEINPUT {
|
|
992
|
+
public int dx; public int dy; public int mouseData; public uint dwFlags; public uint time; public IntPtr dwExtraInfo;
|
|
993
|
+
}
|
|
994
|
+
[StructLayout(LayoutKind.Explicit)] public struct INPUT {
|
|
995
|
+
[FieldOffset(0)] public uint type;
|
|
996
|
+
[FieldOffset(4)] public MOUSEINPUT mi;
|
|
997
|
+
}
|
|
998
|
+
[StructLayout(LayoutKind.Sequential)] public struct KEYBDINPUT {
|
|
999
|
+
public ushort wVk; public ushort wScan; public uint dwFlags; public uint time; public IntPtr dwExtraInfo;
|
|
1000
|
+
}
|
|
1001
|
+
[StructLayout(LayoutKind.Explicit)] public struct KINPUT {
|
|
1002
|
+
[FieldOffset(0)] public uint type;
|
|
1003
|
+
[FieldOffset(4)] public KEYBDINPUT ki;
|
|
1004
|
+
}
|
|
1005
|
+
[DllImport("user32.dll", SetLastError=true)] public static extern uint SendInput(uint n, INPUT[] i, int cb);
|
|
1006
|
+
[DllImport("user32.dll", SetLastError=true)] public static extern uint SendInput(uint n, KINPUT[] i, int cb);
|
|
1007
|
+
|
|
1008
|
+
// --- Keyboard ---
|
|
1009
|
+
[DllImport("user32.dll")] public static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, UIntPtr dwExtraInfo);
|
|
1010
|
+
[DllImport("user32.dll")] public static extern short VkKeyScan(char ch);
|
|
1011
|
+
|
|
1012
|
+
// --- Window ---
|
|
1013
|
+
[DllImport("user32.dll")] public static extern IntPtr GetForegroundWindow();
|
|
1014
|
+
[DllImport("user32.dll")] public static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint pid);
|
|
1015
|
+
[DllImport("user32.dll", CharSet=CharSet.Unicode)] public static extern int GetWindowText(IntPtr hWnd, StringBuilder sb, int max);
|
|
1016
|
+
|
|
1017
|
+
// Constants
|
|
1018
|
+
public const uint INPUT_MOUSE = 0, INPUT_KEYBOARD = 1;
|
|
1019
|
+
public const uint MOUSEEVENTF_LEFTDOWN = 0x0002, MOUSEEVENTF_LEFTUP = 0x0004;
|
|
1020
|
+
public const uint MOUSEEVENTF_RIGHTDOWN = 0x0008, MOUSEEVENTF_RIGHTUP = 0x0010;
|
|
1021
|
+
public const uint MOUSEEVENTF_MIDDLEDOWN = 0x0020, MOUSEEVENTF_MIDDLEUP = 0x0040;
|
|
1022
|
+
public const uint MOUSEEVENTF_WHEEL = 0x0800, MOUSEEVENTF_HWHEEL = 0x1000;
|
|
1023
|
+
public const uint KEYEVENTF_KEYUP = 0x0002;
|
|
1024
|
+
}
|
|
1025
|
+
'@
|
|
1026
|
+
`,K=null,Er=null,Dr=null,kr={async moveMouse(e,t){if(K){yn(Math.round(e),Math.round(t));return}x(`${G}; [CuWin32]::SetCursorPos(${Math.round(e)}, ${Math.round(t)}) | Out-Null`)},async click(e,t,n){if(K){yn(Math.round(e),Math.round(t),!0);let r=W().findEditChild(K)??K;W().sendClick(r,Math.round(e),Math.round(t),n)||W().sendClick(K,Math.round(e),Math.round(t),n);return}x(`${G}; [CuWin32]::SetCursorPos(${Math.round(e)}, ${Math.round(t)}) | Out-Null; $i = New-Object CuWin32+INPUT; $i.type=[CuWin32]::INPUT_MOUSE; $i.mi.dwFlags=[CuWin32]::${n===`left`?`MOUSEEVENTF_LEFTDOWN`:n===`right`?`MOUSEEVENTF_RIGHTDOWN`:`MOUSEEVENTF_MIDDLEDOWN`}; [CuWin32]::SendInput(1, @($i), [Runtime.InteropServices.Marshal]::SizeOf($i)) | Out-Null; $i.mi.dwFlags=[CuWin32]::${n===`left`?`MOUSEEVENTF_LEFTUP`:n===`right`?`MOUSEEVENTF_RIGHTUP`:`MOUSEEVENTF_MIDDLEUP`}; [CuWin32]::SendInput(1, @($i), [Runtime.InteropServices.Marshal]::SizeOf($i)) | Out-Null`)},async typeText(t){if(Er===`word`&&Dr){let{appendText:n}=(an(),e(Gt));n(Dr,t);return}if(K){if(!W().sendText(K,t))throw Error(`typeText failed: SendMessage to HWND ${K} returned false. The edit control may not have been found (findEditChild returned null).`);return}throw Error(`typeText requires a bound window or file. Call open() first.`)},async key(e,t){if(K){let n=wt[e.toLowerCase()]??(e.length===1?e.charCodeAt(0):0);n&&W().sendKey(K,n,t===`release`?`up`:`down`);return}throw Error(`key requires a bound window HWND. Call open() first.`)},async keys(e){if(K){if(!W().sendKeys(K,e))throw Error(`keys [${e.join(`+`)}] failed on HWND ${K}`);return}throw Error(`keys requires a bound window HWND. Call open() first.`)},async scroll(e,t){if(K){let n=t===`vertical`?`0x0115`:`0x0114`,r=e>0?`1`:`0`,i=Math.abs(Math.round(e)),a=`
|
|
1027
|
+
Add-Type @'
|
|
1028
|
+
using System;
|
|
1029
|
+
using System.Runtime.InteropServices;
|
|
1030
|
+
public class WScroll {
|
|
1031
|
+
[DllImport("user32.dll", CharSet=CharSet.Unicode, EntryPoint="SendMessageW")]
|
|
1032
|
+
public static extern IntPtr SendMessage(IntPtr h, uint m, IntPtr w, IntPtr l);
|
|
1033
|
+
}
|
|
1034
|
+
'@
|
|
1035
|
+
`;for(let e=0;e<i;e++)a+=`[WScroll]::SendMessage([IntPtr]::new([long]${K}), ${n}, [IntPtr]${r}, [IntPtr]::Zero) | Out-Null; `;x(a);return}x(`${G}; $i = New-Object CuWin32+INPUT; $i.type=[CuWin32]::INPUT_MOUSE; $i.mi.dwFlags=[CuWin32]::${t===`vertical`?`MOUSEEVENTF_WHEEL`:`MOUSEEVENTF_HWHEEL`}; $i.mi.mouseData=${e*120}; [CuWin32]::SendInput(1, @($i), [Runtime.InteropServices.Marshal]::SizeOf($i)) | Out-Null`)},async mouseLocation(){let[e,t]=x(`${G}; $p = New-Object CuWin32+POINT; [CuWin32]::GetCursorPos([ref]$p) | Out-Null; "$($p.X),$($p.Y)"`).split(`,`);return{x:Number(e),y:Number(t)}},async sendChar(e,t){W().sendChar(String(e),t)},async sendKey(e,t,n){W().sendKey(String(e),t,n)},async sendClick(e,t,n,r){W().sendClick(String(e),t,n,r)},async sendText(e,t){W().sendText(String(e),t)}},Ar={async captureScreen(e){if(K){let e=await this.captureWindow?.(String(K));if(e)return e}let t=_r(`screenshot`,{display_id:e??0});if(t&&t.base64)return t;throw Error(`[computer-use] Screenshot failed: Python bridge returned no data. Ensure python3 + mss + Pillow are installed (pip install mss Pillow).`)},async captureRegion(e,t,n,r){if(K){let e=await this.captureWindow?.(String(K));if(e)return e}return this.captureScreen()},async captureWindow(e){let t=_r(`screenshot_window`,{hwnd:String(e)});if(t&&t.base64)return t;throw Error(`[computer-use] Window screenshot failed for HWND ${e}: Python bridge returned no data.`)}},jr={listAll(){try{return x(`
|
|
1036
|
+
Add-Type -AssemblyName System.Windows.Forms
|
|
1037
|
+
$result = @()
|
|
1038
|
+
$idx = 0
|
|
1039
|
+
foreach ($s in [System.Windows.Forms.Screen]::AllScreens) {
|
|
1040
|
+
$result += "$($s.Bounds.Width),$($s.Bounds.Height),$idx,$($s.Primary)"
|
|
1041
|
+
$idx++
|
|
1042
|
+
}
|
|
1043
|
+
$result -join "|"
|
|
1044
|
+
`).split(`|`).filter(Boolean).map(e=>{let[t,n,r]=e.split(`,`);return{width:Number(t),height:Number(n),scaleFactor:1,displayId:Number(r)}})}catch{return[{width:1920,height:1080,scaleFactor:1,displayId:0}]}},getSize(e){let t=this.listAll();if(e!==void 0){let n=t.find(t=>t.displayId===e);if(n)return n}return t[0]??{width:1920,height:1080,scaleFactor:1,displayId:0}}},Mr={listRunning(){return pe().map(e=>({id:String(e.hwnd),pid:e.pid,title:e.title}))},async listInstalled(){try{return(await St(`
|
|
1045
|
+
$apps = @()
|
|
1046
|
+
|
|
1047
|
+
# Traditional Win32 apps from registry
|
|
1048
|
+
$paths = @(
|
|
1049
|
+
'HKLM:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\*',
|
|
1050
|
+
'HKLM:\\SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\*',
|
|
1051
|
+
'HKCU:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\*'
|
|
1052
|
+
)
|
|
1053
|
+
foreach ($p in $paths) {
|
|
1054
|
+
Get-ItemProperty $p -ErrorAction SilentlyContinue | Where-Object { $_.DisplayName } | ForEach-Object {
|
|
1055
|
+
$apps += "$($_.DisplayName)|$($_.InstallLocation)|$($_.PSChildName)"
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
|
|
1059
|
+
# UWP/MSIX apps (Windows 10/11 Store apps)
|
|
1060
|
+
Get-AppxPackage -ErrorAction SilentlyContinue | Where-Object { $_.IsFramework -eq $false -and $_.SignatureKind -eq 'Store' } | ForEach-Object {
|
|
1061
|
+
$cleanName = $_.Name -replace '^Microsoft\\.Windows', '' -replace '^Microsoft\\.', ''
|
|
1062
|
+
$apps += "$cleanName|$($_.InstallLocation)|$($_.PackageFamilyName)"
|
|
1063
|
+
}
|
|
1064
|
+
|
|
1065
|
+
$apps | Select-Object -Unique | Select-Object -First 300
|
|
1066
|
+
`)).split(`
|
|
1067
|
+
`).filter(Boolean).map(e=>{let[t,n,r]=e.trim().split(`|`,3);return{id:(r??t??``).trim(),displayName:(t??``).trim(),path:(n??``).trim()}})}catch{return[]}},async open(e){let t=on(e);if(t===`excel`||t===`word`){let t=await sn(e);t.filePath&&xr(t.filePath,t.type);return}let n=e;if(e.includes(`_`)&&e.includes(`.`)){let t=e.split(`_`)[0]?.split(`.`)??[],r=t[t.length-1]??e;n=r.replace(/^Windows/,``)||r}let r=Cr(n);if(r){br(r.hwnd,r.pid);return}let i=n.replace(/'/g,`''`),a=await St(`
|
|
1068
|
+
${G}
|
|
1069
|
+
Add-Type @'
|
|
1070
|
+
using System;
|
|
1071
|
+
using System.Runtime.InteropServices;
|
|
1072
|
+
using System.Text;
|
|
1073
|
+
public class CuLaunch {
|
|
1074
|
+
public delegate bool EnumProc(IntPtr h, IntPtr lp);
|
|
1075
|
+
[DllImport("user32.dll")] public static extern bool EnumWindows(EnumProc cb, IntPtr lp);
|
|
1076
|
+
[DllImport("user32.dll")] public static extern bool IsWindowVisible(IntPtr h);
|
|
1077
|
+
[DllImport("user32.dll")] public static extern uint GetWindowThreadProcessId(IntPtr h, out uint pid);
|
|
1078
|
+
[DllImport("user32.dll", CharSet=CharSet.Unicode)] public static extern int GetWindowText(IntPtr h, StringBuilder sb, int n);
|
|
1079
|
+
[DllImport("user32.dll")] public static extern bool ShowWindow(IntPtr h, int cmd);
|
|
1080
|
+
public const int SW_SHOWMINNOACTIVE = 7;
|
|
1081
|
+
// Get all visible window HWNDs as array
|
|
1082
|
+
public static long[] GetAllVisibleHwnds() {
|
|
1083
|
+
var list = new System.Collections.Generic.List<long>();
|
|
1084
|
+
EnumWindows((h, _) => {
|
|
1085
|
+
if (IsWindowVisible(h)) list.Add(h.ToInt64());
|
|
1086
|
+
return true;
|
|
1087
|
+
}, IntPtr.Zero);
|
|
1088
|
+
return list.ToArray();
|
|
1089
|
+
}
|
|
1090
|
+
// Get PID for a single HWND
|
|
1091
|
+
public static uint GetPidForHwnd(long hwnd) {
|
|
1092
|
+
uint pid; GetWindowThreadProcessId((IntPtr)hwnd, out pid);
|
|
1093
|
+
return pid;
|
|
1094
|
+
}
|
|
1095
|
+
// Get title for a single HWND
|
|
1096
|
+
public static string GetTitle(long hwnd) {
|
|
1097
|
+
var sb = new StringBuilder(256);
|
|
1098
|
+
GetWindowText((IntPtr)hwnd, sb, 256);
|
|
1099
|
+
return sb.ToString();
|
|
1100
|
+
}
|
|
1101
|
+
}
|
|
1102
|
+
'@
|
|
1103
|
+
# Launch strategy: all exe-based, no GUI dialogs.
|
|
1104
|
+
# 1) exact path 2) exe in PATH 3) registry install dir 4) raw name
|
|
1105
|
+
$target = '${i}'
|
|
1106
|
+
$proc = $null
|
|
1107
|
+
|
|
1108
|
+
# 1. Exact file path
|
|
1109
|
+
if (Test-Path $target) {
|
|
1110
|
+
$proc = Start-Process $target -PassThru -ErrorAction SilentlyContinue
|
|
1111
|
+
}
|
|
1112
|
+
|
|
1113
|
+
# 2. exe name in PATH (notepad.exe, code.exe, chrome.exe, etc.)
|
|
1114
|
+
if (-not $proc) {
|
|
1115
|
+
# Try with .exe suffix if not already
|
|
1116
|
+
$tryExe = if ($target -notmatch '[.]exe$') { "$target.exe" } else { $target }
|
|
1117
|
+
$found = Get-Command $tryExe -ErrorAction SilentlyContinue | Select-Object -First 1
|
|
1118
|
+
if (-not $found) { $found = Get-Command $target -ErrorAction SilentlyContinue | Select-Object -First 1 }
|
|
1119
|
+
if ($found) { $proc = Start-Process $found.Source -PassThru -ErrorAction SilentlyContinue }
|
|
1120
|
+
}
|
|
1121
|
+
|
|
1122
|
+
# 3. Search registry for install location by display name → find .exe
|
|
1123
|
+
if (-not $proc) {
|
|
1124
|
+
$regPaths = @('HKLM:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\*','HKLM:\\SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\*','HKCU:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\*')
|
|
1125
|
+
foreach ($p in $regPaths) {
|
|
1126
|
+
$app = Get-ItemProperty $p -ErrorAction SilentlyContinue | Where-Object {
|
|
1127
|
+
$_.DisplayName -and $_.DisplayName -match [regex]::Escape($target)
|
|
1128
|
+
} | Select-Object -First 1
|
|
1129
|
+
if ($app) {
|
|
1130
|
+
# Try DisplayIcon (often the exe path), then InstallLocation
|
|
1131
|
+
$exePath = $null
|
|
1132
|
+
if ($app.DisplayIcon -and $app.DisplayIcon -match '[.]exe') {
|
|
1133
|
+
$exePath = ($app.DisplayIcon -split ',')[0].Trim('"')
|
|
1134
|
+
}
|
|
1135
|
+
if (-not $exePath -and $app.InstallLocation) {
|
|
1136
|
+
$exeFile = Get-ChildItem $app.InstallLocation -Filter '*.exe' -ErrorAction SilentlyContinue | Select-Object -First 1
|
|
1137
|
+
if ($exeFile) { $exePath = $exeFile.FullName }
|
|
1138
|
+
}
|
|
1139
|
+
if ($exePath -and (Test-Path $exePath)) {
|
|
1140
|
+
$proc = Start-Process $exePath -PassThru -ErrorAction SilentlyContinue
|
|
1141
|
+
break
|
|
1142
|
+
}
|
|
1143
|
+
}
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
|
|
1147
|
+
# 4. Last resort: direct Start-Process (Windows may resolve it)
|
|
1148
|
+
if (-not $proc) { $proc = Start-Process -FilePath $target -PassThru -ErrorAction SilentlyContinue }
|
|
1149
|
+
|
|
1150
|
+
if (-not $proc) { Write-Host "LAUNCH_FAILED"; exit }
|
|
1151
|
+
|
|
1152
|
+
# Snapshot ALL visible window HWNDs before the new window appears
|
|
1153
|
+
$beforeHwnds = [CuLaunch]::GetAllVisibleHwnds()
|
|
1154
|
+
|
|
1155
|
+
# Wait for a NEW window from our process PID
|
|
1156
|
+
$hwnd = 0
|
|
1157
|
+
for ($i = 0; $i -lt 50; $i++) {
|
|
1158
|
+
Start-Sleep -Milliseconds 200
|
|
1159
|
+
$afterHwnds = [CuLaunch]::GetAllVisibleHwnds()
|
|
1160
|
+
# Find new windows (in after but not in before)
|
|
1161
|
+
foreach ($h in $afterHwnds) {
|
|
1162
|
+
if ($beforeHwnds -contains $h) { continue }
|
|
1163
|
+
# New window found — check PID
|
|
1164
|
+
$wPid = [CuLaunch]::GetPidForHwnd($h)
|
|
1165
|
+
if ($wPid -eq [uint32]$proc.Id) {
|
|
1166
|
+
$hwnd = $h; break # exact PID match
|
|
1167
|
+
}
|
|
1168
|
+
}
|
|
1169
|
+
if ($hwnd -ne 0) { break }
|
|
1170
|
+
# PID didn't match (process redirect) — accept new window matching title hint
|
|
1171
|
+
if ($i -gt 10) {
|
|
1172
|
+
$hint = '${i}'.Split('\\')[-1].Replace('.exe','')
|
|
1173
|
+
foreach ($h in $afterHwnds) {
|
|
1174
|
+
if ($beforeHwnds -contains $h) { continue }
|
|
1175
|
+
$title = [CuLaunch]::GetTitle($h)
|
|
1176
|
+
if ($title -and $title.IndexOf($hint, [StringComparison]::OrdinalIgnoreCase) -ge 0) {
|
|
1177
|
+
$hwnd = $h; break
|
|
1178
|
+
}
|
|
1179
|
+
}
|
|
1180
|
+
if ($hwnd -ne 0) { break }
|
|
1181
|
+
}
|
|
1182
|
+
}
|
|
1183
|
+
if ($hwnd -eq 0) { Write-Host "HWND_NOT_FOUND|$($proc.Id)"; exit }
|
|
1184
|
+
# Move offscreen instead of minimizing — keeps window restored so
|
|
1185
|
+
# PrintWindow and SendMessage work without needing restore/re-minimize.
|
|
1186
|
+
# User cannot see the window at -32000,-32000.
|
|
1187
|
+
Add-Type @'
|
|
1188
|
+
using System;
|
|
1189
|
+
using System.Runtime.InteropServices;
|
|
1190
|
+
public class CuPos {
|
|
1191
|
+
[DllImport("user32.dll")] public static extern bool SetWindowPos(IntPtr h, IntPtr a, int x, int y, int w, int h2, uint f);
|
|
1192
|
+
public const uint SWP_NOSIZE = 0x0001;
|
|
1193
|
+
public const uint SWP_NOZORDER = 0x0004;
|
|
1194
|
+
public const uint SWP_NOACTIVATE = 0x0010;
|
|
1195
|
+
}
|
|
1196
|
+
'@
|
|
1197
|
+
[CuPos]::SetWindowPos([IntPtr]::new([long]$hwnd), [IntPtr]::Zero, -32000, -32000, 0, 0, [CuPos]::SWP_NOSIZE -bor [CuPos]::SWP_NOZORDER -bor [CuPos]::SWP_NOACTIVATE) | Out-Null
|
|
1198
|
+
Write-Host "$hwnd|$($proc.Id)"
|
|
1199
|
+
`);if(!a)throw Error(`open(): failed to launch '${e}' — no output from launcher script`);if(a.startsWith(`LAUNCH_FAILED`))throw Error(`open(): failed to launch '${e}' — process did not start (${a})`);if(a.startsWith(`HWND_NOT_FOUND`))throw Error(`open(): launched '${e}' but could not find its window HWND (${a})`);let o=a.trim().split(`|`),s=o[0].trim(),c=Number(o[1]);s&&s!==`0`&&br(s,c)},getFrontmostApp(){try{let e=x(`${G}
|
|
1200
|
+
$hwnd = [CuWin32]::GetForegroundWindow()
|
|
1201
|
+
$procId = [uint32]0
|
|
1202
|
+
[CuWin32]::GetWindowThreadProcessId($hwnd, [ref]$procId) | Out-Null
|
|
1203
|
+
$proc = Get-Process -Id $procId -ErrorAction SilentlyContinue
|
|
1204
|
+
"$($proc.MainModule.FileName)|$($proc.ProcessName)"`);if(!e||!e.includes(`|`))return null;let[t,n]=e.split(`|`,2);return{id:t,appName:n}}catch{return null}},findWindowByTitle(e){let t=pe().find(t=>t.title.includes(e));return t?{id:String(t.hwnd),pid:t.pid,title:t.title}:null}},q=`
|
|
1205
|
+
Add-Type @'
|
|
1206
|
+
using System;
|
|
1207
|
+
using System.Runtime.InteropServices;
|
|
1208
|
+
|
|
1209
|
+
public class CuWinMgmt {
|
|
1210
|
+
[DllImport("user32.dll")]
|
|
1211
|
+
public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
|
|
1212
|
+
|
|
1213
|
+
[DllImport("user32.dll")]
|
|
1214
|
+
public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hAfter, int X, int Y, int cx, int cy, uint uFlags);
|
|
1215
|
+
|
|
1216
|
+
[DllImport("user32.dll")]
|
|
1217
|
+
public static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);
|
|
1218
|
+
|
|
1219
|
+
[DllImport("user32.dll")]
|
|
1220
|
+
public static extern bool SetForegroundWindow(IntPtr hWnd);
|
|
1221
|
+
|
|
1222
|
+
[DllImport("user32.dll")]
|
|
1223
|
+
public static extern bool BringWindowToTop(IntPtr hWnd);
|
|
1224
|
+
|
|
1225
|
+
[DllImport("user32.dll", CharSet=CharSet.Unicode, EntryPoint="SendMessageW")]
|
|
1226
|
+
public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
|
|
1227
|
+
|
|
1228
|
+
[DllImport("user32.dll")]
|
|
1229
|
+
public static extern bool IsIconic(IntPtr hWnd);
|
|
1230
|
+
|
|
1231
|
+
[DllImport("user32.dll")]
|
|
1232
|
+
public static extern bool IsZoomed(IntPtr hWnd);
|
|
1233
|
+
|
|
1234
|
+
[StructLayout(LayoutKind.Sequential)]
|
|
1235
|
+
public struct RECT {
|
|
1236
|
+
public int Left; public int Top; public int Right; public int Bottom;
|
|
1237
|
+
}
|
|
1238
|
+
|
|
1239
|
+
// ShowWindow constants
|
|
1240
|
+
public const int SW_MINIMIZE = 6;
|
|
1241
|
+
public const int SW_MAXIMIZE = 3;
|
|
1242
|
+
public const int SW_RESTORE = 9;
|
|
1243
|
+
public const int SW_SHOWNOACTIVATE = 4;
|
|
1244
|
+
public const int SW_SHOWMINNOACTIVE = 7;
|
|
1245
|
+
|
|
1246
|
+
// SetWindowPos flags
|
|
1247
|
+
public const uint SWP_NOSIZE = 0x0001;
|
|
1248
|
+
public const uint SWP_NOMOVE = 0x0002;
|
|
1249
|
+
public const uint SWP_NOZORDER = 0x0004;
|
|
1250
|
+
public const uint SWP_NOACTIVATE = 0x0010;
|
|
1251
|
+
public const uint SWP_SHOWWINDOW = 0x0040;
|
|
1252
|
+
|
|
1253
|
+
// WM_CLOSE
|
|
1254
|
+
public const uint WM_CLOSE = 0x0010;
|
|
1255
|
+
// WM_SYSCOMMAND
|
|
1256
|
+
public const uint WM_SYSCOMMAND = 0x0112;
|
|
1257
|
+
public const int SC_MINIMIZE = 0xF020;
|
|
1258
|
+
public const int SC_MAXIMIZE = 0xF030;
|
|
1259
|
+
public const int SC_RESTORE = 0xF120;
|
|
1260
|
+
public const int SC_CLOSE = 0xF060;
|
|
1261
|
+
}
|
|
1262
|
+
'@
|
|
1263
|
+
`,Nr={manageWindow(e,t){if(!K)return!1;let n=K;switch(e){case`minimize`:return x(`${q}; [CuWinMgmt]::ShowWindow([IntPtr]::new([long]${n}), [CuWinMgmt]::SW_SHOWMINNOACTIVE)`)!==``;case`maximize`:return x(`${q}; [CuWinMgmt]::ShowWindow([IntPtr]::new([long]${n}), [CuWinMgmt]::SW_MAXIMIZE)`)!==``;case`restore`:return x(`${q}; [CuWinMgmt]::ShowWindow([IntPtr]::new([long]${n}), [CuWinMgmt]::SW_RESTORE)`)!==``;case`close`:return mn(n),x(`${q}; [CuWinMgmt]::SendMessage([IntPtr]::new([long]${n}), [CuWinMgmt]::WM_CLOSE, [IntPtr]::Zero, [IntPtr]::Zero)`),Sr(),!0;case`focus`:return x(`${q}
|
|
1264
|
+
$h = [IntPtr]::new([long]${n})
|
|
1265
|
+
if ([CuWinMgmt]::IsIconic($h)) {
|
|
1266
|
+
[CuWinMgmt]::ShowWindow($h, [CuWinMgmt]::SW_RESTORE) | Out-Null
|
|
1267
|
+
}
|
|
1268
|
+
[CuWinMgmt]::SetForegroundWindow($h) | Out-Null
|
|
1269
|
+
[CuWinMgmt]::BringWindowToTop($h) | Out-Null
|
|
1270
|
+
`),!0;case`move_offscreen`:return x(`${q}; [CuWinMgmt]::SetWindowPos([IntPtr]::new([long]${n}), [IntPtr]::Zero, -32000, -32000, 0, 0, [CuWinMgmt]::SWP_NOSIZE -bor [CuWinMgmt]::SWP_NOZORDER -bor [CuWinMgmt]::SWP_NOACTIVATE)`),!0;case`move_resize`:return t?.x!==void 0&&t?.y!==void 0&&this.moveResize(t.x,t.y,t.width,t.height),!0;case`get_rect`:return!0;default:return!1}},moveResize(e,t,n,r){if(!K)return!1;let i=K;return x(n!==void 0&&r!==void 0?`${q}; [CuWinMgmt]::SetWindowPos([IntPtr]::new([long]${i}), [IntPtr]::Zero, ${e}, ${t}, ${n}, ${r}, [CuWinMgmt]::SWP_NOZORDER -bor [CuWinMgmt]::SWP_NOACTIVATE)`:`${q}; [CuWinMgmt]::SetWindowPos([IntPtr]::new([long]${i}), [IntPtr]::Zero, ${e}, ${t}, 0, 0, [CuWinMgmt]::SWP_NOSIZE -bor [CuWinMgmt]::SWP_NOZORDER -bor [CuWinMgmt]::SWP_NOACTIVATE)`),!0},getWindowRect(){if(!K)return null;let e=x(`${q}
|
|
1271
|
+
$rect = New-Object CuWinMgmt+RECT
|
|
1272
|
+
if ([CuWinMgmt]::GetWindowRect([IntPtr]::new([long]${K}), [ref]$rect)) {
|
|
1273
|
+
"$($rect.Left),$($rect.Top),$($rect.Right),$($rect.Bottom)"
|
|
1274
|
+
} else { "FAIL" }
|
|
1275
|
+
`);if(!e||e===`FAIL`)return null;let[t,n,r,i]=e.split(`,`).map(Number);return{x:t,y:n,width:r-t,height:i-n}}},process.on(`exit`,wr),process.on(`SIGINT`,()=>{wr(),process.exit()}),process.on(`SIGTERM`,()=>{wr(),process.exit()}),Pr={input:kr,screenshot:Ar,display:jr,apps:Mr,windowManagement:Nr}})),Fr=n({platform:()=>Jr});function Y(e){let t=Bun.spawnSync({cmd:e,stdout:`pipe`,stderr:`pipe`});return new TextDecoder().decode(t.stdout).trim()}async function X(e){let t=Bun.spawn(e,{stdout:`pipe`,stderr:`pipe`}),n=await new Response(t.stdout).text();return await t.exited,n.trim()}function Ir(e){return Bun.spawnSync({cmd:[`which`,e],stdout:`pipe`,stderr:`pipe`}).exitCode===0}function Lr(e){return Br[e.toLowerCase()]??e}function Rr(e){return e===`left`?`1`:e===`right`?`3`:`2`}async function zr(e,t,n){if(Ir(`convert`)){await X([`convert`,e,`-quality`,`75`,Wr]);let r=await Bun.file(Wr).arrayBuffer();return{base64:Buffer.from(r).toString(`base64`),width:t,height:n}}if(Ir(`ffmpeg`)){await X([`ffmpeg`,`-y`,`-i`,e,`-q:v`,`5`,Wr]);let r=await Bun.file(Wr).arrayBuffer();return{base64:Buffer.from(r).toString(`base64`),width:t,height:n}}let r=await Bun.file(e).arrayBuffer();return{base64:Buffer.from(r).toString(`base64`),width:t,height:n}}var Br,Vr,Hr,Ur,Wr,Gr,Kr,qr,Jr,Yr=t((()=>{Br={return:`Return`,enter:`Return`,tab:`Tab`,space:`space`,backspace:`BackSpace`,delete:`Delete`,escape:`Escape`,esc:`Escape`,left:`Left`,up:`Up`,right:`Right`,down:`Down`,home:`Home`,end:`End`,pageup:`Prior`,pagedown:`Next`,f1:`F1`,f2:`F2`,f3:`F3`,f4:`F4`,f5:`F5`,f6:`F6`,f7:`F7`,f8:`F8`,f9:`F9`,f10:`F10`,f11:`F11`,f12:`F12`,shift:`shift`,lshift:`shift`,rshift:`shift`,control:`ctrl`,ctrl:`ctrl`,lcontrol:`ctrl`,rcontrol:`ctrl`,alt:`alt`,option:`alt`,lalt:`alt`,ralt:`alt`,win:`super`,meta:`super`,command:`super`,cmd:`super`,super:`super`,insert:`Insert`,printscreen:`Print`,pause:`Pause`,numlock:`Num_Lock`,capslock:`Caps_Lock`,scrolllock:`Scroll_Lock`},Vr=new Set([`shift`,`lshift`,`rshift`,`control`,`ctrl`,`lcontrol`,`rcontrol`,`alt`,`option`,`lalt`,`ralt`,`win`,`meta`,`command`,`cmd`,`super`]),Hr={async moveMouse(e,t){Y([`xdotool`,`mousemove`,`--sync`,String(Math.round(e)),String(Math.round(t))])},async click(e,t,n){Y([`xdotool`,`mousemove`,`--sync`,String(Math.round(e)),String(Math.round(t))]),Y([`xdotool`,`click`,Rr(n)])},async typeText(e){Y([`xdotool`,`type`,`--delay`,`12`,e])},async key(e,t){let n=Lr(e);Y(t===`press`?[`xdotool`,`keydown`,n]:[`xdotool`,`keyup`,n])},async keys(e){let t=[],n=null;for(let r of e)Vr.has(r.toLowerCase())?t.push(Lr(r)):n=r;n&&Y([`xdotool`,`key`,[...t,Lr(n)].join(`+`)])},async scroll(e,t){if(t===`vertical`){let t=e>=0?`5`:`4`,n=Math.abs(Math.round(e));n>0&&Y([`xdotool`,`click`,`--repeat`,String(n),t])}else{let t=e>=0?`7`:`6`,n=Math.abs(Math.round(e));n>0&&Y([`xdotool`,`click`,`--repeat`,String(n),t])}},async mouseLocation(){let e=Y([`xdotool`,`getmouselocation`]),t=e.match(/x:(\d+)/),n=e.match(/y:(\d+)/);return{x:t?Number(t[1]):0,y:n?Number(n[1]):0}}},Ur=`/tmp/cu-screenshot-tmp.png`,Wr=`/tmp/cu-screenshot.jpg`,Gr={async captureScreen(e){try{await X([`scrot`,`-o`,Ur]);let t=Kr.getSize(e);return zr(Ur,t.width,t.height)}catch{return{base64:``,width:0,height:0}}},async captureRegion(e,t,n,r){try{return await X([`scrot`,`-a`,`${e},${t},${n},${r}`,`-o`,Ur]),zr(Ur,n,r)}catch{return{base64:``,width:n,height:r}}},async captureWindow(e){try{if(Ir(`import`)){let t=`/tmp/cu-window-capture.jpg`;await X([`import`,`-window`,e,`-quality`,`75`,t]);let n=Y([`xdotool`,`getwindowgeometry`,`--shell`,e]),r=n.match(/WIDTH=(\d+)/),i=n.match(/HEIGHT=(\d+)/),a=r?Number(r[1]):0,o=i?Number(i[1]):0,s=await Bun.file(t).arrayBuffer();return{base64:Buffer.from(s).toString(`base64`),width:a,height:o}}return null}catch{return null}}},Kr={listAll(){try{let e=Y([`xrandr`,`--query`]),t=[],n=0,r=/^\S+\s+connected\s+(?:primary\s+)?(\d+)x(\d+)\+\d+\+\d+/gm,i;for(;(i=r.exec(e))!==null;)t.push({width:Number(i[1]),height:Number(i[2]),scaleFactor:1,displayId:n++});return t.length===0?[{width:1920,height:1080,scaleFactor:1,displayId:0}]:t}catch{return[{width:1920,height:1080,scaleFactor:1,displayId:0}]}},getSize(e){let t=this.listAll();if(e!==void 0){let n=t.find(t=>t.displayId===e);if(n)return n}return t[0]??{width:1920,height:1080,scaleFactor:1,displayId:0}}},qr={listRunning(){try{if(Ir(`wmctrl`)){let e=Y([`wmctrl`,`-l`,`-p`]),t=[];for(let n of e.split(`
|
|
1276
|
+
`).filter(Boolean)){let e=n.split(/\s+/),r=e[0],i=Number(e[2]);if(!i)continue;let a=e.slice(4).join(` `),o=``;try{o=Y([`readlink`,`-f`,`/proc/${i}/exe`])}catch{}t.push({id:r??``,pid:i,title:a,exePath:o||void 0})}let n=new Set;return t.filter(e=>n.has(e.id)?!1:(n.add(e.id),!0)).slice(0,50)}let e=Y([`xdotool`,`search`,`--name`,``]),t=[];for(let n of e.split(`
|
|
1277
|
+
`).filter(Boolean).slice(0,50)){let e=Y([`xdotool`,`getwindowname`,n]),r=0;try{r=Number(Y([`xdotool`,`getwindowpid`,n]))}catch{}e&&t.push({id:n,pid:r,title:e})}return t}catch{return[]}},async listInstalled(){try{let e=[`/usr/share/applications`,`/usr/local/share/applications`,`${process.env.HOME}/.local/share/applications`],t=[];for(let n of e){let e;try{e=Y([`find`,n,`-name`,`*.desktop`,`-maxdepth`,`1`])}catch{continue}for(let n of e.split(`
|
|
1278
|
+
`).filter(Boolean))try{let e=Y([`cat`,n]),r=e.match(/^Name=(.+)$/m),i=e.match(/^Exec=(.+)$/m);if(e.match(/^NoDisplay=true$/m))continue;let a=r?.[1]??``,o=i?.[1]??``;if(!a)continue;t.push({id:n.split(`/`).pop()?.replace(`.desktop`,``)??``,displayName:a,path:o.split(/\s+/)[0]??``})}catch{}}return t.slice(0,200)}catch{return[]}},async open(e){try{let t=e.endsWith(`.desktop`)?e:`${e}.desktop`;if(Ir(`gtk-launch`)){await X([`gtk-launch`,t]);return}}catch{}await X([`xdg-open`,e])},getFrontmostApp(){try{let e=Y([`xdotool`,`getactivewindow`]);if(!e)return null;let t=Y([`xdotool`,`getwindowpid`,e]);if(!t)return null;let n=``;try{n=Y([`readlink`,`-f`,`/proc/${t}/exe`])}catch{}let r=``;try{r=Y([`cat`,`/proc/${t}/comm`])}catch{}return!n&&!r?null:{id:n||`/proc/${t}/exe`,appName:r||`unknown`}}catch{return null}},findWindowByTitle(e){try{let t=Y([`xdotool`,`search`,`--name`,e]).split(`
|
|
1279
|
+
`)[0];if(!t)return null;let n=Y([`xdotool`,`getwindowname`,t]),r=0;try{r=Number(Y([`xdotool`,`getwindowpid`,t]))}catch{}return{id:t,pid:r,title:n}}catch{return null}}},Jr={input:Hr,screenshot:Gr,display:Kr,apps:qr}}));function Xr(){if(Zr)return Zr;switch(process.platform){case`darwin`:Zr=(Mt(),e(Et)).platform;break;case`win32`:Zr=(J(),e(U)).platform;break;case`linux`:Zr=(Yr(),e(Fr)).platform;break;default:throw Error(`Computer Use not supported on ${process.platform}`)}return Zr}var Zr,Qr=t((()=>{})),$r=n({captureAccessibilitySnapshot:()=>ei,findNodeInSnapshot:()=>ii});function ei(e,t=4,n=!0){e=b(e);let r=`
|
|
1280
|
+
Add-Type -AssemblyName UIAutomationClient
|
|
1281
|
+
Add-Type -AssemblyName UIAutomationTypes
|
|
1282
|
+
Add-Type -AssemblyName WindowsBase
|
|
1283
|
+
${n?`
|
|
1284
|
+
# Interactive control types only
|
|
1285
|
+
$interactiveTypes = @(
|
|
1286
|
+
'Button','Edit','ComboBox','CheckBox','RadioButton',
|
|
1287
|
+
'MenuItem','Menu','MenuBar','Link','Slider','Spinner',
|
|
1288
|
+
'Tab','TabItem','List','ListItem','Tree','TreeItem',
|
|
1289
|
+
'DataGrid','DataItem','Document','ScrollBar','ToolBar',
|
|
1290
|
+
'SplitButton','ToggleButton','Hyperlink'
|
|
1291
|
+
)
|
|
1292
|
+
function Is-Interactive($ct) {
|
|
1293
|
+
$typeName = $ct -replace 'ControlType\\.', ''
|
|
1294
|
+
return $interactiveTypes -contains $typeName
|
|
1295
|
+
}`:`
|
|
1296
|
+
function Is-Interactive($ct) { return $true }`}
|
|
1297
|
+
|
|
1298
|
+
function Get-Tree($el, $depth, $maxDepth) {
|
|
1299
|
+
if ($depth -ge $maxDepth) { return @() }
|
|
1300
|
+
$result = @()
|
|
1301
|
+
$children = $el.FindAll(
|
|
1302
|
+
[System.Windows.Automation.TreeScope]::Children,
|
|
1303
|
+
[System.Windows.Automation.Condition]::TrueCondition)
|
|
1304
|
+
foreach ($child in $children) {
|
|
1305
|
+
$ct = $child.Current.ControlType.ProgrammaticName
|
|
1306
|
+
$typeName = $ct -replace 'ControlType\\.', ''
|
|
1307
|
+
$name = [string]$child.Current.Name
|
|
1308
|
+
$autoId = [string]$child.Current.AutomationId
|
|
1309
|
+
$rect = $child.Current.BoundingRectangle
|
|
1310
|
+
$enabled = $child.Current.IsEnabled
|
|
1311
|
+
|
|
1312
|
+
# Skip invisible/offscreen elements
|
|
1313
|
+
if ($rect.Width -le 0 -or $rect.Height -le 0) { continue }
|
|
1314
|
+
if ($rect.X -lt -10000) { continue }
|
|
1315
|
+
|
|
1316
|
+
$val = $null
|
|
1317
|
+
try {
|
|
1318
|
+
$vp = $child.GetCurrentPattern([System.Windows.Automation.ValuePattern]::Pattern)
|
|
1319
|
+
if ($vp -ne $null) { $val = $vp.Current.Value }
|
|
1320
|
+
} catch {}
|
|
1321
|
+
|
|
1322
|
+
$isInteractive = Is-Interactive $ct
|
|
1323
|
+
$sub = Get-Tree $child ($depth + 1) $maxDepth
|
|
1324
|
+
|
|
1325
|
+
if ($isInteractive -or $sub.Count -gt 0) {
|
|
1326
|
+
$node = @{
|
|
1327
|
+
role = $typeName
|
|
1328
|
+
name = $name
|
|
1329
|
+
id = $autoId
|
|
1330
|
+
x = [int]$rect.X; y = [int]$rect.Y
|
|
1331
|
+
w = [int]$rect.Width; h = [int]$rect.Height
|
|
1332
|
+
on = $enabled
|
|
1333
|
+
}
|
|
1334
|
+
if ($val -ne $null -and $val -ne '') { $node['v'] = $val }
|
|
1335
|
+
if ($sub.Count -gt 0) { $node['c'] = $sub }
|
|
1336
|
+
$result += $node
|
|
1337
|
+
}
|
|
1338
|
+
}
|
|
1339
|
+
return $result
|
|
1340
|
+
}
|
|
1341
|
+
|
|
1342
|
+
try {
|
|
1343
|
+
$root = [System.Windows.Automation.AutomationElement]::FromHandle([IntPtr]::new([long]${e}))
|
|
1344
|
+
if ($root -eq $null) { Write-Output '[]'; exit }
|
|
1345
|
+
$tree = Get-Tree $root 0 ${t}
|
|
1346
|
+
if ($tree -eq $null -or $tree.Count -eq 0) {
|
|
1347
|
+
Write-Output '[]'
|
|
1348
|
+
} else {
|
|
1349
|
+
$tree | ConvertTo-Json -Depth 20 -Compress
|
|
1350
|
+
}
|
|
1351
|
+
} catch {
|
|
1352
|
+
Write-Output '[]'
|
|
1353
|
+
}
|
|
1354
|
+
`;try{let e=x(r);if(!e||e===`[]`)return null;let t=JSON.parse(e),n=Array.isArray(t)?t.map(ti):[ti(t)];return{text:ni(n),nodes:n,timestamp:Date.now()}}catch{return null}}function ti(e){return{role:e.role||``,name:e.name||``,automationId:e.id||``,bounds:{x:e.x||0,y:e.y||0,w:e.w||0,h:e.h||0},enabled:e.on!==!1,value:e.v,children:e.c?Array.isArray(e.c)?e.c.map(ti):[ti(e.c)]:void 0}}function ni(e,t=0){let n=[],r=` `.repeat(t);for(let i of e){let e=`${r}[${i.role}]`;i.name&&(e+=` "${ri(i.name,40)}"`),e+=` (${i.bounds.x},${i.bounds.y} ${i.bounds.w}x${i.bounds.h})`,i.enabled||(e+=` DISABLED`),i.value&&(e+=` value="${ri(i.value,30)}"`),i.automationId&&(e+=` id=${i.automationId}`),n.push(e),i.children&&n.push(ni(i.children,t+1))}return n.join(`
|
|
1355
|
+
`)}function ri(e,t){return e.length>t?e.slice(0,t-1)+`…`:e}function ii(e,t){for(let n of e){let e=!0;if(t.name&&!n.name.toLowerCase().includes(t.name.toLowerCase())&&(e=!1),t.role&&n.role.toLowerCase()!==t.role.toLowerCase()&&(e=!1),t.automationId&&n.automationId!==t.automationId&&(e=!1),e&&(t.name||t.role||t.automationId))return n;if(n.children){let e=ii(n.children,t);if(e)return e}}return null}var ai=t((()=>{C()})),oi=n({clickElement:()=>ui,elementAtPoint:()=>fi,findElement:()=>li,getUITree:()=>ci,setValue:()=>di});function si(e,t){try{return e?JSON.parse(e):t}catch{return t}}function ci(e,t=3){let n=si(x(`
|
|
1356
|
+
${mi}
|
|
1357
|
+
$title = '${e.replace(/'/g,`''`)}'
|
|
1358
|
+
${hi}
|
|
1359
|
+
if ($window -eq $null) {
|
|
1360
|
+
Write-Output '[]'
|
|
1361
|
+
exit
|
|
1362
|
+
}
|
|
1363
|
+
|
|
1364
|
+
function Get-UIChildren($parent, $currentDepth, $maxDepth) {
|
|
1365
|
+
if ($currentDepth -ge $maxDepth) { return @() }
|
|
1366
|
+
$children = $parent.FindAll(
|
|
1367
|
+
[System.Windows.Automation.TreeScope]::Children,
|
|
1368
|
+
[System.Windows.Automation.Condition]::TrueCondition)
|
|
1369
|
+
$result = @()
|
|
1370
|
+
foreach ($el in $children) {
|
|
1371
|
+
$rect = $el.Current.BoundingRectangle
|
|
1372
|
+
$obj = @{
|
|
1373
|
+
name = [string]$el.Current.Name
|
|
1374
|
+
controlType = $el.Current.ControlType.ProgrammaticName -replace 'ControlType\\.', ''
|
|
1375
|
+
automationId = [string]$el.Current.AutomationId
|
|
1376
|
+
boundingRect = @{
|
|
1377
|
+
x = [int]$rect.X
|
|
1378
|
+
y = [int]$rect.Y
|
|
1379
|
+
w = [int]$rect.Width
|
|
1380
|
+
h = [int]$rect.Height
|
|
1381
|
+
}
|
|
1382
|
+
isEnabled = $el.Current.IsEnabled
|
|
1383
|
+
}
|
|
1384
|
+
try {
|
|
1385
|
+
$vp = $el.GetCurrentPattern([System.Windows.Automation.ValuePattern]::Pattern)
|
|
1386
|
+
if ($vp -ne $null) { $obj['value'] = $vp.Current.Value }
|
|
1387
|
+
} catch {}
|
|
1388
|
+
$sub = Get-UIChildren $el ($currentDepth + 1) $maxDepth
|
|
1389
|
+
if ($sub.Count -gt 0) { $obj['children'] = $sub }
|
|
1390
|
+
$result += $obj
|
|
1391
|
+
}
|
|
1392
|
+
return $result
|
|
1393
|
+
}
|
|
1394
|
+
|
|
1395
|
+
$tree = Get-UIChildren $window 0 ${t}
|
|
1396
|
+
if ($tree -eq $null -or $tree.Count -eq 0) {
|
|
1397
|
+
Write-Output '[]'
|
|
1398
|
+
} else {
|
|
1399
|
+
$tree | ConvertTo-Json -Depth 20 -Compress
|
|
1400
|
+
}
|
|
1401
|
+
`),[]);return Array.isArray(n)?n:[n]}function li(e,t){let n=e.replace(/'/g,`''`),r=[];if(t.name){let e=t.name.replace(/'/g,`''`);r.push(`[System.Windows.Automation.PropertyCondition]::new([System.Windows.Automation.AutomationElement]::NameProperty, '${e}')`)}if(t.controlType){if(!pi.has(t.controlType))return null;let e=t.controlType.replace(/'/g,`''`);r.push(`[System.Windows.Automation.PropertyCondition]::new([System.Windows.Automation.AutomationElement]::ControlTypeProperty, [System.Windows.Automation.ControlType]::${e})`)}if(t.automationId){let e=t.automationId.replace(/'/g,`''`);r.push(`[System.Windows.Automation.PropertyCondition]::new([System.Windows.Automation.AutomationElement]::AutomationIdProperty, '${e}')`)}if(r.length===0)return null;let i;return i=r.length===1?r[0]:`[System.Windows.Automation.AndCondition]::new(@(${r.join(`, `)}))`,si(x(`
|
|
1402
|
+
${mi}
|
|
1403
|
+
$title = '${n}'
|
|
1404
|
+
${hi}
|
|
1405
|
+
if ($window -eq $null) {
|
|
1406
|
+
Write-Output 'null'
|
|
1407
|
+
exit
|
|
1408
|
+
}
|
|
1409
|
+
$cond = ${i}
|
|
1410
|
+
$el = $window.FindFirst([System.Windows.Automation.TreeScope]::Descendants, $cond)
|
|
1411
|
+
if ($el -eq $null) {
|
|
1412
|
+
Write-Output 'null'
|
|
1413
|
+
exit
|
|
1414
|
+
}
|
|
1415
|
+
$rect = $el.Current.BoundingRectangle
|
|
1416
|
+
$obj = @{
|
|
1417
|
+
name = [string]$el.Current.Name
|
|
1418
|
+
controlType = $el.Current.ControlType.ProgrammaticName -replace 'ControlType\\.', ''
|
|
1419
|
+
automationId = [string]$el.Current.AutomationId
|
|
1420
|
+
boundingRect = @{
|
|
1421
|
+
x = [int]$rect.X
|
|
1422
|
+
y = [int]$rect.Y
|
|
1423
|
+
w = [int]$rect.Width
|
|
1424
|
+
h = [int]$rect.Height
|
|
1425
|
+
}
|
|
1426
|
+
isEnabled = $el.Current.IsEnabled
|
|
1427
|
+
}
|
|
1428
|
+
try {
|
|
1429
|
+
$vp = $el.GetCurrentPattern([System.Windows.Automation.ValuePattern]::Pattern)
|
|
1430
|
+
if ($vp -ne $null) { $obj['value'] = $vp.Current.Value }
|
|
1431
|
+
} catch {}
|
|
1432
|
+
$obj | ConvertTo-Json -Compress
|
|
1433
|
+
`),null)}function ui(e,t){return x(`
|
|
1434
|
+
${mi}
|
|
1435
|
+
$title = '${e.replace(/'/g,`''`)}'
|
|
1436
|
+
${hi}
|
|
1437
|
+
if ($window -eq $null) {
|
|
1438
|
+
Write-Output 'false'
|
|
1439
|
+
exit
|
|
1440
|
+
}
|
|
1441
|
+
$cond = [System.Windows.Automation.PropertyCondition]::new(
|
|
1442
|
+
[System.Windows.Automation.AutomationElement]::AutomationIdProperty, '${t.replace(/'/g,`''`)}')
|
|
1443
|
+
$el = $window.FindFirst([System.Windows.Automation.TreeScope]::Descendants, $cond)
|
|
1444
|
+
if ($el -eq $null) {
|
|
1445
|
+
Write-Output 'false'
|
|
1446
|
+
exit
|
|
1447
|
+
}
|
|
1448
|
+
try {
|
|
1449
|
+
$ip = $el.GetCurrentPattern([System.Windows.Automation.InvokePattern]::Pattern)
|
|
1450
|
+
$ip.Invoke()
|
|
1451
|
+
Write-Output 'true'
|
|
1452
|
+
} catch {
|
|
1453
|
+
Write-Output 'false'
|
|
1454
|
+
}
|
|
1455
|
+
`)===`true`}function di(e,t,n){return x(`
|
|
1456
|
+
${mi}
|
|
1457
|
+
$title = '${e.replace(/'/g,`''`)}'
|
|
1458
|
+
${hi}
|
|
1459
|
+
if ($window -eq $null) {
|
|
1460
|
+
Write-Output 'false'
|
|
1461
|
+
exit
|
|
1462
|
+
}
|
|
1463
|
+
$cond = [System.Windows.Automation.PropertyCondition]::new(
|
|
1464
|
+
[System.Windows.Automation.AutomationElement]::AutomationIdProperty, '${t.replace(/'/g,`''`)}')
|
|
1465
|
+
$el = $window.FindFirst([System.Windows.Automation.TreeScope]::Descendants, $cond)
|
|
1466
|
+
if ($el -eq $null) {
|
|
1467
|
+
Write-Output 'false'
|
|
1468
|
+
exit
|
|
1469
|
+
}
|
|
1470
|
+
try {
|
|
1471
|
+
$vp = $el.GetCurrentPattern([System.Windows.Automation.ValuePattern]::Pattern)
|
|
1472
|
+
$vp.SetValue('${n.replace(/'/g,`''`)}')
|
|
1473
|
+
Write-Output 'true'
|
|
1474
|
+
} catch {
|
|
1475
|
+
Write-Output 'false'
|
|
1476
|
+
}
|
|
1477
|
+
`)===`true`}function fi(e,t){return si(x(`
|
|
1478
|
+
${mi}
|
|
1479
|
+
try {
|
|
1480
|
+
$point = [System.Windows.Point]::new(${e}, ${t})
|
|
1481
|
+
$el = [System.Windows.Automation.AutomationElement]::FromPoint($point)
|
|
1482
|
+
if ($el -eq $null) {
|
|
1483
|
+
Write-Output 'null'
|
|
1484
|
+
exit
|
|
1485
|
+
}
|
|
1486
|
+
$rect = $el.Current.BoundingRectangle
|
|
1487
|
+
$obj = @{
|
|
1488
|
+
name = [string]$el.Current.Name
|
|
1489
|
+
controlType = $el.Current.ControlType.ProgrammaticName -replace 'ControlType\\.', ''
|
|
1490
|
+
automationId = [string]$el.Current.AutomationId
|
|
1491
|
+
boundingRect = @{
|
|
1492
|
+
x = [int]$rect.X
|
|
1493
|
+
y = [int]$rect.Y
|
|
1494
|
+
w = [int]$rect.Width
|
|
1495
|
+
h = [int]$rect.Height
|
|
1496
|
+
}
|
|
1497
|
+
isEnabled = $el.Current.IsEnabled
|
|
1498
|
+
}
|
|
1499
|
+
try {
|
|
1500
|
+
$vp = $el.GetCurrentPattern([System.Windows.Automation.ValuePattern]::Pattern)
|
|
1501
|
+
if ($vp -ne $null) { $obj['value'] = $vp.Current.Value }
|
|
1502
|
+
} catch {}
|
|
1503
|
+
$obj | ConvertTo-Json -Compress
|
|
1504
|
+
} catch {
|
|
1505
|
+
Write-Output 'null'
|
|
1506
|
+
}
|
|
1507
|
+
`),null)}var pi,mi,hi,gi=t((()=>{C(),pi=new Set(`Button.Calendar.CheckBox.ComboBox.Custom.DataGrid.DataItem.Document.Edit.Group.Header.HeaderItem.Hyperlink.Image.List.ListItem.Menu.MenuBar.MenuItem.Pane.ProgressBar.RadioButton.ScrollBar.Separator.Slider.Spinner.SplitButton.StatusBar.Tab.TabItem.Table.Text.Thumb.TitleBar.ToolBar.ToolTip.Tree.TreeItem.Window`.split(`.`)),mi=`
|
|
1508
|
+
Add-Type -AssemblyName UIAutomationClient
|
|
1509
|
+
Add-Type -AssemblyName UIAutomationTypes
|
|
1510
|
+
Add-Type -AssemblyName WindowsBase
|
|
1511
|
+
`,hi=`
|
|
1512
|
+
$root = [System.Windows.Automation.AutomationElement]::RootElement
|
|
1513
|
+
$window = $root.FindFirst(
|
|
1514
|
+
[System.Windows.Automation.TreeScope]::Children,
|
|
1515
|
+
[System.Windows.Automation.PropertyCondition]::new(
|
|
1516
|
+
[System.Windows.Automation.AutomationElement]::NameProperty, $title))
|
|
1517
|
+
if ($window -eq $null) {
|
|
1518
|
+
$all = $root.FindAll(
|
|
1519
|
+
[System.Windows.Automation.TreeScope]::Children,
|
|
1520
|
+
[System.Windows.Automation.Condition]::TrueCondition)
|
|
1521
|
+
foreach ($el in $all) {
|
|
1522
|
+
if ($el.Current.Name -and $el.Current.Name.Contains($title)) {
|
|
1523
|
+
$window = $el
|
|
1524
|
+
break
|
|
1525
|
+
}
|
|
1526
|
+
}
|
|
1527
|
+
}
|
|
1528
|
+
`})),_i=n({createCrossPlatformExecutor:()=>Ci,unhideComputerUseAppsCrossPlatform:()=>wi});function vi(){if(process.platform!==`win32`)return null;try{let{getBoundHwnd:t}=(J(),e(U));return t()}catch{return null}}function Z(){return vi()!==null}function yi(){if(process.platform!==`win32`)return{dx:0,dy:0};try{let{getBoundHwnd:t}=(J(),e(U)),n=t();if(!n)return{dx:0,dy:0};b(n);let r=Bun.spawnSync({cmd:[`powershell`,`-NoProfile`,`-NonInteractive`,`-Command`,`
|
|
1529
|
+
Add-Type @'
|
|
1530
|
+
using System;
|
|
1531
|
+
using System.Runtime.InteropServices;
|
|
1532
|
+
public class NcCalc {
|
|
1533
|
+
[DllImport("user32.dll")] public static extern bool GetWindowRect(IntPtr h, out RECT r);
|
|
1534
|
+
[DllImport("user32.dll")] public static extern bool GetClientRect(IntPtr h, out RECT r);
|
|
1535
|
+
[DllImport("user32.dll")] public static extern bool ClientToScreen(IntPtr h, ref POINT p);
|
|
1536
|
+
[StructLayout(LayoutKind.Sequential)] public struct RECT { public int L, T, R, B; }
|
|
1537
|
+
[StructLayout(LayoutKind.Sequential)] public struct POINT { public int X, Y; }
|
|
1538
|
+
}
|
|
1539
|
+
'@
|
|
1540
|
+
$h = [IntPtr]::new([long]${n})
|
|
1541
|
+
$wr = New-Object NcCalc+RECT
|
|
1542
|
+
$cr = New-Object NcCalc+RECT
|
|
1543
|
+
[NcCalc]::GetWindowRect($h, [ref]$wr) | Out-Null
|
|
1544
|
+
[NcCalc]::GetClientRect($h, [ref]$cr) | Out-Null
|
|
1545
|
+
$pt = New-Object NcCalc+POINT
|
|
1546
|
+
$pt.X = 0; $pt.Y = 0
|
|
1547
|
+
[NcCalc]::ClientToScreen($h, [ref]$pt) | Out-Null
|
|
1548
|
+
"$($pt.X - $wr.L),$($pt.Y - $wr.T)"
|
|
1549
|
+
`],stdout:`pipe`,stderr:`pipe`}),[i,a]=new TextDecoder().decode(r.stdout).trim().split(`,`);return{dx:Number(i)||0,dy:Number(a)||0}}catch{return{dx:0,dy:0}}}function bi(){if(process.platform!==`win32`)return{dx:0,dy:0};try{let{getBoundHwnd:t}=(J(),e(U)),n=t();return n?Q&&$===n?Q:(Q=yi(),$=n,Q):{dx:0,dy:0}}catch{return{dx:0,dy:0}}}function xi(){if(!(process.platform!==`win32`||!Z()))try{let{getBoundHwnd:t}=(J(),e(U)),n=t();if(!n)return;let{captureAccessibilitySnapshot:r}=(ai(),e($r)),i=r(n);return!i||!i.text?void 0:i.text}catch{return}}function Si(e,t){if(Z()){let t=xi();return{base64:e.base64,width:e.width,height:e.height,displayWidth:e.width,displayHeight:e.height,originX:0,originY:0,accessibilityText:t}}return{base64:e.base64,width:e.width,height:e.height,displayWidth:t.width,displayHeight:t.height,originX:0,originY:0}}function Ci(t){let n=Xr();return a(`[computer-use] cross-platform executor for ${process.platform}`),{capabilities:{...re,hostBundleId:te},async prepareForAction(){return[]},async previewHideSet(){return[]},async getDisplaySize(e){let t=n.display.getSize(e);return{...t,scaleFactor:t.scaleFactor??1,displayId:t.displayId??0,originX:0,originY:0}},async listDisplays(){return n.display.listAll().map(e=>({...e,originX:0,originY:0}))},async findWindowDisplays(e){return e.map(e=>({bundleId:e,displayIds:[0]}))},async resolvePrepareCapture(e){let t=n.display.getSize(e.preferredDisplayId);return{...Si(await n.screenshot.captureScreen(e.preferredDisplayId),t),hidden:[],displayId:e.preferredDisplayId??t.displayId??0}},async screenshot(e){let t=n.display.getSize(e.displayId);return Si(await n.screenshot.captureScreen(e.displayId),t)},async zoom(e,t,r){return n.screenshot.captureRegion(e.x,e.y,e.w,e.h)},async key(e,t){let r=e.split(`+`).filter(e=>e.length>0),i=t??1;for(let e=0;e<i;e++)e>0&&await l(8),await n.input.keys(r)},async holdKey(e,t){for(let t of e)await n.input.key(t,`press`);await l(t);for(let t of[...e].reverse())await n.input.key(t,`release`)},async type(e,t){await n.input.typeText(e)},async readClipboard(){if(process.platform===`win32`){let e=Bun.spawnSync({cmd:[`powershell`,`-NoProfile`,`-Command`,`Get-Clipboard`],stdout:`pipe`});return new TextDecoder().decode(e.stdout).trim()}let e=Bun.spawnSync({cmd:[`xclip`,`-selection`,`clipboard`,`-o`],stdout:`pipe`});return new TextDecoder().decode(e.stdout).trim()},async writeClipboard(e){if(process.platform===`win32`){let t=e.replace(/'/g,`''`);Bun.spawnSync({cmd:[`powershell`,`-NoProfile`,`-Command`,`Set-Clipboard -Value '${t}'`]});return}let t=Bun.spawn([`xclip`,`-selection`,`clipboard`],{stdin:`pipe`});t.stdin.write(e),t.stdin.end(),await t.exited},async moveMouse(e,t){await n.input.moveMouse(e,t)},async click(e,t,r,i,o){let s=Math.round(e),c=Math.round(t);if(Z()){let n=bi();s-=n.dx,c-=n.dy,a(`[computer-use] click(${Math.round(e)},${Math.round(t)}) → client(${s},${c}) [nc offset: ${n.dx},${n.dy}]`)}for(let e=0;e<i;e++)await n.input.click(s,c,r)},async mouseDown(){if(Z()&&process.platform===`win32`){let{getBoundHwnd:t}=(J(),e(U)),r=t();if(r){let{sendMouseDown:t}=(H(),e(R)),i=await n.input.mouseLocation();t(r,i.x,i.y);return}}if(process.platform===`win32`){Bun.spawnSync({cmd:[`powershell`,`-NoProfile`,`-NonInteractive`,`-Command`,`Add-Type -Language CSharp @'
|
|
1550
|
+
using System; using System.Runtime.InteropServices;
|
|
1551
|
+
public class MDown { [StructLayout(LayoutKind.Sequential)] public struct MOUSEINPUT { public int dx; public int dy; public int mouseData; public uint dwFlags; public uint time; public IntPtr dwExtraInfo; }
|
|
1552
|
+
[StructLayout(LayoutKind.Explicit)] public struct INPUT { [FieldOffset(0)] public uint type; [FieldOffset(4)] public MOUSEINPUT mi; }
|
|
1553
|
+
[DllImport("user32.dll",SetLastError=true)] public static extern uint SendInput(uint n, INPUT[] i, int cb); }
|
|
1554
|
+
'@
|
|
1555
|
+
$i = New-Object MDown+INPUT; $i.type=0; $i.mi.dwFlags=0x0002; [MDown]::SendInput(1, @($i), [Runtime.InteropServices.Marshal]::SizeOf($i)) | Out-Null`]});return}},async mouseUp(){if(Z()&&process.platform===`win32`){let{getBoundHwnd:t}=(J(),e(U)),r=t();if(r){let{sendMouseUp:t}=(H(),e(R)),i=await n.input.mouseLocation();t(r,i.x,i.y);return}}if(process.platform===`win32`){Bun.spawnSync({cmd:[`powershell`,`-NoProfile`,`-NonInteractive`,`-Command`,`Add-Type -Language CSharp @'
|
|
1556
|
+
using System; using System.Runtime.InteropServices;
|
|
1557
|
+
public class MUp { [StructLayout(LayoutKind.Sequential)] public struct MOUSEINPUT { public int dx; public int dy; public int mouseData; public uint dwFlags; public uint time; public IntPtr dwExtraInfo; }
|
|
1558
|
+
[StructLayout(LayoutKind.Explicit)] public struct INPUT { [FieldOffset(0)] public uint type; [FieldOffset(4)] public MOUSEINPUT mi; }
|
|
1559
|
+
[DllImport("user32.dll",SetLastError=true)] public static extern uint SendInput(uint n, INPUT[] i, int cb); }
|
|
1560
|
+
'@
|
|
1561
|
+
$i = New-Object MUp+INPUT; $i.type=0; $i.mi.dwFlags=0x0004; [MUp]::SendInput(1, @($i), [Runtime.InteropServices.Marshal]::SizeOf($i)) | Out-Null`]});return}},async getCursorPosition(){return n.input.mouseLocation()},async drag(t,r){if(Z()&&process.platform===`win32`){let{getBoundHwnd:n}=(J(),e(U)),i=n();if(i){let{sendMouseDown:n,sendMouseMove:a,sendMouseUp:o}=(H(),e(R)),s=bi();t&&n(i,Math.round(t.x)-s.dx,Math.round(t.y)-s.dy),await l(50);let c=Math.round(r.x)-s.dx,u=Math.round(r.y)-s.dy;a(i,c,u),await l(16),o(i,c,u);return}}t&&(await n.input.moveMouse(t.x,t.y),await l(16)),await this.mouseDown(),await l(50),await n.input.moveMouse(r.x,r.y),await l(16),await this.mouseUp()},async scroll(e,t,r,i){i!==0&&await n.input.scroll(i,`vertical`),r!==0&&await n.input.scroll(r,`horizontal`)},async getFrontmostApp(){if(Z())return{bundleId:`cu-bound-window`,displayName:`Bound Window`};let e=n.apps.getFrontmostApp();return e?{bundleId:e.id,displayName:e.appName}:null},async appUnderPoint(e,t){return null},async listInstalledApps(){return(await n.apps.listInstalled()).map(e=>({bundleId:e.id,displayName:e.displayName,path:e.path}))},async getAppIcon(e){},async listRunningApps(){return n.apps.listRunning().map(e=>({bundleId:e.id,displayName:e.title}))},async openApp(e){await n.apps.open(e),Q=null,$=null},async manageWindow(e,t){if(!n.windowManagement)return!1;let r=n.windowManagement.manageWindow(e,t);return Q=null,$=null,r},async getWindowRect(){return n.windowManagement?n.windowManagement.getWindowRect():null},async openTerminal(t){if(process.platform!==`win32`)return null;try{let{listWindows:n}=(ce(),e(se)),{bindWindow:r}=(J(),e(U)),i={claude:`claude`,codex:`codex`,gemini:`gemini`,custom:t.command??``}[t.agent];if(!i)return null;let a=new Set(n().map(e=>e.hwnd)),o=(t.workingDirectory??process.cwd()).replace(/'/g,`''`);Bun.spawnSync({cmd:[`powershell`,`-Command`,`Start-Process powershell -ArgumentList '-NoExit','-Command','cd ''${o}''; ${i}'`],stdout:`ignore`,stderr:`ignore`});let s=null,c=``;for(let e=0;e<25;e++){await l(200);for(let e of n())if(!a.has(e.hwnd)){let t=e.title.toLowerCase();if(t.includes(`terminal`)||t.includes(`powershell`)||t.includes(`cmd`)||t.includes(i.toLowerCase())){s=e.hwnd,c=e.title;break}}if(s)break}if(!s)return null;let u=n().find(e=>e.hwnd===s);return r(s,u?.pid),Q=null,$=null,await l(2e3),{hwnd:s,title:c,launched:!0}}catch{return null}},async bindToWindow(t){if(process.platform!==`win32`)return null;let{bindWindow:n}=(J(),e(U)),{listWindows:r}=(ce(),e(se)),i=r(),a;if(t.hwnd)a=i.find(e=>e.hwnd===t.hwnd);else if(t.title){let e=t.title.toLowerCase();a=i.find(t=>t.title.toLowerCase().includes(e))}else t.pid&&(a=i.find(e=>e.pid===t.pid));return a?(n(a.hwnd,a.pid),Q=null,$=null,a):null},async unbindFromWindow(){if(process.platform!==`win32`)return;let{unbindWindow:t}=(J(),e(U));t(),Q=null,$=null},async hasBoundWindow(){return Z()},async getBindingStatus(){if(process.platform!==`win32`)return null;let{getBoundHwnd:t}=(J(),e(U)),r=t();if(!r)return{bound:!1};let{listWindows:i}=(ce(),e(se)),a=i().find(e=>e.hwnd===r),o=n.windowManagement?.getWindowRect()??void 0;return{bound:!0,hwnd:r,title:a?.title,pid:a?.pid,rect:o??void 0}},async listVisibleWindows(){if(process.platform!==`win32`)return[];let{listWindows:t}=(ce(),e(se));return t()},async statusIndicator(t,n){if(process.platform!==`win32`)return{active:!1};try{let r=(Gn(),e(An));return t===`show`&&n?(r.updateIndicator(n),{active:!0,message:n}):t===`hide`?(r.hideIndicator(),{active:!1}):{active:Z()}}catch{return{active:!1}}},async virtualKeyboard(t){if(process.platform!==`win32`||!Z())return!1;try{let n=vi();if(!n)return!1;let r=(H(),e(R)),{VK_MAP:i}=(C(),e(xt)),a=t.repeat??1;for(let e=0;e<a;e++)switch(e>0&&await l(30),t.action){case`type`:r.sendText(n,t.text);break;case`combo`:{let e=t.text.split(`+`).map(e=>e.trim()).filter(Boolean);r.sendKeys(n,e);break}case`press`:{let e=i[t.text.toLowerCase()]??(t.text.length===1?t.text.charCodeAt(0):0);e&&r.sendKey(n,e,`down`);break}case`release`:{let e=i[t.text.toLowerCase()]??(t.text.length===1?t.text.charCodeAt(0):0);e&&r.sendKey(n,e,`up`);break}case`hold`:{let e=t.text.split(`+`).map(e=>e.trim()).filter(Boolean);for(let t of e){let e=i[t.toLowerCase()]??(t.length===1?t.charCodeAt(0):0);e&&r.sendKey(n,e,`down`)}await l((t.duration??1)*1e3);for(let t of[...e].reverse()){let e=i[t.toLowerCase()]??(t.length===1?t.charCodeAt(0):0);e&&r.sendKey(n,e,`up`)}break}}return!0}catch{return!1}},async virtualMouse(t){if(process.platform!==`win32`||!Z())return!1;try{let n=vi();if(!n)return!1;let r=(H(),e(R)),i=(kn(),e(gn)),a=Math.round(t.x),o=Math.round(t.y);switch(t.action){case`click`:i.moveVirtualCursor(a,o,!0),r.sendClick(n,a,o,`left`);break;case`double_click`:i.moveVirtualCursor(a,o,!0),r.sendClick(n,a,o,`left`),await l(50),r.sendClick(n,a,o,`left`);break;case`right_click`:i.moveVirtualCursor(a,o,!0),r.sendClick(n,a,o,`right`);break;case`move`:i.moveVirtualCursor(a,o),r.sendMouseMove(n,a,o);break;case`drag`:{let e=Math.round(t.startX??a),s=Math.round(t.startY??o);i.moveVirtualCursor(e,s,!0),r.sendMouseDown(n,e,s),await l(16),r.sendMouseMove(n,a,o),i.moveVirtualCursor(a,o),await l(16),r.sendMouseUp(n,a,o);break}case`down`:i.moveVirtualCursor(a,o,!0),r.sendMouseDown(n,a,o);break;case`up`:i.moveVirtualCursor(a,o),r.sendMouseUp(n,a,o);break}return!0}catch{return!1}},async mouseWheel(t,n,r,i){if(process.platform!==`win32`||!Z())return!1;try{let a=vi();if(!a)return!1;try{if(($n(),e(Kn)).callSync(`send_mouse_wheel`,{hwnd:a,x:Math.round(t),y:Math.round(n),delta:r,horizontal:i??!1})!==null)return!0}catch{}let{sendMouseWheel:o}=(H(),e(R));return o(a,Math.round(t),Math.round(n),r,i??!1)}catch{return!1}},async activateWindow(t,r){if(process.platform!==`win32`||!Z())return!1;try{let{getBoundHwnd:i}=(J(),e(U)),a=i();if(!a)return!1;n.windowManagement&&n.windowManagement.manageWindow(`focus`);let{sendClick:o}=(H(),e(R));if(t!==void 0&&r!==void 0)o(a,t,r,`left`);else{let e=n.windowManagement?.getWindowRect();if(e){let t=bi();o(a,Math.round(e.width/2)-t.dx,Math.round(e.height/2)-t.dy,`left`)}}return!0}catch{return!1}},async respondToPrompt(t){if(process.platform!==`win32`||!Z())return!1;try{let{getBoundHwnd:n}=(J(),e(U)),r=n();if(!r)return!1;let i=(H(),e(R));switch(t.responseType){case`yes`:i.sendChar(r,`y`),await l(50),i.sendKey(r,13,`down`),i.sendKey(r,13,`up`);break;case`no`:i.sendChar(r,`n`),await l(50),i.sendKey(r,13,`down`),i.sendKey(r,13,`up`);break;case`enter`:i.sendKey(r,13,`down`),i.sendKey(r,13,`up`);break;case`escape`:i.sendKey(r,27,`down`),i.sendKey(r,27,`up`);break;case`select`:{let e=(t.arrowDirection??`down`)===`down`?40:38,n=t.arrowCount??1;for(let t=0;t<n;t++)i.sendKey(r,e,`down`),i.sendKey(r,e,`up`),await l(30);await l(50),i.sendKey(r,13,`down`),i.sendKey(r,13,`up`);break}case`type`:t.text&&(i.sendText(r,t.text),await l(50)),i.sendKey(r,13,`down`),i.sendKey(r,13,`up`);break}return!0}catch{return!1}},async clickElement(t){if(process.platform!==`win32`||!Z())return!1;try{let{getBoundHwnd:n}=(J(),e(U)),r=n();if(!r)return!1;let{captureAccessibilitySnapshot:i,findNodeInSnapshot:a}=(ai(),e($r)),o=i(r);if(!o)return!1;let s=a(o.nodes,t);if(!s)return!1;let{clickElement:c}=(gi(),e(oi)),l=(ce(),e(se)).listWindows().find(e=>e.hwnd===r);if(l&&s.automationId&&c(l.title,s.automationId))return!0;let u=s.bounds.x+Math.round(s.bounds.w/2),ee=s.bounds.y+Math.round(s.bounds.h/2),te=bi(),{sendClick:ne}=(H(),e(R));return ne((H(),e(R)).findEditChild(r)??r,u-te.dx,ee-te.dy,`left`),!0}catch{return!1}},async typeIntoElement(t,n){if(process.platform!==`win32`||!Z())return!1;try{let{getBoundHwnd:r}=(J(),e(U)),i=r();if(!i)return!1;let a=(ce(),e(se)).listWindows().find(e=>e.hwnd===i);if(a){let{setValue:r,findElement:i}=(gi(),e(oi));if(t.automationId&&r(a.title,t.automationId,n))return!0;if(t.name){let e=i(a.title,t);if(e&&e.automationId&&r(a.title,e.automationId,n))return!0}}let{captureAccessibilitySnapshot:o,findNodeInSnapshot:s}=(ai(),e($r)),c=o(i);if(!c)return!1;let u=s(c.nodes,t);if(!u)return!1;let ee=bi(),te=u.bounds.x+Math.round(u.bounds.w/2)-ee.dx,ne=u.bounds.y+Math.round(u.bounds.h/2)-ee.dy,{sendClick:re,sendText:ie}=(H(),e(R));return re(i,te,ne,`left`),await l(50),ie(i,n)}catch{return!1}}}}async function wi(e){}var Q,$,Ti=t((()=>{o(),u(),ne(),C(),Qr(),Q=null,$=null}));function Ei(e,t,n){return ae(Math.round(e*n),Math.round(t*n),ie)}async function Di(){if(process.platform===`win32`){let{stdout:e,code:t}=await c(`powershell`,[`-NoProfile`,`-Command`,`Get-Clipboard`],{useCwd:!1});if(t!==0)throw Error(`PowerShell Get-Clipboard exited with code ${t}`);return e}if(process.platform===`linux`){let{stdout:e,code:t}=await c(`xclip`,[`-selection`,`clipboard`,`-o`],{useCwd:!1});if(t!==0)throw Error(`xclip exited with code ${t}`);return e}let{stdout:e,code:t}=await c(`pbpaste`,[],{useCwd:!1});if(t!==0)throw Error(`pbpaste exited with code ${t}`);return e}async function Oi(e){if(process.platform===`win32`){let{code:t}=await c(`powershell`,[`-NoProfile`,`-Command`,`Set-Clipboard -Value '${e.replace(/'/g,`''`)}'`],{useCwd:!1});if(t!==0)throw Error(`PowerShell Set-Clipboard exited with code ${t}`);return}if(process.platform===`linux`){let{code:t}=await c(`xclip`,[`-selection`,`clipboard`],{input:e,useCwd:!1});if(t!==0)throw Error(`xclip exited with code ${t}`);return}let{code:t}=await c(`pbcopy`,[],{input:e,useCwd:!1});if(t!==0)throw Error(`pbcopy exited with code ${t}`)}function ki(e){if(e.length!==1)return!1;let t=e[0].toLowerCase();return t===`escape`||t===`esc`}async function Ai(e,t,n){await e.moveMouse(t,n,!1),await l(Ri)}async function ji(e,t){let n;for(;(n=t.pop())!==void 0;)try{await e.key(n,`release`)}catch{}}async function Mi(e,t,n){let r=[];try{for(let n of t)await e.key(n,`press`),r.push(n);return await n()}finally{await ji(e,r)}}async function Ni(e,t){let n;try{n=await Di()}catch{a(`[computer-use] pbpaste before paste failed; proceeding without restore`)}try{if(await Oi(t),await Di()!==t)throw Error(`Clipboard write did not round-trip.`);await e.keys([process.platform===`darwin`?`command`:`ctrl`,`v`]),await l(100)}finally{if(typeof n==`string`)try{await Oi(n)}catch{a(`[computer-use] clipboard restore after paste failed`)}}}async function Pi(e,t,n,r){if(!r){await Ai(e,t,n);return}let i=await e.mouseLocation(),a=t-i.x,o=n-i.y,s=Math.hypot(a,o);if(s<1)return;let c=Math.min(s/2e3,.5);if(c<.03){await Ai(e,t,n);return}let u=Math.floor(c*60);for(let t=1;t<=u;t++){let n=1-(1-t/u)**3;await e.moveMouse(Math.round(i.x+a*n),Math.round(i.y+o*n),!1),t<u&&await l(16.666666666666668)}await l(Ri)}function Fi(t){if(process.platform!==`darwin`){let{createCrossPlatformExecutor:n}=(Ti(),e(_i));return n(t)}let n=f(),{getMouseAnimationEnabled:i,getHideBeforeActionEnabled:o}=t,s=ee(),c=s??`com.anthropic.claude-code.cli-no-window`,u=e=>s===null?[...e]:e.filter(e=>e!==s);return a(s?`[computer-use] terminal ${s} → surrogate host (hide-exempt, activate-skip, screenshot-excluded)`:`[computer-use] terminal not detected; falling back to sentinel host`),{capabilities:{...re,hostBundleId:te},async prepareForAction(e,t){return o()?d(async()=>{try{let r=await n.apps.prepareDisplay(e,c,t);return r.activated&&a(`[computer-use] prepareForAction: activated ${r.activated}`),r.hidden}catch(e){return a(`[computer-use] prepareForAction failed; continuing to action: ${r(e)}`,{level:`warn`}),[]}}):[]},async previewHideSet(e,t){return n.apps.previewHideSet([...e,c],t)},async getDisplaySize(e){return n.display.getSize(e)},async listDisplays(){return n.display.listAll()},async findWindowDisplays(e){return n.apps.findWindowDisplays(e)},async resolvePrepareCapture(e){let t=n.display.getSize(e.preferredDisplayId),[r,i]=Ei(t.width,t.height,t.scaleFactor),a=await d(()=>n.resolvePrepareCapture(u(e.allowedBundleIds),c,Li,r,i,e.preferredDisplayId)),o=a;return{...a,displayWidth:o.displayWidth??o.width,displayHeight:o.displayHeight??o.height,originX:o.originX??0,originY:o.originY??0,hidden:o.hidden??[],displayId:o.displayId??e.preferredDisplayId??t.displayId}},async screenshot(e){let t=n.display.getSize(e.displayId),[r,i]=Ei(t.width,t.height,t.scaleFactor);return d(()=>n.screenshot.captureExcluding(u(e.allowedBundleIds),Li,r,i,e.displayId))},async zoom(e,t,r){let i=n.display.getSize(r),[a,o]=Ei(e.w,e.h,i.scaleFactor);return d(()=>n.screenshot.captureRegion(u(t),e.x,e.y,e.w,e.h,a,o,Li,r))},async key(e,t){let n=y(),r=e.split(`+`).filter(e=>e.length>0),i=ki(r),a=t??1;await d(async()=>{for(let e=0;e<a;e++)e>0&&await l(8),i&&le(),await n.keys(r)})},async holdKey(e,t){let n=y(),r=[],i=!1;try{await d(async()=>{for(let t of e){if(i)return;ki([t])&&le(),await n.key(t,`press`),r.push(t)}}),await l(t)}finally{i=!0,await d(()=>ji(n,r))}},async type(e,t){let n=y();if(t.viaClipboard){await d(()=>Ni(n,e));return}await n.typeText(e)},readClipboard:Di,writeClipboard:Oi,async moveMouse(e,t){await Ai(y(),e,t)},async click(e,t,n,r,i){let a=y();await Ai(a,e,t),i&&i.length>0?await d(()=>Mi(a,i,()=>a.mouseButton(n,`click`,r))):await a.mouseButton(n,`click`,r)},async mouseDown(){await y().mouseButton(`left`,`press`)},async mouseUp(){await y().mouseButton(`left`,`release`)},async getCursorPosition(){return y().mouseLocation()},async drag(e,t){let n=y();e!==void 0&&await Ai(n,e.x,e.y),await n.mouseButton(`left`,`press`),await l(Ri);try{await Pi(n,t.x,t.y,i())}finally{await n.mouseButton(`left`,`release`)}},async scroll(e,t,n,r){let i=y();await Ai(i,e,t),r!==0&&await i.mouseScroll(r,`vertical`),n!==0&&await i.mouseScroll(n,`horizontal`)},async getFrontmostApp(){let e=y().getFrontmostAppInfo();return!e||!e.bundleId?null:{bundleId:e.bundleId,displayName:e.appName}},async appUnderPoint(e,t){return n.apps.appUnderPoint(e,t)},async listInstalledApps(){return d(()=>n.apps.listInstalled())},async getAppIcon(e){return n.apps.iconDataUrl(e)??void 0},async listRunningApps(){return n.apps.listRunning()},async openApp(e){await n.apps.open(e)}}}async function Ii(e){e.length!==0&&process.platform===`darwin`&&await f().apps.unhide([...e])}var Li,Ri,zi=t((()=>{oe(),o(),i(),s(),u(),ne(),ue(),fe(),bt(),de(),Li=.75,Ri=50}));export{zi as n,Ii as r,Fi as t};
|