pi-daddy 0.56.2 → 0.57.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 +11 -0
- package/README.md +16 -2
- package/dist/executors/owned-worker.d.ts.map +1 -1
- package/dist/executors/owned-worker.js +16 -14
- package/dist/executors/owned-worker.js.map +1 -1
- package/dist/executors/worker-artifact.d.ts +1 -1
- package/dist/executors/worker-artifact.js +1 -1
- package/dist/governance/approval-prompt.d.ts +3 -1
- package/dist/governance/approval-prompt.d.ts.map +1 -1
- package/dist/governance/approval-prompt.js +7 -3
- package/dist/governance/approval-prompt.js.map +1 -1
- package/dist/governance/permission-question.d.ts.map +1 -1
- package/dist/governance/permission-question.js +15 -5
- package/dist/governance/permission-question.js.map +1 -1
- package/dist/kernel/child-tools.d.ts +17 -0
- package/dist/kernel/child-tools.d.ts.map +1 -0
- package/dist/kernel/child-tools.js +46 -0
- package/dist/kernel/child-tools.js.map +1 -0
- package/dist/kernel/definitions.d.ts +2 -0
- package/dist/kernel/definitions.d.ts.map +1 -1
- package/dist/kernel/definitions.js.map +1 -1
- package/dist/kernel/delegate-types.d.ts +2 -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 +12 -1
- package/dist/kernel/delegate.js.map +1 -1
- package/dist/kernel/principal-binding.d.ts.map +1 -1
- package/dist/kernel/principal-binding.js +11 -0
- package/dist/kernel/principal-binding.js.map +1 -1
- package/dist/kernel/selected-definitions.d.ts.map +1 -1
- package/dist/kernel/selected-definitions.js +10 -1
- package/dist/kernel/selected-definitions.js.map +1 -1
- package/dist/kernel/selected-resources.d.ts +21 -0
- package/dist/kernel/selected-resources.d.ts.map +1 -0
- package/dist/kernel/selected-resources.js +10 -0
- package/dist/kernel/selected-resources.js.map +1 -0
- package/dist/kernel/spawn.d.ts +2 -0
- package/dist/kernel/spawn.d.ts.map +1 -1
- package/dist/kernel/spawn.js +3 -1
- package/dist/kernel/spawn.js.map +1 -1
- package/dist/products/dashboard-components.d.ts.map +1 -1
- package/dist/products/dashboard-components.js +17 -1
- package/dist/products/dashboard-components.js.map +1 -1
- package/dist/products/dashboard-screen.d.ts.map +1 -1
- package/dist/products/dashboard-screen.js +1 -1
- package/dist/products/dashboard-screen.js.map +1 -1
- package/dist/products/dashboard-settings.d.ts +2 -1
- package/dist/products/dashboard-settings.d.ts.map +1 -1
- package/dist/products/dashboard-settings.js +10 -1
- package/dist/products/dashboard-settings.js.map +1 -1
- package/extensions/approvals.ts +52 -38
- package/extensions/chain-approval-facts.ts +20 -0
- package/extensions/definition-describe.ts +1 -0
- package/extensions/delegate-chain.ts +35 -21
- package/extensions/grants.ts +2 -0
- package/extensions/session.ts +3 -0
- package/native/linux-x64/worker +0 -0
- package/native/linux-x64/worker.sha256 +1 -1
- package/native/provenance.json +3 -3
- package/native/worker.c +35 -4
- package/package.json +2 -2
- package/src/executors/owned-worker.ts +16 -14
- package/src/executors/worker-artifact.ts +1 -1
- package/src/governance/approval-prompt.ts +10 -4
- package/src/governance/permission-question.ts +16 -5
- package/src/kernel/child-tools.ts +62 -0
- package/src/kernel/definitions.ts +2 -0
- package/src/kernel/delegate-types.ts +2 -0
- package/src/kernel/delegate.ts +12 -1
- package/src/kernel/principal-binding.ts +11 -0
- package/src/kernel/selected-definitions.ts +11 -1
- package/src/kernel/selected-resources.ts +20 -0
- package/src/kernel/spawn.ts +4 -1
- package/src/products/dashboard-components.ts +21 -1
- package/src/products/dashboard-screen.ts +1 -0
- package/src/products/dashboard-settings.ts +11 -0
|
@@ -24,7 +24,7 @@ export function dashboardJevNotice(jev) {
|
|
|
24
24
|
return "JEV controls unavailable; inspect the parent Pi session";
|
|
25
25
|
return jev.error || `JEV ${jev.enabled ? "enabled" : "disabled"}; ${jev.availability ?? "status unknown"}`;
|
|
26
26
|
}
|
|
27
|
-
export function dashboardSettingsLines(settings, auto, selected, width) {
|
|
27
|
+
export function dashboardSettingsLines(settings, auto, selected, width, autoSource) {
|
|
28
28
|
if (!settings)
|
|
29
29
|
return ["Owner settings unavailable. Reconnect from /grants dashboard."];
|
|
30
30
|
const row = (key, label, nested = false) => `${key === selected ? ">" : " "}${nested ? " " : " "}${label}`;
|
|
@@ -45,6 +45,15 @@ export function dashboardSettingsLines(settings, auto, selected, width) {
|
|
|
45
45
|
return [
|
|
46
46
|
sectionHeading("PERMISSIONS", width),
|
|
47
47
|
row("auto", `Permission Auto: ${auto ? "ON" : "OFF"}`),
|
|
48
|
+
...(autoSource
|
|
49
|
+
? [
|
|
50
|
+
autoSource === "session"
|
|
51
|
+
? " Session choice; /new uses the startup setting."
|
|
52
|
+
: autoSource === "environment"
|
|
53
|
+
? " From the startup environment."
|
|
54
|
+
: " Startup default: OFF.",
|
|
55
|
+
]
|
|
56
|
+
: []),
|
|
48
57
|
"",
|
|
49
58
|
sectionHeading("JEV · optional advice", width),
|
|
50
59
|
row("jev", `JEV: ${jev.pending ? "waiting for consent" : !jev.available ? "unavailable" : jev.enabled ? "ON" : "OFF"}`),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dashboard-settings.js","sourceRoot":"","sources":["../../src/products/dashboard-settings.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"dashboard-settings.js","sourceRoot":"","sources":["../../src/products/dashboard-settings.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD,4FAA4F;AAC5F,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,OAAO,EAAE,WAAW,EAAE,OAAO,CAAU,CAAC;AAEzE,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,KAAc,EAA0B,EAAE,CACxE,gBAAgB,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,KAAK,KAAK,GAAG,CAAC,CAAC;AAGhD,MAAM,CAAC,MAAM,sBA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Ae,GAAG,CAAC,YAAY,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,YAAY,KAAK,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,EAAE,EAClG,IAAI,CACL;wBACD,+CAA+C;qBAChD;oBACH,CAAC,CAAC,EAAE,CAAC;aACR;YACH,CAAC,CAAC,CAAC,iDAAiD,CAAC,CAAC;QACxD,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,GAAG,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAC1C,EAAE;QACF,cAAc,CAAC,gBAAgB,EAAE,KAAK,CAAC;QACvC,GAAG,CAAC,MAAM,EAAE,eAAe,QAAQ,CAAC,WAAW,MAAM,QAAQ,CAAC,UAAU,GAAG,CAAC;QAC5E,GAAG,CAAC,MAAM,EAAE,eAAe,QAAQ,CAAC,WAAW,MAAM,QAAQ,CAAC,UAAU,GAAG,CAAC;QAC5E,QAAQ,CAAC,QAAQ;YACf,CAAC,CAAC,gDAAgD;YAClD,CAAC,CAAC,sDAAsD;QAC1D,EAAE;QACF,cAAc,CAAC,oCAAoC,EAAE,KAAK,CAAC;QAC3D,GAAG,CAAC,aAAa,EAAE,uBAAuB,QAAQ,CAAC,WAAW,KAAK,QAAQ,CAAC,QAAQ,8BAA8B,CAAC;QACnH,GAAG,CAAC,OAAO,EAAE,kBAAkB,QAAQ,CAAC,QAAQ,uBAAuB,CAAC;QACxE,GAAG,CAAC,SAAS,EAAE,sBAAsB,QAAQ,CAAC,OAAO,uBAAuB,CAAC;KAC9E,CAAC;AACJ,CAAC"}
|
package/extensions/approvals.ts
CHANGED
|
@@ -168,13 +168,13 @@ export async function storedApprovals(
|
|
|
168
168
|
gated: Capability[],
|
|
169
169
|
subject: string,
|
|
170
170
|
expectedBinding?: ApprovalBinding,
|
|
171
|
-
): Promise<ResolveApprovalsResult> {
|
|
171
|
+
): Promise<ResolveApprovalsResult & { recheckReasons: Record<Capability, string> }> {
|
|
172
172
|
const { valid, dropped } = await loadApprovals({
|
|
173
173
|
cwd: session.cwd,
|
|
174
174
|
now: new Date(),
|
|
175
175
|
snapshotOf: (name) => snapshotOf(session, name),
|
|
176
176
|
});
|
|
177
|
-
|
|
177
|
+
const result = resolveApprovals({
|
|
178
178
|
gated,
|
|
179
179
|
subject,
|
|
180
180
|
sessionApprovals: session.sessionApprovals,
|
|
@@ -186,6 +186,28 @@ export async function storedApprovals(
|
|
|
186
186
|
// arrives at `session_start` — after the session object is built.
|
|
187
187
|
inherited: verifyInherited(session.inheritedApprovals, (name) => snapshotOf(session, name)),
|
|
188
188
|
});
|
|
189
|
+
const recheckReasons: Record<Capability, string> = {};
|
|
190
|
+
const reasons = {
|
|
191
|
+
expired: "The previous permission expired or its expiry could not be verified.",
|
|
192
|
+
"instructions-changed": "The agent instructions changed or their previous version could not be verified.",
|
|
193
|
+
"type-changed": "The agent’s requested tools changed since the previous permission.",
|
|
194
|
+
"type-missing": "The previously approved agent definition is no longer available.",
|
|
195
|
+
"foreign-cwd": "The previous permission belongs to a different project folder.",
|
|
196
|
+
valid: "",
|
|
197
|
+
};
|
|
198
|
+
for (const capability of result.needsPrompt) {
|
|
199
|
+
const key = approvalKey(capability, subject);
|
|
200
|
+
const previous = dropped.find((entry) => entry.key === key);
|
|
201
|
+
if (previous) recheckReasons[capability] = reasons[previous.verdict];
|
|
202
|
+
else if (result.scopeMismatched.includes(capability))
|
|
203
|
+
recheckReasons[capability] = "The saved permission covers a different request.";
|
|
204
|
+
else {
|
|
205
|
+
const inherited = session.inheritedApprovals.get(key);
|
|
206
|
+
if (inherited && inherited !== snapshotOf(session, subject)?.bodySha256)
|
|
207
|
+
recheckReasons[capability] = reasons["instructions-changed"];
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return { ...result, recheckReasons };
|
|
189
211
|
}
|
|
190
212
|
|
|
191
213
|
/**
|
|
@@ -255,40 +277,32 @@ export async function obtainApprovals(
|
|
|
255
277
|
let refusalCode: RefusalCode | undefined;
|
|
256
278
|
let reason: string | undefined;
|
|
257
279
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
// RPC mode too, so an automated client's timeout or dismissal there would misreport as "a human
|
|
277
|
-
// declined" if we asked `ctx.hasUI` instead. Only `kind === "declined"` means a person said no.
|
|
278
|
-
humanDenied = outcome.kind === "declined";
|
|
279
|
-
// The full discriminant, not just the one bit of it that had a field. `no-ui`, `dismissed` and
|
|
280
|
-
// `error` used to produce records identical to each other, separated only by free-text `reason` —
|
|
281
|
-
// so "was there an operator who timed out, or was there nobody?" had no answer, and the two want
|
|
282
|
-
// different fixes. It was computed here all along and thrown away.
|
|
283
|
-
gateOutcome = outcome.kind;
|
|
284
|
-
refusalCode = pre.expired.includes(capability)
|
|
280
|
+
const outcome = await gate.request({
|
|
281
|
+
capability: pre.needsPrompt[0]!,
|
|
282
|
+
capabilities: pre.needsPrompt,
|
|
283
|
+
subject,
|
|
284
|
+
path,
|
|
285
|
+
task,
|
|
286
|
+
signal,
|
|
287
|
+
project: session.cwd,
|
|
288
|
+
workspace: expectedBinding?.workspace_id,
|
|
289
|
+
recheckReason: [...new Set(Object.values(pre.recheckReasons))].join(" ") || undefined,
|
|
290
|
+
...(expectedBinding ? { bindingKey: approvalBindingDigest(expectedBinding) } : {}),
|
|
291
|
+
});
|
|
292
|
+
if (outcome.scope === null) {
|
|
293
|
+
// Only an explicit Deny is a human refusal. Cancellation, expiry and UI failure grant nothing.
|
|
294
|
+
humanDenied = outcome.kind === "declined";
|
|
295
|
+
gateOutcome = outcome.kind;
|
|
296
|
+
refusalCode =
|
|
297
|
+
pre.expired.length > 0
|
|
285
298
|
? "APPROVAL_EXPIRED"
|
|
286
|
-
: pre.scopeMismatched.
|
|
299
|
+
: pre.scopeMismatched.length > 0
|
|
287
300
|
? "APPROVAL_SCOPE_MISMATCH"
|
|
288
301
|
: "GATED_UNAPPROVED";
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
302
|
+
reason = outcome.reason;
|
|
303
|
+
}
|
|
304
|
+
for (const capability of outcome.scope === null ? [] : pre.needsPrompt) {
|
|
305
|
+
const scope = outcome.scope!;
|
|
292
306
|
approved.push(capability);
|
|
293
307
|
// R-66: `prompt` means A HUMAN SAW A DIALOG FOR THIS. A caller that joined another's in-flight answer
|
|
294
308
|
// did not, so it records the source it actually had — the session approval that answer created. Eight
|
|
@@ -296,12 +310,12 @@ export async function obtainApprovals(
|
|
|
296
310
|
// prompt. Same repair as R-46, one level up: stop asserting a human was asked on a path where they
|
|
297
311
|
// were not.
|
|
298
312
|
sources[capability] = outcome.source === "auto" ? "auto" : outcome.joined ? "session" : "prompt";
|
|
299
|
-
scopes[capability] =
|
|
300
|
-
recordedScopes[capability] =
|
|
313
|
+
scopes[capability] = scope;
|
|
314
|
+
recordedScopes[capability] = scope;
|
|
301
315
|
if (expectedBinding) bindings[capability] = expectedBinding;
|
|
302
|
-
if (
|
|
316
|
+
if (scope === "once") uses[capability] = { max: 1, remaining: 0 };
|
|
303
317
|
|
|
304
|
-
if (
|
|
318
|
+
if (scope === "session" || scope === "always") {
|
|
305
319
|
const key = approvalKey(capability, subject);
|
|
306
320
|
// Whether THIS call created the authority, decided before we add it. `joined` means a human answer
|
|
307
321
|
// opened by another delegation was shared with us; an existing key means it was already standing.
|
|
@@ -313,7 +327,7 @@ export async function obtainApprovals(
|
|
|
313
327
|
else session.sessionApprovals.add(key);
|
|
314
328
|
banked.push({ key, capability, subject, persisted: false, owned });
|
|
315
329
|
}
|
|
316
|
-
if (
|
|
330
|
+
if (scope === "always") {
|
|
317
331
|
const now = new Date();
|
|
318
332
|
const current = snapshot(subject);
|
|
319
333
|
// No readable ceiling means the entry would carry `grantAtApproval: []`, which `entryVerdict`
|
|
@@ -2,6 +2,26 @@ import type { InheritableApproval } from "../src/kernel/approval.ts";
|
|
|
2
2
|
import type { Capability } from "../src/kernel/resolve.ts";
|
|
3
3
|
import type { ApprovalOutcome } from "./approvals.ts";
|
|
4
4
|
|
|
5
|
+
/** An upfront Auto answer is provisional until an actual step admission, never consumed approval evidence. */
|
|
6
|
+
export function retainedChainApproval(outcome: ApprovalOutcome): ApprovalOutcome | undefined {
|
|
7
|
+
const approved = outcome.approved.filter((capability) => outcome.sources[capability] !== "auto");
|
|
8
|
+
if (!approved.length) return undefined;
|
|
9
|
+
const keep = new Set(approved);
|
|
10
|
+
const filter = <T>(values: Record<Capability, T>): Record<Capability, T> =>
|
|
11
|
+
Object.fromEntries(Object.entries(values).filter(([capability]) => keep.has(capability)));
|
|
12
|
+
return {
|
|
13
|
+
...outcome,
|
|
14
|
+
approved,
|
|
15
|
+
sources: filter(outcome.sources),
|
|
16
|
+
scopes: filter(outcome.scopes),
|
|
17
|
+
recordedScopes: filter(outcome.recordedScopes),
|
|
18
|
+
bindings: filter(outcome.bindings),
|
|
19
|
+
expiresAt: filter(outcome.expiresAt),
|
|
20
|
+
uses: filter(outcome.uses),
|
|
21
|
+
...(outcome.banked ? { banked: outcome.banked.filter((entry) => keep.has(entry.capability)) } : {}),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
5
25
|
export interface ChainApprovalAudit {
|
|
6
26
|
sources: Map<string, ApprovalOutcome["sources"][Capability]>;
|
|
7
27
|
scopes: Map<string, ApprovalOutcome["recordedScopes"][Capability]>;
|
|
@@ -38,6 +38,7 @@ export function registerDefinitionDescribe(pi: ExtensionAPI, session: GrantsSess
|
|
|
38
38
|
bodySha256: digestDefinition(definition).sha256,
|
|
39
39
|
binding: definition.binding ?? null,
|
|
40
40
|
definitionId: definition.definitionId,
|
|
41
|
+
selectedResources: definition.selectedResources ?? null,
|
|
41
42
|
};
|
|
42
43
|
const capture = publicEvidenceCall(session.publicEvidence, _id, "delegate_describe", [{ agent: params.agent }]);
|
|
43
44
|
capture.selected(0, definition);
|
|
@@ -44,7 +44,12 @@ import { runOneDelegation } from "./run-delegation.ts";
|
|
|
44
44
|
import { isCriticalAssuranceBlock } from "./execute-child.ts";
|
|
45
45
|
import type { GrantsSession } from "./session.ts";
|
|
46
46
|
import { GovernanceRefusal, refusal, type StructuredRefusal } from "../src/kernel/refusals.ts";
|
|
47
|
-
import {
|
|
47
|
+
import {
|
|
48
|
+
chainApprovalFacts,
|
|
49
|
+
newChainApprovalAudit,
|
|
50
|
+
rememberChainApproval,
|
|
51
|
+
retainedChainApproval,
|
|
52
|
+
} from "./chain-approval-facts.ts";
|
|
48
53
|
import { newExecutionId } from "../src/kernel/execution-id.ts";
|
|
49
54
|
import { planChain, type GateRequest } from "./chain-plan.ts";
|
|
50
55
|
import { contextShape } from "./context-shape.ts";
|
|
@@ -234,7 +239,7 @@ export function registerChainTool(pi: ExtensionAPI, session: GrantsSession): voi
|
|
|
234
239
|
throw new Error(message);
|
|
235
240
|
}
|
|
236
241
|
|
|
237
|
-
// One dialog per
|
|
242
|
+
// One dialog per exact permission set for an agent/step, all before the first step runs.
|
|
238
243
|
const preApproved: InheritableApproval[] = [];
|
|
239
244
|
const approvalAudit = newChainApprovalAudit();
|
|
240
245
|
const approvalStep = new Map<string, number>();
|
|
@@ -242,36 +247,45 @@ export function registerChainTool(pi: ExtensionAPI, session: GrantsSession): voi
|
|
|
242
247
|
[];
|
|
243
248
|
let declined: { request: GateRequest; outcome: Awaited<ReturnType<typeof obtainApprovals>> } | undefined;
|
|
244
249
|
|
|
250
|
+
const requestGroups = new Map<string, GateRequest[]>();
|
|
245
251
|
for (const request of chainPlan.requests) {
|
|
252
|
+
const key = JSON.stringify([request.subject, request.path, request.stepIndex]);
|
|
253
|
+
const group = requestGroups.get(key) ?? [];
|
|
254
|
+
group.push(request);
|
|
255
|
+
requestGroups.set(key, group);
|
|
256
|
+
}
|
|
257
|
+
for (const requests of requestGroups.values()) {
|
|
258
|
+
const request = requests[0]!;
|
|
246
259
|
const outcome = await obtainApprovals(
|
|
247
260
|
session,
|
|
248
|
-
|
|
261
|
+
requests.map((entry) => entry.capability),
|
|
249
262
|
request.subject,
|
|
250
263
|
request.path,
|
|
251
264
|
ctx,
|
|
252
265
|
request.task,
|
|
253
266
|
signal,
|
|
254
267
|
);
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
//
|
|
258
|
-
|
|
259
|
-
declined = { request, outcome };
|
|
268
|
+
const missing = requests.find((entry) => !outcome.approved.includes(entry.capability));
|
|
269
|
+
if (missing) {
|
|
270
|
+
// Once the chain cannot run, ask nobody else and bank no further authority.
|
|
271
|
+
declined = { request: missing, outcome };
|
|
260
272
|
break;
|
|
261
273
|
}
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
274
|
+
for (const entry of requests) {
|
|
275
|
+
// Auto belongs to actual step admission, never to the upfront permission set.
|
|
276
|
+
if (outcome.sources[entry.capability] === "auto") continue;
|
|
277
|
+
preApproved.push({
|
|
278
|
+
capability: entry.capability,
|
|
279
|
+
subject: entry.subject,
|
|
280
|
+
scope: outcome.scopes[entry.capability] ?? ("once" as const),
|
|
281
|
+
bodySha256: snapshotOf(session, entry.subject)?.bodySha256,
|
|
282
|
+
});
|
|
283
|
+
rememberChainApproval(approvalAudit, entry.capability, entry.subject, outcome);
|
|
284
|
+
approvalStep.set(`${entry.capability}@${entry.subject}`, entry.stepIndex);
|
|
285
|
+
}
|
|
286
|
+
// Retain the group once, excluding provisional Auto facts that no step has admitted or consumed.
|
|
287
|
+
const retained = retainedChainApproval(outcome);
|
|
288
|
+
if (retained) approvedDecisions.push({ request, outcome: retained });
|
|
275
289
|
}
|
|
276
290
|
|
|
277
291
|
if (declined) {
|
package/extensions/grants.ts
CHANGED
|
@@ -42,6 +42,7 @@ import { ENV_WORKSPACE_REGISTRY } from "../src/kernel/workspace.ts";
|
|
|
42
42
|
import { appendRecord, buildRecord } from "../src/governance/ledger.ts";
|
|
43
43
|
import { openPaneCount, reapOpenPanesAsync } from "../src/executors/pane-reaper.ts";
|
|
44
44
|
import { ENV_GRANT, deriveOwnGrant, observeToolNames } from "../src/kernel/propagation.ts";
|
|
45
|
+
import { snapshotChildTools } from "../src/kernel/child-tools.ts";
|
|
45
46
|
import { snapshotOf } from "./approvals.ts";
|
|
46
47
|
import { registerDelegationTools } from "./delegation.ts";
|
|
47
48
|
import { grantsCommand } from "./grants-command.ts";
|
|
@@ -89,6 +90,7 @@ export default function (pi: ExtensionAPI, trustedSession?: GrantsSession) {
|
|
|
89
90
|
})();
|
|
90
91
|
const observerExtensionPath = fileURLToPath(new URL("./activity-timeline.ts", import.meta.url));
|
|
91
92
|
const session = trustedSession ?? createGrantsSession(extensionPath, undefined, observerExtensionPath);
|
|
93
|
+
session.childToolSources = () => snapshotChildTools(pi.getAllTools());
|
|
92
94
|
bindEcosystemVersions(pi, session, fileURLToPath(new URL("../", import.meta.url)));
|
|
93
95
|
session.currentThinking = typeof pi.getThinkingLevel === "function" ? () => pi.getThinkingLevel() : undefined;
|
|
94
96
|
registerActivityTimeline(pi, session);
|
package/extensions/session.ts
CHANGED
|
@@ -244,6 +244,8 @@ export interface GrantsSession extends NativeSessionHost {
|
|
|
244
244
|
ownGrant: Capability[];
|
|
245
245
|
observed: boolean;
|
|
246
246
|
observedTools: string[] | null;
|
|
247
|
+
/** Re-read public origins at admission; a parent's callable name does not prove child delivery. */
|
|
248
|
+
childToolSources?: () => readonly import("../src/kernel/child-tools.ts").ChildToolSource[];
|
|
247
249
|
/** ADR-0016: `SKILL.md` definitions, keyed by name. The format this package spawns from now. */
|
|
248
250
|
ensureDefinitions?: () => Promise<void>;
|
|
249
251
|
definitions: Map<string, SkillDefinition>;
|
|
@@ -687,6 +689,7 @@ export function createGrantsSession(
|
|
|
687
689
|
ledgerPath: session.ledgerPath,
|
|
688
690
|
extensionPath: session.extensionPath,
|
|
689
691
|
observerExtensionPath: session.observerExtensionPath,
|
|
692
|
+
childToolSources: session.childToolSources?.(),
|
|
690
693
|
childEnv: activityChildEnv(session.activity),
|
|
691
694
|
// ADR-0042: the pin this session holds, handed to the kernel so a delegated child inherits a narrowed
|
|
692
695
|
// one through the same builder `publishChildEnv` uses. Read here rather than in the kernel so there is
|
package/native/linux-x64/worker
CHANGED
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
9afee17eeac4a584ca023e5c2e65bcc4ed1e7ca3254e52da19b8fd9727359462
|
package/native/provenance.json
CHANGED
|
@@ -20,12 +20,12 @@
|
|
|
20
20
|
},
|
|
21
21
|
"source": {
|
|
22
22
|
"path": "native/worker.c",
|
|
23
|
-
"sha256": "
|
|
23
|
+
"sha256": "68070865b1e0cd0b081044fc4210319e84550e57442535ac82514823990314c4"
|
|
24
24
|
},
|
|
25
25
|
"artifact": {
|
|
26
26
|
"path": "native/linux-x64/worker",
|
|
27
|
-
"sha256": "
|
|
28
|
-
"bytes":
|
|
27
|
+
"sha256": "9afee17eeac4a584ca023e5c2e65bcc4ed1e7ca3254e52da19b8fd9727359462",
|
|
28
|
+
"bytes": 58040
|
|
29
29
|
},
|
|
30
30
|
"licenses": [
|
|
31
31
|
{
|
package/native/worker.c
CHANGED
|
@@ -101,6 +101,35 @@ static int validate_channel(int fd, int writing) {
|
|
|
101
101
|
if ((writing && (flags & O_ACCMODE) == O_RDONLY) || (!writing && (flags & O_ACCMODE) == O_WRONLY)) return -1;
|
|
102
102
|
return writing ? 0 : fcntl(fd, F_SETFL, flags | O_NONBLOCK);
|
|
103
103
|
}
|
|
104
|
+
/* Private inherited command channel: bounded NUL-separated argv, ending at EOF before any fork.
|
|
105
|
+
* Keeping command/task text out of this helper's argv prevents service-name cleanup matching it.
|
|
106
|
+
* This is accident prevention, not protection against hostile same-uid process inspection. */
|
|
107
|
+
static char **read_command(void) {
|
|
108
|
+
const size_t maximum = 2 * 1024 * 1024, maximum_args = 65536;
|
|
109
|
+
char *data = malloc(maximum + 1); if (!data) return NULL;
|
|
110
|
+
size_t used = 0, count = 0;
|
|
111
|
+
long long deadline = monotonic_ms() + 5000;
|
|
112
|
+
for (;;) {
|
|
113
|
+
if (requested_signal || monotonic_ms() >= deadline) { free(data); return NULL; }
|
|
114
|
+
ssize_t n = read(7, data + used, maximum + 1 - used);
|
|
115
|
+
if (n > 0) {
|
|
116
|
+
used += (size_t)n;
|
|
117
|
+
if (used > maximum) { free(data); return NULL; }
|
|
118
|
+
} else if (n == 0) break;
|
|
119
|
+
else if (errno != EAGAIN && errno != EWOULDBLOCK && errno != EINTR) { free(data); return NULL; }
|
|
120
|
+
struct pollfd pfd = { .fd=7, .events=POLLIN | POLLHUP };
|
|
121
|
+
int polled = poll(&pfd, 1, 10);
|
|
122
|
+
if ((polled < 0 && errno != EINTR) || (polled > 0 && (pfd.revents & POLLNVAL))) { free(data); return NULL; }
|
|
123
|
+
}
|
|
124
|
+
if (!used || !data[0] || data[used-1]) { free(data); return NULL; }
|
|
125
|
+
for (size_t i = 0; i < used; i++) if (!data[i]) count++;
|
|
126
|
+
if (count > maximum_args) { free(data); return NULL; }
|
|
127
|
+
char **args = calloc(count + 1, sizeof(*args));
|
|
128
|
+
if (!args) { free(data); return NULL; }
|
|
129
|
+
args[0] = data;
|
|
130
|
+
for (size_t i = 0, next = 1; i + 1 < used; i++) if (!data[i]) args[next++] = data + i + 1;
|
|
131
|
+
return args;
|
|
132
|
+
}
|
|
104
133
|
/* A direct child cannot reuse its PID before our waitpid. Forget its signal record only after reaping. */
|
|
105
134
|
struct signalled_child { pid_t pid; int signo; };
|
|
106
135
|
static struct signalled_child *signalled;
|
|
@@ -137,12 +166,12 @@ static int signal_children(int signo) {
|
|
|
137
166
|
fclose(children); return ok;
|
|
138
167
|
}
|
|
139
168
|
int main(int argc, char **argv) {
|
|
140
|
-
/* execution nonce canonical-root helper-sha ownership-dir grace-ms cleanup-ms
|
|
141
|
-
if (argc
|
|
169
|
+
/* execution nonce canonical-root helper-sha ownership-dir grace-ms cleanup-ms; command on fd 7 */
|
|
170
|
+
if (argc != 8) return 64;
|
|
142
171
|
struct identity id = { .execution=argv[1], .nonce=argv[2], .root=argv[3], .hash=argv[4], .directory=argv[5] };
|
|
143
172
|
long grace, ceiling;
|
|
144
173
|
if (milliseconds(argv[6], 60000, &grace) < 0 || milliseconds(argv[7], 120000, &ceiling) < 0 || ceiling < grace) return 64;
|
|
145
|
-
if (validate_channel(3, 0) < 0 || validate_channel(4, 1) < 0) return 65;
|
|
174
|
+
if (validate_channel(3, 0) < 0 || validate_channel(4, 1) < 0 || validate_channel(7, 0) < 0) return 65;
|
|
146
175
|
if (stat(id.root, &id.workspace) < 0 || !S_ISDIR(id.workspace.st_mode)) return 65;
|
|
147
176
|
if (read_text("/proc/sys/kernel/random/boot_id", id.boot, sizeof(id.boot)) < 0 || self_start(id.start, sizeof(id.start)) < 0) return 65;
|
|
148
177
|
ssize_t n = readlink("/proc/self/ns/pid", id.ns, sizeof(id.ns)-1); if (n < 0) return 65; id.ns[n] = 0;
|
|
@@ -152,6 +181,7 @@ int main(int argc, char **argv) {
|
|
|
152
181
|
int probe = (int)syscall(SYS_pidfd_open, getpid(), 0); if (probe < 0) return 65; close(probe);
|
|
153
182
|
if (signal_children(0) < 0) return 65; /* Probe /proc children support before admitting work. */
|
|
154
183
|
signal(SIGPIPE, SIG_IGN); signal(SIGTERM, on_signal); signal(SIGINT, on_signal); signal(SIGHUP, on_signal);
|
|
184
|
+
char **command = read_command(); close(7); if (!command) return 64;
|
|
155
185
|
int gate[2]; if (pipe2(gate, O_CLOEXEC) < 0) return 65;
|
|
156
186
|
id.worker = fork(); if (id.worker < 0) return 65;
|
|
157
187
|
if (id.worker == 0) {
|
|
@@ -159,8 +189,9 @@ int main(int argc, char **argv) {
|
|
|
159
189
|
signal(SIGTERM, SIG_DFL); signal(SIGINT, SIG_DFL); signal(SIGHUP, SIG_DFL); signal(SIGPIPE, SIG_DFL);
|
|
160
190
|
char release; if (read(gate[0], &release, 1) != 1 || release != 'S') _exit(125);
|
|
161
191
|
close(gate[0]); if (chdir(id.root) < 0) _exit(126);
|
|
162
|
-
execvp(
|
|
192
|
+
execvp(command[0], command); _exit(errno == ENOENT ? 127 : 126);
|
|
163
193
|
}
|
|
194
|
+
free(command[0]); free(command);
|
|
164
195
|
close(gate[0]);
|
|
165
196
|
int ready = durable(&id, 0, 0, "ready") == 0;
|
|
166
197
|
if (ready) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-daddy",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.57.0",
|
|
4
4
|
"description": "Capability governance for pi sub-agents: spawn Agent Skills (SKILL.md) definitions whose allowed-tools becomes a grant that can only narrow going down a delegation tree, enforced by pi's own --tools allowlist, with an append-only ledger.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"typecheck": "tsc -p tsconfig.check.json",
|
|
54
54
|
"test": "node scripts/unit-tests.ts",
|
|
55
55
|
"test:integration": "node --test test-integration/*.it.ts",
|
|
56
|
-
"test:integration:ci": "node --test test-integration/approval.it.ts test-integration/governance.it.ts test-integration/activity.it.ts test-integration/auto-chain.it.ts test-integration/pi-sdk/automatic-start.it.ts test-integration/pi-sdk/dashboard-prompts.it.ts",
|
|
56
|
+
"test:integration:ci": "node --test test-integration/approval.it.ts test-integration/governance.it.ts test-integration/activity.it.ts test-integration/auto-chain.it.ts test-integration/pi-sdk/automatic-start.it.ts test-integration/pi-sdk/dashboard-prompts.it.ts test-integration/pi-sdk/owned-pattern-cleanup.it.ts test-integration/pi-sdk/child-tool-delivery.it.ts",
|
|
57
57
|
"contracts:generate": "node scripts/generate-ledger-record-contract.ts",
|
|
58
58
|
"prepack": "npm run build",
|
|
59
59
|
"test:smoke": "node scripts/smoke-installed.mjs",
|
|
@@ -50,6 +50,12 @@ export async function runOwnedChild(request: OwnedChildRunRequest): Promise<Owne
|
|
|
50
50
|
return notStarted("captured worker requires qualified Linux x64 helper");
|
|
51
51
|
if (request.terminalUi && (!process.stdin.isTTY || !process.stdout.isTTY || !process.stderr.isTTY))
|
|
52
52
|
return notStarted("native Pi view requires a real pane terminal on stdin, stdout and stderr");
|
|
53
|
+
const commandArgs = [request.command, ...request.args];
|
|
54
|
+
if (!request.command || commandArgs.some((arg) => typeof arg !== "string" || arg.includes("\0")))
|
|
55
|
+
return notStarted("worker command must contain non-NUL strings and a nonempty executable");
|
|
56
|
+
const commandPayload = Buffer.from(commandArgs.join("\0") + "\0");
|
|
57
|
+
if (commandPayload.length > 2 * 1024 * 1024 || commandArgs.length > 65536)
|
|
58
|
+
return notStarted("worker command exceeds the private channel bound");
|
|
53
59
|
let helper: string, root: string, hash: string;
|
|
54
60
|
const nonce = randomUUID();
|
|
55
61
|
let binary: import("node:fs/promises").FileHandle | undefined;
|
|
@@ -84,24 +90,13 @@ export async function runOwnedChild(request: OwnedChildRunRequest): Promise<Owne
|
|
|
84
90
|
const cleanupCeiling = grace + 5000;
|
|
85
91
|
const child = spawn(
|
|
86
92
|
"/proc/self/fd/5",
|
|
87
|
-
[
|
|
88
|
-
request.executionId,
|
|
89
|
-
nonce,
|
|
90
|
-
root,
|
|
91
|
-
hash,
|
|
92
|
-
request.ownershipDir,
|
|
93
|
-
String(grace),
|
|
94
|
-
String(cleanupCeiling),
|
|
95
|
-
"--",
|
|
96
|
-
request.command,
|
|
97
|
-
...request.args,
|
|
98
|
-
],
|
|
93
|
+
[request.executionId, nonce, root, hash, request.ownershipDir, String(grace), String(cleanupCeiling)],
|
|
99
94
|
{
|
|
100
95
|
cwd: root,
|
|
101
96
|
env: request.env,
|
|
102
97
|
stdio: request.terminalUi
|
|
103
|
-
? ["inherit", "inherit", "inherit", "pipe", "pipe", binary!.fd, "pipe"]
|
|
104
|
-
: ["ignore", "pipe", "pipe", "pipe", "pipe", binary!.fd],
|
|
98
|
+
? ["inherit", "inherit", "inherit", "pipe", "pipe", binary!.fd, "pipe", "pipe"]
|
|
99
|
+
: ["ignore", "pipe", "pipe", "pipe", "pipe", binary!.fd, "ignore", "pipe"],
|
|
105
100
|
// The UI shares the pane's foreground process group for raw input and SIGWINCH.
|
|
106
101
|
// Cleanup still targets owned descendants by pidfd, never by process group.
|
|
107
102
|
detached: !request.terminalUi,
|
|
@@ -110,6 +105,13 @@ export async function runOwnedChild(request: OwnedChildRunRequest): Promise<Owne
|
|
|
110
105
|
void binary!.close();
|
|
111
106
|
const control = child.stdio[3] as import("node:stream").Duplex;
|
|
112
107
|
const status = child.stdio[4] as import("node:stream").Readable;
|
|
108
|
+
// A cleanup pattern in a delegated task must not also identify its native owner.
|
|
109
|
+
// This inherited pipe is closed before forking; argv remains metadata-only throughout startup.
|
|
110
|
+
const command = child.stdio.at(7) as import("node:stream").Writable;
|
|
111
|
+
command.on("error", () => {
|
|
112
|
+
/* Native readiness/receipt validation evaluates an early command-channel close. */
|
|
113
|
+
});
|
|
114
|
+
command.end(commandPayload);
|
|
113
115
|
const streams = {
|
|
114
116
|
stdout: request.terminalUi ? (child.stdio.at(6) as import("node:stream").Readable) : child.stdout,
|
|
115
117
|
stderr: child.stderr,
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** Generated by scripts/build-worker.ts; the loader never trusts a sidecar hash. */
|
|
2
|
-
export const WORKER_SHA256 = "
|
|
2
|
+
export const WORKER_SHA256 = "9afee17eeac4a584ca023e5c2e65bcc4ed1e7ca3254e52da19b8fd9727359462";
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
|
|
13
13
|
import { randomUUID } from "node:crypto";
|
|
14
14
|
import type { AutoModeReader } from "../kernel/auto-mode.ts";
|
|
15
|
-
import {
|
|
15
|
+
import { offeredScopes, type ApprovalPath, type ApprovalScope } from "../kernel/approval.ts";
|
|
16
16
|
import type { Capability } from "../kernel/resolve.ts";
|
|
17
17
|
import { selectPermission } from "./permission-question.ts";
|
|
18
18
|
|
|
@@ -36,6 +36,8 @@ export const SCOPE_LABELS: Record<ApprovalScope, string> = {
|
|
|
36
36
|
|
|
37
37
|
export interface PromptRequest {
|
|
38
38
|
capability: Capability;
|
|
39
|
+
/** Exact set covered by this one decision. Omitted for legacy single-capability callers. */
|
|
40
|
+
capabilities?: Capability[];
|
|
39
41
|
/** Agent type name, or `DELEGATE_SUBJECT` on the delegate path. */
|
|
40
42
|
subject: string;
|
|
41
43
|
path: ApprovalPath;
|
|
@@ -159,7 +161,7 @@ async function selectApproval(
|
|
|
159
161
|
untrack = options.autoMode?.trackPending({
|
|
160
162
|
id: randomUUID(),
|
|
161
163
|
subject: request.subject,
|
|
162
|
-
capability: request.capability,
|
|
164
|
+
capability: (request.capabilities ?? [request.capability]).join(", "),
|
|
163
165
|
});
|
|
164
166
|
const selection = selectPermission(options.ui, request, labels, controller.signal).then((chosen) => {
|
|
165
167
|
settled = true;
|
|
@@ -211,7 +213,7 @@ async function joinApproval(pending: Promise<PromptOutcome>, request: PromptRequ
|
|
|
211
213
|
}
|
|
212
214
|
|
|
213
215
|
/**
|
|
214
|
-
* The single-flight queue: one dialog per
|
|
216
|
+
* The single-flight queue: one dialog per exact capability set, subject and binding at a time.
|
|
215
217
|
*
|
|
216
218
|
* `delegate` sets no `executionMode`, so an orchestrator can fan out several children at once and two can
|
|
217
219
|
* hit the same gate simultaneously — otherwise two stacked dialogs asking the identical question.
|
|
@@ -302,6 +304,10 @@ export function createApprovalGate(
|
|
|
302
304
|
|
|
303
305
|
return {
|
|
304
306
|
async request(request: PromptRequest): Promise<PromptOutcome> {
|
|
307
|
+
const capabilities = [...new Set(request.capabilities ?? [request.capability])].sort();
|
|
308
|
+
if (!capabilities.length || !capabilities.includes(request.capability))
|
|
309
|
+
return { scope: null, kind: "error", reason: "Invalid permission set; no permission was granted." };
|
|
310
|
+
request = { ...request, capabilities };
|
|
305
311
|
if (request.signal?.aborted) return interrupted(request, "aborted");
|
|
306
312
|
try {
|
|
307
313
|
if (options.autoMode && (await options.autoMode.read()).enabled) {
|
|
@@ -322,7 +328,7 @@ export function createApprovalGate(
|
|
|
322
328
|
};
|
|
323
329
|
}
|
|
324
330
|
|
|
325
|
-
const key =
|
|
331
|
+
const key = JSON.stringify([request.path, request.subject, capabilities, request.bindingKey ?? null]);
|
|
326
332
|
|
|
327
333
|
// R-29. Join an in-flight dialog, but only *keep* its answer if that answer was about more than one
|
|
328
334
|
// spawn. A `once` belongs to whichever caller the human was actually looking at — the title shows
|
|
@@ -24,16 +24,22 @@ function oneLine(value: string, limit: number): string {
|
|
|
24
24
|
.trimEnd() + "…";
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
function
|
|
27
|
+
function permissionAction(capability: string): string {
|
|
28
28
|
const actions: Record<string, string> = {
|
|
29
29
|
"tool:bash": "run shell commands",
|
|
30
30
|
"tool:write": "write files",
|
|
31
31
|
"tool:edit": "edit files",
|
|
32
32
|
"tool:delegate": "delegate work to another agent",
|
|
33
33
|
};
|
|
34
|
+
return actions[capability] ?? `use ${oneLine(clean(capability), 90)}`;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function headline(request: PromptRequest): string {
|
|
38
|
+
const capabilities = request.capabilities ?? [request.capability];
|
|
34
39
|
const subject = request.path === "delegate" ? "this delegated agent" : oneLine(clean(request.subject), 80);
|
|
35
|
-
|
|
36
|
-
|
|
40
|
+
return capabilities.length === 1
|
|
41
|
+
? `Allow ${subject} to ${permissionAction(capabilities[0]!)}?`
|
|
42
|
+
: `Allow ${subject} these ${capabilities.length} permissions?`;
|
|
37
43
|
}
|
|
38
44
|
|
|
39
45
|
function scopeHint(request: PromptRequest): string {
|
|
@@ -46,7 +52,7 @@ function scopeHint(request: PromptRequest): string {
|
|
|
46
52
|
/** Render the full, untrusted brief in pages so choices stay reachable on a typical terminal. */
|
|
47
53
|
function detailLines(request: PromptRequest): string[] {
|
|
48
54
|
const rows = [
|
|
49
|
-
`Permission: ${clean(
|
|
55
|
+
...(request.capabilities ?? [request.capability]).map((capability) => `Permission: ${clean(capability)}`),
|
|
50
56
|
`Agent: ${clean(request.subject)}`,
|
|
51
57
|
...(request.project ? [`Permission project: ${clean(request.project)}`] : []),
|
|
52
58
|
...(request.workspace ? [`Requested workspace: ${clean(request.workspace)}`] : []),
|
|
@@ -77,11 +83,16 @@ export async function selectPermission(
|
|
|
77
83
|
.find((line) => line.trim());
|
|
78
84
|
const title = [
|
|
79
85
|
headline(request),
|
|
86
|
+
...((request.capabilities?.length ?? 1) > 1
|
|
87
|
+
? request.capabilities!.map((capability) => ` • ${permissionAction(capability)}`)
|
|
88
|
+
: []),
|
|
80
89
|
...(task ? [`Requested task: ${oneLine(task, 115)}`] : []),
|
|
81
90
|
...(request.project
|
|
82
91
|
? [`Permission project: ${oneLine(clean(basename(request.project) || request.project), 60)}`]
|
|
83
92
|
: []),
|
|
84
|
-
...(request.
|
|
93
|
+
...((request.capabilities ?? [request.capability]).includes("tool:bash")
|
|
94
|
+
? ["Shell access can change files and run other commands."]
|
|
95
|
+
: []),
|
|
85
96
|
...(request.recheckReason ? [request.recheckReason] : []),
|
|
86
97
|
scopeHint(request),
|
|
87
98
|
].join("\n");
|