@henryqw/pi-herdr 0.6.1 → 0.6.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
@@ -58,6 +58,14 @@ Errors expose `code` and `dispatched`. If `dispatched` is true, a mutation can h
58
58
 
59
59
  An optional third argument, `directCheckouts(input, ctx)`, returns additional canonical checkout paths for a direct request. Admission reserves the current checkout and the complete selected set together. A conflict in one member blocks the request without a partial reservation. The caller validates repository selection; the hold function releases the set only after caller-proved worker termination.
60
60
 
61
+ ### Path locks
62
+
63
+ `withWorktreeLock(checkout, operation)` locks a path while the operation runs. Acquisition, heartbeat updates, and release use synchronous filesystem calls. Slow storage can block the event loop. The operation can remain asynchronous. A heartbeat cannot remain in flight when the helper releases the lock.
64
+
65
+ If a heartbeat detects lost ownership, the call rejects after the operation finishes and does not release the changed lock. If the operation also fails, an `AggregateError` contains both errors. Acquisition, operation, and release errors remain visible. The helper does not stop or undo the operation.
66
+
67
+ Heartbeats do not prove continuous ownership or detect all external lock removal or replacement between checks. Do not remove active lock files. Long event-loop pauses can delay heartbeats and permit stale-lock recovery by another process. A lock error does not prove that the operation had no effect. Inspect state before a retry.
68
+
61
69
  ### `startPiAgent`
62
70
 
63
71
  On macOS, a shell that starts or runs a prompt hook can lose Enter for a launch command longer than 1024 bytes. The pane then waits forever. To prevent this, the helper first checks `pane process-info`. When the pane shell owns the foreground process group, it runs `pane run <pane> "echo <token>"` and polls `pane read` for up to 20 seconds. The probe passes when the token appears on its own line, with a prompt after it.
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { lock } from "proper-lockfile";
1
+ import { lockSync } from "proper-lockfile";
2
2
  export { requestHerdr, HerdrRequestError } from "./socket.js";
3
3
  export { checkoutAdmission, checkoutKey, registerCheckoutAdmission } from "./admission.js";
4
4
  const delay = (milliseconds) => new Promise((resolve) => setTimeout(resolve, milliseconds));
@@ -139,12 +139,24 @@ export function hasHerdrErrorCode(result, expected) {
139
139
  }
140
140
  /** Lock a Herdr worktree checkout path while mutating it via the Herdr CLI. */
141
141
  export async function withWorktreeLock(checkout, operation) {
142
- const release = await lock(checkout);
142
+ let compromised;
143
+ // Synchronous heartbeats cannot remain in flight when release removes the lock.
144
+ const release = lockSync(checkout, { onCompromised: (error) => { compromised = error; } });
143
145
  try {
144
- return await operation();
146
+ const result = await operation();
147
+ if (compromised)
148
+ throw compromised;
149
+ return result;
150
+ }
151
+ catch (error) {
152
+ if (compromised && error !== compromised)
153
+ throw new AggregateError([error, compromised], "Operation failed and lock ownership was lost.");
154
+ throw error;
145
155
  }
146
156
  finally {
147
- await release();
157
+ // A compromised lock is no longer ours to release.
158
+ if (!compromised)
159
+ release();
148
160
  }
149
161
  }
150
162
  function herdrCommandName(args) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@henryqw/pi-herdr",
3
- "version": "0.6.1",
3
+ "version": "0.6.2",
4
4
  "description": "Shared client for interacting with Herdr from Node.js tools and Pi packages.",
5
5
  "keywords": [
6
6
  "pi-package",