@lousy-agents/agent-shell 5.23.8 → 5.23.10

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 +310 -232
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -387,7 +387,7 @@ const external_node_async_hooks_namespaceObject = __rspack_createRequire_require
387
387
 
388
388
  const file_observation_active = new external_node_async_hooks_namespaceObject.AsyncLocalStorage();
389
389
  function recordFileObservationFailure(error, kind) {
390
- const failures = file_observation_active.getStore();
390
+ const failures = file_observation_active.getStore()?.failures;
391
391
  if (!failures)
392
392
  return;
393
393
  let kinds = failures.get(error);
@@ -396,13 +396,17 @@ function recordFileObservationFailure(error, kind) {
396
396
  kinds.add(kind);
397
397
  }
398
398
  function isFileObservationFailure(error, kind) {
399
- return file_observation_active.getStore()?.get(error)?.has(kind) === true;
399
+ return file_observation_active.getStore()?.failures.get(error)?.has(kind) === true;
400
+ }
401
+ async function observedFilePublicationPending(filePath, identity) {
402
+ return await file_observation_active.getStore()?.publicationPending?.(filePath, identity) ?? false;
400
403
  }
401
404
  // Each Root observation owns its receipts, including nested and concurrent reads.
402
- function fileObservation() {
405
+ function fileObservation(options = {}) {
403
406
  const failures = new Map();
407
+ const context = { failures, ...options };
404
408
  return {
405
- run(operation) { return file_observation_active.run(failures, operation); },
409
+ run(operation) { return file_observation_active.run(context, operation); },
406
410
  has(error, kind) { return failures.get(error)?.has(kind) === true; },
407
411
  };
408
412
  }
@@ -2679,17 +2683,19 @@ function cleanupSidecarStages(target, assertCurrent, native, onlyStage) {
2679
2683
  }
2680
2684
  // Readers reject the linked record and retry. Authorized cleanup may handle
2681
2685
  // the one matching stage; recognition streams past the opportunistic budget.
2682
- function sidecar_lock_staging_sidecarPublicationPending(target, onStage) {
2686
+ function sidecar_lock_staging_sidecarPublicationPending(target, onStage, options = {}) {
2683
2687
  let entries;
2684
2688
  let callbackFailure;
2685
2689
  try {
2686
2690
  const current = external_node_fs_namespaceObject.lstatSync(target, { bigint: true, throwIfNoEntry: false });
2687
2691
  if (!current)
2688
- return true;
2692
+ return !options.requireStage;
2693
+ if (options.identity && !sameFileIdentityForCleanup(current, options.identity))
2694
+ return false;
2689
2695
  if (!current.isFile() || current.isSymbolicLink())
2690
2696
  return false;
2691
2697
  if (current.nlink === 1n)
2692
- return true;
2698
+ return !options.requireStage;
2693
2699
  if (current.nlink !== 2n)
2694
2700
  return false;
2695
2701
  const prefix = stagingPrefix(target);
@@ -2713,7 +2719,7 @@ function sidecar_lock_staging_sidecarPublicationPending(target, onStage) {
2713
2719
  }
2714
2720
  }
2715
2721
  const after = external_node_fs_namespaceObject.lstatSync(target, { bigint: true, throwIfNoEntry: false });
2716
- return !after || !sameFileIdentityForCleanup(after, current) || after.nlink === 1n;
2722
+ return !options.requireStage && (!after || !sameFileIdentityForCleanup(after, current) || after.nlink === 1n);
2717
2723
  }
2718
2724
  catch {
2719
2725
  if (callbackFailure)
@@ -3242,6 +3248,236 @@ function pinNodeDirectoryForModeSync(dirPath, options = {}) {
3242
3248
  }
3243
3249
  }
3244
3250
 
3251
+ ;// CONCATENATED MODULE: ../../node_modules/@openclaw/fs-safe/dist/test-hooks.js
3252
+
3253
+ let test_hooks_fsSafeTestHooks;
3254
+ function allowFsSafeTestHooks() {
3255
+ return false || process.env.VITEST === "true";
3256
+ }
3257
+ function getFsSafeTestHooks() {
3258
+ return test_hooks_fsSafeTestHooks;
3259
+ }
3260
+ function __setFsSafeTestHooksForTest(hooks) {
3261
+ if (hooks && !allowFsSafeTestHooks()) {
3262
+ throw new Error("__setFsSafeTestHooksForTest is only available in tests");
3263
+ }
3264
+ test_hooks_fsSafeTestHooks = hooks;
3265
+ }
3266
+
3267
+ ;// CONCATENATED MODULE: ../../node_modules/@openclaw/fs-safe/dist/timing.js
3268
+ const MAX_TIMER_DELAY_MS = 2 ** 31 - 1;
3269
+ function scheduleTimeout(callback, ms) {
3270
+ let timer;
3271
+ if (Number.isFinite(ms) && ms > MAX_TIMER_DELAY_MS) {
3272
+ const startedAt = performance.now();
3273
+ const tick = () => {
3274
+ const remaining = ms - (performance.now() - startedAt);
3275
+ if (remaining <= 0)
3276
+ callback();
3277
+ else
3278
+ timer = setTimeout(tick, Math.min(remaining, MAX_TIMER_DELAY_MS));
3279
+ };
3280
+ // Node clamps overflowing delays to 1 ms. Rearm bounded timers against a
3281
+ // monotonic clock so clock changes and event-loop stalls cannot shorten them.
3282
+ timer = setTimeout(tick, MAX_TIMER_DELAY_MS);
3283
+ }
3284
+ else {
3285
+ timer = setTimeout(callback, ms);
3286
+ }
3287
+ return () => clearTimeout(timer);
3288
+ }
3289
+ function sleep(ms) {
3290
+ return new Promise((resolve) => { scheduleTimeout(resolve, ms); });
3291
+ }
3292
+ function sleepSync(ms) {
3293
+ if (ms <= 0) {
3294
+ return;
3295
+ }
3296
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
3297
+ }
3298
+ async function withTimeout(promise, timeoutMs, labelOrOptions = {
3299
+ message: "timeout",
3300
+ }) {
3301
+ if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) {
3302
+ return await promise;
3303
+ }
3304
+ const options = typeof labelOrOptions === "string" ? { label: labelOrOptions } : labelOrOptions;
3305
+ const createError = options.createError ??
3306
+ (() => new Error(options.message ?? `${options.label ?? "operation"} timed out after ${timeoutMs}ms`));
3307
+ let cancelTimeout;
3308
+ try {
3309
+ return await Promise.race([
3310
+ promise,
3311
+ new Promise((_, reject) => {
3312
+ cancelTimeout = scheduleTimeout(() => {
3313
+ try {
3314
+ reject(createError());
3315
+ }
3316
+ catch (error) {
3317
+ reject(error);
3318
+ }
3319
+ }, timeoutMs);
3320
+ }),
3321
+ ]);
3322
+ }
3323
+ finally {
3324
+ cancelTimeout?.();
3325
+ }
3326
+ }
3327
+
3328
+ ;// CONCATENATED MODULE: ../../node_modules/@openclaw/fs-safe/dist/publication-recovery.js
3329
+
3330
+
3331
+
3332
+
3333
+
3334
+
3335
+
3336
+
3337
+ const non9pDevices = new Set();
3338
+ /** Other platforms keep their existing path even when the option is enabled. */
3339
+ function shouldPrepareDrvfsRecovery(enabled, dev) {
3340
+ if (enabled !== true)
3341
+ return false;
3342
+ // Synthetic mount evidence must not inherit observations from the real host.
3343
+ if (getFsSafeTestHooks()?.drvfsMountObservation)
3344
+ return true;
3345
+ if (process.platform !== "linux")
3346
+ return false;
3347
+ if (dev === undefined)
3348
+ return true;
3349
+ // Linux 9p allocates anonymous devices (major zero), never block devices.
3350
+ if (((dev >> 8n) & 0xfffn) !== 0n || ((dev >> 32n) & 0xfffff000n) !== 0n)
3351
+ return false;
3352
+ return !non9pDevices.has(dev);
3353
+ }
3354
+ /** Negative evidence only: a stale/reused device number can only disable recovery. */
3355
+ function mayPrepareDrvfsRecoveryAtFd(parentFd, dev) {
3356
+ if (!shouldPrepareDrvfsRecovery(true, dev))
3357
+ return false;
3358
+ if (getFsSafeTestHooks()?.drvfsMountObservation)
3359
+ return true;
3360
+ try {
3361
+ if (native_getNativeBinding()?.is9pFilesystem?.(parentFd) === false) {
3362
+ non9pDevices.add(dev);
3363
+ return false;
3364
+ }
3365
+ }
3366
+ catch { /* Unavailable evidence preserves full recovery-time verification. */ }
3367
+ return true;
3368
+ }
3369
+ /** No sampling or positive cache: the retained directory's exact mount owns admission. */
3370
+ function admitsDrvfsRenameRecoveryAtFd(parentFd) {
3371
+ try {
3372
+ const hook = getFsSafeTestHooks()?.drvfsMountObservation;
3373
+ if (!hook && process.platform !== "linux")
3374
+ return false;
3375
+ if (!Number.isInteger(parentFd) || parentFd < 0)
3376
+ return false;
3377
+ const observation = hook ? hook(parentFd) : (() => {
3378
+ if (external_node_fs_namespaceObject.statfsSync("/proc/self/fd", { bigint: true }).type !== 0x9fa0n)
3379
+ return undefined;
3380
+ // statfs follows this kernel-owned descriptor alias to the retained parent.
3381
+ return {
3382
+ magic: external_node_fs_namespaceObject.statfsSync(`/proc/self/fd/${parentFd}`, { bigint: true }).type,
3383
+ fdinfo: external_node_fs_namespaceObject.readFileSync(`/proc/self/fdinfo/${parentFd}`, "utf8"),
3384
+ mountinfo: external_node_fs_namespaceObject.readFileSync("/proc/self/mountinfo", "utf8"),
3385
+ };
3386
+ })();
3387
+ if (!observation || observation.magic !== 0x01021997n)
3388
+ return false;
3389
+ const ids = [...observation.fdinfo.matchAll(/^mnt_id:\s*(\d+)\s*$/gm)];
3390
+ if (ids.length !== 1)
3391
+ return false;
3392
+ const entries = observation.mountinfo.split("\n").filter(line => line.split(" ")[0] === ids[0][1]);
3393
+ if (entries.length !== 1)
3394
+ return false;
3395
+ const [before, after, extra] = entries[0].split(" - ");
3396
+ if (!before || !after || extra !== undefined || before.split(" ").length < 6)
3397
+ return false;
3398
+ const fields = after.split(" ");
3399
+ return fields.length === 3 && fields[0] === "9p" &&
3400
+ fields[2].split(",").some(option => option === "aname=drvfs" || option.startsWith("aname=drvfs;"));
3401
+ }
3402
+ catch {
3403
+ return false;
3404
+ }
3405
+ }
3406
+ /** Exact metadata is necessary but cannot exclude inode reuse after the final close. */
3407
+ function assertRecoveredPublication(actual, expected) {
3408
+ if (!actual.isFile() || actual.isSymbolicLink() || actual.nlink !== 1n ||
3409
+ actual.dev !== expected.dev || actual.ino !== expected.ino || actual.size !== expected.size ||
3410
+ actual.mode !== expected.mode || actual.uid !== expected.uid || actual.gid !== expected.gid) {
3411
+ throw new errors_FsSafeError("path-mismatch", "published file changed during DrvFS recovery");
3412
+ }
3413
+ }
3414
+ async function recoverAfterHiddenRename(params) {
3415
+ if (!admitsDrvfsRenameRecoveryAtFd(params.parentFd)) {
3416
+ throw new errors_FsSafeError("path-mismatch", "hidden rename recovery requires a verified DrvFS mount");
3417
+ }
3418
+ await params.closeWriter();
3419
+ for (let attempt = 0;; attempt++) {
3420
+ let recovered;
3421
+ try {
3422
+ recovered = await params.reopen();
3423
+ }
3424
+ catch (error) {
3425
+ if (!hasErrorCode(error, "ENOENT") || attempt === 4)
3426
+ throw error;
3427
+ await sleep(20);
3428
+ continue;
3429
+ }
3430
+ try {
3431
+ await params.retain?.(recovered);
3432
+ }
3433
+ catch (error) {
3434
+ await params.dispose?.(recovered).catch(() => undefined);
3435
+ throw error;
3436
+ }
3437
+ return recovered;
3438
+ }
3439
+ }
3440
+ function recoverAfterHiddenRenameSync(params) {
3441
+ if (!admitsDrvfsRenameRecoveryAtFd(params.parentFd)) {
3442
+ throw new errors_FsSafeError("path-mismatch", "hidden rename recovery requires a verified DrvFS mount");
3443
+ }
3444
+ params.closeWriter();
3445
+ for (let attempt = 0;; attempt++) {
3446
+ try {
3447
+ return params.reopen();
3448
+ }
3449
+ catch (error) {
3450
+ if (!hasErrorCode(error, "ENOENT") || attempt === 4)
3451
+ throw error;
3452
+ sleepSync(20);
3453
+ }
3454
+ }
3455
+ }
3456
+ function assertRecoveredFile(fd, expected, content) {
3457
+ assertRecoveredPublication(external_node_fs_namespaceObject.fstatSync(fd, { bigint: true }), expected);
3458
+ if (content && !bounded_read_readFileDescriptorBoundedSync(fd, content.byteLength).equals(content)) {
3459
+ throw new errors_FsSafeError("path-mismatch", "published content changed during DrvFS recovery");
3460
+ }
3461
+ assertRecoveredPublication(external_node_fs_namespaceObject.fstatSync(fd, { bigint: true }), expected);
3462
+ }
3463
+ function reopenRecoveredNativeFile(binding, parentFd, basename, expected, content) {
3464
+ if (!binding.openBeneath || !binding.closeOwnedFd || !binding.stagedFileMatches) {
3465
+ throw new errors_FsSafeError("helper-unavailable", "native DrvFS recovery requires descriptor-relative verification");
3466
+ }
3467
+ const fd = binding.openBeneath(parentFd, basename, nativeOpenFlags(external_node_fs_namespaceObject.constants.O_RDONLY | external_node_fs_namespaceObject.constants.O_NONBLOCK)).fd;
3468
+ try {
3469
+ assertRecoveredFile(fd, expected, content);
3470
+ if (!binding.stagedFileMatches(parentFd, basename, fd)) {
3471
+ throw new errors_FsSafeError("path-mismatch", "published name changed during DrvFS recovery");
3472
+ }
3473
+ return fd;
3474
+ }
3475
+ catch (error) {
3476
+ binding.closeOwnedFd(fd);
3477
+ throw error;
3478
+ }
3479
+ }
3480
+
3245
3481
  ;// CONCATENATED MODULE: ../../node_modules/@openclaw/fs-safe/dist/root-boundary.js
3246
3482
 
3247
3483
 
@@ -3620,67 +3856,6 @@ function recursiveMkdirPath(directory) {
3620
3856
  return needsAbsolutePath ? absolutePathWithRawSegments(directory) : directory;
3621
3857
  }
3622
3858
 
3623
- ;// CONCATENATED MODULE: ../../node_modules/@openclaw/fs-safe/dist/timing.js
3624
- const MAX_TIMER_DELAY_MS = 2 ** 31 - 1;
3625
- function scheduleTimeout(callback, ms) {
3626
- let timer;
3627
- if (Number.isFinite(ms) && ms > MAX_TIMER_DELAY_MS) {
3628
- const startedAt = performance.now();
3629
- const tick = () => {
3630
- const remaining = ms - (performance.now() - startedAt);
3631
- if (remaining <= 0)
3632
- callback();
3633
- else
3634
- timer = setTimeout(tick, Math.min(remaining, MAX_TIMER_DELAY_MS));
3635
- };
3636
- // Node clamps overflowing delays to 1 ms. Rearm bounded timers against a
3637
- // monotonic clock so clock changes and event-loop stalls cannot shorten them.
3638
- timer = setTimeout(tick, MAX_TIMER_DELAY_MS);
3639
- }
3640
- else {
3641
- timer = setTimeout(callback, ms);
3642
- }
3643
- return () => clearTimeout(timer);
3644
- }
3645
- function sleep(ms) {
3646
- return new Promise((resolve) => { scheduleTimeout(resolve, ms); });
3647
- }
3648
- function sleepSync(ms) {
3649
- if (ms <= 0) {
3650
- return;
3651
- }
3652
- Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
3653
- }
3654
- async function withTimeout(promise, timeoutMs, labelOrOptions = {
3655
- message: "timeout",
3656
- }) {
3657
- if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) {
3658
- return await promise;
3659
- }
3660
- const options = typeof labelOrOptions === "string" ? { label: labelOrOptions } : labelOrOptions;
3661
- const createError = options.createError ??
3662
- (() => new Error(options.message ?? `${options.label ?? "operation"} timed out after ${timeoutMs}ms`));
3663
- let cancelTimeout;
3664
- try {
3665
- return await Promise.race([
3666
- promise,
3667
- new Promise((_, reject) => {
3668
- cancelTimeout = scheduleTimeout(() => {
3669
- try {
3670
- reject(createError());
3671
- }
3672
- catch (error) {
3673
- reject(error);
3674
- }
3675
- }, timeoutMs);
3676
- }),
3677
- ]);
3678
- }
3679
- finally {
3680
- cancelTimeout?.();
3681
- }
3682
- }
3683
-
3684
3859
  ;// CONCATENATED MODULE: ../../node_modules/@openclaw/fs-safe/dist/exclusive-create.js
3685
3860
 
3686
3861
 
@@ -3972,6 +4147,7 @@ class AtomicFile {
3972
4147
 
3973
4148
 
3974
4149
 
4150
+
3975
4151
  function replace_file_descriptor_parentCloseFailure(primary, closeError) {
3976
4152
  return primary ? new AggregateError([primary.error, closeError], "Atomic parent preparation and close failed") : closeError;
3977
4153
  }
@@ -4034,6 +4210,8 @@ async function pinDirectoryForMode(params) {
4034
4210
  ignoreChmodError: params.ignoreChmodError,
4035
4211
  });
4036
4212
  await owner.verify();
4213
+ if (params.allowDrvfsRenameRecovery)
4214
+ mayPrepareDrvfsRecoveryAtFd(handle.fd, expected.dev);
4037
4215
  return owner;
4038
4216
  }
