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.
Files changed (149) hide show
  1. package/CHANGELOG.md +56 -1
  2. package/README.md +218 -28
  3. package/dist/governance/initiative-coordinator.d.ts +58 -0
  4. package/dist/governance/initiative-coordinator.d.ts.map +1 -0
  5. package/dist/governance/initiative-coordinator.js +348 -0
  6. package/dist/governance/initiative-coordinator.js.map +1 -0
  7. package/dist/governance/initiative-effects.d.ts +20 -0
  8. package/dist/governance/initiative-effects.d.ts.map +1 -0
  9. package/dist/governance/initiative-effects.js +108 -0
  10. package/dist/governance/initiative-effects.js.map +1 -0
  11. package/dist/governance/initiative-state.d.ts +13 -0
  12. package/dist/governance/initiative-state.d.ts.map +1 -0
  13. package/dist/governance/initiative-state.js +122 -0
  14. package/dist/governance/initiative-state.js.map +1 -0
  15. package/dist/governance/operation-artifact-io.d.ts +8 -0
  16. package/dist/governance/operation-artifact-io.d.ts.map +1 -0
  17. package/dist/governance/operation-artifact-io.js +95 -0
  18. package/dist/governance/operation-artifact-io.js.map +1 -0
  19. package/dist/governance/operation-artifact-scan.d.ts +13 -0
  20. package/dist/governance/operation-artifact-scan.d.ts.map +1 -0
  21. package/dist/governance/operation-artifact-scan.js +71 -0
  22. package/dist/governance/operation-artifact-scan.js.map +1 -0
  23. package/dist/governance/operation-artifacts.d.ts +53 -0
  24. package/dist/governance/operation-artifacts.d.ts.map +1 -0
  25. package/dist/governance/operation-artifacts.js +309 -0
  26. package/dist/governance/operation-artifacts.js.map +1 -0
  27. package/dist/governance/runtime-settlement.d.ts +2 -0
  28. package/dist/governance/runtime-settlement.d.ts.map +1 -1
  29. package/dist/governance/runtime-settlement.js +26 -0
  30. package/dist/governance/runtime-settlement.js.map +1 -1
  31. package/dist/governance/workspace-acceptance.d.ts +5 -0
  32. package/dist/governance/workspace-acceptance.d.ts.map +1 -1
  33. package/dist/governance/workspace-acceptance.js +16 -0
  34. package/dist/governance/workspace-acceptance.js.map +1 -1
  35. package/dist/index.d.ts +8 -0
  36. package/dist/index.d.ts.map +1 -1
  37. package/dist/index.js +8 -0
  38. package/dist/index.js.map +1 -1
  39. package/dist/kernel/dashboard-observation.d.ts +76 -0
  40. package/dist/kernel/dashboard-observation.d.ts.map +1 -0
  41. package/dist/kernel/dashboard-observation.js +49 -0
  42. package/dist/kernel/dashboard-observation.js.map +1 -0
  43. package/dist/kernel/dispatch-operation.d.ts +2 -0
  44. package/dist/kernel/dispatch-operation.d.ts.map +1 -1
  45. package/dist/kernel/dispatch-operation.js.map +1 -1
  46. package/dist/kernel/initiative.d.ts +94 -0
  47. package/dist/kernel/initiative.d.ts.map +1 -0
  48. package/dist/kernel/initiative.js +38 -0
  49. package/dist/kernel/initiative.js.map +1 -0
  50. package/dist/kernel/operation-artifact.d.ts +49 -0
  51. package/dist/kernel/operation-artifact.d.ts.map +1 -0
  52. package/dist/kernel/operation-artifact.js +4 -0
  53. package/dist/kernel/operation-artifact.js.map +1 -0
  54. package/dist/kernel/principal-binding.d.ts +4 -0
  55. package/dist/kernel/principal-binding.d.ts.map +1 -0
  56. package/dist/kernel/principal-binding.js +94 -0
  57. package/dist/kernel/principal-binding.js.map +1 -0
  58. package/dist/kernel/project-paths.d.ts +6 -0
  59. package/dist/kernel/project-paths.d.ts.map +1 -1
  60. package/dist/kernel/project-paths.js +12 -0
  61. package/dist/kernel/project-paths.js.map +1 -1
  62. package/dist/kernel/selected-definitions.d.ts.map +1 -1
  63. package/dist/kernel/selected-definitions.js +5 -91
  64. package/dist/kernel/selected-definitions.js.map +1 -1
  65. package/dist/kernel/workspace-diagnostics.d.ts +24 -0
  66. package/dist/kernel/workspace-diagnostics.d.ts.map +1 -0
  67. package/dist/kernel/workspace-diagnostics.js +81 -0
  68. package/dist/kernel/workspace-diagnostics.js.map +1 -0
  69. package/dist/products/activity-storage.d.ts +2 -0
  70. package/dist/products/activity-storage.d.ts.map +1 -0
  71. package/dist/products/activity-storage.js +119 -0
  72. package/dist/products/activity-storage.js.map +1 -0
  73. package/dist/products/activity-timeline.d.ts +4 -0
  74. package/dist/products/activity-timeline.d.ts.map +1 -1
  75. package/dist/products/activity-timeline.js +12 -0
  76. package/dist/products/activity-timeline.js.map +1 -1
  77. package/dist/products/dashboard-cli.d.ts +2 -0
  78. package/dist/products/dashboard-cli.d.ts.map +1 -1
  79. package/dist/products/dashboard-cli.js +41 -9
  80. package/dist/products/dashboard-cli.js.map +1 -1
  81. package/dist/products/dashboard-display-controls.d.ts.map +1 -1
  82. package/dist/products/dashboard-display-controls.js +30 -0
  83. package/dist/products/dashboard-display-controls.js.map +1 -1
  84. package/dist/products/dashboard-file-cache.d.ts +10 -0
  85. package/dist/products/dashboard-file-cache.d.ts.map +1 -0
  86. package/dist/products/dashboard-file-cache.js +38 -0
  87. package/dist/products/dashboard-file-cache.js.map +1 -0
  88. package/dist/products/dashboard-panels.d.ts +6 -0
  89. package/dist/products/dashboard-panels.d.ts.map +1 -0
  90. package/dist/products/dashboard-panels.js +179 -0
  91. package/dist/products/dashboard-panels.js.map +1 -0
  92. package/dist/products/dashboard-screen.d.ts +8 -0
  93. package/dist/products/dashboard-screen.d.ts.map +1 -1
  94. package/dist/products/dashboard-screen.js +86 -15
  95. package/dist/products/dashboard-screen.js.map +1 -1
  96. package/dist/products/dashboard-session-client.d.ts +16 -2
  97. package/dist/products/dashboard-session-client.d.ts.map +1 -1
  98. package/dist/products/dashboard-session-client.js +64 -11
  99. package/dist/products/dashboard-session-client.js.map +1 -1
  100. package/dist/products/dashboard-settings.d.ts.map +1 -1
  101. package/dist/products/dashboard-settings.js +4 -6
  102. package/dist/products/dashboard-settings.js.map +1 -1
  103. package/dist/products/ecosystem-versions.d.ts +1 -1
  104. package/dist/products/ecosystem-versions.d.ts.map +1 -1
  105. package/extensions/activity-timeline.ts +3 -1
  106. package/extensions/artifact-bridge.ts +130 -0
  107. package/extensions/dashboard-live.ts +63 -0
  108. package/extensions/dashboard-observation.ts +39 -0
  109. package/extensions/dashboard-session-server.ts +45 -3
  110. package/extensions/dashboard-sources.ts +124 -0
  111. package/extensions/delegation-artifacts.ts +125 -0
  112. package/extensions/delegation-operations.ts +100 -42
  113. package/extensions/ecosystem-versions.ts +12 -5
  114. package/extensions/grants-command.ts +34 -6
  115. package/extensions/grants.ts +9 -20
  116. package/extensions/initiative-dashboard.ts +143 -0
  117. package/extensions/initiative-runtime.ts +406 -0
  118. package/extensions/runtime-snapshot.ts +121 -2
  119. package/extensions/session-environment.ts +13 -1
  120. package/extensions/session.ts +28 -10
  121. package/extensions/workspace-diagnostics.ts +90 -0
  122. package/package.json +1 -1
  123. package/src/governance/initiative-coordinator.ts +400 -0
  124. package/src/governance/initiative-effects.ts +146 -0
  125. package/src/governance/initiative-state.ts +144 -0
  126. package/src/governance/operation-artifact-io.ts +103 -0
  127. package/src/governance/operation-artifact-scan.ts +77 -0
  128. package/src/governance/operation-artifacts.ts +363 -0
  129. package/src/governance/runtime-settlement.ts +28 -0
  130. package/src/governance/workspace-acceptance.ts +18 -0
  131. package/src/index.ts +13 -0
  132. package/src/kernel/dashboard-observation.ts +109 -0
  133. package/src/kernel/dispatch-operation.ts +2 -0
  134. package/src/kernel/initiative.ts +126 -0
  135. package/src/kernel/operation-artifact.ts +46 -0
  136. package/src/kernel/principal-binding.ts +104 -0
  137. package/src/kernel/project-paths.ts +16 -0
  138. package/src/kernel/selected-definitions.ts +5 -100
  139. package/src/kernel/workspace-diagnostics.ts +110 -0
  140. package/src/products/activity-storage.ts +128 -0
  141. package/src/products/activity-timeline.ts +11 -0
  142. package/src/products/dashboard-cli.ts +44 -9
  143. package/src/products/dashboard-display-controls.ts +27 -0
  144. package/src/products/dashboard-file-cache.ts +38 -0
  145. package/src/products/dashboard-panels.ts +217 -0
  146. package/src/products/dashboard-screen.ts +107 -17
  147. package/src/products/dashboard-session-client.ts +78 -14
  148. package/src/products/dashboard-settings.ts +4 -6
  149. package/src/products/ecosystem-versions.ts +2 -1
