@xmoon76/dsh-pi-tui 0.5.8 → 0.5.9

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.
Files changed (77) hide show
  1. package/README.en.md +61 -25
  2. package/README.md +61 -25
  3. package/cordis.patch.yml +13 -0
  4. package/dist/acp-stdio.mjs +151 -0
  5. package/dist/{bootstrap-CMIjGyuk.mjs → bootstrap-CVyHGQDX.mjs} +21901 -6575
  6. package/dist/browser-CDUSHIIr.mjs +76 -0
  7. package/dist/builtins.mjs +2 -2
  8. package/dist/{client-bootstrap-BjGPc-DM.mjs → client-bootstrap-4UoeVIHE.mjs} +2488 -2734
  9. package/dist/client-runtime-BHBlVUf5.mjs +1376 -0
  10. package/dist/{daemon-launcher-Dult7Jxv.mjs → daemon-launcher-DxIgjBHW.mjs} +1549 -172
  11. package/dist/daemon-launcher.d.mts +85 -14
  12. package/dist/daemon-launcher.mjs +2 -2
  13. package/dist/{local-profile-daemon-admin-BmQSdzT0.mjs → diagnostics-Db5iVcuJ.mjs} +3 -90
  14. package/dist/{entry-control-DjNsE3I0.mjs → entry-control-BDLZgg4m.mjs} +1 -1
  15. package/dist/{extensions-B4uLpSTv.mjs → extensions-Dx7ncPNA.mjs} +1 -1
  16. package/dist/extensions.mjs +1 -1
  17. package/dist/handoff-BjoEy3f8.mjs +106 -0
  18. package/dist/history-search-limits-Cx2UvRC2.mjs +16 -0
  19. package/dist/history-search-remote-BHuoellG.mjs +113 -0
  20. package/dist/history-search-remote-BzXdvrxk.mjs +26 -0
  21. package/dist/history-search-seat-BcHJTpeB.mjs +639 -0
  22. package/dist/history-search-seat-rZcq0XV6.mjs +639 -0
  23. package/dist/{host-bootstrap-MVxks641.mjs → host-bootstrap-BfnufpnW.mjs} +37 -72
  24. package/dist/{host-foundation-probe-DMNTmNrH.mjs → host-foundation-probe-DlD8-N_Q.mjs} +2 -2
  25. package/dist/host-runtime.mjs +5611 -290
  26. package/dist/index.d.mts +13 -6
  27. package/dist/index.mjs +22334 -6695
  28. package/dist/installed-dsh-BjUiJSwR.mjs +142 -0
  29. package/dist/interaction-port-D1Yv9zgu.mjs +45 -0
  30. package/dist/local-acp-control-CC5z4Xbq.mjs +304 -0
  31. package/dist/local-acp-endpoint-D1jYdJdv.mjs +41 -0
  32. package/dist/local-acp-listener-Cmgb5M0H.mjs +9493 -0
  33. package/dist/local-acp-status-B_25Q6kU.mjs +101 -0
  34. package/dist/local-client.mjs +292 -63
  35. package/dist/local-daemon-control-BFJAC8Kg.mjs +2199 -0
  36. package/dist/local-daemon-control-Bm3imctD.mjs +2101 -0
  37. package/dist/{local-discovery-uOBfFq5j.mjs → local-discovery-BMhaGIiJ.mjs} +254 -544
  38. package/dist/{local-discovery-egN4_gsQ.mjs → local-discovery-Ba7_-NNC.mjs} +1 -1
  39. package/dist/{local-discovery-DOSsCh9q.mjs → local-discovery-QSbFpjK2.mjs} +301 -544
  40. package/dist/local-host.mjs +952 -501
  41. package/dist/local-profile-daemon-admin-otpm69R6.mjs +469 -0
  42. package/dist/{local-scope-DamiMqPd.mjs → local-scope-5DEKA_lW.mjs} +1023 -96
  43. package/dist/{local-transport-Iwo0mtu3.mjs → local-transport-DeWmdZ5E.mjs} +14 -3
  44. package/dist/{local-web-control-DMrjwCkl.mjs → local-web-control-Dny93N-r.mjs} +10 -7
  45. package/dist/{local-workspace-object-D06GL0UO.mjs → local-workspace-object-D0RVQt8U.mjs} +33 -9
  46. package/dist/model-selection-CYlqg2DV.mjs +83 -0
  47. package/dist/native-client-domains-Dg4srzYt.mjs +2 -0
  48. package/dist/native-client.d.mts +735 -0
  49. package/dist/native-client.mjs +3534 -0
  50. package/dist/{open-CmOBxSjN.mjs → open-QQva8-ar.mjs} +24 -20
  51. package/dist/{pi-tui-remote-contribution-Do8ECrUy.mjs → pi-tui-remote-contribution-565wiLWp.mjs} +741 -150
  52. package/dist/preferences.mjs +1 -1
  53. package/dist/{profile-preferences-migration-CThz4rHH.mjs → profile-preferences-migration-CNOWIdnr.mjs} +1 -1
  54. package/dist/{profile-preferences-migration-BfUGdPZx.mjs → profile-preferences-migration-IrnXcJWK.mjs} +10 -8
  55. package/dist/{prompt-sections-DXmjB58H.mjs → prompt-sections-Bi-9_Gr_.mjs} +28 -10
  56. package/dist/{prompt-sections-DUKmWb8g.mjs → prompt-sections-DFS1dqsY.mjs} +342 -56
  57. package/dist/{dist-BFgC-5tL.mjs → recall-scope-9Nuoto_i.mjs} +353 -1
  58. package/dist/rolldown-runtime-8H4AJuhK.mjs +14 -0
  59. package/dist/schema-CCLvDa7Q.mjs +177 -0
  60. package/dist/{schema-qE_P09zJ.mjs → schema-t97l3aK8.mjs} +56 -3
  61. package/dist/{session-C6tSs86s.mjs → session-Cs8iLCEx.mjs} +784 -342
  62. package/dist/{session-CstInGIA.mjs → session-EBRZF6Ow.mjs} +783 -341
  63. package/dist/session-create-facts-CkfG5DpQ.mjs +20 -0
  64. package/dist/{startup-CarQxWwi.d.mts → startup-Dti3Udne.d.mts} +30 -3
  65. package/dist/{startup-EG5UqIcd.mjs → startup-UtFQSDe_.mjs} +90 -15
  66. package/dist/startup.d.mts +2 -2
  67. package/dist/startup.mjs +1 -1
  68. package/dist/task-read-remote-DRtkXDrZ.mjs +1083 -0
  69. package/dist/{terminal-progress-source-CpfpQO_h.mjs → terminal-progress-source-VsczdXA-.mjs} +610 -332
  70. package/dist/{transcript-view-CuJYWkhp.mjs → transcript-view-B6vCnukn.mjs} +2096 -977
  71. package/dist/{transcript-view-C1YtJ49Y.mjs → transcript-view-DSSdE2vK.mjs} +2078 -651
  72. package/dist/write-failure-xNKczXH7.mjs +189 -0
  73. package/package.json +20 -3
  74. package/dist/local-acp-listener-B65J0Bx4.mjs +0 -3115
  75. package/dist/local-daemon-control-C14q9KnD.mjs +0 -1588
  76. package/dist/local-daemon-control-TCnERL7n.mjs +0 -1424
  77. package/dist/preset-BcWqOtY7.mjs +0 -46
@@ -7,57 +7,33 @@ import { fileURLToPath } from "node:url";
7
7
  import { createServer } from "node:net";
8
8
  import { userInfo } from "node:os";
9
9
  import { Buffer as Buffer$1 } from "node:buffer";
10
- /** `<sys/proc_info.h>`: PROC_PIDTBSDINFO. */
11
- const PROC_PIDTBSDINFO_FLAVOR = 3;
12
- /** XNU's private flavor 17 (PROC_PIDUNIQIDENTIFIERINFO), not in the public SDK. */
13
- const PROC_PIDUNIQIDENTIFIER_FLAVOR = 17;
14
- const LIBPROC = "/usr/lib/libproc.dylib";
15
- const LIBSYSTEM = "/usr/lib/libSystem.B.dylib";
16
- const ESRCH = 3;
17
- const EPERM = 1;
18
- const EACCES = 13;
19
- const EINVAL = 22;
20
- /** `kern.bootsessionuuid` capacity — the UUID text is 36 bytes plus NUL. */
21
- const BOOT_UUID_CAPACITY = 128;
10
+ //#region src/runtime/native-process/installed-dsh.ts
22
11
  /**
23
- * Classify one libproc read outcome into this repository's observation
24
- * taxonomy. `expectedBytes` is the ABI struct size this build was written for;
25
- * `actualBytes` is what the kernel reported. A positive-but-different reply is
26
- * an ABI mismatch even when the kernel also set an errno: the reply must never
27
- * be truncated or reinterpreted.
12
+ * The installed `@deepseek-ai/dsh` anchor and module-closure primitives shared
13
+ * by the platform-native loaders.
14
+ *
15
+ * A real Direct launcher entry (`process.argv[1]`) identifies its own installed
16
+ * DSH package and always wins over an inherited environment anchor: a shell or
17
+ * tool child of a Split Host inherits SPLIT_PROCESS_DSH_ANCHOR, but a Direct
18
+ * `dsh` CLI started from it must use the installation executing that CLI. A
19
+ * caller that already holds the official profile's `installAnchor` may supply
20
+ * it explicitly (the Direct composition does); only a Split Host/Client entry,
21
+ * whose argv[1] is the product's own local-host/local-client script, falls back
22
+ * to the launcher-verified SPLIT_PROCESS_DSH_ANCHOR. No NODE_PATH, profile
23
+ * node_modules or source tree is consulted.
24
+ *
25
+ * Module lookup must prove the resolved dependency belongs to its owner's
26
+ * installation closure: npm keeps sibling dependencies in the owner's nearest
27
+ * `node_modules`; pnpm keeps every package in a shared virtual store (`.mise`
28
+ * in the mise install and `.pnpm` in a project install). Any other ancestor
29
+ * `node_modules` is an accidental hoist and must not supply a dependency.
30
+ *
31
+ * @module runtime/native-process/installed-dsh
28
32
  */
