@wobuxcm/dsh-win-tools 0.0.0-stage → 0.2.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 cjl15
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,89 @@
1
- # Temporary Holding Version
1
+ # @wobuxcm/dsh-win-tools
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Windows 桌面控制插件(DeepSeek Harness 宿主插件)。自带全部运行时:没有其它插件依赖。
4
+
5
+ ## 工具(15 个 `pc_*`)
6
+
7
+ | 工具 | 作用 |
8
+ |---|---|
9
+ | `pc_status` | 无障碍桥接健康、平台、权限、CLI 版本 |
10
+ | `pc_snapshot` | 读无障碍树,返回 `@ref`;支持 `surface` / `waitFor` / `root` / `includeBounds` |
11
+ | `pc_find` | 按 role/name/value/text 直接搜索元素(比全量快照轻) |
12
+ | `pc_read` | 按 `@ref` 读单个属性或状态(text/value/bounds/visible…) |
13
+ | `pc_act` | 按 `ref` 执行无障碍动作,或按坐标注入鼠标/键盘(自绘界面) |
14
+ | `pc_key` | 按键组合(SendInput,Unicode 安全) |
15
+ | `pc_screen` | GDI 截图,返回 PNG 路径并作为图片附件返回;`annotate: true` 叠无障碍框与编号 |
16
+ | `pc_display` | 显示器布局(物理像素)与 DPI |
17
+ | `pc_window` | 列举/聚焦窗口 |
18
+ | `pc_browser` | 浏览器 DOM 操作:title/text/table/links/click/type/shot |
19
+ | `pc_wait` | 进程内轮询:窗口标题 / 像素 / 区域比例 / 画面变化,可附带动作 |
20
+ | `pc_app` | 应用列举/启动/关闭/缩放/最小化/最大化/还原 |
21
+ | `pc_clipboard` | 读写文本剪贴板 |
22
+ | `pc_notify` | 托盘气泡通知 |
23
+ | `pc_pause` | 操作员急停开关(pause/resume/status) |
24
+
25
+ ## 安全
26
+
27
+ - **急停(唯一开关)**:全局热键 `Ctrl+Alt+Shift+F12` 切换 `%DSH_HOME%/cua.stop`;文件存在时所有写操作(`pc_act`/`pc_key`/`pc_window` focus/`pc_app`/`pc_wait`)返回 `PAUSED_BY_USER`
28
+ - **黑名单**:点击/按键前检查目标点与前台窗口标题,命中「支付/充值/购买/授权/扫码/付款/收银/转账/下单/结算/微信支付/支付宝」直接返回 `BLOCKED_KEYWORD`
29
+ - **日志**:`%DSH_HOME%/win-tools.log`(JSONL)
30
+
31
+ ## 内置组件
32
+
33
+ | 路径 | 来源 | 许可 |
34
+ |---|---|---|
35
+ | `lib/cua/*.js`(native/input/screen/engine/safety) | 本项目原创 | MIT,见根目录 `LICENSE` |
36
+ | `bin/agent-desktop-win32-x64.exe` | agent-desktop(Vercel Labs) | Apache-2.0,见 `LICENSES/Apache-2.0.txt` 与 `THIRD-PARTY-NOTICES.md` |
37
+ | `bin/web.js` | 本项目原创 | MIT |
38
+ | 依赖 `koffi`、`pngjs` | npm | 各自许可 |
39
+ | 可选 `playwright-core` | npm | 仅 `pc_browser` 需要 |
40
+
41
+ ## 安装
42
+
43
+ 作为 npm 包安装到 DSH profile:
44
+
45
+ ```powershell
46
+ npm i @wobuxcm/dsh-win-tools
47
+ # 本机开发时也可以直接 link 源码目录:
48
+ # "@wobuxcm/dsh-win-tools": "link:D:/DSH-Home/plugin-sources/dsh-win-tools"
49
+ ```
50
+
51
+ 然后在 profile 的 `package.json` 里把插件加入 `dsh.profile.bundles`:
52
+
53
+ ```json
54
+ "dsh": { "profile": { "bundles": ["@wobuxcm/dsh-win-tools"] } }
55
+ ```
56
+
57
+ 开发时用 junction 指向源码目录:
58
+
59
+ ```powershell
60
+ New-Item -ItemType Junction -Path "<profile>\node_modules\@wobuxcm\dsh-win-tools" -Target "<插件源码目录>"
61
+ ```
62
+
63
+ ## 环境变量覆盖
64
+
65
+ `PC_AGENT_BIN`(无障碍二进制)、`PC_CUA_DIR`(cua 库目录)、`PC_BROWSER_JS`(web.js)、`PC_NODE_BIN`(跑 web.js 的 node)。
66
+
67
+ ## 打包
68
+
69
+ ```powershell
70
+ npm pack --dry-run # 清单预演
71
+ npm pack # 生成 wobuxcm-dsh-win-tools-<version>.tgz
72
+ ```
73
+
74
+ 清单:`index.js`、`lib/`、`bin/`、`LICENSES/`、`THIRD-PARTY-NOTICES.md`、`cordis.patch.yml`、`README.md`、`package.json`。
75
+
76
+ ## 许可与第三方
77
+
78
+ - 本插件自身代码(`index.js`、`lib/core.js`、`lib/cua/*`、`bin/web.js`): **MIT**,见根目录 `LICENSE`(Copyright (c) 2026 cjl15)
79
+ - `bin/agent-desktop-win32-x64.exe`: **Apache-2.0**,来自 [vercel-labs/agent-desktop](https://github.com/vercel-labs/agent-desktop),**未修改**(与上游 `agent-desktop@1.2.0` 内的同名产物 SHA-256 一致),以独立进程调用;许可证全文见 `LICENSES/Apache-2.0.txt`
80
+ - npm 依赖:`koffi`(MIT)、`pngjs`(MIT)、`playwright-core`(Apache-2.0,可选)
81
+ - 本项目与 Vercel Labs 无隶属或背书关系;不使用其名称作为项目名
82
+
83
+ 完整声明见 `THIRD-PARTY-NOTICES.md`。
84
+
85
+ ## 限制
86
+
87
+ - 仅 Windows x64(二进制与 SendInput/GDI 均为 Windows 实现)
88
+ - `pc_browser` 需要 `playwright-core`(可选依赖)与本机 Edge/Chrome
89
+ - `pc_wait` 的 `image_changed` 需要显式 `rect`,整屏轮询开销大
@@ -0,0 +1,36 @@
1
+ # 第三方组件声明(Third-Party Notices)
2
+
3
+ 本插件(dsh-win-tools)自身代码采用 MIT 许可,见根目录 `LICENSE`。
4
+ 下列第三方组件按各自许可分发,本插件不改变其许可条款。
5
+
6
+ ## 1. agent-desktop(Vercel Labs)— Apache-2.0
7
+
8
+ - **来源**:https://github.com/vercel-labs/agent-desktop
9
+ - **分发形式**:`bin/agent-desktop-win32-x64.exe`(官方 npm 包 `agent-desktop@1.2.0` 内的 Windows x64 产物)
10
+ - **修改情况**:**未修改**。以独立进程调用(`child_process.spawn`),不链接、不静态嵌入、不改写二进制。
11
+ - **许可证全文**:`LICENSES/Apache-2.0.txt`
12
+ - **上游 NOTICE**:npm 包内未提供 NOTICE 文件,本仓库不附带。
13
+ - **商标**:agent-desktop 及其名称归其作者所有;本项目为独立社区实现,**与 Vercel Labs 无隶属、合作或背书关系**,不使用其名称作为本项目名称或宣传语。
14
+
15
+ ## 2. 内嵌 Windows 原生库(lib/cua/)
16
+
17
+ - **作者**:本项目作者(cjl15),2026 年原创编写
18
+ - **许可**:随本插件以 MIT 分发(见根目录 `LICENSE`)
19
+ - **内容**:`lib/cua/native.js`、`input.js`、`screen.js`、`engine.js`、`safety.js`
20
+ - **依赖**:运行时通过 npm 依赖 `koffi`(MIT)调用 Win32 API
21
+
22
+ ## 3. 浏览器 CLI(bin/web.js)
23
+
24
+ - **作者**:本项目作者(cjl15)
25
+ - **许可**:随本插件以 MIT 分发
26
+ - **依赖**:`playwright-core`(Apache-2.0),作为 **可选依赖**,不随本包分发
27
+
28
+ ## 4. npm 依赖
29
+
30
+ | 包 | 许可 | 用途 |
31
+ |---|---|---|
32
+ | koffi | MIT | Win32 API FFI |
33
+ | pngjs | MIT | PNG 解码(截图/像素) |
34
+ | playwright-core(可选) | Apache-2.0 | 浏览器自动化 |
35
+
36
+ 这些依赖由使用者在安装时获取,各自保留其许可与版权声明。
Binary file
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
package/bin/web.js ADDED
@@ -0,0 +1,147 @@
1
+ // web.js — Layer-2 browser automation CLI (Playwright driving installed Edge/Chrome).
2
+ // No screenshots, no OCR, no coordinate guessing.
3
+ //
4
+ // node web.js title <url>
5
+ // node web.js text <url> [maxChars]
6
+ // node web.js table <url> <css-selector> # selector points at <tr>
7
+ // node web.js links <url> [maxLinks]
8
+ // node web.js click <url> <css-selector> # prints title+url after click
9
+ // node web.js type <url> <selector> <text> # fill an input, press Enter
10
+ // node web.js shot <url> <out.png> [width] # only when you truly need pixels
11
+ //
12
+ // Flags: --profile <dir> persist cookies/logins --headful show the window
13
+ // --wait <ms> extra settle time --cdp <url> attach to running browser
14
+
15
+ const { chromium } = require("playwright-core");
16
+ const path = require("path");
17
+ const fs = require("fs");
18
+
19
+ const EDGE = "C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe";
20
+ const CHROME = "C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe";
21
+
22
+ const argv = process.argv.slice(2);
23
+ const flags = {};
24
+ const pos = [];
25
+ for (let i = 0; i < argv.length; i++) {
26
+ const a = argv[i];
27
+ if (a.startsWith("--")) {
28
+ const key = a.slice(2);
29
+ const next = argv[i + 1];
30
+ if (next && !next.startsWith("--")) { flags[key] = next; i++; }
31
+ else flags[key] = true;
32
+ } else pos.push(a);
33
+ }
34
+
35
+ const [cmd, ...rest] = pos;
36
+ const headless = !flags.headful;
37
+
38
+ async function open() {
39
+ if (flags.cdp) {
40
+ const b = await chromium.connectOverCDP(String(flags.cdp));
41
+ const ctx = b.contexts()[0] || (await b.newContext());
42
+ return { browser: b, ctx, page: await ctx.newPage(), close: () => b.close() };
43
+ }
44
+ const launchOpts = { headless, args: ["--disable-blink-features=AutomationControlled"] };
45
+ let ctx, browser;
46
+ if (flags.profile) {
47
+ ctx = await chromium.launchPersistentContext(path.resolve(String(flags.profile)), launchOpts);
48
+ return { browser: null, ctx, page: await ctx.newPage(), close: () => ctx.close() };
49
+ }
50
+ for (const extra of [{ channel: "msedge" }, { executablePath: EDGE }, { channel: "chrome" }, { executablePath: CHROME }]) {
51
+ try {
52
+ browser = await chromium.launch({ ...launchOpts, ...extra });
53
+ break;
54
+ } catch {}
55
+ }
56
+ if (!browser) throw new Error("no usable Chromium browser (Edge/Chrome) found");
57
+ ctx = await browser.newContext();
58
+ return { browser, ctx, page: await ctx.newPage(), close: () => browser.close() };
59
+ }
60
+
61
+ (async () => {
62
+ const sess = await open();
63
+ const page = sess.page;
64
+ const out = { cmd };
65
+ try {
66
+ const url = rest[0];
67
+ if (!url) throw new Error("missing url");
68
+ await page.goto(url, { timeout: 45000, waitUntil: "domcontentloaded" });
69
+ if (flags.wait) await page.waitForTimeout(Number(flags.wait));
70
+ out.url = page.url();
71
+ out.title = await page.title();
72
+
73
+ if (cmd === "title") {
74
+ // done
75
+ } else if (cmd === "text") {
76
+ const max = Number(rest[1] || 4000);
77
+ out.text = await page.evaluate(() => {
78
+ const el = document.body;
79
+ return (el ? el.innerText : "").replace(/\n{3,}/g, "\n\n").trim();
80
+ }).then(t => t.slice(0, max));
81
+ } else if (cmd === "table") {
82
+ const sel = rest[1];
83
+ if (!sel) throw new Error("missing selector");
84
+ out.rows = await page.evaluate((s) => {
85
+ return Array.from(document.querySelectorAll(s)).slice(0, 500).map(tr =>
86
+ Array.from(tr.querySelectorAll("th,td")).map(c => (c.textContent || "").trim()));
87
+ }, sel);
88
+ out.count = out.rows.length;
89
+ } else if (cmd === "links") {
90
+ const max = Number(rest[1] || 40);
91
+ out.links = await page.evaluate((m) => Array.from(document.querySelectorAll("a[href]"))
92
+ .slice(0, m).map(a => ({ text: (a.textContent || "").trim().slice(0, 80), href: a.href })), max);
93
+ } else if (cmd === "click") {
94
+ const sel = rest[1];
95
+ if (!sel) throw new Error("missing selector");
96
+ await page.locator(sel).first().click({ timeout: 20000 });
97
+ await page.waitForTimeout(Number(flags.wait || 1200));
98
+ out.after_url = page.url();
99
+ out.after_title = await page.title();
100
+ out.after_text = await page.evaluate(() =>
101
+ (document.body?.innerText || "").replace(/\n{3,}/g, "\n\n").trim().slice(0, 2000));
102
+ } else if (cmd === "type") {
103
+ const [, sel, text] = rest;
104
+ if (!sel || text === undefined) throw new Error("usage: type <url> <selector> <text>");
105
+ const loc = page.locator(sel).first();
106
+ let method = "click+type";
107
+ try {
108
+ await loc.click({ timeout: 6000 });
109
+ await page.keyboard.type(String(text), { delay: 20 });
110
+ } catch {
111
+ // Fallback for inputs that are attached but not "visible" (hidden originals,
112
+ // overlays, custom-styled search boxes): set the value and dispatch events.
113
+ method = "evaluate+dispatch";
114
+ await page.evaluate(({ s, v }) => {
115
+ const el = document.querySelector(s);
116
+ if (!el) throw new Error("selector not found: " + s);
117
+ el.focus();
118
+ el.value = v;
119
+ el.dispatchEvent(new Event("input", { bubbles: true }));
120
+ el.dispatchEvent(new Event("change", { bubbles: true }));
121
+ }, { s: sel, v: String(text) });
122
+ }
123
+ await page.keyboard.press("Enter");
124
+ await page.waitForTimeout(Number(flags.wait || 2500));
125
+ out.method = method;
126
+ out.after_url = page.url();
127
+ out.after_title = await page.title();
128
+ out.after_text = await page.evaluate(() =>
129
+ (document.body?.innerText || "").replace(/\n{3,}/g, "\n\n").trim().slice(0, 2000));
130
+ } else if (cmd === "shot") {
131
+ const file = rest[1];
132
+ if (!file) throw new Error("missing output path");
133
+ const w = Number(rest[2] || 1440);
134
+ await page.setViewportSize({ width: w, height: 900 });
135
+ await page.screenshot({ path: file, fullPage: flags.full === true });
136
+ out.saved = path.resolve(file);
137
+ out.bytes = fs.statSync(file).size;
138
+ } else {
139
+ throw new Error("unknown command: " + cmd);
140
+ }
141
+ } catch (e) {
142
+ out.error = String((e && e.message) || e);
143
+ } finally {
144
+ await sess.close().catch(() => {});
145
+ }
146
+ console.log(JSON.stringify(out, null, 2));
147
+ })();
@@ -0,0 +1,4 @@
1
+ # dsh-win-tools: one Host row exposing the unified pc_* tool surface.
2
+ - insert:
3
+ - id: win-tools
4
+ name: '@wobuxcm/dsh-win-tools'