@henryqw/pi-herdr 0.6.2 → 0.6.3

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
@@ -52,7 +52,9 @@ Errors expose `code` and `dispatched`. If `dispatched` is true, a mutation can h
52
52
 
53
53
  ### Checkout admission
54
54
 
55
- `checkoutAdmission(pi)` finds one coordinator through Pi's public event bus. Call `install(pi)` to register tool lifecycle guards. `guard(name, refresh)` installs an awaited recovery check before writes. `reserve(owner, checkout)` returns a release function only when no admitted writer or Main write is active. `restore(owner, checkout)` restores durable ownership; `release(owner)` requires caller-proved completion.
55
+ `checkoutAdmission(pi)` finds one coordinator through Pi's public event bus. Call `install(pi)` to register tool lifecycle guards.
56
+
57
+ `guard(name, refresh)` installs an awaited recovery check before writes. The callback receives the exact canonical checkout set after target resolution and before any member is admitted. `reserve` passes its one checkout to the same checks. If recovery fails, no member is admitted. `reserve(owner, checkout)` returns a release function only when no admitted writer or Main write is active. `restore(owner, checkout)` restores durable ownership; `release(owner)` requires caller-proved completion.
56
58
 
57
59
  `registerCheckoutAdmission(pi, directCanWrite)` keeps the direct-subagent policy: Main writes can overlap, but direct writers must wait for them and exclude other writes. A returned hold function keeps a direct request admitted beyond its tool result. Consumers must restore durable command ownership before allowing writes after restart. These mechanisms do not intercept external processes or provide a sandbox.
58
60
 
@@ -41,7 +41,7 @@ declare function createAdmission(): {
41
41
  classifyDirect: (classify: (input: unknown) => boolean, select?: ((input: unknown, ctx: {
42
42
  cwd: string;
43
43
  }) => Promise<readonly string[]>) | undefined) => void;
44
- guard: (name: string, refresh: () => Promise<void>) => void;
44
+ guard: (name: string, refresh: (checkouts: readonly string[]) => Promise<void>) => void;
45
45
  restore: (owner: string, checkout: string) => void;
46
46
  release: (owner: string) => void;
47
47
  reserve(owner: string, checkout: string): Promise<() => void>;
package/dist/admission.js CHANGED
@@ -50,18 +50,12 @@ function createAdmission() {
50
50
  if (ownerByCheckout.get(key) === toolCallId)
51
51
  ownerByCheckout.delete(key);
52
52
  };
53
- const refresh = async () => { for (const guard of guards.values())
54
- await guard(); };
53
+ const refresh = async (keys) => { for (const guard of guards.values())
54
+ await guard(keys); };
55
55
  const admit = async (event, ctx, host) => {
56
56
  const direct = event.toolName === "delegate_task";
57
57
  if (event.toolName === "background_command" || (direct ? !directCanWrite(event.input) : MAIN_NON_WRITING_TOOLS.has(event.toolName)))
58
58
  return;
59
- try {
60
- await refresh();
61
- }
62
- catch {
63
- return { block: true, reason: "Command ownership recovery failed; writes are blocked. Inspect /commands." };
64
- }
65
59
  const call = { direct };
66
60
  calls.set(event.toolCallId, call);
67
61
  let keys;
@@ -72,6 +66,13 @@ function createAdmission() {
72
66
  release(event.toolCallId);
73
67
  throw error;
74
68
  }
69
+ try {
70
+ await refresh(keys);
71
+ }
72
+ catch {
73
+ release(event.toolCallId);
74
+ return { block: true, reason: "Command ownership recovery failed; writes are blocked. Inspect /commands." };
75
+ }
75
76
  if (calls.get(event.toolCallId) !== call) {
76
77
  return { block: true, reason: `Call ${event.toolCallId} already settled; use mode: isolated to keep Main free.` };
77
78
  }
@@ -122,7 +123,7 @@ function createAdmission() {
122
123
  restore: (owner, checkout) => { durable.set(owner, checkout); },
123
124
  release: (owner) => { durable.delete(owner); },
124
125
  async reserve(owner, checkout) {
125
- await refresh();
126
+ await refresh([checkout]);
126
127
  const conflict = [...durable].find(([, key]) => key === checkout)?.[0]
127
128
  ?? ownerByCheckout.get(checkout)
128
129
  ?? [...calls].find(([, call]) => call.keys?.includes(checkout))?.[0];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@henryqw/pi-herdr",
3
- "version": "0.6.2",
3
+ "version": "0.6.3",
4
4
  "description": "Shared client for interacting with Herdr from Node.js tools and Pi packages.",
5
5
  "keywords": [
6
6
  "pi-package",