@henryqw/pi-subagent 27.10.4 → 27.11.0
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/CONTEXT.md +1 -1
- package/README.md +2 -0
- package/extensions/admission.ts +1 -82
- package/package.json +2 -2
package/CONTEXT.md
CHANGED
|
@@ -25,7 +25,7 @@ A display and continuation reference for one recorded direct worker, such as `D7
|
|
|
25
25
|
A new direct worker that resumes a finished worker's saved Pi conversation in a new tab with a new Direct reference.
|
|
26
26
|
|
|
27
27
|
**Checkout admission**:
|
|
28
|
-
The exclusive permission held by a direct write request that prevents Main and other direct writers from writing to the shared checkout.
|
|
28
|
+
The exclusive permission held by a direct write request or managed background writer that prevents Main and other direct writers from writing to the shared checkout. Pi Herdr supplies the shared process-local coordinator. Each owner keeps admission until termination is proven; read classification is not a sandbox.
|
|
29
29
|
|
|
30
30
|
**Isolated request**:
|
|
31
31
|
A durable goal and dependency graph of text and changeset tasks, with checked results and recovery state.
|
package/README.md
CHANGED
|
@@ -73,6 +73,8 @@ Every task requires `access: "read"` or `access: "write"`. Declare `write` for f
|
|
|
73
73
|
|
|
74
74
|
Read requests run parallel tasks up to `maxSubagents`. Chains run in order, replace literal `{previous}` with the preceding successful answer, and stop on failure. Any `write` task makes the whole request serial and reserves checkout admission until all owned workers stop.
|
|
75
75
|
|
|
76
|
+
Checkout admission is shared with managed background commands from `pi-herdr-tools`. An active or unknown background writer blocks direct writes. Main writes and direct writers block new command launches. Status and read tools remain available. This is process-local coordination, not an operating-system sandbox.
|
|
77
|
+
|
|
76
78
|
Direct writes change Main's checkout immediately, including dirty checkouts, and have no automatic checks or rollback. Preserve unrelated edits. See [Direct contract](./docs/orchestration.md#direct-contract) for write scope and checkout-admission rules.
|
|
77
79
|
|
|
78
80
|
Tasks in write requests must return one JSON completion object:
|
package/extensions/admission.ts
CHANGED
|
@@ -1,82 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
3
|
-
|
|
4
|
-
// Main's own tools that never change a checkout; every other Main call may write.
|
|
5
|
-
// `codemode` mutates nothing itself: its nested tool calls are admitted by their own names.
|
|
6
|
-
const MAIN_NON_WRITING_TOOLS = new Set([
|
|
7
|
-
"read", "grep", "find", "ffgrep", "fffind", "ls", "codegraph_explore", "subagent_status", "codemode",
|
|
8
|
-
]);
|
|
9
|
-
|
|
10
|
-
async function checkoutKey(pi: ExtensionAPI, ctx: ExtensionContext): Promise<string> {
|
|
11
|
-
const cwd = await realpath(ctx.cwd);
|
|
12
|
-
const result = await pi.exec("git", ["rev-parse", "--show-toplevel"], { cwd, timeout: 5_000 });
|
|
13
|
-
if (result.code !== 0 || result.killed) return cwd;
|
|
14
|
-
const root = result.stdout.replace(/\r?\n$/, "");
|
|
15
|
-
if (!root || /[\r\n\0]/.test(root)) throw new Error("Git returned a malformed checkout root during delegation admission.");
|
|
16
|
-
return await realpath(root);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Reserve checkouts only for direct writers. Main writes can run together, but
|
|
21
|
-
* each call must finish before a direct writer can start in that checkout.
|
|
22
|
-
* External processes and trusted extension lifecycle code are not intercepted.
|
|
23
|
-
*/
|
|
24
|
-
export function registerCheckoutAdmission(pi: ExtensionAPI, directCanWrite: (input: unknown) => boolean): (toolCallId: string) => () => void {
|
|
25
|
-
const heldCalls = new Set<string>();
|
|
26
|
-
const ownerByCheckout = new Map<string, string>();
|
|
27
|
-
const calls = new Map<string, { direct: boolean; key?: string }>();
|
|
28
|
-
// One Git lookup per working directory per session; a failed lookup is retried.
|
|
29
|
-
const checkouts = new Map<string, Promise<string>>();
|
|
30
|
-
const lookup = (ctx: ExtensionContext) => {
|
|
31
|
-
const cached = checkouts.get(ctx.cwd);
|
|
32
|
-
if (cached) return cached;
|
|
33
|
-
const key = checkoutKey(pi, ctx);
|
|
34
|
-
checkouts.set(ctx.cwd, key);
|
|
35
|
-
key.catch(() => { if (checkouts.get(ctx.cwd) === key) checkouts.delete(ctx.cwd); });
|
|
36
|
-
return key;
|
|
37
|
-
};
|
|
38
|
-
const release = (toolCallId: string) => {
|
|
39
|
-
if (heldCalls.has(toolCallId)) return;
|
|
40
|
-
const call = calls.get(toolCallId);
|
|
41
|
-
calls.delete(toolCallId);
|
|
42
|
-
if (call?.key && ownerByCheckout.get(call.key) === toolCallId) ownerByCheckout.delete(call.key);
|
|
43
|
-
};
|
|
44
|
-
pi.on("tool_call", async (event, ctx) => {
|
|
45
|
-
const direct = event.toolName === "delegate_task";
|
|
46
|
-
if (direct ? !directCanWrite(event.input) : MAIN_NON_WRITING_TOOLS.has(event.toolName)) return;
|
|
47
|
-
const call: { direct: boolean; key?: string } = { direct };
|
|
48
|
-
calls.set(event.toolCallId, call);
|
|
49
|
-
const key = await lookup(ctx);
|
|
50
|
-
if (calls.get(event.toolCallId) !== call) {
|
|
51
|
-
return { block: true, reason: `Call ${event.toolCallId} already settled; use mode: isolated to keep Main free.` };
|
|
52
|
-
}
|
|
53
|
-
const owner = ownerByCheckout.get(key);
|
|
54
|
-
const main = direct ? [...calls].find(([, active]) => !active.direct && active.key === key)?.[0] : undefined;
|
|
55
|
-
if (owner || main) {
|
|
56
|
-
release(event.toolCallId);
|
|
57
|
-
return {
|
|
58
|
-
block: true,
|
|
59
|
-
reason: `Checkout ${key} has ${owner ? `an admitted direct writer (${owner})` : `a Main potentially-writing call in flight (${main})`}; retry after it stops, or use mode: isolated to keep Main free.`,
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
call.key = key;
|
|
63
|
-
if (direct) ownerByCheckout.set(key, event.toolCallId);
|
|
64
|
-
});
|
|
65
|
-
pi.on("tool_result", (event) => release(event.toolCallId));
|
|
66
|
-
pi.on("tool_execution_end", (event) => release(event.toolCallId));
|
|
67
|
-
pi.on("session_start", () => checkouts.clear());
|
|
68
|
-
pi.on("session_shutdown", () => {
|
|
69
|
-
checkouts.clear();
|
|
70
|
-
// Session replacement is not proof that a held direct worker stopped.
|
|
71
|
-
for (const toolCallId of calls.keys()) release(toolCallId);
|
|
72
|
-
});
|
|
73
|
-
// The tool returns a handle before its worker stops. Release only after verified termination.
|
|
74
|
-
return (toolCallId) => {
|
|
75
|
-
const call = calls.get(toolCallId);
|
|
76
|
-
if (!call?.direct || !call.key) {
|
|
77
|
-
throw new Error(`Direct call ${toolCallId} was not admitted as a checkout writer; delegate again.`);
|
|
78
|
-
}
|
|
79
|
-
heldCalls.add(toolCallId);
|
|
80
|
-
return () => { heldCalls.delete(toolCallId); release(toolCallId); };
|
|
81
|
-
};
|
|
82
|
-
}
|
|
1
|
+
export { registerCheckoutAdmission } from "@henryqw/pi-herdr";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@henryqw/pi-subagent",
|
|
3
|
-
"version": "27.
|
|
3
|
+
"version": "27.11.0",
|
|
4
4
|
"description": "Delegate bounded direct work or durable checked isolated task graphs to Pi roles.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package",
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
},
|
|
72
72
|
"dependencies": {
|
|
73
73
|
"@henryqw/pi-config-store": "^4.0.0",
|
|
74
|
-
"@henryqw/pi-herdr": "^0.
|
|
74
|
+
"@henryqw/pi-herdr": "^0.6.0",
|
|
75
75
|
"@henryqw/pi-multi-codex": "^3.0.0",
|
|
76
76
|
"@henryqw/pi-process": "^0.2.0",
|
|
77
77
|
"@henryqw/pi-task-models": "^9.0.0",
|