4039
4217
  catch (error) {
@@ -4080,6 +4258,8 @@ function* applyDirectoryMode(io, params) {
4080
4258
  let primary;
4081
4259
  try {
4082
4260
  inspectAtomicIdentity(io, () => file.statExact(), expected, false, admit);
4261
+ if (params.allowDrvfsRenameRecovery)
4262
+ mayPrepareDrvfsRecoveryAtFd(file.fd, expected.dev);
4083
4263
  if (params.mode !== "preserve") {
4084
4264
  params.mutation?.assert();
4085
4265
  file.chmod(params.mode & 0o7777);
@@ -4305,146 +4485,6 @@ function __cleanupRegisteredTempPathForTest(tempPath) {
4305
4485
  }
4306
4486
  }
4307
4487
 
4308
- ;// CONCATENATED MODULE: ../../node_modules/@openclaw/fs-safe/dist/test-hooks.js
4309
-
4310
- let test_hooks_fsSafeTestHooks;
4311
- function allowFsSafeTestHooks() {
4312
- return false || process.env.VITEST === "true";
4313
- }
4314
- function getFsSafeTestHooks() {
4315
- return test_hooks_fsSafeTestHooks;
4316
- }
4317
- function __setFsSafeTestHooksForTest(hooks) {
4318
- if (hooks && !allowFsSafeTestHooks()) {
4319
- throw new Error("__setFsSafeTestHooksForTest is only available in tests");
4320
- }
4321
- test_hooks_fsSafeTestHooks = hooks;
4322
- }
4323
-
4324
- ;// CONCATENATED MODULE: ../../node_modules/@openclaw/fs-safe/dist/publication-recovery.js
4325
-
4326
-
4327
-
4328
-
4329
-
4330
-
4331
-
4332
- /** Other platforms keep their existing path even when the option is enabled. */
4333
- function shouldPrepareDrvfsRecovery(enabled) {
4334
- return enabled === true && (process.platform === "linux" || getFsSafeTestHooks()?.drvfsMountObservation !== undefined);
4335
- }
4336
- /** No sampling or positive cache: the retained directory's exact mount owns admission. */
4337
- function admitsDrvfsRenameRecoveryAtFd(parentFd) {
4338
- try {
4339
- const hook = getFsSafeTestHooks()?.drvfsMountObservation;
4340
- if (!hook && process.platform !== "linux")
4341
- return false;
4342
- if (!Number.isInteger(parentFd) || parentFd < 0)
4343
- return false;
4344
- const observation = hook ? hook(parentFd) : (() => {
4345
- if (external_node_fs_namespaceObject.statfsSync("/proc/self/fd", { bigint: true }).type !== 0x9fa0n)
4346
- return undefined;
4347
- // statfs follows this kernel-owned descriptor alias to the retained parent.
4348
- return {
4349
- magic: external_node_fs_namespaceObject.statfsSync(`/proc/self/fd/${parentFd}`, { bigint: true }).type,
4350
- fdinfo: external_node_fs_namespaceObject.readFileSync(`/proc/self/fdinfo/${parentFd}`, "utf8"),
4351
- mountinfo: external_node_fs_namespaceObject.readFileSync("/proc/self/mountinfo", "utf8"),
4352
- };
4353
- })();
4354
- if (!observation || observation.magic !== 0x01021997n)
4355
- return false;
4356
- const ids = [...observation.fdinfo.matchAll(/^mnt_id:\s*(\d+)\s*$/gm)];
4357
- if (ids.length !== 1)
4358
- return false;
4359
- const entries = observation.mountinfo.split("\n").filter(line => line.split(" ")[0] === ids[0][1]);
4360
- if (entries.length !== 1)
4361
- return false;
4362
- const [before, after, extra] = entries[0].split(" - ");
4363
- if (!before || !after || extra !== undefined || before.split(" ").length < 6)
4364
- return false;
4365
- const fields = after.split(" ");
4366
- return fields.length === 3 && fields[0] === "9p" &&
4367
- fields[2].split(",").some(option => option === "aname=drvfs" || option.startsWith("aname=drvfs;"));
4368
- }
4369
- catch {
4370
- return false;
4371
- }
4372
- }
4373
- /** Exact metadata is necessary but cannot exclude inode reuse after the final close. */
4374
- function assertRecoveredPublication(actual, expected) {
4375
- if (!actual.isFile() || actual.isSymbolicLink() || actual.nlink !== 1n ||
4376
- actual.dev !== expected.dev || actual.ino !== expected.ino || actual.size !== expected.size ||
4377
- actual.mode !== expected.mode || actual.uid !== expected.uid || actual.gid !== expected.gid) {
4378
- throw new errors_FsSafeError("path-mismatch", "published file changed during DrvFS recovery");
4379
- }
4380
- }
4381
- async function recoverAfterHiddenRename(params) {
4382
- if (!admitsDrvfsRenameRecoveryAtFd(params.parentFd)) {
4383
- throw new errors_FsSafeError("path-mismatch", "hidden rename recovery requires a verified DrvFS mount");
4384
- }
4385
- await params.closeWriter();
4386
- for (let attempt = 0;; attempt++) {
4387
- let recovered;
4388
- try {
4389
- recovered = await params.reopen();
4390
- }
4391
- catch (error) {
4392
- if (!hasErrorCode(error, "ENOENT") || attempt === 4)
4393
- throw error;
4394
- await sleep(20);
4395
- continue;
4396
- }
4397
- try {
4398
- await params.retain?.(recovered);
4399
- }
4400
- catch (error) {
4401
- await params.dispose?.(recovered).catch(() => undefined);
4402
- throw error;
4403
- }
4404
- return recovered;
4405
- }
4406
- }
4407
- function recoverAfterHiddenRenameSync(params) {
4408
- if (!admitsDrvfsRenameRecoveryAtFd(params.parentFd)) {
4409
- throw new errors_FsSafeError("path-mismatch", "hidden rename recovery requires a verified DrvFS mount");
4410
- }
4411
- params.closeWriter();
4412
- for (let attempt = 0;; attempt++) {
4413
- try {
4414
- return params.reopen();
4415
- }
4416
- catch (error) {
4417
- if (!hasErrorCode(error, "ENOENT") || attempt === 4)
4418
- throw error;
4419
- sleepSync(20);
4420
- }
4421
- }
4422
- }
4423
- function assertRecoveredFile(fd, expected, content) {
4424
- assertRecoveredPublication(external_node_fs_namespaceObject.fstatSync(fd, { bigint: true }), expected);
4425
- if (content && !bounded_read_readFileDescriptorBoundedSync(fd, content.byteLength).equals(content)) {
4426
- throw new errors_FsSafeError("path-mismatch", "published content changed during DrvFS recovery");
4427
- }
4428
- assertRecoveredPublication(external_node_fs_namespaceObject.fstatSync(fd, { bigint: true }), expected);
4429
- }
4430
- function reopenRecoveredNativeFile(binding, parentFd, basename, expected, content) {
4431
- if (!binding.openBeneath || !binding.closeOwnedFd || !binding.stagedFileMatches) {
4432
- throw new errors_FsSafeError("helper-unavailable", "native DrvFS recovery requires descriptor-relative verification");
4433
- }
4434
- const fd = binding.openBeneath(parentFd, basename, nativeOpenFlags(external_node_fs_namespaceObject.constants.O_RDONLY | external_node_fs_namespaceObject.constants.O_NONBLOCK)).fd;
4435
- try {
4436
- assertRecoveredFile(fd, expected, content);
4437
- if (!binding.stagedFileMatches(parentFd, basename, fd)) {
4438
- throw new errors_FsSafeError("path-mismatch", "published name changed during DrvFS recovery");
4439
- }
4440
- return fd;
4441
- }
4442
- catch (error) {
4443
- binding.closeOwnedFd(fd);
4444
- throw error;
4445
- }
4446
- }
4447
-
4448
4488
  ;// CONCATENATED MODULE: ../../node_modules/@openclaw/fs-safe/dist/directory-receipt.js
4449
4489
 
4450
4490
 
@@ -5037,8 +5077,11 @@ function staged_directory_openStagedDirectory(directory) {
5037
5077
 
5038
5078
 
5039
5079
 
5080
+
5040
5081
  /** Retained only for an explicitly enabled operation; no new default-path I/O. */
5041
- function retainDrvfsParent(directory) {
5082
+ function retainDrvfsParent(directory, dev, filesystemChecked = false) {
5083
+ if (!shouldPrepareDrvfsRecovery(true, dev))
5084
+ return undefined;
5042
5085
  let parent;
5043
5086
  try {
5044
5087
  // Resolve through the filesystem first: lexical normalization of link/..
@@ -5052,6 +5095,11 @@ function retainDrvfsParent(directory) {
5052
5095
  assertStagedDirectoryCurrent(retained.receipt);
5053
5096
  };
5054
5097
  assertCurrent();
5098
+ if (!filesystemChecked && !mayPrepareDrvfsRecoveryAtFd(retained.fd, retained.receipt.identity.dev)) {
5099
+ parent = undefined;
5100
+ external_node_fs_namespaceObject.closeSync(retained.fd);
5101
+ return undefined;
5102
+ }
5055
5103
  return { fd: retained.fd, assertCurrent, close() { external_node_fs_namespaceObject.closeSync(retained.fd); } };
5056
5104
  }
5057
5105
  catch {
@@ -5171,10 +5219,10 @@ class AtomicTempOwner {
5171
5219
  throw new Error("Atomic temp owner has no descriptor");
5172
5220
  return this.resource.fd;
5173
5221
  }
5174
- *prepareRecovery(content, directory = external_node_path_namespaceObject.dirname(this.pathname)) {
5222
+ *prepareRecovery(content, directory = external_node_path_namespaceObject.dirname(this.pathname), filesystemChecked = false) {
5175
5223
  if (!shouldPrepareDrvfsRecovery(true))
5176
5224
  return;
5177
- this.recoveryParent = retainDrvfsParent(directory);
5225
+ this.recoveryParent = retainDrvfsParent(directory, this.identity.dev, filesystemChecked);
5178
5226
  if (!this.recoveryParent)
5179
5227
  return;
5180
5228
  const observed = this.resource.statExact();
@@ -7525,11 +7573,11 @@ function fileLockSyncRootReceiptStillCurrent(pathAuthority, receipt) {
7525
7573
 
7526
7574
 
7527
7575
 
7528
- async function rootSidecarPublicationPending(lockRoot, relative, cleanAbandoned = false) {
7576
+ async function rootSidecarPublicationPending(lockRoot, relative, options = {}) {
7529
7577
  const resolved = await lockRoot.resolve(relative);
7530
7578
  const parent = external_node_path_namespaceObject.dirname(resolved);
7531
7579
  const identity = await directory_guard_inspectDirectoryIdentity(parent);
7532
- if (cleanAbandoned) {
7580
+ if (options.cleanAbandoned) {
7533
7581
  const admitted = admitFileLockSyncRootPath(captureFileLockSyncRootAuthority(lockRoot), resolved);
7534
7582
  const receipt = observeDirectory(external_node_path_namespaceObject.dirname(admitted.path));
7535
7583
  cleanupSidecarStages(admitted.path, candidate => {
@@ -7540,7 +7588,7 @@ async function rootSidecarPublicationPending(lockRoot, relative, cleanAbandoned
7540
7588
  assertFileLockSyncRootMutationAllowed(candidate, admitted.authority.denyMutations);
7541
7589
  });
7542
7590
  }
7543
- const pending = sidecar_lock_staging_sidecarPublicationPending(resolved);
7591
+ const pending = sidecar_lock_staging_sidecarPublicationPending(resolved, undefined, options);
7544
7592
  await directory_guard_inspectDirectoryIdentity(parent, identity);
7545
7593
  return pending && await lockRoot.resolve(relative) === resolved;
7546
7594
  }
@@ -7572,7 +7620,10 @@ async function openSidecarRoot(lockRoot, relative, discardObservation, onOpenFai
7572
7620
  break;
7573
7621
  }
7574
7622
  }
7575
- const observation = fileObservation();
7623
+ const observation = fileObservation({
7624
+ publicationPending: async (candidate, identity) => discardObservation === "changed" && candidate === resolved &&
7625
+ await rootSidecarPublicationPending(lockRoot, relative, { requireStage: true, identity }),
7626
+ });
7576
7627
  try {
7577
7628
  const opened = await observation.run(() => lockRoot.open(relative));
7578
7629
  if (opened.realPath !== expectedRealPath) {
@@ -7593,13 +7644,19 @@ async function openSidecarRoot(lockRoot, relative, discardObservation, onOpenFai
7593
7644
  return null;
7594
7645
  const discardable = observation.has(error, `unlinked:${resolved}`) ||
7595
7646
  (discardObservation === "changed" && observation.has(error, `changed:${resolved}`));
7596
- if (!discardObservation || (!missing && (!completeParents || !discardable)))
7647
+ const linkedChange = discardObservation === "changed" && observation.has(error, `linked-change:${resolved}`);
7648
+ if (!discardObservation || (!missing && (!completeParents || (!discardable && !linkedChange))))
7597
7649
  throw error;
7598
7650
  try {
7651
+ // Linked-change receipts already proved a matching stage while the exact
7652
+ // descriptor was open; retained ancestry and the current path still fence it.
7599
7653
  const probe = fileObservation();
7600
7654
  try {
7601
7655
  const current = await probe.run(() => lockRoot.stat(relative));
7602
- if (!current.isFile || current.isSymbolicLink || current.nlink !== 1)
7656
+ // A successor can still hold its matching publication-stage link.
7657
+ // Discard only the old read; retained ancestry is revalidated below.
7658
+ if (!current.isFile || current.isSymbolicLink || (current.nlink !== 1 &&
7659
+ !(current.nlink === 2 && await rootSidecarPublicationPending(lockRoot, relative))))
7603
7660
  throw error;
7604
7661
  }
7605
7662
  catch (probeError) {
@@ -15249,6 +15306,7 @@ class NativeStagedFile {
15249
15306
  #recoveryIdentity;
15250
15307
  #recoveryContent;
15251
15308
  #recovered = false;
15309
+ #prepareRecovery;
15252
15310
  #publicationTask;
15253
15311
  #rejectFinalSymlink = false;
15254
15312
  #unsupportedNoReplace;
@@ -15262,6 +15320,8 @@ class NativeStagedFile {
15262
15320
  this.#assertBeforeMutation = owner.assertBeforeMutation;
15263
15321
  this.#private = owner.permissionPolicy === "private-creation";
15264
15322
  this.#verifyMode = owner.permissionPolicy !== undefined;
15323
+ this.#prepareRecovery = shouldPrepareDrvfsRecovery(owner.allowDrvfsRenameRecovery, owner.directory.identity.dev) &&
15324
+ mayPrepareDrvfsRecoveryAtFd(owner.parentFd, owner.directory.identity.dev);
15265
15325
  }
15266
15326
  // The supplied closer owns parentFd even on construction or preparation failure.
15267
15327
  static async create(owner, input, maxBytes) {
@@ -15278,7 +15338,7 @@ class NativeStagedFile {
15278
15338
  }
15279
15339
  throw error;
15280
15340
  }
15281
- if (shouldPrepareDrvfsRecovery(owner.allowDrvfsRenameRecovery) && input.kind === "buffer") {
15341
+ if (staged.#prepareRecovery && input.kind === "buffer") {
15282
15342
  staged.#recoveryContent = typeof input.data === "string" ? Buffer.from(input.data, input.encoding) : Buffer.from(input.data);
15283
15343
  }
15284
15344
  await staged.#prepare(input, maxBytes);
@@ -15516,7 +15576,7 @@ class NativeStagedFile {
15516
15576
  this.#assertCurrent();
15517
15577
  assertFinalSymlinkRejected(external_node_path_namespaceObject.join(this.#owner.directory.realPath, basename), this.#rejectFinalSymlink);
15518
15578
  }
15519
- if (shouldPrepareDrvfsRecovery(this.#owner.allowDrvfsRenameRecovery)) {
15579
+ if (this.#prepareRecovery) {
15520
15580
  // Apply restrictive modes before exposing the name or releasing its last fd.
15521
15581
  if ((this.#owner.mode & 0o600) !== 0o600)
15522
15582
  external_node_fs_namespaceObject.fchmodSync(this.#file(), this.#owner.mode);
@@ -16116,10 +16176,11 @@ async function handleStaleSidecarAdmission(params) {
16116
16176
  throw error;
16117
16177
  }
16118
16178
  // An incomplete owner can still be writing; age is not liveness evidence.
16119
- if (!snapshot || (!params.parserState.parser && snapshot.payload === null) || isIncompleteSidecarLockRecord(snapshot.raw)) {
16179
+ if (!snapshot) {
16120
16180
  await params.waitForRetry();
16121
16181
  return;
16122
16182
  }
16183
+ const incomplete = (!params.parserState.parser && snapshot.payload === null) || isIncompleteSidecarLockRecord(snapshot.raw);
16123
16184
  const staleOptions = params.staleOptionsState;
16124
16185
  try {
16125
16186
  if (!staleOptions.shouldReclaimObserved) {
@@ -16155,7 +16216,7 @@ async function handleStaleSidecarAdmission(params) {
16155
16216
  assertUnheld();
16156
16217
  try {
16157
16218
  if (!shouldReclaim)
16158
- return defaultSidecarLockShouldReclaim(snapshot, params.staleMs, Date.now());
16219
+ return !incomplete && defaultSidecarLockShouldReclaim(snapshot, params.staleMs, Date.now());
16159
16220
  return await Reflect.apply(shouldReclaim, undefined, [{
16160
16221
  lockPath,
16161
16222
  normalizedTargetPath,
@@ -16201,6 +16262,9 @@ async function handleStaleSidecarAdmission(params) {
16201
16262
  await params.waitForRetry();
16202
16263
  return;
16203
16264
  }
16265
+ // Policy may diagnose an incomplete record, but can never authorize its removal.
16266
+ if (incomplete)
16267
+ throw sidecarLockStale(lockPath, normalizedTargetPath);
16204
16268
  if ((staleOptions.staleRecovery ?? "fail-closed") === "remove-if-unchanged") {
16205
16269
  const acquiredGuard = await admission.run(() => tryAcquireSidecarReclaimGuard(params.reclaimGuards, params.reclaimGuardPath, params.lockRoot));
16206
16270
  if (acquiredGuard)
@@ -16909,7 +16973,7 @@ async function acquireSidecarLock(options, context) {
16909
16973
  catch (error) {
16910
16974
  let cause = error;
16911
16975
  for (let depth = 0; depth < 4 && cause && typeof cause === "object"; depth++) {
16912
- if (observation.has(cause, "hardlink") && await rootSidecarPublicationPending(lockRoot, relativeLockPath, true)) {
16976
+ if (observation.has(cause, "hardlink") && await rootSidecarPublicationPending(lockRoot, relativeLockPath, { cleanAbandoned: true })) {
16913
16977
  exclusiveCreateConflict = true;
16914
16978
  throw Object.assign(new Error("sidecar publication in progress"), { code: "EEXIST" });
16915
16979
  }
@@ -17829,7 +17893,7 @@ async function runPinnedStagedWrite(params, parentPath, parentGuard) {
17829
17893
  ((params.mode & 0o400) !== 0 ||
17830
17894
  (process.platform === "linux" && (process.arch === "x64" || process.arch === "arm64")));
17831
17895
  if (shouldPrepareDrvfsRecovery(params.allowDrvfsRenameRecovery)) {
17832
- recoveryParent = retainDrvfsParent(parentPath);
17896
+ recoveryParent = retainDrvfsParent(parentPath, parentGuard.stat.dev);
17833
17897
  if (recoveryParent)
17834
17898
  recoveryIdentity = external_node_fs_namespaceObject.fstatSync(handle.fd, { bigint: true });
17835
17899
  if (recoveryParent && params.input.kind === "buffer")
@@ -18416,16 +18480,26 @@ function openedPathResolutionError(error = new errors_FsSafeError("path-mismatch
18416
18480
  }
18417
18481
  async function recordPreOpenFileChange(error, handle, filePath, before, opened) {
18418
18482
  if (!isFileObservationFailure(error, "identity") || !before?.isFile() || !opened?.isFile() ||
18419
- ![0n, 1n].includes(before.nlink) || ![0n, 1n].includes(opened.nlink))
18483
+ ![0n, 1n].includes(before.nlink) || ![0n, 1n, 2n].includes(opened.nlink))
18420
18484
  return;
18421
18485
  try {
18422
18486
  await strict_file_identity_inspectFileIdentity(async () => before);
18423
- const current = await strict_file_identity_inspectFileIdentity(() => process.platform === "win32"
18487
+ // A fresh exact descriptor distinguishes a completed handoff from a
18488
+ // still-linked generation that needs separate publication proof.
18489
+ const inspectCurrent = () => strict_file_identity_inspectFileIdentity(() => process.platform === "win32"
18424
18490
  ? external_node_fs_namespaceObject.fstatSync(handle.fd, { bigint: true }) : handle.stat({ bigint: true }), opened);
18425
- if (current.isFile() && [0n, 1n].includes(current.nlink) &&
18426
- (before.dev !== current.dev || before.ino !== current.ino)) {
18491
+ let current = await inspectCurrent();
18492
+ let publication = false;
18493
+ if (current.isFile() && current.nlink === 2n) {
18494
+ publication = await observedFilePublicationPending(filePath, current);
18495
+ current = await inspectCurrent();
18496
+ }
18497
+ if (current.isFile() && (before.dev !== current.dev || before.ino !== current.ino)) {
18427
18498
  // A stale pathname sample is not proof that its former inode was unlinked.
18428
- recordFileObservationFailure(error, `changed:${filePath}`);
18499
+ if ([0n, 1n].includes(current.nlink))
18500
+ recordFileObservationFailure(error, `changed:${filePath}`);
18501
+ else if (current.nlink === 2n && publication)
18502
+ recordFileObservationFailure(error, `linked-change:${filePath}`);
18429
18503
  }
18430
18504
  }
18431
18505
  catch {
@@ -18531,7 +18605,7 @@ async function openLocalFileDescriptor(filePath, options) {
18531
18605
  : await strict_file_identity_inspectFileIdentity(async () => inspect(await handle.stat({ bigint: true })), expected);
18532
18606
  }
18533
18607
  catch (error) {
18534
- if (openedIdentity && [0n, 1n].includes(openedIdentity.nlink)) {
18608
+ if (openedIdentity && [0n, 1n, 2n].includes(openedIdentity.nlink)) {
18535
18609
  await recordPreOpenFileChange(error, handle, filePath, preOpenStat, openedIdentity);
18536
18610
  }
18537
18611
  throw error;
@@ -22663,8 +22737,12 @@ async function commitPinnedWriteInRoot(root, pinned, params, input) {
22663
22737
  });
22664
22738
  }
22665
22739
  catch (error) {
22666
- if (error instanceof SidecarFallbackWriteError)
22667
- throw error.failure;
22740
+ if (error instanceof SidecarFallbackWriteError) {
22741
+ // Windows keeps its historical direct-write error identity.
22742
+ if (process.platform === "win32")
22743
+ throw error.failure;
22744
+ error = error.failure;
22745
+ }
22668
22746
  if (verifyingPublication)
22669
22747
  throw error;
22670
22748
  const errorCode = error?.code;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lousy-agents/agent-shell",
3
- "version": "5.23.8",
3
+ "version": "5.23.10",
4
4
  "description": "A flight recorder for npm script execution",
5
5
  "type": "module",
6
6
  "repository": {
@@ -37,7 +37,7 @@
37
37
  "typecheck": "tsc --noEmit"
38
38
  },
39
39
  "dependencies": {
40
- "@openclaw/fs-safe": "0.28.0",
40
+ "@openclaw/fs-safe": "0.28.1",
41
41
  "zod": "4.6.7"
42
42
  },
43
43
  "peerDependencies": {