@@ -0,0 +1,125 @@
1
+ /** Compose durable producer evidence with the existing live operation election. */
2
+ import type { OperationClaim, OperationRequest, OperationReference } from "../src/kernel/dispatch-operation.ts";
3
+ import type { OperationArtifactOutcome, OperationArtifactRef } from "../src/kernel/operation-artifact.ts";
4
+ import type { OperationArtifactStore } from "../src/governance/operation-artifacts.ts";
5
+ import type { GrantsSession } from "./session.ts";
6
+ const owners = new WeakMap<
7
+ OperationClaim,
8
+ {
9
+ store: OperationArtifactStore;
10
+ request: OperationRequest;
11
+ reference?: OperationArtifactRef;
12
+ publish?: (reference: OperationArtifactRef) => void;
13
+ }
14
+ >();
15
+ export function operationHistory(session: GrantsSession, operationId: string, includeFinal = true) {
16
+ return session.reloadLifecycle?.operationFinals?.artifacts?.history(operationId, includeFinal) ?? null;
17
+ }
18
+ export async function claimWithArtifact(
19
+ session: GrantsSession,
20
+ request: OperationRequest,
21
+ claim: () => Promise<OperationClaim>,
22
+ scope = session.reloadLifecycle?.operationFinals,
23
+ ): Promise<OperationClaim> {
24
+ if (scope !== session.reloadLifecycle?.operationFinals) throw Error("Operation owner changed before admission");
25
+ const store = scope?.artifacts;
26
+ // Unit-only hosts without the extension lifecycle still exercise the pure live election.
27
+ if (!store) {
28
+ if (session.reloadLifecycle) throw Error("Durable operation owner is not ready; no dispatch started");
29
+ return claim();
30
+ }
31
+ const old = store.history(request.operationId, false);
32
+ if (old) {
33
+ if (old.requestDigest !== request.requestDigest) throw Error("Operation identity conflict with retained request");
34
+ const live = await session.autoMode!.operations!.read(request.operationId);
35
+ if (!live || live.executionId !== old.operation.executionId) return { reused: true, operation: old.operation };
36
+ }
37
+ if (scope !== session.reloadLifecycle?.operationFinals) throw Error("Operation owner changed before admission");
38
+ const initiative = session.initiativeOperations?.capture(request);
39
+ await initiative?.assertCurrent();
40
+ const owned = await claim();
41
+ if (owned.reused) {
42
+ if (old?.artifact && old.operation.executionId === owned.operation.executionId)
43
+ owned.operation.artifact = old.artifact;
44
+ return owned;
45
+ }
46
+ try {
47
+ if (scope !== session.reloadLifecycle?.operationFinals) throw Error("Operation owner changed during admission");
48
+ await initiative?.begin();
49
+ if (scope !== session.reloadLifecycle?.operationFinals)
50
+ throw Error("Operation owner changed during initiative admission");
51
+ const admission = store.admit(request);
52
+ if (!admission.created) throw Error("A retained operation already owns this attempt; no dispatch started");
53
+ } catch (error) {
54
+ await initiative?.notAdmitted().catch(() => undefined);
55
+ await owned.finish?.("not-started", { cleanup: { state: "not-started" } }).catch(() => undefined);
56
+ // This execution never left admission. Persist that original-owner fact even after selection revocation.
57
+ // A competing retained execution remains authoritative: never overwrite it with this occurrence's no-start.
58
+ try {
59
+ const admission = store.admit(request);
60
+ if (
61
+ admission.created ||
62
+ ("operation" in admission &&
63
+ admission.operation.executionId === request.executionId &&
64
+ admission.requestDigest === request.requestDigest)
65
+ ) {
66
+ const reference = store.finish(request, {
67
+ operation: {
68
+ ...owned.operation,
69
+ state: "not-started",
70
+ runtime: { cleanup: { state: "not-started" } },
71
+ updatedAt: new Date().toISOString(),
72
+ },
73
+ });
74
+ try {
75
+ scope.publishArtifact?.(reference);
76
+ } catch {
77
+ /* optional reference hint */
78
+ }
79
+ }
80
+ } catch {
81
+ /* Unavailable persistence remains uncertain; absence is never no-start proof. */
82
+ }
83
+ throw error;
84
+ }
85
+ const state = { store, request: { ...request }, publish: scope.publishArtifact };
86
+ owners.set(owned, state);
87
+ const started = owned.started!;
88
+ owned.started = async (cwd, workspaceId) => {
89
+ await initiative?.assertCurrent({ cwd, workspaceId });
90
+ store.started(request, cwd, workspaceId);
91
+ await started(cwd, workspaceId);
92
+ owned.operation = { ...owned.operation, state: "running", cwd, workspaceId };
93
+ };
94
+ const finish = owned.finish!;
95
+ owned.finish = async (status, runtime) => {
96
+ await finish(status, runtime);
97
+ owned.operation = {
98
+ ...owned.operation,
99
+ state: status,
100
+ ...(runtime ? { runtime } : {}),
101
+ updatedAt: new Date().toISOString(),
102
+ };
103
+ if (!owners.get(owned)!.reference) retainOperationArtifact(owned, { operation: owned.operation });
104
+ owned.operation.artifact = owners.get(owned)!.reference;
105
+ };
106
+ return owned;
107
+ }
108
+ export function retainOperationArtifact(claim: OperationClaim, outcome: OperationArtifactOutcome) {
109
+ const owner = owners.get(claim);
110
+ if (!owner) return;
111
+ const reference = owner.store.finish(owner.request, outcome);
112
+ owner.reference = reference;
113
+ claim.operation.artifact = reference;
114
+ // Pi receives only a small reference, never duplicated full authored content.
115
+ try {
116
+ owner.publish?.(reference);
117
+ } catch {
118
+ /* Durable publication is authoritative; optional hints are recoverable. */
119
+ }
120
+ return reference;
121
+ }
122
+ export function operationArtifactReference(session: GrantsSession, operation: OperationReference) {
123
+ const historical = operationHistory(session, operation.operationId, false);
124
+ return historical?.operation.executionId === operation.executionId ? historical.artifact : undefined;
125
+ }
@@ -1,4 +1,8 @@
1
1
  /** Non-authorizing dispatch election. The elected caller still runs the ordinary governance path. */
