pi-edit-fence 1.0.0 → 1.0.2

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/README.md CHANGED
@@ -64,7 +64,7 @@ Edit the tunables at the top of `extensions/edit-fence.ts`:
64
64
  | `SCOPE` | `"file"` | `"file"` locks the exact file. `"dir"` locks a subtree for area-level coordination. |
65
65
  | `CLAIM_DEPTH` | `2` | Subtree depth when `SCOPE === "dir"` (2 keeps `src/api` and `src/ui` distinct). |
66
66
  | `LEASE_MS` | `5 min` | Idle time before a lock auto-expires. |
67
- | `CONTENDED_LEASE_MS` | `20 s` | Shorter idle lease applied while another session is waiting. |
67
+ | `CONTENDED_LEASE_MS` | `10 s` | Shorter idle lease applied while another session is waiting. |
68
68
  | `WAIT_MS` | `15 s` | How long a blocked edit waits before returning the retry-later message. |
69
69
  | `SHARED_PATTERNS` | configs, lockfiles | Glob patterns treated as warn-only shared zones. |
70
70
 
@@ -63,7 +63,7 @@ const LEASE_MS = 5 * 60 * 1000;
63
63
  // When another session is actively waiting on a subtree, the owner's idle lease
64
64
  // shortens to this. A genuinely-done owner frees fast, but only under contention;
65
65
  // a solo owner keeps the full LEASE_MS.
66
- const CONTENDED_LEASE_MS = 20 * 1000;
66
+ const CONTENDED_LEASE_MS = 10 * 1000;
67
67
  // On a blocked edit, wait this long for the owner to release/expire before giving
68
68
  // the agent a retry-later message (transparently absorbs brief overlaps).
69
69
  const WAIT_MS = 15 * 1000;
@@ -269,13 +269,15 @@ export default function (pi: ExtensionAPI) {
269
269
  return undefined;
270
270
  }
271
271
  if (result.kind === "block") {
272
+ // How long until the lock auto-expires if the owner stays idle from now.
273
+ // Contention shortens the lease, so this is the worst-case wait before retry succeeds.
274
+ const lease = result.owner.contendedAt != null ? CONTENDED_LEASE_MS : LEASE_MS;
275
+ const remainingSec = Math.max(0, Math.ceil((result.owner.ts + lease - Date.now()) / 1000));
272
276
  return {
273
277
  block: true,
274
278
  reason:
275
- `path-fence: ${SCOPE === "file" ? "file" : "area"} "${key}" is currently locked by another active pi session (${result.owner.session}, pid ${result.owner.pid}). ` +
276
- `This lock is TEMPORARY and releases automatically when that session moves on. ` +
277
- `Do not loop-retry now. Instead: ${SCOPE === "file" ? "work on OTHER files" : `work on files OUTSIDE "${key}"`} first, then RETRY this edit LATER — it will succeed once the other session is done. ` +
278
- `If you have no other work, tell the user "${key}" is held by another session (they can run "/steal ${key}" to force handover; you cannot run that yourself).`,
279
+ `path-fence: ${SCOPE === "file" ? "file" : "area"} "${key}" is locked by another active pi session (${result.owner.session}, pid ${result.owner.pid}). ` +
280
+ `Work on other files, or wait and retry this edit. The lock releases when the other session is done, and auto-expires in ~${remainingSec}s if it goes idle now (each edit it makes resets that timer).`,
279
281
  };
280
282
  }
281
283
  if (result.kind === "warn" && ctx.hasUI) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-edit-fence",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Stop concurrent pi sessions from clobbering each other's edits. Per-file locks, auto-claim on edit, retry-later, lease expiry, crash recovery. No git worktrees.",
5
5
  "keywords": [
6
6
  "pi-package",