@lousy-agents/agent-shell 5.22.0 → 5.22.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +713 -123
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import { createRequire as __rspack_createRequire } from "node:module";
3
3
  const __rspack_createRequire_require = __rspack_createRequire(import.meta.url);
4
4
  var __webpack_modules__ = ({
5
- 981(__unused_rspack_module, __unused_rspack___webpack_exports__, __webpack_require__) {
5
+ 402(__unused_rspack_module, __unused_rspack___webpack_exports__, __webpack_require__) {
6
6
 
7
7
  ;// CONCATENATED MODULE: external "node:child_process"
8
8
  const external_node_child_process_namespaceObject = __rspack_createRequire_require("node:child_process");
@@ -222,6 +222,17 @@ function getFsSafeNativeConfig() {
222
222
  "auto",
223
223
  };
224
224
  }
225
+ /** Internal provenance; keep the public configuration shape unchanged. */
226
+ function getNativeModeSetting() {
227
+ if (overrideConfig.mode !== undefined)
228
+ return { mode: overrideConfig.mode, source: "programmatic configuration" };
229
+ for (const source of ["FS_SAFE_NATIVE_MODE", "OPENCLAW_FS_SAFE_NATIVE_MODE"]) {
230
+ const mode = parseMode(process.env[source]);
231
+ if (mode !== undefined)
232
+ return { mode, source };
233
+ }
234
+ return { mode: "auto", source: "default" };
235
+ }
225
236
  function isFsSafeNativeRequired() {
226
237
  return (overrideConfig.mode ??
227
238
  parseMode(process.env.FS_SAFE_NATIVE_MODE) ??
@@ -247,6 +258,62 @@ let native_binding;
247
258
  let native_loadError;
248
259
  let attempted = false;
249
260
  let loadBinding = loadBundledBinding;
261
+ let resolvePackage = (name) => native_require.resolve(name);
262
+ let loadOutcome = { reason: "not-probed" };
263
+ let selectedTarget;
264
+ let targetDescription;
265
+ function loadFailure(error, packageName) {
266
+ try {
267
+ return classifyLoadFailure(error, packageName);
268
+ }
269
+ catch {
270
+ // Diagnostic inspection must not replace an arbitrary thrown load value.
271
+ return { reason: "load-failed", code: "UNKNOWN" };
272
+ }
273
+ }
274
+ function classifyLoadFailure(error, packageName) {
275
+ const code = typeof error === "object" && error !== null && "code" in error ? error.code : undefined;
276
+ // Resolution must fail for the selected package itself. An exception inside
277
+ // an installed package (even one naming this package) is not package omission.
278
+ if (code === "MODULE_NOT_FOUND" && error instanceof Error &&
279
+ error.message.split("\n", 1)[0] === `Cannot find module '${packageName}'`) {
280
+ try {
281
+ resolvePackage(packageName);
282
+ }
283
+ catch (resolutionError) {
284
+ if (resolutionError instanceof Error && "code" in resolutionError &&
285
+ resolutionError.code === "MODULE_NOT_FOUND" &&
286
+ resolutionError.message.split("\n", 1)[0] === `Cannot find module '${packageName}'`) {
287
+ return { reason: "package-missing" };
288
+ }
289
+ }
290
+ }
291
+ // An allowlist excludes paths, secrets and arbitrary text in exception codes.
292
+ const knownCodes = ["ERR_DLOPEN_FAILED", "MODULE_NOT_FOUND", "ERR_MODULE_NOT_FOUND",
293
+ "ERR_PACKAGE_PATH_NOT_EXPORTED", "ERR_INVALID_PACKAGE_CONFIG", "EACCES", "EPERM", "ENOENT"];
294
+ return { reason: "load-failed", code: typeof code === "string" && knownCodes.includes(code) ? code : "UNKNOWN" };
295
+ }
296
+ /** Internal view of the cached load; never attempts to load an addon. */
297
+ function getNativeFallbackDiagnostic(...capabilities) {
298
+ const setting = getNativeModeSetting();
299
+ const target = targetDescription === undefined ? bundledTarget() : selectedTarget;
300
+ const packageName = target === undefined ? undefined : nativePackageForTarget(target);
301
+ const manifest = native_require("../package.json");
302
+ const expected = {
303
+ target: targetDescription,
304
+ packageName,
305
+ packageVersion: packageName === undefined ? undefined : manifest.optionalDependencies[packageName],
306
+ };
307
+ if (setting.mode === "off")
308
+ return { ...expected, reason: "disabled", source: setting.source };
309
+ const loaded = native_binding;
310
+ if (loaded) {
311
+ const missing = capabilities.filter(name => typeof loaded[name] !== "function");
312
+ if (missing.length)
313
+ return { ...expected, reason: "capability-missing", capabilities: missing };
314
+ }
315
+ return { ...expected, ...loadOutcome };
316
+ }
250
317
  function isMuslFilename(file) {
251
318
  return file.includes("libc.musl-") || file.includes("ld-musl-");
252
319
  }
@@ -376,7 +443,10 @@ function targetFor(platform, arch, musl) {
376
443
  return undefined;
377
444
  }
378
445
  function bundledTarget() {
379
- return targetFor(process.platform, process.arch, isMusl());
446
+ const musl = isMusl();
447
+ selectedTarget = targetFor(process.platform, process.arch, musl);
448
+ targetDescription = selectedTarget ?? `${process.platform}-${process.arch}${process.platform === "linux" ? `-${musl ? "musl" : "gnu"}` : ""}`;
449
+ return selectedTarget;
380
450
  }
381
451
  function nativePackageForTarget(target) {
382
452
  return `@openclaw/fs-safe-${target}`;
@@ -384,9 +454,13 @@ function nativePackageForTarget(target) {
384
454
  function loadBundledBinding() {
385
455
  const target = bundledTarget();
386
456
  if (!target) {
457
+ loadOutcome = { reason: "unsupported-target" };
387
458
  throw new Error(`Unsupported OS or architecture: ${process.platform}-${process.arch}`);
388
459
  }
389
460
  const loaded = runNativeInitialization(() => native_require(nativePackageForTarget(target)));
461
+ if (typeof loaded.closeOwnedFd !== "function") {
462
+ loadOutcome = { reason: "capability-missing", capabilities: ["closeOwnedFd"] };
463
+ }
390
464
  captureNativeFdClose(loaded);
391
465
  return loaded;
392
466
  }
@@ -428,11 +502,19 @@ function native_getNativeBinding(...capabilities) {
428
502
  attempted = true;
429
503
  try {
430
504
  const loaded = loadBinding();
505
+ if (typeof loaded.closeOwnedFd !== "function") {
506
+ loadOutcome = { reason: "capability-missing", capabilities: ["closeOwnedFd"] };
507
+ }
431
508
  captureNativeFdClose(loaded);
432
509
  native_binding = loaded;
510
+ loadOutcome = { reason: "loaded" };
433
511
  }
434
512
  catch (error) {
435
513
  native_loadError = error;
514
+ if (loadOutcome.reason === "not-probed") {
515
+ selectedTarget ??= bundledTarget();
516
+ loadOutcome = loadFailure(error, nativePackageForTarget(selectedTarget ?? `${process.platform}-${process.arch}`));
517
+ }
436
518
  }
437
519
  }
438
520
  if (native_binding)
@@ -453,17 +535,25 @@ function native_requireNativeBinding(...capabilities) {
453
535
  }
454
536
  return native;
455
537
  }
456
- function __setNativeLoaderForTest(loader) {
538
+ function __setNativeLoaderForTest(loader, resolver) {
457
539
  native_binding = undefined;
458
540
  native_loadError = undefined;
459
541
  attempted = false;
460
542
  loadBinding = loader;
543
+ loadOutcome = { reason: "not-probed" };
544
+ selectedTarget = undefined;
545
+ targetDescription = undefined;
546
+ resolvePackage = resolver ?? ((name) => native_require.resolve(name));
461
547
  }
462
548
  function __resetNativeLoaderForTest() {
463
549
  native_binding = undefined;
464
550
  native_loadError = undefined;
465
551
  attempted = false;
466
552
  loadBinding = loadBundledBinding;
553
+ loadOutcome = { reason: "not-probed" };
554
+ selectedTarget = undefined;
555
+ targetDescription = undefined;
556
+ resolvePackage = (name) => native_require.resolve(name);
467
557
  }
468
558
 
469
559
  ;// CONCATENATED MODULE: ../../node_modules/@openclaw/fs-safe/dist/file-observation.js
@@ -1946,6 +2036,15 @@ function assertDirectoryObservationGuardSync(guard) {
1946
2036
  }
1947
2037
  }
1948
2038
 
2039
+ ;// CONCATENATED MODULE: ../../node_modules/@openclaw/fs-safe/dist/native-stat-identity.js
2040
+ /** Native stat identities are unsigned; Node BigIntStats preserves them as signed bits. */
2041
+ function statIdentityFromNative(value) {
2042
+ return value <= 0x7fffffffffffffffn || process.versions.bun ? value : BigInt.asIntN(64, value);
2043
+ }
2044
+ function isNativeStatIdentity(value) {
2045
+ return typeof value === "bigint" && value >= 0n && value <= 0xffffffffffffffffn;
2046
+ }
2047
+
1949
2048
  ;// CONCATENATED MODULE: ../../node_modules/@openclaw/fs-safe/dist/directory-receipt.js
1950
2049
 
1951
2050
 
@@ -2450,6 +2549,7 @@ function createSuppressedError(error, suppressed, message) {
2450
2549
 
2451
2550
 
2452
2551
 
2552
+
2453
2553
  /** Shared by tree byte copying and per-file copying; never resolves the target. */
2454
2554
  async function readCopyLinkTarget(source) {
2455
2555
  return await promises_namespaceObject.readlink(source, { encoding: "buffer" });
@@ -2519,7 +2619,7 @@ async function copyLinkAtParent(params, input, parent, native) {
2519
2619
  directory_guard_assertSyncDirectoryGuard(parent);
2520
2620
  if (native?.binding.createCopySymlink) {
2521
2621
  const created = native.binding.createCopySymlink(native.fd, temporaryName, input.target, params.mode, input.preserveMetadata ? input.identity.atimeNs : undefined, input.preserveMetadata ? input.identity.mtimeNs : undefined);
2522
- identity = created;
2622
+ identity = { dev: statIdentityFromNative(created.dev), ino: statIdentityFromNative(created.ino) };
2523
2623
  if (created.errorCode)
2524
2624
  throw Object.assign(new Error(created.errorMessage), { code: created.errorCode });
2525
2625
  }
@@ -3245,14 +3345,61 @@ function pinNodeDirectoryForModeSync(dirPath, options = {}) {
3245
3345
  }
3246
3346
  }
3247
3347
 
3348
+ ;// CONCATENATED MODULE: ../../node_modules/@openclaw/fs-safe/dist/native-guidance.js
3349
+ /** Shared, path-free next steps for status reports and fallback warnings. */
3350
+ function nativeGuidance(reason, modeSource) {
3351
+ switch (reason) {
3352
+ case "disabled": {
3353
+ const enable = modeSource === "programmatic configuration"
3354
+ ? 'call configureFsSafeNative({ mode: "auto" }) or configureFsSafeNative({ mode: "require" })'
3355
+ : `set ${modeSource}=auto or ${modeSource}=require`;
3356
+ return `If native loading is intended, ${enable}; keep intentional off settings.`;
3357
+ }
3358
+ case "unsupported-target":
3359
+ return "Portable mode is expected on this target.";
3360
+ case "package-missing":
3361
+ return "Reinstall with optional dependencies included: npm --include=optional, or pnpm without --no-optional / optional=false. Check the lockfile and registry mirror.";
3362
+ case "load-failed":
3363
+ return "Check Node architecture, Linux libc compatibility, package dependencies, and OS code-integrity policy. Reinstalling identical bytes may not help.";
3364
+ case "capability-missing":
3365
+ return "Use matching fs-safe and platform-package versions; some targets intentionally provide only a subset of capabilities.";
3366
+ default:
3367
+ return undefined;
3368
+ }
3369
+ }
3370
+
3248
3371
  ;// CONCATENATED MODULE: ../../node_modules/@openclaw/fs-safe/dist/native-fallback-warning.js
3372
+
3373
+
3374
+
3249
3375
  const warnedFeatures = new Set();
3376
+ function fallbackReason(capabilities) {
3377
+ const diagnostic = getNativeFallbackDiagnostic(...capabilities);
3378
+ const expected = diagnostic.packageName === undefined
3379
+ ? `No native package is published for ${diagnostic.target}.`
3380
+ : `Expected ${diagnostic.packageName}@${diagnostic.packageVersion}.`;
3381
+ const guidance = nativeGuidance(diagnostic.reason, getNativeModeSetting().source);
3382
+ switch (diagnostic.reason) {
3383
+ case "disabled":
3384
+ return `native support is disabled by ${diagnostic.source} (disabled). ${expected} ${guidance}`;
3385
+ case "unsupported-target":
3386
+ return `the target ${diagnostic.target} is unsupported (unsupported-target). ${expected} ${guidance}`;
3387
+ case "package-missing":
3388
+ return `the selected native package could not be resolved (package-missing). ${expected} ${guidance}`;
3389
+ case "load-failed":
3390
+ return `the native package could not be loaded (load-failed: ${diagnostic.code}). ${expected} ${guidance}`;
3391
+ case "capability-missing":
3392
+ return `the native package lacks requested functions (capability-missing: ${diagnostic.capabilities.join(", ")}). ${expected} ${guidance}`;
3393
+ default:
3394
+ return `the requested native operation is unavailable (${diagnostic.reason}). ${expected}`;
3395
+ }
3396
+ }
3250
3397
  /** Warn once per capability, without including caller paths or native error text. */
3251
- function warnNativeFallback(feature, limitation) {
3398
+ function warnNativeFallback(feature, limitation, ...capabilities) {
3252
3399
  if (warnedFeatures.has(feature))
3253
3400
  return;
3254
3401
  warnedFeatures.add(feature);
3255
- process.emitWarning(`${feature} is using its portable fallback because native support is unavailable or disabled. ${limitation}`, { code: "FS_SAFE_NATIVE_FALLBACK", type: "FsSafeWarning" });
3402
+ process.emitWarning(`${feature} is using its portable fallback because ${fallbackReason(capabilities)} ${limitation}`, { code: "FS_SAFE_NATIVE_FALLBACK", type: "FsSafeWarning" });
3256
3403
  }
3257
3404
  function __resetNativeFallbackWarningsForTest() {
3258
3405
  warnedFeatures.clear();
@@ -4089,17 +4236,17 @@ function creation_boundary_assertPrivateFileCreationAvailable() {
4089
4236
  typeof native.verifyPrivateWindowsFile !== "function")
4090
4237
  creation_boundary_unavailable();
4091
4238
  }
4092
- function commandFallback() {
4239
+ function commandFallback(capability) {
4093
4240
  if (getFsSafeNativeConfig().mode === "require")
4094
4241
  creation_boundary_unavailable();
4095
- warnNativeFallback("windows-private-creation", "Private Windows creation uses a slower built-in system command.");
4242
+ warnNativeFallback("windows-private-creation", "Private Windows creation launches the packaged .NET helper for each check or creation.", capability);
4096
4243
  }
4097
4244
  function creationOperation(name) {
4098
4245
  const native = native_getNativeBinding();
4099
4246
  const operation = native?.[name];
4100
4247
  if (typeof operation === "function")
4101
4248
  return operation.bind(native);
4102
- commandFallback();
4249
+ commandFallback(name);
4103
4250
  return undefined;
4104
4251
  }
4105
4252
  /** Full Windows identity, with security validation when requested; no repairs. */
@@ -6428,6 +6575,7 @@ function mergeDenyMutationPolicies(defaultPolicy, callPolicy) {
6428
6575
 
6429
6576
 
6430
6577
 
6578
+
6431
6579
  function getNativeDirectoryObservationBackend(enabled = true) {
6432
6580
  if (!enabled)
6433
6581
  return undefined;
@@ -6437,14 +6585,15 @@ function getNativeDirectoryObservationBackend(enabled = true) {
6437
6585
  : undefined;
6438
6586
  }
6439
6587
  function validateNativeDirectoryObservation(observation) {
6440
- if (!observation || typeof observation.dev !== "bigint" || observation.dev < 0n ||
6441
- typeof observation.ino !== "bigint" || observation.ino < 0n ||
6588
+ if (!observation || !isNativeStatIdentity(observation.dev) ||
6589
+ !isNativeStatIdentity(observation.ino) ||
6442
6590
  typeof observation.realPath !== "string" ||
6443
6591
  observation.realPath.includes("\0") ||
6444
6592
  (!external_node_path_namespaceObject.isAbsolute(observation.realPath) && !external_node_path_namespaceObject.win32.isAbsolute(observation.realPath))) {
6445
6593
  throw new errors_FsSafeError("path-mismatch", "native directory observation is invalid");
6446
6594
  }
6447
- return observation;
6595
+ const dev = statIdentityFromNative(observation.dev), ino = statIdentityFromNative(observation.ino);
6596
+ return dev === observation.dev && ino === observation.ino ? observation : { ...observation, dev, ino };
6448
6597
  }
6449
6598
  /** Exact identity, type, and canonical path captured from one retained handle. */
6450
6599
  function inspectNativeDirectoryObservation(backend, pathname, expected, platform = process.platform) {
@@ -6466,6 +6615,7 @@ function isNativeDirectoryObservationGuard(guard) {
6466
6615
 
6467
6616
 
6468
6617
 
6618
+
6469
6619
  class NativePolicyDirectoryMismatch extends errors_FsSafeError {
6470
6620
  constructor(cause) {
6471
6621
  super("path-mismatch", "staging directory pathname changed", { cause });
@@ -6504,8 +6654,8 @@ function native_policy_directory_observation_nativePolicyDirectoryObserver(bindi
6504
6654
  }
6505
6655
  if (getFsSafeNativeConfig().mode !== mode)
6506
6656
  return undefined;
6507
- if (!observed || typeof observed.dev !== "bigint" || observed.dev < 0n || observed.dev > 0xffffffffffffffffn ||
6508
- typeof observed.ino !== "bigint" || observed.ino < 0n || observed.ino > 0xffffffffffffffffn ||
6657
+ if (!observed || !isNativeStatIdentity(observed.dev) ||
6658
+ !isNativeStatIdentity(observed.ino) ||
6509
6659
  typeof observed.mode !== "bigint" || observed.mode < 0n || observed.mode > 0xffffffffn ||
6510
6660
  typeof observed.nlink !== "bigint" || observed.nlink < 0n || observed.nlink > 0xffffffffffffffffn ||
6511
6661
  typeof observed.realPath !== "string" || observed.realPath.includes("\0") ||
@@ -6518,7 +6668,7 @@ function native_policy_directory_observation_nativePolicyDirectoryObserver(bindi
6518
6668
  return Object.freeze({
6519
6669
  canonicalPath: observed.realPath,
6520
6670
  identity: Object.freeze({
6521
- dev: observed.dev, ino: observed.ino, mode: observed.mode, nlink: observed.nlink,
6671
+ dev: statIdentityFromNative(observed.dev), ino: statIdentityFromNative(observed.ino), mode: observed.mode, nlink: observed.nlink,
6522
6672
  }),
6523
6673
  });
6524
6674
  };
@@ -9308,6 +9458,64 @@ function __setFsSafeTestHooksForTest(hooks) {
9308
9458
  test_hooks_fsSafeTestHooks = hooks;
9309
9459
  }
9310
9460
 
9461
+ ;// CONCATENATED MODULE: ../../node_modules/@openclaw/fs-safe/dist/root-native-creation-path.js
9462
+
9463
+
9464
+
9465
+
9466
+
9467
+
9468
+
9469
+
9470
+
9471
+ function existingCreationParent(params) {
9472
+ if (params.private || params.policy || params.assertBeforeMutation !== undefined ||
9473
+ getFsSafeTestHooks()?.beforeRootFallbackMutation || !params.originalPath ||
9474
+ params.directory !== external_node_path_namespaceObject.dirname(params.target))
9475
+ return undefined;
9476
+ const segments = params.originalPath.split(external_node_path_namespaceObject.sep === "\\" ? /[\\/]/ : "/");
9477
+ if (segments.some(segment => !isSafePathSegment(segment, { allowDotPrefix: true }) || segment.endsWith(".")) ||
9478
+ external_node_path_namespaceObject.join(params.root.rootReal, ...segments) !== params.target)
9479
+ return undefined;
9480
+ let rootStat;
9481
+ root_context_assertRootIdentityCurrentSync(params.root, stat => { rootStat = stat; });
9482
+ try {
9483
+ const identity = directory_guard_inspectDirectoryIdentitySync(params.directory, undefined, params.directory === params.root.rootReal ? rootStat : undefined);
9484
+ if (realpath_realpathSync.native(windows_path_alias_pathForWindowsFilesystem(params.directory)) !== params.directory)
9485
+ return undefined;
9486
+ return {
9487
+ path: params.directory, identity,
9488
+ relative: external_node_path_namespaceObject.relative(params.root.rootReal, params.directory).split(external_node_path_namespaceObject.sep).join("/"),
9489
+ flags: (nodeDirectorySearchOnlyFlags()?.flags ?? external_node_fs_namespaceObject.constants.O_RDONLY) |
9490
+ (external_node_fs_namespaceObject.constants.O_DIRECTORY ?? 0) | (external_node_fs_namespaceObject.constants.O_NOFOLLOW ?? 0),
9491
+ };
9492
+ }
9493
+ catch {
9494
+ return undefined;
9495
+ }
9496
+ }
9497
+ function probeNativeCreationPath(root, relativePath) {
9498
+ if (typeof relativePath !== "string")
9499
+ return undefined;
9500
+ const segments = relativePath.split(external_node_path_namespaceObject.sep === "\\" ? /[\\/]/ : "/");
9501
+ if (segments.some(segment => !isSafePathSegment(segment, { allowDotPrefix: true }) || segment.endsWith(".")))
9502
+ return undefined;
9503
+ const target = external_node_path_namespaceObject.join(root.rootReal, ...segments);
9504
+ root_context_assertRootIdentityCurrentSync(root);
9505
+ try {
9506
+ if (external_node_fs_namespaceObject.lstatSync(windows_path_alias_pathForWindowsFilesystem(target), { throwIfNoEntry: false }))
9507
+ return undefined;
9508
+ }
9509
+ catch {
9510
+ return undefined;
9511
+ }
9512
+ const parent = existingCreationParent({ root, target, directory: external_node_path_namespaceObject.dirname(target), mkdir: true,
9513
+ originalPath: relativePath, resolveCurrent: async () => target });
9514
+ if (!parent)
9515
+ return undefined;
9516
+ return { rootReal: root.rootReal, rootWithSep: root.rootWithSep, resolved: target, parent };
9517
+ }
9518
+
9311
9519
  ;// CONCATENATED MODULE: ../../node_modules/@openclaw/fs-safe/dist/root-create-native.js
9312
9520
  var root_create_native_addDisposableResource = (undefined && undefined.__addDisposableResource) || function (env, value, async) {
9313
9521
  if (value !== null && value !== void 0) {
@@ -9385,6 +9593,8 @@ var root_create_native_disposeResources = (undefined && undefined.__disposeResou
9385
9593
 
9386
9594
 
9387
9595
 
9596
+
9597
+
9388
9598
 
9389
9599
 
9390
9600
 
@@ -9394,6 +9604,10 @@ function rootWriteQueueKey(root, relativePath) {
9394
9604
  function buildAtomicWriteTempPath(targetPath) {
9395
9605
  return external_node_path_namespaceObject.join(external_node_path_namespaceObject.dirname(targetPath), `.fs-safe-${(0,external_node_crypto_namespaceObject.randomUUID)()}.tmp`);
9396
9606
  }
9607
+ const nativeCreateCollisions = new WeakSet();
9608
+ function isNativeCreateCollision(error) {
9609
+ return typeof error === "object" && error !== null && nativeCreateCollisions.has(error);
9610
+ }
9397
9611
  function root_create_native_unavailable() {
9398
9612
  throw new errors_FsSafeError("helper-unavailable", "native confined creation is unavailable");
9399
9613
  }
@@ -9401,6 +9615,60 @@ async function withNativeDirectory(params, operation, discard) {
9401
9615
  const binding = native_getNativeBinding("openBeneath", "mkdirChildBeneath");
9402
9616
  if (!binding?.openBeneath || !binding.mkdirChildBeneath || (params.private && process.platform === "win32"))
9403
9617
  return root_create_native_unavailable();
9618
+ const existing = params.selectedParent ?? existingCreationParent(params);
9619
+ if (existing) {
9620
+ let pending;
9621
+ try {
9622
+ const env_1 = { stack: [], error: void 0, hasError: false };
9623
+ try {
9624
+ const rootOwner = root_create_native_addDisposableResource(env_1, openExactNativeRootSync(binding, {
9625
+ rootPath: params.root.rootReal, rootIdentity: params.root.rootIdentity,
9626
+ }), false);
9627
+ const close = captureNativeFdClose(binding);
9628
+ const borrowed = existing.path === params.root.rootReal;
9629
+ const fd = borrowed ? rootOwner.fd : binding.openBeneath(rootOwner.fd, existing.relative, existing.flags).fd;
9630
+ const parentOwner = root_create_native_addDisposableResource(env_1, { [Symbol.dispose]() { if (!borrowed)
9631
+ close(fd); } }, false);
9632
+ strict_file_identity_inspectFileIdentitySync(() => borrowed ? rootOwner.stat : external_node_fs_namespaceObject.fstatSync(fd, { bigint: true }), existing.identity);
9633
+ verifyMkdirDirectory(binding, fd, existing.path);
9634
+ const guard = { dir: existing.path, realPath: existing.path, stat: existing.identity };
9635
+ const assertCurrent = () => {
9636
+ let currentRoot;
9637
+ root_context_assertRootIdentityCurrentSync(params.root, stat => { currentRoot = stat; });
9638
+ if (borrowed) {
9639
+ // Root and parent are the same name in this synchronous fence.
9640
+ directory_guard_inspectDirectoryIdentitySync(existing.path, existing.identity, currentRoot);
9641
+ if (realpath_realpathSync.native(windows_path_alias_pathForWindowsFilesystem(existing.path)) !== existing.path) {
9642
+ throw new errors_FsSafeError("path-mismatch", "directory changed during operation");
9643
+ }
9644
+ }
9645
+ else {
9646
+ directory_guard_assertSyncDirectoryGuard(guard);
9647
+ }
9648
+ };
9649
+ pending = { value: await operation(binding, fd, assertCurrent) };
9650
+ return pending.value;
9651
+ }
9652
+ catch (e_1) {
9653
+ env_1.error = e_1;
9654
+ env_1.hasError = true;
9655
+ }
9656
+ finally {
9657
+ root_create_native_disposeResources(env_1);
9658
+ }
9659
+ }
9660
+ catch (error) {
9661
+ if (pending && discard) {
9662
+ try {
9663
+ await discard(pending.value);
9664
+ }
9665
+ catch (cleanupError) {
9666
+ throw createSuppressedError(cleanupError, error, "creation handoff and cleanup failed");
9667
+ }
9668
+ }
9669
+ throw error;
9670
+ }
9671
+ }
9404
9672
  const directoryTarget = params.directory === params.target;
9405
9673
  const canonicalTarget = async (target) => directoryTarget
9406
9674
  ? await resolvePathViaExistingAncestor(target)
@@ -9417,14 +9685,14 @@ async function withNativeDirectory(params, operation, discard) {
9417
9685
  const close = captureNativeFdClose(binding);
9418
9686
  let pending;
9419
9687
  try {
9420
- const env_1 = { stack: [], error: void 0, hasError: false };
9688
+ const env_2 = { stack: [], error: void 0, hasError: false };
9421
9689
  try {
9422
9690
  const admitted = await openNativeRootAdmission(binding, {
9423
9691
  rootPath: params.root.rootReal, rootIdentity: params.root.rootIdentity, operation: "create", reportCloseErrors: true, searchOnly: true,
9424
9692
  });
9425
- const rootOwner = root_create_native_addDisposableResource(env_1, admitted.root, true);
9693
+ const rootOwner = root_create_native_addDisposableResource(env_2, admitted.root, true);
9426
9694
  const descriptors = [];
9427
- const directoryOwner = root_create_native_addDisposableResource(env_1, { [Symbol.dispose]() {
9695
+ const directoryOwner = root_create_native_addDisposableResource(env_2, { [Symbol.dispose]() {
9428
9696
  const errors = [];
9429
9697
  for (const fd of descriptors.reverse())
9430
9698
  try {
@@ -9522,12 +9790,12 @@ async function withNativeDirectory(params, operation, discard) {
9522
9790
  pending = { value: await operation(binding, current, assertCurrent) };
9523
9791
  return pending.value;
9524
9792
  }
9525
- catch (e_1) {
9526
- env_1.error = e_1;
9527
- env_1.hasError = true;
9793
+ catch (e_2) {
9794
+ env_2.error = e_2;
9795
+ env_2.hasError = true;
9528
9796
  }
9529
9797
  finally {
9530
- const result_1 = root_create_native_disposeResources(env_1);
9798
+ const result_1 = root_create_native_disposeResources(env_2);
9531
9799
  if (result_1)
9532
9800
  await result_1;
9533
9801
  }
@@ -9606,33 +9874,77 @@ function verifyMkdirDirectory(binding, fd, pathname) {
9606
9874
  describePolicyStagedDirectory(fd, pathname);
9607
9875
  }
9608
9876
  function ensureNativeRootCurrent(root) {
9609
- const env_2 = { stack: [], error: void 0, hasError: false };
9877
+ root_context_assertRootIdentityCurrentSync(root);
9878
+ const binding = native_getNativeBinding("openBeneath", "mkdirChildBeneath");
9879
+ if (!binding?.openBeneath || !binding.mkdirChildBeneath)
9880
+ return root_create_native_unavailable();
9881
+ if (binding.verifyRootDirectory) {
9882
+ const closeNative = captureNativeFdClose(binding);
9883
+ const failure = binding.verifyRootDirectory(root.rootReal, root.rootIdentity.dev, root.rootIdentity.ino);
9884
+ if (failure === null)
9885
+ return;
9886
+ if (failure?.fallbackFd !== undefined && failure.fallbackFd !== null) {
9887
+ const env_3 = { stack: [], error: void 0, hasError: false };
9888
+ try {
9889
+ const fd = failure.fallbackFd;
9890
+ if (!Number.isInteger(fd) || fd < 0)
9891
+ throw new errors_FsSafeError("helper-failed", "invalid root fallback descriptor");
9892
+ const owner = root_create_native_addDisposableResource(env_3, { [Symbol.dispose]() { closeNative(fd); } }, false);
9893
+ if (failure.errorCode || failure.closeErrorCode)
9894
+ throw new errors_FsSafeError("helper-failed", "invalid root verification result");
9895
+ ensureNativeRootCurrentLegacy(root, binding);
9896
+ return;
9897
+ }
9898
+ catch (e_3) {
9899
+ env_3.error = e_3;
9900
+ env_3.hasError = true;
9901
+ }
9902
+ finally {
9903
+ root_create_native_disposeResources(env_3);
9904
+ }
9905
+ }
9906
+ const error = failure?.errorCode ? rootVerificationError(failure.errorCode, failure.errorMessage, failure.errorErrno) : undefined;
9907
+ const closeError = failure?.closeErrorCode ? Object.assign(new Error(failure.closeErrorMessage), {
9908
+ code: failure.closeErrorCode,
9909
+ ...(typeof failure.closeErrorErrno === "number" ? { errno: failure.closeErrorErrno } : {}),
9910
+ }) : undefined;
9911
+ if (error && closeError)
9912
+ throw createSuppressedError(closeError, error, "root verification and close failed");
9913
+ if (error || closeError)
9914
+ throw error ?? closeError;
9915
+ throw new errors_FsSafeError("helper-failed", "invalid root verification result");
9916
+ }
9917
+ ensureNativeRootCurrentLegacy(root, binding);
9918
+ }
9919
+ function rootVerificationError(code, message, errno) {
9920
+ const error = Object.assign(new Error(message), { code, ...(typeof errno === "number" ? { errno } : {}) });
9921
+ return code === "path-mismatch" || code === "OBSERVATION_REDIRECTED"
9922
+ ? new errors_FsSafeError("path-mismatch", "root identity changed during verification", { cause: error }) : error;
9923
+ }
9924
+ function ensureNativeRootCurrentLegacy(root, binding) {
9925
+ const env_4 = { stack: [], error: void 0, hasError: false };
9610
9926
  try {
9611
- root_context_assertRootIdentityCurrentSync(root);
9612
- const binding = native_getNativeBinding("openBeneath", "mkdirChildBeneath");
9613
- if (!binding?.openBeneath || !binding.mkdirChildBeneath)
9614
- return root_create_native_unavailable();
9615
- const rootOwner = root_create_native_addDisposableResource(env_2, openExactNativeRootSync(binding, {
9927
+ const rootOwner = root_create_native_addDisposableResource(env_4, openExactNativeRootSync(binding, {
9616
9928
  rootPath: root.rootReal, rootIdentity: root.rootIdentity,
9617
9929
  }), false);
9618
9930
  verifyMkdirDirectory(binding, rootOwner.fd, root.rootReal);
9619
9931
  root_context_assertRootIdentityCurrentSync(root);
9620
9932
  }
9621
- catch (e_2) {
9622
- env_2.error = e_2;
9623
- env_2.hasError = true;
9933
+ catch (e_4) {
9934
+ env_4.error = e_4;
9935
+ env_4.hasError = true;
9624
9936
  }
9625
9937
  finally {
9626
- root_create_native_disposeResources(env_2);
9938
+ root_create_native_disposeResources(env_4);
9627
9939
  }
9628
9940
  }
9629
9941
  function mkdirNativeRootChild(params) {
9630
- const env_3 = { stack: [], error: void 0, hasError: false };
9942
+ const env_5 = { stack: [], error: void 0, hasError: false };
9631
9943
  try {
9632
9944
  const binding = native_getNativeBinding("openBeneath", "mkdirChildBeneath");
9633
9945
  if (!binding?.openBeneath || !binding.mkdirChildBeneath)
9634
9946
  return root_create_native_unavailable();
9635
- const rootOwner = root_create_native_addDisposableResource(env_3, openExactNativeRootSync(binding, {
9947
+ const rootOwner = root_create_native_addDisposableResource(env_5, openExactNativeRootSync(binding, {
9636
9948
  rootPath: params.root.rootReal, rootIdentity: params.root.rootIdentity,
9637
9949
  }), false);
9638
9950
  verifyMkdirDirectory(binding, rootOwner.fd, params.root.rootReal);
@@ -9645,17 +9957,17 @@ function mkdirNativeRootChild(params) {
9645
9957
  ? binding.mkdirOpenChildBeneath(rootOwner.fd, name, 0o777, flags).fd
9646
9958
  : (binding.mkdirChildBeneath(rootOwner.fd, name, 0o777), binding.openBeneath(rootOwner.fd, name, flags).fd);
9647
9959
  const close = captureNativeFdClose(binding);
9648
- const childOwner = root_create_native_addDisposableResource(env_3, { [Symbol.dispose]() { close(child); } }, false);
9960
+ const childOwner = root_create_native_addDisposableResource(env_5, { [Symbol.dispose]() { close(child); } }, false);
9649
9961
  root_context_assertRootIdentityCurrentSync(params.root);
9650
9962
  verifyMkdirDirectory(binding, child, params.target);
9651
9963
  verifyMkdirDirectory(binding, rootOwner.fd, params.root.rootReal);
9652
9964
  }
9653
- catch (e_3) {
9654
- env_3.error = e_3;
9655
- env_3.hasError = true;
9965
+ catch (e_5) {
9966
+ env_5.error = e_5;
9967
+ env_5.hasError = true;
9656
9968
  }
9657
9969
  finally {
9658
- root_create_native_disposeResources(env_3);
9970
+ root_create_native_disposeResources(env_5);
9659
9971
  }
9660
9972
  }
9661
9973
  async function tryOpenCreateRootNative(params) {
@@ -9677,7 +9989,7 @@ async function tryOpenCreateRootNative(params) {
9677
9989
  if (creationMode() === undefined)
9678
9990
  return root_create_native_unavailable();
9679
9991
  return await withNativeDirectory(params, async (binding, parent, assertCurrent) => {
9680
- const env_4 = { stack: [], error: void 0, hasError: false };
9992
+ const env_6 = { stack: [], error: void 0, hasError: false };
9681
9993
  try {
9682
9994
  params.assertBeforeMutation?.();
9683
9995
  assertCurrent();
@@ -9687,13 +9999,21 @@ async function tryOpenCreateRootNative(params) {
9687
9999
  // Native creation owns the only O_CREAT dispatch. The subsequent Node open
9688
10000
  // carries neither O_CREAT nor O_TRUNC and must match this retained inode.
9689
10001
  const close = captureNativeFdClose(binding);
9690
- const fd = binding.openCreateBeneath(parent, external_node_path_namespaceObject.basename(params.target), params.flags, params.mode & 0o7777);
10002
+ let fd;
10003
+ try {
10004
+ fd = binding.openCreateBeneath(parent, external_node_path_namespaceObject.basename(params.target), params.flags, params.mode & 0o7777);
10005
+ }
10006
+ catch (error) {
10007
+ if (hasNodeErrorCode(error, "EEXIST") && typeof error === "object" && error !== null)
10008
+ nativeCreateCollisions.add(error);
10009
+ throw error;
10010
+ }
9691
10011
  let rawOpen = true;
9692
10012
  const closeRaw = () => { if (rawOpen) {
9693
10013
  rawOpen = false;
9694
10014
  close(fd);
9695
10015
  } };
9696
- const owner = root_create_native_addDisposableResource(env_4, { [Symbol.dispose]: closeRaw }, false);
10016
+ const owner = root_create_native_addDisposableResource(env_6, { [Symbol.dispose]: closeRaw }, false);
9697
10017
  try {
9698
10018
  const identity = strict_file_identity_inspectFileIdentitySync(() => external_node_fs_namespaceObject.fstatSync(fd, { bigint: true }));
9699
10019
  if (!identity.isFile() || identity.nlink !== 1n)
@@ -9747,26 +10067,26 @@ async function tryOpenCreateRootNative(params) {
9747
10067
  throw error;
9748
10068
  }
9749
10069
  }
9750
- catch (e_4) {
9751
- env_4.error = e_4;
9752
- env_4.hasError = true;
10070
+ catch (e_6) {
10071
+ env_6.error = e_6;
10072
+ env_6.hasError = true;
9753
10073
  }
9754
10074
  finally {
9755
- root_create_native_disposeResources(env_4);
10075
+ root_create_native_disposeResources(env_6);
9756
10076
  }
9757
10077
  }, async (created) => {
9758
- const env_5 = { stack: [], error: void 0, hasError: false };
10078
+ const env_7 = { stack: [], error: void 0, hasError: false };
9759
10079
  try {
9760
- const handle = root_create_native_addDisposableResource(env_5, created.handle, true);
9761
- const parent = root_create_native_addDisposableResource(env_5, { [Symbol.dispose]: created.releaseCreationParent }, false);
10080
+ const handle = root_create_native_addDisposableResource(env_7, created.handle, true);
10081
+ const parent = root_create_native_addDisposableResource(env_7, { [Symbol.dispose]: created.releaseCreationParent }, false);
9762
10082
  await created.cleanupCreated();
9763
10083
  }
9764
- catch (e_5) {
9765
- env_5.error = e_5;
9766
- env_5.hasError = true;
10084
+ catch (e_7) {
10085
+ env_7.error = e_7;
10086
+ env_7.hasError = true;
9767
10087
  }
9768
10088
  finally {
9769
- const result_2 = root_create_native_disposeResources(env_5);
10089
+ const result_2 = root_create_native_disposeResources(env_7);
9770
10090
  if (result_2)
9771
10091
  await result_2;
9772
10092
  }
@@ -10502,7 +10822,7 @@ function privateDirectoryBackend() {
10502
10822
  if (getFsSafeNativeConfig().mode === "require") {
10503
10823
  throw new errors_FsSafeError("helper-unavailable", "private directory creation requires an up-to-date native parent identity capability");
10504
10824
  }
10505
- warnNativeFallback("windows-private-directory", "Private Windows directory creation uses a slower built-in system command.");
10825
+ warnNativeFallback("windows-private-directory", "Private Windows directory creation launches the packaged .NET helper for each check or creation.", "createPrivateDirectoryWithParentIdentity");
10506
10826
  return undefined;
10507
10827
  }
10508
10828
  async function createDirectory(targetPath, options = {}) {
@@ -16312,6 +16632,247 @@ async function read_opened_file_readOpenedFileSafely(params) {
16312
16632
  };
16313
16633
  }
16314
16634
 
16635
+ ;// CONCATENATED MODULE: ../../node_modules/@openclaw/fs-safe/dist/root-mkdir-native.js
16636
+ var root_mkdir_native_addDisposableResource = (undefined && undefined.__addDisposableResource) || function (env, value, async) {
16637
+ if (value !== null && value !== void 0) {
16638
+ if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
16639
+ var dispose, inner;
16640
+ if (async) {
16641
+ if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
16642
+ dispose = value[Symbol.asyncDispose];
16643
+ }
16644
+ if (dispose === void 0) {
16645
+ if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
16646
+ dispose = value[Symbol.dispose];
16647
+ if (async) inner = dispose;
16648
+ }
16649
+ if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
16650
+ if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
16651
+ env.stack.push({ value: value, dispose: dispose, async: async });
16652
+ }
16653
+ else if (async) {
16654
+ env.stack.push({ async: true });
16655
+ }
16656
+ return value;
16657
+ };
16658
+ var root_mkdir_native_disposeResources = (undefined && undefined.__disposeResources) || (function (SuppressedError) {
16659
+ return function (env) {
16660
+ function fail(e) {
16661
+ env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
16662
+ env.hasError = true;
16663
+ }
16664
+ var r, s = 0;
16665
+ function next() {
16666
+ while (r = env.stack.pop()) {
16667
+ try {
16668
+ if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
16669
+ if (r.dispose) {
16670
+ var result = r.dispose.call(r.value);
16671
+ if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
16672
+ }
16673
+ else s |= 1;
16674
+ }
16675
+ catch (e) {
16676
+ fail(e);
16677
+ }
16678
+ }
16679
+ if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
16680
+ if (env.hasError) throw env.error;
16681
+ }
16682
+ return next();
16683
+ };
16684
+ })(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
16685
+ var e = new Error(message);
16686
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
16687
+ });
16688
+
16689
+
16690
+
16691
+
16692
+
16693
+
16694
+
16695
+
16696
+
16697
+
16698
+
16699
+
16700
+
16701
+
16702
+
16703
+
16704
+
16705
+ function tryMkdirNativeParents(root, relativePath) {
16706
+ try {
16707
+ return mkdirOrdinaryNativeParents(root, relativePath);
16708
+ }
16709
+ catch (error) {
16710
+ if (hasNodeErrorCode(error, "ENOTDIR"))
16711
+ throw root_errors_directoryComponentNotDirectoryError(error);
16712
+ throw error;
16713
+ }
16714
+ }
16715
+ function mkdirOrdinaryNativeParents(root, relativePath) {
16716
+ if (getFsSafeTestHooks()?.beforeRootFallbackMutation)
16717
+ return false;
16718
+ const segments = relativePath.split(external_node_path_namespaceObject.sep === "\\" ? /[\\/]/ : "/");
16719
+ if (segments.length < 2 || segments.some(segment => !isSafePathSegment(segment, { allowDotPrefix: true }) || segment.endsWith(".")))
16720
+ return false;
16721
+ let rootStat;
16722
+ root_context_assertRootIdentityCurrentSync(root, stat => { rootStat = stat; });
16723
+ const target = external_node_path_namespaceObject.join(root.rootReal, ...segments);
16724
+ const parentPath = external_node_path_namespaceObject.dirname(target);
16725
+ try {
16726
+ const child = external_node_fs_namespaceObject.lstatSync(windows_path_alias_pathForWindowsFilesystem(target), { throwIfNoEntry: false });
16727
+ if (child && (!child.isDirectory() || realpath_realpathSync.native(windows_path_alias_pathForWindowsFilesystem(target)) !== target))
16728
+ return false;
16729
+ }
16730
+ catch {
16731
+ return false;
16732
+ }
16733
+ let parentIdentity;
16734
+ try {
16735
+ parentIdentity = directory_guard_inspectDirectoryIdentitySync(parentPath);
16736
+ }
16737
+ catch (error) {
16738
+ // Reuse this exact Root snapshot and failed parent observation without an
16739
+ // intervening await. All opened ancestors still receive fresh native fences.
16740
+ return hasNodeErrorCode(error, "ENOENT") ? mkdirMissingParents(root, segments, rootStat) : false;
16741
+ }
16742
+ try {
16743
+ if (realpath_realpathSync.native(windows_path_alias_pathForWindowsFilesystem(parentPath)) !== parentPath)
16744
+ return false;
16745
+ }
16746
+ catch {
16747
+ return false;
16748
+ }
16749
+ return mkdirExistingParent(root, segments, parentIdentity);
16750
+ }
16751
+ /** Ordinary missing suffixes need no policy callbacks or repeated path resolution. */
16752
+ function mkdirMissingParents(root, segments, rootStat) {
16753
+ const binding = native_getNativeBinding("openBeneath", "mkdirChildBeneath");
16754
+ if (!binding?.openBeneath || !binding.mkdirOpenChildBeneath)
16755
+ return false;
16756
+ let parentDepth = segments.length - 2;
16757
+ let parentPath;
16758
+ let parentIdentity;
16759
+ for (;;) {
16760
+ parentPath = external_node_path_namespaceObject.join(root.rootReal, ...segments.slice(0, parentDepth));
16761
+ try {
16762
+ parentIdentity = directory_guard_inspectDirectoryIdentitySync(parentPath, undefined, parentDepth === 0 ? rootStat : undefined);
16763
+ if (realpath_realpathSync.native(windows_path_alias_pathForWindowsFilesystem(parentPath)) !== parentPath)
16764
+ return false;
16765
+ break;
16766
+ }
16767
+ catch (error) {
16768
+ if (!hasNodeErrorCode(error, "ENOENT") || parentDepth === 0)
16769
+ return false;
16770
+ parentDepth--;
16771
+ }
16772
+ }
16773
+ try {
16774
+ const env_1 = { stack: [], error: void 0, hasError: false };
16775
+ try {
16776
+ const rootOwner = root_mkdir_native_addDisposableResource(env_1, openExactNativeRootSync(binding, {
16777
+ rootPath: root.rootReal, rootIdentity: root.rootIdentity,
16778
+ }), false);
16779
+ const close = captureNativeFdClose(binding);
16780
+ const directories = [];
16781
+ const directoryOwner = root_mkdir_native_addDisposableResource(env_1, { [Symbol.dispose]() {
16782
+ const errors = [];
16783
+ for (const directory of directories.toReversed()) {
16784
+ try {
16785
+ close(directory.fd);
16786
+ }
16787
+ catch (error) {
16788
+ errors.push(error);
16789
+ }
16790
+ }
16791
+ if (errors.length)
16792
+ throw new AggregateError(errors, "mkdir directory close failed");
16793
+ } }, false);
16794
+ const flags = (nodeDirectorySearchOnlyFlags()?.flags ?? external_node_fs_namespaceObject.constants.O_RDONLY) |
16795
+ (external_node_fs_namespaceObject.constants.O_DIRECTORY ?? 0) | (external_node_fs_namespaceObject.constants.O_NOFOLLOW ?? 0);
16796
+ let current = rootOwner.fd;
16797
+ if (parentDepth > 0) {
16798
+ current = binding.openBeneath(rootOwner.fd, segments.slice(0, parentDepth).join("/"), flags).fd;
16799
+ directories.push({ fd: current, pathname: parentPath });
16800
+ strict_file_identity_inspectFileIdentitySync(() => external_node_fs_namespaceObject.fstatSync(current, { bigint: true }), parentIdentity);
16801
+ }
16802
+ const assertCurrent = () => {
16803
+ root_context_assertRootIdentityCurrentSync(root);
16804
+ for (const directory of directories)
16805
+ verifyMkdirDirectory(binding, directory.fd, directory.pathname);
16806
+ verifyMkdirDirectory(binding, rootOwner.fd, root.rootReal);
16807
+ };
16808
+ assertCurrent();
16809
+ for (const segment of segments.slice(parentDepth)) {
16810
+ const child = binding.mkdirOpenChildBeneath(current, segment, 0o777, flags);
16811
+ parentPath = external_node_path_namespaceObject.join(parentPath, segment);
16812
+ directories.push({ fd: child.fd, pathname: parentPath });
16813
+ // Retain every ancestor until the complete suffix is admitted. The
16814
+ // post-create fence also precedes the next synchronous child mutation.
16815
+ assertCurrent();
16816
+ current = child.fd;
16817
+ }
16818
+ return true;
16819
+ }
16820
+ catch (e_1) {
16821
+ env_1.error = e_1;
16822
+ env_1.hasError = true;
16823
+ }
16824
+ finally {
16825
+ root_mkdir_native_disposeResources(env_1);
16826
+ }
16827
+ }
16828
+ catch (error) {
16829
+ if (hasNodeErrorCode(error, "ENOTDIR"))
16830
+ throw root_errors_directoryComponentNotDirectoryError(error);
16831
+ throw error;
16832
+ }
16833
+ }
16834
+ function mkdirExistingParent(root, segments, parentIdentity) {
16835
+ const env_2 = { stack: [], error: void 0, hasError: false };
16836
+ try {
16837
+ const target = external_node_path_namespaceObject.join(root.rootReal, ...segments);
16838
+ const parentPath = external_node_path_namespaceObject.dirname(target);
16839
+ const binding = native_getNativeBinding("openBeneath", "mkdirChildBeneath");
16840
+ if (!binding?.openBeneath || !binding.mkdirChildBeneath) {
16841
+ throw new errors_FsSafeError("helper-unavailable", "native confined creation is unavailable");
16842
+ }
16843
+ const rootOwner = root_mkdir_native_addDisposableResource(env_2, openExactNativeRootSync(binding, {
16844
+ rootPath: root.rootReal, rootIdentity: root.rootIdentity,
16845
+ }), false);
16846
+ verifyMkdirDirectory(binding, rootOwner.fd, root.rootReal);
16847
+ const flags = (nodeDirectorySearchOnlyFlags()?.flags ?? external_node_fs_namespaceObject.constants.O_RDONLY) |
16848
+ (external_node_fs_namespaceObject.constants.O_DIRECTORY ?? 0) | (external_node_fs_namespaceObject.constants.O_NOFOLLOW ?? 0);
16849
+ const close = captureNativeFdClose(binding);
16850
+ const parent = binding.openBeneath(rootOwner.fd, segments.slice(0, -1).join("/"), flags).fd;
16851
+ const parentOwner = root_mkdir_native_addDisposableResource(env_2, { [Symbol.dispose]() { close(parent); } }, false);
16852
+ strict_file_identity_inspectFileIdentitySync(() => external_node_fs_namespaceObject.fstatSync(parent, { bigint: true }), parentIdentity);
16853
+ verifyMkdirDirectory(binding, parent, parentPath);
16854
+ root_context_assertRootIdentityCurrentSync(root);
16855
+ const name = segments.at(-1);
16856
+ const child = binding.mkdirOpenChildBeneath
16857
+ ? binding.mkdirOpenChildBeneath(parent, name, 0o777, flags).fd
16858
+ : (binding.mkdirChildBeneath(parent, name, 0o777), binding.openBeneath(parent, name, flags).fd);
16859
+ const childOwner = root_mkdir_native_addDisposableResource(env_2, { [Symbol.dispose]() { close(child); } }, false);
16860
+ root_context_assertRootIdentityCurrentSync(root);
16861
+ verifyMkdirDirectory(binding, child, target);
16862
+ directory_guard_inspectDirectoryIdentitySync(parentPath, parentIdentity);
16863
+ verifyMkdirDirectory(binding, parent, parentPath);
16864
+ verifyMkdirDirectory(binding, rootOwner.fd, root.rootReal);
16865
+ return true;
16866
+ }
16867
+ catch (e_2) {
16868
+ env_2.error = e_2;
16869
+ env_2.hasError = true;
16870
+ }
16871
+ finally {
16872
+ root_mkdir_native_disposeResources(env_2);
16873
+ }
16874
+ }
16875
+
16315
16876
  ;// CONCATENATED MODULE: ../../node_modules/@openclaw/fs-safe/dist/write-open-flags.js
16316
16877
 
16317
16878
 
@@ -19384,6 +19945,7 @@ var root_impl_disposeResources = (undefined && undefined.__disposeResources) ||
19384
19945
 
19385
19946
 
19386
19947
 
19948
+
19387
19949
 
19388
19950
 
19389
19951
  function logWarn(message) {
@@ -19784,7 +20346,9 @@ async function openWritableFileInRoot(root, params, options) {
19784
20346
  denyMutations: params.denyMutations,
19785
20347
  mutationSymlinks: params.mutationSymlinks,
19786
20348
  });
19787
- const { resolved } = guardedTarget?.resolvedPath ?? await resolveGuardedWritePathInRoot(root, {
20349
+ const creationProbe = requireNative && !guardedTarget && params.assertBeforeMutation === undefined && options?.createIfMissing !== false
20350
+ ? probeNativeCreationPath(root, params.relativePath) : undefined;
20351
+ const { resolved } = creationProbe ?? guardedTarget?.resolvedPath ?? await resolveGuardedWritePathInRoot(root, {
19788
20352
  relativePath: params.relativePath,
19789
20353
  });
19790
20354
  const resolveCurrent = async () => (await resolveGuardedWritePathInRoot(root, {
@@ -19813,27 +20377,30 @@ async function openWritableFileInRoot(root, params, options) {
19813
20377
  let ioPath = nativeCreatesParents ? resolved : prepared?.targetPath ?? (params.mkdir === false ? resolved :
19814
20378
  await prepareRootWriteTarget(root, resolved, params.assertBeforeMutation));
19815
20379
  const operationTargetPath = ioPath;
19816
- try {
19817
- assertFinalSymlinkRejected(ioPath, params.mutationSymlinks !== undefined);
19818
- const resolvedRealPath = params.mutationSymlinks === undefined ? realpath_realpathSync.native(ioPath) : ioPath;
19819
- const admittedRealPath = root_boundary_admitPathInsideRoot({
19820
- rootPath: root.rootReal,
19821
- candidatePath: resolvedRealPath,
19822
- rootIdentity: root.rootIdentity,
19823
- });
19824
- if (!admittedRealPath) {
19825
- throw root_errors_outsideWorkspaceError();
19826
- }
19827
- ioPath = admittedRealPath.path;
19828
- }
19829
- catch (err) {
19830
- if (err instanceof errors_FsSafeError) {
19831
- throw err;
20380
+ let observedMissing = Boolean(creationProbe);
20381
+ if (!creationProbe)
20382
+ try {
20383
+ assertFinalSymlinkRejected(ioPath, params.mutationSymlinks !== undefined);
20384
+ const resolvedRealPath = params.mutationSymlinks === undefined ? realpath_realpathSync.native(ioPath) : ioPath;
20385
+ const admittedRealPath = root_boundary_admitPathInsideRoot({
20386
+ rootPath: root.rootReal,
20387
+ candidatePath: resolvedRealPath,
20388
+ rootIdentity: root.rootIdentity,
20389
+ });
20390
+ if (!admittedRealPath) {
20391
+ throw root_errors_outsideWorkspaceError();
20392
+ }
20393
+ ioPath = admittedRealPath.path;
19832
20394
  }
19833
- if (!path_isNotFoundPathError(err)) {
19834
- throw err;
20395
+ catch (err) {
20396
+ if (err instanceof errors_FsSafeError) {
20397
+ throw err;
20398
+ }
20399
+ if (!path_isNotFoundPathError(err)) {
20400
+ throw err;
20401
+ }
20402
+ observedMissing = true;
19835
20403
  }
19836
- }
19837
20404
  assertRootFallbackWritePath(params.expectedWritePath, ioPath);
19838
20405
  const mode = params.mode ?? 0o600;
19839
20406
  let handle;
@@ -19847,61 +20414,82 @@ async function openWritableFileInRoot(root, params, options) {
19847
20414
  writePathSelection = guardedTarget
19848
20415
  ? await prepareGuardedRootWritePathSelection(guardedTarget, ioPath, operationTargetPath, preparedParent)
19849
20416
  : undefined;
19850
- try {
19851
- if (writePathSelection)
19852
- assertRootWritePathSelectionSync(root, writePathSelection);
19853
- handle = await promises_namespaceObject.open(ioPath, existingFlags, mode);
19854
- }
19855
- catch (err) {
19856
- if (await isNonRegularWriteOpenError(err, ioPath, existingFlags)) {
19857
- throw new errors_FsSafeError("not-file", "path is not a regular file under root");
20417
+ const createNative = () => tryOpenCreateRootNative({
20418
+ originalPath: params.relativePath,
20419
+ root, directory: external_node_path_namespaceObject.dirname(ioPath), target: ioPath, mkdir: params.mkdir !== false, policy,
20420
+ selectedParent: creationProbe?.parent,
20421
+ resolveCurrent,
20422
+ assertBeforeMutation: params.assertBeforeMutation !== undefined || writePathSelection !== undefined ? () => {
20423
+ params.assertBeforeMutation?.();
20424
+ if (writePathSelection)
20425
+ assertRootWritePathSelectionSync(root, writePathSelection);
20426
+ } : undefined,
20427
+ flags: createFlags, existingFlags, mode,
20428
+ });
20429
+ let precreated;
20430
+ if (requireNative && observedMissing && !guardedTarget && params.assertBeforeMutation === undefined && options?.createIfMissing !== false) {
20431
+ try {
20432
+ precreated = await createNative();
19858
20433
  }
19859
- if (!path_isNotFoundPathError(err)) {
19860
- throw err;
20434
+ catch (error) {
20435
+ if (!hasNodeErrorCode(error, "EEXIST") || !isNativeCreateCollision(error))
20436
+ throw error;
19861
20437
  }
19862
- if (options?.createIfMissing === false) {
19863
- if (nativeCreatesParents && !guardedTarget)
19864
- await tryMkdirRootNative({
19865
- originalPath: params.relativePath,
19866
- root, directory: external_node_path_namespaceObject.dirname(ioPath), target: ioPath, mkdir: true, policy,
19867
- resolveCurrent, assertBeforeMutation: params.assertBeforeMutation,
19868
- });
19869
- const parentGuard = writePathSelection?.parentGuard ??
19870
- await directory_guard_createAsyncDirectoryGuard(external_node_path_namespaceObject.dirname(ioPath), { bigint: true });
19871
- root_context_assertRootIdentityCurrentSync(root);
19872
- if (!root_boundary_admitPathInsideRoot({
19873
- rootPath: root.rootReal, candidatePath: parentGuard.realPath, rootIdentity: root.rootIdentity,
19874
- }))
19875
- throw root_errors_outsideWorkspaceError();
19876
- directory_guard_assertSyncDirectoryGuard(parentGuard);
19877
- return { missing: true, targetPath: ioPath, parentGuard, writeSelection: writePathSelection };
20438
+ }
20439
+ if (precreated) {
20440
+ handle = precreated.handle;
20441
+ cleanupCreated = precreated.cleanupCreated;
20442
+ releaseCreationParent = precreated.releaseCreationParent;
20443
+ createdForWrite = true;
20444
+ }
20445
+ else {
20446
+ try {
20447
+ if (writePathSelection)
20448
+ assertRootWritePathSelectionSync(root, writePathSelection);
20449
+ handle = await promises_namespaceObject.open(ioPath, existingFlags, mode);
19878
20450
  }
19879
- if (writePathSelection)
19880
- await refreshRootWritePathSelection(writePathSelection);
19881
- const nativeCreated = requireNative ? await tryOpenCreateRootNative({
19882
- originalPath: params.relativePath,
19883
- root, directory: external_node_path_namespaceObject.dirname(ioPath), target: ioPath, mkdir: params.mkdir !== false, policy,
19884
- resolveCurrent, assertBeforeMutation() {
20451
+ catch (err) {
20452
+ if (await isNonRegularWriteOpenError(err, ioPath, existingFlags)) {
20453
+ throw new errors_FsSafeError("not-file", "path is not a regular file under root");
20454
+ }
20455
+ if (!path_isNotFoundPathError(err)) {
20456
+ throw err;
20457
+ }
20458
+ if (options?.createIfMissing === false) {
20459
+ if (nativeCreatesParents && !guardedTarget)
20460
+ await tryMkdirRootNative({
20461
+ originalPath: params.relativePath,
20462
+ root, directory: external_node_path_namespaceObject.dirname(ioPath), target: ioPath, mkdir: true, policy,
20463
+ resolveCurrent, assertBeforeMutation: params.assertBeforeMutation,
20464
+ });
20465
+ const parentGuard = writePathSelection?.parentGuard ??
20466
+ await directory_guard_createAsyncDirectoryGuard(external_node_path_namespaceObject.dirname(ioPath), { bigint: true });
20467
+ root_context_assertRootIdentityCurrentSync(root);
20468
+ if (!root_boundary_admitPathInsideRoot({
20469
+ rootPath: root.rootReal, candidatePath: parentGuard.realPath, rootIdentity: root.rootIdentity,
20470
+ }))
20471
+ throw root_errors_outsideWorkspaceError();
20472
+ directory_guard_assertSyncDirectoryGuard(parentGuard);
20473
+ return { missing: true, targetPath: ioPath, parentGuard, writeSelection: writePathSelection };
20474
+ }
20475
+ if (writePathSelection)
20476
+ await refreshRootWritePathSelection(writePathSelection);
20477
+ const nativeCreated = requireNative ? await createNative() : undefined;
20478
+ if (nativeCreated)
20479
+ handle = nativeCreated.handle;
20480
+ else {
19885
20481
  params.assertBeforeMutation?.();
19886
20482
  if (writePathSelection)
19887
20483
  assertRootWritePathSelectionSync(root, writePathSelection);
19888
- },
19889
- flags: createFlags, existingFlags, mode,
19890
- }) : undefined;
19891
- if (nativeCreated)
19892
- handle = nativeCreated.handle;
19893
- else {
19894
- params.assertBeforeMutation?.();
19895
- if (writePathSelection)
19896
- assertRootWritePathSelectionSync(root, writePathSelection);
19897
- // Windows can follow a dangling symlink even with O_EXCL.
19898
- if (!SUPPORTS_NOFOLLOW)
19899
- assertFinalSymlinkRejected(ioPath, true);
19900
- handle = await promises_namespaceObject.open(ioPath, createFlags, mode);
20484
+ // Windows can follow a dangling symlink even with O_EXCL.
20485
+ if (!SUPPORTS_NOFOLLOW)
20486
+ assertFinalSymlinkRejected(ioPath, true);
20487
+ handle = await promises_namespaceObject.open(ioPath, createFlags, mode);
20488
+ }
20489
+ cleanupCreated = nativeCreated?.cleanupCreated;
20490
+ releaseCreationParent = nativeCreated?.releaseCreationParent;
20491
+ createdForWrite = true;
19901
20492
  }
19902
- cleanupCreated = nativeCreated?.cleanupCreated;
19903
- releaseCreationParent = nativeCreated?.releaseCreationParent;
19904
- createdForWrite = true;
19905
20493
  }
19906
20494
  }
19907
20495
  catch (err) {
@@ -20148,6 +20736,8 @@ async function mkdirPathInRoot(root, params) {
20148
20736
  }
20149
20737
  if (tryMkdirNativeDirectChild(root, params.relativePath))
20150
20738
  return;
20739
+ if (tryMkdirNativeParents(root, params.relativePath))
20740
+ return;
20151
20741
  }
20152
20742
  const resolution = { relativePath: params.relativePath, allowRoot: params.allowRoot, ...policy };
20153
20743
  const resolveCurrent = policy
@@ -33155,4 +33745,4 @@ if (installedChunkData !== 0) { // 0 means "already installed".'
33155
33745
  // module factories are used so entry inlining is disabled
33156
33746
  // startup
33157
33747
  // Load entry module and return exports
33158
- var __webpack_exports__ = __webpack_require__(981);
33748
+ var __webpack_exports__ = __webpack_require__(402);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lousy-agents/agent-shell",
3
- "version": "5.22.0",
3
+ "version": "5.22.1",
4
4
  "description": "A flight recorder for npm script execution",
5
5
  "type": "module",
6
6
  "repository": {
@@ -37,11 +37,11 @@
37
37
  "typecheck": "tsc --noEmit"
38
38
  },
39
39
  "dependencies": {
40
- "@openclaw/fs-safe": "0.26.2",
40
+ "@openclaw/fs-safe": "0.26.3",
41
41
  "zod": "4.5.2"
42
42
  },
43
43
  "peerDependencies": {
44
- "@github/copilot-sdk": "1.0.19"
44
+ "@github/copilot-sdk": "1.0.20"
45
45
  },
46
46
  "peerDependenciesMeta": {
47
47
  "@github/copilot-sdk": {