deepseek-harness-win32-picker 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,64 @@
1
+ # DeepSeek Harness Win32 Picker
2
+
3
+ 为 DeepSeek Harness 的 Windows Web 界面提供原生文件夹选择器。用户从设置页或工作区流程选择目录时,插件打开 Windows `IFileOpenDialog`,并把当前前台浏览器窗口设为 owner,让选择器保持在发起操作的窗口上方。
4
+
5
+ ## 安装到 DSH
6
+
7
+ 需要 Windows、Node.js 22.19 或更高版本,以及已安装的 `dsh` CLI。把 npm 包安装到 `web` profile:
8
+
9
+ ```sh
10
+ dsh plugin --profile web add deepseek-harness-win32-picker
11
+ dsh web
12
+ ```
13
+
14
+ npm 包名是全局唯一名称,使用 npm 安装时不需要 GitHub 用户名。也可以直接从 GitHub 安装;GitHub 地址需要包含组织名:
15
+
16
+ ```sh
17
+ dsh plugin --profile web add github:civilization-os/deepseek-harness-win32-picker
18
+ dsh web
19
+ ```
20
+
21
+ 安装或更新后需要重启正在运行的 `dsh web`,再刷新浏览器页面。插件会替换 web profile 的自适应目录选择器,并复用 DSH 自带的原生目录选择 UI。
22
+
23
+ 更新或卸载:
24
+
25
+ ```sh
26
+ dsh plugin --profile web update deepseek-harness-win32-picker
27
+ dsh plugin --profile web remove deepseek-harness-win32-picker
28
+ ```
29
+
30
+ ## 行为
31
+
32
+ - 只在 Windows 上启动;其他系统会在加载时给出明确错误。
33
+ - 使用现代 Windows 文件夹选择器,只允许选择文件系统目录。
34
+ - 在打开选择器前读取当前前台窗口,并把它传给 `IFileDialog::Show(owner)`。
35
+ - 取消选择返回空结果,不会当作执行错误。
36
+ - DSH 中止请求时,插件向选择器线程发送 `WM_CLOSE`;无响应时终止独立 worker 进程。
37
+ - COM 对话框在独立 Node.js 子进程中运行,不阻塞 DSH 主进程事件循环。
38
+
39
+ 这个 owner 关系只让选择器位于发起操作的浏览器窗口上方,不会把它设为覆盖所有应用的系统级置顶窗口。
40
+
41
+ ## 本地开发
42
+
43
+ ```sh
44
+ pnpm install
45
+ pnpm test
46
+ pnpm build
47
+ ```
48
+
49
+ 把当前 checkout 安装到本机 web profile:
50
+
51
+ ```sh
52
+ dsh plugin --profile web add .
53
+ dsh web
54
+ ```
55
+
56
+ 发布内容只有编译后的 host 插件、Win32 worker、DSH patch、README 和许可证。`koffi` 是运行时依赖;插件不下载浏览器或其他原生程序。
57
+
58
+ ## 发布
59
+
60
+ GitHub Actions 在推送 `v*` tag 或手动运行工作流时执行测试、构建并发布 npm 包。仓库需要配置名为 `NPM_TOKEN` 的 Actions secret。tag 必须与 `package.json` 版本一致,例如 `0.1.0` 对应 `v0.1.0`。
61
+
62
+ ## 许可证
63
+
64
+ [MIT](LICENSE)
@@ -0,0 +1,8 @@
1
+ # Replace the web profile's adaptive picker with this Windows backend and
2
+ # mount the official native directory-picker browser surface beside it.
3
+ - id: directory-picker
4
+ name: deepseek-harness-win32-picker
5
+
6
+ - insert:
7
+ - id: directory-picker-win32-surface
8
+ name: '@deepseek-ai/dsh-client-ui-directory-picker-native'
package/lib/index.js ADDED
@@ -0,0 +1,159 @@
1
+ // src/index.ts
2
+ import { Service } from "@deepseek-ai/cordis";
3
+
4
+ // src/win32-dialog-host.ts
5
+ import { spawn } from "node:child_process";
6
+ import { fileURLToPath } from "node:url";
7
+
8
+ // src/win32-dialog-bindings.ts
9
+ var SIGDN_FILESYSPATH = 2147844096 | 0;
10
+ var WM_CLOSE = 16;
11
+ function guidBytes(text) {
12
+ const match = /^([0-9a-f]{8})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{12})$/i.exec(text);
13
+ const bytes = Buffer.alloc(16);
14
+ bytes.writeUInt32LE(parseInt(match[1], 16), 0);
15
+ bytes.writeUInt16LE(parseInt(match[2], 16), 4);
16
+ bytes.writeUInt16LE(parseInt(match[3], 16), 6);
17
+ Buffer.from(match[4] + match[5], "hex").copy(bytes, 8);
18
+ return bytes;
19
+ }
20
+ var CLSID_FILE_OPEN_DIALOG = guidBytes("dc1c5a9c-e88a-4dde-a5a1-60f82a20aef7");
21
+ var IID_IFILE_OPEN_DIALOG = guidBytes("d57c7288-d4ad-4768-be02-9d969532d960");
22
+ async function closeThreadWindows(threadId) {
23
+ const koffi = (await import("koffi")).default;
24
+ const user32 = koffi.load("user32.dll");
25
+ const enumThreadWindows = user32.func("__stdcall", "EnumThreadWindows", "int", ["uint32", "void *", "intptr"]);
26
+ const postMessageW = user32.func("__stdcall", "PostMessageW", "int", ["void *", "uint32", "uintptr", "intptr"]);
27
+ const protoEnumProc = koffi.proto("int __stdcall DshEnumThreadWndProc(void *hwnd, intptr lparam)");
28
+ const callback = koffi.register((hwnd) => {
29
+ postMessageW(hwnd, WM_CLOSE, 0, 0);
30
+ return 1;
31
+ }, koffi.pointer(protoEnumProc));
32
+ try {
33
+ enumThreadWindows(threadId, callback, 0);
34
+ } finally {
35
+ koffi.unregister(callback);
36
+ }
37
+ }
38
+
39
+ // src/win32-dialog-host.ts
40
+ function spawnDialogWorker(data) {
41
+ const env = { ...process.env, DSH_DIALOG_TITLE: data.title };
42
+ const stdio = ["ignore", "inherit", "inherit", "ipc"];
43
+ if (!import.meta.url.endsWith(".ts")) {
44
+ return spawn(process.execPath, [fileURLToPath(new URL("./worker.cjs", import.meta.url))], { env, stdio, windowsHide: true });
45
+ }
46
+ return spawn(process.execPath, ["--import", import.meta.resolve("tsx/esm"), fileURLToPath(new URL("./win32-dialog-worker.ts", import.meta.url))], { env, stdio, windowsHide: true });
47
+ }
48
+
49
+ // src/win32-dialog.ts
50
+ var DIALOG_TITLE = "Select Workspace Directory";
51
+ var CLOSE_RETRY_MS = 150;
52
+ var CLOSE_MAX_ATTEMPTS = 20;
53
+ function assertNever(value) {
54
+ throw new TypeError(`unknown win32 dialog worker message kind: ${String(value)}`);
55
+ }
56
+ async function pickWin32Directory(signal, internals = {}) {
57
+ if (signal.aborted) throw new Error("native directory picker aborted");
58
+ const spawnWorker = internals.spawnWorker ?? spawnDialogWorker;
59
+ const closeWindows = internals.closeThreadWindows ?? closeThreadWindows;
60
+ const closeRetryMs = internals.closeRetryMs ?? CLOSE_RETRY_MS;
61
+ const worker = spawnWorker({ title: DIALOG_TITLE });
62
+ let dialogThreadId;
63
+ let closeTimer;
64
+ let settled = false;
65
+ return await new Promise((resolve, reject) => {
66
+ const settle = (outcome) => {
67
+ if (settled) return;
68
+ settled = true;
69
+ if (closeTimer !== void 0) clearInterval(closeTimer);
70
+ signal.removeEventListener("abort", onAbort);
71
+ worker.unref?.();
72
+ outcome();
73
+ };
74
+ const postClose = () => {
75
+ if (dialogThreadId !== void 0) void closeWindows(dialogThreadId).catch(() => void 0);
76
+ };
77
+ const serviceAbort = () => {
78
+ let attempts = 0;
79
+ closeTimer = setInterval(() => {
80
+ attempts += 1;
81
+ if (attempts > CLOSE_MAX_ATTEMPTS) {
82
+ settle(() => {
83
+ worker.kill();
84
+ reject(new Error("native directory picker aborted (dialog unresponsive; worker killed)"));
85
+ });
86
+ return;
87
+ }
88
+ postClose();
89
+ }, closeRetryMs);
90
+ postClose();
91
+ };
92
+ const onAbort = () => {
93
+ serviceAbort();
94
+ };
95
+ signal.addEventListener("abort", onAbort, { once: true });
96
+ worker.on("message", (message) => {
97
+ switch (message.kind) {
98
+ case "showing":
99
+ dialogThreadId = message.threadId;
100
+ if (signal.aborted) postClose();
101
+ return;
102
+ case "done":
103
+ settle(() => {
104
+ if (signal.aborted) reject(new Error("native directory picker aborted"));
105
+ else resolve(message.path);
106
+ });
107
+ return;
108
+ case "error":
109
+ settle(() => {
110
+ reject(new Error(`win32 folder dialog failed: ${message.message}`));
111
+ });
112
+ return;
113
+ /* v8 ignore next 2 -- closed worker-owned union; a fourth kind becomes a compile error */
114
+ default:
115
+ assertNever(message);
116
+ }
117
+ });
118
+ worker.on("error", (error) => {
119
+ settle(() => {
120
+ reject(error);
121
+ });
122
+ });
123
+ worker.on("exit", () => {
124
+ settle(() => {
125
+ reject(new Error("win32 folder dialog worker exited before reporting a result"));
126
+ });
127
+ });
128
+ });
129
+ }
130
+
131
+ // src/index.ts
132
+ var name = "win32-directory-picker";
133
+ var Win32DirectoryPicker = class extends Service {
134
+ nativeCapability = {
135
+ kind: "native",
136
+ pick: (signal) => pickWin32Directory(signal)
137
+ };
138
+ /**
139
+ * @param ctx - Cordis context that owns the service lifetime.
140
+ */
141
+ constructor(ctx) {
142
+ if (process.platform !== "win32") {
143
+ throw new Error("deepseek-harness-win32-picker requires Windows");
144
+ }
145
+ super(ctx, "directoryPicker");
146
+ }
147
+ /**
148
+ * Return the stable native picker capability.
149
+ * @returns the capability used by the DSH workspace UI.
150
+ */
151
+ capability() {
152
+ return this.nativeCapability;
153
+ }
154
+ };
155
+ export {
156
+ Win32DirectoryPicker as default,
157
+ name,
158
+ pickWin32Directory
159
+ };
package/lib/worker.cjs ADDED
@@ -0,0 +1,186 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (let key of __getOwnPropNames(from))
11
+ if (!__hasOwnProp.call(to, key) && key !== except)
12
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
13
+ }
14
+ return to;
15
+ };
16
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
17
+ // If the importer is in node compatibility mode or this is not an ESM
18
+ // file that has been converted to a CommonJS file using a Babel-
19
+ // compatible transform (i.e. "__esModule" has not been set), then set
20
+ // "default" to the CommonJS "module.exports" for node compatibility.
21
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
+ mod
23
+ ));
24
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
+
26
+ // src/win32-dialog-worker.ts
27
+ var win32_dialog_worker_exports = {};
28
+ module.exports = __toCommonJS(win32_dialog_worker_exports);
29
+
30
+ // src/win32-dialog-bindings.ts
31
+ function readUtf16(koffi, address) {
32
+ const bytes = Buffer.from(koffi.view(address, 32768));
33
+ let end = 0;
34
+ while (end + 1 < bytes.length && !(bytes[end] === 0 && bytes[end + 1] === 0)) end += 2;
35
+ return bytes.toString("utf16le", 0, end);
36
+ }
37
+ var COINIT_APARTMENTTHREADED = 2;
38
+ var CLSCTX_INPROC_SERVER = 1;
39
+ var SIGDN_FILESYSPATH = 2147844096 | 0;
40
+ var DPI_AWARENESS_CONTEXTS = [-4, -3, -2];
41
+ var SLOT_RELEASE = 2;
42
+ var SLOT_SHOW = 3;
43
+ var SLOT_SET_OPTIONS = 9;
44
+ var SLOT_SET_TITLE = 17;
45
+ var SLOT_GET_RESULT = 20;
46
+ var SLOT_GET_DISPLAY_NAME = 5;
47
+ function guidBytes(text) {
48
+ const match = /^([0-9a-f]{8})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{12})$/i.exec(text);
49
+ const bytes = Buffer.alloc(16);
50
+ bytes.writeUInt32LE(parseInt(match[1], 16), 0);
51
+ bytes.writeUInt16LE(parseInt(match[2], 16), 4);
52
+ bytes.writeUInt16LE(parseInt(match[3], 16), 6);
53
+ Buffer.from(match[4] + match[5], "hex").copy(bytes, 8);
54
+ return bytes;
55
+ }
56
+ var CLSID_FILE_OPEN_DIALOG = guidBytes("dc1c5a9c-e88a-4dde-a5a1-60f82a20aef7");
57
+ var IID_IFILE_OPEN_DIALOG = guidBytes("d57c7288-d4ad-4768-be02-9d969532d960");
58
+ async function loadWin32DialogBindings() {
59
+ const koffi = (await import("koffi")).default;
60
+ const ole32 = koffi.load("ole32.dll");
61
+ const user32 = koffi.load("user32.dll");
62
+ const kernel32 = koffi.load("kernel32.dll");
63
+ const pointerSize = koffi.sizeof("void *");
64
+ const coInitializeEx = ole32.func("__stdcall", "CoInitializeEx", "int32", ["void *", "uint32"]);
65
+ const coUninitialize = ole32.func("__stdcall", "CoUninitialize", "void", []);
66
+ const coCreateInstance = ole32.func("__stdcall", "CoCreateInstance", "int32", ["void *", "void *", "uint32", "void *", "void *"]);
67
+ const coTaskMemFree = ole32.func("__stdcall", "CoTaskMemFree", "void", ["void *"]);
68
+ const getCurrentThreadId = kernel32.func("__stdcall", "GetCurrentThreadId", "uint32", []);
69
+ const getForegroundWindow = user32.func("__stdcall", "GetForegroundWindow", "void *", []);
70
+ const protoShow = koffi.proto("int32 __stdcall DshDialogShow(void *self, void *owner)");
71
+ const protoSetOptions = koffi.proto("int32 __stdcall DshDialogSetOptions(void *self, uint32 options)");
72
+ const protoSetTitle = koffi.proto("int32 __stdcall DshDialogSetTitle(void *self, str16 title)");
73
+ const protoGetResult = koffi.proto("int32 __stdcall DshDialogGetResult(void *self, _Out_ void **item)");
74
+ const protoGetDisplayName = koffi.proto("int32 __stdcall DshItemGetDisplayName(void *self, int32 form, _Out_ void **name)");
75
+ const protoRelease = koffi.proto("uint32 __stdcall DshComRelease(void *self)");
76
+ const method = (self, slot, proto) => {
77
+ const vtable = koffi.decode(self, "void *");
78
+ const fn = koffi.decode(vtable, slot * pointerSize, "void *");
79
+ return (...args) => koffi.call(fn, proto, self, ...args);
80
+ };
81
+ return {
82
+ setThreadDpiAwareness: () => {
83
+ let setContext;
84
+ try {
85
+ setContext = user32.func("__stdcall", "SetThreadDpiAwarenessContext", "void *", ["intptr"]);
86
+ } catch {
87
+ return;
88
+ }
89
+ for (const context of DPI_AWARENESS_CONTEXTS) {
90
+ if (setContext(context) !== null) return;
91
+ }
92
+ },
93
+ coInitializeSta: () => coInitializeEx(null, COINIT_APARTMENTTHREADED),
94
+ coUninitialize: () => {
95
+ coUninitialize();
96
+ },
97
+ currentThreadId: () => getCurrentThreadId(),
98
+ foregroundWindow: () => getForegroundWindow(),
99
+ createFolderDialog: () => {
100
+ const out = Buffer.alloc(pointerSize);
101
+ const created = coCreateInstance(CLSID_FILE_OPEN_DIALOG, null, CLSCTX_INPROC_SERVER, IID_IFILE_OPEN_DIALOG, out);
102
+ if (created < 0) throw new Error(`CoCreateInstance(FileOpenDialog) failed: HRESULT 0x${(created >>> 0).toString(16)}`);
103
+ const dialog = koffi.decode(out, "void *");
104
+ return {
105
+ setOptions: (options) => method(dialog, SLOT_SET_OPTIONS, protoSetOptions)(options),
106
+ setTitle: (title2) => method(dialog, SLOT_SET_TITLE, protoSetTitle)(title2),
107
+ show: (owner) => method(dialog, SLOT_SHOW, protoShow)(owner),
108
+ resultPath: () => {
109
+ const itemOut = [null];
110
+ const gotItem = method(dialog, SLOT_GET_RESULT, protoGetResult)(itemOut);
111
+ if (gotItem < 0) return { hr: gotItem };
112
+ const item = itemOut[0];
113
+ try {
114
+ const nameOut = [null];
115
+ const gotName = method(item, SLOT_GET_DISPLAY_NAME, protoGetDisplayName)(SIGDN_FILESYSPATH, nameOut);
116
+ if (gotName < 0) return { hr: gotName };
117
+ const path = readUtf16(koffi, nameOut[0]);
118
+ coTaskMemFree(nameOut[0]);
119
+ return { hr: gotName, path };
120
+ } finally {
121
+ method(item, SLOT_RELEASE, protoRelease)();
122
+ }
123
+ },
124
+ release: () => {
125
+ method(dialog, SLOT_RELEASE, protoRelease)();
126
+ }
127
+ };
128
+ }
129
+ };
130
+ }
131
+
132
+ // src/win32-dialog-logic.ts
133
+ var HRESULT_CANCELLED = 2147943623 | 0;
134
+ var FOS_PICKFOLDERS = 32;
135
+ var FOS_FORCEFILESYSTEM = 64;
136
+ var FOS_NOCHANGEDIR = 8;
137
+ function check(hr, what) {
138
+ if (hr < 0) throw new Error(`${what} failed: HRESULT 0x${(hr >>> 0).toString(16)}`);
139
+ return hr;
140
+ }
141
+ function runFolderDialog(bindings, title2, onShowing) {
142
+ bindings.setThreadDpiAwareness();
143
+ check(bindings.coInitializeSta(), "CoInitializeEx");
144
+ try {
145
+ const dialog = bindings.createFolderDialog();
146
+ try {
147
+ check(dialog.setOptions(FOS_PICKFOLDERS | FOS_FORCEFILESYSTEM | FOS_NOCHANGEDIR), "SetOptions");
148
+ check(dialog.setTitle(title2), "SetTitle");
149
+ onShowing(bindings.currentThreadId());
150
+ const shown = dialog.show(bindings.foregroundWindow());
151
+ if (shown === HRESULT_CANCELLED) return null;
152
+ check(shown, "Show");
153
+ const result = dialog.resultPath();
154
+ check(result.hr, "GetResult");
155
+ return result.path;
156
+ } finally {
157
+ dialog.release();
158
+ }
159
+ } finally {
160
+ bindings.coUninitialize();
161
+ }
162
+ }
163
+
164
+ // src/win32-dialog-worker.ts
165
+ var title = process.env.DSH_DIALOG_TITLE ?? "";
166
+ if (title === "") throw new Error("win32-dialog-worker: DSH_DIALOG_TITLE is required");
167
+ if (process.send === void 0) throw new Error("win32-dialog-worker must run as a child process with an IPC channel");
168
+ var send = process.send.bind(process);
169
+ var post = (message) => {
170
+ send(message, () => {
171
+ if (process.connected) process.disconnect();
172
+ });
173
+ };
174
+ process.on("disconnect", () => process.exit(0));
175
+ void (async () => {
176
+ try {
177
+ const bindings = await loadWin32DialogBindings();
178
+ const path = runFolderDialog(bindings, title, (threadId) => {
179
+ post({ kind: "showing", threadId });
180
+ });
181
+ post({ kind: "done", path });
182
+ } catch (error) {
183
+ const message = error instanceof Error ? error.stack ?? error.message : String(error);
184
+ post({ kind: "error", message });
185
+ }
186
+ })();
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "deepseek-harness-win32-picker",
3
+ "version": "0.1.0",
4
+ "description": "Foreground-owned Windows folder picker for DeepSeek Harness",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/civilization-os/deepseek-harness-win32-picker.git"
8
+ },
9
+ "homepage": "https://github.com/civilization-os/deepseek-harness-win32-picker#readme",
10
+ "bugs": "https://github.com/civilization-os/deepseek-harness-win32-picker/issues",
11
+ "license": "MIT",
12
+ "type": "module",
13
+ "exports": {
14
+ ".": "./lib/index.js",
15
+ "./package.json": "./package.json"
16
+ },
17
+ "files": [
18
+ "lib",
19
+ "cordis.patch.yml",
20
+ "README.md",
21
+ "LICENSE"
22
+ ],
23
+ "dsh": {
24
+ "bundle": {
25
+ "patch": "./cordis.patch.yml"
26
+ }
27
+ },
28
+ "scripts": {
29
+ "build": "node scripts/build.js",
30
+ "test": "node --import tsx/esm --test tests/*.test.ts",
31
+ "typecheck": "tsc --noEmit",
32
+ "prepack": "pnpm run build"
33
+ },
34
+ "engines": {
35
+ "node": ">=22.19.0"
36
+ },
37
+ "packageManager": "pnpm@10.33.0",
38
+ "dependencies": {
39
+ "@deepseek-ai/dsh-client-ui-directory-picker-native": "0.0.1-rc.3",
40
+ "koffi": "^3.2.1"
41
+ },
42
+ "peerDependencies": {
43
+ "@deepseek-ai/cordis": ">=4.0.2"
44
+ },
45
+ "devDependencies": {
46
+ "@deepseek-ai/cordis": "4.0.2",
47
+ "@types/node": "^24.3.0",
48
+ "esbuild": "^0.28.2",
49
+ "tsx": "^4.19.2",
50
+ "typescript": "^5.9.2"
51
+ }
52
+ }