@wspc/cli 0.1.11 → 0.1.12

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/cli.js CHANGED
@@ -1520,9 +1520,9 @@ function createConsistencyFetch(opts) {
1520
1520
  }
1521
1521
 
1522
1522
  // src/version.ts
1523
- var VERSION = "0.1.11";
1523
+ var VERSION = "0.1.12";
1524
1524
  var SPEC_SHA = "bec760cd";
1525
- var SPEC_FETCHED_AT = "2026-07-08T01:27:32.122Z";
1525
+ var SPEC_FETCHED_AT = "2026-07-08T02:10:53.728Z";
1526
1526
  var API_BASE = "https://api.wspc.ai";
1527
1527
 
1528
1528
  // src/index.ts
@@ -5040,17 +5040,18 @@ async function writeDriveRealtimeState(root, realtime) {
5040
5040
  async function withDriveLock(root, fn) {
5041
5041
  await mkdir(join2(root, DRIVE_DIR), { recursive: true });
5042
5042
  const lockFile = join2(root, DRIVE_DIR, "sync.lock");
5043
- const fh = await open(lockFile, "wx").catch(async (error) => {
5043
+ const acquire = async () => {
5044
+ const handle = await open(lockFile, "wx");
5045
+ await handle.writeFile(String(process.pid));
5046
+ return handle;
5047
+ };
5048
+ const fh = await acquire().catch(async (error) => {
5044
5049
  if (error.code !== "EEXIST") throw error;
5045
- const lockStat = await stat2(lockFile).catch((statError) => {
5046
- if (statError.code === "ENOENT") return void 0;
5047
- throw statError;
5048
- });
5049
- if (lockStat && Date.now() - lockStat.mtimeMs <= STALE_LOCK_MS) {
5050
+ if (!await isLockAbandoned(lockFile)) {
5050
5051
  throw new Error("sync lock already exists");
5051
5052
  }
5052
5053
  await rm(lockFile, { force: true });
5053
- return open(lockFile, "wx").catch((retryError) => {
5054
+ return acquire().catch((retryError) => {
5054
5055
  if (retryError.code === "EEXIST") {
5055
5056
  throw new Error("sync lock already exists");
5056
5057
  }
@@ -5066,6 +5067,28 @@ async function withDriveLock(root, fn) {
5066
5067
  });
5067
5068
  }
5068
5069
  }
5070
+ async function isLockAbandoned(lockFile) {
5071
+ const pid = await readLockPid(lockFile);
5072
+ if (pid !== void 0 && !isProcessAlive(pid)) return true;
5073
+ const lockStat = await stat2(lockFile).catch((statError) => {
5074
+ if (statError.code === "ENOENT") return void 0;
5075
+ throw statError;
5076
+ });
5077
+ return lockStat === void 0 || Date.now() - lockStat.mtimeMs > STALE_LOCK_MS;
5078
+ }
5079
+ async function readLockPid(lockFile) {
5080
+ const text = await readFile2(lockFile, "utf8").catch(() => void 0);
5081
+ if (text === void 0 || !/^\d+$/.test(text.trim())) return void 0;
5082
+ return Number(text.trim());
5083
+ }
5084
+ function isProcessAlive(pid) {
5085
+ try {
5086
+ process.kill(pid, 0);
5087
+ return true;
5088
+ } catch (error) {
5089
+ return error.code !== "ESRCH";
5090
+ }
5091
+ }
5069
5092
  function isRecord2(value) {
5070
5093
  return typeof value === "object" && value !== null && !Array.isArray(value);
5071
5094
  }
@@ -6628,6 +6651,7 @@ async function runDriveWatch(root, options = {}) {
6628
6651
  do {
6629
6652
  rerunRequested = false;
6630
6653
  try {
6654
+ emit({ kind: "drive_sync_start" });
6631
6655
  const summary = await runSync(root);
6632
6656
  emit({ kind: "drive_sync_once", ...summary });
6633
6657
  backoffMs = 1e3;