29
- function classifyDarwinReadOutcome(expectedBytes, actualBytes, errno) {
30
- if (actualBytes === expectedBytes && expectedBytes > 0) return { kind: "ok" };
31
- if (actualBytes > 0) return {
32
- kind: "unknown",
33
- code: "ABI_UNSUPPORTED"
34
- };
35
- if (errno === ESRCH) return { kind: "gone" };
36
- if (errno === EPERM || errno === EACCES) return {
37
- kind: "unknown",
38
- code: "ACCESS_DENIED"
39
- };
40
- if (errno === EINVAL) return {
41
- kind: "unknown",
42
- code: "ABI_UNSUPPORTED"
43
- };
44
- return {
45
- kind: "unknown",
46
- code: "READ_FAILED"
47
- };
48
- }
49
- /** A 64-bit kernel counter as an exact decimal string (Koffi yields a BigInt
50
- * only when the value would lose precision as a JS number). */
51
- function decimal(value) {
52
- if (typeof value === "bigint") return value.toString(10);
53
- if (typeof value === "number" && Number.isSafeInteger(value)) return String(value);
54
- throw new Error(`expected an exact 64-bit integer, got ${String(value)}`);
55
- }
56
- let loaded;
57
33
  /** One installed `@deepseek-ai/dsh` manifest, or undefined when the path is
58
34
  * unreadable, malformed, or belongs to another package. The name check is
59
35
  * load-bearing: `createRequire` would otherwise walk into an unrelated ancestor
60
- * `node_modules` and silently borrow a Koffi copy that does not belong to the
36
+ * `node_modules` and silently borrow a dependency that does not belong to the
61
37
  * running DSH installation. */
