pi-daddy 0.49.5 → 0.50.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 +51 -1
- package/README.md +217 -27
- package/dist/governance/initiative-coordinator.d.ts +58 -0
- package/dist/governance/initiative-coordinator.d.ts.map +1 -0
- package/dist/governance/initiative-coordinator.js +348 -0
- package/dist/governance/initiative-coordinator.js.map +1 -0
- package/dist/governance/initiative-effects.d.ts +20 -0
- package/dist/governance/initiative-effects.d.ts.map +1 -0
- package/dist/governance/initiative-effects.js +108 -0
- package/dist/governance/initiative-effects.js.map +1 -0
- package/dist/governance/initiative-state.d.ts +13 -0
- package/dist/governance/initiative-state.d.ts.map +1 -0
- package/dist/governance/initiative-state.js +122 -0
- package/dist/governance/initiative-state.js.map +1 -0
- package/dist/governance/operation-artifact-io.d.ts +8 -0
- package/dist/governance/operation-artifact-io.d.ts.map +1 -0
- package/dist/governance/operation-artifact-io.js +95 -0
- package/dist/governance/operation-artifact-io.js.map +1 -0
- package/dist/governance/operation-artifact-scan.d.ts +13 -0
- package/dist/governance/operation-artifact-scan.d.ts.map +1 -0
- package/dist/governance/operation-artifact-scan.js +71 -0
- package/dist/governance/operation-artifact-scan.js.map +1 -0
- package/dist/governance/operation-artifacts.d.ts +53 -0
- package/dist/governance/operation-artifacts.d.ts.map +1 -0
- package/dist/governance/operation-artifacts.js +309 -0
- package/dist/governance/operation-artifacts.js.map +1 -0
- package/dist/governance/runtime-settlement.d.ts +2 -0
- package/dist/governance/runtime-settlement.d.ts.map +1 -1
- package/dist/governance/runtime-settlement.js +26 -0
- package/dist/governance/runtime-settlement.js.map +1 -1
- package/dist/governance/workspace-acceptance.d.ts +5 -0
- package/dist/governance/workspace-acceptance.d.ts.map +1 -1
- package/dist/governance/workspace-acceptance.js +16 -0
- package/dist/governance/workspace-acceptance.js.map +1 -1
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -1
- package/dist/kernel/dashboard-observation.d.ts +76 -0
- package/dist/kernel/dashboard-observation.d.ts.map +1 -0
- package/dist/kernel/dashboard-observation.js +49 -0
- package/dist/kernel/dashboard-observation.js.map +1 -0
- package/dist/kernel/dispatch-operation.d.ts +2 -0
- package/dist/kernel/dispatch-operation.d.ts.map +1 -1
- package/dist/kernel/dispatch-operation.js.map +1 -1
- package/dist/kernel/initiative.d.ts +94 -0
- package/dist/kernel/initiative.d.ts.map +1 -0
- package/dist/kernel/initiative.js +38 -0
- package/dist/kernel/initiative.js.map +1 -0
- package/dist/kernel/operation-artifact.d.ts +49 -0
- package/dist/kernel/operation-artifact.d.ts.map +1 -0
- package/dist/kernel/operation-artifact.js +4 -0
- package/dist/kernel/operation-artifact.js.map +1 -0
- package/dist/kernel/principal-binding.d.ts +4 -0
- package/dist/kernel/principal-binding.d.ts.map +1 -0
- package/dist/kernel/principal-binding.js +94 -0
- package/dist/kernel/principal-binding.js.map +1 -0
- package/dist/kernel/project-paths.d.ts +6 -0
- package/dist/kernel/project-paths.d.ts.map +1 -1
- package/dist/kernel/project-paths.js +12 -0
- package/dist/kernel/project-paths.js.map +1 -1
- package/dist/kernel/selected-definitions.d.ts.map +1 -1
- package/dist/kernel/selected-definitions.js +5 -91
- package/dist/kernel/selected-definitions.js.map +1 -1
- package/dist/kernel/workspace-diagnostics.d.ts +24 -0
- package/dist/kernel/workspace-diagnostics.d.ts.map +1 -0
- package/dist/kernel/workspace-diagnostics.js +81 -0
- package/dist/kernel/workspace-diagnostics.js.map +1 -0
- package/dist/products/activity-storage.d.ts +2 -0
- package/dist/products/activity-storage.d.ts.map +1 -0
- package/dist/products/activity-storage.js +119 -0
- package/dist/products/activity-storage.js.map +1 -0
- package/dist/products/activity-timeline.d.ts +4 -0
- package/dist/products/activity-timeline.d.ts.map +1 -1
- package/dist/products/activity-timeline.js +12 -0
- package/dist/products/activity-timeline.js.map +1 -1
- package/dist/products/dashboard-cli.d.ts +2 -0
- package/dist/products/dashboard-cli.d.ts.map +1 -1
- package/dist/products/dashboard-cli.js +41 -9
- package/dist/products/dashboard-cli.js.map +1 -1
- package/dist/products/dashboard-display-controls.d.ts.map +1 -1
- package/dist/products/dashboard-display-controls.js +30 -0
- package/dist/products/dashboard-display-controls.js.map +1 -1
- package/dist/products/dashboard-file-cache.d.ts +10 -0
- package/dist/products/dashboard-file-cache.d.ts.map +1 -0
- package/dist/products/dashboard-file-cache.js +38 -0
- package/dist/products/dashboard-file-cache.js.map +1 -0
- package/dist/products/dashboard-panels.d.ts +6 -0
- package/dist/products/dashboard-panels.d.ts.map +1 -0
- package/dist/products/dashboard-panels.js +179 -0
- package/dist/products/dashboard-panels.js.map +1 -0
- package/dist/products/dashboard-screen.d.ts +8 -0
- package/dist/products/dashboard-screen.d.ts.map +1 -1
- package/dist/products/dashboard-screen.js +86 -15
- package/dist/products/dashboard-screen.js.map +1 -1
- package/dist/products/dashboard-session-client.d.ts +16 -2
- package/dist/products/dashboard-session-client.d.ts.map +1 -1
- package/dist/products/dashboard-session-client.js +64 -11
- package/dist/products/dashboard-session-client.js.map +1 -1
- package/dist/products/dashboard-settings.d.ts.map +1 -1
- package/dist/products/dashboard-settings.js +4 -6
- package/dist/products/dashboard-settings.js.map +1 -1
- package/dist/products/ecosystem-versions.d.ts +1 -1
- package/dist/products/ecosystem-versions.d.ts.map +1 -1
- package/extensions/activity-timeline.ts +3 -1
- package/extensions/artifact-bridge.ts +130 -0
- package/extensions/dashboard-live.ts +63 -0
- package/extensions/dashboard-observation.ts +39 -0
- package/extensions/dashboard-session-server.ts +45 -3
- package/extensions/dashboard-sources.ts +124 -0
- package/extensions/delegation-artifacts.ts +125 -0
- package/extensions/delegation-operations.ts +42 -13
- package/extensions/ecosystem-versions.ts +12 -5
- package/extensions/grants-command.ts +34 -6
- package/extensions/grants.ts +9 -20
- package/extensions/initiative-dashboard.ts +143 -0
- package/extensions/initiative-runtime.ts +406 -0
- package/extensions/runtime-snapshot.ts +118 -2
- package/extensions/session-environment.ts +13 -1
- package/extensions/session.ts +28 -10
- package/extensions/workspace-diagnostics.ts +90 -0
- package/package.json +1 -1
- package/src/governance/initiative-coordinator.ts +400 -0
- package/src/governance/initiative-effects.ts +146 -0
- package/src/governance/initiative-state.ts +144 -0
- package/src/governance/operation-artifact-io.ts +103 -0
- package/src/governance/operation-artifact-scan.ts +77 -0
- package/src/governance/operation-artifacts.ts +363 -0
- package/src/governance/runtime-settlement.ts +28 -0
- package/src/governance/workspace-acceptance.ts +18 -0
- package/src/index.ts +13 -0
- package/src/kernel/dashboard-observation.ts +109 -0
- package/src/kernel/dispatch-operation.ts +2 -0
- package/src/kernel/initiative.ts +126 -0
- package/src/kernel/operation-artifact.ts +46 -0
- package/src/kernel/principal-binding.ts +104 -0
- package/src/kernel/project-paths.ts +16 -0
- package/src/kernel/selected-definitions.ts +5 -100
- package/src/kernel/workspace-diagnostics.ts +110 -0
- package/src/products/activity-storage.ts +128 -0
- package/src/products/activity-timeline.ts +11 -0
- package/src/products/dashboard-cli.ts +44 -9
- package/src/products/dashboard-display-controls.ts +27 -0
- package/src/products/dashboard-file-cache.ts +38 -0
- package/src/products/dashboard-panels.ts +217 -0
- package/src/products/dashboard-screen.ts +107 -17
- package/src/products/dashboard-session-client.ts +78 -14
- package/src/products/dashboard-settings.ts +4 -6
- package/src/products/ecosystem-versions.ts +2 -1
|
@@ -0,0 +1,406 @@
|
|
|
1
|
+
import { initiativeDashboard } from "./initiative-dashboard.ts";
|
|
2
|
+
/** Trusted selected-work-map connector. A selection permits association only, never dispatch or tool authority. */
|
|
3
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
4
|
+
import { Type } from "typebox";
|
|
5
|
+
import { agentDir } from "../src/kernel/project-paths.ts";
|
|
6
|
+
import { validOperationId, type OperationRequest } from "../src/kernel/dispatch-operation.ts";
|
|
7
|
+
import {
|
|
8
|
+
validInitiativeTask,
|
|
9
|
+
type InitiativeTask,
|
|
10
|
+
type InitiativeTaskIdentity,
|
|
11
|
+
type InitiativeEffectReconciliation,
|
|
12
|
+
} from "../src/kernel/initiative.ts";
|
|
13
|
+
import { readInitiativeState } from "../src/governance/initiative-state.ts";
|
|
14
|
+
import { acquireInitiativeCoordinator, type InitiativeCoordinator } from "../src/governance/initiative-coordinator.ts";
|
|
15
|
+
import { openOperationArtifacts } from "../src/governance/operation-artifacts.ts";
|
|
16
|
+
import { readRuntimeExecutionSettlement } from "../src/governance/runtime-settlement.ts";
|
|
17
|
+
import type { GrantsSession } from "./session.ts";
|
|
18
|
+
export const INITIATIVE_EVENT = "pi-daddy:initiative:v1";
|
|
19
|
+
export interface InitiativeOperationBinding {
|
|
20
|
+
capture(request: OperationRequest):
|
|
21
|
+
| {
|
|
22
|
+
begin(): Promise<void>;
|
|
23
|
+
assertCurrent(scope?: { cwd: string; workspaceId: string | null }): Promise<void>;
|
|
24
|
+
notAdmitted(): Promise<void>;
|
|
25
|
+
}
|
|
26
|
+
| undefined;
|
|
27
|
+
}
|
|
28
|
+
type Owner = { sessionId: string; cwd: string; lifecycle: object };
|
|
29
|
+
export function registerInitiativeRuntime(
|
|
30
|
+
pi: ExtensionAPI,
|
|
31
|
+
session: GrantsSession,
|
|
32
|
+
currentOwner: () => Owner | undefined,
|
|
33
|
+
) {
|
|
34
|
+
// Optional composition is unavailable on minimal/legacy hosts; ordinary Daddy startup remains valid.
|
|
35
|
+
if (typeof pi.events?.on !== "function") return { async reset() {}, async close() {} };
|
|
36
|
+
let selected:
|
|
37
|
+
| {
|
|
38
|
+
initiativeId: string;
|
|
39
|
+
owner: Owner;
|
|
40
|
+
coordinator: InitiativeCoordinator;
|
|
41
|
+
tasks: InitiativeTask[];
|
|
42
|
+
dashboard: ReturnType<typeof initiativeDashboard>;
|
|
43
|
+
associations: Map<string, InitiativeTask>;
|
|
44
|
+
assertSelection(): void | Promise<void>;
|
|
45
|
+
assertTaskReady(task: { taskId: string; taskRevision: string }): void | Promise<void>;
|
|
46
|
+
assertExecutionScope?: (scope: {
|
|
47
|
+
taskId: string;
|
|
48
|
+
taskRevision: string;
|
|
49
|
+
cwd: string;
|
|
50
|
+
workspaceId: string | null;
|
|
51
|
+
}) => void | Promise<void>;
|
|
52
|
+
}
|
|
53
|
+
| undefined;
|
|
54
|
+
let selectionEpoch = 0;
|
|
55
|
+
let lastDisplay: { owner: Owner; dashboard: ReturnType<typeof initiativeDashboard> } | undefined;
|
|
56
|
+
session.dashboardInitiative = () =>
|
|
57
|
+
currentOwner() === lastDisplay?.owner ? lastDisplay?.dashboard.snapshot() : undefined;
|
|
58
|
+
session.refreshInitiative = () => {
|
|
59
|
+
selected?.dashboard.invalidate();
|
|
60
|
+
void selected?.dashboard.refresh().catch(() => undefined);
|
|
61
|
+
};
|
|
62
|
+
const stillSelected = async (s: NonNullable<typeof selected>) => {
|
|
63
|
+
if (selected !== s || currentOwner() !== s.owner) throw Error("initiative selection changed");
|
|
64
|
+
try {
|
|
65
|
+
// The coordinator invokes this selection's same bound assertAuthority callback, with generation checks.
|
|
66
|
+
await s.coordinator.assertCurrent();
|
|
67
|
+
} catch (error) {
|
|
68
|
+
s.dashboard.invalidate();
|
|
69
|
+
throw error;
|
|
70
|
+
}
|
|
71
|
+
if (selected !== s || currentOwner() !== s.owner) throw Error("initiative selection changed");
|
|
72
|
+
};
|
|
73
|
+
const stillObserved = async (s: NonNullable<typeof selected>) => {
|
|
74
|
+
if (selected !== s || currentOwner() !== s.owner) throw Error("initiative selection changed");
|
|
75
|
+
try {
|
|
76
|
+
await s.coordinator.assertObservationCurrent();
|
|
77
|
+
} catch (error) {
|
|
78
|
+
s.dashboard.invalidate();
|
|
79
|
+
throw error;
|
|
80
|
+
}
|
|
81
|
+
if (selected !== s || currentOwner() !== s.owner) throw Error("initiative selection changed");
|
|
82
|
+
};
|
|
83
|
+
const associate = async (
|
|
84
|
+
s: NonNullable<typeof selected>,
|
|
85
|
+
input: InitiativeTaskIdentity & { operationId: string },
|
|
86
|
+
) => {
|
|
87
|
+
await stillSelected(s);
|
|
88
|
+
if (s.coordinator.recoveryOnly)
|
|
89
|
+
throw Error("Recovery-only owner cannot associate or dispatch; reconcile then release and acquire.");
|
|
90
|
+
const task = s.tasks.find((t) => t.taskId === input.taskId && t.taskRevision === input.taskRevision);
|
|
91
|
+
if (input.initiativeId !== s.initiativeId || !task || !validOperationId(input.operationId))
|
|
92
|
+
throw Error("task is outside the selected work map");
|
|
93
|
+
await s.assertTaskReady({ taskId: task.taskId, taskRevision: task.taskRevision });
|
|
94
|
+
await stillSelected(s);
|
|
95
|
+
const previous = s.associations.get(input.operationId);
|
|
96
|
+
if (previous && (previous.taskId !== task.taskId || previous.taskRevision !== task.taskRevision))
|
|
97
|
+
throw Error("operation is already associated with another task");
|
|
98
|
+
await s.coordinator.claim(task);
|
|
99
|
+
await stillSelected(s);
|
|
100
|
+
if (s.associations.size >= 1024 && !previous) throw Error("initiative association bound reached");
|
|
101
|
+
const currentAssociation = s.associations.get(input.operationId);
|
|
102
|
+
if (
|
|
103
|
+
currentAssociation &&
|
|
104
|
+
(currentAssociation.taskId !== task.taskId || currentAssociation.taskRevision !== task.taskRevision)
|
|
105
|
+
)
|
|
106
|
+
throw Error("operation association changed concurrently");
|
|
107
|
+
s.associations.set(input.operationId, task);
|
|
108
|
+
await s.dashboard.refresh();
|
|
109
|
+
return {
|
|
110
|
+
associated: true,
|
|
111
|
+
ownerGeneration: s.coordinator.generation,
|
|
112
|
+
operationId: input.operationId,
|
|
113
|
+
taskId: task.taskId,
|
|
114
|
+
taskRevision: task.taskRevision,
|
|
115
|
+
dispatchStarted: false,
|
|
116
|
+
executionAuthorized: false,
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
const binding: InitiativeOperationBinding = {
|
|
120
|
+
capture(request) {
|
|
121
|
+
const s = selected,
|
|
122
|
+
task = s?.associations.get(request.operationId);
|
|
123
|
+
if (!s || !task) return undefined;
|
|
124
|
+
return {
|
|
125
|
+
async begin() {
|
|
126
|
+
await stillSelected(s);
|
|
127
|
+
await s.assertTaskReady({ taskId: task.taskId, taskRevision: task.taskRevision });
|
|
128
|
+
await stillSelected(s);
|
|
129
|
+
await s.coordinator.begin(task, request);
|
|
130
|
+
await stillSelected(s);
|
|
131
|
+
},
|
|
132
|
+
async assertCurrent(scope) {
|
|
133
|
+
await stillSelected(s);
|
|
134
|
+
await s.assertTaskReady({ taskId: task.taskId, taskRevision: task.taskRevision });
|
|
135
|
+
await stillSelected(s);
|
|
136
|
+
if (scope) {
|
|
137
|
+
if (!s.assertExecutionScope) throw Error("trusted execution scope unavailable");
|
|
138
|
+
await s.assertExecutionScope({ taskId: task.taskId, taskRevision: task.taskRevision, ...scope });
|
|
139
|
+
await stillSelected(s);
|
|
140
|
+
await s.coordinator.assertPriorAttemptsSettled(task, request);
|
|
141
|
+
await stillSelected(s);
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
notAdmitted: () => s.coordinator.notAdmitted(request),
|
|
145
|
+
};
|
|
146
|
+
},
|
|
147
|
+
};
|
|
148
|
+
session.initiativeOperations = binding;
|
|
149
|
+
const off = pi.events.on(INITIATIVE_EVENT, (value: unknown) => {
|
|
150
|
+
const r = value as {
|
|
151
|
+
version?: number;
|
|
152
|
+
requestId?: string;
|
|
153
|
+
action?: string;
|
|
154
|
+
sessionId?: string;
|
|
155
|
+
cwd?: string;
|
|
156
|
+
initiativeId?: string;
|
|
157
|
+
expectedRevision?: string | null;
|
|
158
|
+
tasks?: InitiativeTask[];
|
|
159
|
+
assertSelection?: () => void | Promise<void>;
|
|
160
|
+
assertObservationAuthority?: () => void | Promise<void>;
|
|
161
|
+
assertExecutionScope?: (scope: {
|
|
162
|
+
taskId: string;
|
|
163
|
+
taskRevision: string;
|
|
164
|
+
cwd: string;
|
|
165
|
+
workspaceId: string | null;
|
|
166
|
+
}) => void | Promise<void>;
|
|
167
|
+
assertEffectReconciled?: (input: InitiativeEffectReconciliation) => void | Promise<void>;
|
|
168
|
+
assertTaskReady?: (task: { taskId: string; taskRevision: string }) => void | Promise<void>;
|
|
169
|
+
reply?: (value: unknown) => void;
|
|
170
|
+
};
|
|
171
|
+
if (
|
|
172
|
+
r?.version !== 1 ||
|
|
173
|
+
typeof r.requestId !== "string" ||
|
|
174
|
+
r.requestId.length > 512 ||
|
|
175
|
+
typeof r.reply !== "function"
|
|
176
|
+
)
|
|
177
|
+
return;
|
|
178
|
+
void (async () => {
|
|
179
|
+
const owner = currentOwner();
|
|
180
|
+
if (!owner || r.sessionId !== owner.sessionId || r.cwd !== owner.cwd) throw Error("initiative owner unavailable");
|
|
181
|
+
const envelope = {
|
|
182
|
+
version: 1,
|
|
183
|
+
requestId: r.requestId,
|
|
184
|
+
sessionId: owner.sessionId,
|
|
185
|
+
cwd: owner.cwd,
|
|
186
|
+
initiativeId: r.initiativeId,
|
|
187
|
+
};
|
|
188
|
+
if (r.action === "status") {
|
|
189
|
+
const snapshot = readInitiativeState(agentDir(), r.initiativeId!);
|
|
190
|
+
r.reply!({
|
|
191
|
+
...envelope,
|
|
192
|
+
ok: true,
|
|
193
|
+
revision: snapshot?.revision ?? null,
|
|
194
|
+
generation: snapshot?.record.generation ?? null,
|
|
195
|
+
state: snapshot?.record.state ?? "absent",
|
|
196
|
+
});
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
if (
|
|
200
|
+
!["acquire", "recover"].includes(r.action ?? "") ||
|
|
201
|
+
typeof r.assertSelection !== "function" ||
|
|
202
|
+
typeof r.assertTaskReady !== "function" ||
|
|
203
|
+
(r.assertObservationAuthority !== undefined && typeof r.assertObservationAuthority !== "function") ||
|
|
204
|
+
(r.action === "acquire" && typeof r.assertExecutionScope !== "function") ||
|
|
205
|
+
!Array.isArray(r.tasks) ||
|
|
206
|
+
!r.tasks.length ||
|
|
207
|
+
r.tasks.length > 256 ||
|
|
208
|
+
!r.tasks.every(validInitiativeTask) ||
|
|
209
|
+
new Set(r.tasks.map((t) => t.taskId)).size !== r.tasks.length ||
|
|
210
|
+
!(r.expectedRevision === null || typeof r.expectedRevision === "string")
|
|
211
|
+
)
|
|
212
|
+
throw Error("invalid selected initiative request");
|
|
213
|
+
if (selected) throw Error("release the current initiative before selecting another");
|
|
214
|
+
const epoch = ++selectionEpoch,
|
|
215
|
+
assertSelection = r.assertSelection;
|
|
216
|
+
const assertAuthority = async () => {
|
|
217
|
+
if (selectionEpoch !== epoch || currentOwner() !== owner) throw Error("initiative owner changed");
|
|
218
|
+
await assertSelection();
|
|
219
|
+
if (selectionEpoch !== epoch || currentOwner() !== owner) throw Error("initiative owner changed");
|
|
220
|
+
};
|
|
221
|
+
const observeAuthority = r.assertObservationAuthority ?? assertSelection;
|
|
222
|
+
const assertObservationAuthority = async () => {
|
|
223
|
+
if (selectionEpoch !== epoch || currentOwner() !== owner) throw Error("initiative owner changed");
|
|
224
|
+
await observeAuthority();
|
|
225
|
+
if (selectionEpoch !== epoch || currentOwner() !== owner) throw Error("initiative owner changed");
|
|
226
|
+
};
|
|
227
|
+
const coordinator = await acquireInitiativeCoordinator(
|
|
228
|
+
agentDir(),
|
|
229
|
+
{
|
|
230
|
+
initiativeId: r.initiativeId!,
|
|
231
|
+
owner,
|
|
232
|
+
expectedRevision: r.expectedRevision,
|
|
233
|
+
recoveryOnly: r.action === "recover",
|
|
234
|
+
},
|
|
235
|
+
{
|
|
236
|
+
assertAuthority,
|
|
237
|
+
assertObservationAuthority,
|
|
238
|
+
assertEffectReconciled:
|
|
239
|
+
typeof r.assertEffectReconciled === "function"
|
|
240
|
+
? async (input) => {
|
|
241
|
+
await assertObservationAuthority();
|
|
242
|
+
await r.assertEffectReconciled!(structuredClone(input));
|
|
243
|
+
await assertObservationAuthority();
|
|
244
|
+
}
|
|
245
|
+
: undefined,
|
|
246
|
+
async resolveAttempt(attempt) {
|
|
247
|
+
const original = openOperationArtifacts(agentDir(), attempt.owner).history(attempt.operationId, false);
|
|
248
|
+
if (!original) return attempt.state === "not-admitted" ? "not-started" : "unknown";
|
|
249
|
+
if (
|
|
250
|
+
original.operation.executionId !== attempt.executionId ||
|
|
251
|
+
original.requestDigest !== attempt.requestDigest
|
|
252
|
+
)
|
|
253
|
+
return "unknown";
|
|
254
|
+
if (
|
|
255
|
+
original.operation.state === "not-started" &&
|
|
256
|
+
original.operation.runtime?.cleanup?.state === "not-started"
|
|
257
|
+
)
|
|
258
|
+
return "not-started";
|
|
259
|
+
const live =
|
|
260
|
+
attempt.owner.sessionId === owner.sessionId && attempt.owner.cwd === owner.cwd
|
|
261
|
+
? await session.autoMode?.operations?.read(attempt.operationId)
|
|
262
|
+
: undefined;
|
|
263
|
+
if (live?.executionId === attempt.executionId && ["admitting", "running"].includes(live.state))
|
|
264
|
+
return "running";
|
|
265
|
+
try {
|
|
266
|
+
return await readRuntimeExecutionSettlement(
|
|
267
|
+
agentDir(),
|
|
268
|
+
attempt.owner.sessionId,
|
|
269
|
+
attempt.owner.cwd,
|
|
270
|
+
attempt.executionId,
|
|
271
|
+
);
|
|
272
|
+
} catch {
|
|
273
|
+
return "unknown";
|
|
274
|
+
}
|
|
275
|
+
},
|
|
276
|
+
},
|
|
277
|
+
);
|
|
278
|
+
try {
|
|
279
|
+
await assertAuthority();
|
|
280
|
+
} catch (error) {
|
|
281
|
+
await coordinator.close();
|
|
282
|
+
throw error;
|
|
283
|
+
}
|
|
284
|
+
const s = {
|
|
285
|
+
initiativeId: r.initiativeId!,
|
|
286
|
+
owner,
|
|
287
|
+
coordinator,
|
|
288
|
+
tasks: structuredClone(r.tasks),
|
|
289
|
+
dashboard: initiativeDashboard(coordinator, structuredClone(r.tasks)),
|
|
290
|
+
associations: new Map<string, InitiativeTask>(),
|
|
291
|
+
assertSelection,
|
|
292
|
+
assertTaskReady: r.assertTaskReady!,
|
|
293
|
+
assertExecutionScope: r.assertExecutionScope,
|
|
294
|
+
};
|
|
295
|
+
selected = s;
|
|
296
|
+
lastDisplay = { owner, dashboard: s.dashboard };
|
|
297
|
+
try {
|
|
298
|
+
await s.dashboard.refresh();
|
|
299
|
+
await stillSelected(s);
|
|
300
|
+
r.reply!({
|
|
301
|
+
...envelope,
|
|
302
|
+
ok: true,
|
|
303
|
+
generation: coordinator.generation,
|
|
304
|
+
recoveryOnly: coordinator.recoveryOnly,
|
|
305
|
+
revision: coordinator.revision(),
|
|
306
|
+
handle: {
|
|
307
|
+
recoveryOnly: coordinator.recoveryOnly,
|
|
308
|
+
pendingEffects: async () => {
|
|
309
|
+
await stillSelected(s);
|
|
310
|
+
return coordinator.pendingEffects();
|
|
311
|
+
},
|
|
312
|
+
reconcileEffect: async (input: InitiativeEffectReconciliation) => {
|
|
313
|
+
await stillSelected(s);
|
|
314
|
+
const result = await coordinator.reconcileEffect(input);
|
|
315
|
+
await s.dashboard.refresh();
|
|
316
|
+
return result;
|
|
317
|
+
},
|
|
318
|
+
associate: (input: InitiativeTaskIdentity & { operationId: string }) => associate(s, input),
|
|
319
|
+
observe: async (input: InitiativeTaskIdentity) => {
|
|
320
|
+
await stillObserved(s);
|
|
321
|
+
const task = s.tasks.find((t) => t.taskId === input.taskId && t.taskRevision === input.taskRevision);
|
|
322
|
+
if (!task) return { status: "unavailable" };
|
|
323
|
+
const revision = coordinator.revision();
|
|
324
|
+
try {
|
|
325
|
+
const observed = await coordinator.observe(input, task);
|
|
326
|
+
if (selected !== s || currentOwner() !== s.owner) throw Error("initiative selection changed");
|
|
327
|
+
s.dashboard.record(input, observed, revision);
|
|
328
|
+
await s.dashboard.refresh();
|
|
329
|
+
return observed;
|
|
330
|
+
} catch (error) {
|
|
331
|
+
s.dashboard.invalidate(input);
|
|
332
|
+
throw error;
|
|
333
|
+
}
|
|
334
|
+
},
|
|
335
|
+
async release() {
|
|
336
|
+
await stillSelected(s);
|
|
337
|
+
await coordinator.release();
|
|
338
|
+
if (selected === s) selected = undefined;
|
|
339
|
+
s.dashboard.close();
|
|
340
|
+
},
|
|
341
|
+
async close() {
|
|
342
|
+
s.dashboard.close();
|
|
343
|
+
if (selected === s) {
|
|
344
|
+
selected = undefined;
|
|
345
|
+
++selectionEpoch;
|
|
346
|
+
}
|
|
347
|
+
await coordinator.close();
|
|
348
|
+
},
|
|
349
|
+
},
|
|
350
|
+
});
|
|
351
|
+
} catch (error) {
|
|
352
|
+
s.dashboard.close();
|
|
353
|
+
if (selected === s) selected = undefined;
|
|
354
|
+
await coordinator.close();
|
|
355
|
+
throw error;
|
|
356
|
+
}
|
|
357
|
+
})().catch(() => {
|
|
358
|
+
try {
|
|
359
|
+
r.reply!({
|
|
360
|
+
version: 1,
|
|
361
|
+
requestId: r.requestId,
|
|
362
|
+
sessionId: r.sessionId,
|
|
363
|
+
cwd: r.cwd,
|
|
364
|
+
initiativeId: r.initiativeId,
|
|
365
|
+
ok: false,
|
|
366
|
+
reason: "initiative unavailable, conflicted, or reconciliation required",
|
|
367
|
+
});
|
|
368
|
+
} catch {}
|
|
369
|
+
});
|
|
370
|
+
});
|
|
371
|
+
if (session.mayDelegate)
|
|
372
|
+
pi.registerTool?.({
|
|
373
|
+
name: "initiative_task",
|
|
374
|
+
label: "Associate initiative task",
|
|
375
|
+
description:
|
|
376
|
+
"Associate one exact task from the human-selected work map with a planned operation_id. Does not dispatch or grant permissions.",
|
|
377
|
+
parameters: Type.Object({
|
|
378
|
+
taskId: Type.String({ maxLength: 256 }),
|
|
379
|
+
taskRevision: Type.String({ maxLength: 71 }),
|
|
380
|
+
operationId: Type.String({ maxLength: 160 }),
|
|
381
|
+
}),
|
|
382
|
+
async execute(_id, args) {
|
|
383
|
+
const s = selected;
|
|
384
|
+
if (!s) throw Error("No trusted initiative selected. Select it with the work-map owner first.");
|
|
385
|
+
const result = await associate(s, { ...args, initiativeId: s.initiativeId });
|
|
386
|
+
return { content: [{ type: "text" as const, text: JSON.stringify(result) }], details: result };
|
|
387
|
+
},
|
|
388
|
+
});
|
|
389
|
+
return {
|
|
390
|
+
async reset() {
|
|
391
|
+
++selectionEpoch;
|
|
392
|
+
const old = selected;
|
|
393
|
+
selected = undefined;
|
|
394
|
+
old?.dashboard.close();
|
|
395
|
+
await old?.coordinator.close();
|
|
396
|
+
},
|
|
397
|
+
async close() {
|
|
398
|
+
off?.();
|
|
399
|
+
++selectionEpoch;
|
|
400
|
+
const old = selected;
|
|
401
|
+
selected = undefined;
|
|
402
|
+
old?.dashboard.close();
|
|
403
|
+
await old?.coordinator.close();
|
|
404
|
+
},
|
|
405
|
+
};
|
|
406
|
+
}
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
import { registerInitiativeRuntime } from "./initiative-runtime.ts";
|
|
2
|
+
import { registerDashboardLive } from "./dashboard-live.ts";
|
|
3
|
+
import { registerDashboardSources } from "./dashboard-sources.ts";
|
|
4
|
+
import { registerArtifactBridge, OPERATION_ARTIFACT_READY_EVENT, type ArtifactBridgeOwner } from "./artifact-bridge.ts";
|
|
5
|
+
import { operationHistory, operationArtifactReference } from "./delegation-artifacts.ts";
|
|
1
6
|
/** Trusted extension event bridge. Tool calls and model-produced text cannot supply runtime facts. */
|
|
2
7
|
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
3
8
|
import { realpath } from "node:fs/promises";
|
|
@@ -6,6 +11,7 @@ import { reconcileDelegationCapacity } from "./session-capacity.ts";
|
|
|
6
11
|
import { agentDir } from "../src/kernel/project-paths.ts";
|
|
7
12
|
import type { GrantsSession } from "./session.ts";
|
|
8
13
|
import { bindOperationFinals, operationFinal } from "./delegation-operations.ts";
|
|
14
|
+
export const OPERATION_HISTORY_EVENT = "pi-daddy:operation-history:v1";
|
|
9
15
|
export const OPERATION_STATUS_EVENT = "pi-daddy:operation-status:v1";
|
|
10
16
|
export const RUNTIME_SNAPSHOT_EVENT = "pi-daddy:runtime-snapshot:v1";
|
|
11
17
|
export function registerRuntimeSnapshot(
|
|
@@ -17,6 +23,32 @@ export function registerRuntimeSnapshot(
|
|
|
17
23
|
let bound: { sessionId: string; cwd: string; lifecycle: object } | undefined, problem: string | undefined;
|
|
18
24
|
const generation = {};
|
|
19
25
|
let bindSequence = 0;
|
|
26
|
+
let artifactOwner: ArtifactBridgeOwner | undefined;
|
|
27
|
+
const initiative = registerInitiativeRuntime(pi, session, () =>
|
|
28
|
+
bound?.lifecycle === session.reloadLifecycle && session.reloadLifecycle.runtimeSnapshotGeneration === generation
|
|
29
|
+
? bound
|
|
30
|
+
: undefined,
|
|
31
|
+
);
|
|
32
|
+
const dashboardSources = registerDashboardSources(pi, () =>
|
|
33
|
+
bound?.lifecycle === session.reloadLifecycle && session.reloadLifecycle.runtimeSnapshotGeneration === generation
|
|
34
|
+
? bound
|
|
35
|
+
: undefined,
|
|
36
|
+
);
|
|
37
|
+
session.dashboardObservations = () => dashboardSources.snapshot();
|
|
38
|
+
session.dashboardLive = registerDashboardLive(pi, () =>
|
|
39
|
+
bound?.lifecycle === session.reloadLifecycle && session.reloadLifecycle.runtimeSnapshotGeneration === generation
|
|
40
|
+
? bound
|
|
41
|
+
: undefined,
|
|
42
|
+
);
|
|
43
|
+
session.dashboardArtifacts = [];
|
|
44
|
+
|
|
45
|
+
const artifactBridge = registerArtifactBridge(pi, () =>
|
|
46
|
+
artifactOwner &&
|
|
47
|
+
bound?.lifecycle === session.reloadLifecycle &&
|
|
48
|
+
session.reloadLifecycle.runtimeSnapshotGeneration === generation
|
|
49
|
+
? artifactOwner
|
|
50
|
+
: undefined,
|
|
51
|
+
);
|
|
20
52
|
const unsubscribeRuntime = pi.events?.on?.(RUNTIME_SNAPSHOT_EVENT, (input: unknown) => {
|
|
21
53
|
const request = input as {
|
|
22
54
|
version?: number;
|
|
@@ -141,10 +173,11 @@ export function registerRuntimeSnapshot(
|
|
|
141
173
|
lifecycle.runtimeSnapshotGeneration !== generation
|
|
142
174
|
)
|
|
143
175
|
throw Error("operation owner changed during read");
|
|
176
|
+
const artifact = operation ? operationArtifactReference(session, operation) : undefined;
|
|
144
177
|
request.reply!({
|
|
145
178
|
...envelope,
|
|
146
179
|
qualified: true,
|
|
147
|
-
operation,
|
|
180
|
+
operation: operation ? { ...operation, ...(artifact ? { artifact } : {}) } : null,
|
|
148
181
|
...(!operation
|
|
149
182
|
? { reason: "operation record is absent; this does not prove the dispatch was not started" }
|
|
150
183
|
: {}),
|
|
@@ -155,9 +188,59 @@ export function registerRuntimeSnapshot(
|
|
|
155
188
|
}
|
|
156
189
|
})().catch(() => undefined);
|
|
157
190
|
});
|
|
191
|
+
const unsubscribeHistory = pi.events?.on?.(OPERATION_HISTORY_EVENT, (input: unknown) => {
|
|
192
|
+
const request = input as {
|
|
193
|
+
version?: number;
|
|
194
|
+
requestId?: string;
|
|
195
|
+
sessionId?: string;
|
|
196
|
+
cwd?: string;
|
|
197
|
+
operationId?: string;
|
|
198
|
+
reply?: (value: unknown) => void;
|
|
199
|
+
};
|
|
200
|
+
if (
|
|
201
|
+
request?.version !== 1 ||
|
|
202
|
+
typeof request.requestId !== "string" ||
|
|
203
|
+
request.requestId.length > 512 ||
|
|
204
|
+
typeof request.operationId !== "string" ||
|
|
205
|
+
typeof request.reply !== "function"
|
|
206
|
+
)
|
|
207
|
+
return;
|
|
208
|
+
const current = bound;
|
|
209
|
+
if (current && session.reloadLifecycle.runtimeSnapshotGeneration !== generation) return;
|
|
210
|
+
const envelope = {
|
|
211
|
+
version: 1,
|
|
212
|
+
requestId: request.requestId,
|
|
213
|
+
sessionId: current?.sessionId ?? "",
|
|
214
|
+
cwd: current?.cwd ?? "",
|
|
215
|
+
operationId: request.operationId,
|
|
216
|
+
history: true,
|
|
217
|
+
};
|
|
218
|
+
if (
|
|
219
|
+
!current ||
|
|
220
|
+
current.lifecycle !== session.reloadLifecycle ||
|
|
221
|
+
request.sessionId !== current.sessionId ||
|
|
222
|
+
request.cwd !== current.cwd
|
|
223
|
+
) {
|
|
224
|
+
request.reply({ ...envelope, operation: null, reason: "historical owner is not bound" });
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
try {
|
|
228
|
+
const retained = operationHistory(session, request.operationId);
|
|
229
|
+
request.reply({
|
|
230
|
+
...envelope,
|
|
231
|
+
...(retained ?? { operation: null, reason: "no retained operation; absence is not no-start proof" }),
|
|
232
|
+
});
|
|
233
|
+
} catch (error) {
|
|
234
|
+
request.reply({ ...envelope, operation: null, reason: String(error) });
|
|
235
|
+
}
|
|
236
|
+
});
|
|
158
237
|
const unsubscribe = () => {
|
|
159
238
|
unsubscribeRuntime?.();
|
|
160
239
|
unsubscribeOperations?.();
|
|
240
|
+
unsubscribeHistory?.();
|
|
241
|
+
artifactBridge.close();
|
|
242
|
+
void initiative.close().catch(() => undefined);
|
|
243
|
+
dashboardSources.close();
|
|
161
244
|
};
|
|
162
245
|
return {
|
|
163
246
|
async bind(ctx) {
|
|
@@ -165,6 +248,9 @@ export function registerRuntimeSnapshot(
|
|
|
165
248
|
lifecycle = session.reloadLifecycle;
|
|
166
249
|
lifecycle.runtimeSettlement = undefined;
|
|
167
250
|
bound = undefined;
|
|
251
|
+
artifactOwner = undefined;
|
|
252
|
+
artifactBridge.reset();
|
|
253
|
+
await initiative.reset();
|
|
168
254
|
problem = undefined;
|
|
169
255
|
try {
|
|
170
256
|
const sessionId = ctx.sessionManager.getSessionId(),
|
|
@@ -182,8 +268,38 @@ export function registerRuntimeSnapshot(
|
|
|
182
268
|
}
|
|
183
269
|
if (sequence !== bindSequence || session.reloadLifecycle !== lifecycle) return;
|
|
184
270
|
lifecycle.runtimeSettlement = runtime;
|
|
185
|
-
bindOperationFinals(session, sessionId, cwd)
|
|
271
|
+
bindOperationFinals(session, sessionId, cwd, (reference) => {
|
|
272
|
+
if (
|
|
273
|
+
bound?.sessionId === sessionId &&
|
|
274
|
+
bound.cwd === cwd &&
|
|
275
|
+
bound.lifecycle === lifecycle &&
|
|
276
|
+
lifecycle.runtimeSnapshotGeneration === generation
|
|
277
|
+
) {
|
|
278
|
+
session.refreshInitiative?.();
|
|
279
|
+
session.dashboardArtifacts ??= [];
|
|
280
|
+
if (
|
|
281
|
+
!session.dashboardArtifacts.some(
|
|
282
|
+
(item) =>
|
|
283
|
+
item.executionId === reference.executionId && item.manifest.sha256 === reference.manifest.sha256,
|
|
284
|
+
)
|
|
285
|
+
)
|
|
286
|
+
session.dashboardArtifacts.push(reference);
|
|
287
|
+
if (session.dashboardArtifacts.length > 16) session.dashboardArtifacts.shift();
|
|
288
|
+
try {
|
|
289
|
+
pi.appendEntry?.("pi-daddy:operation-artifact:v1", reference);
|
|
290
|
+
} catch {
|
|
291
|
+
/* recover from producer enumeration */
|
|
292
|
+
}
|
|
293
|
+
try {
|
|
294
|
+
pi.events?.emit?.(OPERATION_ARTIFACT_READY_EVENT, { version: 1, reference });
|
|
295
|
+
} catch {
|
|
296
|
+
/* optional consumer cannot alter settled result */
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
session.dashboardArtifacts = [];
|
|
186
301
|
bound = { sessionId, cwd, lifecycle: session.reloadLifecycle };
|
|
302
|
+
artifactOwner = { owner: { sessionId, cwd }, agentDirectory: agentDir() };
|
|
187
303
|
} catch (error) {
|
|
188
304
|
if (sequence === bindSequence && session.reloadLifecycle === lifecycle) problem = String(error);
|
|
189
305
|
}
|
|
@@ -32,8 +32,20 @@ export function reconcileSessionEnvironment(
|
|
|
32
32
|
lifecycle: ReloadLifecycle,
|
|
33
33
|
): void {
|
|
34
34
|
const grantRaw = environment[ENV_GRANT];
|
|
35
|
-
const stored = storedGrantSessionState(grantRaw, session.storeCwd);
|
|
36
35
|
const bounds = depthConfig(environment[ENV_DEPTH], environment[ENV_MAX_DEPTH]);
|
|
36
|
+
// A selected project's store belongs to a root only. Missing inherited authority is never a request
|
|
37
|
+
// to adopt that project's potentially broader root grant (including when an SDK supplies another cwd).
|
|
38
|
+
const stored = storedGrantSessionState(grantRaw ?? (bounds.depth > 0 ? "" : undefined), session.storeCwd);
|
|
39
|
+
session.grantSource =
|
|
40
|
+
grantRaw !== undefined
|
|
41
|
+
? "environment"
|
|
42
|
+
: bounds.depth > 0
|
|
43
|
+
? "missing-inherited"
|
|
44
|
+
: stored.refusal
|
|
45
|
+
? "invalid-store"
|
|
46
|
+
: stored.stored
|
|
47
|
+
? "stored"
|
|
48
|
+
: "default";
|
|
37
49
|
const ledgerRaw = environment[ENV_LEDGER];
|
|
38
50
|
session.ledgerFromEnvironment = ledgerRaw !== undefined;
|
|
39
51
|
const governanceOff = environment[ENV_GOVERNANCE]?.trim() === "off" || environment[ENV_GOVERNANCE]?.trim() === "0";
|