pi-daddy 0.57.0 → 0.59.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 +13 -0
- 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 +48 -44
- package/dist/governance/operation-artifacts.js.map +1 -1
- package/dist/governance/operation-recovery.d.ts +18 -0
- package/dist/governance/operation-recovery.d.ts.map +1 -0
- package/dist/governance/operation-recovery.js +47 -0
- package/dist/governance/operation-recovery.js.map +1 -0
- package/dist/kernel/dashboard-observation.d.ts +40 -0
- package/dist/kernel/dashboard-observation.d.ts.map +1 -1
- package/dist/kernel/dashboard-observation.js +42 -3
- package/dist/kernel/dashboard-observation.js.map +1 -1
- package/dist/products/dashboard-activity.d.ts +2 -0
- package/dist/products/dashboard-activity.d.ts.map +1 -1
- package/dist/products/dashboard-activity.js +7 -1
- package/dist/products/dashboard-activity.js.map +1 -1
- package/dist/products/dashboard-cli.d.ts.map +1 -1
- package/dist/products/dashboard-cli.js +1 -1
- package/dist/products/dashboard-cli.js.map +1 -1
- package/dist/products/dashboard-components.d.ts.map +1 -1
- package/dist/products/dashboard-components.js +57 -8
- package/dist/products/dashboard-components.js.map +1 -1
- package/dist/products/dashboard-inventory-view.d.ts +9 -0
- package/dist/products/dashboard-inventory-view.d.ts.map +1 -0
- package/dist/products/dashboard-inventory-view.js +44 -0
- package/dist/products/dashboard-inventory-view.js.map +1 -0
- package/dist/products/dashboard-layout.js +4 -3
- package/dist/products/dashboard-layout.js.map +1 -1
- package/dist/products/dashboard-panels.d.ts.map +1 -1
- package/dist/products/dashboard-panels.js +14 -5
- package/dist/products/dashboard-panels.js.map +1 -1
- package/dist/products/dashboard-screen.d.ts +2 -0
- package/dist/products/dashboard-screen.d.ts.map +1 -1
- package/dist/products/dashboard-screen.js +14 -7
- package/dist/products/dashboard-screen.js.map +1 -1
- package/dist/products/dashboard-session-client.d.ts +4 -2
- package/dist/products/dashboard-session-client.d.ts.map +1 -1
- package/dist/products/dashboard-session-client.js +24 -7
- package/dist/products/dashboard-session-client.js.map +1 -1
- package/extensions/dashboard-live.ts +1 -1
- package/extensions/dashboard-session-server.ts +4 -0
- package/extensions/dashboard-source-refresh.ts +95 -0
- package/extensions/dashboard-sources.ts +42 -4
- package/extensions/definition-describe.ts +50 -4
- package/extensions/delegate-chain.ts +8 -6
- package/extensions/delegation.ts +14 -8
- package/extensions/operation-recovery-bridge.ts +100 -0
- package/extensions/runtime-snapshot.ts +10 -0
- package/extensions/session.ts +1 -0
- package/package.json +1 -1
- package/src/governance/operation-artifacts.ts +51 -41
- package/src/governance/operation-recovery.ts +68 -0
- package/src/kernel/dashboard-observation.ts +86 -4
- package/src/products/dashboard-activity.ts +8 -1
- package/src/products/dashboard-cli.ts +1 -0
- package/src/products/dashboard-components.ts +57 -9
- package/src/products/dashboard-inventory-view.ts +44 -0
- package/src/products/dashboard-layout.ts +6 -4
- package/src/products/dashboard-panels.ts +16 -5
- package/src/products/dashboard-screen.ts +16 -7
- package/src/products/dashboard-session-client.ts +31 -11
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/** Optional trusted producers publish display observations; no automatic work, tools, or persistent store. */
|
|
2
2
|
import { registerDashboardChoiceOwner } from "./dashboard-choice-controls.ts";
|
|
3
|
+
import { dashboardSourceRefresh } from "./dashboard-source-refresh.ts";
|
|
3
4
|
import { randomUUID } from "node:crypto";
|
|
4
5
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
5
6
|
import {
|
|
@@ -8,6 +9,7 @@ import {
|
|
|
8
9
|
isBookieChoice,
|
|
9
10
|
validDashboardSourceUpdate,
|
|
10
11
|
type DashboardSourceSnapshot,
|
|
12
|
+
type DashboardSourceRefreshCallback,
|
|
11
13
|
type DashboardSourceUpdate,
|
|
12
14
|
} from "../src/kernel/dashboard-observation.ts";
|
|
13
15
|
export interface DashboardSourceOwner {
|
|
@@ -20,6 +22,7 @@ export function registerDashboardSources(
|
|
|
20
22
|
now: () => number = Date.now,
|
|
21
23
|
) {
|
|
22
24
|
const sources = new Map<string, DashboardSourceSnapshot>();
|
|
25
|
+
const refreshers = new Map<string, ReturnType<typeof dashboardSourceRefresh>>();
|
|
23
26
|
let closed = false;
|
|
24
27
|
let owner = current(),
|
|
25
28
|
generation = randomUUID(),
|
|
@@ -29,6 +32,8 @@ export function registerDashboardSources(
|
|
|
29
32
|
const selected = current();
|
|
30
33
|
if (selected !== owner) {
|
|
31
34
|
owner = selected;
|
|
35
|
+
for (const refresh of refreshers.values()) refresh.close();
|
|
36
|
+
refreshers.clear();
|
|
32
37
|
sources.clear();
|
|
33
38
|
generation = randomUUID();
|
|
34
39
|
sequence = 0;
|
|
@@ -51,6 +56,7 @@ export function registerDashboardSources(
|
|
|
51
56
|
cwd?: unknown;
|
|
52
57
|
producer?: unknown;
|
|
53
58
|
producerVersion?: unknown;
|
|
59
|
+
refresh?: unknown;
|
|
54
60
|
reply?: (value: unknown) => void;
|
|
55
61
|
};
|
|
56
62
|
if (r?.version !== 1 || typeof r.reply !== "function") return;
|
|
@@ -71,6 +77,7 @@ export function registerDashboardSources(
|
|
|
71
77
|
typeof r.producerVersion !== "string" ||
|
|
72
78
|
!r.producerVersion ||
|
|
73
79
|
r.producerVersion.length > 80 ||
|
|
80
|
+
(r.refresh !== undefined && typeof r.refresh !== "function") ||
|
|
74
81
|
(!sources.has(r.producer) && sources.size >= DASHBOARD_SOURCE_LIMIT)
|
|
75
82
|
) {
|
|
76
83
|
reply({ version: 1, ok: false, reason: "dashboard source registration unavailable" });
|
|
@@ -89,21 +96,44 @@ export function registerDashboardSources(
|
|
|
89
96
|
items: [],
|
|
90
97
|
};
|
|
91
98
|
sources.set(producer, snapshot);
|
|
99
|
+
refreshers.get(producer)?.close();
|
|
100
|
+
refreshers.delete(producer);
|
|
92
101
|
const active = () =>
|
|
93
102
|
reconcile() === selected && sources.get(producer) === snapshot && snapshot.availability !== "closed";
|
|
103
|
+
const publish = (value: DashboardSourceUpdate) => {
|
|
104
|
+
if (!active() || !validDashboardSourceUpdate(value) || value.sequence <= snapshot.sequence) return false;
|
|
105
|
+
snapshot.sequence = value.sequence;
|
|
106
|
+
snapshot.items = structuredClone(value.items);
|
|
107
|
+
if (value.inventory) snapshot.inventory = structuredClone(value.inventory);
|
|
108
|
+
else delete snapshot.inventory;
|
|
109
|
+
snapshot.observedAt = new Date(now()).toISOString();
|
|
110
|
+
return true;
|
|
111
|
+
};
|
|
112
|
+
if (r.refresh)
|
|
113
|
+
refreshers.set(
|
|
114
|
+
producer,
|
|
115
|
+
dashboardSourceRefresh(snapshot, r.refresh as DashboardSourceRefreshCallback, active, publish, now),
|
|
116
|
+
);
|
|
94
117
|
reply({
|
|
95
118
|
version: 1,
|
|
96
119
|
ok: true,
|
|
97
120
|
generation: token,
|
|
121
|
+
capabilities: { inventory: 1, refresh: 1 },
|
|
98
122
|
publish(value: DashboardSourceUpdate) {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
123
|
+
const previousInventory = snapshot.inventory;
|
|
124
|
+
if (!publish(value)) return false;
|
|
125
|
+
refreshers
|
|
126
|
+
.get(producer)
|
|
127
|
+
?.observed(
|
|
128
|
+
value.inventory !== undefined && JSON.stringify(previousInventory) !== JSON.stringify(value.inventory),
|
|
129
|
+
);
|
|
103
130
|
return true;
|
|
104
131
|
},
|
|
105
132
|
close() {
|
|
106
133
|
if (active()) {
|
|
134
|
+
refreshers.get(producer)?.close();
|
|
135
|
+
refreshers.delete(producer);
|
|
136
|
+
delete snapshot.inventory;
|
|
107
137
|
snapshot.items = snapshot.items.filter((item) => !isBookieChoice(producer, item));
|
|
108
138
|
snapshot.availability = "closed";
|
|
109
139
|
snapshot.observedAt = new Date(now()).toISOString();
|
|
@@ -113,6 +143,12 @@ export function registerDashboardSources(
|
|
|
113
143
|
});
|
|
114
144
|
return {
|
|
115
145
|
choices,
|
|
146
|
+
requestRefresh() {
|
|
147
|
+
if (!reconcile()) return false;
|
|
148
|
+
let requested = false;
|
|
149
|
+
for (const refresh of refreshers.values()) requested = refresh.request() || requested;
|
|
150
|
+
return requested;
|
|
151
|
+
},
|
|
116
152
|
snapshot() {
|
|
117
153
|
const selected = reconcile();
|
|
118
154
|
return selected
|
|
@@ -128,6 +164,8 @@ export function registerDashboardSources(
|
|
|
128
164
|
},
|
|
129
165
|
close() {
|
|
130
166
|
closed = true;
|
|
167
|
+
for (const refresh of refreshers.values()) refresh.close();
|
|
168
|
+
refreshers.clear();
|
|
131
169
|
choices.close();
|
|
132
170
|
off?.();
|
|
133
171
|
sources.clear();
|
|
@@ -6,22 +6,67 @@ import { digestDefinition } from "../src/kernel/definitions.ts";
|
|
|
6
6
|
import { maySpawnDefinition } from "../src/kernel/delegate.ts";
|
|
7
7
|
import type { GrantsSession } from "./session.ts";
|
|
8
8
|
import { assertDelegationAuthority } from "./delegation-authority.ts";
|
|
9
|
+
|
|
10
|
+
export const definitionIdDescription =
|
|
11
|
+
"Exact definitionId from delegate_describe.delegationArguments. Copy its agent together with this ID; " +
|
|
12
|
+
"the ID alone does not select an agent. Required for Principal phases.";
|
|
13
|
+
|
|
14
|
+
class DefinitionInputError extends Error {}
|
|
15
|
+
|
|
9
16
|
export function assertDefinitionIdentity(
|
|
10
17
|
session: GrantsSession,
|
|
11
18
|
spec: { agent?: string; definitionId?: string },
|
|
12
19
|
): void {
|
|
13
20
|
const definition = spec.agent ? session.definitions.get(spec.agent) : undefined;
|
|
14
|
-
if (spec.definitionId !== undefined
|
|
15
|
-
|
|
21
|
+
if (spec.definitionId !== undefined) {
|
|
22
|
+
if (!spec.agent)
|
|
23
|
+
throw new DefinitionInputError(
|
|
24
|
+
"Missing delegation agent: definitionId does not select an agent. Copy BOTH agent and definitionId " +
|
|
25
|
+
"from delegate_describe.delegationArguments, then add the task. No definition was selected.",
|
|
26
|
+
);
|
|
27
|
+
if (!definition)
|
|
28
|
+
throw new DefinitionInputError(
|
|
29
|
+
`Delegation agent ${JSON.stringify(spec.agent)} is not in the current selected definitions. ` +
|
|
30
|
+
"Use the exact agent name returned by delegate_describe; refreshing an ID cannot correct a wrong agent name.",
|
|
31
|
+
);
|
|
32
|
+
if (definition.definitionId !== spec.definitionId)
|
|
33
|
+
throw new DefinitionInputError(
|
|
34
|
+
`Definition snapshot changed or is unavailable for agent ${JSON.stringify(spec.agent)}: ` +
|
|
35
|
+
"the supplied definitionId does not match its current selection. " +
|
|
36
|
+
"Call delegate_describe for that agent and copy BOTH fields from delegationArguments; do not shorten or invent the ID.",
|
|
37
|
+
);
|
|
38
|
+
}
|
|
16
39
|
if (definition?.binding && !spec.definitionId)
|
|
17
|
-
throw
|
|
40
|
+
throw new DefinitionInputError(
|
|
41
|
+
`Principal delegation for agent ${JSON.stringify(spec.agent)} is missing definitionId. ` +
|
|
42
|
+
"Call delegate_describe for that agent and copy BOTH fields from delegationArguments.",
|
|
43
|
+
);
|
|
18
44
|
}
|
|
45
|
+
|
|
46
|
+
/** Call only before any operation admission; downstream identity rechecks cannot assert this boundary. */
|
|
47
|
+
export function assertDefinitionInputsBeforeAdmission(
|
|
48
|
+
session: GrantsSession,
|
|
49
|
+
specs: readonly { agent?: string; definitionId?: string }[],
|
|
50
|
+
): void {
|
|
51
|
+
try {
|
|
52
|
+
for (const spec of specs) assertDefinitionIdentity(session, spec);
|
|
53
|
+
} catch (error) {
|
|
54
|
+
if (!(error instanceof DefinitionInputError)) throw error;
|
|
55
|
+
error.message +=
|
|
56
|
+
" This call stopped before operation admission; it started no child. " +
|
|
57
|
+
"This does not establish whether an earlier call used the same operation ID.";
|
|
58
|
+
throw error;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
19
62
|
export function registerDefinitionDescribe(pi: ExtensionAPI, session: GrantsSession): void {
|
|
20
63
|
pi.registerTool({
|
|
21
64
|
name: "delegate_describe",
|
|
22
65
|
label: "Describe a governed definition",
|
|
23
66
|
description:
|
|
24
|
-
"Read the exact selected definition identity and Principal binding before delegation.
|
|
67
|
+
"Read the exact selected definition identity and Principal binding before delegation. " +
|
|
68
|
+
"Copy delegationArguments (agent and definitionId) into delegate or a batch/chain entry, then add its task. " +
|
|
69
|
+
"Starts no child and grants nothing.",
|
|
25
70
|
parameters: Type.Object({ agent: Type.String() }),
|
|
26
71
|
async execute(_id, params) {
|
|
27
72
|
assertDelegationAuthority(session);
|
|
@@ -38,6 +83,7 @@ export function registerDefinitionDescribe(pi: ExtensionAPI, session: GrantsSess
|
|
|
38
83
|
bodySha256: digestDefinition(definition).sha256,
|
|
39
84
|
binding: definition.binding ?? null,
|
|
40
85
|
definitionId: definition.definitionId,
|
|
86
|
+
delegationArguments: { agent: params.agent, definitionId: definition.definitionId },
|
|
41
87
|
selectedResources: definition.selectedResources ?? null,
|
|
42
88
|
};
|
|
43
89
|
const capture = publicEvidenceCall(session.publicEvidence, _id, "delegate_describe", [{ agent: params.agent }]);
|
|
@@ -2,7 +2,7 @@ import { dashboardSummaryDescription } from "../src/products/activity-summary.ts
|
|
|
2
2
|
import { operationIdShape, claimDelegationOperation, existingOperationOutcome } from "./delegation-operations.ts";
|
|
3
3
|
import { publicEvidenceCall } from "./public-evidence.ts";
|
|
4
4
|
import { executionEvidenceContent } from "./execution-evidence.ts";
|
|
5
|
-
import {
|
|
5
|
+
import { assertDefinitionInputsBeforeAdmission, definitionIdDescription } from "./definition-describe.ts";
|
|
6
6
|
/**
|
|
7
7
|
* `delegate_chain` — a governed sequential pipeline, planned and gated as one unit (ADR-0033).
|
|
8
8
|
*
|
|
@@ -84,16 +84,18 @@ function mergeGateOutcomes(outcomes: readonly ApprovalOutcome[]): ApprovalOutcom
|
|
|
84
84
|
export function registerChainTool(pi: ExtensionAPI, session: GrantsSession): void {
|
|
85
85
|
const stepShape = Type.Object({
|
|
86
86
|
operation_id: operationIdShape(),
|
|
87
|
-
definitionId: Type.Optional(
|
|
88
|
-
Type.String({ description: "Snapshot id returned by delegate_describe; required for Principal phases." }),
|
|
89
|
-
),
|
|
87
|
+
definitionId: Type.Optional(Type.String({ description: definitionIdDescription })),
|
|
90
88
|
dashboardSummary: Type.Optional(Type.String({ maxLength: 160, description: dashboardSummaryDescription })),
|
|
91
89
|
task: Type.String({
|
|
92
90
|
description:
|
|
93
91
|
`What this step should do. Write ${PLACEHOLDER} where the previous step's output belongs; if you omit it, ` +
|
|
94
92
|
`that output is appended instead. The first step never receives one.`,
|
|
95
93
|
}),
|
|
96
|
-
agent: Type.Optional(
|
|
94
|
+
agent: Type.Optional(
|
|
95
|
+
Type.String({
|
|
96
|
+
description: "Definition for this step; copy with definitionId from delegate_describe.delegationArguments.",
|
|
97
|
+
}),
|
|
98
|
+
),
|
|
97
99
|
tools: Type.Optional(Type.Array(Type.String(), { description: "Capabilities, when no 'agent' fits." })),
|
|
98
100
|
model: Type.Optional(Type.String({ description: "Model as provider/id. Defaults to this session's." })),
|
|
99
101
|
thinking: Type.Optional(
|
|
@@ -136,7 +138,7 @@ export function registerChainTool(pi: ExtensionAPI, session: GrantsSession): voi
|
|
|
136
138
|
assertDelegationAuthority(session);
|
|
137
139
|
const steps = args.steps ?? [];
|
|
138
140
|
await session.ensureDefinitions?.();
|
|
139
|
-
|
|
141
|
+
assertDefinitionInputsBeforeAdmission(session, steps);
|
|
140
142
|
|
|
141
143
|
// **Every cheap refusal happens before any human is asked.** Yesterday's lesson on the `delegate` path: with
|
|
142
144
|
// `PI_DADDY_HERDR=1` and herdr down, the gate ran first, an operator approved `bash`, a 30-day entry was
|
package/extensions/delegation.ts
CHANGED
|
@@ -3,7 +3,11 @@ import { operationIdShape, claimDelegationOperation } from "./delegation-operati
|
|
|
3
3
|
import { publicEvidenceCall } from "./public-evidence.ts";
|
|
4
4
|
import { executionEvidenceContent } from "./execution-evidence.ts";
|
|
5
5
|
import { reconcileDelegationCapacity, reserveDelegationCapacity } from "./session-capacity.ts";
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
assertDefinitionInputsBeforeAdmission,
|
|
8
|
+
definitionIdDescription,
|
|
9
|
+
registerDefinitionDescribe,
|
|
10
|
+
} from "./definition-describe.ts";
|
|
7
11
|
/**
|
|
8
12
|
* Governed delegation, as pi sees it: the `delegate` and `delegate_all` tool registrations.
|
|
9
13
|
*
|
|
@@ -171,7 +175,8 @@ export function registerDelegationTools(pi: ExtensionAPI, session: GrantsSession
|
|
|
171
175
|
*/
|
|
172
176
|
const describeAgent = (names: string[]) =>
|
|
173
177
|
`Name of a definition to spawn — its allowed-tools become the grant and its instructions ` +
|
|
174
|
-
`become the sub-agent's system prompt.
|
|
178
|
+
`become the sub-agent's system prompt. Copy this together with definitionId from delegate_describe.delegationArguments. ` +
|
|
179
|
+
`Available: ${names.join(", ") || "none"}.`;
|
|
175
180
|
|
|
176
181
|
const correlationShape = buildCorrelationShape();
|
|
177
182
|
const workspaceShape = Type.Object({
|
|
@@ -193,9 +198,7 @@ export function registerDelegationTools(pi: ExtensionAPI, session: GrantsSession
|
|
|
193
198
|
);
|
|
194
199
|
const childShape = Type.Object({
|
|
195
200
|
operation_id: operationIdShape(),
|
|
196
|
-
definitionId: Type.Optional(
|
|
197
|
-
Type.String({ description: "Snapshot id returned by delegate_describe; required for Principal phases." }),
|
|
198
|
-
),
|
|
201
|
+
definitionId: Type.Optional(Type.String({ description: definitionIdDescription })),
|
|
199
202
|
dashboardSummary: Type.Optional(Type.String({ maxLength: 160, description: dashboardSummaryDescription })),
|
|
200
203
|
task: Type.String({ description: "The task for this sub-agent. It receives only this." }),
|
|
201
204
|
agent: Type.Optional(Type.String({ description: describeAgent(spawnable()) })),
|
|
@@ -217,9 +220,7 @@ export function registerDelegationTools(pi: ExtensionAPI, session: GrantsSession
|
|
|
217
220
|
|
|
218
221
|
const delegateParams = Type.Object({
|
|
219
222
|
operation_id: operationIdShape(),
|
|
220
|
-
definitionId: Type.Optional(
|
|
221
|
-
Type.String({ description: "Snapshot id returned by delegate_describe; required for Principal phases." }),
|
|
222
|
-
),
|
|
223
|
+
definitionId: Type.Optional(Type.String({ description: definitionIdDescription })),
|
|
223
224
|
dashboardSummary: Type.Optional(Type.String({ maxLength: 160, description: dashboardSummaryDescription })),
|
|
224
225
|
task: Type.String({ description: "The task for the sub-agent. It receives only this." }),
|
|
225
226
|
agent: Type.Optional(Type.String({ description: describeAgent(spawnable()) })),
|
|
@@ -257,6 +258,8 @@ export function registerDelegationTools(pi: ExtensionAPI, session: GrantsSession
|
|
|
257
258
|
prepareArguments: withoutRetiredDelegationArguments,
|
|
258
259
|
async execute(_toolCallId, params, signal, onUpdate, ctx) {
|
|
259
260
|
assertDelegationAuthority(session);
|
|
261
|
+
await session.ensureDefinitions?.();
|
|
262
|
+
assertDefinitionInputsBeforeAdmission(session, [params]);
|
|
260
263
|
// ADR-0032: one child, same block. `_onUpdate` was discarded here, so a delegation showed the bare word
|
|
261
264
|
// `delegate` for up to DEFAULT_TIMEOUT_MS — sixty minutes by default.
|
|
262
265
|
const progress = progressReporter(session, [params.agent ?? "delegate"], onUpdate as never);
|
|
@@ -356,6 +359,9 @@ export function registerDelegationTools(pi: ExtensionAPI, session: GrantsSession
|
|
|
356
359
|
async execute(_toolCallId, params, signal, onUpdate, ctx) {
|
|
357
360
|
assertDelegationAuthority(session);
|
|
358
361
|
const children = params.children ?? [];
|
|
362
|
+
// Correctable definition inputs must not consume earlier siblings' operation IDs.
|
|
363
|
+
await session.ensureDefinitions?.();
|
|
364
|
+
assertDefinitionInputsBeforeAdmission(session, children);
|
|
359
365
|
if (session.capacityRefusal) throw new GovernanceRefusal(session.capacityRefusal);
|
|
360
366
|
await reconcileDelegationCapacity(session);
|
|
361
367
|
const occurrences = children.map((_, index) => newDelegationOccurrence(session, index));
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/** Trusted exact historical observation; the current requester never adopts the original operation owner. */
|
|
2
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
3
|
+
import { readOperationHistory } from "../src/governance/operation-artifacts.ts";
|
|
4
|
+
import { validOperationId } from "../src/kernel/dispatch-operation.ts";
|
|
5
|
+
import { readOperationRecovery, type OperationRecoverySource } from "../src/governance/operation-recovery.ts";
|
|
6
|
+
import type { ArtifactBridgeOwner } from "./artifact-bridge.ts";
|
|
7
|
+
|
|
8
|
+
export const OPERATION_RECOVERY_EVENT = "pi-daddy:operation-recovery:v1";
|
|
9
|
+
export function registerOperationRecoveryBridge(pi: ExtensionAPI, current: () => ArtifactBridgeOwner | undefined) {
|
|
10
|
+
let closed = false;
|
|
11
|
+
const unsubscribe = pi.events?.on?.(OPERATION_RECOVERY_EVENT, (input: unknown) => {
|
|
12
|
+
const r = input as {
|
|
13
|
+
version?: number;
|
|
14
|
+
requestId?: string;
|
|
15
|
+
sessionId?: string;
|
|
16
|
+
cwd?: string;
|
|
17
|
+
source?: OperationRecoverySource;
|
|
18
|
+
authorize?: () => Promise<void | boolean>;
|
|
19
|
+
reply?: (value: unknown) => void;
|
|
20
|
+
};
|
|
21
|
+
if (
|
|
22
|
+
r?.version !== 1 ||
|
|
23
|
+
typeof r.requestId !== "string" ||
|
|
24
|
+
r.requestId.length > 512 ||
|
|
25
|
+
typeof r.reply !== "function"
|
|
26
|
+
)
|
|
27
|
+
return;
|
|
28
|
+
const reply = r.reply;
|
|
29
|
+
const envelope = { version: 1, requestId: r.requestId, sessionId: r.sessionId, cwd: r.cwd };
|
|
30
|
+
void (async () => {
|
|
31
|
+
const selected = current();
|
|
32
|
+
let code: "owner-unavailable" | "invalid-source" | "authority" | "source-changed" = "owner-unavailable";
|
|
33
|
+
let source: OperationRecoverySource | undefined;
|
|
34
|
+
const check = () => {
|
|
35
|
+
code = "owner-unavailable";
|
|
36
|
+
if (
|
|
37
|
+
closed ||
|
|
38
|
+
!selected ||
|
|
39
|
+
current() !== selected ||
|
|
40
|
+
r.sessionId !== selected.owner.sessionId ||
|
|
41
|
+
r.cwd !== selected.owner.cwd
|
|
42
|
+
)
|
|
43
|
+
throw Error("current owner unavailable");
|
|
44
|
+
};
|
|
45
|
+
try {
|
|
46
|
+
check();
|
|
47
|
+
code = "invalid-source";
|
|
48
|
+
if (
|
|
49
|
+
!r.source ||
|
|
50
|
+
!validOperationId(r.source.operationId) ||
|
|
51
|
+
typeof r.source.owner?.sessionId !== "string" ||
|
|
52
|
+
!r.source.owner.sessionId ||
|
|
53
|
+
r.source.owner.sessionId.length > 512 ||
|
|
54
|
+
r.source.owner.cwd !== selected!.owner.cwd
|
|
55
|
+
)
|
|
56
|
+
throw Error("exact original owner in the selected workspace required");
|
|
57
|
+
source = {
|
|
58
|
+
owner: { sessionId: r.source.owner.sessionId, cwd: r.source.owner.cwd },
|
|
59
|
+
operationId: r.source.operationId,
|
|
60
|
+
};
|
|
61
|
+
const authorize = r.authorize;
|
|
62
|
+
const assertAuthority = async () => {
|
|
63
|
+
code = "authority";
|
|
64
|
+
if (typeof authorize !== "function" || (await authorize()) === false)
|
|
65
|
+
throw Error("trusted current authority absent or changed");
|
|
66
|
+
check();
|
|
67
|
+
};
|
|
68
|
+
await assertAuthority();
|
|
69
|
+
code = "source-changed";
|
|
70
|
+
const before = JSON.stringify(readOperationHistory(selected!.agentDirectory, source.owner, source.operationId));
|
|
71
|
+
const observation = await readOperationRecovery(selected!.agentDirectory, source);
|
|
72
|
+
if (observation.operation && observation.operation.cwd !== selected!.owner.cwd) {
|
|
73
|
+
code = "invalid-source";
|
|
74
|
+
throw Error("historical execution is outside the selected workspace");
|
|
75
|
+
}
|
|
76
|
+
await assertAuthority();
|
|
77
|
+
code = "source-changed";
|
|
78
|
+
if (JSON.stringify(readOperationHistory(selected!.agentDirectory, source.owner, source.operationId)) !== before)
|
|
79
|
+
throw Error("historical source changed before disclosure");
|
|
80
|
+
check();
|
|
81
|
+
reply({ ...envelope, source, qualified: true, observation });
|
|
82
|
+
} catch {
|
|
83
|
+
reply({
|
|
84
|
+
...envelope,
|
|
85
|
+
...(source ? { source } : {}),
|
|
86
|
+
qualified: false,
|
|
87
|
+
code,
|
|
88
|
+
reason:
|
|
89
|
+
"Historical operation evidence is unavailable or current access changed; this inspection started no work.",
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
})().catch(() => undefined);
|
|
93
|
+
});
|
|
94
|
+
return {
|
|
95
|
+
close() {
|
|
96
|
+
closed = true;
|
|
97
|
+
unsubscribe?.();
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { registerOperationRecoveryBridge } from "./operation-recovery-bridge.ts";
|
|
1
2
|
import { registerDashboardPrompts } from "./dashboard-ui-prompts.ts";
|
|
2
3
|
import { registerInitiativeRuntime } from "./initiative-runtime.ts";
|
|
3
4
|
import { registerDashboardLive } from "./dashboard-live.ts";
|
|
@@ -36,6 +37,7 @@ export function registerRuntimeSnapshot(
|
|
|
36
37
|
: undefined,
|
|
37
38
|
);
|
|
38
39
|
session.dashboardObservations = () => dashboardSources.snapshot();
|
|
40
|
+
session.dashboardRefreshSources = () => dashboardSources.requestRefresh();
|
|
39
41
|
session.dashboardChoices = dashboardSources.choices;
|
|
40
42
|
session.dashboardLive = registerDashboardLive(pi, () =>
|
|
41
43
|
bound?.lifecycle === session.reloadLifecycle && session.reloadLifecycle.runtimeSnapshotGeneration === generation
|
|
@@ -57,6 +59,13 @@ export function registerRuntimeSnapshot(
|
|
|
57
59
|
? artifactOwner
|
|
58
60
|
: undefined,
|
|
59
61
|
);
|
|
62
|
+
const recoveryBridge = registerOperationRecoveryBridge(pi, () =>
|
|
63
|
+
artifactOwner &&
|
|
64
|
+
bound?.lifecycle === session.reloadLifecycle &&
|
|
65
|
+
session.reloadLifecycle.runtimeSnapshotGeneration === generation
|
|
66
|
+
? artifactOwner
|
|
67
|
+
: undefined,
|
|
68
|
+
);
|
|
60
69
|
const unsubscribeRuntime = pi.events?.on?.(RUNTIME_SNAPSHOT_EVENT, (input: unknown) => {
|
|
61
70
|
const request = input as {
|
|
62
71
|
version?: number;
|
|
@@ -247,6 +256,7 @@ export function registerRuntimeSnapshot(
|
|
|
247
256
|
unsubscribeOperations?.();
|
|
248
257
|
unsubscribeHistory?.();
|
|
249
258
|
artifactBridge.close();
|
|
259
|
+
recoveryBridge.close();
|
|
250
260
|
void initiative.close().catch(() => undefined);
|
|
251
261
|
dashboardSources.close();
|
|
252
262
|
prompts.close();
|
package/extensions/session.ts
CHANGED
|
@@ -156,6 +156,7 @@ export interface GrantsSession extends NativeSessionHost {
|
|
|
156
156
|
dashboardArtifacts?: DashboardSavedEvidence[];
|
|
157
157
|
dashboardChoices?: ReturnType<typeof import("./dashboard-choice-controls.ts").registerDashboardChoiceOwner>;
|
|
158
158
|
dashboardObservations?: () => Omit<DashboardOwnerObservation, "version" | "resources" | "capture"> | undefined;
|
|
159
|
+
dashboardRefreshSources?: () => boolean;
|
|
159
160
|
autoMode?: AutoModeReader;
|
|
160
161
|
autoModeFailure?: string;
|
|
161
162
|
/** Reconciled from the actual owner root on reload; captured call owners stay immutable. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-daddy",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.59.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",
|
|
@@ -216,53 +216,63 @@ export interface OperationArtifactHistory {
|
|
|
216
216
|
final?: RetainedOperationFinal;
|
|
217
217
|
partial?: { text: string; sha256: string };
|
|
218
218
|
}
|
|
219
|
-
|
|
219
|
+
/** Exact read without creating directories, adopting an owner, or publishing an admission. */
|
|
220
|
+
export function readOperationHistory(
|
|
221
|
+
agentDirectory: string,
|
|
222
|
+
owner: OperationArtifactOwner,
|
|
223
|
+
operationId: string,
|
|
224
|
+
includeFinal = true,
|
|
225
|
+
): OperationArtifactHistory | null {
|
|
220
226
|
ownerCheck(owner);
|
|
221
227
|
const directory = realpathSync(agentDirectory);
|
|
222
|
-
|
|
223
|
-
const
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
updatedAt: admission.admittedAt,
|
|
244
|
-
};
|
|
245
|
-
return {
|
|
246
|
-
operation,
|
|
247
|
-
requestDigest: admission.request.requestDigest,
|
|
248
|
-
reason: "admission retained without a published result; no retry or no-start proof",
|
|
249
|
-
};
|
|
250
|
-
}
|
|
251
|
-
const manifest = manifestCheck(JSON.parse(text), admission, path);
|
|
252
|
-
const artifact = refFor(manifest, {
|
|
253
|
-
path: join(path, "result.json"),
|
|
254
|
-
sha256: artifactHash(text),
|
|
255
|
-
bytes: Buffer.byteLength(text),
|
|
256
|
-
});
|
|
257
|
-
const content = includeFinal ? readOperationArtifact(artifact, { agentDirectory: directory }) : undefined;
|
|
228
|
+
const path = location(directory, owner, operationId);
|
|
229
|
+
const admission = admissionAt(path, owner, operationId);
|
|
230
|
+
if (!admission) return null;
|
|
231
|
+
let text: string;
|
|
232
|
+
try {
|
|
233
|
+
text = readBoundedTextSync(join(path, "result.json"), {
|
|
234
|
+
maxBytes: MAX_OPERATION_MANIFEST_BYTES,
|
|
235
|
+
confinedRoot: path,
|
|
236
|
+
}).text;
|
|
237
|
+
} catch (error) {
|
|
238
|
+
if ((error as NodeJS.ErrnoException).code !== "ENOENT") throw error;
|
|
239
|
+
const scope = resolvedScope(path, admission) ?? admission.request;
|
|
240
|
+
const operation: OperationReference = {
|
|
241
|
+
operationId,
|
|
242
|
+
executionId: admission.request.executionId,
|
|
243
|
+
cwd: scope.cwd,
|
|
244
|
+
workspaceId: scope.workspaceId,
|
|
245
|
+
state: "uncertain",
|
|
246
|
+
startedAt: admission.admittedAt,
|
|
247
|
+
updatedAt: admission.admittedAt,
|
|
248
|
+
};
|
|
258
249
|
return {
|
|
259
|
-
operation
|
|
260
|
-
artifact,
|
|
250
|
+
operation,
|
|
261
251
|
requestDigest: admission.request.requestDigest,
|
|
262
|
-
|
|
263
|
-
...(content?.partial ? { partial: content.partial } : {}),
|
|
252
|
+
reason: "admission retained without a published result; no retry or no-start proof",
|
|
264
253
|
};
|
|
254
|
+
}
|
|
255
|
+
const manifest = manifestCheck(JSON.parse(text), admission, path);
|
|
256
|
+
const artifact = refFor(manifest, {
|
|
257
|
+
path: join(path, "result.json"),
|
|
258
|
+
sha256: artifactHash(text),
|
|
259
|
+
bytes: Buffer.byteLength(text),
|
|
260
|
+
});
|
|
261
|
+
const content = includeFinal ? readOperationArtifact(artifact, { agentDirectory: directory }) : undefined;
|
|
262
|
+
return {
|
|
263
|
+
operation: { ...manifest.operation, artifact },
|
|
264
|
+
artifact,
|
|
265
|
+
requestDigest: admission.request.requestDigest,
|
|
266
|
+
...(content?.final ? { final: content.final } : {}),
|
|
267
|
+
...(content?.partial ? { partial: content.partial } : {}),
|
|
265
268
|
};
|
|
269
|
+
}
|
|
270
|
+
export function openOperationArtifacts(agentDirectory: string, owner: OperationArtifactOwner) {
|
|
271
|
+
ownerCheck(owner);
|
|
272
|
+
const directory = realpathSync(agentDirectory);
|
|
273
|
+
privateArtifactDirectory(operationArtifactsDir(directory), true);
|
|
274
|
+
const history = (operationId: string, includeFinal = true) =>
|
|
275
|
+
readOperationHistory(directory, owner, operationId, includeFinal);
|
|
266
276
|
return {
|
|
267
277
|
owner: Object.freeze({ ...owner }),
|
|
268
278
|
history,
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/** Historical producer facts only. No owner adoption, admission, retry or execution authority. */
|
|
2
|
+
import type { OperationArtifactOwner } from "../kernel/operation-artifact.ts";
|
|
3
|
+
import { readOperationHistory, type OperationArtifactHistory } from "./operation-artifacts.ts";
|
|
4
|
+
import { readRuntimeExecutionSettlement } from "./runtime-settlement.ts";
|
|
5
|
+
|
|
6
|
+
export interface OperationRecoverySource {
|
|
7
|
+
owner: OperationArtifactOwner;
|
|
8
|
+
operationId: string;
|
|
9
|
+
}
|
|
10
|
+
export interface OperationRecoveryObservation extends Partial<OperationArtifactHistory> {
|
|
11
|
+
admission: "present" | "absent";
|
|
12
|
+
result: "present" | "absent";
|
|
13
|
+
cleanup: { state: "settled" | "not-started" | "unknown" };
|
|
14
|
+
/** Positive immutable terminal evidence for this exact attempt, never permission for another attempt. */
|
|
15
|
+
noStartProven: boolean;
|
|
16
|
+
}
|
|
17
|
+
export async function readOperationRecovery(
|
|
18
|
+
agentDirectory: string,
|
|
19
|
+
source: OperationRecoverySource,
|
|
20
|
+
): Promise<OperationRecoveryObservation> {
|
|
21
|
+
const retained = readOperationHistory(agentDirectory, source.owner, source.operationId);
|
|
22
|
+
if (!retained)
|
|
23
|
+
return {
|
|
24
|
+
admission: "absent",
|
|
25
|
+
result: "absent",
|
|
26
|
+
cleanup: { state: "unknown" },
|
|
27
|
+
noStartProven: false,
|
|
28
|
+
reason: "No retained admission for this exact owner and operation; absence is not no-start proof.",
|
|
29
|
+
};
|
|
30
|
+
const before = JSON.stringify(retained);
|
|
31
|
+
const { operation, artifact, final, partial } = retained;
|
|
32
|
+
const runtime = operation.runtime;
|
|
33
|
+
const terminalNoStart =
|
|
34
|
+
!!artifact &&
|
|
35
|
+
operation.state === "not-started" &&
|
|
36
|
+
runtime?.cleanup?.state === "not-started" &&
|
|
37
|
+
(runtime.cleanup.executionId === undefined || runtime.cleanup.executionId === operation.executionId) &&
|
|
38
|
+
runtime.cleanup.receiptPath === undefined &&
|
|
39
|
+
(runtime.work === undefined || runtime.work === "unknown") &&
|
|
40
|
+
runtime.final === undefined &&
|
|
41
|
+
!final &&
|
|
42
|
+
!partial;
|
|
43
|
+
let settlement: "settled" | "not-started" | "unknown" = "unknown";
|
|
44
|
+
try {
|
|
45
|
+
settlement = await readRuntimeExecutionSettlement(
|
|
46
|
+
agentDirectory,
|
|
47
|
+
source.owner.sessionId,
|
|
48
|
+
source.owner.cwd,
|
|
49
|
+
operation.executionId,
|
|
50
|
+
);
|
|
51
|
+
} catch {
|
|
52
|
+
// A missing or invalid journal cannot strengthen the immutable result or prove no execution.
|
|
53
|
+
}
|
|
54
|
+
if (JSON.stringify(readOperationHistory(agentDirectory, source.owner, source.operationId)) !== before)
|
|
55
|
+
throw Error("operation recovery evidence changed during read");
|
|
56
|
+
const contradictory = operation.state === "not-started" && (!terminalNoStart || settlement === "settled");
|
|
57
|
+
const noStartProven = terminalNoStart && !contradictory;
|
|
58
|
+
return {
|
|
59
|
+
...retained,
|
|
60
|
+
admission: "present",
|
|
61
|
+
result: artifact ? "present" : "absent",
|
|
62
|
+
cleanup: { state: contradictory ? "unknown" : noStartProven ? "not-started" : settlement },
|
|
63
|
+
noStartProven,
|
|
64
|
+
...(contradictory
|
|
65
|
+
? { reason: "The retained no-start record contains conflicting or incomplete execution evidence." }
|
|
66
|
+
: {}),
|
|
67
|
+
};
|
|
68
|
+
}
|