62
38
  function installedDshManifest(path) {
63
39
  try {
@@ -72,17 +48,14 @@ function installedDshManifest(path) {
72
48
  }
73
49
  /**
74
50
  * The installed `@deepseek-ai/dsh/package.json` this process runs on.
75
- *
76
- * A real Direct launcher entry (`process.argv[1]`) identifies its own installed
77
- * DSH package and always wins over an inherited environment anchor: a shell or
78
- * tool child of a Split Host inherits SPLIT_PROCESS_DSH_ANCHOR, but a Direct
79
- * `dsh` CLI started from it must use the installation executing that CLI.
80
- * Only a Split Host/Client entry, whose argv[1] is the product's own
81
- * local-host/local-client script, falls back to the launcher-verified
82
- * SPLIT_PROCESS_DSH_ANCHOR. No NODE_PATH, profile node_modules or source tree
83
- * is consulted.
51
+ * @param explicitAnchor - an already-resolved official profile install anchor;
52
+ * when provided and valid it outranks the launcher and environment anchors.
84
53
  */
85
- function installedDshAnchor() {
54
+ function installedDshAnchor(explicitAnchor) {
55
+ if (explicitAnchor !== void 0 && explicitAnchor !== "") {
56
+ const provided = installedDshManifest(explicitAnchor);
57
+ if (provided !== void 0) return provided;
58
+ }
86
59
  const entry = process.argv[1];
87
60
  if (entry !== void 0) try {
88
61
  let dir = dirname(realpathSync(entry));
@@ -106,16 +79,11 @@ function nearestModuleRoot(packageDir) {
106
79
  dir = parent;
107
80
  }
108
81
  }
82
+ /** Whether `path` is `root` or below it. */
109
83
  function isInside(path, root) {
110
84
  return path === root || path.startsWith(`${root}${sep}`);
111
85
  }
112
- /** Prove a resolved dependency belongs to its owner's installation closure.
113
- *
114
- * npm keeps sibling dependencies in the owner's nearest `node_modules`. pnpm
115
- * keeps every package in a shared virtual store (`.mise` in the mise install
116
- * and `.pnpm` in a project install), with each package in its own
117
- * `<name>@<version>/node_modules` directory. Any other ancestor `node_modules`
118
- * is an accidental hoist and must not supply a dependency. */
86
+ /** Prove a resolved dependency belongs to its owner's installation closure. */
119
87
  function assertInstallClosure(ownerDir, dependencyDir, label) {
120
88
  const nearest = nearestModuleRoot(ownerDir);
121
89
  if (nearest !== void 0 && isInside(dependencyDir, nearest)) return;
@@ -125,7 +93,7 @@ function assertInstallClosure(ownerDir, dependencyDir, label) {
125
93
  if (parent === dir) break;
126
94
  dir = parent;
127
95
  }
128
- throw new Error(`native process identity: ${label} resolved outside the installed DSH module tree`);
96
+ throw new Error(`installed DSH module: ${label} resolved outside the installed DSH module tree`);
129
97
  }
130
98
  /** Read one JSON package manifest as an object, or undefined when unreadable. */
131
99
  function readManifestObject(path) {
@@ -141,7 +109,13 @@ function readManifestObject(path) {
141
109
  function assertDeclaredDependency(manifest, name, label) {
142
110
  const dependencies = manifest.dependencies;
143
111
  const declared = dependencies !== null && typeof dependencies === "object" && !Array.isArray(dependencies) ? dependencies[name] : void 0;
144
- if (typeof declared !== "string" || declared === "") throw new Error(`native process identity: ${label} does not declare ${name}`);
112
+ if (typeof declared !== "string" || declared === "") throw new Error(`installed DSH module: ${label} does not declare ${name}`);
113
+ }
114
+ /** Require one peer declaration from an owner manifest. */
115
+ function assertDeclaredPeerDependency(manifest, name, label) {
116
+ const peerDependencies = manifest.peerDependencies;
117
+ const declared = peerDependencies !== null && typeof peerDependencies === "object" && !Array.isArray(peerDependencies) ? peerDependencies[name] : void 0;
118
+ if (typeof declared !== "string" || declared === "") throw new Error(`installed DSH module: ${label} does not declare ${name} as a peer`);
145
119
  }
146
120
  /**
147
121
  * Resolve the Koffi entry owned by the running DSH installation:
@@ -152,7 +126,8 @@ function assertDeclaredDependency(manifest, name, label) {
152
126
  * The owner's declared dependency selects the implementation; this code does
153
127
  * not pin or compare a Koffi version, because the running DSH installation owns
154
128
  * that choice and an upgrade must not be rejected only for a different version
155
- * number. The ABI/struct-size checks in loadBridge decide actual compatibility.
129
+ * number. The ABI/struct-size checks in the platform bridge decide actual
130
+ * compatibility.
156
131
  */
157
132
  function resolveDshKoffi(anchor) {
158
133
  const manifest = installedDshManifest(anchor);
@@ -169,6 +144,870 @@ function resolveDshKoffi(anchor) {
169
144
  if (readManifestObject(join(dirname(koffiEntry), "package.json"))?.name !== "koffi") throw new Error("native process identity: the resolved koffi is not the koffi package");
170
145
  return koffiEntry;
171
146
  }
147
+ //#endregion
148
+ //#region src/runtime/native-process/win32.ts
149
+ /**
150
+ * Win32 native process identity, kernel seats, per-instance stop events and
151
+ * private object-security primitives.
152
+ *
153
+ * This module is the ONLY owner of the Win32 FFI layout for these operations.
154
+ * It lazily loads Koffi from the running DSH installation (the verified anchor
155
+ * -> `@deepseek-ai/dsh-subprocess-local` -> that package's own declared
156
+ * `koffi`), decodes exact kernel facts and never decides product policy.
157
+ *
158
+ * The module is imported on every platform (it is part of the native-process
159
+ * layer), but no DLL is loaded until a Win32 function is actually called.
160
+ *
161
+ * @module runtime/native-process/win32
162
+ */
163
+ const ERROR_INVALID_PARAMETER = 87;
164
+ const ERROR_ACCESS_DENIED = 5;
165
+ const ERROR_INVALID_HANDLE = 6;
166
+ const ERROR_ALREADY_EXISTS = 183;
167
+ const WAIT_OBJECT_0 = 0;
168
+ const WAIT_ABANDONED = 128;
169
+ const WAIT_TIMEOUT = 258;
170
+ const WAIT_FAILED = 4294967295;
171
+ const TOKEN_QUERY = 8;
172
+ const PIPE_UNLIMITED_INSTANCES = 255;
173
+ const NETWORK_SID = "S-1-5-2";
174
+ const LOCAL_SYSTEM_SID = "S-1-5-18";
175
+ const BUILTIN_ADMINISTRATORS_SID = "S-1-5-32-544";
176
+ const ACCESS_ALLOWED_ACE_TYPE = 0;
177
+ const ACCESS_DENIED_ACE_TYPE = 1;
178
+ const INVALID_HANDLE_VALUE = 18446744073709551615n;
179
+ const FILE_ATTRIBUTE_DIRECTORY = 16;
180
+ const FILE_ATTRIBUTE_REPARSE_POINT = 1024;
181
+ const FILE_SHARE_ALL = 7;
182
+ const OPEN_EXISTING = 3;
183
+ const DRIVE_FIXED = 3;
184
+ const SE_FILE_OBJECT = 1;
185
+ const SE_KERNEL_OBJECT = 6;
186
+ const OBJECT_INHERIT_ACE = 1;
187
+ const CONTAINER_INHERIT_ACE = 2;
188
+ const SE_DACL_PRESENT = 4;
189
+ const SDDL_REVISION_1 = 1;
190
+ let loaded$1;
191
+ function bind(context, library, name, result, args) {
192
+ return library.func("__stdcall", name, result, [...args]);
193
+ }
194
+ function loadBridge$1() {
195
+ if (loaded$1 !== void 0) return loaded$1;
196
+ let result;
197
+ try {
198
+ const anchor = installedDshAnchor();
199
+ if (anchor === void 0) throw new Error("native win32: no installed DSH anchor");
200
+ const koffi = createRequire(import.meta.url)(resolveDshKoffi(anchor));
201
+ const kernel32 = koffi.load("kernel32.dll");
202
+ const advapi32 = koffi.load("advapi32.dll");
203
+ const context = {
204
+ koffi,
205
+ kernel32,
206
+ advapi32
207
+ };
208
+ result = {
209
+ ok: true,
210
+ bridge: {
211
+ koffi,
212
+ closeHandle: bind(context, kernel32, "CloseHandle", "int", ["void *"]),
213
+ getLastError: bind(context, kernel32, "GetLastError", "uint32", []),
214
+ setLastError: bind(context, kernel32, "SetLastError", "void", ["uint32"]),
215
+ openProcess: bind(context, kernel32, "OpenProcess", "void *", [
216
+ "uint32",
217
+ "bool",
218
+ "uint32"
219
+ ]),
220
+ getProcessTimes: bind(context, kernel32, "GetProcessTimes", "int", [
221
+ "void *",
222
+ "void *",
223
+ "void *",
224
+ "void *",
225
+ "void *"
226
+ ]),
227
+ waitForSingleObject: bind(context, kernel32, "WaitForSingleObject", "uint32", ["void *", "uint32"]),
228
+ waitForMultipleObjects: bind(context, kernel32, "WaitForMultipleObjects", "uint32", [
229
+ "uint32",
230
+ "uintptr_t *",
231
+ "int",
232
+ "uint32"
233
+ ]),
234
+ openProcessToken: bind(context, kernel32, "OpenProcessToken", "int", [
235
+ "void *",
236
+ "uint32",
237
+ "void *"
238
+ ]),
239
+ getTokenInformation: bind(context, advapi32, "GetTokenInformation", "int", [
240
+ "void *",
241
+ "uint32",
242
+ "void *",
243
+ "uint32",
244
+ "void *"
245
+ ]),
246
+ createMutexW: bind(context, kernel32, "CreateMutexW", "void *", [
247
+ "void *",
248
+ "int",
249
+ "const char16_t *"
250
+ ]),
251
+ releaseMutex: bind(context, kernel32, "ReleaseMutex", "int", ["void *"]),
252
+ createEventW: bind(context, kernel32, "CreateEventW", "void *", [
253
+ "void *",
254
+ "int",
255
+ "int",
256
+ "const char16_t *"
257
+ ]),
258
+ openEventW: bind(context, kernel32, "OpenEventW", "void *", [
259
+ "uint32",
260
+ "int",
261
+ "const char16_t *"
262
+ ]),
263
+ setEvent: bind(context, kernel32, "SetEvent", "int", ["void *"]),
264
+ createNamedPipeW: bind(context, kernel32, "CreateNamedPipeW", "void *", [
265
+ "const char16_t *",
266
+ "uint32",
267
+ "uint32",
268
+ "uint32",
269
+ "uint32",
270
+ "uint32",
271
+ "uint32",
272
+ "void *"
273
+ ]),
274
+ createDirectoryW: bind(context, kernel32, "CreateDirectoryW", "int", ["const char16_t *", "void *"]),
275
+ createFileW: bind(context, kernel32, "CreateFileW", "void *", [
276
+ "const char16_t *",
277
+ "uint32",
278
+ "uint32",
279
+ "void *",
280
+ "uint32",
281
+ "uint32",
282
+ "void *"
283
+ ]),
284
+ getFileAttributesW: bind(context, kernel32, "GetFileAttributesW", "uint32", ["const char16_t *"]),
285
+ getDriveTypeW: bind(context, kernel32, "GetDriveTypeW", "uint32", ["const char16_t *"]),
286
+ getVolumeInformationW: bind(context, kernel32, "GetVolumeInformationW", "int", [
287
+ "const char16_t *",
288
+ "void *",
289
+ "uint32",
290
+ "void *",
291
+ "void *",
292
+ "void *",
293
+ "void *",
294
+ "uint32"
295
+ ]),
296
+ getSystemDirectoryW: bind(context, kernel32, "GetSystemDirectoryW", "uint32", ["void *", "uint32"]),
297
+ convertStringSecurityDescriptor: bind(context, advapi32, "ConvertStringSecurityDescriptorToSecurityDescriptorW", "int", [
298
+ "const char16_t *",
299
+ "uint32",
300
+ "void *",
301
+ "void *"
302
+ ]),
303
+ getSecurityDescriptorDacl: bind(context, advapi32, "GetSecurityDescriptorDacl", "int", [
304
+ "void *",
305
+ "void *",
306
+ "void *",
307
+ "void *"
308
+ ]),
309
+ setSecurityInfo: bind(context, advapi32, "SetSecurityInfo", "uint32", [
310
+ "void *",
311
+ "int",
312
+ "uint32",
313
+ "void *",
314
+ "void *",
315
+ "void *",
316
+ "void *"
317
+ ]),
318
+ getSecurityInfo: bind(context, advapi32, "GetSecurityInfo", "uint32", [
319
+ "void *",
320
+ "int",
321
+ "uint32",
322
+ "void *",
323
+ "void *",
324
+ "void *",
325
+ "void *",
326
+ "void *"
327
+ ]),
328
+ getSecurityDescriptorLength: bind(context, advapi32, "GetSecurityDescriptorLength", "uint32", ["void *"]),
329
+ getSecurityDescriptorControl: bind(context, advapi32, "GetSecurityDescriptorControl", "int", [
330
+ "void *",
331
+ "void *",
332
+ "void *"
333
+ ]),
334
+ localFree: bind(context, kernel32, "LocalFree", "void *", ["void *"])
335
+ }
336
+ };
337
+ } catch {
338
+ result = {
339
+ ok: false,
340
+ code: "NATIVE_UNAVAILABLE"
341
+ };
342
+ }
343
+ loaded$1 = result;
344
+ return result;
345
+ }
346
+ /** `GetLastError()` from the live bridge, or 0 when the native addon is unavailable. */
347
+ function lastError(bridge) {
348
+ return bridge.getLastError();
349
+ }
350
+ /** A wide (UTF-16RO) Koffi string is passed through the `const char16_t *` type. */
351
+ function parseSid(bytes, offset) {
352
+ const revision = bytes[offset];
353
+ const count = bytes[offset + 1];
354
+ let authority = 0n;
355
+ for (let i = 0; i < 6; i += 1) authority = authority << 8n | BigInt(bytes[offset + 2 + i]);
356
+ let value = `S-${revision}-${authority}`;
357
+ for (let i = 0; i < count; i += 1) value += `-${bytes.readUInt32LE(offset + 8 + i * 4)}`;
358
+ return value;
359
+ }
360
+ function filetimeFrom(buffer, offset) {
361
+ const low = buffer.readUInt32LE(offset);
362
+ const high = buffer.readUInt32LE(offset + 4);
363
+ return (BigInt(high) << 32n | BigInt(low)).toString(10);
364
+ }
365
+ /** The real Windows system directory reported by kernel32, never an environment value. */
366
+ function win32SystemDirectory() {
367
+ const load = loadBridge$1();
368
+ if (!load.ok) return void 0;
369
+ const buffer = Buffer.alloc(65536);
370
+ const length = load.bridge.getSystemDirectoryW(buffer, Math.floor(buffer.length / 2));
371
+ if (length === 0 || length >= Math.floor(buffer.length / 2)) return void 0;
372
+ const value = buffer.toString("utf16le", 0, length * 2).replace(/\0.*$/u, "");
373
+ return value === "" ? void 0 : value;
374
+ }
375
+ /** The SID of the token's real user (TokenUser), never a username or environment value. */
376
+ function win32CurrentTokenSid() {
377
+ const load = loadBridge$1();
378
+ if (!load.ok) return void 0;
379
+ const bridge = load.bridge;
380
+ const processHandle = bridge.openProcess(1052672, false, process.pid);
381
+ if (processHandle === null || processHandle === void 0) return void 0;
382
+ const token = Buffer.alloc(8);
383
+ if (!bridge.openProcessToken(processHandle, TOKEN_QUERY, token)) {
384
+ bridge.closeHandle(processHandle);
385
+ return;
386
+ }
387
+ const tokenHandle = token.readBigUInt64LE(0);
388
+ try {
389
+ const needed = Buffer.alloc(4);
390
+ bridge.getTokenInformation(tokenHandle, 1, Buffer.alloc(0), 0, needed);
391
+ const length = needed.readUInt32LE(0);
392
+ if (length === 0) return void 0;
393
+ const info = Buffer.alloc(length);
394
+ if (!bridge.getTokenInformation(tokenHandle, 1, info, length, needed)) return void 0;
395
+ const sidAddress = info.readBigUInt64LE(0);
396
+ return parseSid(info, Number(sidAddress - bridge.koffi.address(info)));
397
+ } finally {
398
+ bridge.closeHandle(tokenHandle);
399
+ bridge.closeHandle(processHandle);
400
+ }
401
+ }
402
+ /** Read the current kernel identity of one pid through Win32. */
403
+ function readWin32KernelProcessObservation(pid) {
404
+ if (process.platform !== "win32") return {
405
+ kind: "unknown",
406
+ code: "NATIVE_UNAVAILABLE"
407
+ };
408
+ const opened = openWin32Process(pid);
409
+ if (opened.kind !== "ok") return opened;
410
+ try {
411
+ return {
412
+ kind: "alive",
413
+ identity: opened.capture.identity
414
+ };
415
+ } finally {
416
+ closeWin32Handle(opened.capture.handle);
417
+ }
418
+ }
419
+ /** Open a process handle and return its exact identity after one live observation. */
420
+ function openWin32Process(pid) {
421
+ const load = loadBridge$1();
422
+ if (!load.ok) return {
423
+ kind: "unknown",
424
+ code: load.code
425
+ };
426
+ const bridge = load.bridge;
427
+ const handle = bridge.openProcess(1052672, false, pid);
428
+ if (!handle) {
429
+ const code = lastError(bridge);
430
+ if (code === ERROR_INVALID_PARAMETER) return { kind: "gone" };
431
+ if (code === ERROR_ACCESS_DENIED) return {
432
+ kind: "unknown",
433
+ code: "ACCESS_DENIED"
434
+ };
435
+ return {
436
+ kind: "unknown",
437
+ code: "READ_FAILED"
438
+ };
439
+ }
440
+ const fail = (code) => {
441
+ bridge.closeHandle(handle);
442
+ return {
443
+ kind: "unknown",
444
+ code
445
+ };
446
+ };
447
+ try {
448
+ const times = Buffer.alloc(32);
449
+ if (!bridge.getProcessTimes(handle, times, Buffer.alloc(32), Buffer.alloc(32), Buffer.alloc(32))) return fail(lastError(bridge) === ERROR_ACCESS_DENIED ? "ACCESS_DENIED" : "READ_FAILED");
450
+ const token = Buffer.alloc(8);
451
+ if (!bridge.openProcessToken(handle, TOKEN_QUERY, token)) return fail(lastError(bridge) === ERROR_ACCESS_DENIED ? "ACCESS_DENIED" : "READ_FAILED");
452
+ const tokenHandle = token.readBigUInt64LE(0);
453
+ let sid;
454
+ try {
455
+ const needed = Buffer.alloc(4);
456
+ bridge.getTokenInformation(tokenHandle, 1, Buffer.alloc(0), 0, needed);
457
+ const length = needed.readUInt32LE(0);
458
+ if (length === 0) return fail("READ_FAILED");
459
+ const info = Buffer.alloc(length);
460
+ if (!bridge.getTokenInformation(tokenHandle, 1, info, length, needed)) return fail("READ_FAILED");
461
+ const sidAddress = info.readBigUInt64LE(0);
462
+ sid = parseSid(info, Number(sidAddress - bridge.koffi.address(info)));
463
+ } finally {
464
+ bridge.closeHandle(tokenHandle);
465
+ }
466
+ if (sid === void 0) return fail("READ_FAILED");
467
+ const wait = bridge.waitForSingleObject(handle, 0);
468
+ if (wait === WAIT_OBJECT_0) {
469
+ bridge.closeHandle(handle);
470
+ return { kind: "gone" };
471
+ }
472
+ if (wait !== WAIT_TIMEOUT) return fail("READ_FAILED");
473
+ return {
474
+ kind: "ok",
475
+ capture: {
476
+ handle,
477
+ identity: {
478
+ platform: "win32",
479
+ pid,
480
+ ownerSid: sid,
481
+ creationFiletime: filetimeFrom(times, 0)
482
+ }
483
+ }
484
+ };
485
+ } catch {
486
+ bridge.closeHandle(handle);
487
+ return {
488
+ kind: "unknown",
489
+ code: "READ_FAILED"
490
+ };
491
+ }
492
+ }
493
+ /** Close one Win32 handle; callers track ownership exactly once. */
494
+ function closeWin32Handle(handle) {
495
+ const load = loadBridge$1();
496
+ if (!load.ok) return;
497
+ load.bridge.closeHandle(handle);
498
+ }
499
+ /** Wait for one held process handle to become terminal within a bound. */
500
+ async function waitWin32Handle(handle, timeoutMs) {
501
+ const load = loadBridge$1();
502
+ if (!load.ok) return {
503
+ kind: "failed",
504
+ code: WAIT_FAILED
505
+ };
506
+ return await new Promise((resolve) => {
507
+ load.bridge.waitForSingleObject.async(handle, timeoutMs, (error, code) => {
508
+ if (error !== null) resolve({
509
+ kind: "failed",
510
+ code: WAIT_FAILED
511
+ });
512
+ else if (code === WAIT_OBJECT_0) resolve({
513
+ kind: "terminal",
514
+ code
515
+ });
516
+ else if (code === WAIT_TIMEOUT) resolve({
517
+ kind: "timeout",
518
+ code
519
+ });
520
+ else resolve({
521
+ kind: "failed",
522
+ code
523
+ });
524
+ });
525
+ });
526
+ }
527
+ /** Read the security descriptor of one open kernel/file handle. */
528
+ function readSecurityInfo(handle, objectType) {
529
+ const load = loadBridge$1();
530
+ if (!load.ok) return void 0;
531
+ const bridge = load.bridge;
532
+ const owner = Buffer.alloc(8);
533
+ const group = Buffer.alloc(8);
534
+ const dacl = Buffer.alloc(8);
535
+ const sacl = Buffer.alloc(8);
536
+ const sd = Buffer.alloc(8);
537
+ if (bridge.getSecurityInfo(handle, objectType, 5, owner, group, dacl, sacl, sd) !== 0) return void 0;
538
+ if (sd.readBigUInt64LE(0) === 0n) return void 0;
539
+ const sdPtr = sd.readBigUInt64LE(0);
540
+ try {
541
+ const length = bridge.getSecurityDescriptorLength(sdPtr);
542
+ if (length === 0) return void 0;
543
+ const bytes = Buffer.from(bridge.koffi.decode(sdPtr, "uint8", length));
544
+ const control = Buffer.alloc(2);
545
+ const revision = Buffer.alloc(4);
546
+ if (!bridge.getSecurityDescriptorControl(sdPtr, control, revision)) return void 0;
547
+ const flags = control.readUInt16LE(0);
548
+ const ownerOffset = bytes.readUInt32LE(4);
549
+ const daclOffset = bytes.readUInt32LE(16);
550
+ const aces = [];
551
+ if (daclOffset !== 0) {
552
+ const aceCount = bytes.readUInt16LE(daclOffset + 4);
553
+ let offset = daclOffset + 8;
554
+ for (let i = 0; i < aceCount; i += 1) {
555
+ const type = bytes[offset];
556
+ const aceFlags = bytes[offset + 1];
557
+ const size = bytes.readUInt16LE(offset + 2);
558
+ const mask = bytes.readUInt32LE(offset + 4);
559
+ aces.push({
560
+ sid: parseSid(bytes, offset + 8),
561
+ mask,
562
+ type,
563
+ flags: aceFlags
564
+ });
565
+ offset += size;
566
+ }
567
+ }
568
+ return {
569
+ ownerSid: ownerOffset === 0 ? null : parseSid(bytes, ownerOffset),
570
+ daclPresent: (flags & SE_DACL_PRESENT) !== 0,
571
+ daclNull: daclOffset === 0,
572
+ aces
573
+ };
574
+ } finally {
575
+ bridge.localFree(sdPtr);
576
+ }
577
+ }
578
+ /** Turn one SDDL into a SECURITY_ATTRIBUTES buffer for a new kernel object. */
579
+ function securityAttributesForSddl(bridge, sddl) {
580
+ const sd = Buffer.alloc(8);
581
+ const size = Buffer.alloc(4);
582
+ if (!bridge.convertStringSecurityDescriptor(sddl, SDDL_REVISION_1, sd, size)) throw new Error(`native win32: invalid security descriptor (${String(lastError(bridge))})`);
583
+ const sdPtr = sd.readBigUInt64LE(0);
584
+ const attributes = Buffer.alloc(24);
585
+ attributes.writeUInt32LE(24, 0);
586
+ attributes.writeBigUInt64LE(sd.readBigUInt64LE(0), 8);
587
+ attributes.writeUInt32LE(0, 16);
588
+ return {
589
+ attributes,
590
+ sd: sdPtr
591
+ };
592
+ }
593
+ /**
594
+ * The ACL contract for an EXISTING private product object: owned by the current
595
+ * SID, with a present non-null DACL that grants only to the current SID or to
596
+ * LocalSystem / BUILTIN Administrators (outside the ordinary-account threat
597
+ * model). Deny ACEs never widen access. ACE count, order, protected bit and
598
+ * explicit-vs-inherited representation are ordinary ACL representations, not a
599
+ * security boundary. An ACE type this reader cannot interpret is not proof of
600
+ * safety, so it fails closed.
601
+ */
602
+ function isOwnerPrivateAcl(view, sid) {
603
+ if (view === void 0 || !view.daclPresent || view.daclNull || view.ownerSid !== sid) return false;
604
+ for (const ace of view.aces) {
605
+ if (ace.type === ACCESS_DENIED_ACE_TYPE) continue;
606
+ if (ace.type !== ACCESS_ALLOWED_ACE_TYPE) return false;
607
+ if (ace.sid !== sid && ace.sid !== LOCAL_SYSTEM_SID && ace.sid !== BUILTIN_ADMINISTRATORS_SID) return false;
608
+ }
609
+ return true;
610
+ }
611
+ /** A private directory must additionally pass a current-SID grant to ordinary
612
+ * files and subdirectories. OI/CI can be distributed across multiple ACEs;
613
+ * inherit-only entries still express child inheritance and are not treated as
614
+ * proof of current-directory access. Actual OS access decides usability. */
615
+ function isOwnerPrivateDirectoryAcl(view, sid) {
616
+ if (!isOwnerPrivateAcl(view, sid)) return false;
617
+ let objectInherit = false;
618
+ let containerInherit = false;
619
+ for (const ace of view.aces) {
620
+ if (ace.type !== ACCESS_ALLOWED_ACE_TYPE || ace.sid !== sid) continue;
621
+ objectInherit ||= (ace.flags & OBJECT_INHERIT_ACE) !== 0;
622
+ containerInherit ||= (ace.flags & CONTAINER_INHERIT_ACE) !== 0;
623
+ }
624
+ return objectInherit && containerInherit;
625
+ }
626
+ /** A held named mutex seat with one idempotent release. */
627
+ var NamedMutexSeat = class {
628
+ handle;
629
+ bridge;
630
+ name;
631
+ constructor(bridge, handle, name) {
632
+ this.bridge = bridge;
633
+ this.handle = handle;
634
+ this.name = name;
635
+ }
636
+ assertCurrent() {
637
+ if (this.handle === void 0) throw new Error(`native win32: seat ${this.name} is already closed`);
638
+ }
639
+ async close() {
640
+ const handle = this.handle;
641
+ if (handle === void 0) return;
642
+ this.handle = void 0;
643
+ this.bridge.releaseMutex(handle);
644
+ this.bridge.closeHandle(handle);
645
+ }
646
+ };
647
+ /**
648
+ * Acquire one named `Global\` mutex seat. `conflictCode` is thrown when another
649
+ * live process holds it. A newly created object gets the supplied protected
650
+ * descriptor; only an already existing object needs its descriptor proved
651
+ * before this process adopts it.
652
+ */
653
+ async function acquireWin32KernelSeat(name, conflictCode) {
654
+ const load = loadBridge$1();
655
+ if (!load.ok) throw new Error(`native win32: ${load.code}`);
656
+ const bridge = load.bridge;
657
+ const sid = win32CurrentTokenSid();
658
+ if (sid === void 0) throw new Error("native win32: the current token SID is unavailable");
659
+ const security = securityAttributesForSddl(bridge, `D:P(A;;GA;;;${sid})`);
660
+ let handle;
661
+ let createError = 0;
662
+ try {
663
+ bridge.setLastError(0);
664
+ handle = bridge.createMutexW(security.attributes, 0, name);
665
+ createError = lastError(bridge);
666
+ } finally {
667
+ bridge.localFree(security.sd);
668
+ }
669
+ if (handle === null || handle === void 0) {
670
+ if (createError === ERROR_ACCESS_DENIED) throw new Error("native win32: the named seat is owned by another account");
671
+ if (createError === ERROR_INVALID_HANDLE) throw new Error("native win32: the named seat is another object type");
672
+ throw new Error(`native win32: the named seat could not be created (${String(createError)})`);
673
+ }
674
+ try {
675
+ if (createError === ERROR_ALREADY_EXISTS && !isOwnerPrivateAcl(readSecurityInfo(handle, SE_KERNEL_OBJECT), sid)) throw new Error("native win32: the named seat has a foreign or broad security descriptor");
676
+ const wait = bridge.waitForSingleObject(handle, 0);
677
+ if (wait === WAIT_TIMEOUT) throw Object.assign(/* @__PURE__ */ new Error("native win32: the named seat is already held"), { code: conflictCode });
678
+ if (wait !== WAIT_OBJECT_0 && wait !== WAIT_ABANDONED) throw new Error(`native win32: the named seat wait failed (${String(wait)})`);
679
+ return new NamedMutexSeat(bridge, handle, name);
680
+ } catch (error) {
681
+ bridge.closeHandle(handle);
682
+ throw error;
683
+ }
684
+ }
685
+ /** The deterministic Host/admin mutex name: no secret, bound to scopeId only. */
686
+ function win32SeatName(scopeId, purpose) {
687
+ return `Global\\dsh-pi-tui-${purpose}-${scopeId.slice(0, 48)}`;
688
+ }
689
+ /** The deterministic per-instance stop event name. */
690
+ function win32StopEventName(scopeId, instanceId) {
691
+ return `Global\\dsh-pi-tui-stop-${scopeId.slice(0, 24)}-${instanceId}`;
692
+ }
693
+ /** Open one control-side per-instance stop event and verify its existing-object private boundary. */
694
+ function openWin32StopSignal(scopeId, instanceId) {
695
+ const load = loadBridge$1();
696
+ if (!load.ok) throw new Error(`native win32: ${load.code}`);
697
+ const bridge = load.bridge;
698
+ const sid = win32CurrentTokenSid();
699
+ if (sid === void 0) throw new Error("native win32: the current token SID is unavailable");
700
+ const handle = bridge.openEventW(1179650, 0, win32StopEventName(scopeId, instanceId));
701
+ if (handle === null || handle === void 0) {
702
+ const code = lastError(bridge);
703
+ if (code === 5) throw new Error("native win32: the stop event is owned by another account");
704
+ throw new Error(`native win32: the stop event is unavailable (${String(code)})`);
705
+ }
706
+ if (!isOwnerPrivateAcl(readSecurityInfo(handle, SE_KERNEL_OBJECT), sid)) {
707
+ bridge.closeHandle(handle);
708
+ throw new Error("native win32: the stop event has a foreign or broad security descriptor");
709
+ }
710
+ let set = false;
711
+ let closed = false;
712
+ return {
713
+ setOnce() {
714
+ if (set || closed) return;
715
+ set = true;
716
+ if (!bridge.setEvent(handle)) throw new Error(`native win32: SetEvent failed (${String(lastError(bridge))})`);
717
+ },
718
+ close() {
719
+ if (closed) return;
720
+ closed = true;
721
+ bridge.closeHandle(handle);
722
+ }
723
+ };
724
+ }
725
+ /**
726
+ * Create the Host-side per-instance stop event pair and start one asynchronous
727
+ * native wait. `stopped` resolves only on the stop event; cancellation wakes the
728
+ * native wait without resolving it and is used by `close()`.
729
+ */
730
+ function createWin32StopWaiter(scopeId, instanceId) {
731
+ const load = loadBridge$1();
732
+ if (!load.ok) throw new Error(`native win32: ${load.code}`);
733
+ const bridge = load.bridge;
734
+ const sid = win32CurrentTokenSid();
735
+ if (sid === void 0) throw new Error("native win32: the current token SID is unavailable");
736
+ const security = securityAttributesForSddl(bridge, `D:P(A;;GA;;;${sid})`);
737
+ const eventName = win32StopEventName(scopeId, instanceId);
738
+ let stopHandle;
739
+ let cancelHandle;
740
+ let stopExists = false;
741
+ let createError = 0;
742
+ let cancelError = 0;
743
+ try {
744
+ bridge.setLastError(0);
745
+ stopHandle = bridge.createEventW(security.attributes, 0, 0, eventName);
746
+ createError = lastError(bridge);
747
+ stopExists = stopHandle !== null && createError === ERROR_ALREADY_EXISTS;
748
+ bridge.setLastError(0);
749
+ cancelHandle = bridge.createEventW(null, 0, 0, null);
750
+ cancelError = cancelHandle === null ? lastError(bridge) : 0;
751
+ } finally {
752
+ bridge.localFree(security.sd);
753
+ }
754
+ if (stopExists) {
755
+ if (stopHandle !== null && stopHandle !== void 0) bridge.closeHandle(stopHandle);
756
+ if (cancelHandle !== null && cancelHandle !== void 0) bridge.closeHandle(cancelHandle);
757
+ throw new Error("native win32: a stale per-instance stop event already exists");
758
+ }
759
+ if (stopHandle === null || stopHandle === void 0 || cancelHandle === null || cancelHandle === void 0) {
760
+ if (stopHandle !== null && stopHandle !== void 0) bridge.closeHandle(stopHandle);
761
+ if (cancelHandle !== null && cancelHandle !== void 0) bridge.closeHandle(cancelHandle);
762
+ throw new Error(`native win32: the per-instance stop event could not be created (${String(stopHandle === null ? createError : cancelError)})`);
763
+ }
764
+ const forcedFailure = process.env.SPLIT_PROCESS_HOST_FORCE_NATIVE_WAITER_FAILURE === "1";
765
+ let stopResolve;
766
+ let stopReject;
767
+ const stopped = new Promise((resolve, reject) => {
768
+ stopResolve = resolve;
769
+ stopReject = reject;
770
+ });
771
+ let closed = false;
772
+ let handlesClosed = false;
773
+ const closeHandles = () => {
774
+ if (handlesClosed) return;
775
+ handlesClosed = true;
776
+ bridge.closeHandle(stopHandle);
777
+ bridge.closeHandle(cancelHandle);
778
+ };
779
+ const loopSettled = (async () => {
780
+ try {
781
+ if (forcedFailure) throw new Error("native win32: qualification forced stop-waiter failure");
782
+ for (;;) {
783
+ const code = await new Promise((resolve, reject) => {
784
+ bridge.waitForMultipleObjects.async(2, [stopHandle, cancelHandle], 0, 4294967295, (error, value) => {
785
+ if (error !== null) reject(error);
786
+ else resolve(value);
787
+ });
788
+ });
789
+ if (code === WAIT_OBJECT_0) {
790
+ stopResolve?.();
791
+ return;
792
+ }
793
+ if (code === 1) {
794
+ if (closed) return;
795
+ continue;
796
+ }
797
+ throw new Error(`native win32: the stop-event wait returned ${String(code)}`);
798
+ }
799
+ } catch (error) {
800
+ stopReject?.(error instanceof Error ? error : new Error(String(error)));
801
+ throw error;
802
+ }
803
+ })().catch(() => {});
804
+ return {
805
+ eventName,
806
+ stopped,
807
+ async close() {
808
+ if (closed) {
809
+ await loopSettled;
810
+ closeHandles();
811
+ return;
812
+ }
813
+ closed = true;
814
+ bridge.setEvent(cancelHandle);
815
+ await loopSettled;
816
+ closeHandles();
817
+ }
818
+ };
819
+ }
820
+ /** Whether a path is on a local fixed NTFS volume (the PR2 supported domain). */
821
+ function isWin32LocalFixedNtfs(path) {
822
+ const load = loadBridge$1();
823
+ if (!load.ok) return false;
824
+ const bridge = load.bridge;
825
+ const root = path.slice(0, 2) + "\\";
826
+ if (!/^[A-Za-z]:\\/u.test(root)) return false;
827
+ if (bridge.getDriveTypeW(root) !== DRIVE_FIXED) return false;
828
+ const fsNameChars = 32;
829
+ const fsName = Buffer.alloc(64);
830
+ const flags = Buffer.alloc(4);
831
+ return bridge.getVolumeInformationW(root, null, 0, null, null, flags, fsName, fsNameChars) && fsName.toString("utf16le").replace(/\0.*$/u, "").toUpperCase() === "NTFS";
832
+ }
833
+ /** Read Win32 file attributes; undefined when the path is absent or unreadable. */
834
+ function win32FileAttributes(path) {
835
+ const load = loadBridge$1();
836
+ if (!load.ok) return void 0;
837
+ const value = load.bridge.getFileAttributesW(path) >>> 0;
838
+ if (value === 4294967295) return void 0;
839
+ return {
840
+ directory: (value & FILE_ATTRIBUTE_DIRECTORY) !== 0,
841
+ reparse: (value & FILE_ATTRIBUTE_REPARSE_POINT) !== 0
842
+ };
843
+ }
844
+ /** Open one existing path for a security-descriptor read without following a final reparse. */
845
+ function openExistingPath(path) {
846
+ const load = loadBridge$1();
847
+ if (!load.ok) return void 0;
848
+ const handle = load.bridge.createFileW(path, 131200, FILE_SHARE_ALL, null, OPEN_EXISTING, 35651584, null);
849
+ return handle === null || handle === void 0 ? void 0 : handle;
850
+ }
851
+ /** Verify one existing product directory is a real, non-reparse, private object. */
852
+ function win32PrivateDirectorySafe(path) {
853
+ const attributes = win32FileAttributes(path);
854
+ if (attributes === void 0 || !attributes.directory || attributes.reparse) return false;
855
+ const handle = openExistingPath(path);
856
+ if (handle === void 0) return false;
857
+ try {
858
+ const sid = win32CurrentTokenSid();
859
+ return sid !== void 0 && isOwnerPrivateDirectoryAcl(readSecurityInfo(handle, SE_FILE_OBJECT), sid);
860
+ } finally {
861
+ closeWin32Handle(handle);
862
+ }
863
+ }
864
+ /** Verify one existing product file is a real, non-reparse, private object. */
865
+ function win32PrivateFileSafe(path) {
866
+ const attributes = win32FileAttributes(path);
867
+ if (attributes === void 0 || attributes.directory || attributes.reparse) return false;
868
+ const handle = openExistingPath(path);
869
+ if (handle === void 0) return false;
870
+ try {
871
+ const sid = win32CurrentTokenSid();
872
+ return sid !== void 0 && isOwnerPrivateAcl(readSecurityInfo(handle, SE_FILE_OBJECT), sid);
873
+ } finally {
874
+ closeWin32Handle(handle);
875
+ }
876
+ }
877
+ /** Classify one existing product file before any write/append/cleanup. Only a
878
+ * true missing path is `missing`; every other lstat/open/type/ACL failure is
879
+ * `unsafe` so a caller cannot treat a dangling link or unreadable target as
880
+ * absent. */
881
+ function win32PrivateFileStatus(path) {
882
+ let info;
883
+ try {
884
+ info = lstatSync(path);
885
+ } catch (error) {
886
+ return error.code === "ENOENT" ? "missing" : "unsafe";
887
+ }
888
+ if (info.isSymbolicLink() || !info.isFile()) return "unsafe";
889
+ return win32PrivateFileSafe(path) ? "private" : "unsafe";
890
+ }
891
+ /** Create one directory with a protected owner-only DACL; an already existing
892
+ * directory is reused only after its current owner SID, DACL and child-inherit
893
+ * grants are proved. Created files inherit the directory's ACL and are checked
894
+ * by the shared private-file predicate; the file itself need not carry the
895
+ * protected bit. */
896
+ function ensureWin32PrivateDirectory(path) {
897
+ const load = loadBridge$1();
898
+ if (!load.ok) throw new Error(`native win32: ${load.code}`);
899
+ const bridge = load.bridge;
900
+ const sid = win32CurrentTokenSid();
901
+ if (sid === void 0) throw new Error("native win32: the current token SID is unavailable");
902
+ const security = securityAttributesForSddl(bridge, `D:P(A;OICI;FA;;;${sid})`);
903
+ let created;
904
+ let createError = 0;
905
+ try {
906
+ created = bridge.createDirectoryW(path, security.attributes);
907
+ if (!created) createError = lastError(bridge);
908
+ } finally {
909
+ bridge.localFree(security.sd);
910
+ }
911
+ if (created) return;
912
+ if (createError !== ERROR_ALREADY_EXISTS) throw new Error(`native win32: the private directory could not be created (${String(createError)})`);
913
+ if (!win32PrivateDirectorySafe(path)) throw new Error("native win32: an existing private directory is not private");
914
+ }
915
+ /** A valid Win32 handle; `CreateNamedPipeW` reports failure as INVALID_HANDLE_VALUE. */
916
+ function validWin32Handle(handle) {
917
+ return handle !== null && handle !== void 0 && handle !== INVALID_HANDLE_VALUE;
918
+ }
919
+ /** Create ONE auxiliary instance handle on an existing pipe name for DACL work. */
920
+ function createAcpPipeAuxiliary(bridge, pipeName) {
921
+ bridge.setLastError(0);
922
+ const handle = bridge.createNamedPipeW(pipeName, 1074003971, 0, PIPE_UNLIMITED_INSTANCES, 65536, 65536, 0, null);
923
+ if (!validWin32Handle(handle)) throw new Error(`native win32: the ACP named-pipe auxiliary instance could not be created (${String(lastError(bridge))})`);
924
+ return handle;
925
+ }
926
+ /**
927
+ * Apply the one-shot owner-only + local-only DACL to an already-created Node
928
+ * Named Pipe listener.
929
+ *
930
+ * The auxiliary instance is never connected, accepted or read; it only carries
931
+ * the WRITE_DAC access needed for `SetSecurityInfo`, and it is closed before
932
+ * this function returns. `SetSecurityInfo` on the named pipe object constrains
933
+ * the Node server's subsequent instances; a successful return is the commit
934
+ * point. Any failure throws: callers must not report the listener enabled.
935
+ */
936
+ function secureWin32AcpPipe(pipeName) {
937
+ const load = loadBridge$1();
938
+ if (!load.ok) throw new Error(`native win32: ${load.code}`);
939
+ const bridge = load.bridge;
940
+ const sid = win32CurrentTokenSid();
941
+ if (sid === void 0) throw new Error("native win32: the current token SID is unavailable");
942
+ const writeAux = createAcpPipeAuxiliary(bridge, pipeName);
943
+ try {
944
+ const sddl = `D:P(D;;GA;;;${NETWORK_SID})(A;;GA;;;${sid})`;
945
+ const sd = Buffer.alloc(8);
946
+ const size = Buffer.alloc(4);
947
+ if (!bridge.convertStringSecurityDescriptor(sddl, SDDL_REVISION_1, sd, size)) throw new Error(`native win32: the ACP named-pipe security descriptor is invalid (${String(lastError(bridge))})`);
948
+ const sdPtr = sd.readBigUInt64LE(0);
949
+ try {
950
+ const present = Buffer.alloc(4);
951
+ const dacl = Buffer.alloc(8);
952
+ const defaulted = Buffer.alloc(4);
953
+ if (!bridge.getSecurityDescriptorDacl(sdPtr, present, dacl, defaulted) || present.readInt32LE(0) === 0) throw new Error("native win32: the ACP named-pipe DACL is unavailable");
954
+ const daclPtr = dacl.readBigUInt64LE(0);
955
+ const result = bridge.setSecurityInfo(writeAux, SE_FILE_OBJECT, -2147483644, null, null, daclPtr, null);
956
+ if (result !== 0) throw new Error(`native win32: the ACP named-pipe DACL could not be applied (${String(result)})`);
957
+ } finally {
958
+ bridge.localFree(sdPtr);
959
+ }
960
+ } finally {
961
+ bridge.closeHandle(writeAux);
962
+ }
963
+ }
964
+ /** `<sys/proc_info.h>`: PROC_PIDTBSDINFO. */
965
+ const PROC_PIDTBSDINFO_FLAVOR = 3;
966
+ /** XNU's private flavor 17 (PROC_PIDUNIQIDENTIFIERINFO), not in the public SDK. */
967
+ const PROC_PIDUNIQIDENTIFIER_FLAVOR = 17;
968
+ const LIBPROC = "/usr/lib/libproc.dylib";
969
+ const LIBSYSTEM = "/usr/lib/libSystem.B.dylib";
970
+ const ESRCH = 3;
971
+ const EPERM = 1;
972
+ const EACCES = 13;
973
+ const EINVAL = 22;
974
+ /** `kern.bootsessionuuid` capacity — the UUID text is 36 bytes plus NUL. */
975
+ const BOOT_UUID_CAPACITY = 128;
976
+ /**
977
+ * Classify one libproc read outcome into this repository's observation
978
+ * taxonomy. `expectedBytes` is the ABI struct size this build was written for;
979
+ * `actualBytes` is what the kernel reported. A positive-but-different reply is
980
+ * an ABI mismatch even when the kernel also set an errno: the reply must never
981
+ * be truncated or reinterpreted.
982
+ */
983
+ function classifyDarwinReadOutcome(expectedBytes, actualBytes, errno) {
984
+ if (actualBytes === expectedBytes && expectedBytes > 0) return { kind: "ok" };
985
+ if (actualBytes > 0) return {
986
+ kind: "unknown",
987
+ code: "ABI_UNSUPPORTED"
988
+ };
989
+ if (errno === ESRCH) return { kind: "gone" };
990
+ if (errno === EPERM || errno === EACCES) return {
991
+ kind: "unknown",
992
+ code: "ACCESS_DENIED"
993
+ };
994
+ if (errno === EINVAL) return {
995
+ kind: "unknown",
996
+ code: "ABI_UNSUPPORTED"
997
+ };
998
+ return {
999
+ kind: "unknown",
1000
+ code: "READ_FAILED"
1001
+ };
1002
+ }
1003
+ /** A 64-bit kernel counter as an exact decimal string (Koffi yields a BigInt
1004
+ * only when the value would lose precision as a JS number). */
1005
+ function decimal(value) {
1006
+ if (typeof value === "bigint") return value.toString(10);
1007
+ if (typeof value === "number" && Number.isSafeInteger(value)) return String(value);
1008
+ throw new Error(`expected an exact 64-bit integer, got ${String(value)}`);
1009
+ }
1010
+ let loaded;
172
1011
  /** Load and ABI-check the Darwin bridge once per process. The loader itself
173
1012
  * never throws: an unavailable dylib/addon or an unexpected struct size is a
174
1013
  * classified observation, and the caller fails closed. */
@@ -614,6 +1453,7 @@ function readDarwinKernelProcess(pid) {
614
1453
  function readKernelProcess(pid) {
615
1454
  if (process.platform === "linux") return readLinuxKernelProcess(pid);
616
1455
  if (process.platform === "darwin") return readDarwinKernelProcess(pid);
1456
+ if (process.platform === "win32") return readWin32KernelProcessObservation(pid);
617
1457
  return {
618
1458
  kind: "unknown",
619
1459
  code: "NATIVE_UNAVAILABLE"
@@ -631,12 +1471,14 @@ function sameKernelProcess(expected, observed) {
631
1471
  if (actual.platform !== expected.platform || actual.pid !== expected.pid) return "different";
632
1472
  if (expected.platform === "linux" && actual.platform === "linux") return actual.startTicks === expected.startTicks ? "same" : "different";
633
1473
  if (expected.platform === "darwin" && actual.platform === "darwin") return actual.bootUUID === expected.bootUUID && actual.uniqueId === expected.uniqueId && actual.processUUID === expected.processUUID && actual.startSec === expected.startSec && actual.startUsec === expected.startUsec ? "same" : "different";
1474
+ if (expected.platform === "win32" && actual.platform === "win32") return actual.ownerSid === expected.ownerSid && actual.creationFiletime === expected.creationFiletime ? "same" : "different";
634
1475
  return "different";
635
1476
  }
636
1477
  /** Whether one identity is a member of BOTH the target process group and the
637
1478
  * session the owner created for it (`setsid`: sid === pgid). A member that
638
1479
  * changed its group/session no longer proves ownership of the captured group. */
639
1480
  function isOwnedGroupMember(identity, pgid) {
1481
+ if (identity.platform === "win32") return false;
640
1482
  return identity.pgid === pgid && identity.sid === pgid;
641
1483
  }
642
1484
  /**
@@ -778,19 +1620,22 @@ function assertDarwin() {
778
1620
  function processSeatPath(scopeDir, scopeId, kind) {
779
1621
  return join(scopeDir, `seat-${kind}-${scopeId}.lock`);
780
1622
  }
781
- /** Validate one already-claimed seat file: a real regular file, owned by this
782
- * user, readable/writable by this user ONLY, with exactly one link. */
783
- function assertSeatFileSafe(path, uid) {
1623
+ /** Read and validate one seat file: a real regular file, owned by this user,
1624
+ * readable/writable by this user ONLY, with exactly one link. Absence is the
1625
+ * normal create path; every other read or validation failure is unsafe. */
1626
+ function readSafeSeatFile(path, uid) {
784
1627
  let info;
785
1628
  try {
786
1629
  info = lstatSync(path);
787
1630
  } catch (error) {
1631
+ if (error.code === "ENOENT") return void 0;
788
1632
  throw new LocalScopeError("SCOPE_DIRECTORY_UNSAFE", `local scope: seat ${path} is not accessible`, error);
789
1633
  }
790
1634
  if (info.isSymbolicLink()) throw new LocalScopeError("SCOPE_DIRECTORY_UNSAFE", `local scope: seat ${path} must not be a symlink`);
791
1635
  if (!info.isFile()) throw new LocalScopeError("SCOPE_DIRECTORY_UNSAFE", `local scope: seat ${path} must be a regular file`);
792
1636
  if (info.uid !== uid || (info.mode & 511) !== DARWIN_SEAT_FILE_MODE) throw new LocalScopeError("SCOPE_DIRECTORY_UNSAFE", `local scope: seat ${path} must be owned by uid ${String(uid)} with mode 0600`);
793
1637
  if (info.nlink !== 1) throw new LocalScopeError("SCOPE_DIRECTORY_UNSAFE", `local scope: seat ${path} must have exactly one link`);
1638
+ return info;
794
1639
  }
795
1640
  /** Validate the private 0700 directory the seat file lives in. */
796
1641
  function assertSeatDirectorySafe(dir, uid) {
@@ -832,9 +1677,9 @@ var DarwinKernelSeat = class {
832
1677
  if (this.fd === void 0) throw new LocalScopeError("HOST_IDENTITY_MISMATCH", `local scope: seat ${this.path} was already closed`);
833
1678
  const directory = assertSeatDirectorySafe(this.dir, this.uid);
834
1679
  if (directory.dev !== this.dirDev || directory.ino !== this.dirIno) throw new LocalScopeError("SCOPE_DIRECTORY_UNSAFE", `local scope: seat directory ${this.dir} was replaced`);
835
- assertSeatFileSafe(this.path, this.uid);
1680
+ const pathInfo = readSafeSeatFile(this.path, this.uid);
1681
+ if (pathInfo === void 0) throw new LocalScopeError("SCOPE_DIRECTORY_UNSAFE", `local scope: seat ${this.path} is no longer present`);
836
1682
  const held = fstatSync(this.fd);
837
- const pathInfo = lstatSync(this.path);
838
1683
  if (held.dev !== pathInfo.dev || held.ino !== pathInfo.ino || held.uid !== pathInfo.uid || (held.mode & 511) !== (pathInfo.mode & 511) || held.nlink !== pathInfo.nlink) throw new LocalScopeError("HOST_IDENTITY_MISMATCH", `local scope: seat ${this.path} no longer matches the held inode`);
839
1684
  }
840
1685
  /**
@@ -859,14 +1704,7 @@ async function bindDarwinKernelSeat(scopeDir, scopeId, kind, conflictCode) {
859
1704
  const uid = assertDarwin();
860
1705
  const dirIdentity = assertSeatDirectorySafe(scopeDir, uid);
861
1706
  const path = processSeatPath(scopeDir, scopeId, kind);
862
- let existing = true;
863
- try {
864
- lstatSync(path);
865
- } catch (error) {
866
- if (error.code !== "ENOENT") throw new LocalScopeError("SCOPE_DIRECTORY_UNSAFE", `local scope: seat ${path} is not accessible`, error);
867
- existing = false;
868
- }
869
- if (existing) assertSeatFileSafe(path, uid);
1707
+ readSafeSeatFile(path, uid);
870
1708
  let fd;
871
1709
  try {
872
1710
  fd = openSync(path, DARWIN_SEAT_FLAGS, DARWIN_SEAT_FILE_MODE);
@@ -1157,7 +1995,8 @@ function listInstalledDistFiles(packageRoot) {
1157
1995
  * Fingerprint the actual installed payload. Every regular `dist/**` `.mjs`
1158
1996
  * contributes `relative-posix-name NUL sha256(content) LF` in UTF-8 byte
1159
1997
  * order; the bundle and DSH versions close the stream. The value is computed
1160
- * once by the Host at startup and once by each Client from its own install.
1998
+ * once by the Host at startup and by surface Client startup/reexec paths that
1999
+ * need exact process identity.
1161
2000
  */
1162
2001
  function computeBuildId(packageRoot, dshVersion) {
1163
2002
  if (dshVersion === "") throw new Error("local scope: the installed DSH version must not be empty");
@@ -1180,6 +2019,54 @@ function computeBuildId(packageRoot, dshVersion) {
1180
2019
  hash.update("\n");
1181
2020
  return hash.digest("hex");
1182
2021
  }
2022
+ /** Canonicalize one official Windows directory to the local fixed-NTFS domain. */
2023
+ function canonicalWin32Directory(pathValue, label) {
2024
+ let real;
2025
+ try {
2026
+ real = realpathSync.native(pathValue);
2027
+ } catch (error) {
2028
+ throw new LocalScopeError("SCOPE_DIRECTORY_UNSAFE", `local scope: ${label} is not a readable directory`, error);
2029
+ }
2030
+ if (!/^[A-Za-z]:\\/u.test(real)) throw new LocalScopeError("SCOPE_DIRECTORY_UNSAFE", `local scope: ${label} must be a local drive path`);
2031
+ const canonical = real.slice(0, 1).toUpperCase() + real.slice(1);
2032
+ if (!isWin32LocalFixedNtfs(canonical)) throw new LocalScopeError("SCOPE_DIRECTORY_UNSAFE", `local scope: ${label} must be on a local fixed NTFS volume`);
2033
+ if (!statSync(canonical).isDirectory()) throw new LocalScopeError("SCOPE_DIRECTORY_UNSAFE", `local scope: ${label} must be a directory`);
2034
+ return canonical;
2035
+ }
2036
+ /** The read-only Win32 scope: SID + canonical profile path, fixed hash domain. */
2037
+ function inspectWin32ProfileScope(facts) {
2038
+ const dshHome = canonicalWin32Directory(facts.dshHome, "DSH home");
2039
+ const profileRealpath = canonicalWin32Directory(facts.profileDir, "profile directory");
2040
+ const sid = win32CurrentTokenSid();
2041
+ if (sid === void 0) throw new LocalScopeError("SCOPE_DIRECTORY_UNSAFE", "local scope: the current token SID is unavailable");
2042
+ const bundleVersion = readBundleVersion(facts.packageRoot);
2043
+ const scopeId = createHash("sha256").update(`dsh-pi-tui/local-scope/win32/1\0${sid}\0${profileRealpath}`).digest("hex");
2044
+ return Object.freeze({
2045
+ scopeId,
2046
+ dshHome,
2047
+ profileRealpath,
2048
+ dir: join(dshHome, RUN_ROOT_NAME, SCOPE_ROOT_NAME, scopeId),
2049
+ bundleVersion,
2050
+ dshVersion: facts.dshVersion
2051
+ });
2052
+ }
2053
+ /** Create the Win32 private run chain with protected owner-only DACLs on new
2054
+ * directories; existing directories are reused under the shared private-object
2055
+ * predicate, and files inside inherit the directory ACL and are admitted by the
2056
+ * shared private-file predicate. */
2057
+ function ensureWin32ScopeDirectory(dshHome, scopeId) {
2058
+ const dir = join(dshHome, RUN_ROOT_NAME, SCOPE_ROOT_NAME, scopeId);
2059
+ for (const path of [
2060
+ join(dshHome, RUN_ROOT_NAME),
2061
+ join(dshHome, RUN_ROOT_NAME, SCOPE_ROOT_NAME),
2062
+ dir
2063
+ ]) try {
2064
+ ensureWin32PrivateDirectory(path);
2065
+ } catch (error) {
2066
+ throw new LocalScopeError("SCOPE_DIRECTORY_UNSAFE", `local scope: ${path} is not a private product directory`, error);
2067
+ }
2068
+ return dir;
2069
+ }
1183
2070
  /**
1184
2071
  * Compute the READ-ONLY identity of one installed profile scope. The caller
1185
2072
  * supplies the official DSH home/profile resolution results; this module never
@@ -1190,9 +2077,10 @@ function computeBuildId(packageRoot, dshVersion) {
1190
2077
  * the exact same computation with the one directory-creation step.
1191
2078
  */
1192
2079
  function inspectInstalledProfileScope(facts) {
2080
+ if (process.platform === "win32") return inspectWin32ProfileScope(facts);
1193
2081
  const uid = assertSupportedPosixScopePlatform();
1194
2082
  const dshHome = process.platform === "darwin" ? canonicalOwnedDirectory(facts.dshHome, uid, "DSH home") : canonicalDirectory(facts.dshHome, "DSH home");
1195
- const profileRealpath = process.platform === "darwin" ? canonicalOwnedDirectory(facts.profileDir, uid, "profile directory") : canonicalDirectory(facts.profileDir, "profile directory");
2083
+ const profileRealpath = canonicalDirectory(facts.profileDir, "profile directory");
1196
2084
  const bundleVersion = readBundleVersion(facts.packageRoot);
1197
2085
  const scopeId = createHash("sha256").update(`dsh-pi-tui/local-scope/1\0${String(uid)}\0${profileRealpath}`).digest("hex");
1198
2086
  return Object.freeze({
@@ -1202,28 +2090,50 @@ function inspectInstalledProfileScope(facts) {
1202
2090
  dir: join(dshHome, RUN_ROOT_NAME, SCOPE_ROOT_NAME, scopeId),
1203
2091
  hostSocketName: `${HOST_SEAT_PREFIX}${scopeId.slice(0, 40)}`,
1204
2092
  clientSeatSocketName: `${CLIENT_SEAT_PREFIX}${scopeId.slice(0, 40)}`,
1205
- buildId: computeBuildId(facts.packageRoot, facts.dshVersion),
1206
2093
  bundleVersion,
1207
2094
  dshVersion: facts.dshVersion
1208
2095
  });
1209
2096
  }
1210
2097
  /**
1211
- * Build the one scope for an installed profile AND create/prove its private
1212
- * 0700 run directory, before any process seat or Host Context exists. The
1213
- * scope identity comes from the same read-only computation above; only the run
1214
- * directory creation is added here, so Host admission and stdout/qualification
1215
- * shapes stay unchanged.
2098
+ * Strictly materialize the current installed build for one previously resolved
2099
+ * scope identity. Callers that publish a Host or start a detached process call
2100
+ * this explicitly; a failed walk cannot be hidden
2101
+ * by a placeholder or replaced by a version/mtime.
1216
2102
  */
1217
- function scopeFromInstalledProfile(facts) {
1218
- const inspected = inspectInstalledProfileScope(facts);
2103
+ function materializeBuild(identity, packageRoot) {
2104
+ return Object.freeze({
2105
+ ...identity,
2106
+ buildId: computeBuildId(packageRoot, identity.dshVersion)
2107
+ });
2108
+ }
2109
+ /**
2110
+ * Create/prove the private run directory for one scope identity, preserving the
2111
+ * caller's exact scope type. This directory step does not materialize a build.
2112
+ */
2113
+ function ensureInstalledProfileScopeDirectory(scope) {
2114
+ if (process.platform === "win32") return Object.freeze({
2115
+ ...scope,
2116
+ dir: ensureWin32ScopeDirectory(scope.dshHome, scope.scopeId)
2117
+ });
1219
2118
  const uid = assertSupportedPosixScopePlatform();
1220
- const dir = ensureScopeDirectory(inspected.dshHome, inspected.scopeId, uid);
2119
+ const dir = ensureScopeDirectory(scope.dshHome, scope.scopeId, uid);
1221
2120
  return Object.freeze({
1222
- ...inspected,
2121
+ ...scope,
1223
2122
  dir
1224
2123
  });
1225
2124
  }
1226
2125
  /**
2126
+ * Build the one scope for an installed profile AND create/prove its private
2127
+ * 0700 run directory, before any process seat or Host Context exists. The
2128
+ * scope identity comes from the same read-only computation above; only the
2129
+ * strict build materialization and directory creation are added here, so Host
2130
+ * admission and stdout/qualification shapes stay unchanged. A build failure
2131
+ * happens before any directory creation.
2132
+ */
2133
+ function scopeFromInstalledProfile(facts) {
2134
+ return ensureInstalledProfileScopeDirectory(materializeBuild(inspectInstalledProfileScope(facts), facts.packageRoot));
2135
+ }
2136
+ /**
1227
2137
  * Strict Linux process-start identity. B1 identity comparison never falls
1228
2138
  * back to a bare PID: a missing `/proc` value is a hard failure.
1229
2139
  */
@@ -1241,6 +2151,11 @@ function readLinuxStarttime(pid = process.pid) {
1241
2151
  */
1242
2152
  function readProcessStartDiagnostic(pid = process.pid) {
1243
2153
  if (process.platform === "linux") return readProcessStarttime(pid);
2154
+ if (process.platform === "win32") {
2155
+ const observed = readKernelProcess(pid);
2156
+ if (observed.kind !== "alive" || observed.identity.platform !== "win32") return void 0;
2157
+ return `${observed.identity.ownerSid}:${observed.identity.creationFiletime}`;
2158
+ }
1244
2159
  if (process.platform === "darwin") {
1245
2160
  const observed = readKernelProcess(pid);
1246
2161
  if (observed.kind !== "alive" || observed.identity.platform !== "darwin") return void 0;
@@ -1311,16 +2226,28 @@ function bindProcessSeat(name, conflictCode) {
1311
2226
  }, conflictCode);
1312
2227
  }
1313
2228
  async function bindProfileKernelSeat(scope, kind, conflictCode, options = {}) {
1314
- if (process.platform === "linux") return bindKernelSeat({
1315
- claim: "linux-abstract",
1316
- name: kind === "host" ? scope.hostSocketName : scope.clientSeatSocketName
1317
- }, conflictCode);
2229
+ if (process.platform === "linux") {
2230
+ if (kind === "admin") throw new LocalScopeError("B1_PLATFORM_UNSUPPORTED", "local scope: the Linux admin seat uses bindProcessSeat");
2231
+ return bindKernelSeat({
2232
+ claim: "linux-abstract",
2233
+ name: kind === "host" ? scope.hostSocketName : scope.clientSeatSocketName
2234
+ }, conflictCode);
2235
+ }
1318
2236
  if (process.platform === "darwin") return bindKernelSeat({
1319
2237
  claim: "darwin-file",
1320
2238
  dir: kind === "host" ? darwinHostProfileSeatDir(scope.scopeId, options.accountHome) : scope.dir,
1321
2239
  scopeId: scope.scopeId,
1322
2240
  kind
1323
2241
  }, conflictCode);
2242
+ if (process.platform === "win32") {
2243
+ if (kind === "qualification-client") throw new LocalScopeError("B1_PLATFORM_UNSUPPORTED", "local scope: the Windows qualification Client seat is not available");
2244
+ try {
2245
+ return await acquireWin32KernelSeat(win32SeatName(scope.scopeId, kind), conflictCode);
2246
+ } catch (error) {
2247
+ if (error.code === conflictCode) throw new LocalScopeError(conflictCode, `local scope: the ${kind} seat of this profile is already held by another live process`, error);
2248
+ throw new LocalScopeError("SCOPE_DIRECTORY_UNSAFE", `local scope: the ${kind} seat could not be acquired`, error);
2249
+ }
2250
+ }
1324
2251
  throw new LocalScopeError("B1_PLATFORM_UNSUPPORTED", `local scope: no profile kernel seat is implemented for ${process.platform}`);
1325
2252
  }
1326
2253
  /**
@@ -1337,4 +2264,4 @@ function removeOwnedScratch(scopeDir, scratchDir) {
1337
2264
  });
1338
2265
  }
1339
2266
  //#endregion
1340
- export { parseProcessStat as _, bindProcessSeat as a, readProcessStarttime as b, darwinHostProfileSeatDir as c, readInstalledDshVersion as d, readLinuxStarttime as f, listKernelGroupMembers as g, scopeFromInstalledProfile as h, bindDarwinKernelSeat as i, inspectInstalledProfileScope as l, removeOwnedScratch as m, LocalScopeError as n, bindProfileKernelSeat as o, readProcessStartDiagnostic as p, NO_PROCESS_SEAT as r, computeBuildId as s, LOCAL_PROTOCOL as t, installedPackageRootFromEntry as u, parseProcessStatStarttime as v, sameKernelProcess as x, readKernelProcess as y };
2267
+ export { secureWin32AcpPipe as A, installedDshManifest as B, sameKernelProcess as C, isWin32LocalFixedNtfs as D, ensureWin32PrivateDirectory as E, win32SystemDirectory as F, assertDeclaredDependency as I, assertDeclaredPeerDependency as L, win32CurrentTokenSid as M, win32PrivateDirectorySafe as N, openWin32Process as O, win32PrivateFileStatus as P, assertInstallClosure as R, readProcessStarttime as S, createWin32StopWaiter as T, readManifestObject as V, scopeFromInstalledProfile as _, bindProcessSeat as a, parseProcessStatStarttime as b, darwinHostProfileSeatDir as c, installedPackageRootFromEntry as d, materializeBuild as f, removeOwnedScratch as g, readProcessStartDiagnostic as h, bindDarwinKernelSeat as i, waitWin32Handle as j, openWin32StopSignal as k, ensureInstalledProfileScopeDirectory as l, readLinuxStarttime as m, LocalScopeError as n, bindProfileKernelSeat as o, readInstalledDshVersion as p, NO_PROCESS_SEAT as r, computeBuildId as s, LOCAL_PROTOCOL as t, inspectInstalledProfileScope as u, listKernelGroupMembers as v, closeWin32Handle as w, readKernelProcess as x, parseProcessStat as y, installedDshAnchor as z };