2
+ import { claimWithArtifact, retainOperationArtifact } from "./delegation-artifacts.ts";
3
+ import { openOperationArtifacts, type OperationArtifactStore } from "../src/governance/operation-artifacts.ts";
4
+ import type { OperationArtifactRef } from "../src/kernel/operation-artifact.ts";
5
+ import { agentDir } from "../src/kernel/project-paths.ts";
2
6
  import { createHash } from "node:crypto";
3
7
  import { realpath } from "node:fs/promises";
4
8
  import { Type } from "typebox";
@@ -22,21 +26,30 @@ const FINAL_BYTES = 4 * 1024 * 1024,
22
26
  FINAL_ENTRIES = 128;
23
27
  type Final = Extract<NonNullable<DelegationOutcome["final"]>, { state: "complete" }>;
24
28
  export interface OperationFinalStore {
29
+ artifacts?: OperationArtifactStore;
30
+ publishArtifact?: (reference: OperationArtifactRef) => void;
25
31
  lifecycle: object;
26
32
  owner: string;
27
33
  bytes: number;
28
34
  entries: Map<string, { executionId: string; final: Final }>;
29
35
  }
30
- export function bindOperationFinals(session: GrantsSession, sessionId: string, cwd: string) {
36
+ export function bindOperationFinals(
37
+ session: GrantsSession,
38
+ sessionId: string,
39
+ cwd: string,
40
+ publishArtifact?: (reference: OperationArtifactRef) => void,
41
+ ) {
31
42
  const owner = JSON.stringify([sessionId, cwd]),
32
43
  old = session.reloadLifecycle.operationFinals;
33
44
  if (!old || old.lifecycle !== session.reloadLifecycle || old.owner !== owner)
34
45
  session.reloadLifecycle.operationFinals = {
46
+ artifacts: openOperationArtifacts(agentDir(), { sessionId, cwd }),
35
47
  lifecycle: session.reloadLifecycle,
36
48
  owner,
37
49
  bytes: 0,
38
50
  entries: new Map(),
39
51
  };
52
+ session.reloadLifecycle.operationFinals!.publishArtifact = publishArtifact;
40
53
  }
41
54
  /** Capture before admitting work; a late child cannot write a replacement session's store. */
42
55
  export function operationFinalScope(session: GrantsSession): object | undefined {
@@ -116,9 +129,11 @@ export async function claimDelegationOperation(
116
129
  ctx: DelegationToolContext,
117
130
  signal?: AbortSignal,
118
131
  ): Promise<OperationClaim | undefined> {
119
- if (spec.operation_id === undefined) return undefined;
132
+ const operationScope = session.reloadLifecycle?.operationFinals;
133
+ const operationId = spec.operation_id;
134
+ if (operationId === undefined) return undefined;
120
135
  assertDelegationAuthority(session);
121
- if (!validOperationId(spec.operation_id)) throw Error("Invalid operation_id");
136
+ if (!validOperationId(operationId)) throw Error("Invalid operation_id");
122
137
  if (signal?.aborted) throw Error("Operation request aborted");
123
138
  await session.ensureDefinitions?.();
124
139
  assertDefinitionIdentity(session, spec);
@@ -135,47 +150,73 @@ export async function claimDelegationOperation(
135
150
  childExecutionId: ids.executionId,
136
151
  },
137
152
  );
138
- if (!preview.ok && !shouldSeekApproval(preview.result)) {
139
- await recordDelegationDecision({ session, plan: preview, ids, agent: spec.agent });
140
- if (preview.refusal) throw new GovernanceRefusal(preview.refusal);
141
- throw Error(preview.reason ?? "Operation request is not authorized");
142
- }
143
- const operations = session.autoMode?.operations;
144
- if (!operations) throw Error("Session operation admission is unavailable; no dispatch started");
145
- const cwd = await realpath(ctx.cwd);
146
- const { operation_id: _id, ...request } = spec;
147
- const requestDigest = createHash("sha256")
148
- .update(
149
- JSON.stringify(
150
- canonical({
151
- request,
152
- cwd,
153
- model,
154
- piThinking: session.currentThinking?.(),
155
- definitionDigest: preview.definitionDigest,
156
- grant: [...session.ownGrant].sort(),
157
- gated: [...session.gated].sort(),
158
- depth: session.depth,
159
- maxDepth: session.maxDepth,
160
- executor: session.executor.kind,
161
- definition: spec.agent ? session.definitions.get(spec.agent)?.body : null,
162
- runtimeSettings: session.definitionRuntimeSettings,
163
- runtimeOverrides: [...session.definitionRuntimeOverrides.entries()].sort(([a], [b]) => a.localeCompare(b)),
164
- workspaceRoot: spec.workspace ? session.workspacePin?.get(spec.workspace.workspace_id) : null,
165
- }),
166
- ),
167
- )
168
- .digest("hex");
169
- return operations.claim(
170
- {
171
- operationId: spec.operation_id,
153
+ const denied = !preview.ok && !shouldSeekApproval(preview.result);
154
+ const elect = async () => {
155
+ const operations = session.autoMode?.operations;
156
+ if (!operations) throw Error("Session operation admission is unavailable; no dispatch started");
157
+ const cwd = await realpath(ctx.cwd);
158
+ const { operation_id: _id, ...request } = spec;
159
+ const requestDigest = createHash("sha256")
160
+ .update(
161
+ JSON.stringify(
162
+ canonical({
163
+ request,
164
+ cwd,
165
+ model,
166
+ piThinking: session.currentThinking?.(),
167
+ definitionDigest: preview.definitionDigest,
168
+ grant: [...session.ownGrant].sort(),
169
+ gated: [...session.gated].sort(),
170
+ depth: session.depth,
171
+ maxDepth: session.maxDepth,
172
+ executor: session.executor.kind,
173
+ definition: spec.agent ? session.definitions.get(spec.agent)?.body : null,
174
+ runtimeSettings: session.definitionRuntimeSettings,
175
+ runtimeOverrides: [...session.definitionRuntimeOverrides.entries()].sort(([a], [b]) => a.localeCompare(b)),
176
+ workspaceRoot: spec.workspace ? session.workspacePin?.get(spec.workspace.workspace_id) : null,
177
+ }),
178
+ ),
179
+ )
180
+ .digest("hex");
181
+ const identity = {
182
+ operationId,
172
183
  requestDigest,
173
184
  executionId: ids.executionId,
174
185
  cwd,
175
186
  workspaceId: spec.workspace?.workspace_id ?? null,
176
- },
177
- signal,
178
- );
187
+ };
188
+ return claimWithArtifact(session, identity, () => operations.claim(identity, signal), operationScope);
189
+ };
190
+ if (!denied) return elect();
191
+
192
+ const failure = preview.refusal
193
+ ? new GovernanceRefusal(preview.refusal)
194
+ : Error(preview.reason ?? "Operation request is not authorized");
195
+ const evidenceErrors: unknown[] = [];
196
+ try {
197
+ await recordDelegationDecision({ session, plan: preview, ids, agent: spec.agent });
198
+ } catch (error) {
199
+ // A refused request cannot execute, even if its audit append fails. Keep this
200
+ // failure visible without making independent no-start evidence depend on it.
201
+ evidenceErrors.push(error);
202
+ failure.message += `; ledger evidence unavailable: ${String(error)}`;
203
+ }
204
+ try {
205
+ // Election records identity, not permission. Only this newly elected, unlaunched
206
+ // occurrence may supply no-start proof; a duplicate must never rewrite its owner.
207
+ const claim = await elect();
208
+ if (!claim.reused) await claim.finish!("not-started", { cleanup: { state: "not-started" } });
209
+ } catch (error) {
210
+ // Keep the typed governance refusal and make missing/conflicting evidence explicit.
211
+ evidenceErrors.push(error);
212
+ failure.message += `; operation evidence unavailable: ${String(error)}`;
213
+ }
214
+ if (evidenceErrors.length)
215
+ failure.cause =
216
+ evidenceErrors.length === 1
217
+ ? evidenceErrors[0]
218
+ : new AggregateError(evidenceErrors, "Refusal evidence recording failed");
219
+ throw failure;
179
220
  }
180
221
  export function existingOperationOutcome(claim: OperationClaim, depth: number): DelegationOutcome {
181
222
  const active = ["admitting", "running"].includes(claim.operation.state);
@@ -201,13 +242,13 @@ export async function finishDelegationOperation(
201
242
  finalScope: object | undefined,
202
243
  ) {
203
244
  const cleanup = result.cleanup;
204
- const state =
245
+ const state: OperationReference["state"] =
205
246
  cleanup?.state === "settled"
206
247
  ? "settled"
207
248
  : cleanup?.state === "not-started" || (!result.work && !result.final && !cleanup)
208
249
  ? "not-started"
209
250
  : "uncertain";
210
- await claim.finish!(state, {
251
+ const runtime: NonNullable<OperationReference["runtime"]> = {
211
252
  work: result.work,
212
253
  control: result.control,
213
254
  ...(result.final
@@ -238,7 +279,24 @@ export async function finishDelegationOperation(
238
279
  },
239
280
  }
240
281
  : {}),
282
+ };
283
+ const operation = {
284
+ ...claim.operation,
285
+ state,
286
+ runtime,
287
+ cwd: result.cwd ?? claim.operation.cwd,
288
+ workspaceId: result.workspaceId ?? claim.operation.workspaceId,
289
+ updatedAt: new Date().toISOString(),
290
+ };
291
+ retainOperationArtifact(claim, {
292
+ operation,
293
+ ...(result.final?.state === "complete"
294
+ ? { final: result.final }
295
+ : result.final?.diagnosticText !== undefined
296
+ ? { partial: result.final.diagnosticText }
297
+ : {}),
241
298
  });
299
+ await claim.finish!(state, runtime);
242
300
  retainOperationFinal(session, claim, result, finalScope);
243
301
  result.operation = {
244
302
  ...claim.operation,
@@ -18,6 +18,8 @@ const packages = [
18
18
  { id: "pi-daddy", label: "pi-daddy", names: ["pi-daddy"] },
19
19
  { id: "principal-pi-skills", label: "Principal", names: ["principal-pi-skills"] },
20
20
  { id: "skill-harness", label: "Harness", names: ["skill-harness", "skill-harness-monorepo"] },
21
+ { id: "pi-scout-research", label: "Scout", names: ["pi-scout-research"] },
22
+ { id: "bookie-pi-skills", label: "Bookie", names: ["pi-bookie", "bookie-pi-skills", "@bookie/pi-extension"] },
21
23
  ] as const;
22
24
  interface LoadedPackage {
23
25
  id: EcosystemPackageId;
@@ -74,7 +76,7 @@ export function createEcosystemVersionInventory(
74
76
  if (!value || typeof value !== "object") return;
75
77
  const item = value as LoadedPackage;
76
78
  if (
77
- !["principal-pi-skills", "skill-harness"].includes(item.id) ||
79
+ !["principal-pi-skills", "skill-harness", "pi-scout-research", "bookie-pi-skills"].includes(item.id) ||
78
80
  typeof item.root !== "string" ||
79
81
  !item.root.startsWith("/")
80
82
  )
@@ -92,10 +94,11 @@ export function createEcosystemVersionInventory(
92
94
  }
93
95
  const rows: EcosystemVersionRow[] = packages.map((pkg) => {
94
96
  const loaded = reports.filter((item) => item.id === pkg.id);
97
+ const npmName = (source: string) =>
98
+ pkg.names.find((name) => source === `npm:${name}` || source.startsWith(`npm:${name}@`));
95
99
  const sources = configured.filter(
96
100
  (item) =>
97
- item.source === `npm:${pkg.id}` ||
98
- item.source.startsWith(`npm:${pkg.id}@`) ||
101
+ npmName(item.source) !== undefined ||
99
102
  (item.installedPath !== undefined && ports.readVersion(item.installedPath, pkg.names) !== null) ||
100
103
  loaded.some((x) => item.installedPath && resolve(item.installedPath) === resolve(x.root)),
101
104
  );
@@ -116,7 +119,9 @@ export function createEcosystemVersionInventory(
116
119
  pkg.id === "pi"
117
120
  ? ["pi update"]
118
121
  : source?.source.startsWith("npm:") && !multiple
119
- ? [`pi install${source.scope === "project" ? " --local" : ""} npm:${pkg.id}@<version>`]
122
+ ? [
123
+ `pi install${source.scope === "project" ? " --local" : ""} npm:${npmName(source.source) ?? pkg.names[0]}@<version>`,
124
+ ]
120
125
  : ["pi list", "pi config"];
121
126
  if (pkg.id === "principal-pi-skills" && root && !multiple) {
122
127
  const installer = "'" + join(root, "scripts/install-agents.mjs").replaceAll("'", "'\\''") + "'";
@@ -145,7 +150,9 @@ export function createEcosystemVersionInventory(
145
150
  ? "This package did not report its loaded generation. Installed bytes alone do not establish the running version."
146
151
  : pkg.id === "pi"
147
152
  ? "Restart Pi after changing its version."
148
- : "Use an explicit npm version to replace a pin; pi update keeps pinned versions. Reload Pi after installation." +
153
+ : (source?.source.startsWith("npm:")
154
+ ? "Use an explicit npm version to replace a pin; pi update keeps pinned versions. Reload Pi after installation."
155
+ : "Observed local source; manage its selected path, then reload Pi. This is not a published-version check.") +
149
156
  (pkg.id === "principal-pi-skills"
150
157
  ? " Agent installer commands are optional, for legacy installed agent definitions."
151
158
  : ""),
@@ -53,6 +53,10 @@ export interface GrantsCommandContext {
53
53
  unacceptedWorkspaces?: readonly string[];
54
54
  /** Accept the registry's current ids. Injected, so this diagnostic does not become a governance path. */
55
55
  acceptWorkspaces?: () => Promise<string[]>;
56
+ /** Read-only current routing owner inspection; never acquires approval, a pin or a writer lease. */
57
+ inspectWorkspace?: (id: string) => Promise<string>;
58
+ grantSource?: string;
59
+ storeCwd?: string;
56
60
  observed: boolean;
57
61
  depth: number;
58
62
  maxDepth: number;
@@ -110,6 +114,7 @@ const KNOWN_SUBCOMMANDS: readonly string[] = [
110
114
  "approvals",
111
115
  "revoke",
112
116
  "workspaces",
117
+ "workspace",
113
118
  "models",
114
119
  "auto",
115
120
  ];
@@ -190,6 +195,23 @@ export const grantsCommand = {
190
195
  return;
191
196
  }
192
197
 
198
+ if (sub === "workspace") {
199
+ if (words.length !== 2 || !/^[A-Za-z0-9][A-Za-z0-9._/-]*$/.test(target) || target.length > 128) {
200
+ ctx.ui.notify("grants: use /grants workspace <id> for a read-only routing inspection.", "warning");
201
+ return;
202
+ }
203
+ if (!ctx.grants.inspectWorkspace) {
204
+ ctx.ui.notify("grants: workspace inspection is unavailable for this owner.", "warning");
205
+ return;
206
+ }
207
+ try {
208
+ ctx.ui.notify(await ctx.grants.inspectWorkspace(target), "info");
209
+ } catch (error) {
210
+ ctx.ui.notify(`grants: workspace inspection unavailable — ${String(error)}`, "warning");
211
+ }
212
+ return;
213
+ }
214
+
193
215
  if (sub === "workspaces") {
194
216
  // The one verb that WRITES, and it takes its ability to do so from the caller — the same shape
195
217
  // `/grants init` uses, so this screen cannot become a governance path by accident.
@@ -201,7 +223,8 @@ export const grantsCommand = {
201
223
  const accepted = await accept();
202
224
  ctx.ui.notify(
203
225
  `grants: accepted ${accepted.length} workspace id(s) — ${accepted.join(", ") || "(none)"}. ` +
204
- `Ids added to the registry after this are refused until accepted again.`,
226
+ `Accepted for the next root session; this owner's pin is unchanged, including after /reload. ` +
227
+ `Use /grants workspace <id> to inspect current routing. Ids added later require acceptance again.`,
205
228
  "info",
206
229
  );
207
230
  return;
@@ -466,19 +489,21 @@ export const grantsCommand = {
466
489
  // **Marked here rather than left to a join.** The catalog loads the UNNARROWED registry, so it
467
490
  // lists an id nobody accepted; session start names it separately, and review pointed out that a
468
491
  // reader has to put the two together. An id that cannot be routed to should not read as routable.
469
- ` routable ${catalog
492
+ ` registered ${catalog
470
493
  .byKind("workspace")
471
494
  .map((id) =>
472
- (unacceptedWorkspaces ?? []).includes(id.slice("workspace:".length)) ? `${id} (NOT ACCEPTED)` : id,
495
+ (unacceptedWorkspaces ?? []).includes(id.slice("workspace:".length))
496
+ ? `${id} (NOT ACCEPTED when this owner pinned)`
497
+ : id,
473
498
  )
474
- .join(", ")} — held ones only are usable (ADR-0035)`,
499
+ .join(", ")} — inspect /grants workspace <id>; registration alone is not active routing`,
475
500
  // ADR-0042 made a destination pin a PRECONDITION for routing, and it had no operator surface at
476
501
  // all: not here, not at session start, not in the README. An operator refused for want of a pin
477
502
  // could not discover that the mechanism existed, let alone which ids it covered.
478
503
  ...(unacceptedWorkspaces && unacceptedWorkspaces.length > 0
479
504
  ? [
480
- ` unaccepted ${unacceptedWorkspaces.join(", ")} — in the registry, never accepted here, ` +
481
- `so not routable. /grants workspaces to review and accept.`,
505
+ ` unaccepted ${unacceptedWorkspaces.join(", ")} — unaccepted when this owner pinned. ` +
506
+ `Use /grants workspace <id> for current acceptance and activation state.`,
482
507
  ]
483
508
  : []),
484
509
  ` pinned ${
@@ -500,6 +525,9 @@ export const grantsCommand = {
500
525
  ];
501
526
  // Runs the REAL planner AND the real approval step over each definition, so this listing cannot
502
527
  // disagree with what a spawn would do — the R-28 lesson, kept structural rather than remembered.
528
+ lines.push(
529
+ ` grant source ${ctx.grants.grantSource ?? "unobserved"}; store directory ${ctx.grants.storeCwd ?? cwd}`,
530
+ );
503
531
  const shown = [...definitions].slice(0, PREVIEW_LIMIT);
504
532
  for (const [name] of shown) {
505
533
  const { plan, approval } = await previewDelegation(name);
@@ -28,6 +28,7 @@ import {
28
28
  * spawn triggered the human prompt, and `childEnv` clamps it to the grant again on the way out. Each
29
29
  * child derives its own grant from the tool array of its first provider request.
30
30
  */
31
+ import { inspectSessionWorkspace } from "./workspace-diagnostics.ts";
31
32
  import { registerRuntimeSnapshot } from "./runtime-snapshot.ts";
32
33
  import { fileURLToPath } from "node:url";
33
34
  import { homedir } from "node:os";
@@ -124,7 +125,7 @@ export default function (pi: ExtensionAPI, trustedSession?: GrantsSession) {
124
125
  // isolated; it cannot carry state into another extension instance.
125
126
  const owner = (ctx as { sessionManager?: object }).sessionManager ?? session;
126
127
  const reload = bindReloadLifecycle(owner, session.reloadLifecycle);
127
- session.reconcileEnvironment(reload.environment, reload.lifecycle);
128
+ session.reconcileEnvironment(reload.environment, reload.lifecycle, ctx.cwd);
128
129
  session.ownerBound = true;
129
130
  selectedReady = undefined;
130
131
  selectedReportContext = ctx;
@@ -170,24 +171,8 @@ export default function (pi: ExtensionAPI, trustedSession?: GrantsSession) {
170
171
  ctx.ui.notify(`grants: legacy ledger import failed: ${String(error)}`, "error");
171
172
  }
172
173
  }
173
- // The one case the stored-grant lookup can get wrong (ADR-0030). The factory reads the store keyed by
174
- // `process.cwd()` because it runs before any hook and therefore before `ctx` exists — and S-5 forces
175
- // that ordering, since whether `delegate` is registered is decided there. Almost always the two agree.
176
- // When they do not, the session is governed by a different directory's decision than the one it is
177
- // working in, which is exactly the confusion a grant must never cause, so it is said out loud rather
178
- // than left to be inferred from a surprising refusal. Sync, so it is not the R-60 shape.
179
- // Inside no try of its own, and that is deliberate: it is synchronous, so it cannot be the R-60 shape. A
180
- // reviewer noted it sits before the try that contains `resolveExecutor` — which is the right order, because
181
- // this warning is about WHICH directory's grant was read and must reach the operator even if everything
182
- // after it fails.
183
- if (session.storeCwd !== ctx.cwd && process.env[ENV_GRANT] === undefined) {
184
- ctx.ui.notify(
185
- `grants: this session's stored grant was read for ${session.storeCwd}, but pi is working in ` +
186
- `${ctx.cwd}. A grant belongs to a directory, so run /grants init here, or set PI_DADDY_GRANT ` +
187
- `explicitly — the environment always wins.`,
188
- "warning",
189
- );
190
- }
174
+ // The owner-bound reconciliation already selected ctx.cwd before registering delegation tools.
175
+ // Preserve exact store identity; aliases do not silently borrow another spelling's saved authority.
191
176
  try {
192
177
  await reportGrantStoreRefusal(session, ctx.ui);
193
178
  } catch (error) {
@@ -454,7 +439,8 @@ export default function (pi: ExtensionAPI, trustedSession?: GrantsSession) {
454
439
  // read-only diagnostic may see is a decision, and `GrantsCommandContext` is where it is recorded.
455
440
  handler: async (args, ctx) => {
456
441
  // Auto controls and emergency revoke-all need no definition acquisition; OFF must remain reachable.
457
- if (args.trim() !== "revoke --all" && args.trim().split(/\s+/)[0] !== "auto") await session.ensureDefinitions?.();
442
+ if (args.trim() !== "revoke --all" && !["auto", "workspace"].includes(args.trim().split(/\s+/)[0]))
443
+ await session.ensureDefinitions?.();
458
444
  const autoView = await getDashboardControlState(session)
459
445
  .then(({ auto }) => ({
460
446
  autoModeEnabled: auto.enabled,
@@ -465,6 +451,9 @@ export default function (pi: ExtensionAPI, trustedSession?: GrantsSession) {
465
451
  ...ctx,
466
452
  grants: {
467
453
  cwd: session.cwd,
454
+ storeCwd: session.storeCwd,
455
+ grantSource: session.grantSource,
456
+ inspectWorkspace: (id: string) => inspectSessionWorkspace(session, id),
468
457
  governed: session.governed,
469
458
  ownGrant: session.ownGrant,
470
459
  executor: session.executor,