@lousy-agents/cli 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.
package/dist/index.js CHANGED
@@ -3053,7 +3053,7 @@ exports.basename = (path, { windows } = {}) => {
3053
3053
 
3054
3054
 
3055
3055
  },
3056
- 4101(__unused_rspack_module, __unused_rspack___webpack_exports__, __webpack_require__) {
3056
+ 4517(__unused_rspack_module, __unused_rspack___webpack_exports__, __webpack_require__) {
3057
3057
  // NAMESPACE OBJECT: ../../node_modules/micromark/lib/constructs.js
3058
3058
  var constructs_namespaceObject = {};
3059
3059
  __webpack_require__.r(constructs_namespaceObject);
@@ -3220,6 +3220,17 @@ function getFsSafeNativeConfig() {
3220
3220
  "auto",
3221
3221
  };
3222
3222
  }
3223
+ /** Internal provenance; keep the public configuration shape unchanged. */
3224
+ function getNativeModeSetting() {
3225
+ if (overrideConfig.mode !== undefined)
3226
+ return { mode: overrideConfig.mode, source: "programmatic configuration" };
3227
+ for (const source of ["FS_SAFE_NATIVE_MODE", "OPENCLAW_FS_SAFE_NATIVE_MODE"]) {
3228
+ const mode = parseMode(process.env[source]);
3229
+ if (mode !== undefined)
3230
+ return { mode, source };
3231
+ }
3232
+ return { mode: "auto", source: "default" };
3233
+ }
3223
3234
  function isFsSafeNativeRequired() {
3224
3235
  return (overrideConfig.mode ??
3225
3236
  parseMode(process.env.FS_SAFE_NATIVE_MODE) ??
@@ -3245,6 +3256,62 @@ let native_binding;
3245
3256
  let loadError;
3246
3257
  let attempted = false;
3247
3258
  let loadBinding = loadBundledBinding;
3259
+ let resolvePackage = (name) => native_require.resolve(name);
3260
+ let loadOutcome = { reason: "not-probed" };
3261
+ let selectedTarget;
3262
+ let targetDescription;
3263
+ function loadFailure(error, packageName) {
3264
+ try {
3265
+ return classifyLoadFailure(error, packageName);
3266
+ }
3267
+ catch {
3268
+ // Diagnostic inspection must not replace an arbitrary thrown load value.
3269
+ return { reason: "load-failed", code: "UNKNOWN" };
3270
+ }
3271
+ }
3272
+ function classifyLoadFailure(error, packageName) {
3273
+ const code = typeof error === "object" && error !== null && "code" in error ? error.code : undefined;
3274
+ // Resolution must fail for the selected package itself. An exception inside
3275
+ // an installed package (even one naming this package) is not package omission.
3276
+ if (code === "MODULE_NOT_FOUND" && error instanceof Error &&
3277
+ error.message.split("\n", 1)[0] === `Cannot find module '${packageName}'`) {
3278
+ try {
3279
+ resolvePackage(packageName);
3280
+ }
3281
+ catch (resolutionError) {
3282
+ if (resolutionError instanceof Error && "code" in resolutionError &&
3283
+ resolutionError.code === "MODULE_NOT_FOUND" &&
3284
+ resolutionError.message.split("\n", 1)[0] === `Cannot find module '${packageName}'`) {
3285
+ return { reason: "package-missing" };
3286
+ }
3287
+ }
3288
+ }
3289
+ // An allowlist excludes paths, secrets and arbitrary text in exception codes.
3290
+ const knownCodes = ["ERR_DLOPEN_FAILED", "MODULE_NOT_FOUND", "ERR_MODULE_NOT_FOUND",
3291
+ "ERR_PACKAGE_PATH_NOT_EXPORTED", "ERR_INVALID_PACKAGE_CONFIG", "EACCES", "EPERM", "ENOENT"];
3292
+ return { reason: "load-failed", code: typeof code === "string" && knownCodes.includes(code) ? code : "UNKNOWN" };
3293
+ }
3294
+ /** Internal view of the cached load; never attempts to load an addon. */
3295
+ function getNativeFallbackDiagnostic(...capabilities) {
3296
+ const setting = getNativeModeSetting();
3297
+ const target = targetDescription === undefined ? bundledTarget() : selectedTarget;
3298
+ const packageName = target === undefined ? undefined : nativePackageForTarget(target);
3299
+ const manifest = native_require("../package.json");
3300
+ const expected = {
3301
+ target: targetDescription,
3302
+ packageName,
3303
+ packageVersion: packageName === undefined ? undefined : manifest.optionalDependencies[packageName],
3304
+ };
3305
+ if (setting.mode === "off")
3306
+ return { ...expected, reason: "disabled", source: setting.source };
3307
+ const loaded = native_binding;
3308
+ if (loaded) {
3309
+ const missing = capabilities.filter(name => typeof loaded[name] !== "function");
3310
+ if (missing.length)
3311
+ return { ...expected, reason: "capability-missing", capabilities: missing };
3312
+ }
3313
+ return { ...expected, ...loadOutcome };
3314
+ }
3248
3315
  function isMuslFilename(file) {
3249
3316
  return file.includes("libc.musl-") || file.includes("ld-musl-");
3250
3317
  }
@@ -3374,7 +3441,10 @@ function targetFor(platform, arch, musl) {
3374
3441
  return undefined;
3375
3442
  }
3376
3443
  function bundledTarget() {
3377
- return targetFor(process.platform, process.arch, isMusl());
3444
+ const musl = isMusl();
3445
+ selectedTarget = targetFor(process.platform, process.arch, musl);
3446
+ targetDescription = selectedTarget ?? `${process.platform}-${process.arch}${process.platform === "linux" ? `-${musl ? "musl" : "gnu"}` : ""}`;
3447
+ return selectedTarget;
3378
3448
  }
3379
3449
  function nativePackageForTarget(target) {
3380
3450
  return `@openclaw/fs-safe-${target}`;
@@ -3382,9 +3452,13 @@ function nativePackageForTarget(target) {
3382
3452
  function loadBundledBinding() {
3383
3453
  const target = bundledTarget();
3384
3454
  if (!target) {
3455
+ loadOutcome = { reason: "unsupported-target" };
3385
3456
  throw new Error(`Unsupported OS or architecture: ${process.platform}-${process.arch}`);
3386
3457
  }
3387
3458
  const loaded = runNativeInitialization(() => native_require(nativePackageForTarget(target)));
3459
+ if (typeof loaded.closeOwnedFd !== "function") {
3460
+ loadOutcome = { reason: "capability-missing", capabilities: ["closeOwnedFd"] };
3461
+ }
3388
3462
  captureNativeFdClose(loaded);
3389
3463
  return loaded;
3390
3464
  }
@@ -3426,11 +3500,19 @@ function native_getNativeBinding(...capabilities) {
3426
3500
  attempted = true;
3427
3501
  try {
3428
3502
  const loaded = loadBinding();
3503
+ if (typeof loaded.closeOwnedFd !== "function") {
3504
+ loadOutcome = { reason: "capability-missing", capabilities: ["closeOwnedFd"] };
3505
+ }
3429
3506
  captureNativeFdClose(loaded);
3430
3507
  native_binding = loaded;
3508
+ loadOutcome = { reason: "loaded" };
3431
3509
  }
3432
3510
  catch (error) {
3433
3511
  loadError = error;
3512
+ if (loadOutcome.reason === "not-probed") {
3513
+ selectedTarget ??= bundledTarget();
3514
+ loadOutcome = loadFailure(error, nativePackageForTarget(selectedTarget ?? `${process.platform}-${process.arch}`));
3515
+ }
3434
3516
  }
3435
3517
  }
3436
3518
  if (native_binding)
@@ -3451,17 +3533,25 @@ function native_requireNativeBinding(...capabilities) {
3451
3533
  }
3452
3534
  return native;
3453
3535
  }
3454
- function __setNativeLoaderForTest(loader) {
3536
+ function __setNativeLoaderForTest(loader, resolver) {
3455
3537
  native_binding = undefined;
3456
3538
  loadError = undefined;
3457
3539
  attempted = false;
3458
3540
  loadBinding = loader;
3541
+ loadOutcome = { reason: "not-probed" };
3542
+ selectedTarget = undefined;
3543
+ targetDescription = undefined;
3544
+ resolvePackage = resolver ?? ((name) => native_require.resolve(name));
3459
3545
  }
3460
3546
  function __resetNativeLoaderForTest() {
3461
3547
  native_binding = undefined;
3462
3548
  loadError = undefined;
3463
3549
  attempted = false;
3464
3550
  loadBinding = loadBundledBinding;
3551
+ loadOutcome = { reason: "not-probed" };
3552
+ selectedTarget = undefined;
3553
+ targetDescription = undefined;
3554
+ resolvePackage = (name) => native_require.resolve(name);
3465
3555
  }
3466
3556
 
3467
3557
  ;// CONCATENATED MODULE: ../../node_modules/@openclaw/fs-safe/dist/file-observation.js
@@ -4944,6 +5034,15 @@ function assertDirectoryObservationGuardSync(guard) {
4944
5034
  }
4945
5035
  }
4946
5036
 
5037
+ ;// CONCATENATED MODULE: ../../node_modules/@openclaw/fs-safe/dist/native-stat-identity.js
5038
+ /** Native stat identities are unsigned; Node BigIntStats preserves them as signed bits. */
5039
+ function statIdentityFromNative(value) {
5040
+ return value <= 0x7fffffffffffffffn || process.versions.bun ? value : BigInt.asIntN(64, value);
5041
+ }
5042
+ function isNativeStatIdentity(value) {
5043
+ return typeof value === "bigint" && value >= 0n && value <= 0xffffffffffffffffn;
5044
+ }
5045
+
4947
5046
  ;// CONCATENATED MODULE: ../../node_modules/@openclaw/fs-safe/dist/directory-receipt.js
4948
5047
 
4949
5048
 
@@ -5448,6 +5547,7 @@ function createSuppressedError(error, suppressed, message) {
5448
5547
 
5449
5548
 
5450
5549
 
5550
+
5451
5551
  /** Shared by tree byte copying and per-file copying; never resolves the target. */
5452
5552
  async function readCopyLinkTarget(source) {
5453
5553
  return await promises_.readlink(source, { encoding: "buffer" });
@@ -5517,7 +5617,7 @@ async function copyLinkAtParent(params, input, parent, native) {
5517
5617
  directory_guard_assertSyncDirectoryGuard(parent);
5518
5618
  if (native?.binding.createCopySymlink) {
5519
5619
  const created = native.binding.createCopySymlink(native.fd, temporaryName, input.target, params.mode, input.preserveMetadata ? input.identity.atimeNs : undefined, input.preserveMetadata ? input.identity.mtimeNs : undefined);
5520
- identity = created;
5620
+ identity = { dev: statIdentityFromNative(created.dev), ino: statIdentityFromNative(created.ino) };
5521
5621
  if (created.errorCode)
5522
5622
  throw Object.assign(new Error(created.errorMessage), { code: created.errorCode });
5523
5623
  }
@@ -6243,14 +6343,61 @@ function pinNodeDirectoryForModeSync(dirPath, options = {}) {
6243
6343
  }
6244
6344
  }
6245
6345
 
6346
+ ;// CONCATENATED MODULE: ../../node_modules/@openclaw/fs-safe/dist/native-guidance.js
6347
+ /** Shared, path-free next steps for status reports and fallback warnings. */
6348
+ function nativeGuidance(reason, modeSource) {
6349
+ switch (reason) {
6350
+ case "disabled": {
6351
+ const enable = modeSource === "programmatic configuration"
6352
+ ? 'call configureFsSafeNative({ mode: "auto" }) or configureFsSafeNative({ mode: "require" })'
6353
+ : `set ${modeSource}=auto or ${modeSource}=require`;
6354
+ return `If native loading is intended, ${enable}; keep intentional off settings.`;
6355
+ }
6356
+ case "unsupported-target":
6357
+ return "Portable mode is expected on this target.";
6358
+ case "package-missing":
6359
+ return "Reinstall with optional dependencies included: npm --include=optional, or pnpm without --no-optional / optional=false. Check the lockfile and registry mirror.";
6360
+ case "load-failed":
6361
+ return "Check Node architecture, Linux libc compatibility, package dependencies, and OS code-integrity policy. Reinstalling identical bytes may not help.";
6362
+ case "capability-missing":
6363
+ return "Use matching fs-safe and platform-package versions; some targets intentionally provide only a subset of capabilities.";
6364
+ default:
6365
+ return undefined;
6366
+ }
6367
+ }
6368
+
6246
6369
  ;// CONCATENATED MODULE: ../../node_modules/@openclaw/fs-safe/dist/native-fallback-warning.js
6370
+
6371
+
6372
+
6247
6373
  const warnedFeatures = new Set();
6374
+ function fallbackReason(capabilities) {
6375
+ const diagnostic = getNativeFallbackDiagnostic(...capabilities);
6376
+ const expected = diagnostic.packageName === undefined
6377
+ ? `No native package is published for ${diagnostic.target}.`
6378
+ : `Expected ${diagnostic.packageName}@${diagnostic.packageVersion}.`;
6379
+ const guidance = nativeGuidance(diagnostic.reason, getNativeModeSetting().source);
6380
+ switch (diagnostic.reason) {
6381
+ case "disabled":
6382
+ return `native support is disabled by ${diagnostic.source} (disabled). ${expected} ${guidance}`;
6383
+ case "unsupported-target":
6384
+ return `the target ${diagnostic.target} is unsupported (unsupported-target). ${expected} ${guidance}`;
6385
+ case "package-missing":
6386
+ return `the selected native package could not be resolved (package-missing). ${expected} ${guidance}`;
6387
+ case "load-failed":
6388
+ return `the native package could not be loaded (load-failed: ${diagnostic.code}). ${expected} ${guidance}`;
6389
+ case "capability-missing":
6390
+ return `the native package lacks requested functions (capability-missing: ${diagnostic.capabilities.join(", ")}). ${expected} ${guidance}`;
6391
+ default:
6392
+ return `the requested native operation is unavailable (${diagnostic.reason}). ${expected}`;
6393
+ }
6394
+ }
6248
6395
  /** Warn once per capability, without including caller paths or native error text. */
6249
- function warnNativeFallback(feature, limitation) {
6396
+ function warnNativeFallback(feature, limitation, ...capabilities) {
6250
6397
  if (warnedFeatures.has(feature))
6251
6398
  return;
6252
6399
  warnedFeatures.add(feature);
6253
- process.emitWarning(`${feature} is using its portable fallback because native support is unavailable or disabled. ${limitation}`, { code: "FS_SAFE_NATIVE_FALLBACK", type: "FsSafeWarning" });
6400
+ process.emitWarning(`${feature} is using its portable fallback because ${fallbackReason(capabilities)} ${limitation}`, { code: "FS_SAFE_NATIVE_FALLBACK", type: "FsSafeWarning" });
6254
6401
  }
6255
6402
  function __resetNativeFallbackWarningsForTest() {
6256
6403
  warnedFeatures.clear();
@@ -7089,17 +7236,17 @@ function creation_boundary_assertPrivateFileCreationAvailable() {
7089
7236
  typeof native.verifyPrivateWindowsFile !== "function")
7090
7237
  creation_boundary_unavailable();
7091
7238
  }
7092
- function commandFallback() {
7239
+ function commandFallback(capability) {
7093
7240
  if (getFsSafeNativeConfig().mode === "require")
7094
7241
  creation_boundary_unavailable();
7095
- warnNativeFallback("windows-private-creation", "Private Windows creation uses a slower built-in system command.");
7242
+ warnNativeFallback("windows-private-creation", "Private Windows creation launches the packaged .NET helper for each check or creation.", capability);
7096
7243
  }
7097
7244
  function creationOperation(name) {
7098
7245
  const native = native_getNativeBinding();
7099
7246
  const operation = native?.[name];
7100
7247
  if (typeof operation === "function")
7101
7248
  return operation.bind(native);
7102
- commandFallback();
7249
+ commandFallback(name);
7103
7250
  return undefined;
7104
7251
  }
7105
7252
  /** Full Windows identity, with security validation when requested; no repairs. */
@@ -9428,6 +9575,7 @@ function mergeDenyMutationPolicies(defaultPolicy, callPolicy) {
9428
9575
 
9429
9576
 
9430
9577
 
9578
+
9431
9579
  function getNativeDirectoryObservationBackend(enabled = true) {
9432
9580
  if (!enabled)
9433
9581
  return undefined;
@@ -9437,14 +9585,15 @@ function getNativeDirectoryObservationBackend(enabled = true) {
9437
9585
  : undefined;
9438
9586
  }
9439
9587
  function validateNativeDirectoryObservation(observation) {
9440
- if (!observation || typeof observation.dev !== "bigint" || observation.dev < 0n ||
9441
- typeof observation.ino !== "bigint" || observation.ino < 0n ||
9588
+ if (!observation || !isNativeStatIdentity(observation.dev) ||
9589
+ !isNativeStatIdentity(observation.ino) ||
9442
9590
  typeof observation.realPath !== "string" ||
9443
9591
  observation.realPath.includes("\0") ||
9444
9592
  (!external_node_path_.isAbsolute(observation.realPath) && !external_node_path_.win32.isAbsolute(observation.realPath))) {
9445
9593
  throw new errors_FsSafeError("path-mismatch", "native directory observation is invalid");
9446
9594
  }
9447
- return observation;
9595
+ const dev = statIdentityFromNative(observation.dev), ino = statIdentityFromNative(observation.ino);
9596
+ return dev === observation.dev && ino === observation.ino ? observation : { ...observation, dev, ino };
9448
9597
  }
9449
9598
  /** Exact identity, type, and canonical path captured from one retained handle. */
9450
9599
  function inspectNativeDirectoryObservation(backend, pathname, expected, platform = process.platform) {
@@ -9466,6 +9615,7 @@ function isNativeDirectoryObservationGuard(guard) {
9466
9615
 
9467
9616
 
9468
9617
 
9618
+
9469
9619
  class NativePolicyDirectoryMismatch extends errors_FsSafeError {
9470
9620
  constructor(cause) {
9471
9621
  super("path-mismatch", "staging directory pathname changed", { cause });
@@ -9504,8 +9654,8 @@ function native_policy_directory_observation_nativePolicyDirectoryObserver(bindi
9504
9654
  }
9505
9655
  if (getFsSafeNativeConfig().mode !== mode)
9506
9656
  return undefined;
9507
- if (!observed || typeof observed.dev !== "bigint" || observed.dev < 0n || observed.dev > 0xffffffffffffffffn ||
9508
- typeof observed.ino !== "bigint" || observed.ino < 0n || observed.ino > 0xffffffffffffffffn ||
9657
+ if (!observed || !isNativeStatIdentity(observed.dev) ||
9658
+ !isNativeStatIdentity(observed.ino) ||
9509
9659
  typeof observed.mode !== "bigint" || observed.mode < 0n || observed.mode > 0xffffffffn ||
9510
9660
  typeof observed.nlink !== "bigint" || observed.nlink < 0n || observed.nlink > 0xffffffffffffffffn ||
9511
9661
  typeof observed.realPath !== "string" || observed.realPath.includes("\0") ||
@@ -9518,7 +9668,7 @@ function native_policy_directory_observation_nativePolicyDirectoryObserver(bindi
9518
9668
  return Object.freeze({
9519
9669
  canonicalPath: observed.realPath,
9520
9670
  identity: Object.freeze({
9521
- dev: observed.dev, ino: observed.ino, mode: observed.mode, nlink: observed.nlink,
9671
+ dev: statIdentityFromNative(observed.dev), ino: statIdentityFromNative(observed.ino), mode: observed.mode, nlink: observed.nlink,
9522
9672
  }),
9523
9673
  });
9524
9674
  };
@@ -12308,6 +12458,64 @@ function __setFsSafeTestHooksForTest(hooks) {
12308
12458
  test_hooks_fsSafeTestHooks = hooks;
12309
12459
  }
12310
12460
 
12461
+ ;// CONCATENATED MODULE: ../../node_modules/@openclaw/fs-safe/dist/root-native-creation-path.js
12462
+
12463
+
12464
+
12465
+
12466
+
12467
+
12468
+
12469
+
12470
+
12471
+ function existingCreationParent(params) {
12472
+ if (params.private || params.policy || params.assertBeforeMutation !== undefined ||
12473
+ getFsSafeTestHooks()?.beforeRootFallbackMutation || !params.originalPath ||
12474
+ params.directory !== external_node_path_.dirname(params.target))
12475
+ return undefined;
12476
+ const segments = params.originalPath.split(external_node_path_.sep === "\\" ? /[\\/]/ : "/");
12477
+ if (segments.some(segment => !isSafePathSegment(segment, { allowDotPrefix: true }) || segment.endsWith(".")) ||
12478
+ external_node_path_.join(params.root.rootReal, ...segments) !== params.target)
12479
+ return undefined;
12480
+ let rootStat;
12481
+ root_context_assertRootIdentityCurrentSync(params.root, stat => { rootStat = stat; });
12482
+ try {
12483
+ const identity = directory_guard_inspectDirectoryIdentitySync(params.directory, undefined, params.directory === params.root.rootReal ? rootStat : undefined);
12484
+ if (realpath_realpathSync.native(windows_path_alias_pathForWindowsFilesystem(params.directory)) !== params.directory)
12485
+ return undefined;
12486
+ return {
12487
+ path: params.directory, identity,
12488
+ relative: external_node_path_.relative(params.root.rootReal, params.directory).split(external_node_path_.sep).join("/"),
12489
+ flags: (nodeDirectorySearchOnlyFlags()?.flags ?? external_node_fs_.constants.O_RDONLY) |
12490
+ (external_node_fs_.constants.O_DIRECTORY ?? 0) | (external_node_fs_.constants.O_NOFOLLOW ?? 0),
12491
+ };
12492
+ }
12493
+ catch {
12494
+ return undefined;
12495
+ }
12496
+ }
12497
+ function probeNativeCreationPath(root, relativePath) {
12498
+ if (typeof relativePath !== "string")
12499
+ return undefined;
12500
+ const segments = relativePath.split(external_node_path_.sep === "\\" ? /[\\/]/ : "/");
12501
+ if (segments.some(segment => !isSafePathSegment(segment, { allowDotPrefix: true }) || segment.endsWith(".")))
12502
+ return undefined;
12503
+ const target = external_node_path_.join(root.rootReal, ...segments);
12504
+ root_context_assertRootIdentityCurrentSync(root);
12505
+ try {
12506
+ if (external_node_fs_.lstatSync(windows_path_alias_pathForWindowsFilesystem(target), { throwIfNoEntry: false }))
12507
+ return undefined;
12508
+ }
12509
+ catch {
12510
+ return undefined;
12511
+ }
12512
+ const parent = existingCreationParent({ root, target, directory: external_node_path_.dirname(target), mkdir: true,
12513
+ originalPath: relativePath, resolveCurrent: async () => target });
12514
+ if (!parent)
12515
+ return undefined;
12516
+ return { rootReal: root.rootReal, rootWithSep: root.rootWithSep, resolved: target, parent };
12517
+ }
12518
+
12311
12519
  ;// CONCATENATED MODULE: ../../node_modules/@openclaw/fs-safe/dist/root-create-native.js
12312
12520
  var root_create_native_addDisposableResource = (undefined && undefined.__addDisposableResource) || function (env, value, async) {
12313
12521
  if (value !== null && value !== void 0) {
@@ -12385,6 +12593,8 @@ var root_create_native_disposeResources = (undefined && undefined.__disposeResou
12385
12593
 
12386
12594
 
12387
12595
 
12596
+
12597
+
12388
12598
 
12389
12599
 
12390
12600
 
@@ -12394,6 +12604,10 @@ function rootWriteQueueKey(root, relativePath) {
12394
12604
  function buildAtomicWriteTempPath(targetPath) {
12395
12605
  return external_node_path_.join(external_node_path_.dirname(targetPath), `.fs-safe-${(0,external_node_crypto_.randomUUID)()}.tmp`);
12396
12606
  }
12607
+ const nativeCreateCollisions = new WeakSet();
12608
+ function isNativeCreateCollision(error) {
12609
+ return typeof error === "object" && error !== null && nativeCreateCollisions.has(error);
12610
+ }
12397
12611
  function root_create_native_unavailable() {
12398
12612
  throw new errors_FsSafeError("helper-unavailable", "native confined creation is unavailable");
12399
12613
  }
@@ -12401,6 +12615,60 @@ async function withNativeDirectory(params, operation, discard) {
12401
12615
  const binding = native_getNativeBinding("openBeneath", "mkdirChildBeneath");
12402
12616
  if (!binding?.openBeneath || !binding.mkdirChildBeneath || (params.private && process.platform === "win32"))
12403
12617
  return root_create_native_unavailable();
12618
+ const existing = params.selectedParent ?? existingCreationParent(params);
12619
+ if (existing) {
12620
+ let pending;
12621
+ try {
12622
+ const env_1 = { stack: [], error: void 0, hasError: false };
12623
+ try {
12624
+ const rootOwner = root_create_native_addDisposableResource(env_1, openExactNativeRootSync(binding, {
12625
+ rootPath: params.root.rootReal, rootIdentity: params.root.rootIdentity,
12626
+ }), false);
12627
+ const close = captureNativeFdClose(binding);
12628
+ const borrowed = existing.path === params.root.rootReal;
12629
+ const fd = borrowed ? rootOwner.fd : binding.openBeneath(rootOwner.fd, existing.relative, existing.flags).fd;
12630
+ const parentOwner = root_create_native_addDisposableResource(env_1, { [Symbol.dispose]() { if (!borrowed)
12631
+ close(fd); } }, false);
12632
+ strict_file_identity_inspectFileIdentitySync(() => borrowed ? rootOwner.stat : external_node_fs_.fstatSync(fd, { bigint: true }), existing.identity);
12633
+ verifyMkdirDirectory(binding, fd, existing.path);
12634
+ const guard = { dir: existing.path, realPath: existing.path, stat: existing.identity };
12635
+ const assertCurrent = () => {
12636
+ let currentRoot;
12637
+ root_context_assertRootIdentityCurrentSync(params.root, stat => { currentRoot = stat; });
12638
+ if (borrowed) {
12639
+ // Root and parent are the same name in this synchronous fence.
12640
+ directory_guard_inspectDirectoryIdentitySync(existing.path, existing.identity, currentRoot);
12641
+ if (realpath_realpathSync.native(windows_path_alias_pathForWindowsFilesystem(existing.path)) !== existing.path) {
12642
+ throw new errors_FsSafeError("path-mismatch", "directory changed during operation");
12643
+ }
12644
+ }
12645
+ else {
12646
+ directory_guard_assertSyncDirectoryGuard(guard);
12647
+ }
12648
+ };
12649
+ pending = { value: await operation(binding, fd, assertCurrent) };
12650
+ return pending.value;
12651
+ }
12652
+ catch (e_1) {
12653
+ env_1.error = e_1;
12654
+ env_1.hasError = true;
12655
+ }
12656
+ finally {
12657
+ root_create_native_disposeResources(env_1);
12658
+ }
12659
+ }
12660
+ catch (error) {
12661
+ if (pending && discard) {
12662
+ try {
12663
+ await discard(pending.value);
12664
+ }
12665
+ catch (cleanupError) {
12666
+ throw createSuppressedError(cleanupError, error, "creation handoff and cleanup failed");
12667
+ }
12668
+ }
12669
+ throw error;
12670
+ }
12671
+ }
12404
12672
  const directoryTarget = params.directory === params.target;
12405
12673
  const canonicalTarget = async (target) => directoryTarget
12406
12674
  ? await resolvePathViaExistingAncestor(target)
@@ -12417,14 +12685,14 @@ async function withNativeDirectory(params, operation, discard) {
12417
12685
  const close = captureNativeFdClose(binding);
12418
12686
  let pending;
12419
12687
  try {
12420
- const env_1 = { stack: [], error: void 0, hasError: false };
12688
+ const env_2 = { stack: [], error: void 0, hasError: false };
12421
12689
  try {
12422
12690
  const admitted = await openNativeRootAdmission(binding, {
12423
12691
  rootPath: params.root.rootReal, rootIdentity: params.root.rootIdentity, operation: "create", reportCloseErrors: true, searchOnly: true,
12424
12692
  });
12425
- const rootOwner = root_create_native_addDisposableResource(env_1, admitted.root, true);
12693
+ const rootOwner = root_create_native_addDisposableResource(env_2, admitted.root, true);
12426
12694
  const descriptors = [];
12427
- const directoryOwner = root_create_native_addDisposableResource(env_1, { [Symbol.dispose]() {
12695
+ const directoryOwner = root_create_native_addDisposableResource(env_2, { [Symbol.dispose]() {
12428
12696
  const errors = [];
12429
12697
  for (const fd of descriptors.reverse())
12430
12698
  try {
@@ -12522,12 +12790,12 @@ async function withNativeDirectory(params, operation, discard) {
12522
12790
  pending = { value: await operation(binding, current, assertCurrent) };
12523
12791
  return pending.value;
12524
12792
  }
12525
- catch (e_1) {
12526
- env_1.error = e_1;
12527
- env_1.hasError = true;
12793
+ catch (e_2) {
12794
+ env_2.error = e_2;
12795
+ env_2.hasError = true;
12528
12796
  }
12529
12797
  finally {
12530
- const result_1 = root_create_native_disposeResources(env_1);
12798
+ const result_1 = root_create_native_disposeResources(env_2);
12531
12799
  if (result_1)
12532
12800
  await result_1;
12533
12801
  }
@@ -12606,33 +12874,77 @@ function verifyMkdirDirectory(binding, fd, pathname) {
12606
12874
  describePolicyStagedDirectory(fd, pathname);
12607
12875
  }
12608
12876
  function ensureNativeRootCurrent(root) {
12609
- const env_2 = { stack: [], error: void 0, hasError: false };
12877
+ root_context_assertRootIdentityCurrentSync(root);
12878
+ const binding = native_getNativeBinding("openBeneath", "mkdirChildBeneath");
12879
+ if (!binding?.openBeneath || !binding.mkdirChildBeneath)
12880
+ return root_create_native_unavailable();
12881
+ if (binding.verifyRootDirectory) {
12882
+ const closeNative = captureNativeFdClose(binding);
12883
+ const failure = binding.verifyRootDirectory(root.rootReal, root.rootIdentity.dev, root.rootIdentity.ino);
12884
+ if (failure === null)
12885
+ return;
12886
+ if (failure?.fallbackFd !== undefined && failure.fallbackFd !== null) {
12887
+ const env_3 = { stack: [], error: void 0, hasError: false };
12888
+ try {
12889
+ const fd = failure.fallbackFd;
12890
+ if (!Number.isInteger(fd) || fd < 0)
12891
+ throw new errors_FsSafeError("helper-failed", "invalid root fallback descriptor");
12892
+ const owner = root_create_native_addDisposableResource(env_3, { [Symbol.dispose]() { closeNative(fd); } }, false);
12893
+ if (failure.errorCode || failure.closeErrorCode)
12894
+ throw new errors_FsSafeError("helper-failed", "invalid root verification result");
12895
+ ensureNativeRootCurrentLegacy(root, binding);
12896
+ return;
12897
+ }
12898
+ catch (e_3) {
12899
+ env_3.error = e_3;
12900
+ env_3.hasError = true;
12901
+ }
12902
+ finally {
12903
+ root_create_native_disposeResources(env_3);
12904
+ }
12905
+ }
12906
+ const error = failure?.errorCode ? rootVerificationError(failure.errorCode, failure.errorMessage, failure.errorErrno) : undefined;
12907
+ const closeError = failure?.closeErrorCode ? Object.assign(new Error(failure.closeErrorMessage), {
12908
+ code: failure.closeErrorCode,
12909
+ ...(typeof failure.closeErrorErrno === "number" ? { errno: failure.closeErrorErrno } : {}),
12910
+ }) : undefined;
12911
+ if (error && closeError)
12912
+ throw createSuppressedError(closeError, error, "root verification and close failed");
12913
+ if (error || closeError)
12914
+ throw error ?? closeError;
12915
+ throw new errors_FsSafeError("helper-failed", "invalid root verification result");
12916
+ }
12917
+ ensureNativeRootCurrentLegacy(root, binding);
12918
+ }
12919
+ function rootVerificationError(code, message, errno) {
12920
+ const error = Object.assign(new Error(message), { code, ...(typeof errno === "number" ? { errno } : {}) });
12921
+ return code === "path-mismatch" || code === "OBSERVATION_REDIRECTED"
12922
+ ? new errors_FsSafeError("path-mismatch", "root identity changed during verification", { cause: error }) : error;
12923
+ }
12924
+ function ensureNativeRootCurrentLegacy(root, binding) {
12925
+ const env_4 = { stack: [], error: void 0, hasError: false };
12610
12926
  try {
12611
- root_context_assertRootIdentityCurrentSync(root);
12612
- const binding = native_getNativeBinding("openBeneath", "mkdirChildBeneath");
12613
- if (!binding?.openBeneath || !binding.mkdirChildBeneath)
12614
- return root_create_native_unavailable();
12615
- const rootOwner = root_create_native_addDisposableResource(env_2, openExactNativeRootSync(binding, {
12927
+ const rootOwner = root_create_native_addDisposableResource(env_4, openExactNativeRootSync(binding, {
12616
12928
  rootPath: root.rootReal, rootIdentity: root.rootIdentity,
12617
12929
  }), false);
12618
12930
  verifyMkdirDirectory(binding, rootOwner.fd, root.rootReal);
12619
12931
  root_context_assertRootIdentityCurrentSync(root);
12620
12932
  }
12621
- catch (e_2) {
12622
- env_2.error = e_2;
12623
- env_2.hasError = true;
12933
+ catch (e_4) {
12934
+ env_4.error = e_4;
12935
+ env_4.hasError = true;
12624
12936
  }
12625
12937
  finally {
12626
- root_create_native_disposeResources(env_2);
12938
+ root_create_native_disposeResources(env_4);
12627
12939
  }
12628
12940
  }
12629
12941
  function mkdirNativeRootChild(params) {
12630
- const env_3 = { stack: [], error: void 0, hasError: false };
12942
+ const env_5 = { stack: [], error: void 0, hasError: false };
12631
12943
  try {
12632
12944
  const binding = native_getNativeBinding("openBeneath", "mkdirChildBeneath");
12633
12945
  if (!binding?.openBeneath || !binding.mkdirChildBeneath)
12634
12946
  return root_create_native_unavailable();
12635
- const rootOwner = root_create_native_addDisposableResource(env_3, openExactNativeRootSync(binding, {
12947
+ const rootOwner = root_create_native_addDisposableResource(env_5, openExactNativeRootSync(binding, {
12636
12948
  rootPath: params.root.rootReal, rootIdentity: params.root.rootIdentity,
12637
12949
  }), false);
12638
12950
  verifyMkdirDirectory(binding, rootOwner.fd, params.root.rootReal);
@@ -12645,17 +12957,17 @@ function mkdirNativeRootChild(params) {
12645
12957
  ? binding.mkdirOpenChildBeneath(rootOwner.fd, name, 0o777, flags).fd
12646
12958
  : (binding.mkdirChildBeneath(rootOwner.fd, name, 0o777), binding.openBeneath(rootOwner.fd, name, flags).fd);
12647
12959
  const close = captureNativeFdClose(binding);
12648
- const childOwner = root_create_native_addDisposableResource(env_3, { [Symbol.dispose]() { close(child); } }, false);
12960
+ const childOwner = root_create_native_addDisposableResource(env_5, { [Symbol.dispose]() { close(child); } }, false);
12649
12961
  root_context_assertRootIdentityCurrentSync(params.root);
12650
12962
  verifyMkdirDirectory(binding, child, params.target);
12651
12963
  verifyMkdirDirectory(binding, rootOwner.fd, params.root.rootReal);
12652
12964
  }
12653
- catch (e_3) {
12654
- env_3.error = e_3;
12655
- env_3.hasError = true;
12965
+ catch (e_5) {
12966
+ env_5.error = e_5;
12967
+ env_5.hasError = true;
12656
12968
  }
12657
12969
  finally {
12658
- root_create_native_disposeResources(env_3);
12970
+ root_create_native_disposeResources(env_5);
12659
12971
  }
12660
12972
  }
12661
12973
  async function tryOpenCreateRootNative(params) {
@@ -12677,7 +12989,7 @@ async function tryOpenCreateRootNative(params) {
12677
12989
  if (creationMode() === undefined)
12678
12990
  return root_create_native_unavailable();
12679
12991
  return await withNativeDirectory(params, async (binding, parent, assertCurrent) => {
12680
- const env_4 = { stack: [], error: void 0, hasError: false };
12992
+ const env_6 = { stack: [], error: void 0, hasError: false };
12681
12993
  try {
12682
12994
  params.assertBeforeMutation?.();
12683
12995
  assertCurrent();
@@ -12687,13 +12999,21 @@ async function tryOpenCreateRootNative(params) {
12687
12999
  // Native creation owns the only O_CREAT dispatch. The subsequent Node open
12688
13000
  // carries neither O_CREAT nor O_TRUNC and must match this retained inode.
12689
13001
  const close = captureNativeFdClose(binding);
12690
- const fd = binding.openCreateBeneath(parent, external_node_path_.basename(params.target), params.flags, params.mode & 0o7777);
13002
+ let fd;
13003
+ try {
13004
+ fd = binding.openCreateBeneath(parent, external_node_path_.basename(params.target), params.flags, params.mode & 0o7777);
13005
+ }
13006
+ catch (error) {
13007
+ if (hasNodeErrorCode(error, "EEXIST") && typeof error === "object" && error !== null)
13008
+ nativeCreateCollisions.add(error);
13009
+ throw error;
13010
+ }
12691
13011
  let rawOpen = true;
12692
13012
  const closeRaw = () => { if (rawOpen) {
12693
13013
  rawOpen = false;
12694
13014
  close(fd);
12695
13015
  } };
12696
- const owner = root_create_native_addDisposableResource(env_4, { [Symbol.dispose]: closeRaw }, false);
13016
+ const owner = root_create_native_addDisposableResource(env_6, { [Symbol.dispose]: closeRaw }, false);
12697
13017
  try {
12698
13018
  const identity = strict_file_identity_inspectFileIdentitySync(() => external_node_fs_.fstatSync(fd, { bigint: true }));
12699
13019
  if (!identity.isFile() || identity.nlink !== 1n)
@@ -12747,26 +13067,26 @@ async function tryOpenCreateRootNative(params) {
12747
13067
  throw error;
12748
13068
  }
12749
13069
  }
12750
- catch (e_4) {
12751
- env_4.error = e_4;
12752
- env_4.hasError = true;
13070
+ catch (e_6) {
13071
+ env_6.error = e_6;
13072
+ env_6.hasError = true;
12753
13073
  }
12754
13074
  finally {
12755
- root_create_native_disposeResources(env_4);
13075
+ root_create_native_disposeResources(env_6);
12756
13076
  }
12757
13077
  }, async (created) => {
12758
- const env_5 = { stack: [], error: void 0, hasError: false };
13078
+ const env_7 = { stack: [], error: void 0, hasError: false };
12759
13079
  try {
12760
- const handle = root_create_native_addDisposableResource(env_5, created.handle, true);
12761
- const parent = root_create_native_addDisposableResource(env_5, { [Symbol.dispose]: created.releaseCreationParent }, false);
13080
+ const handle = root_create_native_addDisposableResource(env_7, created.handle, true);
13081
+ const parent = root_create_native_addDisposableResource(env_7, { [Symbol.dispose]: created.releaseCreationParent }, false);
12762
13082
  await created.cleanupCreated();
12763
13083
  }
12764
- catch (e_5) {
12765
- env_5.error = e_5;
12766
- env_5.hasError = true;
13084
+ catch (e_7) {
13085
+ env_7.error = e_7;
13086
+ env_7.hasError = true;
12767
13087
  }
12768
13088
  finally {
12769
- const result_2 = root_create_native_disposeResources(env_5);
13089
+ const result_2 = root_create_native_disposeResources(env_7);
12770
13090
  if (result_2)
12771
13091
  await result_2;
12772
13092
  }
@@ -13502,7 +13822,7 @@ function privateDirectoryBackend() {
13502
13822
  if (getFsSafeNativeConfig().mode === "require") {
13503
13823
  throw new errors_FsSafeError("helper-unavailable", "private directory creation requires an up-to-date native parent identity capability");
13504
13824
  }
13505
- warnNativeFallback("windows-private-directory", "Private Windows directory creation uses a slower built-in system command.");
13825
+ warnNativeFallback("windows-private-directory", "Private Windows directory creation launches the packaged .NET helper for each check or creation.", "createPrivateDirectoryWithParentIdentity");
13506
13826
  return undefined;
13507
13827
  }
13508
13828
  async function createDirectory(targetPath, options = {}) {
@@ -19312,6 +19632,247 @@ async function read_opened_file_readOpenedFileSafely(params) {
19312
19632
  };
19313
19633
  }
19314
19634
 
19635
+ ;// CONCATENATED MODULE: ../../node_modules/@openclaw/fs-safe/dist/root-mkdir-native.js
19636
+ var root_mkdir_native_addDisposableResource = (undefined && undefined.__addDisposableResource) || function (env, value, async) {
19637
+ if (value !== null && value !== void 0) {
19638
+ if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
19639
+ var dispose, inner;
19640
+ if (async) {
19641
+ if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
19642
+ dispose = value[Symbol.asyncDispose];
19643
+ }
19644
+ if (dispose === void 0) {
19645
+ if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
19646
+ dispose = value[Symbol.dispose];
19647
+ if (async) inner = dispose;
19648
+ }
19649
+ if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
19650
+ if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
19651
+ env.stack.push({ value: value, dispose: dispose, async: async });
19652
+ }
19653
+ else if (async) {
19654
+ env.stack.push({ async: true });
19655
+ }
19656
+ return value;
19657
+ };
19658
+ var root_mkdir_native_disposeResources = (undefined && undefined.__disposeResources) || (function (SuppressedError) {
19659
+ return function (env) {
19660
+ function fail(e) {
19661
+ env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
19662
+ env.hasError = true;
19663
+ }
19664
+ var r, s = 0;
19665
+ function next() {
19666
+ while (r = env.stack.pop()) {
19667
+ try {
19668
+ if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
19669
+ if (r.dispose) {
19670
+ var result = r.dispose.call(r.value);
19671
+ if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
19672
+ }
19673
+ else s |= 1;
19674
+ }
19675
+ catch (e) {
19676
+ fail(e);
19677
+ }
19678
+ }
19679
+ if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
19680
+ if (env.hasError) throw env.error;
19681
+ }
19682
+ return next();
19683
+ };
19684
+ })(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
19685
+ var e = new Error(message);
19686
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
19687
+ });
19688
+
19689
+
19690
+
19691
+
19692
+
19693
+
19694
+
19695
+
19696
+
19697
+
19698
+
19699
+
19700
+
19701
+
19702
+
19703
+
19704
+
19705
+ function tryMkdirNativeParents(root, relativePath) {
19706
+ try {
19707
+ return mkdirOrdinaryNativeParents(root, relativePath);
19708
+ }
19709
+ catch (error) {
19710
+ if (hasNodeErrorCode(error, "ENOTDIR"))
19711
+ throw root_errors_directoryComponentNotDirectoryError(error);
19712
+ throw error;
19713
+ }
19714
+ }
19715
+ function mkdirOrdinaryNativeParents(root, relativePath) {
19716
+ if (getFsSafeTestHooks()?.beforeRootFallbackMutation)
19717
+ return false;
19718
+ const segments = relativePath.split(external_node_path_.sep === "\\" ? /[\\/]/ : "/");
19719
+ if (segments.length < 2 || segments.some(segment => !isSafePathSegment(segment, { allowDotPrefix: true }) || segment.endsWith(".")))
19720
+ return false;
19721
+ let rootStat;
19722
+ root_context_assertRootIdentityCurrentSync(root, stat => { rootStat = stat; });
19723
+ const target = external_node_path_.join(root.rootReal, ...segments);
19724
+ const parentPath = external_node_path_.dirname(target);
19725
+ try {
19726
+ const child = external_node_fs_.lstatSync(windows_path_alias_pathForWindowsFilesystem(target), { throwIfNoEntry: false });
19727
+ if (child && (!child.isDirectory() || realpath_realpathSync.native(windows_path_alias_pathForWindowsFilesystem(target)) !== target))
19728
+ return false;
19729
+ }
19730
+ catch {
19731
+ return false;
19732
+ }
19733
+ let parentIdentity;
19734
+ try {
19735
+ parentIdentity = directory_guard_inspectDirectoryIdentitySync(parentPath);
19736
+ }
19737
+ catch (error) {
19738
+ // Reuse this exact Root snapshot and failed parent observation without an
19739
+ // intervening await. All opened ancestors still receive fresh native fences.
19740
+ return hasNodeErrorCode(error, "ENOENT") ? mkdirMissingParents(root, segments, rootStat) : false;
19741
+ }
19742
+ try {
19743
+ if (realpath_realpathSync.native(windows_path_alias_pathForWindowsFilesystem(parentPath)) !== parentPath)
19744
+ return false;
19745
+ }
19746
+ catch {
19747
+ return false;
19748
+ }
19749
+ return mkdirExistingParent(root, segments, parentIdentity);
19750
+ }
19751
+ /** Ordinary missing suffixes need no policy callbacks or repeated path resolution. */
19752
+ function mkdirMissingParents(root, segments, rootStat) {
19753
+ const binding = native_getNativeBinding("openBeneath", "mkdirChildBeneath");
19754
+ if (!binding?.openBeneath || !binding.mkdirOpenChildBeneath)
19755
+ return false;
19756
+ let parentDepth = segments.length - 2;
19757
+ let parentPath;
19758
+ let parentIdentity;
19759
+ for (;;) {
19760
+ parentPath = external_node_path_.join(root.rootReal, ...segments.slice(0, parentDepth));
19761
+ try {
19762
+ parentIdentity = directory_guard_inspectDirectoryIdentitySync(parentPath, undefined, parentDepth === 0 ? rootStat : undefined);
19763
+ if (realpath_realpathSync.native(windows_path_alias_pathForWindowsFilesystem(parentPath)) !== parentPath)
19764
+ return false;
19765
+ break;
19766
+ }
19767
+ catch (error) {
19768
+ if (!hasNodeErrorCode(error, "ENOENT") || parentDepth === 0)
19769
+ return false;
19770
+ parentDepth--;
19771
+ }
19772
+ }
19773
+ try {
19774
+ const env_1 = { stack: [], error: void 0, hasError: false };
19775
+ try {
19776
+ const rootOwner = root_mkdir_native_addDisposableResource(env_1, openExactNativeRootSync(binding, {
19777
+ rootPath: root.rootReal, rootIdentity: root.rootIdentity,
19778
+ }), false);
19779
+ const close = captureNativeFdClose(binding);
19780
+ const directories = [];
19781
+ const directoryOwner = root_mkdir_native_addDisposableResource(env_1, { [Symbol.dispose]() {
19782
+ const errors = [];
19783
+ for (const directory of directories.toReversed()) {
19784
+ try {
19785
+ close(directory.fd);
19786
+ }
19787
+ catch (error) {
19788
+ errors.push(error);
19789
+ }
19790
+ }
19791
+ if (errors.length)
19792
+ throw new AggregateError(errors, "mkdir directory close failed");
19793
+ } }, false);
19794
+ const flags = (nodeDirectorySearchOnlyFlags()?.flags ?? external_node_fs_.constants.O_RDONLY) |
19795
+ (external_node_fs_.constants.O_DIRECTORY ?? 0) | (external_node_fs_.constants.O_NOFOLLOW ?? 0);
19796
+ let current = rootOwner.fd;
19797
+ if (parentDepth > 0) {
19798
+ current = binding.openBeneath(rootOwner.fd, segments.slice(0, parentDepth).join("/"), flags).fd;
19799
+ directories.push({ fd: current, pathname: parentPath });
19800
+ strict_file_identity_inspectFileIdentitySync(() => external_node_fs_.fstatSync(current, { bigint: true }), parentIdentity);
19801
+ }
19802
+ const assertCurrent = () => {
19803
+ root_context_assertRootIdentityCurrentSync(root);
19804
+ for (const directory of directories)
19805
+ verifyMkdirDirectory(binding, directory.fd, directory.pathname);
19806
+ verifyMkdirDirectory(binding, rootOwner.fd, root.rootReal);
19807
+ };
19808
+ assertCurrent();
19809
+ for (const segment of segments.slice(parentDepth)) {
19810
+ const child = binding.mkdirOpenChildBeneath(current, segment, 0o777, flags);
19811
+ parentPath = external_node_path_.join(parentPath, segment);
19812
+ directories.push({ fd: child.fd, pathname: parentPath });
19813
+ // Retain every ancestor until the complete suffix is admitted. The
19814
+ // post-create fence also precedes the next synchronous child mutation.
19815
+ assertCurrent();
19816
+ current = child.fd;
19817
+ }
19818
+ return true;
19819
+ }
19820
+ catch (e_1) {
19821
+ env_1.error = e_1;
19822
+ env_1.hasError = true;
19823
+ }
19824
+ finally {
19825
+ root_mkdir_native_disposeResources(env_1);
19826
+ }
19827
+ }
19828
+ catch (error) {
19829
+ if (hasNodeErrorCode(error, "ENOTDIR"))
19830
+ throw root_errors_directoryComponentNotDirectoryError(error);
19831
+ throw error;
19832
+ }
19833
+ }
19834
+ function mkdirExistingParent(root, segments, parentIdentity) {
19835
+ const env_2 = { stack: [], error: void 0, hasError: false };
19836
+ try {
19837
+ const target = external_node_path_.join(root.rootReal, ...segments);
19838
+ const parentPath = external_node_path_.dirname(target);
19839
+ const binding = native_getNativeBinding("openBeneath", "mkdirChildBeneath");
19840
+ if (!binding?.openBeneath || !binding.mkdirChildBeneath) {
19841
+ throw new errors_FsSafeError("helper-unavailable", "native confined creation is unavailable");
19842
+ }
19843
+ const rootOwner = root_mkdir_native_addDisposableResource(env_2, openExactNativeRootSync(binding, {
19844
+ rootPath: root.rootReal, rootIdentity: root.rootIdentity,
19845
+ }), false);
19846
+ verifyMkdirDirectory(binding, rootOwner.fd, root.rootReal);
19847
+ const flags = (nodeDirectorySearchOnlyFlags()?.flags ?? external_node_fs_.constants.O_RDONLY) |
19848
+ (external_node_fs_.constants.O_DIRECTORY ?? 0) | (external_node_fs_.constants.O_NOFOLLOW ?? 0);
19849
+ const close = captureNativeFdClose(binding);
19850
+ const parent = binding.openBeneath(rootOwner.fd, segments.slice(0, -1).join("/"), flags).fd;
19851
+ const parentOwner = root_mkdir_native_addDisposableResource(env_2, { [Symbol.dispose]() { close(parent); } }, false);
19852
+ strict_file_identity_inspectFileIdentitySync(() => external_node_fs_.fstatSync(parent, { bigint: true }), parentIdentity);
19853
+ verifyMkdirDirectory(binding, parent, parentPath);
19854
+ root_context_assertRootIdentityCurrentSync(root);
19855
+ const name = segments.at(-1);
19856
+ const child = binding.mkdirOpenChildBeneath
19857
+ ? binding.mkdirOpenChildBeneath(parent, name, 0o777, flags).fd
19858
+ : (binding.mkdirChildBeneath(parent, name, 0o777), binding.openBeneath(parent, name, flags).fd);
19859
+ const childOwner = root_mkdir_native_addDisposableResource(env_2, { [Symbol.dispose]() { close(child); } }, false);
19860
+ root_context_assertRootIdentityCurrentSync(root);
19861
+ verifyMkdirDirectory(binding, child, target);
19862
+ directory_guard_inspectDirectoryIdentitySync(parentPath, parentIdentity);
19863
+ verifyMkdirDirectory(binding, parent, parentPath);
19864
+ verifyMkdirDirectory(binding, rootOwner.fd, root.rootReal);
19865
+ return true;
19866
+ }
19867
+ catch (e_2) {
19868
+ env_2.error = e_2;
19869
+ env_2.hasError = true;
19870
+ }
19871
+ finally {
19872
+ root_mkdir_native_disposeResources(env_2);
19873
+ }
19874
+ }
19875
+
19315
19876
  ;// CONCATENATED MODULE: ../../node_modules/@openclaw/fs-safe/dist/write-open-flags.js
19316
19877
 
19317
19878
 
@@ -22384,6 +22945,7 @@ var root_impl_disposeResources = (undefined && undefined.__disposeResources) ||
22384
22945
 
22385
22946
 
22386
22947
 
22948
+
22387
22949
 
22388
22950
 
22389
22951
  function logWarn(message) {
@@ -22784,7 +23346,9 @@ async function openWritableFileInRoot(root, params, options) {
22784
23346
  denyMutations: params.denyMutations,
22785
23347
  mutationSymlinks: params.mutationSymlinks,
22786
23348
  });
22787
- const { resolved } = guardedTarget?.resolvedPath ?? await resolveGuardedWritePathInRoot(root, {
23349
+ const creationProbe = requireNative && !guardedTarget && params.assertBeforeMutation === undefined && options?.createIfMissing !== false
23350
+ ? probeNativeCreationPath(root, params.relativePath) : undefined;
23351
+ const { resolved } = creationProbe ?? guardedTarget?.resolvedPath ?? await resolveGuardedWritePathInRoot(root, {
22788
23352
  relativePath: params.relativePath,
22789
23353
  });
22790
23354
  const resolveCurrent = async () => (await resolveGuardedWritePathInRoot(root, {
@@ -22813,27 +23377,30 @@ async function openWritableFileInRoot(root, params, options) {
22813
23377
  let ioPath = nativeCreatesParents ? resolved : prepared?.targetPath ?? (params.mkdir === false ? resolved :
22814
23378
  await prepareRootWriteTarget(root, resolved, params.assertBeforeMutation));
22815
23379
  const operationTargetPath = ioPath;
22816
- try {
22817
- assertFinalSymlinkRejected(ioPath, params.mutationSymlinks !== undefined);
22818
- const resolvedRealPath = params.mutationSymlinks === undefined ? realpath_realpathSync.native(ioPath) : ioPath;
22819
- const admittedRealPath = root_boundary_admitPathInsideRoot({
22820
- rootPath: root.rootReal,
22821
- candidatePath: resolvedRealPath,
22822
- rootIdentity: root.rootIdentity,
22823
- });
22824
- if (!admittedRealPath) {
22825
- throw root_errors_outsideWorkspaceError();
22826
- }
22827
- ioPath = admittedRealPath.path;
22828
- }
22829
- catch (err) {
22830
- if (err instanceof errors_FsSafeError) {
22831
- throw err;
23380
+ let observedMissing = Boolean(creationProbe);
23381
+ if (!creationProbe)
23382
+ try {
23383
+ assertFinalSymlinkRejected(ioPath, params.mutationSymlinks !== undefined);
23384
+ const resolvedRealPath = params.mutationSymlinks === undefined ? realpath_realpathSync.native(ioPath) : ioPath;
23385
+ const admittedRealPath = root_boundary_admitPathInsideRoot({
23386
+ rootPath: root.rootReal,
23387
+ candidatePath: resolvedRealPath,
23388
+ rootIdentity: root.rootIdentity,
23389
+ });
23390
+ if (!admittedRealPath) {
23391
+ throw root_errors_outsideWorkspaceError();
23392
+ }
23393
+ ioPath = admittedRealPath.path;
22832
23394
  }
22833
- if (!path_isNotFoundPathError(err)) {
22834
- throw err;
23395
+ catch (err) {
23396
+ if (err instanceof errors_FsSafeError) {
23397
+ throw err;
23398
+ }
23399
+ if (!path_isNotFoundPathError(err)) {
23400
+ throw err;
23401
+ }
23402
+ observedMissing = true;
22835
23403
  }
22836
- }
22837
23404
  assertRootFallbackWritePath(params.expectedWritePath, ioPath);
22838
23405
  const mode = params.mode ?? 0o600;
22839
23406
  let handle;
@@ -22847,61 +23414,82 @@ async function openWritableFileInRoot(root, params, options) {
22847
23414
  writePathSelection = guardedTarget
22848
23415
  ? await prepareGuardedRootWritePathSelection(guardedTarget, ioPath, operationTargetPath, preparedParent)
22849
23416
  : undefined;
22850
- try {
22851
- if (writePathSelection)
22852
- assertRootWritePathSelectionSync(root, writePathSelection);
22853
- handle = await promises_.open(ioPath, existingFlags, mode);
22854
- }
22855
- catch (err) {
22856
- if (await isNonRegularWriteOpenError(err, ioPath, existingFlags)) {
22857
- throw new errors_FsSafeError("not-file", "path is not a regular file under root");
23417
+ const createNative = () => tryOpenCreateRootNative({
23418
+ originalPath: params.relativePath,
23419
+ root, directory: external_node_path_.dirname(ioPath), target: ioPath, mkdir: params.mkdir !== false, policy,
23420
+ selectedParent: creationProbe?.parent,
23421
+ resolveCurrent,
23422
+ assertBeforeMutation: params.assertBeforeMutation !== undefined || writePathSelection !== undefined ? () => {
23423
+ params.assertBeforeMutation?.();
23424
+ if (writePathSelection)
23425
+ assertRootWritePathSelectionSync(root, writePathSelection);
23426
+ } : undefined,
23427
+ flags: createFlags, existingFlags, mode,
23428
+ });
23429
+ let precreated;
23430
+ if (requireNative && observedMissing && !guardedTarget && params.assertBeforeMutation === undefined && options?.createIfMissing !== false) {
23431
+ try {
23432
+ precreated = await createNative();
22858
23433
  }
22859
- if (!path_isNotFoundPathError(err)) {
22860
- throw err;
23434
+ catch (error) {
23435
+ if (!hasNodeErrorCode(error, "EEXIST") || !isNativeCreateCollision(error))
23436
+ throw error;
22861
23437
  }
22862
- if (options?.createIfMissing === false) {
22863
- if (nativeCreatesParents && !guardedTarget)
22864
- await tryMkdirRootNative({
22865
- originalPath: params.relativePath,
22866
- root, directory: external_node_path_.dirname(ioPath), target: ioPath, mkdir: true, policy,
22867
- resolveCurrent, assertBeforeMutation: params.assertBeforeMutation,
22868
- });
22869
- const parentGuard = writePathSelection?.parentGuard ??
22870
- await directory_guard_createAsyncDirectoryGuard(external_node_path_.dirname(ioPath), { bigint: true });
22871
- root_context_assertRootIdentityCurrentSync(root);
22872
- if (!root_boundary_admitPathInsideRoot({
22873
- rootPath: root.rootReal, candidatePath: parentGuard.realPath, rootIdentity: root.rootIdentity,
22874
- }))
22875
- throw root_errors_outsideWorkspaceError();
22876
- directory_guard_assertSyncDirectoryGuard(parentGuard);
22877
- return { missing: true, targetPath: ioPath, parentGuard, writeSelection: writePathSelection };
23438
+ }
23439
+ if (precreated) {
23440
+ handle = precreated.handle;
23441
+ cleanupCreated = precreated.cleanupCreated;
23442
+ releaseCreationParent = precreated.releaseCreationParent;
23443
+ createdForWrite = true;
23444
+ }
23445
+ else {
23446
+ try {
23447
+ if (writePathSelection)
23448
+ assertRootWritePathSelectionSync(root, writePathSelection);
23449
+ handle = await promises_.open(ioPath, existingFlags, mode);
22878
23450
  }
22879
- if (writePathSelection)
22880
- await refreshRootWritePathSelection(writePathSelection);
22881
- const nativeCreated = requireNative ? await tryOpenCreateRootNative({
22882
- originalPath: params.relativePath,
22883
- root, directory: external_node_path_.dirname(ioPath), target: ioPath, mkdir: params.mkdir !== false, policy,
22884
- resolveCurrent, assertBeforeMutation() {
23451
+ catch (err) {
23452
+ if (await isNonRegularWriteOpenError(err, ioPath, existingFlags)) {
23453
+ throw new errors_FsSafeError("not-file", "path is not a regular file under root");
23454
+ }
23455
+ if (!path_isNotFoundPathError(err)) {
23456
+ throw err;
23457
+ }
23458
+ if (options?.createIfMissing === false) {
23459
+ if (nativeCreatesParents && !guardedTarget)
23460
+ await tryMkdirRootNative({
23461
+ originalPath: params.relativePath,
23462
+ root, directory: external_node_path_.dirname(ioPath), target: ioPath, mkdir: true, policy,
23463
+ resolveCurrent, assertBeforeMutation: params.assertBeforeMutation,
23464
+ });
23465
+ const parentGuard = writePathSelection?.parentGuard ??
23466
+ await directory_guard_createAsyncDirectoryGuard(external_node_path_.dirname(ioPath), { bigint: true });
23467
+ root_context_assertRootIdentityCurrentSync(root);
23468
+ if (!root_boundary_admitPathInsideRoot({
23469
+ rootPath: root.rootReal, candidatePath: parentGuard.realPath, rootIdentity: root.rootIdentity,
23470
+ }))
23471
+ throw root_errors_outsideWorkspaceError();
23472
+ directory_guard_assertSyncDirectoryGuard(parentGuard);
23473
+ return { missing: true, targetPath: ioPath, parentGuard, writeSelection: writePathSelection };
23474
+ }
23475
+ if (writePathSelection)
23476
+ await refreshRootWritePathSelection(writePathSelection);
23477
+ const nativeCreated = requireNative ? await createNative() : undefined;
23478
+ if (nativeCreated)
23479
+ handle = nativeCreated.handle;
23480
+ else {
22885
23481
  params.assertBeforeMutation?.();
22886
23482
  if (writePathSelection)
22887
23483
  assertRootWritePathSelectionSync(root, writePathSelection);
22888
- },
22889
- flags: createFlags, existingFlags, mode,
22890
- }) : undefined;
22891
- if (nativeCreated)
22892
- handle = nativeCreated.handle;
22893
- else {
22894
- params.assertBeforeMutation?.();
22895
- if (writePathSelection)
22896
- assertRootWritePathSelectionSync(root, writePathSelection);
22897
- // Windows can follow a dangling symlink even with O_EXCL.
22898
- if (!SUPPORTS_NOFOLLOW)
22899
- assertFinalSymlinkRejected(ioPath, true);
22900
- handle = await promises_.open(ioPath, createFlags, mode);
23484
+ // Windows can follow a dangling symlink even with O_EXCL.
23485
+ if (!SUPPORTS_NOFOLLOW)
23486
+ assertFinalSymlinkRejected(ioPath, true);
23487
+ handle = await promises_.open(ioPath, createFlags, mode);
23488
+ }
23489
+ cleanupCreated = nativeCreated?.cleanupCreated;
23490
+ releaseCreationParent = nativeCreated?.releaseCreationParent;
23491
+ createdForWrite = true;
22901
23492
  }
22902
- cleanupCreated = nativeCreated?.cleanupCreated;
22903
- releaseCreationParent = nativeCreated?.releaseCreationParent;
22904
- createdForWrite = true;
22905
23493
  }
22906
23494
  }
22907
23495
  catch (err) {
@@ -23148,6 +23736,8 @@ async function mkdirPathInRoot(root, params) {
23148
23736
  }
23149
23737
  if (tryMkdirNativeDirectChild(root, params.relativePath))
23150
23738
  return;
23739
+ if (tryMkdirNativeParents(root, params.relativePath))
23740
+ return;
23151
23741
  }
23152
23742
  const resolution = { relativePath: params.relativePath, allowRoot: params.allowRoot, ...policy };
23153
23743
  const resolveCurrent = policy
@@ -71024,7 +71614,7 @@ function initializeFlow(effects) {
71024
71614
  */
71025
71615
 
71026
71616
 
71027
- const resolver = {
71617
+ const text_resolver = {
71028
71618
  resolveAll: text_createResolver()
71029
71619
  };
71030
71620
  const text_string = initializeFactory('string');
@@ -79195,7 +79785,7 @@ const constructs_text = {
79195
79785
 
79196
79786
  /** @satisfies {Extension['insideSpan']} */
79197
79787
  const insideSpan = {
79198
- null: [attention_attention, resolver]
79788
+ null: [attention_attention, text_resolver]
79199
79789
  };
79200
79790
 
79201
79791
  /** @satisfies {Extension['attentionMarkers']} */
@@ -110395,4 +110985,4 @@ if (installedChunkData !== 0) { // 0 means "already installed".'
110395
110985
  // module factories are used so entry inlining is disabled
110396
110986
  // startup
110397
110987
  // Load entry module and return exports
110398
- var __webpack_exports__ = __webpack_require__(4101);
110988
+ var __webpack_exports__ = __webpack_require__(4517);