pi-daddy 0.59.0 → 0.60.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/CHANGELOG.md +18 -0
- package/README.md +105 -21
- package/contracts/ledger-record/v1/README.md +6 -0
- package/dist/executors/activity-session.d.ts +4 -0
- package/dist/executors/activity-session.d.ts.map +1 -1
- package/dist/executors/activity-session.js +19 -0
- package/dist/executors/activity-session.js.map +1 -1
- package/dist/executors/child-final.d.ts +2 -0
- package/dist/executors/child-final.d.ts.map +1 -1
- package/dist/executors/child-final.js +4 -0
- package/dist/executors/child-final.js.map +1 -1
- package/dist/executors/child-usage.d.ts +129 -0
- package/dist/executors/child-usage.d.ts.map +1 -0
- package/dist/executors/child-usage.js +202 -0
- package/dist/executors/child-usage.js.map +1 -0
- package/dist/governance/auto-mode-policy.d.ts +3 -0
- package/dist/governance/auto-mode-policy.d.ts.map +1 -1
- package/dist/governance/auto-mode-policy.js +18 -2
- package/dist/governance/auto-mode-policy.js.map +1 -1
- package/dist/governance/operation-artifacts.d.ts +2 -0
- package/dist/governance/operation-artifacts.d.ts.map +1 -1
- package/dist/governance/operation-artifacts.js +20 -1
- package/dist/governance/operation-artifacts.js.map +1 -1
- package/dist/governance/operation-replay.d.ts +7 -0
- package/dist/governance/operation-replay.d.ts.map +1 -0
- package/dist/governance/operation-replay.js +47 -0
- package/dist/governance/operation-replay.js.map +1 -0
- package/dist/governance/parent-tool-calls.d.ts +31 -0
- package/dist/governance/parent-tool-calls.d.ts.map +1 -0
- package/dist/governance/parent-tool-calls.js +156 -0
- package/dist/governance/parent-tool-calls.js.map +1 -0
- package/dist/kernel/child-tools.d.ts +9 -1
- package/dist/kernel/child-tools.d.ts.map +1 -1
- package/dist/kernel/child-tools.js +25 -5
- package/dist/kernel/child-tools.js.map +1 -1
- package/dist/kernel/delegate-types.d.ts +26 -0
- package/dist/kernel/delegate-types.d.ts.map +1 -1
- package/dist/kernel/delegate-types.js.map +1 -1
- package/dist/kernel/delegate.d.ts.map +1 -1
- package/dist/kernel/delegate.js +19 -1
- package/dist/kernel/delegate.js.map +1 -1
- package/dist/kernel/dispatch-operation.d.ts +14 -0
- package/dist/kernel/dispatch-operation.d.ts.map +1 -1
- package/dist/kernel/dispatch-operation.js.map +1 -1
- package/dist/kernel/env-names.d.ts +16 -0
- package/dist/kernel/env-names.d.ts.map +1 -1
- package/dist/kernel/env-names.js +20 -0
- package/dist/kernel/env-names.js.map +1 -1
- package/dist/kernel/parent-tools.d.ts +174 -0
- package/dist/kernel/parent-tools.d.ts.map +1 -0
- package/dist/kernel/parent-tools.js +268 -0
- package/dist/kernel/parent-tools.js.map +1 -0
- package/dist/kernel/propagation.d.ts +1 -1
- package/dist/kernel/propagation.d.ts.map +1 -1
- package/dist/kernel/propagation.js +5 -0
- package/dist/kernel/propagation.js.map +1 -1
- package/dist/kernel/replay-safe.d.ts +110 -0
- package/dist/kernel/replay-safe.d.ts.map +1 -0
- package/dist/kernel/replay-safe.js +121 -0
- package/dist/kernel/replay-safe.js.map +1 -0
- package/dist/products/dashboard-cli.d.ts.map +1 -1
- package/dist/products/dashboard-cli.js +1 -0
- package/dist/products/dashboard-cli.js.map +1 -1
- package/dist/products/dashboard-render.d.ts +5 -0
- package/dist/products/dashboard-render.d.ts.map +1 -1
- package/dist/products/dashboard-render.js +25 -0
- package/dist/products/dashboard-render.js.map +1 -1
- package/dist/products/dashboard-session-client.d.ts +6 -0
- package/dist/products/dashboard-session-client.d.ts.map +1 -1
- package/dist/products/dashboard-session-client.js.map +1 -1
- package/dist/products/episode-report.d.ts +2 -0
- package/dist/products/episode-report.d.ts.map +1 -1
- package/dist/products/episode-report.js +5 -1
- package/dist/products/episode-report.js.map +1 -1
- package/extensions/chain-plan.ts +6 -1
- package/extensions/child-usage-report.ts +77 -0
- package/extensions/dashboard-session-server.ts +12 -0
- package/extensions/definition-describe.ts +74 -16
- package/extensions/delegate-chain.ts +37 -10
- package/extensions/delegation-artifacts.ts +43 -1
- package/extensions/delegation-operations.ts +71 -33
- package/extensions/delegation.ts +86 -15
- package/extensions/execute-child.ts +62 -6
- package/extensions/execution-evidence.ts +139 -4
- package/extensions/fanout-outcome.ts +4 -1
- package/extensions/grants-command.ts +12 -1
- package/extensions/grants.ts +23 -4
- package/extensions/init-command.ts +1 -1
- package/extensions/parent-tool-host.ts +228 -0
- package/extensions/parent-tool-proxy.ts +44 -0
- package/extensions/public-evidence.ts +8 -2
- package/extensions/reload-environment.ts +6 -0
- package/extensions/replay-retry.ts +119 -0
- package/extensions/run-delegation.ts +77 -12
- package/extensions/runtime-snapshot.ts +16 -1
- package/extensions/session-report.ts +25 -1
- package/extensions/session.ts +9 -0
- package/extensions/spawn-summary.ts +72 -3
- package/package.json +2 -2
- package/src/executors/activity-session.ts +28 -0
- package/src/executors/child-final.ts +11 -1
- package/src/executors/child-usage.ts +280 -0
- package/src/governance/auto-mode-policy.ts +19 -2
- package/src/governance/operation-artifacts.ts +21 -1
- package/src/governance/operation-replay.ts +70 -0
- package/src/governance/parent-tool-calls.ts +191 -0
- package/src/kernel/child-tools.ts +39 -9
- package/src/kernel/delegate-types.ts +26 -0
- package/src/kernel/delegate.ts +17 -1
- package/src/kernel/dispatch-operation.ts +11 -0
- package/src/kernel/env-names.ts +20 -0
- package/src/kernel/parent-tools.ts +342 -0
- package/src/kernel/propagation.ts +5 -0
- package/src/kernel/replay-safe.ts +182 -0
- package/src/products/dashboard-cli.ts +1 -0
- package/src/products/dashboard-render.ts +25 -0
- package/src/products/dashboard-session-client.ts +2 -0
- package/src/products/episode-report.ts +8 -1
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parent-run tool calls on the session owner's socket: who may ask, and how one request is answered.
|
|
3
|
+
*
|
|
4
|
+
* The transport is not new. It is the owner socket every governed descendant already calls for live Auto policy
|
|
5
|
+
* and dispatch operations (`auto-mode-policy.ts`): one authenticated JSON line in, one reply line out, and a held
|
|
6
|
+
* connection whose loss cancels what it asked for. This module adds the one thing that socket did not need
|
|
7
|
+
* before, which is **which child is asking**. Every descendant holds the same owner token, so a request must also
|
|
8
|
+
* present the execution id of a child registered here and the key minted for that one execution.
|
|
9
|
+
*
|
|
10
|
+
* What runs the real tool is handed in (`ParentToolGrant.run`); this layer knows no Pi and no tool. A call lives
|
|
11
|
+
* no longer than the child that asked: closing its registration or its connection cancels it, and the child's
|
|
12
|
+
* own wall-clock bound therefore bounds the call. Cancelling answers the child at once; a run slow to honour its
|
|
13
|
+
* signal can go on in the parent after that, and while it does the same child's next call is refused as busy.
|
|
14
|
+
*/
|
|
15
|
+
import { randomBytes, timingSafeEqual } from "node:crypto";
|
|
16
|
+
import { createConnection } from "node:net";
|
|
17
|
+
import type { AutoModeRef } from "../kernel/auto-mode.ts";
|
|
18
|
+
import {
|
|
19
|
+
MAX_PARENT_TOOL_REPLY_CHARS,
|
|
20
|
+
PARENT_TOOL_REFUSALS,
|
|
21
|
+
parseParentToolCall,
|
|
22
|
+
parseParentToolReply,
|
|
23
|
+
type ParentToolCall,
|
|
24
|
+
type ParentToolReply,
|
|
25
|
+
} from "../kernel/parent-tools.ts";
|
|
26
|
+
|
|
27
|
+
/** One running child's permission to ask, registered when it is launched and removed when it settles. */
|
|
28
|
+
export interface ParentToolGrant {
|
|
29
|
+
executionId: string;
|
|
30
|
+
/** The tool names the plan delivered to this child. Nothing else can be asked for under this identity. */
|
|
31
|
+
tools: readonly string[];
|
|
32
|
+
/** Re-check the live conditions and run the real tool. The signal ends when the child, or the call, does. */
|
|
33
|
+
run(tool: string, args: Record<string, unknown>, signal: AbortSignal): Promise<ParentToolReply>;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface ParentToolRegistration {
|
|
37
|
+
/** The secret this execution must present. Travels to the child once, in its launch environment. */
|
|
38
|
+
readonly key: string;
|
|
39
|
+
/** Changes while a call is in flight, so a child waiting on its parent is not mistaken for an idle one. */
|
|
40
|
+
activity(): string;
|
|
41
|
+
/** The child has settled: refuse it from now on and cancel anything it left running. */
|
|
42
|
+
close(): void;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface ParentToolCalls {
|
|
46
|
+
register(grant: ParentToolGrant): ParentToolRegistration;
|
|
47
|
+
/** Answer one request from the socket. Never rejects; every failure is a refusal. */
|
|
48
|
+
handle(call: unknown, signal: AbortSignal): Promise<ParentToolReply>;
|
|
49
|
+
close(): void;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const refused = (reason: string): ParentToolReply => ({ status: "refused", reason });
|
|
53
|
+
|
|
54
|
+
export function createParentToolCalls(): ParentToolCalls {
|
|
55
|
+
interface Entry {
|
|
56
|
+
grant: ParentToolGrant;
|
|
57
|
+
key: Buffer;
|
|
58
|
+
calls: number;
|
|
59
|
+
/** The call whose reply is pending: what activity reports and what cancellation aborts. */
|
|
60
|
+
inFlight?: AbortController;
|
|
61
|
+
/** The run itself, until it settles. A run slow to honour its signal outlives its reply and keeps the slot. */
|
|
62
|
+
running?: Promise<unknown>;
|
|
63
|
+
}
|
|
64
|
+
const entries = new Map<string, Entry>();
|
|
65
|
+
let closed = false;
|
|
66
|
+
return {
|
|
67
|
+
register(grant) {
|
|
68
|
+
if (closed) throw new Error("the session owner is closed; no parent-run tool can be registered");
|
|
69
|
+
if (entries.has(grant.executionId))
|
|
70
|
+
throw new Error("a parent-run tool grant is already registered for this execution");
|
|
71
|
+
const key = randomBytes(24).toString("hex");
|
|
72
|
+
const entry: Entry = { grant, key: Buffer.from(key), calls: 0 };
|
|
73
|
+
entries.set(grant.executionId, entry);
|
|
74
|
+
return {
|
|
75
|
+
key,
|
|
76
|
+
activity: () => `${entry.calls}:${entry.inFlight ? Math.floor(Date.now() / 1000) : "idle"}`,
|
|
77
|
+
close: () => {
|
|
78
|
+
if (entries.get(grant.executionId) === entry) entries.delete(grant.executionId);
|
|
79
|
+
entry.inFlight?.abort();
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
},
|
|
83
|
+
async handle(call, signal) {
|
|
84
|
+
const request = parseParentToolCall(call);
|
|
85
|
+
if ("refusal" in request) return refused(request.refusal);
|
|
86
|
+
const entry = entries.get(request.executionId);
|
|
87
|
+
const offered = Buffer.from(request.key);
|
|
88
|
+
// One answer for an unknown, finished or impersonated child, so a probe learns nothing from the difference.
|
|
89
|
+
if (!entry || offered.length !== entry.key.length || !timingSafeEqual(offered, entry.key))
|
|
90
|
+
return refused(PARENT_TOOL_REFUSALS.unknownChild);
|
|
91
|
+
if (!entry.grant.tools.includes(request.tool)) return refused(PARENT_TOOL_REFUSALS.notGranted);
|
|
92
|
+
if (entry.inFlight || entry.running) return refused(PARENT_TOOL_REFUSALS.busy);
|
|
93
|
+
if (signal.aborted) return refused(PARENT_TOOL_REFUSALS.cancelled);
|
|
94
|
+
const controller = new AbortController();
|
|
95
|
+
entry.inFlight = controller;
|
|
96
|
+
const stop = () => controller.abort();
|
|
97
|
+
signal.addEventListener("abort", stop, { once: true });
|
|
98
|
+
let done = false;
|
|
99
|
+
const running = (async () => entry.grant.run(request.tool, request.arguments, controller.signal))().finally(
|
|
100
|
+
() => void (done = true),
|
|
101
|
+
);
|
|
102
|
+
// One run per child at a time means in the parent, not only on the wire: the slot is free when it settles.
|
|
103
|
+
let slot: Promise<void> | undefined;
|
|
104
|
+
const release = () => {
|
|
105
|
+
if (entry.running === slot) entry.running = undefined;
|
|
106
|
+
};
|
|
107
|
+
slot = running.then(release, release);
|
|
108
|
+
entry.running = slot;
|
|
109
|
+
try {
|
|
110
|
+
// Raced against cancellation: a tool that ignores its signal must not hold the reply.
|
|
111
|
+
return await Promise.race([
|
|
112
|
+
running,
|
|
113
|
+
new Promise<ParentToolReply>((resolve) =>
|
|
114
|
+
controller.signal.addEventListener("abort", () => resolve(refused(PARENT_TOOL_REFUSALS.cancelled)), {
|
|
115
|
+
once: true,
|
|
116
|
+
}),
|
|
117
|
+
),
|
|
118
|
+
]);
|
|
119
|
+
} catch {
|
|
120
|
+
return refused(PARENT_TOOL_REFUSALS.failed);
|
|
121
|
+
} finally {
|
|
122
|
+
signal.removeEventListener("abort", stop);
|
|
123
|
+
if (entry.inFlight === controller) entry.inFlight = undefined;
|
|
124
|
+
if (done) release();
|
|
125
|
+
entry.calls += 1;
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
close() {
|
|
129
|
+
closed = true;
|
|
130
|
+
for (const entry of entries.values()) entry.inFlight?.abort();
|
|
131
|
+
entries.clear();
|
|
132
|
+
},
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const unavailable = () => new Error("the parent session is unavailable; the parent-run tool was not run");
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Ask the session owner to run one tool, from the child. The connection is held for the whole call: closing it
|
|
140
|
+
* (the child was cancelled, or exited) is what cancels the call in the parent.
|
|
141
|
+
*/
|
|
142
|
+
export function callParentTool(
|
|
143
|
+
reference: AutoModeRef,
|
|
144
|
+
call: ParentToolCall,
|
|
145
|
+
signal?: AbortSignal,
|
|
146
|
+
): Promise<ParentToolReply> {
|
|
147
|
+
return new Promise((resolve, reject) => {
|
|
148
|
+
if (signal?.aborted) return reject(new Error("parent-run tool call aborted"));
|
|
149
|
+
const socket = createConnection(reference.socketPath);
|
|
150
|
+
let output = "",
|
|
151
|
+
settled = false;
|
|
152
|
+
const finish = (error?: Error, value?: ParentToolReply) => {
|
|
153
|
+
if (settled) return;
|
|
154
|
+
settled = true;
|
|
155
|
+
signal?.removeEventListener("abort", cancel);
|
|
156
|
+
socket.destroy();
|
|
157
|
+
if (error) reject(error);
|
|
158
|
+
else resolve(value!);
|
|
159
|
+
};
|
|
160
|
+
const cancel = () => finish(new Error("parent-run tool call aborted"));
|
|
161
|
+
signal?.addEventListener("abort", cancel, { once: true });
|
|
162
|
+
socket.setEncoding("utf8");
|
|
163
|
+
// Bounds connecting only. Once the request is sent, the call lives as long as the child's own bounds allow.
|
|
164
|
+
socket.setTimeout(2000, () => finish(unavailable()));
|
|
165
|
+
socket.once("error", () => finish(unavailable()));
|
|
166
|
+
socket.once("connect", () => {
|
|
167
|
+
socket.setTimeout(0);
|
|
168
|
+
socket.write(JSON.stringify({ ...reference, action: "parent-tool", call }) + "\n");
|
|
169
|
+
});
|
|
170
|
+
socket.on("data", (chunk) => {
|
|
171
|
+
output += chunk;
|
|
172
|
+
if (output.length > MAX_PARENT_TOOL_REPLY_CHARS) finish(new Error("the parent-run tool reply is too large"));
|
|
173
|
+
});
|
|
174
|
+
socket.once("end", () => {
|
|
175
|
+
let reply: { ok?: unknown; error?: unknown; value?: unknown };
|
|
176
|
+
try {
|
|
177
|
+
reply = JSON.parse(output);
|
|
178
|
+
} catch {
|
|
179
|
+
return finish(unavailable()); // The owner went away mid-reply, or never answered.
|
|
180
|
+
}
|
|
181
|
+
if (reply?.ok !== true)
|
|
182
|
+
return finish(new Error(`the parent session refused the request (${String(reply?.error)})`));
|
|
183
|
+
try {
|
|
184
|
+
finish(undefined, parseParentToolReply(reply.value));
|
|
185
|
+
} catch (error) {
|
|
186
|
+
finish(error as Error);
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
socket.once("close", () => finish(unavailable()));
|
|
190
|
+
});
|
|
191
|
+
}
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
/** Child delivery is separate from a parent's catalog and from permission to grant a tool. */
|
|
2
2
|
import { toPiToolsAllowlist, type Capability } from "./resolve.ts";
|
|
3
3
|
import { refusal, type StructuredRefusal } from "./refusals.ts";
|
|
4
|
+
import {
|
|
5
|
+
isParentProxy,
|
|
6
|
+
parentProxiedTools,
|
|
7
|
+
parentToolModelNote,
|
|
8
|
+
parentToolsWithheldByModel,
|
|
9
|
+
type ParentToolFacts,
|
|
10
|
+
} from "./parent-tools.ts";
|
|
4
11
|
|
|
5
12
|
/** Native CLI tools shared by the qualified Pi 1.0.4 and 1.5.2 runtimes, not the display catalog. */
|
|
6
13
|
const nativeTools = new Set(["read", "bash", "powershell", "edit", "write", "grep", "find", "ls"]);
|
|
@@ -29,11 +36,31 @@ export function snapshotChildTools(tools: readonly ChildToolSource[]): readonly
|
|
|
29
36
|
);
|
|
30
37
|
}
|
|
31
38
|
|
|
39
|
+
/**
|
|
40
|
+
* The one refusal for a tool a child cannot be given. Shared with the launch-time check, so a plan that admitted
|
|
41
|
+
* a parent-run tool and can no longer be served is refused in exactly these words. `note` is empty except where
|
|
42
|
+
* a parent-run tool would have to be chained through a second level, or where the child's model is not the
|
|
43
|
+
* root's (`parentToolModelNote`).
|
|
44
|
+
*/
|
|
45
|
+
export function childToolUnavailable(tools: readonly string[], note = ""): StructuredRefusal {
|
|
46
|
+
return refusal(
|
|
47
|
+
"UNKNOWN_TOOL",
|
|
48
|
+
`child tool unavailable: ${tools.join(", ")} — the parent catalog is not child delivery. ` +
|
|
49
|
+
"Governed children load native Pi tools and Daddy's explicit entrypoint only; external extensions, MCP and " +
|
|
50
|
+
"SDK-only tools have no qualified child provider here. Keep this work in the parent or choose a definition " +
|
|
51
|
+
"using supported child tools. Additional permission cannot install or qualify a provider." +
|
|
52
|
+
note,
|
|
53
|
+
{ kind: "child-tool-unavailable", tools: tools.join(",") },
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
32
57
|
export function childToolDeliveryRefusal(
|
|
33
58
|
requested: Capability[],
|
|
34
|
-
context: { childToolSources?: readonly ChildToolSource[]; extensionPath?: string },
|
|
59
|
+
context: ParentToolFacts & { childToolSources?: readonly ChildToolSource[]; extensionPath?: string },
|
|
35
60
|
): StructuredRefusal | undefined {
|
|
36
61
|
const unavailable: string[] = [];
|
|
62
|
+
// An allowlisted parent-only tool is delivered by the root running it, and only when every condition holds.
|
|
63
|
+
const parentRun = new Set(parentProxiedTools(requested, context).map((tool) => tool.name));
|
|
37
64
|
for (const name of toPiToolsAllowlist(requested) ?? []) {
|
|
38
65
|
// The existing narrowing guard owns wildcard refusal, not delivery classification.
|
|
39
66
|
if (name === "*") continue;
|
|
@@ -48,15 +75,18 @@ export function childToolDeliveryRefusal(
|
|
|
48
75
|
requested.includes("tool:delegate") &&
|
|
49
76
|
!!context.extensionPath &&
|
|
50
77
|
(unobserved || source?.path === context.extensionPath);
|
|
51
|
-
if (!builtin && !governed) unavailable.push(name);
|
|
78
|
+
if (!builtin && !governed && !parentRun.has(name)) unavailable.push(name);
|
|
52
79
|
}
|
|
53
80
|
if (!unavailable.length) return undefined;
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
81
|
+
// Said only where it is the reason: this session holds the tool because ITS parent runs it.
|
|
82
|
+
const chained = unavailable.filter((name) => isParentProxy(name, context));
|
|
83
|
+
// Or this root would run it, but not for a child on another (or an unknown) provider and model.
|
|
84
|
+
const otherModel = parentToolsWithheldByModel(requested, context).filter((name) => unavailable.includes(name));
|
|
85
|
+
return childToolUnavailable(
|
|
86
|
+
unavailable,
|
|
87
|
+
(chained.length
|
|
88
|
+
? ` ${chained.join(", ")} reached this session through its own parent; a parent-run tool is not passed on ` +
|
|
89
|
+
"to a further level, so it cannot be delegated from here."
|
|
90
|
+
: "") + (otherModel.length ? parentToolModelNote(otherModel) : ""),
|
|
61
91
|
);
|
|
62
92
|
}
|
|
@@ -82,6 +82,20 @@ export interface DelegationContext {
|
|
|
82
82
|
observerExtensionPath?: string;
|
|
83
83
|
/** Public tool origins observed in the current host; names alone do not establish child delivery. */
|
|
84
84
|
childToolSources?: readonly import("./child-tools.ts").ChildToolSource[];
|
|
85
|
+
/** Daddy's child-side entrypoint for parent-run tools; loaded only by a plan that delivers one. */
|
|
86
|
+
parentToolExtensionPath?: string;
|
|
87
|
+
/**
|
|
88
|
+
* Allowlisted parent-only tools this session can run for a child right now, as the composition layer observed
|
|
89
|
+
* them. Absent on a host that cannot run one tool from another, below the root, and when the operator switched
|
|
90
|
+
* the path off; `parentProxiedTools` then admits nothing and the existing child-delivery refusal stands.
|
|
91
|
+
*/
|
|
92
|
+
parentTools?: readonly import("./parent-tools.ts").ParentToolDescriptor[];
|
|
93
|
+
/**
|
|
94
|
+
* The root's current provider and model, from the live tool context of the delegation being planned. A child
|
|
95
|
+
* is given a parent-run tool only when the `--model` it is planned with names the same pair; absent means
|
|
96
|
+
* unknown, which admits nothing. `"preview"` comes only from listings with no delegation in hand.
|
|
97
|
+
*/
|
|
98
|
+
rootModel?: import("./parent-tools.ts").ModelRef | "preview";
|
|
85
99
|
/**
|
|
86
100
|
* Extra per-child environment supplied by the composition layer (today: the activity timeline's local
|
|
87
101
|
* observation identity). Evaluated once the child's execution id is known. The kernel refuses any key in
|
|
@@ -212,6 +226,18 @@ export interface Delegation {
|
|
|
212
226
|
droppedTurns?: number;
|
|
213
227
|
rule?: string;
|
|
214
228
|
};
|
|
229
|
+
/**
|
|
230
|
+
* Parent-only tools this child reaches through the root session (decision of 2026-11-17), by name.
|
|
231
|
+
*
|
|
232
|
+
* Carried on the plan so the executor registers exactly these for the execution and nothing else can be asked
|
|
233
|
+
* for. Absent means the child has no parent-run tool and its arguments and environment are what they always were.
|
|
234
|
+
*/
|
|
235
|
+
parentTools?: string[];
|
|
236
|
+
/**
|
|
237
|
+
* With `parentTools`: the `provider/id` this child is given as `--model`, which was the root's own model when
|
|
238
|
+
* planned. The root compares it with its model again at launch and at every call.
|
|
239
|
+
*/
|
|
240
|
+
parentToolModel?: string;
|
|
215
241
|
/** Ledger id for this child's readable logical position, if the caller assigned one (F8). */
|
|
216
242
|
childId?: string;
|
|
217
243
|
/** Unique identity for this occurrence, if the caller assigned one. */
|
package/src/kernel/delegate.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { planSpawn } from "./spawn.ts";
|
|
|
7
7
|
import { ceilingForDefinition, digestDefinition, type DefinitionDigest, type SkillDefinition } from "./definitions.ts";
|
|
8
8
|
import { assertNarrowing, type Capability, type ResolveResult, expandSubsumed, resolve } from "./resolve.ts";
|
|
9
9
|
import { childToolDeliveryRefusal } from "./child-tools.ts";
|
|
10
|
+
import { parentProxiedTools } from "./parent-tools.ts";
|
|
10
11
|
import { selectedResourcePrompt } from "./selected-resources.ts";
|
|
11
12
|
import { checkRoutingAuthority, checkWorkspaceWildcardRequest } from "./routing-authority.ts";
|
|
12
13
|
import { DELEGATE_CAPABILITY, agentCapability, maySpawnDefinition, normaliseCapability } from "./capabilities.ts";
|
|
@@ -40,6 +41,7 @@ import type { Delegation, DelegationContext, DelegationRequest } from "./delegat
|
|
|
40
41
|
import { assertCapabilitiesArePropagatable } from "./capabilities.ts";
|
|
41
42
|
export type { Delegation, DelegationContext, DelegationRequest } from "./delegate-types.ts";
|
|
42
43
|
import { ENV_CHILD_DEFINITION, ENV_CHILD_EPISODE, ENV_CHILD_EXECUTION, GOVERNANCE_ENV_KEYS } from "./env-names.ts";
|
|
44
|
+
import { ENV_PROXIED_TOOLS } from "./env-names.ts";
|
|
43
45
|
|
|
44
46
|
export function planDelegation(request: DelegationRequest, ctx: DelegationContext): Delegation {
|
|
45
47
|
const childDepth = ctx.depth + 1;
|
|
@@ -301,8 +303,11 @@ export function planDelegation(request: DelegationRequest, ctx: DelegationContex
|
|
|
301
303
|
// Refuse undeliverable tools before calculating a permission request. Preserve escalation precedence:
|
|
302
304
|
// a caller without authority still receives the ordinary denial and its exact denied capability set.
|
|
303
305
|
const authority = resolve({ requested, parentGrant: ctx.ownGrant });
|
|
306
|
+
// Parent-run tools are decided against the model THIS child is given (`--model`), never a caller's claim about
|
|
307
|
+
// it. A separate `--provider` makes Pi resolve the pair differently, so it counts as not known.
|
|
308
|
+
const parentToolFacts = { ...ctx, childModel: request.provider === undefined ? request.model : undefined };
|
|
304
309
|
if (authority.denied.length === 0 && authority.universal.length === 0) {
|
|
305
|
-
const unavailable = childToolDeliveryRefusal(requested,
|
|
310
|
+
const unavailable = childToolDeliveryRefusal(requested, parentToolFacts);
|
|
306
311
|
if (unavailable) return { ...empty, requested, reason: unavailable.message, refusal: unavailable };
|
|
307
312
|
}
|
|
308
313
|
|
|
@@ -404,6 +409,12 @@ export function planDelegation(request: DelegationRequest, ctx: DelegationContex
|
|
|
404
409
|
// `-e` loads even under `--no-extensions`. A delegate-capable child loads the governance extension;
|
|
405
410
|
// a leaf gets only the no-tool observer. Neither path alters --tools or the computed grant.
|
|
406
411
|
const args = [...plan.args];
|
|
412
|
+
// Parent-run tools (2026-11-17): the child loads Daddy's own child-side entrypoint and is told, as public
|
|
413
|
+
// metadata, which tools it may ask the root to run. The same predicate kept these out of the delivery refusal
|
|
414
|
+
// above; here it is applied to what the child actually received. Loaded before the observer or governance
|
|
415
|
+
// entrypoint, so it reads its binding before anything republishes the environment.
|
|
416
|
+
const parentTools = parentProxiedTools(result.effective, parentToolFacts);
|
|
417
|
+
if (parentTools.length > 0) args.splice(args.length - 1, 0, "-e", ctx.parentToolExtensionPath!);
|
|
407
418
|
const observer = canSubDelegate ? ctx.extensionPath : ctx.observerExtensionPath;
|
|
408
419
|
if (observer) args.splice(args.length - 1, 0, "-e", observer);
|
|
409
420
|
|
|
@@ -443,6 +454,8 @@ export function planDelegation(request: DelegationRequest, ctx: DelegationContex
|
|
|
443
454
|
// reason on the other path.
|
|
444
455
|
env[ENV_APPROVED] = inheritApprovals(ctx.approved ?? [], inheritable).join(",");
|
|
445
456
|
if (ctx.ledgerPath) env[ENV_LEDGER] = ctx.ledgerPath;
|
|
457
|
+
// Names, descriptions and schemas only. The per-execution key is minted at launch, never planned.
|
|
458
|
+
if (parentTools.length > 0) env[ENV_PROXIED_TOOLS] = JSON.stringify(parentTools);
|
|
446
459
|
// ADR-0042, through the SAME builder `childEnv` uses. This is the fork the comment above is about: a rule
|
|
447
460
|
// spelled once in `childEnv` and not here is a rule that does not hold on the path a delegated child
|
|
448
461
|
// actually takes. Without this a routed grandchild inherits no pin and can route nowhere — fail-closed,
|
|
@@ -468,6 +481,9 @@ export function planDelegation(request: DelegationRequest, ctx: DelegationContex
|
|
|
468
481
|
...(grantedHandoff ? { handoff: grantedHandoff } : {}),
|
|
469
482
|
...(staged?.record ? { handoffRecord: staged.record } : {}),
|
|
470
483
|
...(staged?.dispose ? { disposeHandoff: staged.dispose } : {}),
|
|
484
|
+
...(parentTools.length > 0
|
|
485
|
+
? { parentTools: parentTools.map((tool) => tool.name), parentToolModel: parentToolFacts.childModel }
|
|
486
|
+
: {}),
|
|
471
487
|
childId: ctx.childSpawnId,
|
|
472
488
|
executionId: ctx.childExecutionId,
|
|
473
489
|
taskDigest,
|
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
import type { OperationArtifactRef } from "./operation-artifact.ts";
|
|
2
|
+
export interface AutomaticRetryEligibility {
|
|
3
|
+
version: 1;
|
|
4
|
+
eligible: true;
|
|
5
|
+
operationId: string;
|
|
6
|
+
executionId: string;
|
|
7
|
+
definitionId: string;
|
|
8
|
+
}
|
|
2
9
|
/** Explicit operation identity prevents duplicate dispatch, never authorizes work or caches results. */
|
|
3
10
|
export interface OperationReference {
|
|
4
11
|
artifact?: OperationArtifactRef;
|
|
@@ -10,6 +17,8 @@ export interface OperationReference {
|
|
|
10
17
|
startedAt: string;
|
|
11
18
|
updatedAt: string;
|
|
12
19
|
runtime?: {
|
|
20
|
+
/** Qualified optional owner evidence, never accepted from a caller's retry argument. */
|
|
21
|
+
automaticRetryEligibility?: AutomaticRetryEligibility;
|
|
13
22
|
control?: "failed";
|
|
14
23
|
work?: "succeeded" | "failed" | "unknown";
|
|
15
24
|
final?: { state: string; sessionId?: string; messageId?: string; leafId?: string; sha256?: string };
|
|
@@ -26,6 +35,8 @@ export interface OperationRequest {
|
|
|
26
35
|
export interface OperationClaim {
|
|
27
36
|
operation: OperationReference;
|
|
28
37
|
reused: boolean;
|
|
38
|
+
/** Read-only compatibility result; never a new admission or current semantic approval. */
|
|
39
|
+
legacyResult?: { text: string; definitionIdentity: "not-recorded" };
|
|
29
40
|
/** Only the elected caller receives these methods. Neither grants execution authority. */
|
|
30
41
|
started?(cwd: string, workspaceId: string | null): Promise<void>;
|
|
31
42
|
finish?(state: "settled" | "not-started" | "uncertain", runtime?: OperationReference["runtime"]): Promise<void>;
|
package/src/kernel/env-names.ts
CHANGED
|
@@ -42,11 +42,27 @@ export const ENV_HERDR_KEEP_PANE = "PI_DADDY_HERDR_KEEP_PANE";
|
|
|
42
42
|
export const ENV_CHILD_TIMEOUT = "PI_DADDY_CHILD_TIMEOUT";
|
|
43
43
|
export const ENV_CHILD_IDLE_TIMEOUT = "PI_DADDY_CHILD_IDLE_TIMEOUT";
|
|
44
44
|
export const ENV_APPROVAL_TIMEOUT = "PI_DADDY_APPROVAL_TIMEOUT";
|
|
45
|
+
/** Kill switch for the one automatic retry of a replay-safe child (2026-11-17); literal `0` turns it off. */
|
|
46
|
+
export const ENV_REPLAY_RETRY = "PI_DADDY_REPLAY_RETRY";
|
|
45
47
|
export const ENV_ALLOW_UNRESOLVED_MODELS = "PI_DADDY_ALLOW_UNRESOLVED_MODELS";
|
|
46
48
|
export const ENV_WORKSPACE_REGISTRY = "PI_DADDY_WORKSPACE_REGISTRY";
|
|
47
49
|
export const ENV_WORKSPACE_LEASE_DIR = "PI_DADDY_WORKSPACE_LEASE_DIR";
|
|
48
50
|
/** ADR-0042: what each authorised workspace id MEANT when the grant was established. Authority, not metadata. */
|
|
49
51
|
export const ENV_WORKSPACE_PIN = "PI_DADDY_WORKSPACE_PIN";
|
|
52
|
+
/**
|
|
53
|
+
* Parent-run tools (decision of 2026-11-17). Three variables, three owners.
|
|
54
|
+
*
|
|
55
|
+
* `ENV_PARENT_TOOLS` is the operator's kill switch: unset or literal `1` leaves the path on, literal `0` turns it
|
|
56
|
+
* off, and any other value is malformed and also off. `ENV_PROXIED_TOOLS` is written by the planner for one child:
|
|
57
|
+
* the public name, description and argument schema of each tool that child may ask the root to run.
|
|
58
|
+
* `ENV_PROXIED_TOOLS_KEY` is written at launch for that one execution: the secret a request must present beside
|
|
59
|
+
* its execution id.
|
|
60
|
+
*
|
|
61
|
+
* The two child-facing names are in `GRANT_ENV_KEYS` as well, so a grandchild never inherits its parent's.
|
|
62
|
+
*/
|
|
63
|
+
export const ENV_PARENT_TOOLS = "PI_DADDY_PARENT_TOOLS";
|
|
64
|
+
export const ENV_PROXIED_TOOLS = "PI_DADDY_PROXIED_TOOLS";
|
|
65
|
+
export const ENV_PROXIED_TOOLS_KEY = "PI_DADDY_PROXIED_TOOLS_KEY";
|
|
50
66
|
/** Explicit operator-only local public-response capture; never inherited by a captured child. */
|
|
51
67
|
export const ENV_PUBLIC_EVIDENCE_DIR = "PI_DADDY_PUBLIC_EVIDENCE_DIR";
|
|
52
68
|
export const ENV_EXECUTION_ARCHIVE = "PI_DADDY_EXECUTION_ARCHIVE";
|
|
@@ -102,10 +118,14 @@ export const GOVERNANCE_ENV_KEYS: readonly string[] = Object.freeze([
|
|
|
102
118
|
ENV_CHILD_TIMEOUT,
|
|
103
119
|
ENV_CHILD_IDLE_TIMEOUT,
|
|
104
120
|
ENV_APPROVAL_TIMEOUT,
|
|
121
|
+
ENV_REPLAY_RETRY,
|
|
105
122
|
ENV_ALLOW_UNRESOLVED_MODELS,
|
|
106
123
|
ENV_WORKSPACE_REGISTRY,
|
|
107
124
|
ENV_WORKSPACE_LEASE_DIR,
|
|
108
125
|
ENV_WORKSPACE_PIN,
|
|
126
|
+
ENV_PARENT_TOOLS,
|
|
127
|
+
ENV_PROXIED_TOOLS,
|
|
128
|
+
ENV_PROXIED_TOOLS_KEY,
|
|
109
129
|
ENV_PUBLIC_EVIDENCE_DIR,
|
|
110
130
|
ENV_EXECUTION_ARCHIVE,
|
|
111
131
|
ENV_NATIVE_SESSION_ROOT,
|