pi-daddy 0.49.4 → 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 +56 -1
- package/README.md +218 -28
- 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 +100 -42
- 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 +121 -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
|
@@ -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,14 @@ 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,
|
|
181
|
+
...(!operation
|
|
182
|
+
? { reason: "operation record is absent; this does not prove the dispatch was not started" }
|
|
183
|
+
: {}),
|
|
148
184
|
...(request.includeFinal === true && operation ? { final: operationFinal(session, operation) } : {}),
|
|
149
185
|
});
|
|
150
186
|
} catch (error) {
|
|
@@ -152,9 +188,59 @@ export function registerRuntimeSnapshot(
|
|
|
152
188
|
}
|
|
153
189
|
})().catch(() => undefined);
|
|
154
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
|
+
});
|
|
155
237
|
const unsubscribe = () => {
|
|
156
238
|
unsubscribeRuntime?.();
|
|
157
239
|
unsubscribeOperations?.();
|
|
240
|
+
unsubscribeHistory?.();
|
|
241
|
+
artifactBridge.close();
|
|
242
|
+
void initiative.close().catch(() => undefined);
|
|
243
|
+
dashboardSources.close();
|
|
158
244
|
};
|
|
159
245
|
return {
|
|
160
246
|
async bind(ctx) {
|
|
@@ -162,6 +248,9 @@ export function registerRuntimeSnapshot(
|
|
|
162
248
|
lifecycle = session.reloadLifecycle;
|
|
163
249
|
lifecycle.runtimeSettlement = undefined;
|
|
164
250
|
bound = undefined;
|
|
251
|
+
artifactOwner = undefined;
|
|
252
|
+
artifactBridge.reset();
|
|
253
|
+
await initiative.reset();
|
|
165
254
|
problem = undefined;
|
|
166
255
|
try {
|
|
167
256
|
const sessionId = ctx.sessionManager.getSessionId(),
|
|
@@ -179,8 +268,38 @@ export function registerRuntimeSnapshot(
|
|
|
179
268
|
}
|
|
180
269
|
if (sequence !== bindSequence || session.reloadLifecycle !== lifecycle) return;
|
|
181
270
|
lifecycle.runtimeSettlement = runtime;
|
|
182
|
-
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 = [];
|
|
183
301
|
bound = { sessionId, cwd, lifecycle: session.reloadLifecycle };
|
|
302
|
+
artifactOwner = { owner: { sessionId, cwd }, agentDirectory: agentDir() };
|
|
184
303
|
} catch (error) {
|
|
185
304
|
if (sequence === bindSequence && session.reloadLifecycle === lifecycle) problem = String(error);
|
|
186
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";
|
package/extensions/session.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import type { InitiativeOperationBinding } from "./initiative-runtime.ts";
|
|
2
|
+
import type { DashboardSourceSnapshot, DashboardContribution } from "../src/kernel/dashboard-observation.ts";
|
|
3
|
+
import type { OperationArtifactRef } from "../src/kernel/operation-artifact.ts";
|
|
4
|
+
import type { DashboardOwnerObservation } from "../src/kernel/dashboard-observation.ts";
|
|
1
5
|
import type { EcosystemVersions } from "../src/products/ecosystem-versions.ts";
|
|
2
6
|
import type { AutoModeReader } from "../src/kernel/auto-mode.ts";
|
|
3
7
|
/**
|
|
@@ -143,7 +147,13 @@ export function activityChildEnv(activity: { rootId: string; path: string; taskI
|
|
|
143
147
|
}
|
|
144
148
|
/** Keep each child's pane after it finishes, for inspection. Off by default: fan-out would flood it. */
|
|
145
149
|
export interface GrantsSession extends NativeSessionHost {
|
|
150
|
+
initiativeOperations?: InitiativeOperationBinding;
|
|
151
|
+
dashboardInitiative?: () => DashboardSourceSnapshot | undefined;
|
|
152
|
+
refreshInitiative?: () => void;
|
|
146
153
|
ecosystemVersions?: () => EcosystemVersions;
|
|
154
|
+
dashboardLive?: () => { turn?: DashboardContribution; activity: DashboardContribution[] };
|
|
155
|
+
dashboardArtifacts?: OperationArtifactRef[];
|
|
156
|
+
dashboardObservations?: () => Omit<DashboardOwnerObservation, "version" | "resources" | "capture"> | undefined;
|
|
147
157
|
autoMode?: AutoModeReader;
|
|
148
158
|
autoModeFailure?: string;
|
|
149
159
|
/** Reconciled from the actual owner root on reload; captured call owners stay immutable. */
|
|
@@ -193,7 +203,7 @@ export interface GrantsSession extends NativeSessionHost {
|
|
|
193
203
|
/** Results from pi's synchronous model catalogue, shared by every delegation in this session. */
|
|
194
204
|
readonly modelResolutionCache: Map<string, boolean>;
|
|
195
205
|
/** Committed per-definition and global child runtime defaults. */
|
|
196
|
-
|
|
206
|
+
definitionRuntimeSettings: DefinitionRuntimeSettings;
|
|
197
207
|
/** PD-7's future session controls write here; deliberately empty in this commit. */
|
|
198
208
|
currentThinking?: () => string;
|
|
199
209
|
readonly definitionRuntimeOverrides: Map<string, DefinitionRuntimeChoice>;
|
|
@@ -295,11 +305,10 @@ export interface GrantsSession extends NativeSessionHost {
|
|
|
295
305
|
* prompted the human. A value scoped to one specific child is never written to this global channel.
|
|
296
306
|
*/
|
|
297
307
|
publishChildEnv(): void;
|
|
298
|
-
/**
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
readonly storeCwd: string;
|
|
308
|
+
/** Exact selected directory whose stored grant was read; provisional process.cwd() before owner binding. */
|
|
309
|
+
storeCwd: string;
|
|
310
|
+
/** Observed provenance only. Explicit/inherited environment always takes precedence over a root store. */
|
|
311
|
+
grantSource?: "environment" | "stored" | "default" | "invalid-store" | "missing-inherited" | "operator-init";
|
|
303
312
|
/** Invalid stored state fails closed and is reported/ledgered during session_start. */
|
|
304
313
|
grantStoreRefusal?: { reason: GrantStoreRefusalReason; path: string };
|
|
305
314
|
/**
|
|
@@ -314,7 +323,7 @@ export interface GrantsSession extends NativeSessionHost {
|
|
|
314
323
|
* widen its own session's ceiling by calling something.
|
|
315
324
|
*/
|
|
316
325
|
adoptGrant(grant: Capability[], projectLedger?: string): void;
|
|
317
|
-
reconcileEnvironment(environment: NodeJS.ProcessEnv, lifecycle: ReloadLifecycle): void;
|
|
326
|
+
reconcileEnvironment(environment: NodeJS.ProcessEnv, lifecycle: ReloadLifecycle, cwd?: string): void;
|
|
318
327
|
}
|
|
319
328
|
/**
|
|
320
329
|
* Parse the environment once and build the session every other module reads through.
|
|
@@ -578,10 +587,11 @@ export function createGrantsSession(
|
|
|
578
587
|
// Local governance is on unless PI_DADDY_GOVERNANCE opts out; explicit inherited grants still win.
|
|
579
588
|
// The factory precedes ctx, so its cwd/store identity is reconciled at session_start.
|
|
580
589
|
const grantRaw = environment[ENV_GRANT];
|
|
590
|
+
const bounds = depthConfig(environment[ENV_DEPTH], environment[ENV_MAX_DEPTH]);
|
|
581
591
|
const storeCwd = process.cwd();
|
|
582
592
|
// One root-only store read supplies both decisions made by `/grants init`. A child always has ENV_GRANT,
|
|
583
593
|
// so it cannot activate a ledger merely because its routed cwd happens to have a v2 store (ADR-0037).
|
|
584
|
-
const storedState = storedGrantSessionState(grantRaw, storeCwd);
|
|
594
|
+
const storedState = storedGrantSessionState(grantRaw ?? (bounds.depth > 0 ? "" : undefined), storeCwd);
|
|
585
595
|
const governanceOff = environment[ENV_GOVERNANCE]?.trim() === "off" || environment[ENV_GOVERNANCE]?.trim() === "0";
|
|
586
596
|
const governed = governanceOff ? false : true;
|
|
587
597
|
const inherited = governanceOff ? storedState.inherited : storedState.governed ? storedState.inherited : [WILDCARD];
|
|
@@ -593,7 +603,6 @@ export function createGrantsSession(
|
|
|
593
603
|
const storedLedger = storedState.defaultLedger;
|
|
594
604
|
// G7 / A-S4 + B-I4: strict, three-way parsing that fails CLOSED. A malformed bound used to yield
|
|
595
605
|
// `NaN`, and every comparison against `NaN` is false, so depth limiting switched itself off.
|
|
596
|
-
const bounds = depthConfig(environment[ENV_DEPTH], environment[ENV_MAX_DEPTH]);
|
|
597
606
|
const runtimeConfig = projectDefinitionRuntimeConfiguration(storeCwd);
|
|
598
607
|
const depth = bounds.depth;
|
|
599
608
|
const maxDepth = runtimeConfig.malformed ? 0 : bounds.maxDepth;
|
|
@@ -709,6 +718,8 @@ export function createGrantsSession(
|
|
|
709
718
|
// enforcer, which is the defect R-28 is named for.
|
|
710
719
|
session.governed = true;
|
|
711
720
|
session.ownGrant = grant;
|
|
721
|
+
session.grantSource = "operator-init";
|
|
722
|
+
session.storeCwd = session.cwd;
|
|
712
723
|
// An environment ledger remains the explicit answer. Otherwise init's v2 choice becomes live now,
|
|
713
724
|
// before publishChildEnv gives the same absolute path to descendants.
|
|
714
725
|
if (!session.ledgerFromEnvironment && projectLedger !== undefined) {
|
|
@@ -716,7 +727,9 @@ export function createGrantsSession(
|
|
|
716
727
|
}
|
|
717
728
|
session.publishChildEnv();
|
|
718
729
|
},
|
|
719
|
-
reconcileEnvironment: (environment, lifecycle) => {
|
|
730
|
+
reconcileEnvironment: (environment, lifecycle, cwd = session.cwd) => {
|
|
731
|
+
const runtimeConfig = projectDefinitionRuntimeConfiguration(cwd);
|
|
732
|
+
session.storeCwd = cwd;
|
|
720
733
|
const evidenceDirectory = environment[ENV_PUBLIC_EVIDENCE_DIR];
|
|
721
734
|
if (session.reloadLifecycle !== lifecycle || session.publicEvidence?.directory !== evidenceDirectory)
|
|
722
735
|
session.publicEvidence = createPublicEvidenceOwner(evidenceDirectory);
|
|
@@ -726,6 +739,11 @@ export function createGrantsSession(
|
|
|
726
739
|
session.discoveryCleanupFailure = lifecycle.discoveryCleanupFailure;
|
|
727
740
|
}
|
|
728
741
|
reconcileSessionEnvironment(session, environment, lifecycle);
|
|
742
|
+
session.definitionRuntimeSettings = runtimeConfig.settings;
|
|
743
|
+
if (runtimeConfig.malformed) {
|
|
744
|
+
session.maxDepth = 0;
|
|
745
|
+
session.malformedBounds.push(runtimeConfig.malformed);
|
|
746
|
+
}
|
|
729
747
|
},
|
|
730
748
|
publishChildEnv: () => {
|
|
731
749
|
const env = childEnv({
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/** Explicit owner inspection, cached for display only. Never refresh authority or scan during a redraw. */
|
|
2
|
+
import { inspectWorkspaceRouting, type WorkspaceRoutingObservation } from "../src/kernel/workspace-diagnostics.ts";
|
|
3
|
+
import { loadWorkspaceRegistry, ENV_WORKSPACE_REGISTRY } from "../src/kernel/workspace.ts";
|
|
4
|
+
import { inspectAcceptedWorkspaces } from "../src/governance/workspace-acceptance.ts";
|
|
5
|
+
import type { DashboardSourceSnapshot } from "../src/kernel/dashboard-observation.ts";
|
|
6
|
+
import type { GrantsSession } from "./session.ts";
|
|
7
|
+
const cached = new WeakMap<GrantsSession, { lifecycle: object; signature: string; value: DashboardSourceSnapshot }>();
|
|
8
|
+
const signature = (s: GrantsSession) =>
|
|
9
|
+
JSON.stringify([
|
|
10
|
+
s.cwd,
|
|
11
|
+
s.storeCwd,
|
|
12
|
+
s.grantSource,
|
|
13
|
+
s.depth,
|
|
14
|
+
s.ownGrant,
|
|
15
|
+
[...(s.workspacePin ?? [])],
|
|
16
|
+
process.env[ENV_WORKSPACE_REGISTRY],
|
|
17
|
+
]);
|
|
18
|
+
const clip = (s: string) => s.replace(/[\x00-\x1f\x7f-\x9f]/g, " ").slice(0, 240);
|
|
19
|
+
export function workspaceDiagnosticSnapshot(session: GrantsSession): DashboardSourceSnapshot | undefined {
|
|
20
|
+
const prior = cached.get(session);
|
|
21
|
+
if (!prior || prior.lifecycle !== session.reloadLifecycle || prior.signature !== signature(session)) return undefined;
|
|
22
|
+
return structuredClone(prior.value);
|
|
23
|
+
}
|
|
24
|
+
export async function inspectSessionWorkspace(session: GrantsSession, workspaceId: string): Promise<string> {
|
|
25
|
+
const lifecycle = session.reloadLifecycle,
|
|
26
|
+
before = signature(session),
|
|
27
|
+
registryPath = process.env[ENV_WORKSPACE_REGISTRY];
|
|
28
|
+
const source = `Grant source: ${session.grantSource ?? "unobserved"}; selected store directory: ${session.storeCwd}`;
|
|
29
|
+
let lines: string[],
|
|
30
|
+
state: WorkspaceRoutingObservation["state"] = "unavailable";
|
|
31
|
+
try {
|
|
32
|
+
if (!session.ownerBound) throw Error("session owner is not bound");
|
|
33
|
+
if (!registryPath) throw Error(`${ENV_WORKSPACE_REGISTRY} is not configured`);
|
|
34
|
+
const registry = await loadWorkspaceRegistry(registryPath);
|
|
35
|
+
const acceptance = await inspectAcceptedWorkspaces(registryPath);
|
|
36
|
+
const result = await inspectWorkspaceRouting({
|
|
37
|
+
workspaceId,
|
|
38
|
+
registry,
|
|
39
|
+
accepted: acceptance.state === "recorded" ? acceptance.accepted.includes(workspaceId) : null,
|
|
40
|
+
ownGrant: [...session.ownGrant],
|
|
41
|
+
pins: session.workspacePin ? new Map(session.workspacePin) : undefined,
|
|
42
|
+
depth: session.depth,
|
|
43
|
+
});
|
|
44
|
+
state = result.state;
|
|
45
|
+
lines = [
|
|
46
|
+
`Workspace ${workspaceId}: ${state}`,
|
|
47
|
+
source,
|
|
48
|
+
`Registry: ${registryPath}`,
|
|
49
|
+
`Known acceptance: ${result.accepted === null ? acceptance.state : result.accepted ? "accepted" : "not in current accepted set"}; capability: ${result.capability}; pin: ${result.pin}`,
|
|
50
|
+
...(result.canonicalRoot ? [`Canonical root: ${result.canonicalRoot}`] : []),
|
|
51
|
+
result.reason,
|
|
52
|
+
result.recovery,
|
|
53
|
+
result.dispatchChecks,
|
|
54
|
+
];
|
|
55
|
+
} catch (error) {
|
|
56
|
+
lines = [
|
|
57
|
+
`Workspace ${workspaceId}: unavailable`,
|
|
58
|
+
source,
|
|
59
|
+
String(error),
|
|
60
|
+
"Correct the named configuration or unavailable source, then inspect again. No state was changed.",
|
|
61
|
+
];
|
|
62
|
+
}
|
|
63
|
+
if (session.reloadLifecycle !== lifecycle || signature(session) !== before)
|
|
64
|
+
throw Error("Workspace inspection owner or authority changed; inspect again.");
|
|
65
|
+
const previous = cached.get(session),
|
|
66
|
+
observedAt = new Date().toISOString();
|
|
67
|
+
cached.set(session, {
|
|
68
|
+
lifecycle,
|
|
69
|
+
signature: before,
|
|
70
|
+
value: {
|
|
71
|
+
producer: "workspace-routing",
|
|
72
|
+
producerVersion: "1",
|
|
73
|
+
generation: `workspace:${session.episodeId}`,
|
|
74
|
+
sequence: (previous?.value.sequence ?? -1) + 1,
|
|
75
|
+
observedAt,
|
|
76
|
+
staleAfterMs: 120_000,
|
|
77
|
+
availability: "observed",
|
|
78
|
+
items: [
|
|
79
|
+
{
|
|
80
|
+
id: "workspace-routing",
|
|
81
|
+
kind: "status",
|
|
82
|
+
label: clip(`Workspace ${workspaceId}: ${state}`),
|
|
83
|
+
state: state === "active" ? "observed" : "unavailable",
|
|
84
|
+
details: [clip(`Last explicit inspection: ${observedAt}`), clip(source), ...lines.slice(-3).map(clip)],
|
|
85
|
+
},
|
|
86
|
+
],
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
return lines.join("\n");
|
|
90
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-daddy",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.50.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",
|