@lawaty/lacode 0.1.8 → 0.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +35 -4
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -2245,9 +2245,16 @@ function writeState(state2, path4 = STATE_PATH) {
2245
2245
  }
2246
2246
  }
2247
2247
  var isDue = (state2, now, interval = CHECK_INTERVAL_MS) => typeof state2.checkedAt !== "number" || now - state2.checkedAt >= interval;
2248
- function acquireLock(path4 = LOCK_PATH, now = Date.now()) {
2248
+ var isProcessAlive = (pid) => {
2249
2249
  try {
2250
- mkdirSync2(dirname3(path4), { recursive: true });
2250
+ process.kill(pid, 0);
2251
+ return true;
2252
+ } catch (error) {
2253
+ return error.code === "EPERM";
2254
+ }
2255
+ };
2256
+ function acquireLock(path4 = LOCK_PATH, now = Date.now()) {
2257
+ const claim = () => {
2251
2258
  const fd = openSync(path4, "wx");
2252
2259
  writeSync(fd, String(process.pid));
2253
2260
  closeSync(fd);
@@ -2257,12 +2264,36 @@ function acquireLock(path4 = LOCK_PATH, now = Date.now()) {
2257
2264
  } catch {
2258
2265
  }
2259
2266
  };
2267
+ };
2268
+ try {
2269
+ mkdirSync2(dirname3(path4), { recursive: true });
2270
+ return claim();
2260
2271
  } catch {
2272
+ let orphaned = false;
2261
2273
  try {
2262
- if (now - statSync3(path4).mtimeMs > LOCK_STALE_MS) unlinkSync2(path4);
2274
+ const pid = Number.parseInt(readFileSync4(path4, "utf8").trim(), 10);
2275
+ orphaned = !Number.isFinite(pid) || pid <= 0 || !isProcessAlive(pid);
2263
2276
  } catch {
2277
+ orphaned = true;
2278
+ }
2279
+ if (!orphaned) {
2280
+ try {
2281
+ orphaned = now - statSync3(path4).mtimeMs > LOCK_STALE_MS;
2282
+ } catch {
2283
+ orphaned = true;
2284
+ }
2285
+ }
2286
+ if (!orphaned) return void 0;
2287
+ try {
2288
+ unlinkSync2(path4);
2289
+ } catch {
2290
+ return void 0;
2291
+ }
2292
+ try {
2293
+ return claim();
2294
+ } catch {
2295
+ return void 0;
2264
2296
  }
2265
- return void 0;
2266
2297
  }
2267
2298
  }
2268
2299
  async function checkForUpdate(opts) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lawaty/lacode",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "description": "Ultimate opencode setup for Go users — cost-controlled pooled subagents, hang recovery, and notifications for opencode.",
5
5
  "license": "MIT",
6
6
  "type": "module",